applying esp-dsp IIR biquad to pipeline or element ?
- shabtronic
- Posts: 49
- Joined: Sun Nov 03, 2019 1:33 pm
Re: applying esp-dsp IIR biquad to pipeline or element ?
that's my PC code - VST2 - it's all doubles!
u need floats or whatever the DSP lib takes - I assumed float - but I've not looked at it at all
I'll post my full EQ later - once I've tidied it up - it's not actually mine - came from a blog - in turn came from RBJ's cookbook. But I did add the Z-transform stuff
u need floats or whatever the DSP lib takes - I assumed float - but I've not looked at it at all
I'll post my full EQ later - once I've tidied it up - it's not actually mine - came from a blog - in turn came from RBJ's cookbook. But I did add the Z-transform stuff
Re: applying esp-dsp IIR biquad to pipeline or element ?
did a test bypassing DSP int16 --> float --> int16 and its stereo again.
you are correct , ESP32 has no problem with that conversion.
so something strange happening to the samples in the DSP library making the samples mono and a small buzzing !
will post here if I can find out why.
you are correct , ESP32 has no problem with that conversion.
so something strange happening to the samples in the DSP library making the samples mono and a small buzzing !
will post here if I can find out why.
Re: applying esp-dsp IIR biquad to pipeline or element ?
fixed the buzzing ( was samples out of range +1 -1 float )
I (443) EQUALIZER: Impulse response of IIR filter with F=0.250000, qFactor=4.000000
I (453) view: Data min[2] = -1.535849, Data max[0] = 1.975187
________________________________________________________________
0xxx |
1xxxxx |
2xxxxxxx |
3xxxxxxxxxxx |
4xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx|
5xxxxxxxx |
6xxxxxx |
7xxxx |
8xx |
9x |
0123456789012345678901234567890123456789012345678901234567890123
I divided the DSP processed float values in half
// half dsp outpt values sould be less than +/-1 ****************
float devideit = 0.5;
for ( int z = 0; z < len; z++ )
{
FloatDspBufB[z] = FloatDspBufB[z] * devideit; // half
}
tried different values for the dsps_biquad_gen_lpf_f32
float freq = 0.25;
float qFactor = 0.5;
the it works without buzzing.
Now just to work out why its going into mono ! maybe the delay line is messing up things.
I (443) EQUALIZER: Impulse response of IIR filter with F=0.250000, qFactor=4.000000
I (453) view: Data min[2] = -1.535849, Data max[0] = 1.975187
________________________________________________________________
0xxx |
1xxxxx |
2xxxxxxx |
3xxxxxxxxxxx |
4xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx|
5xxxxxxxx |
6xxxxxx |
7xxxx |
8xx |
9x |
0123456789012345678901234567890123456789012345678901234567890123
I divided the DSP processed float values in half
// half dsp outpt values sould be less than +/-1 ****************
float devideit = 0.5;
for ( int z = 0; z < len; z++ )
{
FloatDspBufB[z] = FloatDspBufB[z] * devideit; // half
}
tried different values for the dsps_biquad_gen_lpf_f32
float freq = 0.25;
float qFactor = 0.5;
the it works without buzzing.
Now just to work out why its going into mono ! maybe the delay line is messing up things.
Re: applying esp-dsp IIR biquad to pipeline or element ?
Awsome if you want to share your EQ code later !
would love to see how it's working.
would love to see how it's working.
- shabtronic
- Posts: 49
- Joined: Sun Nov 03, 2019 1:33 pm
Re: applying esp-dsp IIR biquad to pipeline or element ?
Here you go - here's my old filter code - it's for PC Vst2. But it gives a great a insight into the coefficient calculations and the Freq response Plotting code.
I wouldn't use this - because - you know the IDF and ADF so far for me have been superb - it's fast and quick to get stuff up and running. I havn't looked at the DSP lib, but these espressif folk know what they are doing with the esp32 FPU - so it's gonna a fair amount of work to blindly optimize that code.
But have fun anyhow!
https://github.com/shabtronic/Audio-Filters
I wouldn't use this - because - you know the IDF and ADF so far for me have been superb - it's fast and quick to get stuff up and running. I havn't looked at the DSP lib, but these espressif folk know what they are doing with the esp32 FPU - so it's gonna a fair amount of work to blindly optimize that code.
But have fun anyhow!
https://github.com/shabtronic/Audio-Filters
Last edited by shabtronic on Sun Dec 29, 2019 8:04 am, edited 1 time in total.
Re: applying esp-dsp IIR biquad to pipeline or element ?
Wow, thanks for that code! Will definately be useful as a reference.
I'm slowly getting there. Narrowing down simple things. the coefficient I was manually supplying to the DSP lib were in double and not float ( 8 byte rather than 4 byte)
I still have the 2 channels turning to mono as soon as I process the float samples in the array.
I aslo ran the biquad code in C and it did the same. It probely just used a few more cpu cycles.
Just need to find out what's changing to make everything mono. The only thing I can think of is the I2S is left justified and processing the samples with the biquad maths is changing to right justified.
I should probebly send a bunch of &FFFFFFFF followed by & 00000000 as samples and take a look at the binary values before and after the maths and check justification of the bits.
I'm slowly getting there. Narrowing down simple things. the coefficient I was manually supplying to the DSP lib were in double and not float ( 8 byte rather than 4 byte)
I still have the 2 channels turning to mono as soon as I process the float samples in the array.
I aslo ran the biquad code in C and it did the same. It probely just used a few more cpu cycles.
Just need to find out what's changing to make everything mono. The only thing I can think of is the I2S is left justified and processing the samples with the biquad maths is changing to right justified.
I should probebly send a bunch of &FFFFFFFF followed by & 00000000 as samples and take a look at the binary values before and after the maths and check justification of the bits.
- shabtronic
- Posts: 49
- Joined: Sun Nov 03, 2019 1:33 pm
Re: applying esp-dsp IIR biquad to pipeline or element ?
cool stuff!
I noticed on your previous code your doing this:
I know it's pseudo code - but it should be /2 because len is in bytes
The raw audio data from the i2s stream is interleaved, with array element 0=left,1=right,2=left,3=right e.t.c. (or the otherway around - depends on the driver e.t.c.)
Havn't look at the dsp stuff tho - so I can't help you - it's half the "fun" working all this stuff out
have fun!
I noticed on your previous code your doing this:
Code: Select all
for ( int i = 0; i < len; i++ )
{
// do this properly with ESP-DSP maths ?
FloatDspBuf = ((float)DspBuf) / (float)32768;
}
Code: Select all
for ( int i = 0; i < len/2; i++ )
{
// do this properly with ESP-DSP maths ?
FloatDspBuf[i] = ((float)DspBuf[i]) / (float)32768;
}
Havn't look at the dsp stuff tho - so I can't help you - it's half the "fun" working all this stuff out
have fun!
Re: applying esp-dsp IIR biquad to pipeline or element ?
Ah, good to know len is in bytes! Had wrongly presumed it was just an int.
I'll try changing that now. I assume the len value is doubled when I have stereo streams. Will take a better look at that.
I'll try changing that now. I assume the len value is doubled when I have stereo streams. Will take a better look at that.
- shabtronic
- Posts: 49
- Joined: Sun Nov 03, 2019 1:33 pm
Re: applying esp-dsp IIR biquad to pipeline or element ?
this would be the code if your I2S stream is 16bit:
elsewhere in code
in DSP Function:
Havn't tested that, just wrote it for clarity, probably some errors - but you get the idea!
Have fun
elsewhere in code
Code: Select all
BiQuad MyFilter;
MyFilter.CalcCoeffs(4,000,1,1,44100,-1);
float MyFloatBuf[1024];
in DSP Function:
Code: Select all
// convert to floats
for (int a=0;a<len/2;a++)
MyFloatBuf[a]=(float)((short*)Buf)[a]/32768;
// Process Left/Right samples /4 this time because we are processing Left/Right
for (int a=0;a<len/4;a++)
MyFilter.Process(MyFloatBuf[a*2+0],MyFloatBuf[a*2+1]);
// Convert back to stream
for (int a=0;a<len/2;a++)
((short*)Buf)[a]=MyFloatBuf[a]*32768;
Have fun
Re: applying esp-dsp IIR biquad to pipeline or element ?
Dps fullily working now?
I'm just processing all the samples in the
Buffer in one go because I'm applying the same effect to both left and right channel.
I change to interleaved in case I need stereo fx.
It turns out my mono problem is a hardware fault or possibly a firmware that needs updating.
I convinced myself stereo pass through was working at one point but I had only enabled the direct line input to output feature of the codec.
If I just flash basic pass through example either mic or line, channel 1 inputs on ADC (mic) or channel 2 inputs on ADC (line aux connector) I get a mix of both channels.
I have another lyrat 4.3 board in the post so I'll check that soon as I arrives.
I flashed the esp32 to latest bootloader firmware but did'nt help.
I the lyrat 4.3 manual it shows 3 other bin files at diffent address and so far I have no idea what they are. I better start a new post for that.
So anyway, a massive thanks for you help / interest.
The original equalizer.c element input / output samples buffer is set to 100 length , seams like an odd number
So far I have to say I'm impressed with the lyrat Esp-adf / esp32 framework.
OK going to post some firmware questions before I assume the board is defective but its looking like it might be.
I'm just processing all the samples in the
Buffer in one go because I'm applying the same effect to both left and right channel.
I change to interleaved in case I need stereo fx.
It turns out my mono problem is a hardware fault or possibly a firmware that needs updating.
I convinced myself stereo pass through was working at one point but I had only enabled the direct line input to output feature of the codec.
If I just flash basic pass through example either mic or line, channel 1 inputs on ADC (mic) or channel 2 inputs on ADC (line aux connector) I get a mix of both channels.
I have another lyrat 4.3 board in the post so I'll check that soon as I arrives.
I flashed the esp32 to latest bootloader firmware but did'nt help.
I the lyrat 4.3 manual it shows 3 other bin files at diffent address and so far I have no idea what they are. I better start a new post for that.
So anyway, a massive thanks for you help / interest.
The original equalizer.c element input / output samples buffer is set to 100 length , seams like an odd number
So far I have to say I'm impressed with the lyrat Esp-adf / esp32 framework.
OK going to post some firmware questions before I assume the board is defective but its looking like it might be.
Who is online
Users browsing this forum: No registered users and 6 guests