Generate audio samples.
The output samples will continue from where the samples generated by the previous hexwave_generate_samples() on this oscillator ended.
192{
199 float dt = (float)
fabs(freq);
200 float recip_dt = (dt == 0.0f) ? 0.0f : 1.0f / dt;
201
203
204
205 if (num_samples <= 0)
206 return;
207
208
210
211 if (
hex->prev_dt != dt) {
212
213 float slope;
214 for (j=1; j < 6; ++j)
216 break;
218 if (slope != 0)
219 hex_blamp(output, 0, (dt -
hex->prev_dt)*slope, engine);
221 }
222
223
224 memset(output, 0,
sizeof(
float)*num_samples);
225 memset(temp_output, 0, 2*engine->
width*
sizeof(
float));
226
227 if (num_samples >= engine->
width) {
228 memcpy(output,
hex->buffer, buffered_length);
229 } else {
230
231 memcpy(temp_output,
hex->buffer, buffered_length);
232 }
233
234 for (pass=0; pass < 2; ++pass) {
236 float *out;
237
238
239
240
241
242
243
244 if (pass == 0) {
245 if (num_samples < engine->
width)
246 continue;
247
248 out = output;
249 i0 = 0;
250 i1 = num_samples - engine->
width;
251 } else {
252
253 out = temp_output;
254 i0 = 0;
255 if (num_samples >= engine->
width)
257 else
258 i1 = num_samples;
259 }
260
261
262 for (j=0; j < 8; ++j)
264 break;
265
266 i = i0;
267 for(;;) {
268 while (
t < vert[j+1].
t) {
269 if (i == i1)
271 out[i+halfw] += vert[j].
v + vert[j].
s*(
t - vert[j].
t);
273 ++i;
274 }
275
276
277 if (vert[j].
t == vert[j+1].
t)
278 hex_blep(out+i, recip_dt*(
t-vert[j+1].
t), (vert[j+1].v - vert[j].v), engine);
279 hex_blamp(out+i, recip_dt*(
t-vert[j+1].
t), dt*(vert[j+1].s - vert[j].s), engine);
280 ++j;
281
282 if (j == 8) {
283
284 j = 0;
286 if (
hex->have_pending) {
287 float prev_s0 = vert[j].
s;
288 float prev_v0 = vert[j].
v;
289 hex->current =
hex->pending;
290 hex->have_pending = 0;
292
293
294 if (vert[j].v != prev_v0)
295 hex_blep (out+i, recip_dt*
t, (vert[j].v - prev_v0), engine);
296 if (vert[j].s != prev_s0)
297 hex_blamp(out+i, recip_dt*
t, dt*(vert[j].s - prev_s0), engine);
298 }
299 }
300 }
302 ;
303 }
304
305
306 if (num_samples >= engine->
width) {
307
308 for (i=0; i < engine->
width; ++i)
309 output[num_samples-engine->
width + i] += temp_output[i];
311 } else {
312 for (i=0; i < num_samples; ++i)
313 output[i] = temp_output[i];
314 memcpy(
hex->buffer, temp_output+num_samples, buffered_length);
315 }
316
318}
void * memcpy(void *dest, const void *src, size_t n) FL_NOEXCEPT
double fabs(double value) FL_NOEXCEPT
static void hex_blep(float *output, float time_since_transition, float scale, HexWaveEngine *engine) FL_NOEXCEPT
void * memset(void *s, int c, size_t n) FL_NOEXCEPT
static void hexwave_generate_linesegs(hexvert vert[9], HexWave *hex, float dt) FL_NOEXCEPT
static void hex_blamp(float *output, float time_since_transition, float scale, HexWaveEngine *engine) FL_NOEXCEPT
int32_t width
Width of fixup in samples (4..64)
Engine state holding BLEP/BLAMP tables.
#define FL_STB_HEXWAVE_MAX_BLEP_LENGTH