diff --git a/AudioFilterConvolution_F32.cpp b/AudioFilterConvolution_F32.cpp index d38a8e2..6052903 100644 --- a/AudioFilterConvolution_F32.cpp +++ b/AudioFilterConvolution_F32.cpp @@ -51,7 +51,7 @@ void AudioFilterConvolution_F32::impulse(float32_t *FIR_coef) arm_cfft_f32( &arm_cfft_sR_f32_len1024, FIR_filter_mask, 0, 1); // for 1st time thru, zero out the last sample buffer to 0 - arm_fill_f32(0, last_sample_buffer_L, BUFFER_SIZE *4); + arm_fill_f32(0, last_sample_buffer_L, 128*4); state = 0; enabled = 1; //enable audio stream again @@ -79,9 +79,9 @@ void AudioFilterConvolution_F32::update(void) l++; } } - arm_copy_f32 (&buffer[0], &tbuffer[0], BUFFER_SIZE*4); + arm_copy_f32 (&buffer[0], &tbuffer[0], 128*4); bp = block->data; - for (int i = 0; i < AUDIO_BLOCK_SAMPLES; i++) { + for (int i = 0; i < 128; i++) { buffer[i] = *bp; *bp++ = tbuffer[i]; } @@ -92,7 +92,7 @@ void AudioFilterConvolution_F32::update(void) case 1: bp = block->data; - for (int i = 0; i < AUDIO_BLOCK_SAMPLES; i++) { + for (int i = 0; i < 128; i++) { buffer[128+i] = *bp; *bp++ = tbuffer[i+128]; } @@ -103,7 +103,7 @@ void AudioFilterConvolution_F32::update(void) case 2: bp = block->data; - for (int i = 0; i < AUDIO_BLOCK_SAMPLES; i++) { + for (int i = 0; i < 128; i++) { buffer[256 + i] = *bp; *bp++ = tbuffer[i+256]; // tbuffer contains results of last FFT/multiply/iFFT processing (convolution filtering) } @@ -117,7 +117,7 @@ void AudioFilterConvolution_F32::update(void) case 3: bp = block->data; - for (int i = 0; i < AUDIO_BLOCK_SAMPLES; i++) { + for (int i = 0; i < 128; i++) { buffer[384 + i] = *bp; *bp++ = tbuffer[i + 384]; // tbuffer contains results of last FFT/multiply/iFFT processing (convolution filtering) } @@ -165,7 +165,7 @@ float AudioFilterConvolution_F32::m_sinc(int m, float fc) { // fc is f_cut/(Fsamp/2) // m is between -M and M step 2 // - float x = m*PIH; + float x = m*PIH_F32; if(m == 0) return 1.0f; else @@ -229,8 +229,8 @@ void AudioFilterConvolution_F32::calc_FIR_coeffs if(2*ii==nc) continue; float x =(float)(2*ii - nc)/(float)nc; float w = Izero(Beta*sqrtf(1.0f - x*x))/izb; // Kaiser window - coeffs[ii-1] = 1.0f/(PIH*(float)(ii-nc/2)) * w ; - //coeffs[2*ii+1] = 1.0f/(PIH*(float)(ii-nc/2)) * w ; + coeffs[ii-1] = 1.0f/(PIH_F32*(float)(ii-nc/2)) * w ; + //coeffs[2*ii+1] = 1.0f/(PIH_F32*(float)(ii-nc/2)) * w ; } return; // From Hilbert design } @@ -249,11 +249,11 @@ void AudioFilterConvolution_F32::calc_FIR_coeffs } else if (type==BANDPASS) { - for(jj=0; jj< nc+1; jj++) coeffs[jj] *= 2.0f*cosf(PIH*(2*jj-nc)*fc); + for(jj=0; jj< nc+1; jj++) coeffs[jj] *= 2.0f*cosf(PIH_F32*(2*jj-nc)*fc); } else if (type==BANDREJECT) { - for(jj=0; jj< nc+1; jj++) coeffs[jj] *= -2.0f*cosf(PIH*(2*jj-nc)*fc); + for(jj=0; jj< nc+1; jj++) coeffs[jj] *= -2.0f*cosf(PIH_F32*(2*jj-nc)*fc); coeffs[nc/2] += 1; } } // END calc_FIR_coef diff --git a/AudioFilterConvolution_F32.h b/AudioFilterConvolution_F32.h index b3a557b..cf8f6c0 100644 --- a/AudioFilterConvolution_F32.h +++ b/AudioFilterConvolution_F32.h @@ -95,6 +95,8 @@ * See the example TestConvolutionFilter.ino for more inforation on the * use of this class. * + * Removed #defines that were not needed. Thanks K7MDL. Bob 6 Mar 2022 + * * ************************************************************ */ #ifndef AudioFilterConvolution_F32_h_ @@ -105,10 +107,8 @@ #include #define MAX_NUMCOEF 513 -#define TPI 6.28318530717959f -#define PIH 1.57079632679490f -#define FOURPI 2.0 * TPI -#define SIXPI 3.0 * TPI + +#define PIH_F32 1.5707963f #define LOWPASS 0 #define HIGHPASS 1 @@ -122,7 +122,7 @@ class AudioFilterConvolution_F32 : public: AudioFilterConvolution_F32(void) : AudioStream_F32(1, inputQueueArray_F32) { fs = AUDIO_SAMPLE_RATE; - //block_size = AUDIO_BLOCK_SAMPLES; + //block_size = 128; // Always }; AudioFilterConvolution_F32(const AudioSettings_F32 &settings) : AudioStream_F32(1, inputQueueArray_F32) { // Performs the first initialize @@ -139,7 +139,6 @@ public: //#define Alternate filter init private: - #define BUFFER_SIZE 128 float32_t fs; audio_block_f32_t *inputQueueArray_F32[1]; float32_t *sp_L; @@ -151,7 +150,6 @@ private: int enabled=0; float32_t FIR_Coef[MAX_NUMCOEF]; const uint32_t FFT_length = 1024; -// float32_t FIR_coef[2048] __attribute__((aligned(4))); <<<<<<<<<<<<<<< float32_t FIR_filter_mask[2048] __attribute__((aligned(4))); float32_t buffer[2048] __attribute__((aligned(4))); float32_t tbuffer[2048]__attribute__((aligned(4)));