2025-03-28 7:03 AM - last edited on 2025-03-28 7:06 AM by Andrew Neil
Hello,
I would like some advice on understanding a code with an example provided with the STM32L5xx evaluation board. I have this code below :
/* Initialize the data buffer */
for(int i=0; i < PLAY_BUFF_SIZE; i+=2)
{
PlayBuff[i]=*((__IO uint16_t *)(AUDIO_FILE_ADDRESS + PLAY_HEADER + i));
}PLAY_BUFF_SIZE = 4096
uint16_t PlayBuff [PLAY_BUFF_SIZE];
#define AUDIO_FILE_ADDRESS 0x08040000
#define PLAY_HEADER 0x2C
I understand a little bit but where does the value 0x2C come from, what does it come from ? What does PLAY_HEADER mean ?
Thank you for your helps.
Solved! Go to Solution.
2025-03-28 7:28 AM
The WAV file has a 44-byte header. This skips past the header and reads the data.
2025-03-28 7:28 AM
The WAV file has a 44-byte header. This skips past the header and reads the data.
2025-03-28 7:36 AM
@TDK wrote:The WAV file has a 44-byte header. This skips past the header and reads the data.
Where did you find this information ? Indeed, at the beginning it says that you have to load the music into a memory area.
2025-03-28 7:40 AM
WAV is a well-known, standard file format - it is well documented; eg,
https://en.wikipedia.org/wiki/WAV#WAV_file_header
2025-03-28 7:54 AM - edited 2025-03-28 7:54 AM
I searched google and also have general knowledge that files often have a header which lines up with the variable names.
2025-03-28 8:17 AM - edited 2025-03-28 9:33 AM
@TDK wrote:I searched google and also have general knowledge that files often have a header which lines up with the variable names.
Thank you for this information, I can often see audio but nothing tells me that it is the WAV format but apparently it is the case. So if I understand correctly, we make a copy of the data recorded at the AUDIO_FILE_ADDRESS address
in the PlayBuff table ? why is the size 4096 ?
Isn't this size chosen randomly ? It depends on the SAI speed and the frame length to go fast enough so as not to lose data in the DMA. Right ?
2025-03-28 12:59 PM
> So if I understand correctly, we make a copy of the data recorded at the AUDIO_FILE_ADDRESS address
in the PlayBuff table ?
Yes.
> why is the size 4096 ?
Yes, 4096 is somewhat arbitrary. It should be large enough that you only need to update it every 1ms or more, but small enough to fit into memory.
We’re moving the ST Community to a new platform to give you a better and more reliable community experience.