1 /*
2 * Copyright (C) 2020, Fuzhou Rockchip Electronics Co., Ltd.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of Fuzhou Rockchip Electronics Co., Ltd. nor the
14 * names of its contributors may be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33
34 #include <time.h>
35
36 #include "RKAP_3A.h"
37
main(int argc,char ** argv)38 int main(int argc, char **argv)
39 {
40 RKAP_Handle *ap_aec_tx = NULL, * ap_aec_rx = NULL;
41 RKAP_AEC_State state;
42 FILE *fp_near = NULL, *fp_far = NULL, *fp_out_tx = NULL, *fp_out_rx = NULL;
43 int swFs;
44 int swFrameLen;
45 void *vParaData;
46 short *swBufferIn, *swBufferRef, *swBufferOut;
47 int dataLen = 0;
48
49 if (argc != 6)
50 {
51 fprintf(stderr, "Usage: ./test_rkap_3a <near.pcm> <far.pcm> <out.pcm> <para.bin> <rate 8000 or 16000>\n");
52 fprintf(stderr, "For example:\n");
53 fprintf(stderr, " ./test_rkap_3a rec.pcm ref.pcm out_aec.pcm RKAP_3A_Para.bin 8000\n");
54 exit(1);
55 }
56 fp_near = fopen(argv[1], "rb");
57 if (fp_near == NULL)
58 {
59 fprintf(stderr, "%s fp_near fopen failed\n", argv[1]);
60 exit(1);
61 }
62 fp_far = fopen(argv[2], "rb");
63 if (fp_far == NULL)
64 {
65 fprintf(stderr, "%s fp_far fopen failed\n", argv[2]);
66 exit(1);
67 }
68 fp_out_tx = fopen(argv[3], "wb");
69 if (fp_out_tx == NULL)
70 {
71 fprintf(stderr, "%s fp_out_tx fopen failed\n", argv[3]);
72 exit(1);
73 }
74
75 state.pathPara = argv[4];
76
77 swFs = atoi(argv[5]);
78 if (swFs != 8000 && swFs != 16000)
79 {
80 fprintf(stderr, "Not supported sample rate: %d\n", swFs);
81 exit(1);
82 }
83 swFrameLen = swFs / 50;
84 state.swSampleRate = swFs;
85 state.swFrameLen = swFrameLen;
86
87 /* tx init */
88 ap_aec_tx = RKAP_3A_Init(&state, AEC_TX_TYPE);
89 if (ap_aec_tx == NULL)
90 {
91 fprintf(stderr, "RKAP 3A TX Init Failed\n");
92 exit(1);
93 }
94 /* rx init */
95 ap_aec_rx = RKAP_3A_Init(&state, AEC_RX_TYPE);
96 if (ap_aec_rx == NULL)
97 {
98 fprintf(stderr, "RKAP 3A RX Init Failed\n");
99 exit(1);
100 }
101
102 swBufferIn = (short *)malloc(sizeof(short) * swFrameLen);
103 swBufferRef = (short *)malloc(sizeof(short) * swFrameLen);
104 swBufferOut = (short *)malloc(sizeof(short) * swFrameLen);
105
106 while (!feof(fp_near) && !feof(fp_far))
107 {
108 dataLen = fread(swBufferIn, sizeof(short), swFrameLen, fp_near);
109 dataLen = fread(swBufferRef, sizeof(short), swFrameLen, fp_far);
110 RKAP_3A_Process(ap_aec_rx, swBufferIn, NULL, swBufferOut);
111 RKAP_3A_Process(ap_aec_tx, swBufferIn, swBufferRef, swBufferOut);
112 fwrite(swBufferOut, sizeof(short), swFrameLen, fp_out_tx);
113 }
114
115 RKAP_3A_Destroy(ap_aec_tx);
116 RKAP_3A_Destroy(ap_aec_rx);
117 free(swBufferRef);
118 free(swBufferIn);
119 free(swBufferOut);
120
121 if (fp_far)
122 fclose(fp_far);
123 if (fp_near)
124 fclose(fp_near);
125 if (fp_out_tx)
126 fclose(fp_out_tx);
127
128 printf("test_rkap_3a Done\n");
129
130 return 0;
131 }
132