Unified · Split
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | /*============================================================================== |
| 2 | 2 | |
| 3 | − leaf_808.h | |
| 3 | + leaf-808.h | |
| 4 | 4 | Created: 30 Nov 2018 10:24:44am |
| 5 | 5 | Author: airship |
| 6 | 6 | |
| @@ -0,0 +1,64 @@ | ||
| 1 | +/* | |
| 2 | + ============================================================================== | |
| 3 | + | |
| 4 | + leaf-crusher.h | |
| 5 | + Created: 7 Feb 2019 10:58:22am | |
| 6 | + Author: airship | |
| 7 | + | |
| 8 | + ============================================================================== | |
| 9 | +*/ | |
| 10 | + | |
| 11 | +#ifndef LEAF_CRUSHER_H_INCLUDED | |
| 12 | +#define LEAF_CRUSHER_H_INCLUDED | |
| 13 | + | |
| 14 | + | |
| 15 | +#ifdef __cplusplus | |
| 16 | +extern "C" { | |
| 17 | +#endif | |
| 18 | + | |
| 19 | +//============================================================================== | |
| 20 | + | |
| 21 | +#include "leaf-globals.h" | |
| 22 | +#include "leaf-math.h" | |
| 23 | + | |
| 24 | +//============================================================================== | |
| 25 | + | |
| 26 | +typedef struct _tCrusher | |
| 27 | +{ | |
| 28 | + float srr; | |
| 29 | + float mult, div; | |
| 30 | + float rnd; | |
| 31 | + | |
| 32 | + uint32_t op; //which bitwise operation (0-7) | |
| 33 | + | |
| 34 | + float gain; | |
| 35 | + | |
| 36 | +} tCrusher; | |
| 37 | + | |
| 38 | + | |
| 39 | +void tCrusher_init (tCrusher* const); | |
| 40 | +void tCrusher_free (tCrusher* const); | |
| 41 | + | |
| 42 | +float tCrusher_tick (tCrusher* const, float input); | |
| 43 | + | |
| 44 | +// 0-7 | |
| 45 | +void tCrusher_setOperation (tCrusher* const, uint32_t op); | |
| 46 | + | |
| 47 | +// 0.0 - 1.0 | |
| 48 | +void tCrusher_setQuality (tCrusher* const, float val); | |
| 49 | + | |
| 50 | +// what division to round to | |
| 51 | +void tCrusher_setRound (tCrusher* const, float rnd); | |
| 52 | + | |
| 53 | +// sampling ratio | |
| 54 | +void tCrusher_setSamplingRatio (tCrusher* const, float ratio); | |
| 55 | + | |
| 56 | +//============================================================================== | |
| 57 | + | |
| 58 | +#ifdef __cplusplus | |
| 59 | +} | |
| 60 | +#endif | |
| 61 | + | |
| 62 | +#endif // LEAF_WAVEFOLDER_H_INCLUDED | |
| 63 | + | |
| 64 | +//============================================================================== | |
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | /*============================================================================== |
| 2 | 2 | |
| 3 | − LEAFDelay.h | |
| 3 | + leaf-delay.h | |
| 4 | 4 | Created: 20 Jan 2017 12:01:24pm |
| 5 | 5 | Author: Michael R Mulshine |
| 6 | 6 | |
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | /*============================================================================== |
| 2 | 2 | |
| 3 | − LEAFFilter.h | |
| 3 | + leaf-filter.h | |
| 4 | 4 | Created: 20 Jan 2017 12:01:10pm |
| 5 | 5 | Author: Michael R Mulshine |
| 6 | 6 | |
| @@ -60,6 +60,11 @@ extern const float shaper1[SHAPER1_TABLE_SIZE]; · 59 unmodified lines | ||
| 60 | 60 | #define TALKBOX_BUFFER_LENGTH 1600 // Every talkbox instance introduces 5 buffers of this size |
| 61 | 61 | |
| 62 | 62 | |
| 63 | +union unholy_t { /* a union between a float and an integer */ | |
| 64 | + float f; | |
| 65 | + int i; | |
| 66 | +}; | |
| 67 | + | |
| 63 | 68 | //============================================================================== |
| 64 | 69 | |
| 65 | 70 | #ifdef __cplusplus |
| @@ -1,22 +1,22 @@ | ||
| 1 | 1 | /*============================================================================== |
| 2 | 2 | |
| 3 | − LEAFMath.h | |
| 3 | + leaf-math.h | |
| 4 | 4 | Created: 22 Jan 2017 7:02:56pm |
| 5 | 5 | Author: Michael R Mulshine |
| 6 | 6 | |
| 7 | 7 | ==============================================================================*/ |
| 8 | 8 | |
| 9 | 9 | #ifndef LEAF_MATH_H_INCLUDED |
| 10 | −#define LEAF_MATH_H_INCLUDED | |
| 11 | − | |
| 12 | −#ifdef __cplusplus | |
| 13 | −extern "C" { | |
| 10 | +#define LEAF_MATH_H_INCLUDED | |
| 11 | + | |
| 12 | +#ifdef __cplusplus | |
| 13 | +extern "C" { | |
| 14 | 14 | #endif |
| 15 | 15 | |
| 16 | 16 | #include "math.h" |
| 17 | 17 | #include "stdint.h" |
| 18 | −#include "stdlib.h" | |
| 19 | − | |
| 18 | +#include "stdlib.h" | |
| 19 | + | |
| 20 | 20 | //============================================================================== |
| 21 | 21 | |
| 22 | 22 | typedef enum oBool |
| @@ -76,47 +76,51 @@ typedef enum oBool · 53 unmodified lines | ||
| 76 | 76 | |
| 77 | 77 | // Jones shaper |
| 78 | 78 | float LEAF_shaper (float input, float m_drive); |
| 79 | −float LEAF_reedTable (float input, float offset, float slope); | |
| 79 | +float LEAF_reedTable (float input, float offset, float slope); | |
| 80 | + | |
| 81 | +float LEAF_reduct (float input, float srr); | |
| 82 | +float LEAF_round (float input, float rnd); | |
| 83 | +float LEAF_bitwise_or(float input, uint32_t op); | |
| 80 | 84 | |
| 81 | −float LEAF_clip (float min, float val, float max); | |
| 85 | +float LEAF_clip (float min, float val, float max); | |
| 82 | 86 | int LEAF_clipInt (int min, int val, int max); |
| 83 | 87 | float LEAF_softClip (float val, float thresh); |
| 84 | −oBool LEAF_isPrime (uint64_t number ); | |
| 85 | − | |
| 86 | −float LEAF_midiToFrequency (float f); | |
| 87 | −float LEAF_frequencyToMidi(float f); | |
| 88 | − | |
| 89 | −void LEAF_generate_sine (float* buffer, int size); | |
| 90 | −void LEAF_generate_sawtooth (float* buffer, float basefreq, int size); | |
| 91 | −void LEAF_generate_triangle (float* buffer, float basefreq, int size); | |
| 88 | +oBool LEAF_isPrime (uint64_t number ); | |
| 89 | + | |
| 90 | +float LEAF_midiToFrequency (float f); | |
| 91 | +float LEAF_frequencyToMidi(float f); | |
| 92 | + | |
| 93 | +void LEAF_generate_sine (float* buffer, int size); | |
| 94 | +void LEAF_generate_sawtooth (float* buffer, float basefreq, int size); | |
| 95 | +void LEAF_generate_triangle (float* buffer, float basefreq, int size); | |
| 92 | 96 | void LEAF_generate_square (float* buffer, float basefreq, int size); |
| 93 | 97 | |
| 94 | 98 | // dope af |
| 95 | 99 | float LEAF_chebyshevT(float in, int n); |
| 96 | 100 | float LEAF_CompoundChebyshevT(float in, int n, float* amps); |
| 97 | − | |
| 98 | − | |
| 99 | −// Hermite interpolation | |
| 100 | −float LEAF_interpolate_hermite (float A, float B, float C, float D, float t); | |
| 101 | −float LEAF_interpolation_linear (float A, float B, float t); | |
| 102 | − | |
| 103 | −float interpolate3max(float *buf, const int peakindex); | |
| 104 | −float interpolate3phase(float *buf, const int peakindex); | |
| 105 | − | |
| 106 | −// alternative implementation for abs() | |
| 107 | −// REQUIRES: 32 bit integers | |
| 108 | −int fastabs_int(int in); | |
| 109 | − | |
| 110 | −// alternative implementation for abs() | |
| 111 | −// REQUIRES: 32 bit floats | |
| 112 | −float fastabs(float f); | |
| 113 | − | |
| 114 | −//============================================================================== | |
| 115 | − | |
| 116 | −#ifdef __cplusplus | |
| 117 | −} | |
| 118 | −#endif | |
| 119 | 101 | |
| 120 | −#endif // LEAF_MATH_H_INCLUDED | |
| 121 | − | |
| 102 | + | |
| 103 | +// Hermite interpolation | |
| 104 | +float LEAF_interpolate_hermite (float A, float B, float C, float D, float t); | |
| 105 | +float LEAF_interpolation_linear (float A, float B, float t); | |
| 106 | + | |
| 107 | +float interpolate3max(float *buf, const int peakindex); | |
| 108 | +float interpolate3phase(float *buf, const int peakindex); | |
| 109 | + | |
| 110 | +// alternative implementation for abs() | |
| 111 | +// REQUIRES: 32 bit integers | |
| 112 | +int fastabs_int(int in); | |
| 113 | + | |
| 114 | +// alternative implementation for abs() | |
| 115 | +// REQUIRES: 32 bit floats | |
| 116 | +float fastabs(float f); | |
| 117 | + | |
| 118 | +//============================================================================== | |
| 119 | + | |
| 120 | +#ifdef __cplusplus | |
| 121 | +} | |
| 122 | +#endif | |
| 123 | + | |
| 124 | +#endif // LEAF_MATH_H_INCLUDED | |
| 125 | + | |
| 122 | 126 | //============================================================================== |
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | /*============================================================================== |
| 2 | 2 | |
| 3 | − LEAFOscillator.h | |
| 3 | + leaf-oscillator.h | |
| 4 | 4 | Created: 20 Jan 2017 12:00:58pm |
| 5 | 5 | Author: Michael R Mulshine |
| 6 | 6 | |
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | /*============================================================================== |
| 2 | 2 | |
| 3 | − LEAFReverb.h | |
| 3 | + leaf-reverb.h | |
| 4 | 4 | Created: 20 Jan 2017 12:02:04pm |
| 5 | 5 | Author: Michael R Mulshine |
| 6 | 6 | |
| @@ -17,8 +17,8 @@ extern "C" { · 16 unmodified lines | ||
| 17 | 17 | //============================================================================== |
| 18 | 18 | |
| 19 | 19 | #include "leaf-globals.h" |
| 20 | −#include "leaf-math.h" | |
| 21 | − | |
| 20 | +#include "leaf-math.h" | |
| 21 | + | |
| 22 | 22 | #include "leaf-utilities.h" |
| 23 | 23 | |
| 24 | 24 | //============================================================================== |
| @@ -34,11 +34,11 @@ extern "C" { · 9 unmodified lines | ||
| 34 | 34 | { |
| 35 | 35 | float* buff; |
| 36 | 36 | |
| 37 | − uint32_t idx; | |
| 37 | + uint32_t idx; | |
| 38 | 38 | uint32_t length; |
| 39 | 39 | |
| 40 | − RecordMode mode; | |
| 41 | − | |
| 40 | + RecordMode mode; | |
| 41 | + | |
| 42 | 42 | int active; |
| 43 | 43 | |
| 44 | 44 | } tBuffer; |
| @@ -46,72 +46,72 @@ extern "C" { · 1 unmodified line | ||
| 46 | 46 | void tBuffer_init (tBuffer* const, uint32_t length); |
| 47 | 47 | void tBuffer_free (tBuffer* const); |
| 48 | 48 | |
| 49 | − void tBuffer_tick (tBuffer* const, float sample); | |
| 50 | − | |
| 51 | − void tBuffer_read(tBuffer* const, float* buff, uint32_t len); | |
| 52 | − | |
| 53 | − float tBuffer_get (tBuffer* const, int idx); | |
| 49 | + void tBuffer_tick (tBuffer* const, float sample); | |
| 50 | + | |
| 51 | + void tBuffer_read(tBuffer* const, float* buff, uint32_t len); | |
| 52 | + | |
| 53 | + float tBuffer_get (tBuffer* const, int idx); | |
| 54 | 54 | |
| 55 | 55 | void tBuffer_record (tBuffer* const); |
| 56 | 56 | void tBuffer_stop (tBuffer* const); |
| 57 | 57 | |
| 58 | − void tBuffer_setRecordMode (tBuffer* const, RecordMode mode); | |
| 59 | − | |
| 60 | − void tBuffer_clear (tBuffer* const); | |
| 61 | − | |
| 62 | −//============================================================================== | |
| 63 | − | |
| 64 | − typedef enum Mode | |
| 65 | − { | |
| 66 | − Normal, | |
| 67 | − Loop, | |
| 68 | − BackAndForth, | |
| 69 | − SampleModeNil | |
| 70 | − } Mode; | |
| 71 | − | |
| 72 | − typedef struct _tSampler | |
| 73 | − { | |
| 74 | − tBuffer* samp; | |
| 75 | − | |
| 76 | − tRamp gain; | |
| 77 | − | |
| 78 | − float idx; | |
| 79 | − float inc; | |
| 80 | − float iinc; | |
| 81 | − int8_t dir; | |
| 82 | − int8_t flip; | |
| 83 | − int8_t bnf; | |
| 84 | − | |
| 85 | − int32_t start; | |
| 86 | − int32_t end; | |
| 87 | − uint32_t len; | |
| 88 | − uint32_t cfxlen; | |
| 89 | − | |
| 90 | − Mode mode; | |
| 91 | − int retrigger; | |
| 92 | − | |
| 93 | − int active; | |
| 94 | − | |
| 95 | − } tSampler; | |
| 96 | − | |
| 97 | − void tSampler_init (tSampler* const, tBuffer* s); | |
| 98 | − void tSampler_free (tSampler* const); | |
| 99 | − | |
| 100 | − float tSampler_tick (tSampler* const); | |
| 101 | − | |
| 102 | − void tSampler_setSample (tSampler* const, tBuffer* s); | |
| 103 | − | |
| 104 | − void tSampler_setMode (tSampler* const, Mode mode); | |
| 105 | − | |
| 106 | − void tSampler_play (tSampler* const); | |
| 107 | − void tSampler_stop (tSampler* const); | |
| 108 | − | |
| 109 | − void tSampler_setStart (tSampler* const, int32_t start); | |
| 110 | − void tSampler_setEnd (tSampler* const, int32_t end); | |
| 111 | − | |
| 112 | − void tSampler_setCrossfadeLength (tSampler* const p, uint32_t length); | |
| 113 | − | |
| 114 | − void tSampler_setRate (tSampler* const, float rate); | |
| 58 | + void tBuffer_setRecordMode (tBuffer* const, RecordMode mode); | |
| 59 | + | |
| 60 | + void tBuffer_clear (tBuffer* const); | |
| 61 | + | |
| 62 | +//============================================================================== | |
| 63 | + | |
| 64 | + typedef enum Mode | |
| 65 | + { | |
| 66 | + Normal, | |
| 67 | + Loop, | |
| 68 | + BackAndForth, | |
| 69 | + SampleModeNil | |
| 70 | + } Mode; | |
| 71 | + | |
| 72 | + typedef struct _tSampler | |
| 73 | + { | |
| 74 | + tBuffer* samp; | |
| 75 | + | |
| 76 | + tRamp gain; | |
| 77 | + | |
| 78 | + float idx; | |
| 79 | + float inc; | |
| 80 | + float iinc; | |
| 81 | + int8_t dir; | |
| 82 | + int8_t flip; | |
| 83 | + int8_t bnf; | |
| 84 | + | |
| 85 | + int32_t start; | |
| 86 | + int32_t end; | |
| 87 | + uint32_t len; | |
| 88 | + uint32_t cfxlen; | |
| 89 | + | |
| 90 | + Mode mode; | |
| 91 | + int retrigger; | |
| 92 | + | |
| 93 | + int active; | |
| 94 | + | |
| 95 | + } tSampler; | |
| 96 | + | |
| 97 | + void tSampler_init (tSampler* const, tBuffer* s); | |
| 98 | + void tSampler_free (tSampler* const); | |
| 99 | + | |
| 100 | + float tSampler_tick (tSampler* const); | |
| 101 | + | |
| 102 | + void tSampler_setSample (tSampler* const, tBuffer* s); | |
| 103 | + | |
| 104 | + void tSampler_setMode (tSampler* const, Mode mode); | |
| 105 | + | |
| 106 | + void tSampler_play (tSampler* const); | |
| 107 | + void tSampler_stop (tSampler* const); | |
| 108 | + | |
| 109 | + void tSampler_setStart (tSampler* const, int32_t start); | |
| 110 | + void tSampler_setEnd (tSampler* const, int32_t end); | |
| 111 | + | |
| 112 | + void tSampler_setCrossfadeLength (tSampler* const p, uint32_t length); | |
| 113 | + | |
| 114 | + void tSampler_setRate (tSampler* const, float rate); | |
| 115 | 115 | |
| 116 | 116 | //============================================================================== |
| 117 | 117 | |
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | /*============================================================================== |
| 2 | 2 | |
| 3 | − LEAFUtilities.h | |
| 3 | + leaf-utilities.h | |
| 4 | 4 | Created: 20 Jan 2017 12:02:17pm |
| 5 | 5 | Author: Michael R Mulshine |
| 6 | 6 | |
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | /*============================================================================== |
| 2 | 2 | |
| 3 | − LEAFInstrument.h | |
| 3 | + leaf-vocoder.h | |
| 4 | 4 | Created: 20 Jan 2017 12:01:54pm |
| 5 | 5 | Author: Michael R Mulshine |
| 6 | 6 | |
| @@ -4,14 +4,14 @@ · 3 unmodified lines | ||
| 4 | 4 | Created: 30 Nov 2018 11:57:05am |
| 5 | 5 | Author: airship |
| 6 | 6 | |
| 7 | −==============================================================================*/ | |
| 8 | − | |
| 9 | −#ifndef LEAF_WAVEFOLDER_H_INCLUDED | |
| 10 | −#define LEAF_WAVEFOLDER_H_INCLUDED | |
| 11 | − | |
| 12 | − | |
| 13 | −#ifdef __cplusplus | |
| 14 | −extern "C" { | |
| 7 | +==============================================================================*/ | |
| 8 | + | |
| 9 | +#ifndef LEAF_WAVEFOLDER_H_INCLUDED | |
| 10 | +#define LEAF_WAVEFOLDER_H_INCLUDED | |
| 11 | + | |
| 12 | + | |
| 13 | +#ifdef __cplusplus | |
| 14 | +extern "C" { | |
| 15 | 15 | #endif |
| 16 | 16 | |
| 17 | 17 | //============================================================================== |
| @@ -45,14 +45,14 @@ void tLockhartWavefolder_init (tLockhartWavefolder* const); · 27 unmodified lines | ||
| 45 | 45 | void tLockhartWavefolder_free (tLockhartWavefolder* const); |
| 46 | 46 | |
| 47 | 47 | float tLockhartWavefolder_tick (tLockhartWavefolder* const, float samp); |
| 48 | − | |
| 49 | − | |
| 50 | −//============================================================================== | |
| 51 | − | |
| 52 | −#ifdef __cplusplus | |
| 53 | −} | |
| 54 | −#endif | |
| 55 | − | |
| 56 | −#endif // LEAF_WAVEFOLDER_H_INCLUDED | |
| 57 | − | |
| 48 | + | |
| 49 | + | |
| 50 | +//============================================================================== | |
| 51 | + | |
| 52 | +#ifdef __cplusplus | |
| 53 | +} | |
| 54 | +#endif | |
| 55 | + | |
| 56 | +#endif // LEAF_WAVEFOLDER_H_INCLUDED | |
| 57 | + | |
| 58 | 58 | //============================================================================== |
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | /*============================================================================== |
| 2 | 2 | |
| 3 | − LEAFWavetables.h | |
| 3 | + leaf-wavetables.h | |
| 4 | 4 | Created: 4 Dec 2016 9:42:41pm |
| 5 | 5 | Author: Michael R Mulshine |
| 6 | 6 | |
| @@ -1,12 +1,10 @@ | ||
| 1 | −/* | |
| 2 | − ============================================================================== | |
| 1 | +/*============================================================================== | |
| 3 | 2 | |
| 4 | − leaf_808.cpp | |
| 3 | + leaf-808.c | |
| 5 | 4 | Created: 30 Nov 2018 10:24:21am |
| 6 | 5 | Author: airship |
| 7 | 6 | |
| 8 | − ============================================================================== | |
| 9 | −*/ | |
| 7 | +==============================================================================*/ | |
| 10 | 8 | |
| 11 | 9 | #if _WIN32 || _WIN64 |
| 12 | 10 | |
| @@ -0,0 +1,84 @@ | ||
| 1 | +/*============================================================================== | |
| 2 | + | |
| 3 | + leaf-crusher.c | |
| 4 | + Created: 30 Nov 2018 11:56:49am | |
| 5 | + Author: airship | |
| 6 | + | |
| 7 | +==============================================================================*/ | |
| 8 | + | |
| 9 | +#if _WIN32 || _WIN64 | |
| 10 | + | |
| 11 | +#include "..\Inc\leaf-crusher.h" | |
| 12 | + | |
| 13 | +#else | |
| 14 | + | |
| 15 | +#include "../Inc/leaf-crusher.h" | |
| 16 | + | |
| 17 | +#endif | |
| 18 | + | |
| 19 | +//============================================================================== | |
| 20 | + | |
| 21 | +#define SCALAR 5000.f | |
| 22 | + | |
| 23 | +void tCrusher_init (tCrusher* const c) | |
| 24 | +{ | |
| 25 | + c->op = 4; | |
| 26 | + c->div = SCALAR; | |
| 27 | + c->rnd = 0.25f; | |
| 28 | + c->srr = 0.25f; | |
| 29 | + | |
| 30 | + c->gain = (c->div / SCALAR) * 0.7f + 0.3f; | |
| 31 | +} | |
| 32 | + | |
| 33 | +void tCrusher_free (tCrusher* const c) | |
| 34 | +{ | |
| 35 | + leaf_free(c); | |
| 36 | +} | |
| 37 | + | |
| 38 | +float tCrusher_tick (tCrusher* const c, float input) | |
| 39 | +{ | |
| 40 | + float sample = input; | |
| 41 | + | |
| 42 | + sample *= SCALAR; // SCALAR is 5000 by default | |
| 43 | + | |
| 44 | + sample = floorf(sample); | |
| 45 | + | |
| 46 | + sample /= c->div; | |
| 47 | + | |
| 48 | + sample = LEAF_bitwise_or(sample, c->op << 23); | |
| 49 | + | |
| 50 | + sample = LEAF_clip(-1.f, sample, 1.f); | |
| 51 | + | |
| 52 | + sample = LEAF_round(sample, c->rnd); | |
| 53 | + | |
| 54 | + sample = LEAF_reduct(sample, c->srr); | |
| 55 | + | |
| 56 | + return sample * c->gain; | |
| 57 | + | |
| 58 | +} | |
| 59 | + | |
| 60 | +void tCrusher_setOperation (tCrusher* const c, uint32_t op) | |
| 61 | +{ | |
| 62 | + c->op = op % 8; | |
| 63 | +} | |
| 64 | + | |
| 65 | +// 0.0 - 1.0 | |
| 66 | +void tCrusher_setQuality (tCrusher* const c, float val) | |
| 67 | +{ | |
| 68 | + val = LEAF_clip(0.0f, val, 1.0f); | |
| 69 | + | |
| 70 | + c->div = 0.01f + val * SCALAR; | |
| 71 | + | |
| 72 | + c->gain = (c->div / SCALAR) * 0.7f + 0.3f; | |
| 73 | +} | |
| 74 | + | |
| 75 | +// what decimal to round to | |
| 76 | +void tCrusher_setRound (tCrusher* const c, float rnd) | |
| 77 | +{ | |
| 78 | + c->rnd = fabsf(rnd); | |
| 79 | +} | |
| 80 | + | |
| 81 | +void tCrusher_setSamplingRatio (tCrusher* const c, float ratio) | |
| 82 | +{ | |
| 83 | + c->srr = ratio; | |
| 84 | +} | |
| @@ -1,12 +1,10 @@ | ||
| 1 | −/* | |
| 2 | − ============================================================================== | |
| 1 | +/*============================================================================== | |
| 3 | 2 | |
| 4 | − LEAFDelay.c | |
| 3 | + leaf-delay.c | |
| 5 | 4 | Created: 20 Jan 2017 12:01:24pm |
| 6 | 5 | Author: Michael R Mulshine |
| 7 | 6 | |
| 8 | − ============================================================================== | |
| 9 | −*/ | |
| 7 | +==============================================================================*/ | |
| 10 | 8 | |
| 11 | 9 | #if _WIN32 || _WIN64 |
| 12 | 10 | |
| @@ -1,12 +1,10 @@ | ||
| 1 | −/* | |
| 2 | − ============================================================================== | |
| 1 | +/*============================================================================== | |
| 3 | 2 | |
| 4 | − LEAFFilter.c | |
| 3 | + leaf-filter.c | |
| 5 | 4 | Created: 20 Jan 2017 12:01:10pm |
| 6 | 5 | Author: Michael R Mulshine |
| 7 | 6 | |
| 8 | − ============================================================================== | |
| 9 | −*/ | |
| 7 | +==============================================================================*/ | |
| 10 | 8 | |
| 11 | 9 | #if _WIN32 || _WIN64 |
| 12 | 10 | |
| @@ -1,12 +1,10 @@ | ||
| 1 | −/* | |
| 2 | − ============================================================================== | |
| 1 | +/*============================================================================== | |
| 3 | 2 | |
| 4 | − leaf-formant.cpp | |
| 3 | + leaf-formant.c | |
| 5 | 4 | Created: 30 Nov 2018 11:03:30am |
| 6 | 5 | Author: airship |
| 7 | 6 | |
| 8 | − ============================================================================== | |
| 9 | −*/ | |
| 7 | +==============================================================================*/ | |
| 10 | 8 | |
| 11 | 9 | #if _WIN32 || _WIN64 |
| 12 | 10 | |
| @@ -1,12 +1,10 @@ | ||
| 1 | −/* | |
| 2 | − ============================================================================== | |
| 1 | +/*============================================================================== | |
| 3 | 2 | |
| 4 | − LEAFMath.c | |
| 3 | + leaf-math.c | |
| 5 | 4 | Created: 22 Jan 2017 7:02:56pm |
| 6 | 5 | Author: Michael R Mulshine |
| 7 | 6 | |
| 8 | − ============================================================================== | |
| 9 | −*/ | |
| 7 | +==============================================================================*/ | |
| 10 | 8 | |
| 11 | 9 | #if _WIN32 || _WIN64 |
| 12 | 10 | |
| @@ -24,7 +22,7 @@ · 11 unmodified lines | ||
| 24 | 22 | #define TWO_TO_16 65536.f |
| 25 | 23 | |
| 26 | 24 | #define EXPONENTIAL_TABLE_SIZE 65536 |
| 27 | − | |
| 25 | + | |
| 28 | 26 | |
| 29 | 27 | float interpolate3max(float *buf, const int peakindex) |
| 30 | 28 | { |
| @@ -119,6 +117,50 @@ float LEAF_shaper(float input, float m_drive) · 88 unmodified lines | ||
| 119 | 117 | float shaperOut = w*(c+ 0.05f*xc2)*(m_drive + 0.75f); |
| 120 | 118 | shaperOut *= 0.5f; // post_scale |
| 121 | 119 | return shaperOut; |
| 120 | +} | |
| 121 | + | |
| 122 | +// reduce sample resolution | |
| 123 | +float LEAF_reduct (float input, float sr) | |
| 124 | +{ | |
| 125 | + float samp = input; | |
| 126 | + | |
| 127 | + samp *= sr; | |
| 128 | + | |
| 129 | + // method 1 | |
| 130 | + samp = ceilf(samp); | |
| 131 | + | |
| 132 | + samp /= sr; | |
| 133 | + | |
| 134 | + /* | |
| 135 | + // method 2 | |
| 136 | + samp = floorf(samp + 0.5f) - 0.5f; | |
| 137 | + | |
| 138 | + samp /= srr; | |
| 139 | + */ | |
| 140 | + | |
| 141 | + return samp; | |
| 142 | +} | |
| 143 | + | |
| 144 | +// round input to nearest rnd | |
| 145 | +float LEAF_round (float input, float rnd) | |
| 146 | +{ | |
| 147 | + rnd = fabsf(rnd); | |
| 148 | + | |
| 149 | + if (rnd <= 0.0000001f) return input; | |
| 150 | + | |
| 151 | + float scale = 1.f / rnd; | |
| 152 | + | |
| 153 | + return roundf(input * scale) / scale; | |
| 154 | +} | |
| 155 | + | |
| 156 | +union unholy_t unholy; | |
| 157 | + | |
| 158 | +float LEAF_bitwise_or(float input, uint32_t op) | |
| 159 | +{ | |
| 160 | + unholy.f = input; | |
| 161 | + unholy.i = (unholy.i | op); | |
| 162 | + | |
| 163 | + return unholy.f; | |
| 122 | 164 | } |
| 123 | 165 | |
| 124 | 166 | float LEAF_reedTable(float input, float offset, float slope) |
| @@ -1,12 +1,10 @@ | ||
| 1 | −/* | |
| 2 | − ============================================================================== | |
| 1 | +/*============================================================================== | |
| 3 | 2 | |
| 4 | − leaf-midi.cpp | |
| 3 | + leaf-midi.c | |
| 5 | 4 | Created: 30 Nov 2018 11:29:16am |
| 6 | 5 | Author: airship |
| 7 | 6 | |
| 8 | − ============================================================================== | |
| 9 | −*/ | |
| 7 | +==============================================================================*/ | |
| 10 | 8 | |
| 11 | 9 | #if _WIN32 || _WIN64 |
| 12 | 10 | |
| @@ -1,12 +1,10 @@ | ||
| 1 | −/* | |
| 2 | − ============================================================================== | |
| 1 | +/*============================================================================== | |
| 3 | 2 | |
| 4 | − LEAFOscillator.c | |
| 3 | + leaf-oscillator.c | |
| 5 | 4 | Created: 20 Jan 2017 12:00:58pm |
| 6 | 5 | Author: Michael R Mulshine |
| 7 | 6 | |
| 8 | − ============================================================================== | |
| 9 | −*/ | |
| 7 | +==============================================================================*/ | |
| 10 | 8 | |
| 11 | 9 | #if _WIN32 || _WIN64 |
| 12 | 10 | |
| @@ -1,12 +1,10 @@ | ||
| 1 | −/* | |
| 2 | − ============================================================================== | |
| 1 | +/*============================================================================== | |
| 3 | 2 | |
| 4 | − leaf-pitch.cpp | |
| 3 | + leaf-pitch.c | |
| 5 | 4 | Created: 30 Nov 2018 11:02:59am |
| 6 | 5 | Author: airship |
| 7 | 6 | |
| 8 | − ============================================================================== | |
| 9 | −*/ | |
| 7 | +==============================================================================*/ | |
| 10 | 8 | |
| 11 | 9 | #if _WIN32 || _WIN64 |
| 12 | 10 | |
| @@ -1,12 +1,10 @@ | ||
| 1 | −/* | |
| 2 | − ============================================================================== | |
| 1 | +/*============================================================================== | |
| 3 | 2 | |
| 4 | − LEAFReverb.c | |
| 3 | + leaf-reverb.c | |
| 5 | 4 | Created: 20 Jan 2017 12:02:04pm |
| 6 | 5 | Author: Michael R Mulshine |
| 7 | 6 | |
| 8 | − ============================================================================== | |
| 9 | −*/ | |
| 7 | +==============================================================================*/ | |
| 10 | 8 | |
| 11 | 9 | #if _WIN32 || _WIN64 |
| 12 | 10 | |
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | /* |
| 2 | 2 | ============================================================================== |
| 3 | 3 | |
| 4 | − LEAFUtilities.c | |
| 4 | + leaf-sample.c | |
| 5 | 5 | Created: 20 Jan 2017 12:02:17pm |
| 6 | 6 | Author: Michael R Mulshine |
| 7 | 7 | |
| @@ -10,7 +10,7 @@ · 2 unmodified lines | ||
| 10 | 10 | |
| 11 | 11 | |
| 12 | 12 | #if _WIN32 || _WIN64 |
| 13 | − | |
| 13 | + | |
| 14 | 14 | #include "..\Inc\leaf-sample.h" |
| 15 | 15 | #include "..\leaf.h" |
| 16 | 16 | |
| @@ -19,412 +19,412 @@ · 2 unmodified lines | ||
| 19 | 19 | #include "../Inc/leaf-sample.h" |
| 20 | 20 | #include "../leaf.h" |
| 21 | 21 | |
| 22 | −#endif | |
| 23 | − | |
| 24 | −//============================================================================== | |
| 25 | − | |
| 26 | −void tBuffer_init (tBuffer* const s, uint32_t length) | |
| 27 | −{ | |
| 28 | − s->buff = (float*) leaf_alloc( sizeof(float) * length); | |
| 29 | − | |
| 30 | − | |
| 31 | − s->length = length; | |
| 32 | − s->active = 0; | |
| 33 | − s->idx = 0; | |
| 34 | − s->mode = RecordOneShot; | |
| 35 | − | |
| 36 | − tBuffer_clear(s); | |
| 37 | −} | |
| 38 | − | |
| 39 | −void tBuffer_free (tBuffer* const s) | |
| 40 | −{ | |
| 41 | − leaf_free(s->buff); | |
| 42 | − leaf_free(s); | |
| 43 | −} | |
| 44 | − | |
| 45 | −void tBuffer_tick (tBuffer* const s, float sample) | |
| 46 | −{ | |
| 47 | − if (s->active == 1) | |
| 48 | − { | |
| 49 | − s->buff[s->idx] = sample; | |
| 50 | − | |
| 51 | − s->idx += 1; | |
| 52 | − | |
| 53 | − if (s->idx >= s->length) | |
| 54 | − { | |
| 55 | − if (s->mode == RecordOneShot) | |
| 56 | − { | |
| 57 | − tBuffer_stop(s); | |
| 58 | − } | |
| 59 | − else if (s->mode == RecordLoop) | |
| 60 | − { | |
| 61 | − s->idx = 0; | |
| 62 | − } | |
| 63 | − } | |
| 64 | − } | |
| 65 | −} | |
| 66 | − | |
| 67 | −void tBuffer_read(tBuffer* const s, float* buff, uint32_t len) | |
| 68 | −{ | |
| 69 | − for (int i = 0; i < s->length; i++) | |
| 70 | − { | |
| 71 | − if (i < len) s->buff[i] = buff[i]; | |
| 72 | − else s->buff[i] = 0.f; | |
| 73 | − } | |
| 74 | −} | |
| 75 | − | |
| 76 | −float tBuffer_get (tBuffer* const s, int idx) | |
| 77 | −{ | |
| 78 | − if ((idx < 0) || (idx >= s->length)) return 0.f; | |
| 79 | − | |
| 80 | − return s->buff[idx]; | |
| 81 | −} | |
| 82 | − | |
| 83 | −void tBuffer_record(tBuffer* const s) | |
| 84 | −{ | |
| 85 | − s->active = 1; | |
| 86 | − s->idx = 0; | |
| 87 | −} | |
| 88 | − | |
| 89 | −void tBuffer_stop(tBuffer* const s) | |
| 90 | −{ | |
| 91 | − s->active = 0; | |
| 92 | −} | |
| 93 | − | |
| 94 | −void tBuffer_setRecordMode (tBuffer* const s, RecordMode mode) | |
| 95 | −{ | |
| 96 | − s->mode = mode; | |
| 97 | −} | |
| 98 | − | |
| 99 | −void tBuffer_clear (tBuffer* const s) | |
| 100 | −{ | |
| 101 | − for (int i = 0; i < s->length; i++) | |
| 102 | − { | |
| 103 | − s->buff[i] = 0.f; | |
| 104 | − } | |
| 105 | −} | |
| 106 | − | |
| 107 | −//================================tSampler===================================== | |
| 108 | − | |
| 109 | −void tSampler_init (tSampler* const p, tBuffer* s) | |
| 110 | −{ | |
| 111 | − p->samp = s; | |
| 112 | − | |
| 113 | − p->active = 0; | |
| 114 | − | |
| 115 | − p->start = 0; | |
| 116 | − p->end = p->samp->length - 1; | |
| 117 | − | |
| 118 | − p->len = p->end - p->start; | |
| 119 | − | |
| 120 | − p->idx = 0.f; | |
| 121 | − p->inc = 1.f; | |
| 122 | − p->iinc = 1.f; | |
| 123 | − | |
| 124 | − p->dir = 1; | |
| 125 | − p->flip = 1; | |
| 126 | − p->bnf = 1; | |
| 127 | − | |
| 128 | − p->mode = Normal; | |
| 129 | − | |
| 130 | − p->cfxlen = 300; // default 300 sample crossfade | |
| 131 | − | |
| 132 | − tRamp_init(&p->gain, 7.0f, 1); | |
| 133 | − tRamp_setVal(&p->gain, 0.f); | |
| 134 | −} | |
| 135 | − | |
| 136 | −void tSampler_free (tSampler* const p) | |
| 137 | −{ | |
| 138 | − leaf_free(p->samp); | |
| 139 | − leaf_free(p); | |
| 140 | −} | |
| 141 | − | |
| 142 | −float tSampler_tick (tSampler* const p) | |
| 143 | −{ | |
| 144 | − if (p->active == 0 || (p->len < 4)) return 0.f; | |
| 145 | − | |
| 146 | − float sample = 0.f; | |
| 147 | − float cfxsample = 0.f; | |
| 148 | − int numsamps; | |
| 149 | − float g1 = 1.f, g2 = 0.f; | |
| 150 | − | |
| 151 | − float* buff = p->samp->buff; | |
| 152 | − | |
| 153 | − int dir = p->bnf * p->dir * p->flip; | |
| 154 | − | |
| 22 | +#endif | |
| 23 | + | |
| 24 | +//============================================================================== | |
| 25 | + | |
| 26 | +void tBuffer_init (tBuffer* const s, uint32_t length) | |
| 27 | +{ | |
| 28 | + s->buff = (float*) leaf_alloc( sizeof(float) * length); | |
| 29 | + | |
| 30 | + | |
| 31 | + s->length = length; | |
| 32 | + s->active = 0; | |
| 33 | + s->idx = 0; | |
| 34 | + s->mode = RecordOneShot; | |
| 35 | + | |
| 36 | + tBuffer_clear(s); | |
| 37 | +} | |
| 38 | + | |
| 39 | +void tBuffer_free (tBuffer* const s) | |
| 40 | +{ | |
| 41 | + leaf_free(s->buff); | |
| 42 | + leaf_free(s); | |
| 43 | +} | |
| 44 | + | |
| 45 | +void tBuffer_tick (tBuffer* const s, float sample) | |
| 46 | +{ | |
| 47 | + if (s->active == 1) | |
| 48 | + { | |
| 49 | + s->buff[s->idx] = sample; | |
| 50 | + | |
| 51 | + s->idx += 1; | |
| 52 | + | |
| 53 | + if (s->idx >= s->length) | |
| 54 | + { | |
| 55 | + if (s->mode == RecordOneShot) | |
| 56 | + { | |
| 57 | + tBuffer_stop(s); | |
| 58 | + } | |
| 59 | + else if (s->mode == RecordLoop) | |
| 60 | + { | |
| 61 | + s->idx = 0; | |
| 62 | + } | |
| 63 | + } | |
| 64 | + } | |
| 65 | +} | |
| 66 | + | |
| 67 | +void tBuffer_read(tBuffer* const s, float* buff, uint32_t len) | |
| 68 | +{ | |
| 69 | + for (int i = 0; i < s->length; i++) | |
| 70 | + { | |
| 71 | + if (i < len) s->buff[i] = buff[i]; | |
| 72 | + else s->buff[i] = 0.f; | |
| 73 | + } | |
| 74 | +} | |
| 75 | + | |
| 76 | +float tBuffer_get (tBuffer* const s, int idx) | |
| 77 | +{ | |
| 78 | + if ((idx < 0) || (idx >= s->length)) return 0.f; | |
| 79 | + | |
| 80 | + return s->buff[idx]; | |
| 81 | +} | |
| 82 | + | |
| 83 | +void tBuffer_record(tBuffer* const s) | |
| 84 | +{ | |
| 85 | + s->active = 1; | |
| 86 | + s->idx = 0; | |
| 87 | +} | |
| 88 | + | |
| 89 | +void tBuffer_stop(tBuffer* const s) | |
| 90 | +{ | |
| 91 | + s->active = 0; | |
| 92 | +} | |
| 93 | + | |
| 94 | +void tBuffer_setRecordMode (tBuffer* const s, RecordMode mode) | |
| 95 | +{ | |
| 96 | + s->mode = mode; | |
| 97 | +} | |
| 98 | + | |
| 99 | +void tBuffer_clear (tBuffer* const s) | |
| 100 | +{ | |
| 101 | + for (int i = 0; i < s->length; i++) | |
| 102 | + { | |
| 103 | + s->buff[i] = 0.f; | |
| 104 | + } | |
| 105 | +} | |
| 106 | + | |
| 107 | +//================================tSampler===================================== | |
| 108 | + | |
| 109 | +void tSampler_init (tSampler* const p, tBuffer* s) | |
| 110 | +{ | |
| 111 | + p->samp = s; | |
| 112 | + | |
| 113 | + p->active = 0; | |
| 114 | + | |
| 115 | + p->start = 0; | |
| 116 | + p->end = p->samp->length - 1; | |
| 117 | + | |
| 118 | + p->len = p->end - p->start; | |
| 119 | + | |
| 120 | + p->idx = 0.f; | |
| 121 | + p->inc = 1.f; | |
| 122 | + p->iinc = 1.f; | |
| 123 | + | |
| 124 | + p->dir = 1; | |
| 125 | + p->flip = 1; | |
| 126 | + p->bnf = 1; | |
| 127 | + | |
| 128 | + p->mode = Normal; | |
| 129 | + | |
| 130 | + p->cfxlen = 300; // default 300 sample crossfade | |
| 131 | + | |
| 132 | + tRamp_init(&p->gain, 7.0f, 1); | |
| 133 | + tRamp_setVal(&p->gain, 0.f); | |
| 134 | +} | |
| 135 | + | |
| 136 | +void tSampler_free (tSampler* const p) | |
| 137 | +{ | |
| 138 | + leaf_free(p->samp); | |
| 139 | + leaf_free(p); | |
| 140 | +} | |
| 141 | + | |
| 142 | +float tSampler_tick (tSampler* const p) | |
| 143 | +{ | |
| 144 | + if (p->active == 0 || (p->len < 4)) return 0.f; | |
| 145 | + | |
| 146 | + float sample = 0.f; | |
| 147 | + float cfxsample = 0.f; | |
| 148 | + int numsamps; | |
| 149 | + float g1 = 1.f, g2 = 0.f; | |
| 150 | + | |
| 151 | + float* buff = p->samp->buff; | |
| 152 | + | |
| 153 | + int dir = p->bnf * p->dir * p->flip; | |
| 154 | + | |
| 155 | 155 | int idx; |
| 156 | 156 | float alpha; |
| 157 | − | |
| 158 | − if (dir > 0) | |
| 159 | − { | |
| 157 | + | |
| 158 | + if (dir > 0) | |
| 159 | + { | |
| 160 | 160 | idx = (int) p->idx; |
| 161 | 161 | alpha = p->idx - idx; |
| 162 | − } | |
| 163 | − else | |
| 164 | − { | |
| 165 | − 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; | |
| 167 | − } | |
| 168 | − | |
| 169 | − int32_t start = p->start, end = p->end; | |
| 170 | − if (p->flip < 0) | |
| 171 | − { | |
| 172 | − start = p->end; | |
| 173 | − end = p->start; | |
| 174 | − } | |
| 175 | − | |
| 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 == Loop) | |
| 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 | |
| 217 | − { | |
| 218 | − // REVERSE | |
| 219 | − int i1 = idx+1; | |
| 220 | − int i3 = idx-1; | |
| 221 | − int i4 = idx-2; | |
| 222 | − | |
| 223 | − sample = LEAF_interpolate_hermite (buff[i1], | |
| 224 | − buff[idx], | |
| 225 | − buff[i3], | |
| 226 | − buff[i4], | |
| 227 | − 1.0f-alpha); | |
| 228 | − | |
| 229 | − numsamps = (idx - start) / p->inc; | |
| 230 | − | |
| 231 | − if (p->mode == Loop) | |
| 232 | − { | |
| 233 | − if (numsamps <= p->cfxlen) | |
| 234 | − { | |
| 235 | − // CROSSFADE SAMPLE | |
| 236 | − float idxx = p->idx + p->len + 1.f; | |
| 237 | − int cdx = (int)(idxx); | |
| 238 | − alpha = idxx - cdx; | |
| 239 | − | |
| 240 | − i1 = cdx+1; | |
| 241 | − i3 = cdx-1; | |
| 242 | − i4 = cdx-2; | |
| 243 | − | |
| 244 | − cfxsample = LEAF_interpolate_hermite (buff[i1], | |
| 245 | − buff[cdx], | |
| 246 | − buff[i3], | |
| 247 | − buff[i4], | |
| 248 | − 1.f-alpha); | |
| 249 | − | |
| 250 | − g2 = (float) (p->cfxlen - numsamps) / (float) p->cfxlen; | |
| 251 | − } | |
| 252 | − } | |
| 253 | − } | |
| 254 | − | |
| 255 | − p->idx += (dir * p->inc); | |
| 256 | − | |
| 257 | − if (p->mode == Normal) | |
| 258 | − { | |
| 259 | − if (numsamps < (0.007f * leaf.sampleRate)) | |
| 260 | − { | |
| 261 | − tRamp_setDest(&p->gain, 0.f); | |
| 262 | − p->active = -1; | |
| 263 | − } | |
| 264 | − } | |
| 265 | − else if (p->mode == Loop ) // == Normal or Loop | |
| 266 | − { | |
| 267 | − if (idx <= start) | |
| 268 | − { | |
| 269 | − p->idx += (float)(p->len); | |
| 270 | − } | |
| 271 | − else if (idx >= end) | |
| 272 | − { | |
| 273 | − p->idx -= (float)(p->len); | |
| 274 | − } | |
| 275 | − } | |
| 276 | − else // == BackAndForth | |
| 277 | − { | |
| 278 | − if (p->idx < start) | |
| 279 | − { | |
| 280 | − p->bnf = -p->bnf; | |
| 281 | − p->idx = start; | |
| 282 | − } | |
| 283 | − else if (p->idx > end) | |
| 284 | − { | |
| 285 | − p->bnf = -p->bnf; | |
| 286 | − p->idx = end; | |
| 287 | − } | |
| 288 | − } | |
| 289 | − | |
| 290 | − g1 = 1.f - g2; | |
| 291 | − | |
| 292 | − sample = sample * g1 + cfxsample * g2; | |
| 293 | − | |
| 294 | − sample = sample * tRamp_tick(&p->gain); | |
| 295 | − | |
| 296 | − if (p->active < 0) | |
| 297 | − { | |
| 298 | − if (tRamp_sample(&p->gain) <= 0.00001f) | |
| 299 | − { | |
| 300 | − if (p->retrigger == 1) | |
| 301 | − { | |
| 302 | − p->active = 1; | |
| 303 | − p->retrigger = 0; | |
| 304 | − tRamp_setDest(&p->gain, 1.f); | |
| 305 | − | |
| 306 | − if (p->dir > 0) | |
| 307 | − { | |
| 308 | − if (p->flip > 0) p->idx = p->start; | |
| 309 | − else p->idx = p->end; | |
| 310 | − } | |
| 311 | − else | |
| 312 | − { | |
| 313 | − if (p->flip > 0) p->idx = p->end; | |
| 314 | − else p->idx = p->start; | |
| 315 | − } | |
| 316 | − } | |
| 317 | − else | |
| 318 | − { | |
| 319 | − p->active = 0; | |
| 320 | − } | |
| 321 | − | |
| 322 | − } | |
| 323 | − } | |
| 324 | − | |
| 325 | − return sample; | |
| 326 | −} | |
| 327 | − | |
| 328 | −void tSampler_setSample (tSampler* const p, tBuffer* s) | |
| 329 | −{ | |
| 330 | − p->samp = s; | |
| 331 | −} | |
| 332 | − | |
| 333 | −void tSampler_setMode (tSampler* const p, Mode mode) | |
| 334 | −{ | |
| 335 | − p->mode = mode; | |
| 336 | −} | |
| 337 | − | |
| 338 | −void tSampler_setCrossfadeLength (tSampler* const p, uint32_t length) | |
| 339 | −{ | |
| 340 | − uint32_t cfxlen = LEAF_clip(0, length, 1000); | |
| 341 | − | |
| 342 | − //if (cfxlen > p->len) cfxlen = p->len * 0.25f; | |
| 343 | − | |
| 344 | − p->cfxlen = cfxlen; | |
| 345 | −} | |
| 346 | − | |
| 347 | −void tSampler_play (tSampler* const p) | |
| 348 | −{ | |
| 349 | − if (p->active != 0) | |
| 350 | − { | |
| 351 | − p->active = -1; | |
| 352 | − p->retrigger = 1; | |
| 353 | − | |
| 354 | − tRamp_setDest(&p->gain, 0.f); | |
| 355 | − } | |
| 356 | − else | |
| 357 | − { | |
| 358 | − p->active = 1; | |
| 359 | − p->retrigger = 0; | |
| 360 | − | |
| 361 | − tRamp_setDest(&p->gain, 1.f); | |
| 362 | − | |
| 363 | − if (p->dir > 0) | |
| 364 | − { | |
| 365 | − if (p->flip > 0) p->idx = p->start; | |
| 366 | − else p->idx = p->end; | |
| 367 | − } | |
| 368 | − else | |
| 369 | − { | |
| 370 | − if (p->flip > 0) p->idx = p->end; | |
| 371 | − else p->idx = p->start; | |
| 372 | − } | |
| 373 | − } | |
| 374 | −} | |
| 375 | − | |
| 376 | −void tSampler_stop (tSampler* const p) | |
| 377 | −{ | |
| 378 | − p->active = -1; | |
| 379 | − | |
| 380 | − tRamp_setDest(&p->gain, 0.f); | |
| 381 | −} | |
| 382 | − | |
| 383 | −static void handleStartEndChange(tSampler* const p) | |
| 384 | −{ | |
| 385 | − p->len = abs(p->end - p->start); | |
| 386 | − | |
| 387 | − //if (p->len < p->cfxlen) p->cfxlen = p->len * 0.9f; | |
| 388 | − | |
| 389 | − if (p->start > p->end) | |
| 390 | − { | |
| 391 | − p->flip = -1; | |
| 392 | − } | |
| 393 | − else | |
| 394 | − { | |
| 395 | − p->flip = 1; | |
| 396 | − } | |
| 397 | −} | |
| 398 | − | |
| 399 | −void tSampler_setStart (tSampler* const p, int32_t start) | |
| 400 | −{ | |
| 401 | − p->start = LEAF_clipInt(0, start, (p->samp->length - 1)); | |
| 402 | − | |
| 403 | − handleStartEndChange(p); | |
| 404 | −} | |
| 405 | − | |
| 406 | −void tSampler_setEnd (tSampler* const p, int32_t end) | |
| 407 | −{ | |
| 408 | − p->end = LEAF_clipInt(0, end, (p->samp->length - 1)); | |
| 409 | − | |
| 410 | − handleStartEndChange(p); | |
| 411 | −} | |
| 412 | − | |
| 413 | −void tSampler_setRate (tSampler* const p, float rate) | |
| 414 | −{ | |
| 415 | − if (rate < 0.f) | |
| 416 | − { | |
| 417 | − rate = -rate; | |
| 418 | − p->dir = -1; | |
| 419 | − } | |
| 420 | − else | |
| 421 | − { | |
| 422 | − p->dir = 1; | |
| 423 | − } | |
| 424 | − | |
| 425 | − p->inc = LEAF_clip(0.f, rate, 8.0f); | |
| 426 | − p->iinc = 1.f / p->inc; | |
| 427 | −} | |
| 428 | − | |
| 429 | − | |
| 162 | + } | |
| 163 | + else | |
| 164 | + { | |
| 165 | + 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; | |
| 167 | + } | |
| 168 | + | |
| 169 | + int32_t start = p->start, end = p->end; | |
| 170 | + if (p->flip < 0) | |
| 171 | + { | |
| 172 | + start = p->end; | |
| 173 | + end = p->start; | |
| 174 | + } | |
| 175 | + | |
| 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 == Loop) | |
| 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 | |
| 217 | + { | |
| 218 | + // REVERSE | |
| 219 | + int i1 = idx+1; | |
| 220 | + int i3 = idx-1; | |
| 221 | + int i4 = idx-2; | |
| 222 | + | |
| 223 | + sample = LEAF_interpolate_hermite (buff[i1], | |
| 224 | + buff[idx], | |
| 225 | + buff[i3], | |
| 226 | + buff[i4], | |
| 227 | + 1.0f-alpha); | |
| 228 | + | |
| 229 | + numsamps = (idx - start) / p->inc; | |
| 230 | + | |
| 231 | + if (p->mode == Loop) | |
| 232 | + { | |
| 233 | + if (numsamps <= p->cfxlen) | |
| 234 | + { | |
| 235 | + // CROSSFADE SAMPLE | |
| 236 | + float idxx = p->idx + p->len + 1.f; | |
| 237 | + int cdx = (int)(idxx); | |
| 238 | + alpha = idxx - cdx; | |
| 239 | + | |
| 240 | + i1 = cdx+1; | |
| 241 | + i3 = cdx-1; | |
| 242 | + i4 = cdx-2; | |
| 243 | + | |
| 244 | + cfxsample = LEAF_interpolate_hermite (buff[i1], | |
| 245 | + buff[cdx], | |
| 246 | + buff[i3], | |
| 247 | + buff[i4], | |
| 248 | + 1.f-alpha); | |
| 249 | + | |
| 250 | + g2 = (float) (p->cfxlen - numsamps) / (float) p->cfxlen; | |
| 251 | + } | |
| 252 | + } | |
| 253 | + } | |
| 254 | + | |
| 255 | + p->idx += (dir * p->inc); | |
| 256 | + | |
| 257 | + if (p->mode == Normal) | |
| 258 | + { | |
| 259 | + if (numsamps < (0.007f * leaf.sampleRate)) | |
| 260 | + { | |
| 261 | + tRamp_setDest(&p->gain, 0.f); | |
| 262 | + p->active = -1; | |
| 263 | + } | |
| 264 | + } | |
| 265 | + else if (p->mode == Loop ) // == Normal or Loop | |
| 266 | + { | |
| 267 | + if (idx <= start) | |
| 268 | + { | |
| 269 | + p->idx += (float)(p->len); | |
| 270 | + } | |
| 271 | + else if (idx >= end) | |
| 272 | + { | |
| 273 | + p->idx -= (float)(p->len); | |
| 274 | + } | |
| 275 | + } | |
| 276 | + else // == BackAndForth | |
| 277 | + { | |
| 278 | + if (p->idx < start) | |
| 279 | + { | |
| 280 | + p->bnf = -p->bnf; | |
| 281 | + p->idx = start; | |
| 282 | + } | |
| 283 | + else if (p->idx > end) | |
| 284 | + { | |
| 285 | + p->bnf = -p->bnf; | |
| 286 | + p->idx = end; | |
| 287 | + } | |
| 288 | + } | |
| 289 | + | |
| 290 | + g1 = 1.f - g2; | |
| 291 | + | |
| 292 | + sample = sample * g1 + cfxsample * g2; | |
| 293 | + | |
| 294 | + sample = sample * tRamp_tick(&p->gain); | |
| 295 | + | |
| 296 | + if (p->active < 0) | |
| 297 | + { | |
| 298 | + if (tRamp_sample(&p->gain) <= 0.00001f) | |
| 299 | + { | |
| 300 | + if (p->retrigger == 1) | |
| 301 | + { | |
| 302 | + p->active = 1; | |
| 303 | + p->retrigger = 0; | |
| 304 | + tRamp_setDest(&p->gain, 1.f); | |
| 305 | + | |
| 306 | + if (p->dir > 0) | |
| 307 | + { | |
| 308 | + if (p->flip > 0) p->idx = p->start; | |
| 309 | + else p->idx = p->end; | |
| 310 | + } | |
| 311 | + else | |
| 312 | + { | |
| 313 | + if (p->flip > 0) p->idx = p->end; | |
| 314 | + else p->idx = p->start; | |
| 315 | + } | |
| 316 | + } | |
| 317 | + else | |
| 318 | + { | |
| 319 | + p->active = 0; | |
| 320 | + } | |
| 321 | + | |
| 322 | + } | |
| 323 | + } | |
| 324 | + | |
| 325 | + return sample; | |
| 326 | +} | |
| 327 | + | |
| 328 | +void tSampler_setSample (tSampler* const p, tBuffer* s) | |
| 329 | +{ | |
| 330 | + p->samp = s; | |
| 331 | +} | |
| 332 | + | |
| 333 | +void tSampler_setMode (tSampler* const p, Mode mode) | |
| 334 | +{ | |
| 335 | + p->mode = mode; | |
| 336 | +} | |
| 337 | + | |
| 338 | +void tSampler_setCrossfadeLength (tSampler* const p, uint32_t length) | |
| 339 | +{ | |
| 340 | + uint32_t cfxlen = LEAF_clip(0, length, 1000); | |
| 341 | + | |
| 342 | + //if (cfxlen > p->len) cfxlen = p->len * 0.25f; | |
| 343 | + | |
| 344 | + p->cfxlen = cfxlen; | |
| 345 | +} | |
| 346 | + | |
| 347 | +void tSampler_play (tSampler* const p) | |
| 348 | +{ | |
| 349 | + if (p->active != 0) | |
| 350 | + { | |
| 351 | + p->active = -1; | |
| 352 | + p->retrigger = 1; | |
| 353 | + | |
| 354 | + tRamp_setDest(&p->gain, 0.f); | |
| 355 | + } | |
| 356 | + else | |
| 357 | + { | |
| 358 | + p->active = 1; | |
| 359 | + p->retrigger = 0; | |
| 360 | + | |
| 361 | + tRamp_setDest(&p->gain, 1.f); | |
| 362 | + | |
| 363 | + if (p->dir > 0) | |
| 364 | + { | |
| 365 | + if (p->flip > 0) p->idx = p->start; | |
| 366 | + else p->idx = p->end; | |
| 367 | + } | |
| 368 | + else | |
| 369 | + { | |
| 370 | + if (p->flip > 0) p->idx = p->end; | |
| 371 | + else p->idx = p->start; | |
| 372 | + } | |
| 373 | + } | |
| 374 | +} | |
| 375 | + | |
| 376 | +void tSampler_stop (tSampler* const p) | |
| 377 | +{ | |
| 378 | + p->active = -1; | |
| 379 | + | |
| 380 | + tRamp_setDest(&p->gain, 0.f); | |
| 381 | +} | |
| 382 | + | |
| 383 | +static void handleStartEndChange(tSampler* const p) | |
| 384 | +{ | |
| 385 | + p->len = abs(p->end - p->start); | |
| 386 | + | |
| 387 | + //if (p->len < p->cfxlen) p->cfxlen = p->len * 0.9f; | |
| 388 | + | |
| 389 | + if (p->start > p->end) | |
| 390 | + { | |
| 391 | + p->flip = -1; | |
| 392 | + } | |
| 393 | + else | |
| 394 | + { | |
| 395 | + p->flip = 1; | |
| 396 | + } | |
| 397 | +} | |
| 398 | + | |
| 399 | +void tSampler_setStart (tSampler* const p, int32_t start) | |
| 400 | +{ | |
| 401 | + p->start = LEAF_clipInt(0, start, (p->samp->length - 1)); | |
| 402 | + | |
| 403 | + handleStartEndChange(p); | |
| 404 | +} | |
| 405 | + | |
| 406 | +void tSampler_setEnd (tSampler* const p, int32_t end) | |
| 407 | +{ | |
| 408 | + p->end = LEAF_clipInt(0, end, (p->samp->length - 1)); | |
| 409 | + | |
| 410 | + handleStartEndChange(p); | |
| 411 | +} | |
| 412 | + | |
| 413 | +void tSampler_setRate (tSampler* const p, float rate) | |
| 414 | +{ | |
| 415 | + if (rate < 0.f) | |
| 416 | + { | |
| 417 | + rate = -rate; | |
| 418 | + p->dir = -1; | |
| 419 | + } | |
| 420 | + else | |
| 421 | + { | |
| 422 | + p->dir = 1; | |
| 423 | + } | |
| 424 | + | |
| 425 | + p->inc = LEAF_clip(0.f, rate, 8.0f); | |
| 426 | + p->iinc = 1.f / p->inc; | |
| 427 | +} | |
| 428 | + | |
| 429 | + | |
| 430 | 430 | //============================================================================== |
| @@ -1,12 +1,10 @@ | ||
| 1 | −/* | |
| 2 | − ============================================================================== | |
| 1 | +/*============================================================================== | |
| 3 | 2 | |
| 4 | − leaf-string.cpp | |
| 3 | + leaf-string.c | |
| 5 | 4 | Created: 30 Nov 2018 10:41:42am |
| 6 | 5 | Author: airship |
| 7 | 6 | |
| 8 | − ============================================================================== | |
| 9 | −*/ | |
| 7 | +==============================================================================*/ | |
| 10 | 8 | |
| 11 | 9 | #if _WIN32 || _WIN64 |
| 12 | 10 | |
| @@ -1,12 +1,10 @@ | ||
| 1 | −/* | |
| 2 | − ============================================================================== | |
| 1 | +/*============================================================================== | |
| 3 | 2 | |
| 4 | − LEAFUtilities.c | |
| 3 | + leaf-utilities.c | |
| 5 | 4 | Created: 20 Jan 2017 12:02:17pm |
| 6 | 5 | Author: Michael R Mulshine |
| 7 | 6 | |
| 8 | − ============================================================================== | |
| 9 | −*/ | |
| 7 | +==============================================================================*/ | |
| 10 | 8 | |
| 11 | 9 | |
| 12 | 10 | #if _WIN32 || _WIN64 |
| @@ -1,12 +1,10 @@ | ||
| 1 | −/* | |
| 2 | − ============================================================================== | |
| 1 | +/*============================================================================== | |
| 3 | 2 | |
| 4 | − LEAFInstrument.c | |
| 3 | + leaf-vocoder.c | |
| 5 | 4 | Created: 20 Jan 2017 12:01:54pm |
| 6 | 5 | Author: Michael R Mulshine |
| 7 | 6 | |
| 8 | − ============================================================================== | |
| 9 | −*/ | |
| 7 | +==============================================================================*/ | |
| 10 | 8 | |
| 11 | 9 | #if _WIN32 || _WIN64 |
| 12 | 10 | |
| @@ -1,12 +1,10 @@ | ||
| 1 | −/* | |
| 2 | − ============================================================================== | |
| 1 | +/*============================================================================== | |
| 3 | 2 | |
| 4 | − leaf-wavefolder.cpp | |
| 3 | + leaf-wavefolder.c | |
| 5 | 4 | Created: 30 Nov 2018 11:56:49am |
| 6 | 5 | Author: airship |
| 7 | 6 | |
| 8 | − ============================================================================== | |
| 9 | −*/ | |
| 7 | +==============================================================================*/ | |
| 10 | 8 | |
| 11 | 9 | #if _WIN32 || _WIN64 |
| 12 | 10 | |
| @@ -32,7 +32,8 @@ · 31 unmodified lines | ||
| 32 | 32 | #include ".\Inc\leaf-pitch.h" |
| 33 | 33 | #include ".\Inc\leaf-formant.h" |
| 34 | 34 | #include ".\Inc\leaf-midi.h" |
| 35 | −#include ".\Inc\leaf-sample.h" | |
| 35 | +#include ".\Inc\leaf-sample.h" | |
| 36 | +#include ".\Inc\leaf-crusher.h" | |
| 36 | 37 | #include ".\Inc\leaf-wavefolder.h" |
| 37 | 38 | #include ".\Inc\leaf-wavetables.h" |
| 38 | 39 | |
| @@ -51,7 +52,8 @@ · 12 unmodified lines | ||
| 51 | 52 | #include "./Inc/leaf-pitch.h" |
| 52 | 53 | #include "./Inc/leaf-formant.h" |
| 53 | 54 | #include "./Inc/leaf-midi.h" |
| 54 | −#include "./Inc/leaf-sample.h" | |
| 55 | +#include "./Inc/leaf-sample.h" | |
| 56 | +#include "./Inc/leaf-crusher.h" | |
| 55 | 57 | #include "./Inc/leaf-wavefolder.h" |
| 56 | 58 | #include "./Inc/leaf-wavetables.h" |
| 57 | 59 | |
| @@ -40,6 +40,7 @@ · 39 unmodified lines | ||
| 40 | 40 | file="../LEAF/Inc/leaf-utilities.h"/> |
| 41 | 41 | <FILE id="Szb5LP" name="leaf-vocoder.h" compile="0" resource="0" file="../LEAF/Inc/leaf-vocoder.h"/> |
| 42 | 42 | <FILE id="T6KXi7" name="leaf-sample.h" compile="0" resource="0" file="../LEAF/Inc/leaf-sample.h"/> |
| 43 | + <FILE id="bpUZCA" name="leaf-crusher.h" compile="0" resource="0" file="../LEAF/Inc/leaf-crusher.h"/> | |
| 43 | 44 | <FILE id="PRkOp2" name="leaf-wavefolder.h" compile="0" resource="0" |
| 44 | 45 | file="../LEAF/Inc/leaf-wavefolder.h"/> |
| 45 | 46 | <FILE id="KpGzKv" name="leaf-wavetables.h" compile="0" resource="0" |
| @@ -62,6 +63,7 @@ · 16 unmodified lines | ||
| 62 | 63 | file="../LEAF/Src/leaf-utilities.c"/> |
| 63 | 64 | <FILE id="u1aLLR" name="leaf-vocoder.c" compile="1" resource="0" file="../LEAF/Src/leaf-vocoder.c"/> |
| 64 | 65 | <FILE id="nmtoFJ" name="leaf-sample.c" compile="1" resource="0" file="../LEAF/Src/leaf-sample.c"/> |
| 66 | + <FILE id="Oymcac" name="leaf-crusher.c" compile="1" resource="0" file="../LEAF/Src/leaf-crusher.c"/> | |
| 65 | 67 | <FILE id="LVoaGm" name="leaf-wavefolder.c" compile="1" resource="0" |
| 66 | 68 | file="../LEAF/Src/leaf-wavefolder.c"/> |
| 67 | 69 | <FILE id="HRk07h" name="leaf-wavetables.c" compile="1" resource="0" |
| @@ -15,16 +15,16 @@ · 14 unmodified lines | ||
| 15 | 15 | |
| 16 | 16 | std::vector<juce::String> cButtonNames = std::vector<juce::String> |
| 17 | 17 | { |
| 18 | − "sample", | |
| 19 | − "play" | |
| 18 | + | |
| 20 | 19 | }; |
| 21 | 20 | |
| 22 | 21 | std::vector<juce::String> cSliderNames = std::vector<juce::String> |
| 23 | 22 | { |
| 24 | − "rate", | |
| 25 | − "start", | |
| 26 | − "end", | |
| 27 | − "cfxlen" | |
| 23 | + "sr", | |
| 24 | + "rnd", | |
| 25 | + "qual", | |
| 26 | + "op", | |
| 27 | + "mix" | |
| 28 | 28 | }; |
| 29 | 29 | |
| 30 | 30 | std::vector<juce::String> cComboBoxNames = std::vector<juce::String> |
| @@ -14,77 +14,76 @@ · 13 unmodified lines | ||
| 14 | 14 | |
| 15 | 15 | static void leaf_pool_report(void); |
| 16 | 16 | static void leaf_pool_dump(void); |
| 17 | −static void run_pool_test(void); | |
| 18 | − | |
| 19 | −tBuffer sample; | |
| 17 | +static void run_pool_test(void); | |
| 18 | + | |
| 19 | +float mix = 0.f; | |
| 20 | +float fx = 1.f; | |
| 20 | 21 | |
| 21 | −tSampler player; | |
| 22 | +tCrusher crusher; | |
| 22 | 23 | |
| 23 | 24 | void LEAFTest_init (float sampleRate, int blockSize) |
| 24 | 25 | { |
| 25 | − LEAF_init(sampleRate, blockSize, &randomNumberGenerator); | |
| 26 | − | |
| 27 | − tBuffer_init(&sample, leaf.sampleRate * 2); | |
| 28 | − | |
| 29 | − tSampler_init(&player, &sample); | |
| 30 | − tSampler_setMode(&player, Normal); | |
| 31 | − | |
| 32 | − leaf_pool_report(); | |
| 33 | − | |
| 34 | − tBuffer_record(&sample); | |
| 26 | + LEAF_init(sampleRate, blockSize, &randomNumberGenerator); | |
| 27 | + | |
| 28 | + tCrusher_init(&crusher); | |
| 29 | + | |
| 30 | + leaf_pool_report(); | |
| 35 | 31 | } |
| 36 | 32 | |
| 37 | 33 | int timer = 0; |
| 38 | 34 | |
| 39 | 35 | float LEAFTest_tick (float input) |
| 40 | 36 | { |
| 41 | − tBuffer_tick(&sample, input); | |
| 37 | + float sample = 0.f; | |
| 42 | 38 | |
| 43 | − return tSampler_tick(&player); | |
| 39 | + sample = (mix * tCrusher_tick(&crusher, input)) + ((1.f - mix) * input); | |
| 40 | + | |
| 41 | + return sample; | |
| 44 | 42 | } |
| 45 | − | |
| 43 | + | |
| 46 | 44 | bool lastState = false, lastPlayState = false; |
| 47 | 45 | void LEAFTest_block (void) |
| 48 | −{ | |
| 49 | − float val = getSliderValue("rate"); | |
| 46 | +{ | |
| 47 | + float val = getSliderValue("mix"); | |
| 48 | + | |
| 49 | + mix = val; | |
| 50 | + | |
| 51 | + val = getSliderValue("sr"); | |
| 52 | + | |
| 53 | + tCrusher_setSamplingRatio(&crusher, val * 3.99f + 0.01f); | |
| 50 | 54 | |
| 51 | − float rate = val * 16.0f - 8.0f; | |
| 52 | − tSampler_setRate(&player, rate); | |
| 53 | − //DBG("rate: " + String(rate)); | |
| 55 | + val = getSliderValue("rnd"); | |
| 54 | 56 | |
| 55 | − val = getSliderValue("start"); | |
| 56 | − float start = val * sample.length; | |
| 57 | − tSampler_setStart(&player, start); | |
| 58 | − //DBG("start: " + String(start)); | |
| 57 | + tCrusher_setRound(&crusher, val); | |
| 59 | 58 | |
| 60 | − val = getSliderValue("end"); | |
| 61 | − float end = val * sample.length; | |
| 62 | − tSampler_setEnd(&player, end); | |
| 63 | − //DBG("end: " + String(end)); | |
| 59 | + val = getSliderValue("qual"); | |
| 64 | 60 | |
| 65 | − val = getSliderValue("cfxlen"); | |
| 66 | − uint32_t cfxlen = val * 500; | |
| 67 | − tSampler_setCrossfadeLength(&player, cfxlen); | |
| 68 | − DBG("cfxlen: " + String(cfxlen)); | |
| 61 | + tCrusher_setQuality(&crusher, val); | |
| 69 | 62 | |
| 70 | − bool state = getButtonState("sample"); | |
| 63 | + val = getSliderValue("op"); | |
| 71 | 64 | |
| 72 | − if (state && !lastState) | |
| 73 | − { | |
| 74 | − timer = 0; | |
| 75 | − tBuffer_record(&sample); | |
| 76 | − } | |
| 65 | + tCrusher_setOperation(&crusher, (int)(val * 8.0f)); | |
| 77 | 66 | |
| 78 | − lastState = state; | |
| 67 | + /* | |
| 68 | + float samp = -1.f + 2.f * val; | |
| 79 | 69 | |
| 80 | − state = getButtonState("play"); | |
| 70 | + union unholy_t bw; | |
| 71 | + bw.f = samp; | |
| 72 | + bw.i = (bw.i | (op << 23)); | |
| 81 | 73 | |
| 82 | − if (state && !lastPlayState) | |
| 83 | − { | |
| 84 | − tSampler_play(&player); | |
| 85 | − } | |
| 74 | + DBG(String(samp) + " " + String(bw.f)); | |
| 75 | + */ | |
| 86 | 76 | |
| 87 | − lastPlayState = state; | |
| 77 | + // rounding test | |
| 78 | + /* | |
| 79 | + val = getSliderValue("rnd"); | |
| 80 | + | |
| 81 | + float to_rnd = -1.f + 2.f * val; | |
| 82 | + | |
| 83 | + float rnd = LEAF_round(to_rnd, 0.3f); | |
| 84 | + | |
| 85 | + DBG("to_rnd: " + String(to_rnd) + " rnd: " + String(rnd)); | |
| 86 | + */ | |
| 88 | 87 | } |
| 89 | 88 | |
| 90 | 89 | void LEAFTest_controllerInput (int cnum, float cval) |
| @@ -148,7 +147,7 @@ static void run_pool_test(void) · 57 unmodified lines | ||
| 148 | 147 | } |
| 149 | 148 | |
| 150 | 149 | leaf_pool_report(); |
| 151 | − | |
| 150 | + | |
| 152 | 151 | DBG("ALLOC BUFFER 2"); |
| 153 | 152 | size = 25; |
| 154 | 153 | |