| #include "input_adc.h" | #include "input_adc.h" | ||||
| #include "utility/pdb.h" | #include "utility/pdb.h" | ||||
| #include "utility/dspinst.h" | |||||
| 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; | ||||
| { | { | ||||
| audio_block_t *new_left=NULL, *out_left=NULL; | audio_block_t *new_left=NULL, *out_left=NULL; | ||||
| unsigned int dc, offset; | unsigned int dc, offset; | ||||
| int32_t tmp; | |||||
| int16_t s, *p, *end; | int16_t s, *p, *end; | ||||
| //Serial.println("update"); | //Serial.println("update"); | ||||
| p = out_left->data; | p = out_left->data; | ||||
| end = p + AUDIO_BLOCK_SAMPLES; | end = p + AUDIO_BLOCK_SAMPLES; | ||||
| do { | do { | ||||
| s = (uint16_t)(*p) - dc; // TODO: should be saturating subtract | |||||
| tmp = (uint16_t)(*p) - (int32_t)dc; | |||||
| s = signed_saturate_rshift(tmp, 16, 0); | |||||
| *p++ = s; | *p++ = s; | ||||
| dc += s >> 13; // approx 5.38 Hz high pass filter | |||||
| dc += s / 12000; // slow response, remove DC component | |||||
| } while (p < end); | } while (p < end); | ||||
| dc_average = dc; | dc_average = dc; | ||||