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
|
/**************************************************************************//**
*
* @copyright (C) 2019 Nuvoton Technology Corp. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2020-1-16 Wayne First version
*
******************************************************************************/
#include <rtconfig.h>
#if defined(PKG_USING_WAVPLAYER)
#include "wavrecorder.h"
#include "wavplayer.h"
#include <dfs_file.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/statfs.h>
/*
The routine just for test automatically.
- For record function: Run it w/o parameter.
- For replay function: Run it with parameter.
*/
static int audio_test(int argc, char **argv)
{
#define DEF_MAX_ARGV_NUM 8
#define DEF_MAX_TEST_SECOND 5
int smplrate[] = {8000, 16000, 44100, 48000};
int smplbit[] = {16};
int chnum[] = {1, 2};
struct wavrecord_info info;
char strbuf[128];
int i, j, k;
int bDoRecording = 1;
struct stat stat_buf;
if (argc > 1)
bDoRecording = 0;
for (i = 0; i < sizeof(smplrate) / sizeof(int); i++)
{
for (j = 0; j < sizeof(smplbit) / sizeof(int); j++)
{
for (k = 0; k < sizeof(chnum) / sizeof(int); k++)
{
snprintf(strbuf, sizeof(strbuf), "/mnt/sd0/%d_%d_%d.wav", smplrate[i], smplbit[j], chnum[k]);
if (bDoRecording)
{
rt_kprintf("Recording file at %s\n", strbuf);
info.uri = strbuf;
info.samplerate = smplrate[i];
info.samplebits = smplbit[j];
info.channels = chnum[k];
wavrecorder_start(&info);
rt_thread_mdelay(DEF_MAX_TEST_SECOND * 1000);
wavrecorder_stop();
rt_thread_mdelay(DEF_MAX_TEST_SECOND * 1000);
}
else
{
if (stat((const char *)strbuf, &stat_buf) < 0)
{
rt_kprintf("%s non-exist.\n", strbuf);
continue;
}
rt_kprintf("Replay file at %s\n", strbuf);
wavplayer_play(strbuf);
rt_thread_mdelay(DEF_MAX_TEST_SECOND * 1000);
wavplayer_stop();
}
} // k
} // j
} // i
return 0;
}
#ifdef FINSH_USING_MSH
MSH_CMD_EXPORT(audio_test, Audio record / replay);
#endif
static int audio_overnight(int argc, char **argv)
{
#define DEF_MAX_TEST_SECOND 5
struct wavrecord_info info;
char strbuf[128];
struct stat stat_buf;
snprintf(strbuf, sizeof(strbuf), "/test.wav");
while (1)
{
rt_kprintf("Recording file at %s\n", strbuf);
info.uri = strbuf;
info.samplerate = 16000;
info.samplebits = 16;
info.channels = 2;
wavrecorder_start(&info);
rt_thread_mdelay(DEF_MAX_TEST_SECOND * 1000);
wavrecorder_stop();
rt_thread_mdelay(1000);
if (stat((const char *)strbuf, &stat_buf) < 0)
{
rt_kprintf("%s non-exist.\n", strbuf);
break;
}
rt_kprintf("Replay file at %s\n", strbuf);
wavplayer_play(strbuf);
rt_thread_mdelay(DEF_MAX_TEST_SECOND * 1000);
wavplayer_stop();
rt_thread_mdelay(1000);
}
return 0;
}
#ifdef FINSH_USING_MSH
MSH_CMD_EXPORT(audio_overnight, auto test record / replay);
#endif
#endif /* PKG_USING_WAVPLAYER */
|