Przeglądaj źródła

Reformat FIR Filter spacing

dds
PaulStoffregen 10 lat temu
rodzic
commit
0933185d86
9 zmienionych plików z 58 dodań i 66 usunięć
  1. +0
    -0
      examples/Effects/Filter_FIR/Filter_FIR.ino
  2. +0
    -0
      examples/Effects/Filter_FIR/bandp_1200_1700.h
  3. +0
    -0
      examples/Effects/Filter_FIR/filters.cpp
  4. +0
    -0
      examples/Effects/Filter_FIR/filters.h
  5. +0
    -0
      examples/Effects/Filter_FIR/lopass_4000_44100.h
  6. +0
    -0
      examples/Effects/Filter_FIR/screencap_bandpass.jpg
  7. +0
    -0
      examples/Effects/Filter_FIR/screencap_lowpass.jpg
  8. +38
    -35
      filter_fir.cpp
  9. +20
    -31
      filter_fir.h

examples/Effects/fir_filter/fir_filter.ino → examples/Effects/Filter_FIR/Filter_FIR.ino Wyświetl plik


examples/Effects/fir_filter/bandp_1200_1700.h → examples/Effects/Filter_FIR/bandp_1200_1700.h Wyświetl plik


examples/Effects/fir_filter/filters.cpp → examples/Effects/Filter_FIR/filters.cpp Wyświetl plik


examples/Effects/fir_filter/filters.h → examples/Effects/Filter_FIR/filters.h Wyświetl plik


examples/Effects/fir_filter/lopass_4000_44100.h → examples/Effects/Filter_FIR/lopass_4000_44100.h Wyświetl plik


examples/Effects/fir_filter/screencap_bandpass.jpg → examples/Effects/Filter_FIR/screencap_bandpass.jpg Wyświetl plik


examples/Effects/fir_filter/screencap_lowpass.jpg → examples/Effects/Filter_FIR/screencap_lowpass.jpg Wyświetl plik


+ 38
- 35
filter_fir.cpp Wyświetl plik

@@ -22,54 +22,57 @@

#include "filter_fir.h"

void AudioFilterFIR::begin(short *cp,int n_coeffs)
void AudioFilterFIR::begin(short *cp, int n_coeffs)
{
// pointer to coefficients
coeff_p = cp;
// Initialize FIR instances for the left and right channels
if(coeff_p && (coeff_p != FIR_PASSTHRU)) {
arm_fir_init_q15(&l_fir_inst, n_coeffs, coeff_p, &l_StateQ15[0], AUDIO_BLOCK_SAMPLES);
}
// pointer to coefficients
coeff_p = cp;
// Initialize FIR instances for the left and right channels
if(coeff_p && (coeff_p != FIR_PASSTHRU)) {
arm_fir_init_q15(&l_fir_inst, n_coeffs, coeff_p,
&l_StateQ15[0], AUDIO_BLOCK_SAMPLES);
}
}

// This has the same effect as begin(NULL,0);
void AudioFilterFIR::stop(void)
{
coeff_p = NULL;
coeff_p = NULL;
}


void AudioFilterFIR::update(void)
{
audio_block_t *block,*b_new;
audio_block_t *block,*b_new;
// If there's no coefficient table, give up.
if(coeff_p == NULL)return;
// If there's no coefficient table, give up.
if(coeff_p == NULL) return;

// do passthru
if(coeff_p == FIR_PASSTHRU) {
// Just passthrough
block = receiveReadOnly(0);
if(block) {
transmit(block,0);
release(block);
}
return;
}
// Left Channel
block = receiveReadOnly(0);
// get a block for the FIR output
b_new = allocate();
if(block && b_new) {
if(arm_fast)
arm_fir_fast_q15(&l_fir_inst, (q15_t *)block->data, (q15_t *)b_new->data, AUDIO_BLOCK_SAMPLES);
else
arm_fir_q15(&l_fir_inst, (q15_t *)block->data, (q15_t *)b_new->data, AUDIO_BLOCK_SAMPLES);
// send the FIR output to the left channel
transmit(b_new,0);
}
if(block)release(block);
if(b_new)release(b_new);
// do passthru
if (coeff_p == FIR_PASSTHRU) {
// Just passthrough
block = receiveReadOnly(0);
if(block) {
transmit(block,0);
release(block);
}
return;
}
// Left Channel
block = receiveReadOnly(0);
// get a block for the FIR output
b_new = allocate();
if (block && b_new) {
if (arm_fast) {
arm_fir_fast_q15(&l_fir_inst, (q15_t *)block->data,
(q15_t *)b_new->data, AUDIO_BLOCK_SAMPLES);
} else {
arm_fir_q15(&l_fir_inst, (q15_t *)block->data,
(q15_t *)b_new->data, AUDIO_BLOCK_SAMPLES);
}
transmit(b_new,0); // send the FIR output
}
if (block) release(block);
if (b_new) release(b_new);
}



+ 20
- 31
filter_fir.h Wyświetl plik

@@ -26,45 +26,34 @@
#include "AudioStream.h"
#include "arm_math.h"

#define USE_FAST_FIR true
#define USE_SLOW_FIR false


// Maximum number of coefficients in a FIR filter
// The audio breaks up with 128 coefficients so a
// maximum of 150 is more than sufficient
#define MAX_COEFFS 150

// Indicates that the code should just pass through the audio
// without any filtering (as opposed to doing nothing at all)
#define FIR_PASSTHRU ((short *) 1)

class AudioFilterFIR :
public AudioStream
#define FIR_MAX_COEFFS 120

class AudioFilterFIR : public AudioStream
{
public:
AudioFilterFIR(const boolean a_f):
AudioStream(1,inputQueueArray), arm_fast(a_f), coeff_p(NULL)
{
}

void begin(short *coeff_p,int n_coeffs);
virtual void update(void);
void stop(void);
AudioFilterFIR(const boolean a_f): AudioStream(1,inputQueueArray),
arm_fast(a_f), coeff_p(NULL) {
}
void begin(short *coeff_p,int n_coeffs);
virtual void update(void);
void stop(void);
private:
audio_block_t *inputQueueArray[1];
// arm state arrays and FIR instances for left and right channels
// the state arrays are defined to handle a maximum of MAX_COEFFS
// coefficients in a filter
q15_t l_StateQ15[AUDIO_BLOCK_SAMPLES + MAX_COEFFS];

// Whether to use the fast arm FIR code
const boolean arm_fast;
// pointer to current coefficients or NULL or FIR_PASSTHRU
short *coeff_p;
arm_fir_instance_q15 l_fir_inst;

audio_block_t *inputQueueArray[1];
// arm state arrays and FIR instances for left and right channels
// the state arrays are defined to handle a maximum of MAX_COEFFS
// coefficients in a filter
q15_t l_StateQ15[AUDIO_BLOCK_SAMPLES + FIR_MAX_COEFFS];

// Whether to use the fast arm FIR code
const boolean arm_fast;
// pointer to current coefficients or NULL or FIR_PASSTHRU
short *coeff_p;
arm_fir_instance_q15 l_fir_inst;
};

#endif

Ładowanie…
Anuluj
Zapisz