|
|
@ -22,38 +22,38 @@ |
|
|
|
class AudioFilterFIR_F32 : public AudioStream_F32 |
|
|
|
class AudioFilterFIR_F32 : public AudioStream_F32 |
|
|
|
{ |
|
|
|
{ |
|
|
|
//GUI: inputs:1, outputs:1 //this line used for automatic generation of GUI node
|
|
|
|
//GUI: inputs:1, outputs:1 //this line used for automatic generation of GUI node
|
|
|
|
public: |
|
|
|
public: |
|
|
|
AudioFilterFIR_F32(void): AudioStream_F32(1,inputQueueArray), coeff_p(FIR_F32_PASSTHRU) { |
|
|
|
AudioFilterFIR_F32(void): AudioStream_F32(1,inputQueueArray),
|
|
|
|
} |
|
|
|
coeff_p(FIR_F32_PASSTHRU), n_coeffs(1), configured_block_size(0) { } |
|
|
|
void begin(const float32_t *cp, int n_coeffs) { |
|
|
|
|
|
|
|
coeff_p = cp; |
|
|
|
//initialize the FIR filter by giving it the filter coefficients
|
|
|
|
// Initialize FIR instance (ARM DSP Math Library)
|
|
|
|
void begin(const float32_t *cp, const int _n_coeffs) { begin(cp, _n_coeffs, AUDIO_BLOCK_SAMPLES); } //assume that the block size is the maximum
|
|
|
|
if (coeff_p && (coeff_p != FIR_F32_PASSTHRU) && n_coeffs <= FIR_MAX_COEFFS) { |
|
|
|
void begin(const float32_t *cp, const int _n_coeffs, const int block_size) { //or, you can provide it with the block size
|
|
|
|
arm_fir_init_f32(&fir_inst, n_coeffs, (float32_t *)coeff_p, &StateF32[0], AUDIO_BLOCK_SAMPLES); |
|
|
|
coeff_p = cp; |
|
|
|
//if (arm_fir_init_f32(&fir_inst, n_coeffs, (float32_t *)coeff_p, &StateF32[0], AUDIO_BLOCK_SAMPLES) != ARM_MATH_SUCCESS) {
|
|
|
|
n_coeffs = _n_coeffs; |
|
|
|
// n_coeffs must be an even number, 4 or larger
|
|
|
|
|
|
|
|
//coeff_p = NULL;
|
|
|
|
// Initialize FIR instance (ARM DSP Math Library)
|
|
|
|
//}
|
|
|
|
if (coeff_p && (coeff_p != FIR_F32_PASSTHRU) && n_coeffs <= FIR_MAX_COEFFS) { |
|
|
|
} |
|
|
|
arm_fir_init_f32(&fir_inst, n_coeffs, (float32_t *)coeff_p, &StateF32[0], block_size); |
|
|
|
} |
|
|
|
configured_block_size = block_size; |
|
|
|
void end(void) { |
|
|
|
} |
|
|
|
coeff_p = NULL; |
|
|
|
} |
|
|
|
} |
|
|
|
void end(void) { coeff_p = NULL; } |
|
|
|
virtual void update(void); |
|
|
|
virtual void update(void); |
|
|
|
|
|
|
|
|
|
|
|
void setBlockDC(void) { |
|
|
|
//void setBlockDC(void) {} //helper function that sets this up for a first-order HP filter at 20Hz
|
|
|
|
//helper function that sets this up for a first-order HP filter at 20Hz
|
|
|
|
|
|
|
|
|
|
|
|
private: |
|
|
|
} |
|
|
|
audio_block_f32_t *inputQueueArray[1]; |
|
|
|
private: |
|
|
|
|
|
|
|
audio_block_f32_t *inputQueueArray[1]; |
|
|
|
// pointer to current coefficients or NULL or FIR_PASSTHRU
|
|
|
|
|
|
|
|
const float32_t *coeff_p; |
|
|
|
// pointer to current coefficients or NULL or FIR_PASSTHRU
|
|
|
|
int n_coeffs; |
|
|
|
const float32_t *coeff_p; |
|
|
|
int configured_block_size; |
|
|
|
|
|
|
|
|
|
|
|
// ARM DSP Math library filter instance
|
|
|
|
// ARM DSP Math library filter instance
|
|
|
|
arm_fir_instance_f32 fir_inst; |
|
|
|
arm_fir_instance_f32 fir_inst; |
|
|
|
float32_t StateF32[AUDIO_BLOCK_SAMPLES + FIR_MAX_COEFFS]; |
|
|
|
float32_t StateF32[AUDIO_BLOCK_SAMPLES + FIR_MAX_COEFFS]; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -78,14 +78,21 @@ void AudioFilterFIR_F32::update(void) |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// get a block for the FIR output
|
|
|
|
// get a block for the FIR output
|
|
|
|
b_new = AudioStream_F32::allocate_f32(); |
|
|
|
b_new = AudioStream_F32::allocate_f32(); |
|
|
|
if (b_new) { |
|
|
|
if (b_new) { |
|
|
|
arm_fir_f32(&fir_inst, (float32_t *)block->data, (float32_t *)b_new->data, block->length); |
|
|
|
//check to make sure our FIR instance has the right size
|
|
|
|
AudioStream_F32::transmit(b_new); // send the FIR output
|
|
|
|
if (block->length != configured_block_size) { |
|
|
|
AudioStream_F32::release(b_new); |
|
|
|
//doesn't match. re-initialize
|
|
|
|
} |
|
|
|
Serial.println("AudioFilterFIR_F32: block size doesn't match. Re-initializing FIR."); |
|
|
|
AudioStream_F32::release(block); |
|
|
|
begin(coeff_p, n_coeffs, block->length); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//apply the FIR
|
|
|
|
|
|
|
|
arm_fir_f32(&fir_inst, (float32_t *)block->data, (float32_t *)b_new->data, block->length); |
|
|
|
|
|
|
|
AudioStream_F32::transmit(b_new); // send the FIR output
|
|
|
|
|
|
|
|
AudioStream_F32::release(b_new); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
AudioStream_F32::release(block); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#endif |
|
|
|
#endif |
|
|
|