diff --git a/source/include/signalflow/core/constants.h b/source/include/signalflow/core/constants.h index 2f164f0a..2303661a 100644 --- a/source/include/signalflow/core/constants.h +++ b/source/include/signalflow/core/constants.h @@ -48,7 +48,7 @@ typedef RingBuffer SampleRingBuffer; * TODO: Turn this into a run-time config parameter, and set default to 2 * Otherwise memory usage is very high by default *-----------------------------------------------------------------------*/ -#define SIGNALFLOW_NODE_INITIAL_OUTPUT_BUFFERS 64 +#define SIGNALFLOW_NODE_INITIAL_OUTPUT_BUFFERS 256 /*------------------------------------------------------------------------ * Max supported number of FFT bins. diff --git a/source/src/node/processors/panning/spatial-environment.cpp b/source/src/node/processors/panning/spatial-environment.cpp index c065389a..ba8b86f9 100644 --- a/source/src/node/processors/panning/spatial-environment.cpp +++ b/source/src/node/processors/panning/spatial-environment.cpp @@ -137,14 +137,26 @@ void SpatialPanner::process(Buffer &out, int num_frames) { // m/s float SPEED_OF_SOUND = 343.0; - float distance = sqrtf(powf(speaker->x - this->x->out[0][frame], 2) + powf(speaker->y - this->y->out[0][frame], 2) + powf(speaker->z - this->z->out[0][frame], 2)); - - float distance_m = distance; - float attenuation = 1.0 / (distance_m * distance_m); - - if (use_delays->out[0][frame]) - { - float delay_seconds = distance_m / SPEED_OF_SOUND; + // float distance = sqrtf(powf(speaker->x - this->x->out[0][frame], 2) + powf(speaker->y - this->y->out[0][frame], 2) + powf(speaker->z - this->z->out[0][frame], 2)); + float dx = speaker->x - this->x->out[0][frame]; + float dy = speaker->y - this->y->out[0][frame]; + float dz = speaker->z - this->z->out[0][frame]; + float distance_squared = dx * dx + dy * dy + dz * dz; + + float MIN_DISTANCE_SQUARED = 0.1; + if (distance_squared < MIN_DISTANCE_SQUARED) + distance_squared = MIN_DISTANCE_SQUARED; + + float distance = sqrtf(distance_squared); + + // float attenuation = 1.0 / distance_m; // 2024-05-29 + float attenuation = (1.0f / distance_squared) * 0.25f; + // float attenuation = (1.0 / powf(distance, 1.5)) * 0.1; + // float attenuation = (distance_squared) * 0.1; + + // if (use_delays->out[0][frame]) + // { + float delay_seconds = distance / SPEED_OF_SOUND; float delay_samples = delay_seconds * this->graph->get_sample_rate(); if (frame == 0) { @@ -152,11 +164,11 @@ void SpatialPanner::process(Buffer &out, int num_frames) } out[channel][frame] = this->buffer->get(-delay_samples) * attenuation; - } - else - { - out[channel][frame] = this->buffer->get(-1) * attenuation; - } + // } + // else + // { + // out[channel][frame] = this->buffer->get(-1) * attenuation; + // } } } }