|
|
@@ -30,7 +30,7 @@ |
|
|
|
|
|
|
|
#if defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__) |
|
|
|
|
|
|
|
#define COEF_HPF_DCBLOCK (1048300<<4) // DC Removal filter coefficient in S7.24 |
|
|
|
#define COEF_HPF_DCBLOCK (1048300<<10) // DC Removal filter coefficient in S1.30 |
|
|
|
|
|
|
|
DMAMEM static uint16_t left_buffer[AUDIO_BLOCK_SAMPLES]; |
|
|
|
DMAMEM static uint16_t right_buffer[AUDIO_BLOCK_SAMPLES]; |
|
|
@@ -70,12 +70,12 @@ void AudioInputAnalogStereo::init(uint8_t pin0, uint8_t pin1) |
|
|
|
// Probably not useful to spin cycles here stabilizing |
|
|
|
// since DC blocking is similar to te external analog filters |
|
|
|
tmp = (uint16_t) analogRead(pin0); |
|
|
|
tmp = ( ((int32_t) tmp) << 8); |
|
|
|
tmp = ( ((int32_t) tmp) << 14); |
|
|
|
hpf_x1[0] = tmp; // With constant DC level x1 would be x0 |
|
|
|
hpf_y1[0] = 0; // Output will settle here when stable |
|
|
|
|
|
|
|
tmp = (uint16_t) analogReadADC1(pin1); |
|
|
|
tmp = ( ((int32_t) tmp) << 8); |
|
|
|
tmp = ( ((int32_t) tmp) << 14); |
|
|
|
hpf_x1[1] = tmp; // With constant DC level x1 would be x0 |
|
|
|
hpf_y1[1] = 0; // Output will settle here when stable |
|
|
|
|
|
|
@@ -263,9 +263,7 @@ void AudioInputAnalogStereo::update(void) |
|
|
|
// y = a*(x[n] - x[n-1] + y[n-1]) |
|
|
|
// The coefficient "a" is as follows: |
|
|
|
// a = UNITY*e^(-2*pi*fc/fs) |
|
|
|
// UNITY = 2^20 |
|
|
|
// fc = 2 |
|
|
|
// fs = 44100 |
|
|
|
// fc = 2 @ fs = 44100 |
|
|
|
// |
|
|
|
|
|
|
|
// DC removal, LEFT |
|
|
@@ -273,12 +271,12 @@ void AudioInputAnalogStereo::update(void) |
|
|
|
end = p + AUDIO_BLOCK_SAMPLES; |
|
|
|
do { |
|
|
|
tmp = (uint16_t)(*p); |
|
|
|
tmp = ( ((int32_t) tmp) << 8); |
|
|
|
tmp = ( ((int32_t) tmp) << 14); |
|
|
|
int32_t acc = hpf_y1[0] - hpf_x1[0]; |
|
|
|
acc += tmp; |
|
|
|
hpf_y1[0] = FRACMUL_SHL(acc, COEF_HPF_DCBLOCK, 7); |
|
|
|
hpf_y1[0] = FRACMUL_SHL(acc, COEF_HPF_DCBLOCK, 1); |
|
|
|
hpf_x1[0] = tmp; |
|
|
|
s = signed_saturate_rshift(hpf_y1[0], 16, 8); |
|
|
|
s = signed_saturate_rshift(hpf_y1[0], 16, 14); |
|
|
|
*p++ = s; |
|
|
|
} while (p < end); |
|
|
|
|
|
|
@@ -287,12 +285,12 @@ void AudioInputAnalogStereo::update(void) |
|
|
|
end = p + AUDIO_BLOCK_SAMPLES; |
|
|
|
do { |
|
|
|
tmp = (uint16_t)(*p); |
|
|
|
tmp = ( ((int32_t) tmp) << 8); |
|
|
|
tmp = ( ((int32_t) tmp) << 14); |
|
|
|
int32_t acc = hpf_y1[1] - hpf_x1[1]; |
|
|
|
acc += tmp; |
|
|
|
hpf_y1[1]= FRACMUL_SHL(acc, COEF_HPF_DCBLOCK, 7); |
|
|
|
hpf_y1[1]= FRACMUL_SHL(acc, COEF_HPF_DCBLOCK, 1); |
|
|
|
hpf_x1[1] = tmp; |
|
|
|
s = signed_saturate_rshift(hpf_y1[1], 16, 8); |
|
|
|
s = signed_saturate_rshift(hpf_y1[1], 16, 14); |
|
|
|
*p++ = s; |
|
|
|
} while (p < end); |
|
|
|
|