History

updated tLivingString and probably tSampler

spiricom committed 6 years ago

Commit bc99f481 parent b1b598911 files · +369 −240Browse files

Unified · Split

11 files
  1. .DS_Store +0 −0
  2. LEAF/.DS_Store +0 −0
  3. LEAF/Inc/leaf-delay.h +1 −0
  4. LEAF/Inc/leaf-reverb.h +5 −3
  5. LEAF/Inc/leaf-sampling.h +6 −4
  6. LEAF/Src/leaf-delay.c +7 −0
  7. LEAF/Src/leaf-mempool.c +6 −1
  8. LEAF/Src/leaf-physical.c +3 −0
  9. LEAF/Src/leaf-reverb.c +226 −125
  10. LEAF/Src/leaf-sampling.c +116 −109
  11. LEAF/Src/leaf.c +1 −0
.DS_Store+0−0

Binary file not shown.

LEAF/.DS_Store+0−0

Binary file not shown.

LEAF/Inc/leaf-delay.h+1−0
@@ -150,6 +150,7 @@ extern "C" { · 149 unmodified lines
150150 float tTapeDelay_tapOut (tTapeDelay* const d, float tapDelay);
151151 float tTapeDelay_addTo (tTapeDelay* const, float value, uint32_t tapDelay);
152152 float tTapeDelay_tick (tTapeDelay* const, float sample);
153+ void tTapeDelay_incrementInPoint(tTapeDelay* const dl);
153154 float tTapeDelay_getLastOut (tTapeDelay* const);
154155 float tTapeDelay_getLastIn (tTapeDelay* const);
155156
LEAF/Inc/leaf-reverb.h+5−3
@@ -61,8 +61,8 @@ extern "C" { · 60 unmodified lines
6161
6262 float inv_sr, inv_441;
6363
64− tDelay allpassDelays[8];
65− tDelay combDelays[6];
64+ tLinearDelay allpassDelays[8];
65+ tLinearDelay combDelays[6];
6666 float allpassCoeff;
6767 float combCoeffs[6];
6868 float lowpassState;
@@ -77,6 +77,7 @@ extern "C" { · 8 unmodified lines
7777 void tNReverb_free (tNReverb* const);
7878
7979 float tNReverb_tick (tNReverb* const, float input);
80+ void tNReverb_tickStereo(tNReverb* const rev, float input, float* output);
8081
8182 // Set reverb time in seconds.
8283 void tNReverb_setT60 (tNReverb* const, float t60);
@@ -93,7 +94,7 @@ extern "C" { · 10 unmodified lines
9394 float feedback_filter;
9495 float feedback_gain;
9596 float mix;
96−
97+ uint32_t frozen;
9798
9899 float size, size_max, t;
99100
@@ -138,6 +139,7 @@ extern "C" { · 38 unmodified lines
138139 float tDattorroReverb_tick (tDattorroReverb* const, float input);
139140 void tDattorroReverb_tickStereo (tDattorroReverb* const rev, float input, float* output);
140141 void tDattorroReverb_setMix (tDattorroReverb* const, float mix);
142+ void tDattorroReverb_setFreeze (tDattorroReverb* const rev, uint32_t freeze);
141143 void tDattorroReverb_setHP (tDattorroReverb* const, float freq);
142144 void tDattorroReverb_setSize (tDattorroReverb* const, float size);
143145 void tDattorroReverb_setInputDelay (tDattorroReverb* const, float preDelay);
LEAF/Inc/leaf-sampling.h+6−4
@@ -35,8 +35,8 @@ extern "C" { · 34 unmodified lines
3535 float* buff;
3636
3737 uint32_t idx;
38− uint32_t length;
39−
38+ uint32_t bufferLength;
39+ uint32_t recordedLength;
4040 RecordMode mode;
4141
4242 int active;
@@ -64,7 +64,8 @@ extern "C" { · 21 unmodified lines
6464
6565 void tBuffer_clear (tBuffer* const);
6666
67− uint32_t tBuffer_getLength(tBuffer* const);
67+ uint32_t tBuffer_getBufferLength(tBuffer* const);
68+ uint32_t tBuffer_getRecordedLength(tBuffer* const sb);
6869
6970 //==============================================================================
7071
@@ -92,6 +93,7 @@ extern "C" { · 21 unmodified lines
9293
9394 int32_t start, targetstart;
9495 int32_t end, targetend;
96+
9597 uint32_t len;
9698 uint32_t cfxlen;
9799 float numticks;
@@ -118,7 +120,7 @@ extern "C" { · 20 unmodified lines
118120
119121 void tSampler_setStart (tSampler* const, int32_t start);
120122 void tSampler_setEnd (tSampler* const, int32_t end);
121−
123+
122124 static void handleStartEndChange(tSampler* const sp);
123125
124126 void tSampler_setCrossfadeLength (tSampler* const sp, uint32_t length);
LEAF/Src/leaf-delay.c+7−0
@@ -552,6 +552,13 @@ float tTapeDelay_tick (tTapeDelay* const dl, float input) · 551 unmodified lines
552552 return d->lastOut;
553553 }
554554
555+void tTapeDelay_incrementInPoint(tTapeDelay* const dl)
556+{
557+ _tTapeDelay* d = *dl;
558+ // Increment input pointer modulo length.
559+ if (++(d->inPoint) == d->maxDelay ) d->inPoint = 0;
560+}
561+
555562
556563 void tTapeDelay_setRate(tTapeDelay* const dl, float rate)
557564 {
LEAF/Src/leaf-mempool.c+6−1
@@ -71,9 +71,14 @@ void mpool_create (char* memory, size_t size, mpool_t* pool) · 70 unmodified lines
7171
7272 pool->head = create_node(pool->mpool, NULL, NULL, pool->msize-header_size);
7373
74− for (int i = 0; i < pool->head->size; i++) memory[i+header_size]=0;
74+ for (int i = 0; i < pool->head->size; i++)
75+ {
76+ memory[i+header_size]=0;
77+ }
7578 }
7679
80+
81+
7782 void leaf_pool_init(char* memory, size_t size)
7883 {
7984 mpool_create(memory, size, &leaf_pool);
LEAF/Src/leaf-physical.c+3−0
@@ -440,6 +440,7 @@ void tLivingString_init(tLivingString* const pl, float freq, float pickPos, f · 439 unmodified lines
440440 p->curr=0.0f;
441441 tExpSmooth_init(&p->wlSmooth, leaf.sampleRate/freq, 0.01); // smoother for string wavelength (not freq, to avoid expensive divisions)
442442 tLivingString_setFreq(pl, freq);
443+ p->freq = freq;
443444 tExpSmooth_init(&p->ppSmooth, pickPos, 0.01); // smoother for pick position
444445 tLivingString_setPickPos(pl, pickPos);
445446 p->prepIndex=prepIndex;
@@ -447,6 +448,7 @@ void tLivingString_init(tLivingString* const pl, float freq, float pickPos, f · 1 unmodified line
447448 tLinearDelay_init(&p->delUF,p->waveLengthInSamples, 2400);
448449 tLinearDelay_init(&p->delUB,p->waveLengthInSamples, 2400);
449450 tLinearDelay_init(&p->delLB,p->waveLengthInSamples, 2400);
451+ p->dampFreq = dampFreq;
450452 tOnePole_init(&p->bridgeFilter, dampFreq);
451453 tOnePole_init(&p->nutFilter, dampFreq);
452454 tOnePole_init(&p->prepFilterU, dampFreq);
@@ -454,6 +456,7 @@ void tLivingString_init(tLivingString* const pl, float freq, float pickPos, f · 1 unmodified line
454456 tHighpass_init(&p->DCblockerU,13);
455457 tHighpass_init(&p->DCblockerL,13);
456458 p->decay=decay;
459+ p->prepIndex = prepIndex;
457460 tFeedbackLeveler_init(&p->fbLevU, targetLev, levSmoothFactor, levStrength, levMode);
458461 tFeedbackLeveler_init(&p->fbLevL, targetLev, levSmoothFactor, levStrength, levMode);
459462 p->levMode=levMode;
LEAF/Src/leaf-reverb.c+226−125
@@ -149,19 +149,15 @@ void tNReverb_init(tNReverb* const rev, float t60) · 148 unmodified lines
149149
150150 for ( i=0; i<6; i++ )
151151 {
152− tDelay_init(&r->combDelays[i], lengths[i], lengths[i] * 2.0f);
152+ tLinearDelay_init(&r->combDelays[i], lengths[i], lengths[i] * 2.0f);
153153 r->combCoeffs[i] = pow(10.0, (-3 * lengths[i] * leaf.invSampleRate / t60));
154154 }
155155
156156 for ( i=0; i<8; i++ )
157157 {
158− tDelay_init(&r->allpassDelays[i], lengths[i+6], lengths[i+6] * 2.0f);
159− }
160−
161− for ( i=0; i<2; i++ )
162− {
163− tDelay_setDelay(&r->combDelays[i], lengths[i+2]);
158+ tLinearDelay_init(&r->allpassDelays[i], lengths[i+6], lengths[i+6] * 2.0f);
164159 }
160+
165161
166162 tNReverb_setT60(rev, t60);
167163 r->allpassCoeff = 0.7f;
@@ -174,12 +170,12 @@ void tNReverb_free(tNReverb* const rev) · 6 unmodified lines
174170
175171 for (int i = 0; i < 6; i++)
176172 {
177− tDelay_free(&r->combDelays[i]);
173+ tLinearDelay_free(&r->combDelays[i]);
178174 }
179175
180176 for (int i = 0; i < 8; i++)
181177 {
182− tDelay_free(&r->allpassDelays[i]);
178+ tLinearDelay_free(&r->allpassDelays[i]);
183179 }
184180
185181 leaf_free(r);
@@ -193,7 +189,7 @@ void tNReverb_setT60(tNReverb* const rev, float t60) · 7 unmodified lines
193189
194190 r->t60 = t60;
195191
196− for (int i=0; i<6; i++) r->combCoeffs[i] = pow(10.0, (-3.0 * tDelay_getDelay(&r->combDelays[i]) * leaf.invSampleRate / t60 ));
192+ for (int i=0; i<6; i++) r->combCoeffs[i] = pow(10.0, (-3.0 * tLinearDelay_getDelay(&r->combDelays[i]) * leaf.invSampleRate / t60 ));
197193
198194 }
199195
@@ -208,60 +204,114 @@ float tNReverb_tick(tNReverb* const rev, float input) · 8 unmodified lines
208204 _tNReverb* r = *rev;
209205 r->lastIn = input;
210206
211− float temp, temp0, temp1, temp2, out;
207+ float temp, temp0, temp1, temp2, temp3, out;
212208 int i;
213209
214210 temp0 = 0.0;
215211 for ( i=0; i<6; i++ )
216212 {
217− temp = input + (r->combCoeffs[i] * tDelay_getLastOut(&r->combDelays[i]));
218− temp0 += tDelay_tick(&r->combDelays[i],temp);
213+ temp = input + (r->combCoeffs[i] * tLinearDelay_getLastOut(&r->combDelays[i]));
214+ temp0 += tLinearDelay_tick(&r->combDelays[i],temp);
219215 }
220216
221217 for ( i=0; i<3; i++ )
222218 {
223− temp = tDelay_getLastOut(&r->allpassDelays[i]);
219+ temp = tLinearDelay_getLastOut(&r->allpassDelays[i]);
224220 temp1 = r->allpassCoeff * temp;
225221 temp1 += temp0;
226− tDelay_tick(&r->allpassDelays[i], temp1);
222+ tLinearDelay_tick(&r->allpassDelays[i], temp1);
227223 temp0 = -(r->allpassCoeff * temp1) + temp;
228224 }
229225
230226 // One-pole lowpass filter.
231227 r->lowpassState = 0.7f * r->lowpassState + 0.3f * temp0;
232− temp = tDelay_getLastOut(&r->allpassDelays[3]);
228+
229+ temp = tLinearDelay_getLastOut(&r->allpassDelays[3]);
233230 temp1 = r->allpassCoeff * temp;
234231 temp1 += r->lowpassState;
235− tDelay_tick(&r->allpassDelays[3], temp1 );
232+ tLinearDelay_tick(&r->allpassDelays[3], temp1 );
236233 temp1 = -(r->allpassCoeff * temp1) + temp;
237234
238− temp = tDelay_getLastOut(&r->allpassDelays[4]);
235+ temp = tLinearDelay_getLastOut(&r->allpassDelays[4]);
239236 temp2 = r->allpassCoeff * temp;
240237 temp2 += temp1;
241− tDelay_tick(&r->allpassDelays[4], temp2 );
242− out = r->mix * ( -( r->allpassCoeff * temp2 ) + temp );
238+ tLinearDelay_tick(&r->allpassDelays[4], temp2 );
239+ out = -( r->allpassCoeff * temp2 ) + temp ;
243240
244− /*
245− temp = tLinearDelayGetLastOut(&r->allpassDelays[5]);
241+ //the other channel in stereo version below
242+/*
243+ temp = tLinearDelay_getLastOut(&r->allpassDelays[5]);
246244 temp3 = r->allpassCoeff * temp;
247245 temp3 += temp1;
248− tLinearDelayTick(&r->allpassDelays[5], temp3 );
249− lastFrame_[1] = effectMix_*( - ( r->allpassCoeff * temp3 ) + temp );
250− */
251−
246+ tLinearDelay_tick(&r->allpassDelays[5], temp3 );
247+ out = r->mix *( - ( r->allpassCoeff * temp3 ) + temp );
248+*/
249+
252250 temp = ( 1.0f - r->mix ) * input;
253−
251+
254252 out += temp;
255−
253+
256254 r->lastOut = out;
257−
255+
258256 return out;
259257 }
260258
259+void tNReverb_tickStereo(tNReverb* const rev, float input, float* output)
260+{
261+ _tNReverb* r = *rev;
262+ r->lastIn = input;
263+
264+ float temp, temp0, temp1, temp2, temp3, out;
265+ int i;
266+
267+ temp0 = 0.0;
268+ for ( i=0; i<6; i++ )
269+ {
270+ temp = input + (r->combCoeffs[i] * tLinearDelay_getLastOut(&r->combDelays[i]));
271+ temp0 += tLinearDelay_tick(&r->combDelays[i],temp);
272+ }
273+
274+ for ( i=0; i<3; i++ )
275+ {
276+ temp = tLinearDelay_getLastOut(&r->allpassDelays[i]);
277+ temp1 = r->allpassCoeff * temp;
278+ temp1 += temp0;
279+ tLinearDelay_tick(&r->allpassDelays[i], temp1);
280+ temp0 = -(r->allpassCoeff * temp1) + temp;
281+ }
282+
283+ // One-pole lowpass filter.
284+ r->lowpassState = 0.7f * r->lowpassState + 0.3f * temp0;
285+
286+ temp = tLinearDelay_getLastOut(&r->allpassDelays[3]);
287+ temp1 = r->allpassCoeff * temp;
288+ temp1 += r->lowpassState;
289+ tLinearDelay_tick(&r->allpassDelays[3], temp1 );
290+ temp1 = -(r->allpassCoeff * temp1) + temp;
291+
292+ float drymix = ( 1.0f - r->mix ) * input;
293+
294+ temp = tLinearDelay_getLastOut(&r->allpassDelays[4]);
295+ temp2 = r->allpassCoeff * temp;
296+ temp2 += temp1;
297+ tLinearDelay_tick(&r->allpassDelays[4], temp2 );
298+ output[0] = -( r->allpassCoeff * temp2 ) + temp + drymix;
299+ out = output[0];
300+
301+
302+ temp = tLinearDelay_getLastOut(&r->allpassDelays[5]);
303+ temp3 = r->allpassCoeff * temp;
304+ temp3 += temp1;
305+ tLinearDelay_tick(&r->allpassDelays[5], temp3 );
306+ output[1] = r->mix *( - ( r->allpassCoeff * temp3 ) + temp + drymix);
307+
308+ r->lastOut = out;
309+}
310+
261311 void tNReverbSampleRateChanged (tNReverb* const rev)
262312 {
263313 _tNReverb* r = *rev;
264− for (int i=0; i<6; i++) r->combCoeffs[i] = pow(10.0, (-3.0 * tDelay_getDelay(&r->combDelays[i]) * leaf.invSampleRate / r->t60 ));
314+ for (int i=0; i<6; i++) r->combCoeffs[i] = pow(10.0, (-3.0 * tLinearDelay_getDelay(&r->combDelays[i]) * leaf.invSampleRate / r->t60 ));
265315 }
266316
267317 // ======================================DATTORRO=========================================
@@ -279,7 +329,7 @@ void tDattorroReverb_init (tDattorroReverb* const rev) · 11 unmodified lines
279329 r->size_max = 2.0f;
280330 r->size = 1.f;
281331 r->t = r->size * leaf.sampleRate * 0.001f;
282−
332+ r->frozen = 0;
283333 // INPUT
284334 tTapeDelay_init(&r->in_delay, 0.f, SAMP(200.f));
285335 tOnePole_init(&r->in_filter, 1.f);
@@ -381,66 +431,74 @@ float tDattorroReverb_tick (tDattorroReverb* const rev, float inp · 95 unmodified lines
381431 {
382432 _tDattorroReverb* r = *rev;
383433
384− // INPUT
385− float in_sample = tTapeDelay_tick(&r->in_delay, input);
386−
387− in_sample = tOnePole_tick(&r->in_filter, in_sample);
388−
389− for (int i = 0; i < 4; i++)
434+
435+ float in_sample, f1_sample,f1_delay_2_sample, f2_sample, f2_delay_2_sample;
436+
437+ if (r->frozen)
390438 {
391− in_sample = tAllpass_tick(&r->in_allpass[i], in_sample);
392− }
393−
394− // FEEDBACK 1
395− float f1_sample = in_sample + r->f2_last; // + f2_last_out;
396−
397− tAllpass_setDelay(&r->f1_allpass, SAMP(30.51f) + tCycle_tick(&r->f1_lfo) * SAMP(4.0f));
398−
399− f1_sample = tAllpass_tick(&r->f1_allpass, f1_sample);
400−
401− f1_sample = tTapeDelay_tick(&r->f1_delay_1, f1_sample);
402−
403− f1_sample = tOnePole_tick(&r->f1_filter, f1_sample);
404−
405− f1_sample = f1_sample + r->f1_delay_2_last * 0.5f;
406−
407− float f1_delay_2_sample = tTapeDelay_tick(&r->f1_delay_2, f1_sample * 0.5f);
408−
409− r->f1_delay_2_last = f1_delay_2_sample;
410−
411− f1_sample = r->f1_delay_2_last + f1_sample;
412−
413− f1_sample = tHighpass_tick(&r->f1_hp, f1_sample);
414−
415− f1_sample *= r->feedback_gain;
416−
417− r->f1_last = tTapeDelay_tick(&r->f1_delay_3, f1_sample);
418−
419− // FEEDBACK 2
420− float f2_sample = in_sample + r->f1_last;
421−
422− tAllpass_setDelay(&r->f2_allpass, SAMP(22.58f) + tCycle_tick(&r->f2_lfo) * SAMP(4.0f));
423−
424− f2_sample = tAllpass_tick(&r->f2_allpass, f2_sample);
425−
426− f2_sample = tTapeDelay_tick(&r->f2_delay_1, f2_sample);
427−
428− f2_sample = tOnePole_tick(&r->f2_filter, f2_sample);
429−
430− f2_sample = f2_sample + r->f2_delay_2_last * 0.5f;
431−
432− float f2_delay_2_sample = tTapeDelay_tick(&r->f2_delay_2, f2_sample * 0.5f);
433−
434− r->f2_delay_2_last = f2_delay_2_sample;
435−
436− f2_sample = r->f2_delay_2_last + f2_sample;
437−
438− f2_sample = tHighpass_tick(&r->f2_hp, f2_sample);
439−
440− f2_sample *= r->feedback_gain;
441−
442− r->f2_last = tTapeDelay_tick(&r->f2_delay_3, f2_sample);
443−
439+ input = 0.0f;
440+ //r->f1_last = 0.0f;
441+ //r->f2_last = 0.0f;
442+ }
443+ // INPUT
444+ in_sample = tTapeDelay_tick(&r->in_delay, input);
445+
446+ in_sample = tOnePole_tick(&r->in_filter, in_sample);
447+
448+ for (int i = 0; i < 4; i++)
449+ {
450+ in_sample = tAllpass_tick(&r->in_allpass[i], in_sample);
451+ }
452+
453+ // FEEDBACK 1
454+ f1_sample = in_sample + r->f2_last; // + f2_last_out;
455+
456+ tAllpass_setDelay(&r->f1_allpass, SAMP(30.51f) + tCycle_tick(&r->f1_lfo) * SAMP(4.0f));
457+
458+ f1_sample = tAllpass_tick(&r->f1_allpass, f1_sample);
459+
460+ f1_sample = tTapeDelay_tick(&r->f1_delay_1, f1_sample);
461+
462+ f1_sample = tOnePole_tick(&r->f1_filter, f1_sample);
463+
464+ f1_sample = f1_sample + r->f1_delay_2_last * 0.5f;
465+
466+ f1_delay_2_sample = tTapeDelay_tick(&r->f1_delay_2, f1_sample * 0.5f);
467+
468+ r->f1_delay_2_last = f1_delay_2_sample;
469+
470+ f1_sample = r->f1_delay_2_last + f1_sample;
471+
472+ f1_sample = tHighpass_tick(&r->f1_hp, f1_sample);
473+
474+ f1_sample *= r->feedback_gain;
475+
476+ r->f1_last = tTapeDelay_tick(&r->f1_delay_3, f1_sample);
477+
478+ // FEEDBACK 2
479+ f2_sample = in_sample + r->f1_last;
480+
481+ tAllpass_setDelay(&r->f2_allpass, SAMP(22.58f) + tCycle_tick(&r->f2_lfo) * SAMP(4.0f));
482+
483+ f2_sample = tAllpass_tick(&r->f2_allpass, f2_sample);
484+
485+ f2_sample = tTapeDelay_tick(&r->f2_delay_1, f2_sample);
486+
487+ f2_sample = tOnePole_tick(&r->f2_filter, f2_sample);
488+
489+ f2_sample = f2_sample + r->f2_delay_2_last * 0.5f;
490+
491+ f2_delay_2_sample = tTapeDelay_tick(&r->f2_delay_2, f2_sample * 0.5f);
492+
493+ r->f2_delay_2_last = f2_delay_2_sample;
494+
495+ f2_sample = r->f2_delay_2_last + f2_sample;
496+
497+ f2_sample = tHighpass_tick(&r->f2_hp, f2_sample);
498+
499+ f2_sample *= r->feedback_gain;
500+
501+ r->f2_last = tTapeDelay_tick(&r->f2_delay_3, f2_sample);
444502
445503 // TAP OUT 1
446504 f1_sample = tTapeDelay_tapOut(&r->f1_delay_1, SAMP(8.9f)) +
@@ -482,70 +540,84 @@ float tDattorroReverb_tick (tDattorroReverb* const rev, float inp · 35 unmodified lines
482540 void tDattorroReverb_tickStereo (tDattorroReverb* const rev, float input, float* output)
483541 {
484542 _tDattorroReverb* r = *rev;
543+ float in_sample, f1_sample,f1_delay_2_sample, f2_sample, f2_delay_2_sample;
485544
486− // INPUT
487− float in_sample = tTapeDelay_tick(&r->in_delay, input);
488−
489− in_sample = tOnePole_tick(&r->in_filter, in_sample);
490−
491− for (int i = 0; i < 4; i++)
545+ if (r->frozen)
492546 {
493− in_sample = tAllpass_tick(&r->in_allpass[i], in_sample);
547+ input = 0.0f;
548+ //r->f1_last = 0.0f;
549+ //r->f2_last = 0.0f;
494550 }
551+ // INPUT
552+ in_sample = tTapeDelay_tick(&r->in_delay, input);
495553
496− // FEEDBACK 1
497− float f1_sample = in_sample + r->f2_last; // + f2_last_out;
554+ in_sample = tOnePole_tick(&r->in_filter, in_sample);
498555
499− tAllpass_setDelay(&r->f1_allpass, SAMP(30.51f) + tCycle_tick(&r->f1_lfo) * SAMP(4.0f));
556+ for (int i = 0; i < 4; i++)
557+ {
558+ in_sample = tAllpass_tick(&r->in_allpass[i], in_sample);
559+ }
500560
501− f1_sample = tAllpass_tick(&r->f1_allpass, f1_sample);
502561
503− f1_sample = tTapeDelay_tick(&r->f1_delay_1, f1_sample);
562+ // FEEDBACK 1
563+ f1_sample = in_sample + r->f2_last; // + f2_last_out;
504564
505− f1_sample = tOnePole_tick(&r->f1_filter, f1_sample);
565+ tAllpass_setDelay(&r->f1_allpass, SAMP(30.51f) + tCycle_tick(&r->f1_lfo) * SAMP(4.0f));
506566
507− f1_sample = f1_sample + r->f1_delay_2_last * 0.5f;
567+ f1_sample = tAllpass_tick(&r->f1_allpass, f1_sample);
508568
509− float f1_delay_2_sample = tTapeDelay_tick(&r->f1_delay_2, f1_sample * 0.5f);
569+ f1_sample = tTapeDelay_tick(&r->f1_delay_1, f1_sample);
510570
511− r->f1_delay_2_last = f1_delay_2_sample;
571+ f1_sample = tOnePole_tick(&r->f1_filter, f1_sample);
512572
513− f1_sample = r->f1_delay_2_last + f1_sample;
573+ f1_sample = f1_sample + r->f1_delay_2_last * 0.5f;
514574
515− f1_sample = tHighpass_tick(&r->f1_hp, f1_sample);
575+ f1_delay_2_sample = tTapeDelay_tick(&r->f1_delay_2, f1_sample * 0.5f);
516576
517− f1_sample *= r->feedback_gain;
577+ r->f1_delay_2_last = f1_delay_2_sample;
518578
519− f1_sample = tanhf(f1_sample);
579+ f1_sample = r->f1_delay_2_last + f1_sample;
520580
521− r->f1_last = tTapeDelay_tick(&r->f1_delay_3, f1_sample);
581+ f1_sample = tHighpass_tick(&r->f1_hp, f1_sample);
522582
523− // FEEDBACK 2
524− float f2_sample = in_sample + r->f1_last;
583+ f1_sample *= r->feedback_gain;
525584
526− tAllpass_setDelay(&r->f2_allpass, SAMP(22.58f) + tCycle_tick(&r->f2_lfo) * SAMP(4.0f));
585+ if (r->frozen)
586+ {
587+ f1_sample = 0.0f;
588+ }
527589
528− f2_sample = tAllpass_tick(&r->f2_allpass, f2_sample);
590+ r->f1_last = tTapeDelay_tick(&r->f1_delay_3, f1_sample);
529591
530− f2_sample = tTapeDelay_tick(&r->f2_delay_1, f2_sample);
592+ // FEEDBACK 2
593+ f2_sample = in_sample + r->f1_last;
531594
532− f2_sample = tOnePole_tick(&r->f2_filter, f2_sample);
595+ tAllpass_setDelay(&r->f2_allpass, SAMP(22.58f) + tCycle_tick(&r->f2_lfo) * SAMP(4.0f));
533596
534− f2_sample = f2_sample + r->f2_delay_2_last * 0.5f;
597+ f2_sample = tAllpass_tick(&r->f2_allpass, f2_sample);
535598
536− float f2_delay_2_sample = tTapeDelay_tick(&r->f2_delay_2, f2_sample * 0.5f);
599+ f2_sample = tTapeDelay_tick(&r->f2_delay_1, f2_sample);
537600
538− r->f2_delay_2_last = f2_delay_2_sample;
601+ f2_sample = tOnePole_tick(&r->f2_filter, f2_sample);
539602
540− f2_sample = r->f2_delay_2_last + f2_sample;
603+ f2_sample = f2_sample + r->f2_delay_2_last * 0.5f;
541604
542− f2_sample = tHighpass_tick(&r->f2_hp, f2_sample);
605+ f2_delay_2_sample = tTapeDelay_tick(&r->f2_delay_2, f2_sample * 0.5f);
543606
544− f2_sample *= r->feedback_gain;
607+ r->f2_delay_2_last = f2_delay_2_sample;
545608
546− f2_sample = tanhf(f2_sample);
609+ f2_sample = r->f2_delay_2_last + f2_sample;
610+
611+ f2_sample = tHighpass_tick(&r->f2_hp, f2_sample);
612+
613+ f2_sample *= r->feedback_gain;
614+
615+ if (r->frozen)
616+ {
617+ f2_sample = 0.0f;
618+ }
619+ r->f2_last = tTapeDelay_tick(&r->f2_delay_3, f2_sample);
547620
548− r->f2_last = tTapeDelay_tick(&r->f2_delay_3, f2_sample);
549621
550622
551623 // TAP OUT 1
@@ -591,6 +663,35 @@ void tDattorroReverb_setMix (tDattorroReverb* const rev, float mix · 39 unmodified lines
591663 r->mix = LEAF_clip(0.0f, mix, 1.0f);
592664 }
593665
666+void tDattorroReverb_setFreeze (tDattorroReverb* const rev, uint32_t freeze)
667+{
668+ _tDattorroReverb* r = *rev;
669+ r->frozen = freeze;
670+ if (freeze)
671+ {
672+ tAllpass_setGain(&r->f2_allpass, 1.0f);
673+ tAllpass_setGain(&r->f1_allpass, 1.0f);
674+ for (int i = 0; i < 4; i++)
675+ {
676+
677+ //tAllpass_setGain(&r->in_allpass[i], 1.0f);
678+ }
679+ tCycle_setFreq(&r->f1_lfo, 0.0f);
680+ tCycle_setFreq(&r->f2_lfo, 0.0f);
681+ }
682+ else
683+ {
684+ tAllpass_setGain(&r->f2_allpass, 0.7f);
685+ tAllpass_setGain(&r->f1_allpass, 0.7f);
686+ for (int i = 0; i < 4; i++)
687+ {
688+ //tAllpass_setGain(&r->in_allpass[i], in_allpass_gains[i]);
689+ }
690+ tCycle_setFreq(&r->f1_lfo, 0.1f);
691+ tCycle_setFreq(&r->f2_lfo, 0.07f);
692+ }
693+}
694+
594695
595696 void tDattorroReverb_setHP (tDattorroReverb* const rev, float freq)
596697 {
LEAF/Src/leaf-sampling.c+116−109
@@ -30,7 +30,8 @@ void tBuffer_init (tBuffer* const sb, uint32_t length) · 29 unmodified lines
3030
3131 s->buff = (float*) leaf_alloc( sizeof(float) * length);
3232
33− s->length = length;
33+ s->bufferLength = length;
34+ s->recordedLength = 0;
3435 s->active = 0;
3536 s->idx = 0;
3637 s->mode = RecordOneShot;
@@ -44,8 +45,8 @@ void tBuffer_init_locate (tBuffer* const sb, uint32_t length, mpool_t* pool) · 7 unmodified lines
4445
4546 s->buff = (float*) mpool_alloc( sizeof(float) * length, pool);
4647
47− s->length = length;
48− s->active = 0;
48+ s->bufferLength = length;
49+ s->recordedLength = 0;
4950 s->idx = 0;
5051 s->mode = RecordOneShot;
5152
@@ -79,7 +80,7 @@ void tBuffer_tick (tBuffer* const sb, float sample) · 27 unmodified lines
7980
8081 s->idx += 1;
8182
82− if (s->idx >= s->length)
83+ if (s->idx >= s->bufferLength)
8384 {
8485 if (s->mode == RecordOneShot)
8586 {
@@ -96,17 +97,18 @@ void tBuffer_tick (tBuffer* const sb, float sample) · 10 unmodified lines
9697 void tBuffer_read(tBuffer* const sb, float* buff, uint32_t len)
9798 {
9899 _tBuffer* s = *sb;
99− for (int i = 0; i < s->length; i++)
100+ for (int i = 0; i < s->bufferLength; i++)
100101 {
101102 if (i < len) s->buff[i] = buff[i];
102103 else s->buff[i] = 0.f;
103104 }
105+ s->recordedLength = len;
104106 }
105107
106108 float tBuffer_get (tBuffer* const sb, int idx)
107109 {
108110 _tBuffer* s = *sb;
109− if ((idx < 0) || (idx >= s->length)) return 0.f;
111+ if ((idx < 0) || (idx >= s->bufferLength)) return 0.f;
110112 return s->buff[idx];
111113 }
112114
@@ -121,6 +123,7 @@ void tBuffer_stop(tBuffer* const sb) · 8 unmodified lines
121123 {
122124 _tBuffer* s = *sb;
123125 s->active = 0;
126+ s->recordedLength = s->idx;
124127 }
125128
126129 int tBuffer_getRecordPosition(tBuffer* const sb)
@@ -138,16 +141,22 @@ void tBuffer_setRecordMode (tBuffer* const sb, RecordMode mode) · 11 unmodified lines
138141 void tBuffer_clear (tBuffer* const sb)
139142 {
140143 _tBuffer* s = *sb;
141− for (int i = 0; i < s->length; i++)
144+ for (int i = 0; i < s->bufferLength; i++)
142145 {
143146 s->buff[i] = 0.f;
144147 }
145148 }
146149
147−uint32_t tBuffer_getLength(tBuffer* const sb)
150+uint32_t tBuffer_getBufferLength(tBuffer* const sb)
148151 {
149152 _tBuffer* s = *sb;
150− return s->length;
153+ return s->bufferLength;
154+}
155+
156+uint32_t tBuffer_getRecordedLength(tBuffer* const sb)
157+{
158+ _tBuffer* s = *sb;
159+ return s->recordedLength;
151160 }
152161
153162 //================================tSampler=====================================
@@ -156,8 +165,6 @@ static void handleStartEndChange(tSampler* const sp); · 2 unmodified lines
156165
157166 static void attemptStartEndChange(tSampler* const sp);
158167
159−static void updateStartEnd(tSampler* const sp);
160−
161168 void tSampler_init(tSampler* const sp, tBuffer* const b)
162169 {
163170 _tSampler* p = *sp = (_tSampler*) leaf_alloc(sizeof(_tSampler));
@@ -168,7 +175,7 @@ void tSampler_init(tSampler* const sp, tBuffer* const b) · 4 unmodified lines
168175 p->active = 0;
169176
170177 p->start = 0;
171− p->end = p->samp->length - 1;
178+ p->end = p->samp->bufferLength - 1;
172179
173180 p->len = p->end - p->start;
174181
@@ -205,8 +212,17 @@ void tSampler_setSample (tSampler* const sp, tBuffer* const b) · 30 unmodified lines
205212 _tBuffer* s = *b;
206213
207214 p->samp = s;
215+
216+ p->start = 0;
217+ p->end = p->samp->bufferLength - 1;
218+
219+ p->len = p->end - p->start;
220+
221+ p->idx = 0.f;
208222 }
209223
224+volatile uint32_t errorState = 0;
225+
210226 float tSampler_tick (tSampler* const sp)
211227 {
212228 _tSampler* p = *sp;
@@ -227,46 +243,22 @@ float tSampler_tick (tSampler* const sp) · 14 unmodified lines
227243
228244 float* buff = p->samp->buff;
229245
230− int dir = p->bnf * p->dir * p->flip;
231246
247+
232248 int idx, revidx;
233249 float alpha, revalpha;
234250
235− int32_t start = p->start, end = p->end;
251+ int32_t start = p->start;
252+ int32_t end = p->end;
236253 if (p->flip < 0)
237254 {
238255 start = p->end;
239256 end = p->start;
240257 }
241− if (p->mode == PlayLoop)
242− {
243258
244− while((int)p->idx < start)
245− {
246− p->idx += (float)(p->len);
247− }
248− while((int)p->idx > end)
249− {
250−
251− p->idx -= (float)(p->len);
252− }
253− }
254− else // == PlayBackAndForth
255− {
256− if (p->idx < start)
257− {
258− p->bnf = -p->bnf;
259− p->idx = start;
260− }
261− else if (p->idx > end)
262− {
263− p->bnf = -p->bnf;
264− p->idx = end;
265− }
266− }
267259
268260
269−
261+ int dir = p->bnf * p->dir * p->flip;
270262 idx = (int) p->idx;
271263 alpha = p->idx - idx;
272264
@@ -280,7 +272,7 @@ float tSampler_tick (tSampler* const sp) · 7 unmodified lines
280272 uint32_t cfxlen = p->cfxlen;
281273 if (p->len < cfxlen) cfxlen = p->len * 0.25f;//p->len;
282274
283− int length = p->samp->length;
275+ int length = p->samp->recordedLength;
284276
285277 if (dir > 0)
286278 { // num samples (hopping the increment size) to end of loop
@@ -291,24 +283,22 @@ float tSampler_tick (tSampler* const sp) · 4 unmodified lines
291283 numticks = (revidx-start) * p->iinc;
292284 }
293285
294−
295−
296− if (cfxlen > 0) // necessary to avoid divide by zero, also a waste of computation otherwise
286+ // Check dir (direction) to interpolate properly
287+ if (dir > 0)
297288 {
298−
299− // Check dir (direction) to interpolate properly
300− if (dir > 0)
289+ // FORWARD NORMAL SAMPLE
290+ int i1 = ((idx-1) < 0) ? 0 : idx-1;
291+ int i3 = ((idx+1) >= length) ? (idx) : (idx+1);
292+ int i4 = ((idx+2) >= length) ? (length-1) : (idx+2);
293+
294+ sample = LEAF_interpolate_hermite_x (buff[i1],
295+ buff[idx],
296+ buff[i3],
297+ buff[i4],
298+ alpha);
299+
300+ if (cfxlen > 0)// necessary to avoid divide by zero, also a waste of computation otherwise
301301 {
302− // FORWARD NORMAL SAMPLE
303− int i1 = ((idx-1) < 0) ? 0 : idx-1;
304− int i3 = ((idx+1) >= length) ? (idx) : (idx+1);
305− int i4 = ((idx+2) >= length) ? (length-1) : (idx+2);
306−
307− sample = LEAF_interpolate_hermite (buff[i1],
308− buff[idx],
309− buff[i3],
310− buff[i4],
311− alpha);
312302
313303 if (p->mode == PlayLoop)
314304 {
@@ -351,32 +341,43 @@ float tSampler_tick (tSampler* const sp) · 36 unmodified lines
351341 }
352342
353343 }
354−
355344 }
356− else
357− {
358− // REVERSE
359− int i1 = ((revidx+1) >= length) ? (length-1) : revidx+1;
360− int i3 = ((revidx-1) < 0) ? revidx : (revidx-1);
361− int i4 = ((revidx-2) < 0) ? 0 : (revidx-2);
345+ else
346+ {
347+ g2 = 0.0f;
348+ }
362349
363− sample = LEAF_interpolate_hermite_x (buff[i1],
364− buff[revidx],
365− buff[i3],
366− buff[i4],
367− revalpha);
350+ }
351+ else
352+ {
353+ // REVERSE
354+ int i1 = ((revidx+1) >= length) ? (length-1) : revidx+1;
355+ int i3 = ((revidx-1) < 0) ? revidx : (revidx-1);
356+ int i4 = ((revidx-2) < 0) ? 0 : (revidx-2);
368357
358+ sample = LEAF_interpolate_hermite_x (buff[i1],
359+ buff[revidx],
360+ buff[i3],
361+ buff[i4],
362+ revalpha);
369363
370364
371365
366+ if (cfxlen > 0)// necessary to avoid divide by zero, also a waste of computation otherwise
367+ {
368+
372369 if (p->mode == PlayLoop)
373370 {
374371 if (numticks <= (float) cfxlen)
375372 {
376373 // CROSSFADE SAMPLE
377374 int cdx = end + (numticks * p->inc);
378− if (cdx > p->samp->length - 2)
375+ if (cdx > length - 2)
379376 {
377+
378+ //the problem with the click is here --- at some point it crosses this threshold and jumps from a point near the boundary to a point far away from the boundary - that's not correct
379+ ///// ooooops
380+
380381 cdx = end - (numticks * p->inc);
381382
382383 i1 = ((cdx-1) < 0) ? 0 : cdx-1;
@@ -403,22 +404,51 @@ float tSampler_tick (tSampler* const sp) · 20 unmodified lines
403404 }
404405 g2 = (float) (cfxlen - numticks) / (float) cfxlen;
405406 }
407+
406408 }
407409 }
410+ else
411+ {
412+ g2 = 0.0f;
413+ }
414+
408415 }
409− else
410− {
411− g2 = 0.0f;
412− }
413−
416+
417+
414418
415419 float inc = fmod(p->inc, p->len);
416420 p->idx += (dir * inc);
417421
422+ //handle start and end cases for looping and back and forth modes
423+ if (p->mode == PlayLoop)
424+ {
418425
426+ while((int)p->idx < start)
427+ {
428+ p->idx += (float)(p->len);
429+ }
430+ while((int)p->idx > end)
431+ {
432+
433+ p->idx -= (float)(p->len);
434+ }
435+ }
436+ else // == PlayBackAndForth
437+ {
438+ if (p->idx < start)
439+ {
440+ p->bnf = -p->bnf;
441+ p->idx = start + 1;
442+ }
443+ else if (p->idx > end)
444+ {
445+ p->bnf = -p->bnf;
446+ p->idx = end - 1;
447+ }
448+ }
419449
420− // attemptStartEndChange(sp);
421450
451+ //handle very short fade out for end of one-shot normal playback
422452 if (p->mode == PlayNormal)
423453 {
424454 if (numticks < (0.007f * leaf.sampleRate))
@@ -463,11 +493,14 @@ float tSampler_tick (tSampler* const sp) · 38 unmodified lines
463493 }
464494 }
465495
496+ if (fabsf(sample-p->last) > 0.1f)
497+ {
498+ errorState = 1;
499+ }
466500
467501 p->last = sample;
468502
469503
470−
471504 return p->last;
472505 }
473506
@@ -532,11 +565,11 @@ void tSampler_stop (tSampler* const sp) · 58 unmodified lines
532565 static void handleStartEndChange(tSampler* const sp)
533566 {
534567 _tSampler* p = *sp;
535−
568+
536569 p->len = abs(p->end - p->start);
537570
538571 if (p->len < (p->cfxlen * 0.25f)) p->cfxlen = p->len * 0.25f;
539−
572+
540573 if (p->start > p->end)
541574 {
542575 p->flip = -1;
@@ -562,32 +595,6 @@ static void attemptStartEndChange(tSampler* const sp) · 19 unmodified lines
562595 }
563596 }
564597
565−static void updateStartEnd(tSampler* const sp)
566−{
567− _tSampler* p = *sp;
568−
569−
570−
571− if (p->targetstart >= 0)
572− {
573− if (p->targetstart != p->end)
574− {
575− p->start = p->targetstart;
576− handleStartEndChange(sp);
577− p->targetstart = -1;
578− }
579− }
580− if (p->targetend >= 0)
581− {
582− if (p->targetend != p->start)
583− {
584− p->end = p->targetend;
585− handleStartEndChange(sp);
586− p->targetend = -1;
587− }
588− }
589−}
590−
591598 void tSampler_setStart (tSampler* const sp, int32_t start)
592599 {
593600 _tSampler* p = *sp;
@@ -611,7 +618,7 @@ void tSampler_setStart (tSampler* const sp, int32_t start) · 17 unmodified lines
611618
612619 int dir = p->bnf * p->dir * tempflip;
613620 uint32_t cfxlen = (p->len < p->cfxlen) ? 0 : p->cfxlen;
614− if (tempflip > 0 && dir > 0) // start is start and we're playing forward
621+ if ((tempflip > 0) && (dir > 0)) // start is start and we're playing forward
615622 {
616623 if (((start > p->idx) || (p->end-p->idx <= cfxlen)) && (start > p->end))// start given is after current index or we're in a crossfade
617624 {
@@ -619,7 +626,7 @@ void tSampler_setStart (tSampler* const sp, int32_t start) · 1 unmodified line
619626 return;
620627 }
621628 }
622− else if (tempflip < 0 && dir < 0) // start is end and we're playing in reverse
629+ else if ((tempflip < 0) && (dir < 0)) // start is end and we're playing in reverse
623630 {
624631 if (((start < p->idx) || (p->idx-p->end <= cfxlen)) && (start < p->end))// start given is before current index or we're in a crossfade
625632 {
@@ -629,7 +636,7 @@ void tSampler_setStart (tSampler* const sp, int32_t start) · 3 unmodified lines
629636 }
630637 }
631638
632− p->start = LEAF_clipInt(0, start, p->samp->length - 1);
639+ p->start = LEAF_clipInt(0, start, p->samp->recordedLength - 1);
633640 handleStartEndChange(sp);
634641 p->targetstart = -1;
635642
@@ -676,7 +683,7 @@ void tSampler_setEnd (tSampler* const sp, int32_t end) · 40 unmodified lines
676683 }
677684 }
678685 }
679− p->end = LEAF_clipInt(0, end, (p->samp->length - 1));
686+ p->end = LEAF_clipInt(0, end, (p->samp->recordedLength - 1));
680687 handleStartEndChange(sp);
681688 p->targetend = -1;
682689 }
LEAF/Src/leaf.c+1−0
@@ -21,6 +21,7 @@ · 20 unmodified lines
2121 LEAF leaf;
2222
2323 void LEAF_init(float sr, int blocksize, char* memory, size_t memorysize, float(*random)(void))
24+
2425 {
2526 leaf_pool_init(memory, memorysize);
2627

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t