History

Merge branch 'master' of https://github.com/spiricom/LEAF

spiricom committed 6 years ago

Commit 9e4dfd72 parents 20f08ff 217246c6 files · +159 −73Browse files

Unified · Split

6 files
  1. LEAF/Inc/leaf-oscillators.h +66 −0
  2. LEAF/Inc/leaf-sampling.h +1 −0
  3. LEAF/Src/leaf-math.c +2 −2
  4. LEAF/Src/leaf-oscillators.c +79 −0
  5. LEAF/Src/leaf-sampling.c +7 −0
  6. LEAF_JUCEPlugin/Source/MyTest.cpp +4 −71
LEAF/Inc/leaf-oscillators.h+66−0
@@ -90,6 +90,72 @@ extern "C" { · 89 unmodified lines
90 90
91 /*! @} */91 /*! @} */
92 92
93 //==============================================================================
94
95 typedef struct _tSine
96 {
97 float* sine;
98 int size;
99 float phase;
100 float inc,freq;
101 } _tSine;
102
103 typedef _tSine* tSine;
104
105 /*!
106 * @defgroup tsine tSine
107 * @ingroup oscillators
108 * @brief A cycle/sine waveform oscillator.
109 * @{
110 */
111
112 //! Initialize a tSine to the default LEAF mempool.
113 /*!
114 @param osc A pointer to the tSine to be initialized.
115 */
116 void tSine_init (tSine* const osc, int size);
117
118
119 //! Free a tSine from the default LEAF mempool.
120 /*!
121 @param osc A pointer to the tSine to be freed.
122 */
123 void tSine_free (tSine* const osc);
124
125
126 //! Initialize a tSine to a specified mempool.
127 /*!
128 @param osc A pointer to the tSine to be initialized.
129 @param pool A pointer to the tMempool to which the tSine should be initialized.
130 */
131 void tSine_initToPool (tSine* const osc, int size, tMempool* const pool);
132
133
134 //! Free a tSine from a specified mempool.
135 /*!
136 @param osc A pointer to the tSine to be freed.
137 @param pool A pointer to the tMempool from which the tSine should be freed.
138 */
139 void tSine_freeFromPool (tSine* const osc, tMempool* const pool);
140
141
142 //! Tick a tSine oscillator.
143 /*!
144 @param osc A pointer to the relevant tSine.
145 @return The ticked sample as a float from -1 to 1.
146 */
147 float tSine_tick (tSine* const osc);
148
149
150 //! Set the frequency of a tSine oscillator.
151 /*!
152 @param osc A pointer to the relevant tSine.
153 @param freq The frequency to set the oscillator to.
154 */
155 void tSine_setFreq (tSine* const osc, float freq);
156
157 /*! @} */
158
93 159
94 //==============================================================================160 //==============================================================================
95 161
LEAF/Inc/leaf-sampling.h+1−0
@@ -137,6 +137,7 @@ extern "C" { · 136 unmodified lines
137 137
138 void tSampler_setStart (tSampler* const, int32_t start);138 void tSampler_setStart (tSampler* const, int32_t start);
139 void tSampler_setEnd (tSampler* const, int32_t end);139 void tSampler_setEnd (tSampler* const, int32_t end);
140 void tSampler_setLength (tSampler* const, int32_t length);
140 141
141 static void handleStartEndChange (tSampler* const sp);142 static void handleStartEndChange (tSampler* const sp);
142 143
LEAF/Src/leaf-math.c+2−2
@@ -262,8 +262,8 @@ float LEAF_softClip(float val, float thresh) · 261 unmodified lines
262 262
263float LEAF_clip(float min, float val, float max)263float LEAF_clip(float min, float val, float max)
264{264{
265 int tempmin = min;265 float tempmin = min;
266 int tempmax = max;266 float tempmax = max;
267 if (min > max)267 if (min > max)
268 {268 {
269 tempmin = max;269 tempmin = max;
LEAF/Src/leaf-oscillators.c+79−0
@@ -91,6 +91,85 @@ void tCycleSampleRateChanged (tCycle* const cy) · 90 unmodified lines
91 c->inc = c->freq * leaf.invSampleRate;91 c->inc = c->freq * leaf.invSampleRate;
92}92}
93 93
94//========================================================================
95// Sine
96void tSine_init(tSine* const cy, int size)
97{
98 tSine_initToPool(cy, size, &leaf.mempool);
99}
100
101void tSine_free(tSine* const cy)
102{
103 tSine_freeFromPool(cy, &leaf.mempool);
104}
105
106void tSine_initToPool (tSine* const cy, int size, tMempool* const mp)
107{
108 _tMempool* m = *mp;
109 _tSine* c = *cy = (_tSine*) mpool_alloc(sizeof(_tSine), m);
110
111 c->size = size;
112 c->sine = (float*) mpool_alloc(sizeof(float) * c->size, m);
113 LEAF_generate_sine(c->sine, size);
114 c->inc = 0.0f;
115 c->phase = 0.0f;
116
117}
118
119void tSine_freeFromPool (tSine* const cy, tMempool* const mp)
120{
121 _tMempool* m = *mp;
122 _tSine* c = *cy;
123
124 mpool_free(c->sine, m);
125 mpool_free(c, m);
126}
127
128void tSine_setFreq(tSine* const cy, float freq)
129{
130 _tSine* c = *cy;
131
132 if (freq < 0.0f) c->freq = 0.0f;
133 else if (freq > 20480.0f) c->freq = 20480.0f;
134 else c->freq = freq;
135
136 c->inc = freq * leaf.invSampleRate;
137}
138
139float tSine_tick(tSine* const cy)
140{
141 _tSine* c = *cy;
142 float temp;
143 int intPart;
144 float fracPart;
145 float samp0;
146 float samp1;
147
148 // Phasor increment
149 c->phase += c->inc;
150 while (c->phase >= 1.0f) c->phase -= 1.0f;
151 while (c->phase < 0.0f) c->phase += 1.0f;
152
153 // Wavetable synthesis
154
155 temp = c->size * c->phase;
156 intPart = (int)temp;
157 fracPart = temp - (float)intPart;
158 samp0 = c->sine[intPart];
159 if (++intPart >= c->size) intPart = 0;
160 samp1 = c->sine[intPart];
161
162 return (samp0 + (samp1 - samp0) * fracPart);
163
164}
165
166void tSineSampleRateChanged (tSine* const cy)
167{
168 _tSine* c = *cy;
169
170 c->inc = c->freq * leaf.invSampleRate;
171}
172
94//========================================================================173//========================================================================
95/* Triangle */174/* Triangle */
96void tTriangle_init(tTriangle* const cy)175void tTriangle_init(tTriangle* const cy)
LEAF/Src/leaf-sampling.c+7−0
@@ -685,6 +685,13 @@ void tSampler_setEnd (tSampler* const sp, int32_t end) · 684 unmodified lines
685 p->targetend = -1;685 p->targetend = -1;
686}686}
687 687
688void tSampler_setLength (tSampler* const sp, int32_t length)
689{
690 _tSampler* p = *sp;
691 if (length == 0) length = 1;
692 tSampler_setEnd(sp, p->start + length);
693}
694
688void tSampler_setRate (tSampler* const sp, float rate)695void tSampler_setRate (tSampler* const sp, float rate)
689{696{
690 _tSampler* p = *sp;697 _tSampler* p = *sp;
LEAF_JUCEPlugin/Source/MyTest.cpp+4−71
@@ -16,22 +16,7 @@ static void leaf_pool_report(void); · 15 unmodified lines
16static void leaf_pool_dump(void);16static void leaf_pool_dump(void);
17static void run_pool_test(void);17static void run_pool_test(void);
18 18
19tNoise noise;19tSine sine;
20tSVF bp1;
21tSVF bp2;
22tFormantShifter fs;
23
24tSampler samp;
25tBuffer buff;
26tEnvelope env;
27
28tAutotune at;
29
30tTriangle tri;
31
32tMinBLEP minblep;
33
34tPhasor phasor;
35 20
36float gain;21float gain;
37float freq;22float freq;
@@ -48,68 +33,16 @@ char memory[MSIZE]; · 10 unmodified lines
48void LEAFTest_init (float sampleRate, int blockSize)33void LEAFTest_init (float sampleRate, int blockSize)
49{34{
50 LEAF_init(sampleRate, blockSize, memory, MSIZE, &getRandomFloat);35 LEAF_init(sampleRate, blockSize, memory, MSIZE, &getRandomFloat);
51
52 tTriangle_init(&tri);
53
54 tMinBLEP_init(&minblep);
55
56 tPhasor_init(&phasor);
57// tNoise_init(&noise, WhiteNoise);
58//
59// tAutotune_init(&at, 1, 1024, 512);
60
61// tSVF_init(&bp1, SVFTypeBandpass, 100, 4.0f);
62// tSVF_init(&bp2, SVFTypeBandpass, 1000, 4.0f);
63//
64// tFormantShifter_init(&fs, 20);
65//
66// // Init and set record
67// tBuffer_init (&buff, leaf.sampleRate); // init, 1 second buffer
68// tBuffer_setRecordMode (&buff, RecordOneShot); // RecordOneShot records once through
69//
70// // Init and set play
71// tSampler_init (&samp, &buff); // init, give address of record buffer
72// tSampler_setMode (&samp, PlayLoop); //set in Loop Mode
73// tSampler_setRate(&samp, 1.763f); // Rate of 1.0
74}
75 36
76inline double getSawFall(double angle) {
77
78 angle = fmod(angle + double_Pi, 2*double_Pi); // shift x
79 double sample = angle/double_Pi - double(1); // computer as remainder
80
81 return sample;
82 37
38 tSine_init(&sine, 1000);
39 tSine_setFreq(&sine, 400);
83}40}
84 41
85float LEAFTest_tick (float input)42float LEAFTest_tick (float input)
86{43{
87// float sample = tNoise_tick(&noise);
88// sample *= 0.5f;
89// float b = tSVF_tick(&bp1, sample);
90// b += tSVF_tick(&bp2, sample);
91//
92// return (tFormantShifter_tick(&fs, input));
93//
94// tBuffer_tick(&buff, input);
95
96// return tSampler_tick(&samp);
97
98// tAutotune_setFreq(&at, 440.0f, 0);
99
100// return tAutotune_tick(&at, input)[0];
101
102 tPhasor_setFreq(&phasor, y);
103
104
105 float sample = tPhasor_tick(&phasor) * 2.0f - 1.0f;
106
107 if (phasor->phaseDidReset)
108 {
109 tMinBLEP_addBLEP(&minblep, 0.0f, 2, 0.0f);
110 }
111 44
112 return tMinBLEP_tick(&minblep, sample);45 return tSine_tick(&sine);
113}46}
114 47
115int firstFrame = 1;48int firstFrame = 1;

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