History

Sampler fixes.

mulshine committed 7 years ago

Commit cb6284e1 parent 1bd52d63 files · +99 −115Browse files

Unified · Split

3 files
  1. LEAF/Src/leaf-sample.c +46 −45
  2. LEAF_JUCEPlugin/Source/LEAFLink.cpp +3 −4
  3. LEAF_JUCEPlugin/Source/MyTest.cpp +50 −66
LEAF/Src/leaf-sample.c+46−45
@@ -162,7 +162,7 @@ float tSampler_tick (tSampler* const p) · 161 unmodified lines
162162 }
163163 else
164164 {
165− idx = (int) (p->idx + 1.f); // we think this is because flooring on int works different when reading backwards
165+ idx = (int) (p->idx+1.f); // we think this is because flooring on int works different when reading backwards
166166 alpha = (p->idx+1.f) - idx;
167167 }
168168
@@ -173,51 +173,52 @@ float tSampler_tick (tSampler* const p) · 4 unmodified lines
173173 end = p->start;
174174 }
175175
176− // Check dir (direction) to interpolate properly
177− if (dir > 0)
178− {
179− // FORWARD NORMAL SAMPLE
180− int i1 = idx-1;
181− int i3 = idx+1;
182− int i4 = idx+2;
183−
184− sample = LEAF_interpolate_hermite (buff[i1],
185− buff[idx],
186− buff[i3],
187− buff[i4],
188− alpha);
189−
190− // num samples to end of loop
191− numsamps = (dir > 0) ? (end - idx) : (idx - start);
192− numsamps *= p->iinc;
193−
194− if (p->mode == PlayLoop)
195− {
196− if (numsamps <= p->cfxlen)
197− {
198− // CROSSFADE SAMPLE
199− float idxx = p->idx - p->len;
200− int cdx = (int)(idxx);
201−
202− i1 = cdx-1;
203− i3 = cdx+1;
204− i4 = cdx+2;
205−
206− cfxsample = LEAF_interpolate_hermite (buff[i1],
207− buff[cdx],
208− buff[i3],
209− buff[i4],
210− alpha);
211−
212− g2 = (float) (p->cfxlen - numsamps) / (float) p->cfxlen;
213− }
214− }
215− }
216− else
176+ // Check dir (direction) to interpolate properly
177+ if (dir > 0)
178+ {
179+ // FORWARD NORMAL SAMPLE
180+ int i1 = idx-1;
181+ int i3 = idx+1;
182+ int i4 = idx+2;
183+
184+ sample = LEAF_interpolate_hermite (buff[i1],
185+ buff[idx],
186+ buff[i3],
187+ buff[i4],
188+ alpha);
189+
190+ // num samples to end of loop
191+ numsamps = (idx - start) / p->inc;
192+ //numsamps = (dir > 0) ? (end - idx) : (idx - start);
193+ //numsamps *= p->iinc;
194+
195+ if (p->mode == PlayLoop)
196+ {
197+ if (numsamps <= p->cfxlen)
198+ {
199+ // CROSSFADE SAMPLE
200+ float idxx = p->idx - p->len;
201+ int cdx = (int)(idxx);
202+
203+ i1 = cdx-1;
204+ i3 = cdx+1;
205+ i4 = cdx+2;
206+
207+ cfxsample = LEAF_interpolate_hermite (buff[i1],
208+ buff[cdx],
209+ buff[i3],
210+ buff[i4],
211+ alpha);
212+
213+ g2 = (float) (p->cfxlen - numsamps) / (float) p->cfxlen;
214+ }
215+ }
216+ }
217+ else
217218 {
218− // REVERSE
219− int i1 = idx+1;
220− int i3 = idx-1;
219+ // REVERSE
220+ int i1 = idx+1;
221+ int i3 = idx-1;
221222 int i4 = idx-2;
222223
223224 sample = LEAF_interpolate_hermite (buff[i1],
LEAF_JUCEPlugin/Source/LEAFLink.cpp+3−4
@@ -15,14 +15,13 @@ · 14 unmodified lines
1515
1616 std::vector<juce::String> cButtonNames = std::vector<juce::String>
1717 {
18−
18+ "record"
1919 };
2020
2121 std::vector<juce::String> cSliderNames = std::vector<juce::String>
2222 {
23− "delay",
24− "feedback",
25− "mix"
23+ "mod freq",
24+ "mod depth"
2625 };
2726
2827 std::vector<juce::String> cComboBoxNames = std::vector<juce::String>
LEAF_JUCEPlugin/Source/MyTest.cpp+50−66
@@ -21,99 +21,83 @@ float fx = 1.f; · 20 unmodified lines
2121
2222 #define NUM_GRAINS 20
2323
24−tBuffer buff;
25−tSampler samp[NUM_GRAINS];
24+
2625
2726 tTapeDelay delay;
2827
2928 float feedback = 0.f;
3029
30+tBuffer buff;
31+tSampler samp;
32+
33+tCycle osc;
3134
3235 void LEAFTest_init (float sampleRate, int blockSize)
3336 {
3437 LEAF_init(sampleRate, blockSize, &getRandomFloat);
3538
36− // Init and set record loop
37− tBuffer_init (&buff, leaf.sampleRate * 1.f); // 0.5-second buffers
38− tBuffer_setRecordMode (&buff, RecordLoop);
39− tBuffer_record(&buff);
40−
41− for (int i = 0; i < NUM_GRAINS; i++)
42− {
43− // Init and set play loop
44− tSampler_init (&samp[i], &buff);
45− tSampler_setMode (&samp[i], PlayLoop);
39+ // Init and set record
40+ tBuffer_init (&buff, leaf.sampleRate * 1.f); // init, 1 second buffer
41+ tBuffer_setRecordMode (&buff, RecordOneShot); // RecordOneShot records once through
42+ tBuffer_record(&buff); // starts recording
4643
47− /*
48− float speed = ((getRandomFloat() < 0.5f) ? 0.5f : 1.f);
49− float dir = (getRandomFloat() < 0.5f) ? -1 : 1;
50−
51− tSampler_setRate(&samp[i], speed * dir);
52− */
53−
54− tSampler_setRate(&samp[i], 1.f);
55−
56− // Record and play
57− tSampler_play(&samp[i]);
58− }
59−
60− tTapeDelay_init(&delay, leaf.sampleRate * 0.05f, leaf.sampleRate * 1.f); // 1 second delay, starts out at 50 ms
44+ // Init and set play
45+ tSampler_init (&samp, &buff); // init, give address of record buffer
46+ tSampler_setMode (&samp, PlayLoop); //set in Loop Mode
47+ tSampler_setRate(&samp, 1.f); // Rate of 1.0
48+ tSampler_play(&samp); // start spitting samples out
49+
50+ tCycle_init(&osc);
6151
6252 leaf_pool_report();
63−}
64−
65−int timer = 0;
66−
67−float lastOut;
53+}
54+
55+float depth = 1.0f;
6856
6957 float LEAFTest_tick (float input)
7058 {
7159 float sample = 0.f;
7260
73− tBuffer_tick(&buff, input);
74−
75− for (int i = 0; i < NUM_GRAINS; i++)
61+ tBuffer_tick(&buff, input); // ticking the buffer records in to buffer
62+
63+ tSampler_setRate(&samp, tCycle_tick(&osc) * depth);
64+
65+ // dont tick sampler if buffer not active (not recording)
66+ if (buff.active == 0)
7667 {
77− sample += tSampler_tick(&samp[i]);
68+ sample = tSampler_tick(&samp); // ticking sampler loops sample
7869 }
7970
80− sample /= NUM_GRAINS;
81−
82− sample = tTapeDelay_tick(&delay, (1.f - feedback) * sample + feedback * lastOut);
8371
84− lastOut = sample;
85−
86− return (sample * mix) +
87− (input * (1.f - mix));
72+ return sample;
8873 }
8974
9075 bool lastState = false, lastPlayState = false;
9176 void LEAFTest_block (void)
9277 {
93− float val = getSliderValue("mix");
94−
95− mix = val;
96−
97− val = getSliderValue("delay");
98−
99− tTapeDelay_setDelay(&delay, val * leaf.sampleRate);
100−
101− val = getSliderValue("feedback");
102−
103− feedback = val;
104−
105− for (int i = 0; i < NUM_GRAINS; i++)
106− {
107− if (getRandomFloat() < 0.01f)
108− {
109− tSampler_setStart(&samp[i], leaf.sampleRate * 0.05f + leaf.sampleRate * getRandomFloat() * 0.95f);
110−
111− uint64_t end = (leaf.sampleRate * 0.05f + getRandomFloat() * leaf.sampleRate * 0.45f + samp[i].start);
112−
113− tSampler_setEnd(&samp[i], end % buff.length); // 10 - 1010 ms
114− }
115− }
116−
78+ bool state = getButtonState("record");
79+
80+ if (state)
81+ {
82+ setButtonState("record", false);
83+ tBuffer_record(&buff);
84+ }
85+
86+ float val = getSliderValue("mod freq");
87+
88+ float freq = 0.1 + 999.9 * val;
89+
90+ tCycle_setFreq(&osc, freq);
91+
92+ DBG("mod freq: " + String(freq));
93+
94+ val = getSliderValue("mod depth");
95+
96+ depth = 0.1 + val * 15.9f;
97+
98+ DBG("mod depth: " + String(depth));
99+
100+
117101 }
118102
119103 void LEAFTest_controllerInput (int cnum, float cval)

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