diff options
| author | Jonathan Bradley <jcb@pikum.xyz> | 2025-07-11 11:41:21 -0400 |
|---|---|---|
| committer | Jonathan Bradley <jcb@pikum.xyz> | 2025-07-11 11:41:21 -0400 |
| commit | f88ca0bc946bae086e02eacdc6c129f00e2e07e3 (patch) | |
| tree | eb8975ec505315e7f53a15ded32fb0cfd6b57731 /src/audio-impl-shared.cpp | |
| parent | 1fd2b900a5f97379e80adc411d3763f9ba811570 (diff) | |
pke: audio: fx boilerplate, low-pass spatial
Diffstat (limited to 'src/audio-impl-shared.cpp')
| -rw-r--r-- | src/audio-impl-shared.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/audio-impl-shared.cpp b/src/audio-impl-shared.cpp new file mode 100644 index 0000000..0c3c730 --- /dev/null +++ b/src/audio-impl-shared.cpp @@ -0,0 +1,22 @@ + +#include "audio-impl-shared.hpp" + +float pke_audio_fx_reverb(float *buffer, uint64_t buffer_len, uint64_t buffer_idx, pke_audio_fx_params_reverb *params) { + if (buffer_idx >= buffer_len-1) return 0.f; + // simple feedback + return buffer[buffer_idx - 1] * params->reverb_strength; +} + +float pke_audio_fx_delay(float *buffer, uint64_t buffer_len, uint64_t buffer_idx, pke_audio_fx_params_delay *params) { + if (buffer_idx >= buffer_len-1) return 0.f; + return buffer[buffer_idx - params->delay_frames]; +} + +float pke_audio_fx_low_pass_filter(float *buffer, uint64_t buffer_len, uint64_t buffer_idx, pke_audio_fx_params_low_pass_filter *params) { + if (buffer_idx >= buffer_len-1) return 0.f; + float rc = 1.f / std::numbers::pi * 2.0 * params->cutoff_freq; + float dt = 1.f / 48000.f; // TODO reference global or pass this in + float alpha = dt / (rc + dt); + params->prev_output = (alpha * buffer[buffer_idx]) + ((1.f - alpha) * params->prev_output); + return params->prev_output; +} |
