1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
84
85
86
87
88
89
90
95
96
97
98
99
100
101
102
103
104
105
106
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
155
156
157
163
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
209
210
211
216
221
222
225
226
227
/* ... */
#include "audio_play.h"
/* ... */
/* ... */
Includes
typedef struct
{
uint32_t ChunkID;
uint32_t FileSize;
uint32_t FileFormat;
uint32_t SubChunk1ID;
uint32_t SubChunk1Size;
uint16_t AudioFormat;
uint16_t NbrChannels;
uint32_t SampleRate;
uint32_t ByteRate;
uint16_t BlockAlign;
uint16_t BitPerSample;
uint32_t SubChunk2ID;
uint32_t SubChunk2Size;
...}WAVE_FormatTypeDef;
Private typedef
/* ... */
#define AUDIO_FILE_SIZE 0x20000
#define AUDIO_FILE_ADDRESS 0x08020000
Private define
extern __IO uint8_t UserPressButton;
extern __IO uint32_t PauseResumeStatus;
WAVE_FormatTypeDef *waveformat = NULL;
__IO uint32_t AudioTest = 0;
uint32_t AudioTotalSize = 0xFFFF;
uint32_t AudioRemSize = 0xFFFF;
uint16_t *CurrentPos;
extern uint16_t WrBuffer[WR_BUFFER_SIZE];
Private variables
/* ... */
void AudioPlay_Test(void)
{
__IO uint8_t volume = 70;
if(BSP_ACCELERO_Init() != ACCELERO_OK)
{
Error_Handler();
}if (BSP_ACCELERO_Init() != ACCELERO_OK) { ... }
BSP_ACCELERO_Click_ITConfig();
BSP_LED_On(LED6);
waveformat = (WAVE_FormatTypeDef*) AUDIO_FILE_ADDRESS;
if(BSP_AUDIO_OUT_Init(OUTPUT_DEVICE_AUTO, volume, waveformat->SampleRate) != 0)
{
Error_Handler();
}if (BSP_AUDIO_OUT_Init(OUTPUT_DEVICE_AUTO, volume, waveformat->SampleRate) != 0) { ... }
UserPressButton = 0;
AudioTest = 0;
AudioTotalSize = AUDIO_FILE_SIZE;
CurrentPos = (uint16_t *)(AUDIO_FILE_ADDRESS);
BSP_AUDIO_OUT_Play(CurrentPos, AudioTotalSize);
AudioRemSize = AudioTotalSize - AUDIODATA_SIZE * DMA_MAX(AudioTotalSize);
CurrentPos += DMA_MAX(AudioTotalSize);
while(!UserPressButton)
{
if (PauseResumeStatus == PAUSE_STATUS)
{
BSP_LED_On(LED4);
BSP_AUDIO_OUT_Pause();
PauseResumeStatus = IDLE_STATUS;
}if (PauseResumeStatus == PAUSE_STATUS) { ... }
else if (PauseResumeStatus == RESUME_STATUS)
{
BSP_LED_Off(LED4);
BSP_AUDIO_OUT_Resume();
PauseResumeStatus = IDLE_STATUS;
}else if (PauseResumeStatus == RESUME_STATUS) { ... }
}while (!UserPressButton) { ... }
if (BSP_AUDIO_OUT_Stop(CODEC_PDWN_HW) != AUDIO_OK)
{
Error_Handler();
}if (BSP_AUDIO_OUT_Stop(CODEC_PDWN_HW) != AUDIO_OK) { ... }
}{ ... }
/* ... */
/* ... */
void BSP_AUDIO_OUT_TransferComplete_CallBack()
{
uint32_t replay = 0;
if (AudioRemSize > 0)
{
BSP_AUDIO_OUT_ChangeBuffer((uint16_t*)CurrentPos, DMA_MAX(AudioRemSize/AUDIODATA_SIZE));
CurrentPos += DMA_MAX(AudioRemSize);
AudioRemSize -= AUDIODATA_SIZE * DMA_MAX(AudioRemSize/AUDIODATA_SIZE);
}if (AudioRemSize > 0) { ... }
else
{
replay = 1;
}else { ... }
if((AudioTest == 0) && (replay == 1))
{
CurrentPos = (uint16_t *)(AUDIO_FILE_ADDRESS);
BSP_AUDIO_OUT_Play(CurrentPos, AudioTotalSize);
AudioRemSize = AudioTotalSize - AUDIODATA_SIZE * DMA_MAX(AudioTotalSize);
CurrentPos += DMA_MAX(AudioTotalSize);
}if ((AudioTest == 0) && (replay == 1)) { ... }
if((AudioTest == 1) && (replay == 1))
{
BSP_AUDIO_OUT_Play(WrBuffer, AudioTotalSize);
}if ((AudioTest == 1) && (replay == 1)) { ... }
}{ ... }
/* ... */
void BSP_AUDIO_OUT_Error_CallBack(void)
{
Error_Handler();
}{ ... }
/* ... */
/* ... */