Width can be larger than 64 if you define FL_STB_HEXWAVE_MAX_BLEP_LENGTH to a larger value
336{
339
341 int32_t half = halfwidth*oversample;
344
345 #ifdef FL_STB_HEXWAVE_NO_ALLOCATION
346 (void)blep_buffer_count;
347 if (user_buffer == nullptr)
348 return nullptr;
349 float *buffers = user_buffer;
350 #else
351 float *buffers = user_buffer ? user_buffer : (
float *)
malloc(
sizeof(
float) * n * 2);
352 #endif
353
354 float *
step = buffers+0*n;
355 float *ramp = buffers+1*n;
356 float *blep_buffer, *blamp_buffer;
357 double integrate_impulse=0, integrate_step=0;
359
360 bool ownsBuffers = false;
361 if (user_buffer == 0) {
362 #ifndef FL_STB_HEXWAVE_NO_ALLOCATION
363 blep_buffer = (
float *)
malloc(
sizeof(
float)*blep_buffer_count);
364 blamp_buffer = (
float *)
malloc(
sizeof(
float)*blep_buffer_count);
365 ownsBuffers = true;
366 #else
367 blep_buffer = nullptr;
368 blamp_buffer = nullptr;
369 #endif
370 } else {
371 blep_buffer = ramp+n;
372 blamp_buffer = blep_buffer + blep_buffer_count;
373 }
374
375
376 for (i=0; i < n; ++i) {
377 for (j=0; j < 16; ++j) {
378 float sinc_t = 3.141592f* (i-half) / oversample;
379 float sinc = (i==half) ? 1.0f : (float)
sin(static_cast<double>(sinc_t)) / (sinc_t);
380 float wt = 2.0f*3.1415926f * i / (n-1);
381 float window = (float) (0.355768 - 0.487396*
cos(
static_cast<double>(wt)) + 0.144232*
cos(2*
static_cast<double>(wt)) - 0.012604*
cos(3*
static_cast<double>(wt)));
382 double value = window * sinc;
383 integrate_impulse +=
value/16;
384 integrate_step += integrate_impulse/16;
385 }
386 step[i] = (float) integrate_impulse;
387 ramp[i] = (float) integrate_step;
388 }
389
390
391 for (i=0; i < n; ++i) {
393 ramp[i] = ramp[i] * (float) (halfwidth / ramp[n-1]);
394 }
395
396
397 for (j=0; j <= oversample; ++j) {
398 for (i=0; i <
width; ++i) {
399 blep_buffer [j*
width+i] =
step[j+i*oversample];
400 blamp_buffer[j*
width+i] = ramp[j+i*oversample];
401 }
402 }
403
404
405
406
407 for (j=0; j <= oversample; ++j) {
408
409 for (i=halfwidth; i <
width; ++i)
410 blep_buffer [j*
width+i] -= 1.0f;
411
412 for (i=halfwidth; i <
width; ++i)
413 blamp_buffer[j*
width+i] -= (j+i*oversample-half)*(1.0f/oversample);
414 }
415
416
417 #ifndef FL_STB_HEXWAVE_NO_ALLOCATION
419 engine->
blep = blep_buffer;
420 engine->blamp = blamp_buffer;
421 engine->width =
width;
422 engine->oversample = oversample;
423 engine->ownsBuffers = ownsBuffers;
424
425 if (user_buffer == 0)
427
428 return engine;
429 #else
430 (void)ownsBuffers;
431 return nullptr;
432 #endif
433}
void * malloc(size_t size)
enable_if< is_fixed_point< T >::value, T >::type cos(T angle) FL_NOEXCEPT
float * blep
Band-limited step table.
Engine state holding BLEP/BLAMP tables.
constexpr int type_rank< T >::value
constexpr enable_if< is_fixed_point< T >::value, T >::type step(T edge, T x) FL_NOEXCEPT
enable_if< is_fixed_point< T >::value, T >::type sin(T angle) FL_NOEXCEPT
#define FL_STB_HEXWAVE_MAX_BLEP_LENGTH