0
\$\begingroup\$

I'm using ADAU1761 in my project and its I2S output is configured to stereo 48kHz/24bit, 8 bit padding, that gives 32bit per channel, 64 BCLK per frame. However I need 16kHz/16bits. 24b to 16b can be performed by simple bitshift (>> 8). I'm having trouble with 48kHz to 16kHz conversion. I'm beginner in audio processing but as far as I understood I can't just take every 3rd sample from original audio and save because of aliasing. There must be a low pass filter but I don't know what cutoff frequency and order it should have. Target platform is STM32L4 but it's easier to just code on PC and then port the code. Here is a snippet:

fread(&WAVE_header, sizeof(WAVE_header_t), 1, pFile); // read wave header, 
uint16_t* ptr = malloc(WAVE_header.SubChunk2Size); // allocate memory for audio data
fread(ptr, WAVE_header.SubChunk2Size, 1, pFile); // read audio data
uint16_t *ptrOut = malloc(WAVE_header.SubChunk2Size/3); // after resampling
for(uint32_t i = 0; i < WAVE_header.SubChunk2Size/3; i+=5){ // 
    ptrOut = ptr+i; // channel 1
    ptrOut = ptr + 1+i; // channel 2
    //filter here?
}
fwrite(ptrOut, WAVE_header.SubChunk2Size/3, 1, outFile);
\$\endgroup\$
1

1 Answer 1

1
\$\begingroup\$

If you are going to a 16kHz sample rate, anything equal to or more than half that will cause aliasing. So, by 8KHz the attenuation of the filter needs to be high enough that the aliasing is acceptable.

What order and cutoff to use is up to you. A higher order will allow the passband to get closer to 8kHz since the transition is sharper. A lower order is simpler.

\$\endgroup\$
1
  • \$\begingroup\$ and once you filter (at the 48 kHz sample rate) the sampled data to an 8 kHz cutoff, then you can toss 2 of every 3 samples. if your LPF is an IIR filter, you have to compute all 3 samples and toss 2. but if your LPF is an FIR, you only need to compute the output sample (one of three) that you're keeping. \$\endgroup\$ Commented Mar 24, 2017 at 6:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.