cancel
Showing results for 
Search instead for 
Did you mean: 

Understand a code provided in the example STM32L552E-EV

DYann.1
Senior II

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.

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

The WAV file has a 44-byte header. This skips past the header and reads the data.

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

6 REPLIES 6
TDK
Guru

The WAV file has a 44-byte header. This skips past the header and reads the data.

If you feel a post has answered your question, please click "Accept as Solution".

@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.

DYann1_0-1743172500335.png

WAV is a well-known, standard file format - it is well documented; eg,

https://en.wikipedia.org/wiki/WAV#WAV_file_header

I searched google and also have general knowledge that files often have a header which lines up with the variable names.

If you feel a post has answered your question, please click "Accept as Solution".

@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 ?

> 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.

If you feel a post has answered your question, please click "Accept as Solution".