Select one of the symbols to view example projects that use it.
 
Outline
Includes
#include "waverecorder.h"
Private define
pHeaderBuff
Private variables
BufferCtl
Private function prototypes
AUDIO_REC_Start()
AUDIO_REC_Process()
BSP_AUDIO_IN_TransferComplete_CallBack()
BSP_AUDIO_IN_HalfTransfer_CallBack()
WavProcess_EncInit(uint32_t, uint8_t *)
WavProcess_HeaderInit(uint8_t *, WAVE_FormatTypeDef *)
WavProcess_HeaderUpdate(uint8_t *, WAVE_FormatTypeDef *)
Files
loading...
CodeScopeSTM32 Libraries and SamplesAudio_playback_and_recordSrc/waverecorder.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/** ****************************************************************************** * @file Audio/Audio_playback_and_record/Src/waverecorder.c * @author MCD Application Team * @brief This file provides the Audio In (record) interface API ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** *//* ... */ /* Includes ------------------------------------------------------------------*/ #include "waverecorder.h" Includes /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ uint8_t pHeaderBuff[44]; Private define /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ static AUDIO_IN_BufferTypeDef BufferCtl; extern WAVE_FormatTypeDef WaveFormat; Private variables /* Private function prototypes -----------------------------------------------*/ static uint32_t WavProcess_EncInit(uint32_t Freq, uint8_t* pHeader); static uint32_t WavProcess_HeaderInit(uint8_t* pHeader, WAVE_FormatTypeDef* pWaveFormatStruct); static uint32_t WavProcess_HeaderUpdate(uint8_t* pHeader, WAVE_FormatTypeDef* pWaveFormatStruct); Private function prototypes /* Private functions ---------------------------------------------------------*/ /* A double MEMS microphone MP45DT02 mounted on STM324X9I-EVAL is connected to the Inter-IC Sound (I2S) peripheral. The I2S is configured in master receiver mode. In this mode, the I2S peripheral provides the clock to the MEMS microphones through CLK_IN and acquires the data (Audio samples) from the MEMS microphone through PDM_OUT. Data acquisition is performed in 16-bit PDM format and using I2S DMA mode. DMA is configured in circular mode In order to avoid data-loss, a 128 bytes buffer is used (BufferCtl.pdm_buff): - When a DMA half transfer is detected using the call back BSP_AUDIO_IN_HalfTransfer_CallBack() PDM frame has been received (64 bytes), a conversion to PCM is done and then this PCM frame is saved in RecBuf. - After converting/filtering samples from PDM to PCM, the samples are stored in USB buffer. - These two steps are repeated when the DMA Transfer complete interrupt is detected - When half of internal USB buffer is reach, an evacuation though USB is done. To avoid data-loss: - IT ISR priority must be set at a higher priority than USB, this priority order must be respected when managing other interrupts; - The processing time of converting/filtering samples from PDM to PCM PDM_Filter_64_LSB()) should be lower than the time required to fill a single buffer. Note that a PDM Audio software decoding library provided in binary is used in this application. For IAR EWARM toolchain, the library is labeled "libPDMFilter_CM4_IAR.a". *//* ... */ /** * @brief Starts Audio streaming. * @param None * @retval Audio error *//* ... */ AUDIO_ErrorTypeDef AUDIO_REC_Start(void) { uint32_t byteswritten = 0; uint8_t str[FILEMGR_FILE_NAME_SIZE + 20]; /* Create a new file system */ if(f_open(&WavFile, REC_WAVE_NAME, FA_CREATE_ALWAYS | FA_WRITE) == FR_OK) { /* Initialize header file */ WavProcess_EncInit(DEFAULT_AUDIO_IN_FREQ, pHeaderBuff); /* Write header file */ if(f_write(&WavFile, pHeaderBuff, 44, (void*)&byteswritten) == FR_OK) { AudioState = AUDIO_STATE_RECORD; BSP_LCD_SetTextColor(LCD_COLOR_WHITE); sprintf((char *)str, "Recording file: %s", (char *)REC_WAVE_NAME); BSP_LCD_ClearStringLine(4); BSP_LCD_DisplayStringAtLine(4, str); BSP_LCD_SetTextColor(LCD_COLOR_CYAN); sprintf((char *)str, "Sample rate : %d Hz", (int)DEFAULT_AUDIO_IN_FREQ); BSP_LCD_ClearStringLine(6); BSP_LCD_DisplayStringAtLine(6, str); sprintf((char *)str, "Channels number : %d", (int)DEFAULT_AUDIO_IN_CHANNEL_NBR); BSP_LCD_ClearStringLine(7); BSP_LCD_DisplayStringAtLine(7, str); sprintf((char *)str, "File Size :"); BSP_LCD_ClearStringLine(8); BSP_LCD_DisplayStringAtLine(8, str); BSP_LCD_DisplayStringAt(250, LINE(14), (uint8_t *)" [RECORD]", LEFT_MODE); { if(byteswritten != 0) { BSP_AUDIO_IN_Init(DEFAULT_AUDIO_IN_FREQ, DEFAULT_AUDIO_IN_BIT_RESOLUTION, DEFAULT_AUDIO_IN_CHANNEL_NBR); BSP_AUDIO_IN_Record((uint16_t*)&BufferCtl.pdm_buff[0], AUDIO_IN_PDM_BUFFER_SIZE); BufferCtl.fptr = byteswritten; BufferCtl.pcm_ptr = 0; BufferCtl.offset = 0; BufferCtl.wr_state = BUFFER_EMPTY; return AUDIO_ERROR_NONE; }if (byteswritten != 0) { ... } ...} }if (f_write(&WavFile, pHeaderBuff, 44, (void*)&byteswritten) == FR_OK) { ... } }if (f_open(&WavFile, REC_WAVE_NAME, FA_CREATE_ALWAYS | FA_WRITE) == FR_OK) { ... } return AUDIO_ERROR_IO; }{ ... } /** * @brief Manages Audio process. * @param None * @retval Audio error *//* ... */ AUDIO_ErrorTypeDef AUDIO_REC_Process(void) { uint32_t byteswritten = 0; AUDIO_ErrorTypeDef audio_error = AUDIO_ERROR_NONE; uint32_t elapsed_time; static uint32_t prev_elapsed_time = 0xFFFFFFFF; uint8_t str[16]; switch(AudioState) { case AUDIO_STATE_RECORD: /* MAX Recording time reached, so stop audio interface and close file */ if(BufferCtl.fptr >= REC_SAMPLE_LENGTH) { AudioState = AUDIO_STATE_STOP; break; }if (BufferCtl.fptr >= REC_SAMPLE_LENGTH) { ... } /* Check if there are Data to write in Usb Key */ if(BufferCtl.wr_state == BUFFER_FULL) { /* write buffer in file */ if(f_write(&WavFile, (uint8_t*)(BufferCtl.pcm_buff + BufferCtl.offset), AUDIO_IN_PCM_BUFFER_SIZE, (void*)&byteswritten) != FR_OK) { BSP_LCD_SetTextColor(LCD_COLOR_RED); BSP_LCD_DisplayStringAtLine(16, (uint8_t *)"RECORD FAIL"); return AUDIO_ERROR_IO; }if (f_write(&WavFile, (uint8_t*)(BufferCtl.pcm_buff + BufferCtl.offset), AUDIO_IN_PCM_BUFFER_SIZE, (void*)&byteswritten) != FR_OK) { ... } BufferCtl.fptr += byteswritten; BufferCtl.wr_state = BUFFER_EMPTY; }if (BufferCtl.wr_state == BUFFER_FULL) { ... } /* Display elapsed time */ elapsed_time = BufferCtl.fptr / (DEFAULT_AUDIO_IN_FREQ * DEFAULT_AUDIO_IN_CHANNEL_NBR * 2); if(prev_elapsed_time != elapsed_time) { prev_elapsed_time = elapsed_time; sprintf((char *)str, "[%02d:%02d]", (int)(elapsed_time /60), (int)(elapsed_time%60)); BSP_LCD_SetTextColor(LCD_COLOR_CYAN); BSP_LCD_DisplayStringAt(263, LINE(8), str, LEFT_MODE); sprintf((char *)str, "%4d KB", (int)((int32_t)BufferCtl.fptr/1024)); BSP_LCD_DisplayStringAt(83, LINE(8), str, LEFT_MODE); }if (prev_elapsed_time != elapsed_time) { ... } break; case AUDIO_STATE_RECORD: case AUDIO_STATE_STOP: /* Stop recorder */ BSP_AUDIO_IN_Stop(); if(f_lseek(&WavFile, 0) == FR_OK) { /* Update the wav file header save it into wav file */ WavProcess_HeaderUpdate(pHeaderBuff, &WaveFormat); if(f_write(&WavFile, pHeaderBuff, sizeof(WAVE_FormatTypeDef), (void*)&byteswritten) == FR_OK) { audio_error = AUDIO_ERROR_EOF; }if (f_write(&WavFile, pHeaderBuff, sizeof(WAVE_FormatTypeDef), (void*)&byteswritten) == FR_OK) { ... } else { audio_error = AUDIO_ERROR_IO; BSP_LCD_SetTextColor(LCD_COLOR_RED); BSP_LCD_DisplayStringAtLine(16, (uint8_t *)"RECORD FAIL"); }else { ... } }if (f_lseek(&WavFile, 0) == FR_OK) { ... } else { BSP_LCD_SetTextColor(LCD_COLOR_RED); BSP_LCD_DisplayStringAtLine(16, (uint8_t *)"RECORD FAIL"); audio_error = AUDIO_ERROR_IO; }else { ... } AudioState = AUDIO_STATE_IDLE; /* Close file */ f_close(&WavFile); break; case AUDIO_STATE_STOP: case AUDIO_STATE_PAUSE: BSP_LCD_DisplayStringAt(250, LINE(14), (uint8_t *)" [PAUSE] ", LEFT_MODE); BSP_AUDIO_IN_Pause(); AudioState = AUDIO_STATE_WAIT; break; case AUDIO_STATE_PAUSE: case AUDIO_STATE_RESUME: BSP_LCD_DisplayStringAt(250, LINE(14), (uint8_t *)" [RECORD] ", LEFT_MODE); BSP_AUDIO_IN_Resume(); AudioState = AUDIO_STATE_RECORD; break; case AUDIO_STATE_RESUME: case AUDIO_STATE_VOLUME_UP: if(AudioInVolume <= 90) { AudioInVolume += 10; }if (AudioInVolume <= 90) { ... } BSP_AUDIO_IN_SetVolume(AudioInVolume); AudioState = AUDIO_STATE_RECORD; break; case AUDIO_STATE_VOLUME_UP: case AUDIO_STATE_VOLUME_DOWN: if(AudioInVolume >= 10) { AudioInVolume -= 10; }if (AudioInVolume >= 10) { ... } BSP_AUDIO_IN_SetVolume(AudioInVolume); AudioState = AUDIO_STATE_RECORD; break; case AUDIO_STATE_VOLUME_DOWN: case AUDIO_STATE_NEXT: case AUDIO_STATE_PREVIOUS: AudioState = AUDIO_STATE_RECORD; break; case AUDIO_STATE_PREVIOUS: case AUDIO_STATE_WAIT: case AUDIO_STATE_IDLE: case AUDIO_STATE_INIT: default: /* Do Nothing */ break;default }switch (AudioState) { ... } return audio_error; }{ ... } /** * @brief Calculates the remaining file size and new position of the pointer. * @param None * @retval None *//* ... */ void BSP_AUDIO_IN_TransferComplete_CallBack(void) { /* PDM to PCM data convert */ BSP_AUDIO_IN_PDMToPCM((uint16_t*)&BufferCtl.pdm_buff[AUDIO_IN_PDM_BUFFER_SIZE/2], &BufferCtl.pcm_buff[BufferCtl.pcm_ptr]); BufferCtl.pcm_ptr+= AUDIO_IN_PDM_BUFFER_SIZE/4/2; if(BufferCtl.pcm_ptr == AUDIO_IN_PCM_BUFFER_SIZE/2) { BufferCtl.wr_state = BUFFER_FULL; BufferCtl.offset = 0; }if (BufferCtl.pcm_ptr == AUDIO_IN_PCM_BUFFER_SIZE/2) { ... } if(BufferCtl.pcm_ptr >= AUDIO_IN_PCM_BUFFER_SIZE) { BufferCtl.wr_state = BUFFER_FULL; BufferCtl.offset = AUDIO_IN_PCM_BUFFER_SIZE/2; BufferCtl.pcm_ptr = 0; }if (BufferCtl.pcm_ptr >= AUDIO_IN_PCM_BUFFER_SIZE) { ... } }{ ... } /** * @brief Manages the DMA Half Transfer complete interrupt. * @param None * @retval None *//* ... */ void BSP_AUDIO_IN_HalfTransfer_CallBack(void) { /* PDM to PCM data convert */ BSP_AUDIO_IN_PDMToPCM((uint16_t*)&BufferCtl.pdm_buff[0], &BufferCtl.pcm_buff[BufferCtl.pcm_ptr]); BufferCtl.pcm_ptr+= AUDIO_IN_PDM_BUFFER_SIZE/4/2; if(BufferCtl.pcm_ptr == AUDIO_IN_PCM_BUFFER_SIZE/2) { BufferCtl.wr_state = BUFFER_FULL; BufferCtl.offset = 0; }if (BufferCtl.pcm_ptr == AUDIO_IN_PCM_BUFFER_SIZE/2) { ... } if(BufferCtl.pcm_ptr >= AUDIO_IN_PCM_BUFFER_SIZE) { BufferCtl.wr_state = BUFFER_FULL; BufferCtl.offset = AUDIO_IN_PCM_BUFFER_SIZE/2; BufferCtl.pcm_ptr = 0; }if (BufferCtl.pcm_ptr >= AUDIO_IN_PCM_BUFFER_SIZE) { ... } }{ ... } /******************************************************************************* Static Functions *******************************************************************************//* ... */ /** * @brief Encoder initialization. * @param Freq: Sampling frequency. * @param pHeader: Pointer to the WAV file header to be written. * @retval 0 if success, !0 else. *//* ... */ static uint32_t WavProcess_EncInit(uint32_t Freq, uint8_t *pHeader) { /* Initialize the encoder structure */ WaveFormat.SampleRate = Freq; /* Audio sampling frequency */ WaveFormat.NbrChannels = 2; /* Number of channels: 1:Mono or 2:Stereo */ WaveFormat.BitPerSample = 16; /* Number of bits per sample (16, 24 or 32) */ WaveFormat.FileSize = 0x001D4C00; /* Total length of useful audio data (payload) */ WaveFormat.SubChunk1Size = 44; /* The file header chunk size */ WaveFormat.ByteRate = (WaveFormat.SampleRate * \ (WaveFormat.BitPerSample/8) * \ WaveFormat.NbrChannels); /* Number of bytes per second (sample rate * block align) */ WaveFormat.BlockAlign = WaveFormat.NbrChannels * \ (WaveFormat.BitPerSample/8); /* channels * bits/sample / 8 */ /* Parse the wav file header and extract required information */ if(WavProcess_HeaderInit(pHeader, &WaveFormat)) { return 1; }if (WavProcess_HeaderInit(pHeader, &WaveFormat)) { ... } return 0; }{ ... } /** * @brief Initialize the wave header file * @param pHeader: Header Buffer to be filled * @param pWaveFormatStruct: Pointer to the wave structure to be filled. * @retval 0 if passed, !0 if failed. *//* ... */ static uint32_t WavProcess_HeaderInit(uint8_t* pHeader, WAVE_FormatTypeDef* pWaveFormatStruct) { /* Write chunkID, must be 'RIFF' ------------------------------------------*/ pHeader[0] = 'R'; pHeader[1] = 'I'; pHeader[2] = 'F'; pHeader[3] = 'F'; Write chunkID, must be 'RIFF' /* Write the file length ---------------------------------------------------*/ /* The sampling time: this value will be written back at the end of the recording operation. Example: 661500 Bytes = 0x000A17FC, byte[7]=0x00, byte[4]=0xFC *//* ... */ pHeader[4] = 0x00; pHeader[5] = 0x4C; pHeader[6] = 0x1D; pHeader[7] = 0x00;Write the file length /* Write the file format, must be 'WAVE' -----------------------------------*/ pHeader[8] = 'W'; pHeader[9] = 'A'; pHeader[10] = 'V'; pHeader[11] = 'E'; Write the file format, must be 'WAVE' /* Write the format chunk, must be'fmt ' -----------------------------------*/ pHeader[12] = 'f'; pHeader[13] = 'm'; pHeader[14] = 't'; pHeader[15] = ' '; Write the format chunk, must be'fmt ' /* Write the length of the 'fmt' data, must be 0x10 ------------------------*/ pHeader[16] = 0x10; pHeader[17] = 0x00; pHeader[18] = 0x00; pHeader[19] = 0x00; Write the length of the 'fmt' data, must be 0x10 /* Write the audio format, must be 0x01 (PCM) ------------------------------*/ pHeader[20] = 0x01; pHeader[21] = 0x00; Write the audio format, must be 0x01 (PCM) /* Write the number of channels, ie. 0x01 (Mono) ---------------------------*/ pHeader[22] = pWaveFormatStruct->NbrChannels; pHeader[23] = 0x00; Write the number of channels, ie. 0x01 (Mono) /* Write the Sample Rate in Hz ---------------------------------------------*/ /* Write Little Endian ie. 8000 = 0x00001F40 => byte[24]=0x40, byte[27]=0x00*/ pHeader[24] = (uint8_t)((pWaveFormatStruct->SampleRate & 0xFF)); pHeader[25] = (uint8_t)((pWaveFormatStruct->SampleRate >> 8) & 0xFF); pHeader[26] = (uint8_t)((pWaveFormatStruct->SampleRate >> 16) & 0xFF); pHeader[27] = (uint8_t)((pWaveFormatStruct->SampleRate >> 24) & 0xFF); Write the Sample Rate in Hz /* Write the Byte Rate -----------------------------------------------------*/ pHeader[28] = (uint8_t)((pWaveFormatStruct->ByteRate & 0xFF)); pHeader[29] = (uint8_t)((pWaveFormatStruct->ByteRate >> 8) & 0xFF); pHeader[30] = (uint8_t)((pWaveFormatStruct->ByteRate >> 16) & 0xFF); pHeader[31] = (uint8_t)((pWaveFormatStruct->ByteRate >> 24) & 0xFF); Write the Byte Rate /* Write the block alignment -----------------------------------------------*/ pHeader[32] = pWaveFormatStruct->BlockAlign; pHeader[33] = 0x00; Write the block alignment /* Write the number of bits per sample -------------------------------------*/ pHeader[34] = pWaveFormatStruct->BitPerSample; pHeader[35] = 0x00; Write the number of bits per sample /* Write the Data chunk, must be 'data' ------------------------------------*/ pHeader[36] = 'd'; pHeader[37] = 'a'; pHeader[38] = 't'; pHeader[39] = 'a'; Write the Data chunk, must be 'data' /* Write the number of sample data -----------------------------------------*/ /* This variable will be written back at the end of the recording operation */ pHeader[40] = 0x00; pHeader[41] = 0x4C; pHeader[42] = 0x1D; pHeader[43] = 0x00; /* Return 0 if all operations are OK */ return 0; }{ ... } /** * @brief Initialize the wave header file * @param pHeader: Header Buffer to be filled * @param pWaveFormatStruct: Pointer to the wave structure to be filled. * @retval 0 if passed, !0 if failed. *//* ... */ static uint32_t WavProcess_HeaderUpdate(uint8_t* pHeader, WAVE_FormatTypeDef* pWaveFormatStruct) { /* Write the file length ---------------------------------------------------*/ /* The sampling time: this value will be written back at the end of the recording operation. Example: 661500 Bytes = 0x000A17FC, byte[7]=0x00, byte[4]=0xFC *//* ... */ pHeader[4] = (uint8_t)(BufferCtl.fptr); pHeader[5] = (uint8_t)(BufferCtl.fptr >> 8); pHeader[6] = (uint8_t)(BufferCtl.fptr >> 16); pHeader[7] = (uint8_t)(BufferCtl.fptr >> 24);Write the file length /* Write the number of sample data -----------------------------------------*/ /* This variable will be written back at the end of the recording operation */ BufferCtl.fptr -=44; pHeader[40] = (uint8_t)(BufferCtl.fptr); pHeader[41] = (uint8_t)(BufferCtl.fptr >> 8); pHeader[42] = (uint8_t)(BufferCtl.fptr >> 16); pHeader[43] = (uint8_t)(BufferCtl.fptr >> 24); /* Return 0 if all operations are OK */ return 0;Write the number of sample data }{ ... }