Selaa lähdekoodia

Further precision increase eliminates DC offset

dds
Transmogrifox 7 vuotta sitten
vanhempi
commit
6424ffbb26
2 muutettua tiedostoa jossa 16 lisäystä ja 20 poistoa
  1. +6
    -8
      input_adc.cpp
  2. +10
    -12
      input_adcs.cpp

+ 6
- 8
input_adc.cpp Näytä tiedosto

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

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

@@ -191,20 +191,18 @@ void AudioInputAnalog::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
//
p = out_left->data;
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 - hpf_x1;
acc += tmp;
hpf_y1 = FRACMUL_SHL(acc, COEF_HPF_DCBLOCK, 7);
hpf_y1 = FRACMUL_SHL(acc, COEF_HPF_DCBLOCK, 1);
hpf_x1 = tmp;
s = signed_saturate_rshift(hpf_y1, 16, 8);
s = signed_saturate_rshift(hpf_y1, 16, 14);
*p++ = s;
} while (p < end);


+ 10
- 12
input_adcs.cpp Näytä tiedosto

@@ -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);


Loading…
Peruuta
Tallenna