Author Topic: STM32F407 - CMSIS DSP - IFFT not working with audio input/output  (Read 654 times)

0 Members and 1 Guest are viewing this topic.

Offline lukegalea16Topic starter

  • Newbie
  • Posts: 6
  • Country: mt
I'm currently using the stm32f407g-disc1 and reading an audio input through PMOD I2S2. I've carried out some examples and the hardware is working fine (writing data from the rx to the tx buffer) such as the code below.

Code: [Select]
for (int i=0; i<BUFFER_LENGTH*4; i=i+4) {
txBuf[i] = rxBuf[i];
txBuf[i+1] = rxBuf[i+1];
txBuf[i+2] = 0;
txBuf[i+3] = 0;
}

I now wish to perform the FFT on this incoming buffer, manipulate it (my first aim is to implement a pitch shifting algorithm) and perform the IFFT again. Thus I've tried the following:

Code: [Select]
for (int i=0; i<BUFFER_LENGTH*4; i=i+4) {
fft_in_buf[fft_in_ptr] = (float) ((int) (rxBuf[i]<<16)|rxBuf[i+1]);
fft_in_ptr++;
}

arm_rfft_fast_f32(&fft_handler, fft_in_buf, fft_out_buf, 0);
arm_rfft_fast_f32(&fft_handler, fft_out_buf, fft_in_buf, 1);

fft_in_ptr = 0;

for (int i=0; i<BUFFER_LENGTH*4; i=i+4) {
        txBuf[i] = (fft_in_buf[fft_in_ptr] >> 16) & 0xFF; // MSB
        txBuf[i + 1] = fft_in_buf[fft_in_ptr] & 0xFF;     // LSB
        txBuf[i + 2] = 0;
        txBuf[i + 3] = 0;

        fft_in_ptr++;
}

In the main initialization I'm also carrying out
Code: [Select]
arm_rfft_fast_init_f32(&fft_handler, BUFFER_LENGTH);

My issue is that I get a very very low output (barely audible) with the above code. I might have a scaling issue as I found in similar issues but I still can't get it to work by scaling fft_in_buf[fft_in_ptr].
 

Offline newbrain

  • Super Contributor
  • ***
  • Posts: 1723
  • Country: se
Re: STM32F407 - CMSIS DSP - IFFT not working with audio input/output
« Reply #1 on: April 29, 2024, 12:57:33 pm »
I don't have a direct answer, but rather some questions, that might guide you to a solution:
  • Are you getting the input data from one of the STM32F407 SAI interfaces?
  • What's the format of the audio stream?
  • If using SAI, what's the purpose of manipulating the byte order?
    SAI data will come correctly aligned for the CPU to handle (Little Endian), and if the "LSb/MSb first" bit in SAI configuration is wrong, well, changing byte order won't help.
  • What are the types of the used buffers?
    The int -> float and float -> int conversions both look really fishy: the sign is not kept in the first one, and the second one is not even possible, since floats cannot be shifted; moreover, you are shifting by 16 position instead of 8...
Nandemo wa shiranai wa yo, shitteru koto dake.
 

Offline lukegalea16Topic starter

  • Newbie
  • Posts: 6
  • Country: mt
Re: STM32F407 - CMSIS DSP - IFFT not working with audio input/output
« Reply #2 on: April 30, 2024, 06:20:37 am »
Hi,

my issue was converting back the tx buffer

Code: [Select]
for (int i=0; i<BUFFER_LENGTH*4; i=i+4) {
        txBuf[i] = (fft_in_buf[fft_in_ptr] >> 16) & 0xFFFF; // MSB
        txBuf[i + 1] = fft_in_buf[fft_in_ptr] & 0xFFFF;     // LSB
        txBuf[i + 2] = 0;
        txBuf[i + 3] = 0;

        fft_in_ptr++;
}
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf