2020-10-05 04:13 PM
Is there any example walking thru how to convert a .wav file of the audio to play on STM32F429?
Solved! Go to Solution.
2020-10-05 10:36 PM
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
2020-10-05 10:36 PM
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
2020-10-06 07:40 AM
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?
2020-10-06 07:45 AM
And your DMA is triggered by a timer?
2020-10-06 07:51 AM
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 */
}
2020-10-06 07:53 AM
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.
2020-10-06 09:12 AM
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.
2020-10-06 10:20 AM
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?
2020-10-06 10:31 AM
Maybe the output is stereo? That would split the samples into two channels.
2020-10-06 10:50 AM
Output from STM32? My assumption has been if the source is 22KHz, the playback should be 22KHz to play back correctly.