YasarYY
Active member
I applied the click patch.
I altered below code, at input_adc.cpp, before IIR High-Pass Filter:
Changed this:
to this:
This unpleasant and error-prone patch basically checks if samples recycled from previous update are balanced (their DC offset is removed) or not, by checking the first recycled value against a threshold. If they're not balanced, it makes IIR filter, which performs DC offset removal, start from the beginning of the capture buffer.
I'll continue to look for a real solution. Since this issue, at least for me, may not be about SD card draws power and pulls 3.3 v line down.
While looking for an adequate place for the patch, I noticed a strange pattern. First, here is the data flow:
ADC --DMA--> ADC buffer --> capture buffer w/recycling --> IIR HP (balancing) --> FIR LP w/subsampling
By writing samples to file at different stages, I observed below patterns (without patching):
Before IIR:
After IIR & Before FIR:
After FIR:
When DC offset (unbalanced) samples are leaked via recycling, and after IIR is applied to newly added samples, they become "remained above" samples. These recycled samples' count is about the length (taps) of the FIR filter, by input_adc.cpp design. And after FIR (with gain) is applied, they become sudden saturated samples that unwind quickly, forming the clicks.
Why recycling occasionally carries unbalanced samples? I don't know yet but it's probably related to SD card's actual write delays (~52 ms for me). Teensy audio system's update() call period is about 2.9 ms, which means about 18 update() calls to be missed during SD actual write operation. An update() call doesn't interrupt an executing update(), so this issue may be about DMA is wrapping ADC buffer several times. Discontinuities at before IIR image probably relates to this.
I'll try to increase ADC buffer size (and maybe capture buffer size as well) to mitigate this issue correctly. A quick try emerged consecutive restarts of Teensy. Obviously this alteration must be made by considering its effects comprehensively.
I altered below code, at input_adc.cpp, before IIR High-Pass Filter:
Changed this:
C++:
int16_t *s = capture_buffer + recycle_samples;
C++:
bool recycle_offset = (*capture_buffer) > (int16_t)(0.024f * 32768);
int16_t *s = capture_buffer + (recycle_offset ? 0 : recycle_samples);
This unpleasant and error-prone patch basically checks if samples recycled from previous update are balanced (their DC offset is removed) or not, by checking the first recycled value against a threshold. If they're not balanced, it makes IIR filter, which performs DC offset removal, start from the beginning of the capture buffer.
I'll continue to look for a real solution. Since this issue, at least for me, may not be about SD card draws power and pulls 3.3 v line down.
While looking for an adequate place for the patch, I noticed a strange pattern. First, here is the data flow:
ADC --DMA--> ADC buffer --> capture buffer w/recycling --> IIR HP (balancing) --> FIR LP w/subsampling
By writing samples to file at different stages, I observed below patterns (without patching):
Before IIR:
After IIR & Before FIR:
After FIR:
When DC offset (unbalanced) samples are leaked via recycling, and after IIR is applied to newly added samples, they become "remained above" samples. These recycled samples' count is about the length (taps) of the FIR filter, by input_adc.cpp design. And after FIR (with gain) is applied, they become sudden saturated samples that unwind quickly, forming the clicks.
Why recycling occasionally carries unbalanced samples? I don't know yet but it's probably related to SD card's actual write delays (~52 ms for me). Teensy audio system's update() call period is about 2.9 ms, which means about 18 update() calls to be missed during SD actual write operation. An update() call doesn't interrupt an executing update(), so this issue may be about DMA is wrapping ADC buffer several times. Discontinuities at before IIR image probably relates to this.
I'll try to increase ADC buffer size (and maybe capture buffer size as well) to mitigate this issue correctly. A quick try emerged consecutive restarts of Teensy. Obviously this alteration must be made by considering its effects comprehensively.


