1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
25
26
30
31
32
33
34
35
36
37
38
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
82
83
84
85
86
87
88
89
90
91
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
155
159
160
161
162
163
164
165
166
167
168
169
170
171
181
187
188
189
190
195
206
207
212
216
217
222
223
224
225
226
227
228
229
230
231
237
238
243
247
248
253
258
259
264
265
266
267
269
270
271
272
273
274
279
280
281
282
283
284
285
286
287
288
289
293
297
298
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
322
323
324
325
326
327
328
329
330
331
332
333
334
335
339
340
341
342
343
344
345
346
347
/* ... */
#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 BufferOffset = 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(BufferOffset == BUFFER_OFFSET_HALF)
{
f_read(&FileRead,
&Audio_Buffer[0],
AUDIO_BUFFER_SIZE/2,
(void *)&bytesread);
BufferOffset = BUFFER_OFFSET_NONE;
}if (BufferOffset == BUFFER_OFFSET_HALF) { ... }
if(BufferOffset == BUFFER_OFFSET_FULL)
{
f_read(&FileRead,
&Audio_Buffer[AUDIO_BUFFER_SIZE/2],
AUDIO_BUFFER_SIZE/2,
(void *)&bytesread);
BufferOffset = BUFFER_OFFSET_NONE;
}if (BufferOffset == 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)
{
BufferOffset = BUFFER_OFFSET_HALF;
}{ ... }
/* ... */
void BSP_AUDIO_OUT_TransferComplete_CallBack(void)
{
BufferOffset = 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)
{
while(1){};
}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) { ... }
}{ ... }
/* ... */