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
162 }162 }
163 else163 else
164 {164 {
165 idx = (int) (p->idx + 1.f); // we think this is because flooring on int works different when reading backwards165 idx = (int) (p->idx+1.f); // we think this is because flooring on int works different when reading backwards
166 alpha = (p->idx+1.f) - idx;166 alpha = (p->idx+1.f) - idx;
167 }167 }
168 168
@@ -173,51 +173,52 @@ float tSampler_tick (tSampler* const p) · 4 unmodified lines
173 end = p->start;173 end = p->start;
174 }174 }
175 175
176 // Check dir (direction) to interpolate properly176 // Check dir (direction) to interpolate properly
177 if (dir > 0)177 if (dir > 0)
178 {178 {
179 // FORWARD NORMAL SAMPLE179 // FORWARD NORMAL SAMPLE
180 int i1 = idx-1;180 int i1 = idx-1;
181 int i3 = idx+1;181 int i3 = idx+1;
182 int i4 = idx+2;182 int i4 = idx+2;
183 183
184 sample = LEAF_interpolate_hermite (buff[i1],184 sample = LEAF_interpolate_hermite (buff[i1],
185 buff[idx],185 buff[idx],
186 buff[i3],186 buff[i3],
187 buff[i4],187 buff[i4],
188 alpha);188 alpha);
189 189
190 // num samples to end of loop190 // num samples to end of loop
191 numsamps = (dir > 0) ? (end - idx) : (idx - start);191 numsamps = (idx - start) / p->inc;
192 numsamps *= p->iinc;192 //numsamps = (dir > 0) ? (end - idx) : (idx - start);
193 193 //numsamps *= p->iinc;
194 if (p->mode == PlayLoop)194
195 {195 if (p->mode == PlayLoop)
196 if (numsamps <= p->cfxlen)196 {
197 {197 if (numsamps <= p->cfxlen)
198 // CROSSFADE SAMPLE198 {
199 float idxx = p->idx - p->len;199 // CROSSFADE SAMPLE
200 int cdx = (int)(idxx);200 float idxx = p->idx - p->len;
201 201 int cdx = (int)(idxx);
202 i1 = cdx-1;202
203 i3 = cdx+1;203 i1 = cdx-1;
204 i4 = cdx+2;204 i3 = cdx+1;
205 205 i4 = cdx+2;
206 cfxsample = LEAF_interpolate_hermite (buff[i1],206
207 buff[cdx],207 cfxsample = LEAF_interpolate_hermite (buff[i1],
208 buff[i3],208 buff[cdx],
209 buff[i4],209 buff[i3],
210 alpha);210 buff[i4],
211 211 alpha);
212 g2 = (float) (p->cfxlen - numsamps) / (float) p->cfxlen;212
213 }213 g2 = (float) (p->cfxlen - numsamps) / (float) p->cfxlen;
214 }214 }
215 }215 }
216 else216 }
217 else
217 {218 {
218 // REVERSE219 // REVERSE
219 int i1 = idx+1;220 int i1 = idx+1;
220 int i3 = idx-1;221 int i3 = idx-1;
221 int i4 = idx-2;222 int i4 = idx-2;
222 223
223 sample = LEAF_interpolate_hermite (buff[i1],224 sample = LEAF_interpolate_hermite (buff[i1],
LEAF_JUCEPlugin/Source/LEAFLink.cpp+3−4
@@ -15,14 +15,13 @@ · 14 unmodified lines
15 15
16std::vector<juce::String> cButtonNames = std::vector<juce::String>16std::vector<juce::String> cButtonNames = std::vector<juce::String>
17{17{
18 18 "record"
19};19};
20 20
21std::vector<juce::String> cSliderNames = std::vector<juce::String>21std::vector<juce::String> cSliderNames = std::vector<juce::String>
22{22{
23 "delay",23 "mod freq",
24 "feedback",24 "mod depth"
25 "mix"
26};25};
27 26
28std::vector<juce::String> cComboBoxNames = std::vector<juce::String>27std::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
21 21
22#define NUM_GRAINS 2022#define NUM_GRAINS 20
23 23
24tBuffer buff;24
25tSampler samp[NUM_GRAINS];
26 25
27tTapeDelay delay;26tTapeDelay delay;
28 27
29float feedback = 0.f;28float feedback = 0.f;
30 29
30tBuffer buff;
31tSampler samp;
32
33tCycle osc;
31 34
32void LEAFTest_init (float sampleRate, int blockSize)35void LEAFTest_init (float sampleRate, int blockSize)
33{36{
34 LEAF_init(sampleRate, blockSize, &getRandomFloat);37 LEAF_init(sampleRate, blockSize, &getRandomFloat);
35 38
36 // Init and set record loop39 // Init and set record
37 tBuffer_init (&buff, leaf.sampleRate * 1.f); // 0.5-second buffers40 tBuffer_init (&buff, leaf.sampleRate * 1.f); // init, 1 second buffer
38 tBuffer_setRecordMode (&buff, RecordLoop);41 tBuffer_setRecordMode (&buff, RecordOneShot); // RecordOneShot records once through
39 tBuffer_record(&buff);42 tBuffer_record(&buff); // starts recording
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);
46 43
47 /*44 // Init and set play
48 float speed = ((getRandomFloat() < 0.5f) ? 0.5f : 1.f);45 tSampler_init (&samp, &buff); // init, give address of record buffer
49 float dir = (getRandomFloat() < 0.5f) ? -1 : 1;46 tSampler_setMode (&samp, PlayLoop); //set in Loop Mode
50 47 tSampler_setRate(&samp, 1.f); // Rate of 1.0
51 tSampler_setRate(&samp[i], speed * dir);48 tSampler_play(&samp); // start spitting samples out
52 */49
53 50 tCycle_init(&osc);
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
61 51
62 leaf_pool_report();52 leaf_pool_report();
63}53}
64 54
65int timer = 0;55float depth = 1.0f;
66
67float lastOut;
68 56
69float LEAFTest_tick (float input)57float LEAFTest_tick (float input)
70{58{
71 float sample = 0.f;59 float sample = 0.f;
72 60
73 tBuffer_tick(&buff, input);61 tBuffer_tick(&buff, input); // ticking the buffer records in to buffer
74 62
75 for (int i = 0; i < NUM_GRAINS; i++)63 tSampler_setRate(&samp, tCycle_tick(&osc) * depth);
64
65 // dont tick sampler if buffer not active (not recording)
66 if (buff.active == 0)
76 {67 {
77 sample += tSampler_tick(&samp[i]);68 sample = tSampler_tick(&samp); // ticking sampler loops sample
78 }69 }
79 70
80 sample /= NUM_GRAINS;
81
82 sample = tTapeDelay_tick(&delay, (1.f - feedback) * sample + feedback * lastOut);
83 71
84 lastOut = sample;72 return sample;
85
86 return (sample * mix) +
87 (input * (1.f - mix));
88}73}
89 74
90bool lastState = false, lastPlayState = false;75bool lastState = false, lastPlayState = false;
91void LEAFTest_block (void)76void LEAFTest_block (void)
92{77{
93 float val = getSliderValue("mix");78 bool state = getButtonState("record");
94 79
95 mix = val;80 if (state)
96 81 {
97 val = getSliderValue("delay");82 setButtonState("record", false);
98 83 tBuffer_record(&buff);
99 tTapeDelay_setDelay(&delay, val * leaf.sampleRate);84 }
100 85
101 val = getSliderValue("feedback");86 float val = getSliderValue("mod freq");
102 87
103 feedback = val;88 float freq = 0.1 + 999.9 * val;
104 89
105 for (int i = 0; i < NUM_GRAINS; i++)90 tCycle_setFreq(&osc, freq);
106 {91
107 if (getRandomFloat() < 0.01f)92 DBG("mod freq: " + String(freq));
108 {93
109 tSampler_setStart(&samp[i], leaf.sampleRate * 0.05f + leaf.sampleRate * getRandomFloat() * 0.95f);94 val = getSliderValue("mod depth");
110 95
111 uint64_t end = (leaf.sampleRate * 0.05f + getRandomFloat() * leaf.sampleRate * 0.45f + samp[i].start);96 depth = 0.1 + val * 15.9f;
112 97
113 tSampler_setEnd(&samp[i], end % buff.length); // 10 - 1010 ms98 DBG("mod depth: " + String(depth));
114 }99
115 }100
116
117}101}
118 102
119void LEAFTest_controllerInput (int cnum, float cval)103void 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