cancel
Showing results for 
Search instead for 
Did you mean: 

I2S for STM32F429

Jtron.11
Senior

Is there any example walking thru how to convert a .wav file of the audio to play on STM32F429?

1 ACCEPTED SOLUTION

Accepted Solutions
KnarfB
Principal III

There is some .wav related code in the F4 firmware repository for similar chips:https://github.com/STMicroelectronics/STM32CubeF4/blob/a86ecaa2fb63029596ba7dabadab2d9c2c139560/Projects/STM32469I-Discovery/Applications/Audio/Audio_playback_and_record/readme.txt

View solution in original post

10 REPLIES 10
KnarfB
Principal III

There is some .wav related code in the F4 firmware repository for similar chips:https://github.com/STMicroelectronics/STM32CubeF4/blob/a86ecaa2fb63029596ba7dabadab2d9c2c139560/Projects/STM32469I-Discovery/Applications/Audio/Audio_playback_and_record/readme.txt

Jtron.11
Senior

Thank you KnarfB. I was looking for the way we can play a wav file from binary file embedded in the flash as code. I tried so many different rate but still didn't get the wav file to play correctly. My set up using STM32F429 + MAX98357 amplifier. I set STM32F429 to play back with Phillips I2S with either 16KHz or 44KHz. From the original wav file, I use the software Audacity to export the wave file to export the right rate 16KHz or 44KHz 16bit sign wav then use WaveToC to convert wav file to C header hexadecial binary file. In STM32 i used the HAL_I2S_Transmit_DMA(&hi2s2, data, NUM_ELEMENTS); function to transmit the data. It play the similar sound, but the rate is not matching with the original rate.

Do you have any idea? Or is there something wrong with my method of conversion?

And your DMA is triggered by a timer?

Jtron.11
Senior

I called it in the infinite loop in such way

/* USER CODE BEGIN WHILE */

 while (1)

 {

    HAL_I2S_Transmit_DMA(&hi2s2, data, NUM_ELEMENTS);

    HAL_Delay(5000);

  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

 }

 /* USER CODE END 3 */

}

Jtron.11
Senior

This is just to test the sound. The sound clip only 2s timing so I delay 5s to be sure the clip is completed. In the real situation, the sound will only DMA transmit once we wanted.

KnarfB
Principal III

If you generate a 1kHz square wave in Audacity, after WaveToC conversion you should see blocks of identical values. The block length is half the sample freq. in kHz. If you play that sound, what freq are you hearing? You may use Audacity or an Android app (Spectroid or thelike) for rough measurments.

Jtron.11
Senior

It play correctly now, but still need an explanation. My source is 22KHz, if I set the STM32 with the same rate playback, the sound is playing back faster. I changed to 11KHz, now I got it plays at the same source. Any idea?

KnarfB
Principal III

Maybe the output is stereo? That would split the samples into two channels.

Jtron.11
Senior

Output from STM32? My assumption has been if the source is 22KHz, the playback should be 22KHz to play back correctly.