Browse Source

Fix indentation and move filtercoefficient to #define constant instead of int32_t variable

dds
Transmogrifox 7 years ago
parent
commit
38c7071270
4 changed files with 19 additions and 20 deletions
  1. +3
    -3
      input_adc.cpp
  2. +3
    -4
      input_adc.h
  3. +4
    -3
      input_adcs.cpp
  4. +9
    -10
      input_adcs.h

+ 3
- 3
input_adc.cpp View File

#include "utility/pdb.h" #include "utility/pdb.h"
#include "utility/dspinst.h" #include "utility/dspinst.h"


#define COEF_HPF_DCBLOCK 1048300 // DC Removal filter coefficient in S12.19

DMAMEM static uint16_t analog_rx_buffer[AUDIO_BLOCK_SAMPLES]; DMAMEM static uint16_t analog_rx_buffer[AUDIO_BLOCK_SAMPLES];
audio_block_t * AudioInputAnalog::block_left = NULL; audio_block_t * AudioInputAnalog::block_left = NULL;
uint16_t AudioInputAnalog::block_offset = 0; uint16_t AudioInputAnalog::block_offset = 0;
int32_t AudioInputAnalog::hpf_y1 = 0; int32_t AudioInputAnalog::hpf_y1 = 0;
int32_t AudioInputAnalog::hpf_x1 = 0; int32_t AudioInputAnalog::hpf_x1 = 0;
int32_t AudioInputAnalog::a = 1048300;


bool AudioInputAnalog::update_responsibility = false; bool AudioInputAnalog::update_responsibility = false;
DMAChannel AudioInputAnalog::dma(false); DMAChannel AudioInputAnalog::dma(false);
void AudioInputAnalog::init(uint8_t pin) void AudioInputAnalog::init(uint8_t pin)
{ {
int32_t tmp; int32_t tmp;
a = 1048300; // DC Removal filter coefficient in S12.19


// Configure the ADC and run at least one software-triggered // Configure the ADC and run at least one software-triggered
// conversion. This completes the self calibration stuff and // conversion. This completes the self calibration stuff and
int32_t acc = tmp; int32_t acc = tmp;
acc += hpf_y1; acc += hpf_y1;
acc -= hpf_x1; acc -= hpf_x1;
hpf_y1 = FRACMUL_SHL(acc, a, 11);
hpf_y1 = FRACMUL_SHL(acc, COEF_HPF_DCBLOCK, 11);
hpf_x1 = tmp; hpf_x1 = tmp;
s = signed_saturate_rshift(hpf_y1, 16, 4); s = signed_saturate_rshift(hpf_y1, 16, 4);
*p++ = s; *p++ = s;

+ 3
- 4
input_adc.h View File

static uint16_t block_offset; static uint16_t block_offset;
static int32_t hpf_y1; static int32_t hpf_y1;
static int32_t hpf_x1; static int32_t hpf_x1;
static int32_t a;


static bool update_responsibility; static bool update_responsibility;
static DMAChannel dma;
static void isr(void);
static void init(uint8_t pin);
static DMAChannel dma;
static void isr(void);
static void init(uint8_t pin);


}; };



+ 4
- 3
input_adcs.cpp View File



#if defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__) #if defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__)


#define COEF_HPF_DCBLOCK 1048300 // DC Removal filter coefficient in S12.19

DMAMEM static uint16_t left_buffer[AUDIO_BLOCK_SAMPLES]; DMAMEM static uint16_t left_buffer[AUDIO_BLOCK_SAMPLES];
DMAMEM static uint16_t right_buffer[AUDIO_BLOCK_SAMPLES]; DMAMEM static uint16_t right_buffer[AUDIO_BLOCK_SAMPLES];
audio_block_t * AudioInputAnalogStereo::block_left = NULL; audio_block_t * AudioInputAnalogStereo::block_left = NULL;
uint16_t AudioInputAnalogStereo::offset_right = 0; uint16_t AudioInputAnalogStereo::offset_right = 0;
int32_t AudioInputAnalogStereo::hpf_y1[2] = { 0, 0 }; int32_t AudioInputAnalogStereo::hpf_y1[2] = { 0, 0 };
int32_t AudioInputAnalogStereo::hpf_x1[2] = { 0, 0 }; int32_t AudioInputAnalogStereo::hpf_x1[2] = { 0, 0 };
int32_t AudioInputAnalogStereo::a = 1048300;
bool AudioInputAnalogStereo::update_responsibility = false; bool AudioInputAnalogStereo::update_responsibility = false;
DMAChannel AudioInputAnalogStereo::dma0(false); DMAChannel AudioInputAnalogStereo::dma0(false);
DMAChannel AudioInputAnalogStereo::dma1(false); DMAChannel AudioInputAnalogStereo::dma1(false);
int32_t acc = tmp; int32_t acc = tmp;
acc += hpf_y1[0]; acc += hpf_y1[0];
acc -= hpf_x1[0]; acc -= hpf_x1[0];
hpf_y1[0] = FRACMUL_SHL(acc, a, 11);
hpf_y1[0] = FRACMUL_SHL(acc, COEF_HPF_DCBLOCK, 11);
hpf_x1[0] = tmp; hpf_x1[0] = tmp;
s = signed_saturate_rshift(hpf_y1[0], 16, 4); s = signed_saturate_rshift(hpf_y1[0], 16, 4);
*p++ = s; *p++ = s;
int32_t acc = tmp; int32_t acc = tmp;
acc += hpf_y1[1]; acc += hpf_y1[1];
acc -= hpf_x1[1]; acc -= hpf_x1[1];
hpf_y1[1]= FRACMUL_SHL(acc, a, 11);
hpf_y1[1]= FRACMUL_SHL(acc, COEF_HPF_DCBLOCK, 11);
hpf_x1[1] = tmp; hpf_x1[1] = tmp;
s = signed_saturate_rshift(hpf_y1[1], 16, 4); s = signed_saturate_rshift(hpf_y1[1], 16, 4);
*p++ = s; *p++ = s;

+ 9
- 10
input_adcs.h View File

{ {
public: public:
AudioInputAnalogStereo() : AudioStream(0, NULL) { AudioInputAnalogStereo() : AudioStream(0, NULL) {
init(A2, A3);
}
init(A2, A3);
}
AudioInputAnalogStereo(uint8_t pin0, uint8_t pin1) : AudioStream(0, NULL) { AudioInputAnalogStereo(uint8_t pin0, uint8_t pin1) : AudioStream(0, NULL) {
init(pin0, pin1);
}
init(pin0, pin1);
}
virtual void update(void); virtual void update(void);
private: private:
static audio_block_t *block_left; static audio_block_t *block_left;
static uint16_t offset_right; static uint16_t offset_right;
static int32_t hpf_y1[2]; static int32_t hpf_y1[2];
static int32_t hpf_x1[2]; static int32_t hpf_x1[2];
static int32_t a;


static bool update_responsibility; static bool update_responsibility;
static DMAChannel dma0;
static DMAChannel dma1;
static void isr0(void);
static void isr1(void);
static void init(uint8_t pin0, uint8_t pin1);
static DMAChannel dma0;
static DMAChannel dma1;
static void isr0(void);
static void isr1(void);
static void init(uint8_t pin0, uint8_t pin1);
}; };


#endif #endif

Loading…
Cancel
Save