@@ -28,12 +28,13 @@ | |||
#include "utility/pdb.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]; | |||
audio_block_t * AudioInputAnalog::block_left = NULL; | |||
uint16_t AudioInputAnalog::block_offset = 0; | |||
int32_t AudioInputAnalog::hpf_y1 = 0; | |||
int32_t AudioInputAnalog::hpf_x1 = 0; | |||
int32_t AudioInputAnalog::a = 1048300; | |||
bool AudioInputAnalog::update_responsibility = false; | |||
DMAChannel AudioInputAnalog::dma(false); | |||
@@ -41,7 +42,6 @@ DMAChannel AudioInputAnalog::dma(false); | |||
void AudioInputAnalog::init(uint8_t pin) | |||
{ | |||
int32_t tmp; | |||
a = 1048300; // DC Removal filter coefficient in S12.19 | |||
// Configure the ADC and run at least one software-triggered | |||
// conversion. This completes the self calibration stuff and | |||
@@ -203,7 +203,7 @@ void AudioInputAnalog::update(void) | |||
int32_t acc = tmp; | |||
acc += hpf_y1; | |||
acc -= hpf_x1; | |||
hpf_y1 = FRACMUL_SHL(acc, a, 11); | |||
hpf_y1 = FRACMUL_SHL(acc, COEF_HPF_DCBLOCK, 11); | |||
hpf_x1 = tmp; | |||
s = signed_saturate_rshift(hpf_y1, 16, 4); | |||
*p++ = s; |
@@ -43,12 +43,11 @@ private: | |||
static uint16_t block_offset; | |||
static int32_t hpf_y1; | |||
static int32_t hpf_x1; | |||
static int32_t a; | |||
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); | |||
}; | |||
@@ -30,6 +30,8 @@ | |||
#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 right_buffer[AUDIO_BLOCK_SAMPLES]; | |||
audio_block_t * AudioInputAnalogStereo::block_left = NULL; | |||
@@ -38,7 +40,6 @@ uint16_t AudioInputAnalogStereo::offset_left = 0; | |||
uint16_t AudioInputAnalogStereo::offset_right = 0; | |||
int32_t AudioInputAnalogStereo::hpf_y1[2] = { 0, 0 }; | |||
int32_t AudioInputAnalogStereo::hpf_x1[2] = { 0, 0 }; | |||
int32_t AudioInputAnalogStereo::a = 1048300; | |||
bool AudioInputAnalogStereo::update_responsibility = false; | |||
DMAChannel AudioInputAnalogStereo::dma0(false); | |||
DMAChannel AudioInputAnalogStereo::dma1(false); | |||
@@ -276,7 +277,7 @@ void AudioInputAnalogStereo::update(void) | |||
int32_t acc = tmp; | |||
acc += hpf_y1[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; | |||
s = signed_saturate_rshift(hpf_y1[0], 16, 4); | |||
*p++ = s; | |||
@@ -291,7 +292,7 @@ void AudioInputAnalogStereo::update(void) | |||
int32_t acc = tmp; | |||
acc += hpf_y1[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; | |||
s = signed_saturate_rshift(hpf_y1[1], 16, 4); | |||
*p++ = s; |
@@ -35,11 +35,11 @@ class AudioInputAnalogStereo : public AudioStream | |||
{ | |||
public: | |||
AudioInputAnalogStereo() : AudioStream(0, NULL) { | |||
init(A2, A3); | |||
} | |||
init(A2, A3); | |||
} | |||
AudioInputAnalogStereo(uint8_t pin0, uint8_t pin1) : AudioStream(0, NULL) { | |||
init(pin0, pin1); | |||
} | |||
init(pin0, pin1); | |||
} | |||
virtual void update(void); | |||
private: | |||
static audio_block_t *block_left; | |||
@@ -48,14 +48,13 @@ private: | |||
static uint16_t offset_right; | |||
static int32_t hpf_y1[2]; | |||
static int32_t hpf_x1[2]; | |||
static int32_t a; | |||
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 |