1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
31
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
83
84
85
86
91
92
93
94
95
96
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
124
130
134
135
136
137
138
139
140
141
142
143
144
145
146
147
153
159
163
164
165
166
167
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
202
203
204
209
210
211
216
220
221
226
230
231
236
241
242
245
246
/* ... */
#include "audio_record.h"
#include "string.h"
/* ... */
/* ... */
Includes
#define AUDIO_BUFFER_SIZE 8192
typedef struct {
int32_t offset;
uint32_t fptr;
...}Audio_BufferTypeDef;
typedef enum
{
BUFFER_OFFSET_NONE = 0,
BUFFER_OFFSET_HALF,
BUFFER_OFFSET_FULL,
...}BUFFER_StateTypeDef;
Private typedef
uint8_t pHeaderBuff[44];
uint16_t WrBuffer[WR_BUFFER_SIZE];
static uint16_t RecBuf[2*PCM_OUT_SIZE];
static uint16_t InternalBuffer[INTERNAL_BUFF_SIZE];
__IO uint32_t ITCounter = 0;
Audio_BufferTypeDef BufferCtl;
__IO uint32_t AUDIODataReady = 0, AUDIOBuffOffset = 0;
extern uint32_t AudioTest;
extern __IO uint8_t UserPressButton;
extern uint32_t AudioTotalSize;
extern uint32_t AudioRemSize;
extern uint16_t *CurrentPos;
Private variables
/* ... */
void AudioRecord_Test(void)
{
BufferCtl.offset = BUFFER_OFFSET_NONE;
if(BSP_AUDIO_IN_Init(DEFAULT_AUDIO_IN_FREQ, DEFAULT_AUDIO_IN_BIT_RESOLUTION, DEFAULT_AUDIO_IN_CHANNEL_NBR) != AUDIO_OK)
{
Error_Handler();
}if (BSP_AUDIO_IN_Init(DEFAULT_AUDIO_IN_FREQ, DEFAULT_AUDIO_IN_BIT_RESOLUTION, DEFAULT_AUDIO_IN_CHANNEL_NBR) != AUDIO_OK) { ... }
BSP_LED_On(LED3);
if (BSP_AUDIO_IN_Record((uint16_t*)&InternalBuffer[0], INTERNAL_BUFF_SIZE) != AUDIO_OK)
{
Error_Handler();
}if (BSP_AUDIO_IN_Record((uint16_t*)&InternalBuffer[0], INTERNAL_BUFF_SIZE) != AUDIO_OK) { ... }
BufferCtl.fptr = 0;
AUDIODataReady = 0;
while (AUDIODataReady != 2)
{
if(BufferCtl.offset == BUFFER_OFFSET_HALF)
{
BSP_AUDIO_IN_PDMToPCM((uint16_t*)&InternalBuffer[0], (uint16_t*)&RecBuf[0]);
memcpy((uint16_t*)&WrBuffer[ITCounter * (PCM_OUT_SIZE*2)], RecBuf, PCM_OUT_SIZE*4);
BufferCtl.offset = BUFFER_OFFSET_NONE;
if(ITCounter == (WR_BUFFER_SIZE/(PCM_OUT_SIZE*4))-1)
{
AUDIODataReady = 1;
AUDIOBuffOffset = 0;
ITCounter++;
}if (ITCounter == (WR_BUFFER_SIZE/(PCM_OUT_SIZE*4))-1) { ... }
else if(ITCounter == (WR_BUFFER_SIZE/(PCM_OUT_SIZE*2))-1)
{
AUDIODataReady = 2;
AUDIOBuffOffset = WR_BUFFER_SIZE/2;
ITCounter = 0;
}else if (ITCounter == (WR_BUFFER_SIZE/(PCM_OUT_SIZE*2))-1) { ... }
else
{
ITCounter++;
}else { ... }
}if (BufferCtl.offset == BUFFER_OFFSET_HALF) { ... }
if(BufferCtl.offset == BUFFER_OFFSET_FULL)
{
BSP_AUDIO_IN_PDMToPCM((uint16_t*)&InternalBuffer[INTERNAL_BUFF_SIZE/2], (uint16_t*)&RecBuf[0]);
memcpy((uint16_t*)&WrBuffer[ITCounter * (PCM_OUT_SIZE*2)], RecBuf, PCM_OUT_SIZE*4);
BufferCtl.offset = BUFFER_OFFSET_NONE;
if(ITCounter == (WR_BUFFER_SIZE/(PCM_OUT_SIZE*4))-1)
{
AUDIODataReady = 1;
AUDIOBuffOffset = 0;
ITCounter++;
}if (ITCounter == (WR_BUFFER_SIZE/(PCM_OUT_SIZE*4))-1) { ... }
else if(ITCounter == (WR_BUFFER_SIZE/(PCM_OUT_SIZE*2))-1)
{
AUDIODataReady = 2;
AUDIOBuffOffset = WR_BUFFER_SIZE/2;
ITCounter = 0;
}else if (ITCounter == (WR_BUFFER_SIZE/(PCM_OUT_SIZE*2))-1) { ... }
else
{
ITCounter++;
}else { ... }
}if (BufferCtl.offset == BUFFER_OFFSET_FULL) { ... }
}while (AUDIODataReady != 2) { ... };
if (BSP_AUDIO_IN_Stop() != AUDIO_OK)
{
Error_Handler();
}if (BSP_AUDIO_IN_Stop() != AUDIO_OK) { ... }
BSP_LED_Off(LED3);
BSP_LED_On(LED6);
AudioTest = 1;
UserPressButton = 0;
BSP_AUDIO_OUT_Init(OUTPUT_DEVICE_AUTO, 70, DEFAULT_AUDIO_IN_FREQ);
AudioTotalSize = AUDIODATA_SIZE * WR_BUFFER_SIZE;
AudioRemSize = 0;
CurrentPos = (uint16_t *)(WrBuffer);
BSP_AUDIO_OUT_Play(WrBuffer , AudioTotalSize);
while(!UserPressButton)
{
}while (!UserPressButton) { ... }
if (BSP_AUDIO_OUT_Stop(CODEC_PDWN_SW) != AUDIO_OK)
{
Error_Handler();
}if (BSP_AUDIO_OUT_Stop(CODEC_PDWN_SW) != AUDIO_OK) { ... }
}{ ... }
/* ... */
void BSP_AUDIO_IN_TransferComplete_CallBack(void)
{
BufferCtl.offset = BUFFER_OFFSET_FULL;
}{ ... }
/* ... */
void BSP_AUDIO_IN_HalfTransfer_CallBack(void)
{
BufferCtl.offset = BUFFER_OFFSET_HALF;
}{ ... }
/* ... */
void BSP_AUDIO_IN_Error_Callback(void)
{
Error_Handler();
}{ ... }
/* ... */
/* ... */