1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
26
27
31
32
33
34
35
36
37
38
39
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
83
84
85
86
87
88
89
90
91
92
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
157
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
184
185
192
193
194
195
200
211
212
217
221
222
227
228
229
230
231
232
233
234
235
236
242
243
248
252
253
258
263
264
269
270
271
272
274
275
276
277
278
279
284
285
286
287
288
289
290
291
292
293
294
298
302
303
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
327
328
329
330
331
332
333
334
335
336
337
338
339
340
344
345
346
347
348
349
350
351
352
/* ... */
#include "main.h"
/* ... */
Includes
#define AUDIO_BUFFER_SIZE 4096
Private define
__IO uint32_t LEDsState;
extern __IO uint32_t RepeatState, PauseResumeStatus, PressCount;
/* ... */
__IO uint32_t AudioPlayStart = 0;
static uint32_t WaveDataLength = 0;
static __IO uint32_t AudioRemSize = 0;
uint8_t Audio_Buffer[AUDIO_BUFFER_SIZE];
__IO BUFFER_StateTypeDef buffer_offset = BUFFER_OFFSET_NONE;
static uint8_t Volume = 70;
extern __IO uint32_t CmdIndex;
FIL FileRead;
DIR Directory;
extern uint32_t WaveRecStatus;
extern MSC_ApplicationTypeDef AppliState;
Private variables
/* ... */
void WavePlayBack(uint32_t AudioFreq)
{
UINT bytesread = 0;
AudioPlayStart = 1;
RepeatState = REPEAT_ON;
if(WavePlayerInit(AudioFreq) != 0)
{
Error_Handler();
}if (WavePlayerInit(AudioFreq) != 0) { ... }
f_lseek(&FileRead, 0);
f_read (&FileRead, &Audio_Buffer[0], AUDIO_BUFFER_SIZE, &bytesread);
AudioRemSize = WaveDataLength - bytesread;
BSP_AUDIO_OUT_Play((uint16_t*)&Audio_Buffer[0], AUDIO_BUFFER_SIZE);
LEDsState = LED6_TOGGLE;
PauseResumeStatus = RESUME_STATUS;
PressCount = 0;
while((AudioRemSize != 0) && (AppliState != APPLICATION_IDLE))
{
if(CmdIndex == CMD_PLAY)
{
if(PauseResumeStatus == PAUSE_STATUS)
{
LEDsState = STOP_TOGGLE;
WavePlayerPauseResume(PauseResumeStatus);
PauseResumeStatus = IDLE_STATUS;
}if (PauseResumeStatus == PAUSE_STATUS) { ... }
else if(PauseResumeStatus == RESUME_STATUS)
{
LEDsState = LED6_TOGGLE;
WavePlayerPauseResume(PauseResumeStatus);
PauseResumeStatus = IDLE_STATUS;
}else if (PauseResumeStatus == RESUME_STATUS) { ... }
bytesread = 0;
if(buffer_offset == BUFFER_OFFSET_HALF)
{
f_read(&FileRead,
&Audio_Buffer[0],
AUDIO_BUFFER_SIZE/2,
(void *)&bytesread);
buffer_offset = BUFFER_OFFSET_NONE;
}if (buffer_offset == BUFFER_OFFSET_HALF) { ... }
if(buffer_offset == BUFFER_OFFSET_FULL)
{
f_read(&FileRead,
&Audio_Buffer[AUDIO_BUFFER_SIZE/2],
AUDIO_BUFFER_SIZE/2,
(void *)&bytesread);
buffer_offset = BUFFER_OFFSET_NONE;
}if (buffer_offset == BUFFER_OFFSET_FULL) { ... }
if(AudioRemSize > (AUDIO_BUFFER_SIZE / 2))
{
AudioRemSize -= bytesread;
}if (AudioRemSize > (AUDIO_BUFFER_SIZE / 2)) { ... }
else
{
AudioRemSize = 0;
}else { ... }
}if (CmdIndex == CMD_PLAY) { ... }
else
{
WavePlayerStop();
f_close(&FileRead);
AudioRemSize = 0;
RepeatState = REPEAT_ON;
break;
}else { ... }
}while ((AudioRemSize != 0) && (AppliState != APPLICATION_IDLE)) { ... }
#ifdef PLAY_REPEAT_DISABLED
RepeatState = REPEAT_OFF;
WavePlayerStop();
f_close(&FileRead);
if(CmdIndex == CMD_PLAY)
{
LEDsState = LED4_TOGGLE;
}if (CmdIndex == CMD_PLAY) { ... }
/* ... */#else
LEDsState = LEDS_OFF;
RepeatState = REPEAT_ON;
AudioPlayStart = 0;
WavePlayerStop();
f_close(&FileRead);/* ... */
#endif
}{ ... }
/* ... */
void WavePlayerPauseResume(uint32_t wState)
{
if(wState == PAUSE_STATUS)
{
BSP_AUDIO_OUT_Pause();
}if (wState == PAUSE_STATUS) { ... }
else
{
BSP_AUDIO_OUT_Resume();
}else { ... }
}{ ... }
/* ... */
void WavePlayerStop(void)
{
BSP_AUDIO_OUT_Stop(CODEC_PDWN_HW);
}{ ... }
/* ... */
int WavePlayerInit(uint32_t AudioFreq)
{
BSP_ACCELERO_Click_ITConfig();
return(BSP_AUDIO_OUT_Init(OUTPUT_DEVICE_AUTO, Volume, AudioFreq));
}{ ... }
/* ... */
/* ... */
void BSP_AUDIO_OUT_HalfTransfer_CallBack(void)
{
buffer_offset = BUFFER_OFFSET_HALF;
}{ ... }
/* ... */
void BSP_AUDIO_OUT_TransferComplete_CallBack(void)
{
buffer_offset = BUFFER_OFFSET_FULL;
BSP_AUDIO_OUT_ChangeBuffer((uint16_t*)&Audio_Buffer[0], AUDIO_BUFFER_SIZE / 2);
}{ ... }
/* ... */
void BSP_AUDIO_OUT_Error_CallBack(void)
{
while (1)
{}while (1) { ... }
}{ ... }
/* ... */
void WavePlayerStart(void)
{
UINT bytesread = 0;
char path[] = "0:/";
char* wavefilename = NULL;
WAVE_FormatTypeDef waveformat;
if(f_opendir(&Directory, path) == FR_OK)
{
if(WaveRecStatus == 1)
{
wavefilename = REC_WAVE_NAME;
}if (WaveRecStatus == 1) { ... }
else
{
wavefilename = WAVE_NAME;
}else { ... }
if(f_open(&FileRead, wavefilename , FA_READ) != FR_OK)
{
BSP_LED_On(LED5);
CmdIndex = CMD_RECORD;
}if (f_open(&FileRead, wavefilename , FA_READ) != FR_OK) { ... }
else
{
f_read (&FileRead, &waveformat, sizeof(waveformat), &bytesread);
WaveDataLength = waveformat.FileSize;
WavePlayBack(waveformat.SampleRate);
}else { ... }
}if (f_opendir(&Directory, path) == FR_OK) { ... }
}{ ... }
/* ... */
void WavePlayer_CallBack(void)
{
if(AppliState != APPLICATION_IDLE)
{
RepeatState = REPEAT_ON;
AudioPlayStart = 0;
LEDsState = LEDS_OFF;
PauseResumeStatus = RESUME_STATUS;
WaveDataLength =0;
PressCount = 0;
if(BSP_AUDIO_OUT_Stop(CODEC_PDWN_HW) != AUDIO_OK)
{
Error_Handler();
}if (BSP_AUDIO_OUT_Stop(CODEC_PDWN_HW) != AUDIO_OK) { ... }
BSP_LED_Off(LED3);
BSP_LED_Off(LED4);
BSP_LED_Off(LED6);
}if (AppliState != APPLICATION_IDLE) { ... }
}{ ... }
/* ... */