Преглед изворни кода

increase precision to minimize DC error

dds
Transmogrifox пре 7 година
родитељ
комит
b8d349fbe7
2 измењених фајлова са 20 додато и 23 уклоњено
  1. +7
    -8
      input_adc.cpp
  2. +13
    -15
      input_adcs.cpp

+ 7
- 8
input_adc.cpp Прегледај датотеку

@@ -28,7 +28,7 @@
#include "utility/pdb.h"
#include "utility/dspinst.h"

#define COEF_HPF_DCBLOCK 1048300 // DC Removal filter coefficient in S12.19
#define COEF_HPF_DCBLOCK (1048300<<4) // DC Removal filter coefficient in S7.24

DMAMEM static uint16_t analog_rx_buffer[AUDIO_BLOCK_SAMPLES];
audio_block_t * AudioInputAnalog::block_left = NULL;
@@ -57,7 +57,7 @@ void AudioInputAnalog::init(uint8_t pin)
// Probably not useful to spin cycles here stabilizing
// since DC blocking is similar to te external analog filters
tmp = (uint16_t) analogRead(pin);
tmp = ( ((int32_t) tmp) << 4);
tmp = ( ((int32_t) tmp) << 8);
hpf_x1 = tmp; // With constant DC level x1 would be x0
hpf_y1 = 0; // Output will settle here when stable

@@ -199,13 +199,12 @@ void AudioInputAnalog::update(void)
end = p + AUDIO_BLOCK_SAMPLES;
do {
tmp = (uint16_t)(*p);
tmp = ( ((int32_t) tmp) << 4);
int32_t acc = tmp;
acc += hpf_y1;
acc -= hpf_x1;
hpf_y1 = FRACMUL_SHL(acc, COEF_HPF_DCBLOCK, 11);
tmp = ( ((int32_t) tmp) << 8);
int32_t acc = hpf_y1 - hpf_x1;
acc += tmp;
hpf_y1 = FRACMUL_SHL(acc, COEF_HPF_DCBLOCK, 7);
hpf_x1 = tmp;
s = signed_saturate_rshift(hpf_y1, 16, 4);
s = signed_saturate_rshift(hpf_y1, 16, 8);
*p++ = s;
} while (p < end);


+ 13
- 15
input_adcs.cpp Прегледај датотеку

@@ -30,7 +30,7 @@

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

#define COEF_HPF_DCBLOCK 1048300 // DC Removal filter coefficient in S12.19
#define COEF_HPF_DCBLOCK (1048300<<4) // DC Removal filter coefficient in S7.24

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) << 4);
tmp = ( ((int32_t) tmp) << 8);
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) << 4);
tmp = ( ((int32_t) tmp) << 8);
hpf_x1[1] = tmp; // With constant DC level x1 would be x0
hpf_y1[1] = 0; // Output will settle here when stable

@@ -273,13 +273,12 @@ void AudioInputAnalogStereo::update(void)
end = p + AUDIO_BLOCK_SAMPLES;
do {
tmp = (uint16_t)(*p);
tmp = ( ((int32_t) tmp) << 4);
int32_t acc = tmp;
acc += hpf_y1[0];
acc -= hpf_x1[0];
hpf_y1[0] = FRACMUL_SHL(acc, COEF_HPF_DCBLOCK, 11);
tmp = ( ((int32_t) tmp) << 8);
int32_t acc = hpf_y1[0] - hpf_x1[0];
acc += tmp;
hpf_y1[0] = FRACMUL_SHL(acc, COEF_HPF_DCBLOCK, 7);
hpf_x1[0] = tmp;
s = signed_saturate_rshift(hpf_y1[0], 16, 4);
s = signed_saturate_rshift(hpf_y1[0], 16, 8);
*p++ = s;
} while (p < end);

@@ -288,13 +287,12 @@ void AudioInputAnalogStereo::update(void)
end = p + AUDIO_BLOCK_SAMPLES;
do {
tmp = (uint16_t)(*p);
tmp = ( ((int32_t) tmp) << 4);
int32_t acc = tmp;
acc += hpf_y1[1];
acc -= hpf_x1[1];
hpf_y1[1]= FRACMUL_SHL(acc, COEF_HPF_DCBLOCK, 11);
tmp = ( ((int32_t) tmp) << 8);
int32_t acc = hpf_y1[1] - hpf_x1[1];
acc += tmp;
hpf_y1[1]= FRACMUL_SHL(acc, COEF_HPF_DCBLOCK, 7);
hpf_x1[1] = tmp;
s = signed_saturate_rshift(hpf_y1[1], 16, 4);
s = signed_saturate_rshift(hpf_y1[1], 16, 8);
*p++ = s;
} while (p < end);


Loading…
Откажи
Сачувај