From 3439f3a497da84a016a6aea96f17d831f80c6115 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Izzo?= Date: Sun, 27 Jun 2021 19:00:06 +0200 Subject: [PATCH] Add invert phase DSP filter --- openrtx/include/dsp.h | 9 +++++++++ openrtx/src/dsp.cpp | 6 ++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/openrtx/include/dsp.h b/openrtx/include/dsp.h index 3d031db3..ce966d2d 100644 --- a/openrtx/include/dsp.h +++ b/openrtx/include/dsp.h @@ -54,6 +54,15 @@ void dsp_pwmCompensate(audio_sample_t *buffer, size_t length); */ void dsp_dcRemoval(audio_sample_t *buffer, size_t length); +/* + * Inverts the phase of the audio buffer passed as paramenter. + * The buffer will be processed in place to save memory. + * + * @param buffer: the buffer to be used as both source and destination. + * @param length: the length of the input buffer. + */ +void dsp_invertPhase(audio_sample_t *buffer, uint16_t length); + #ifdef __cplusplus } diff --git a/openrtx/src/dsp.cpp b/openrtx/src/dsp.cpp index d4ff898c..6f367c08 100644 --- a/openrtx/src/dsp.cpp +++ b/openrtx/src/dsp.cpp @@ -57,9 +57,11 @@ void dsp_applyFIR(audio_sample_t *buffer, uint16_t length, std::array taps) { - for(int i = length - 1; i >= 0; i--) { + for(int i = length - 1; i >= 0; i--) + { float acc = 0.0f; - for(uint16_t j = 0; j < order; j++) { + for(uint16_t j = 0; j < order; j++) + { if (i >= j) acc += buffer[i - j] * taps[j]; }