1 /*
2 * audio_test.c -- audio test application
3 *
4 * Copyright (c) 2017 Rockchip Electronics Co. Ltd.
5 * Author: Panzhenzhuan Wang <randy.wang@rock-chips.com>
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <unistd.h>
24 #include <sys/time.h>
25
26 #include <sys/types.h>
27 #include <sys/stat.h>
28 #include <fcntl.h>
29
30 #include "audio_test.h"
31
32 #define LOG_TAG "audio_test"
33 #include "common.h"
34 #define AUDIO_EVENT_TIMEOUT -85
35
36 //*Audio test
audio_test(void * argv)37 void *audio_test(void *argv)
38 {
39 char cmd[128];
40
41 //* 1���ȷ���
42 fprintf(stderr,"Start test audio record and play.\n");
43 sprintf(cmd,"aplay %s/%s",PCBA_TEST_PATH,AUDIO_PLAY_FILE);
44 system(cmd);
45
46 //* 2��¼���ٷ���
47 //system("aplay /data/cfg/rk_pcba_test/recording_3s.wav");
48
49 //ָ��Card 3��device 0��¼��3��
50 sprintf(cmd,"arecord -D hw:3,0 -f S16_LE -c 2 -r 16000 -d 3 %s/%s",PCBA_TEST_PATH,AUDIO_RECORD_FILE);
51 system(cmd);
52 fprintf(stderr,"recording\n ");
53 sprintf(cmd,"aplay -f S16_LE -c 2 -r 16000 -d 3 %s/%s",PCBA_TEST_PATH,AUDIO_RECORD_FILE); //����
54 system(cmd);
55 fprintf(stderr,"playing\n ");
56 sprintf(cmd,"rm %s/%s",PCBA_TEST_PATH,AUDIO_RECORD_FILE);
57 fprintf(stderr,"=========Audio test finished=============\n");
58 }
59
60 /*���������*/
main(int argc,char * argv[])61 int main(int argc, char *argv[])
62 {
63 int delay_t = 0,err_code = 0;
64 struct timeval t1, t2;
65 char buf[COMMAND_VALUESIZE] = "audio_test";
66 char result[COMMAND_VALUESIZE] = RESULT_PASS;
67
68
69 log_info("audio test start...\n");
70 gettimeofday(&t1, NULL);
71 while(1)
72 {
73 audio_test(argv[0]);
74 gettimeofday(&t2, NULL);
75 delay_t = (t2.tv_sec - t1.tv_sec) * 1000000 + (t2.tv_usec - t1.tv_usec);
76 if (delay_t > MANUAL_TEST_TIMEOUT) {
77 log_warn("audio test end, timeout 60s\n");
78 err_code = AUDIO_EVENT_TIMEOUT;
79 break;
80 }
81 }
82 if (err_code)
83 strcpy(result, RESULT_FAIL);
84 send_msg_to_server(buf, result, err_code);
85 return 0;
86 }
87