History

merge fix

Jeff Snyder committed 7 years ago

Commit ed50a402 parents 344bac3 53cc69a7 files · +135 −131Browse files

Unified · Split

7 files
  1. LEAF/Inc/leaf-crusher.h +1 −1
  2. LEAF/Inc/leaf-math.h +6 −1
  3. LEAF/Inc/leaf-mempool.h +3 −1
  4. LEAF/Src/leaf-crusher.c +1 −1
  5. LEAF/Src/leaf-delay.c +4 −6
  6. LEAF/Src/leaf-math.c +118 −121
  7. LEAF/leaf.h +2 −0
LEAF/Inc/leaf-crusher.h+1−1
@@ -61,4 +61,4 @@ void tCrusher_setSamplingRatio (tCrusher* const, float ratio); · 60 unmodified lines
6161
6262 #endif // LEAF_WAVEFOLDER_H_INCLUDED
6363
64−//==============================================================================
64+//==============================================================================
LEAF/Inc/leaf-math.h+6−1
@@ -19,6 +19,8 @@ extern "C" { · 18 unmodified lines
1919
2020 //==============================================================================
2121
22+//==============================================================================
23+
2224 typedef enum oBool
2325 {
2426 OTRUE = 1,
@@ -82,6 +84,10 @@ float LEAF_reduct (float input, float ratio); · 57 unmodified lines
8284 float LEAF_round (float input, float rnd);
8385 float LEAF_bitwise_xor(float input, uint32_t op);
8486
87+float LEAF_reduct (float input, float ratio);
88+float LEAF_round (float input, float rnd);
89+float LEAF_bitwise_xor(float input, uint32_t op);
90+
8591 float LEAF_clip (float min, float val, float max);
8692 int LEAF_clipInt (int min, int val, int max);
8793 float LEAF_softClip (float val, float thresh);
@@ -99,7 +105,6 @@ void LEAF_generate_square (float* buffer, float basefreq, int size); · 11 unmodified lines
99105 float LEAF_chebyshevT(float in, int n);
100106 float LEAF_CompoundChebyshevT(float in, int n, float* amps);
101107
102−
103108 // Hermite interpolation
104109 float LEAF_interpolate_hermite (float A, float B, float C, float D, float t);
105110 float LEAF_interpolation_linear (float A, float B, float t);
LEAF/Inc/leaf-mempool.h+3−1
@@ -50,7 +50,9 @@ extern "C" { · 49 unmodified lines
5050
5151 //==============================================================================
5252
53−#define MPOOL_POOL_SIZE 300000
53+
54+#define MPOOL_POOL_SIZE 500000
55+
5456 #define MPOOL_ALIGN_SIZE (8)
5557
5658 //#define size_t unsigned long
LEAF/Src/leaf-crusher.c+1−1
@@ -81,4 +81,4 @@ void tCrusher_setRound (tCrusher* const c, float rnd) · 80 unmodified lines
8181 void tCrusher_setSamplingRatio (tCrusher* const c, float ratio)
8282 {
8383 c->srr = ratio;
84−}
84+}
LEAF/Src/leaf-delay.c+4−6
@@ -437,8 +437,6 @@ float tDelayA_getGain (tDelayA* const d) · 436 unmodified lines
437437 void tTapeDelay_init (tTapeDelay* const d, float delay, uint32_t maxDelay)
438438 {
439439 d->maxDelay = maxDelay;
440−
441− d->delay = LEAF_clip(1.f, delay, d->maxDelay);
442440
443441 d->buff = (float*) leaf_alloc(sizeof(float) * maxDelay);
444442
@@ -451,7 +449,7 @@ void tTapeDelay_init (tTapeDelay* const d, float delay, uint32_t maxDelay) · 6 unmodified lines
451449 d->inc = 1.0f;
452450 d->inPoint = 0;
453451
454− tTapeDelay_setDelay(d, 1.f);
452+ tTapeDelay_setDelay(d, delay);
455453 }
456454
457455 void tTapeDelay_free(tTapeDelay* const d)
@@ -462,7 +460,7 @@ void tTapeDelay_free(tTapeDelay* const d) · 4 unmodified lines
462460
463461 int count = 0;
464462
465−#define SMOOTH_FACTOR 10.f
463+//#define SMOOTH_FACTOR 10.f
466464
467465 float tTapeDelay_tick (tTapeDelay* const d, float input)
468466 {
@@ -483,11 +481,11 @@ float tTapeDelay_tick (tTapeDelay* const d, float input) · 14 unmodified lines
483481 float diff = (d->inPoint - d->idx);
484482 while (diff < 0.f) diff += d->maxDelay;
485483
486− d->inc = 1.0f + (diff - d->delay) / d->delay * SMOOTH_FACTOR;
484+ d->inc = 1.0f + (diff - d->delay) / d->delay; //* SMOOTH_FACTOR;
487485
488486 d->idx += d->inc;
489487
490− if (d->idx >= d->maxDelay) d->idx = 0.f;
488+ if (d->idx >= d->maxDelay) d->idx = 0.0f;
491489
492490 return d->lastOut;
493491 }
LEAF/Src/leaf-math.c+118−121
@@ -21,8 +21,7 @@ · 20 unmodified lines
2121 // The C-embedded Audio Library.
2222 #define TWO_TO_16 65536.f
2323
24−#define EXPONENTIAL_TABLE_SIZE 65536
25−
24+#define EXPONENTIAL_TABLE_SIZE 65536
2625
2726 float interpolate3max(float *buf, const int peakindex)
2827 {
@@ -71,7 +70,7 @@ float fastabs(float f) · 42 unmodified lines
7170
7271 alias.f = f;
7372 alias.ui &= 0x7fffffff;
74− return alias.f;
73+ return alias.f;
7574 }
7675
7776 // dope af
@@ -207,8 +206,7 @@ int LEAF_clipInt(int min, int val, int max) · 129 unmodified lines
207206 } else {
208207 return val;
209208 }
210−}
211−
209+}
212210
213211 oBool LEAF_isPrime(uint64_t number )
214212 {
@@ -232,91 +230,91 @@ float LEAF_tanh(float x) · 17 unmodified lines
232230 else
233231 return x * ( 27 + x * x ) / ( 27 + 9 * x * x );
234232 }
235−
236−
237−void LEAF_generate_sine(float* buffer, int size)
238−{
239− float phase;
240− for (int i = 0; i < size; i++)
241− {
242− phase = (float) i / (float) size;
243− buffer[i] = sinf(phase * TWO_PI);
244− }
245−}
246−
247−void LEAF_generate_sawtooth(float* buffer, float basefreq, int size)
248−{
249− int harmonic = 1;
250− float phase = 0.0f;
251− float freq = harmonic * basefreq;
252− float amp;
253−
254− while (freq < (leaf.sampleRate * 0.5))
255− {
256− amp = 1.0f / harmonic;
257− for (int i = 0; i < size; i++)
258− {
259− phase = (float) i / (float) size;
260− buffer[i] += (amp * sinf(harmonic * phase * TWO_PI));
261− }
262−
263− harmonic++;
264− freq = harmonic * basefreq;
265− }
266−}
267−
268−
269−void LEAF_generate_triangle(float* buffer, float basefreq, int size)
270−{
271− int harmonic = 1;
272− float phase = 0.0f;
273− float freq = harmonic * basefreq;
274− float amp = 1.0f;
275−
276− int count = 0;
277− float mult = 1.0f;
278−
279− while (freq < (leaf.sampleRate * 0.5))
280− {
281− amp = 1.0f / (float)(harmonic * harmonic);
282−
283− if (count % 2) mult = -1.0f;
284− else mult = 1.0f;
285−
286− for (int i = 0; i < size; i++)
287− {
288− phase = (float) i / (float) size;
289− buffer[i] += (mult * amp * sinf(harmonic * phase * TWO_PI));
290− }
291−
292− count++;
293− harmonic += 2;
294− freq = harmonic * basefreq;
295− }
296−}
297−
298−void LEAF_generate_square(float* buffer, float basefreq, int size)
299−{
300− int harmonic = 1;
301− float phase = 0.0f;
302− float freq = harmonic * basefreq;
303− float amp = 1.0f;
304−
305− while (freq < (leaf.sampleRate * 0.5))
306− {
307− amp = 1.0f / (float)(harmonic);
308−
309− for (int i = 0; i < size; i++)
310− {
311− phase = (float) i / (float) size;
312− buffer[i] += (amp * sinf(harmonic * phase * TWO_PI));
313− }
314−
315− harmonic += 2;
316− freq = harmonic * basefreq;
317− }
318−}
319−
233+
234+
235+void LEAF_generate_sine(float* buffer, int size)
236+{
237+ float phase;
238+ for (int i = 0; i < size; i++)
239+ {
240+ phase = (float) i / (float) size;
241+ buffer[i] = sinf(phase * TWO_PI);
242+ }
243+}
244+
245+void LEAF_generate_sawtooth(float* buffer, float basefreq, int size)
246+{
247+ int harmonic = 1;
248+ float phase = 0.0f;
249+ float freq = harmonic * basefreq;
250+ float amp;
251+
252+ while (freq < (leaf.sampleRate * 0.5))
253+ {
254+ amp = 1.0f / harmonic;
255+ for (int i = 0; i < size; i++)
256+ {
257+ phase = (float) i / (float) size;
258+ buffer[i] += (amp * sinf(harmonic * phase * TWO_PI));
259+ }
260+
261+ harmonic++;
262+ freq = harmonic * basefreq;
263+ }
264+}
265+
266+
267+void LEAF_generate_triangle(float* buffer, float basefreq, int size)
268+{
269+ int harmonic = 1;
270+ float phase = 0.0f;
271+ float freq = harmonic * basefreq;
272+ float amp = 1.0f;
273+
274+ int count = 0;
275+ float mult = 1.0f;
276+
277+ while (freq < (leaf.sampleRate * 0.5))
278+ {
279+ amp = 1.0f / (float)(harmonic * harmonic);
280+
281+ if (count % 2) mult = -1.0f;
282+ else mult = 1.0f;
283+
284+ for (int i = 0; i < size; i++)
285+ {
286+ phase = (float) i / (float) size;
287+ buffer[i] += (mult * amp * sinf(harmonic * phase * TWO_PI));
288+ }
289+
290+ count++;
291+ harmonic += 2;
292+ freq = harmonic * basefreq;
293+ }
294+}
295+
296+void LEAF_generate_square(float* buffer, float basefreq, int size)
297+{
298+ int harmonic = 1;
299+ float phase = 0.0f;
300+ float freq = harmonic * basefreq;
301+ float amp = 1.0f;
302+
303+ while (freq < (leaf.sampleRate * 0.5))
304+ {
305+ amp = 1.0f / (float)(harmonic);
306+
307+ for (int i = 0; i < size; i++)
308+ {
309+ phase = (float) i / (float) size;
310+ buffer[i] += (amp * sinf(harmonic * phase * TWO_PI));
311+ }
312+
313+ harmonic += 2;
314+ freq = harmonic * basefreq;
315+ }
316+}
317+
320318
321319 //-----------------------------------------------------------------------------
322320 // name: mtof()
@@ -326,35 +324,34 @@ float LEAF_midiToFrequency(float f) · 3 unmodified lines
326324 {
327325 if( f <= -1500.0f ) return (0);
328326 else if( f > 1499.0f ) return (LEAF_midiToFrequency(1499.0f));
329− else return ( powf(2.0f, (f - 69.0f) / 12.0f) * 440.0f );
330−}
331−
332−
333−// alpha, [0.0, 1.0]
334−float LEAF_interpolate_hermite (float A, float B, float C, float D, float alpha)
335−{
336− alpha = LEAF_clip(0.0f, alpha, 1.0f);
337−
338− float a = -A/2.0f + (3.0f*B)/2.0f - (3.0f*C)/2.0f + D/2.0f;
339− float b = A - (5.0f*B)/2.0f + 2.0f*C - D / 2.0f;
340− float c = -A/2.0f + C/2.0f;
341− float d = B;
342−
343− return a*alpha*alpha*alpha + b*alpha*alpha + c*alpha + d;
344−}
345−
346−// alpha, [0.0, 1.0]
347−float LEAF_interpolation_linear (float A, float B, float alpha)
348−{
349− alpha = LEAF_clip(0.0f, alpha, 1.0f);
350−
351− float omAlpha = 1.0f - alpha;
352−
353− // First 1/2 of interpolation
354− float out = A * omAlpha;
355−
356− out += B * alpha;
357−
358− return out;
359−}
327+ else return ( powf(2.0f, (f - 69.0f) * 0.083333333333333f) * 440.0f );
328+}
329+
330+
331+// alpha, [0.0, 1.0]
332+float LEAF_interpolate_hermite (float A, float B, float C, float D, float alpha)
333+{
334+ alpha = LEAF_clip(0.0f, alpha, 1.0f);
335+
336+ float a = -A/2.0f + (3.0f*B)/2.0f - (3.0f*C)/2.0f + D/2.0f;
337+ float b = A - (5.0f*B)/2.0f + 2.0f*C - D / 2.0f;
338+ float c = -A/2.0f + C/2.0f;
339+ float d = B;
340+
341+ return a*alpha*alpha*alpha + b*alpha*alpha + c*alpha + d;
342+}
343+
344+// alpha, [0.0, 1.0]
345+float LEAF_interpolation_linear (float A, float B, float alpha)
346+{
347+ alpha = LEAF_clip(0.0f, alpha, 1.0f);
348+
349+ float omAlpha = 1.0f - alpha;
350+
351+ // First 1/2 of interpolation
352+ float out = A * omAlpha;
360353
354+ out += B * alpha;
355+
356+ return out;
357+}
LEAF/leaf.h+2−0
@@ -37,6 +37,7 @@ · 36 unmodified lines
3737 #include ".\Inc\leaf-crusher.h"
3838 #include ".\Inc\leaf-wavefolder.h"
3939 #include ".\Inc\leaf-wavetables.h"
40+#include ".\Inc\leaf-crusher.h"
4041
4142 #else
4243
@@ -58,6 +59,7 @@ · 15 unmodified lines
5859 #include "./Inc/leaf-crusher.h"
5960 #include "./Inc/leaf-wavefolder.h"
6061 #include "./Inc/leaf-wavetables.h"
62+#include "./Inc/leaf-crusher.h"
6163
6264 #endif
6365

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