Fir filter using 2 ports #1542
-
I have been trying to make a FIR filter work. So far I have tried a 1 port solution and I believe that is just bypassing the filter and copying in to out as the results should be a 90degree phase difference between the 2 output channels. Today I followed the 2 port example, code below. I see wierd timings on the pins and neither "in" or "out" corrolate with the what is reported by Audiologger. I can see it trying to work in so far as there are bursts of output data. Any idea what is going on here?
[ 27][V][esp32-hal-uart.c:330] uartBegin(): UART0 baud(115200) Mode(800001c) rxPin(3) txPin(1) Copy of code #include "AudioTools.h" uint16_t sample_rate = 44100; AudioInfo info(sample_rate, 2, 24); // copy filtered values // define FIR filter parameters // Arduino Setup // setup filters for all available channels // start I2S in in.begin(config_in); // start I2S out Serial.println("I2S started..."); // Arduino loop - copy sound to out |
Beta Was this translation helpful? Give feedback.
Replies: 19 comments 65 replies
-
You can't process an input of 24 bits with a filter for 16 bits (FilteredStream<int16_t, float> )! |
Beta Was this translation helpful? Give feedback.
-
You are very confusing: 48bits/frame ? The bits are specified by sample: as the field name (bits_per_sample) implies ! I think the error message is speaking enough to figure out what you are doing wrong... |
Beta Was this translation helpful? Give feedback.
-
I can reproduce your problem and I am currently not sure how to deal with this the best way. In any case, I have updated the documentation Here are a couple of solution approaches that also work with the latest code: FormatConverterStream conv(out);
StreamCopy copier(conv, in); b) Mark the input as input so that it is not notified about the change FormatConverterStream conv((Stream&)in); |
Beta Was this translation helpful? Give feedback.
-
Floating point operations on microcontrollers are very slow so you need to keep the number of taps as small as possible. Did you try to reduce the sample rate to double check if you passed your limit ? ps.
FilteredStream<int16_t, float> filtered(out, channels);
NumberFormatConverterStream conv(filtered);
StreamCopy copier(conv, in); |
Beta Was this translation helpful? Give feedback.
-
coeff_61.zip |
Beta Was this translation helpful? Give feedback.
-
Before running my own tests: did you correct the bug in your sketch that you call both copier.copy() and copier2.copy() with 16 bits ? |
Beta Was this translation helpful? Give feedback.
-
I have them like this ATM. I'm just adding a fix point FIR option so the code not quite done or tested. I'll upload that soon after lunch |
Beta Was this translation helpful? Give feedback.
-
ok, the last part will be to add the outputs from both FIRs. I'm a bit confused with the last part. I think I need to do something like this? |
Beta Was this translation helpful? Give feedback.
-
Compiling .pio/build/esp32dev/src/main.cpp.o |
Beta Was this translation helpful? Give feedback.
-
I think you are looking for a Mixer: https://github.com/pschatzmann/arduino-audio-tools/wiki/Splitting-and-Merging-Audio After a second thought: if I get you right you want to create a mono signal out of the stereo. I don't think there is currently a class which would do this, so you would need to write some logic yourself e.g. using a CallbackStream |
Beta Was this translation helpful? Give feedback.
-
Just had a look at your TAB include files. I suggest to define the array as const to make sure that it is ending up in PROGMEM and not in RAM |
Beta Was this translation helpful? Give feedback.
-
I would do something like the follows: This provides the sum on channel 0 and dff on channel 1: size_t calcSumAndDiff(uint8_t *data, size_t len){
int32_t *data32 = (int32_t*) data;
int samples = len / sizeof(int32_t);
for (int j=0;j<samples;j+=2){
int32_t add = (0.5f * data32[j]) + (0.5f * data32[j+1]);
int32_t diff = data32[j] - data32[j+1];
data32[j] = add
data32[j+1] = diff;
}
return len;
}
CallbackStrem cb(out, calcSumAndDiff);
ps. I did not test this, so there might still be some errors |
Beta Was this translation helpful? Give feedback.
-
That is because you send the result of the filtered to out instead of to cb |
Beta Was this translation helpful? Give feedback.
-
So I put the callback in the 32bit filter path. I assume it should be working correctly as I guess len is passed to it somehow. This looks like it is outputting the filter input again,but the bursting has gone away. CallbackStream cb(out, calcSumAndDiff); |
Beta Was this translation helpful? Give feedback.
-
This code doesn't do anything. size_t calcSumAndDiff(uint8_t *data, size_t len ){ |
Beta Was this translation helpful? Give feedback.
-
int32_t data32 = (int32_t) data; |
Beta Was this translation helpful? Give feedback.
-
wierd also, when I copy the code from emacs to here, the pointer "*" gets deleted but it is correct inside the real code. |
Beta Was this translation helpful? Give feedback.
-
I have no idea why, but changing the from int8 to size_t fixed the thing. |
Beta Was this translation helpful? Give feedback.
-
The Wiki contains chapters for Resampling and Format Changes! |
Beta Was this translation helpful? Give feedback.
You can't process an input of 24 bits with a filter for 16 bits (FilteredStream<int16_t, float> )!
I suggest to stick with 16 bits....