Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ideoforms/signalflow
Browse files Browse the repository at this point in the history
  • Loading branch information
ideoforms committed Jul 22, 2024
2 parents 066225f + e63d086 commit e41eabe
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 23 deletions.
2 changes: 1 addition & 1 deletion source/include/signalflow/core/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ typedef RingBuffer<sample> 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.
Expand Down
52 changes: 30 additions & 22 deletions source/src/node/processors/panning/spatial-environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,30 +137,38 @@ 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 amp = (this->radius->out[0][frame] - distance) / this->radius->out[0][frame];
// if (amp < 0)
// amp = 0;
float distance_m = distance * 0.001;
float attenuation = 1.0 / (distance_m * distance_m);
// float attenuation = 1.0;
if (frame == 0 && channel == 0)
{
// printf("distance %.4f, attenuation: %.4f\n", distance, attenuation);
// printf("use_delays: %f\n", use_delays->out[0][frame]);
}

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)
{
// printf("distance %.4fm, attenuation: %.4f, delay_samples: %.4f\n", distance, attenuation, delay_samples);
}

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;
// }
}
}
}
Expand Down

0 comments on commit e41eabe

Please sign in to comment.