OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 11 matching lines...) Expand all Loading... |
22 | 22 |
23 /* Runtime statistics */ | 23 /* Runtime statistics */ |
24 #include <time.h> | 24 #include <time.h> |
25 #define CLOCKS_PER_SEC_G722 100000 | 25 #define CLOCKS_PER_SEC_G722 100000 |
26 | 26 |
27 // Forward declaration | 27 // Forward declaration |
28 typedef struct WebRtcG722EncInst G722EncInst; | 28 typedef struct WebRtcG722EncInst G722EncInst; |
29 typedef struct WebRtcG722DecInst G722DecInst; | 29 typedef struct WebRtcG722DecInst G722DecInst; |
30 | 30 |
31 /* function for reading audio data from PCM file */ | 31 /* function for reading audio data from PCM file */ |
32 bool readframe(int16_t *data, FILE *inp, int length) | 32 bool readframe(int16_t *data, FILE *inp, size_t length) |
33 { | 33 { |
34 short rlen = (short)fread(data, sizeof(int16_t), length, inp); | 34 size_t rlen = fread(data, sizeof(int16_t), length, inp); |
35 if (rlen >= length) | 35 if (rlen >= length) |
36 return false; | 36 return false; |
37 memset(data + rlen, 0, (length - rlen) * sizeof(int16_t)); | 37 memset(data + rlen, 0, (length - rlen) * sizeof(int16_t)); |
38 return true; | 38 return true; |
39 } | 39 } |
40 | 40 |
41 int main(int argc, char* argv[]) | 41 int main(int argc, char* argv[]) |
42 { | 42 { |
43 char inname[60], outbit[40], outname[40]; | 43 char inname[60], outbit[40], outname[40]; |
44 FILE *inp, *outbitp, *outp; | 44 FILE *inp, *outbitp, *outp; |
45 | 45 |
46 int framecnt; | 46 int framecnt; |
47 bool endfile; | 47 bool endfile; |
48 int16_t framelength = 160; | 48 size_t framelength = 160; |
49 G722EncInst *G722enc_inst; | 49 G722EncInst *G722enc_inst; |
50 G722DecInst *G722dec_inst; | 50 G722DecInst *G722dec_inst; |
51 int err; | |
52 | 51 |
53 /* Runtime statistics */ | 52 /* Runtime statistics */ |
54 double starttime; | 53 double starttime; |
55 double runtime = 0; | 54 double runtime = 0; |
56 double length_file; | 55 double length_file; |
57 | 56 |
58 int16_t stream_len = 0; | 57 size_t stream_len = 0; |
59 int16_t shortdata[960]; | 58 int16_t shortdata[960]; |
60 int16_t decoded[960]; | 59 int16_t decoded[960]; |
61 uint8_t streamdata[80 * 6]; | 60 uint8_t streamdata[80 * 6]; |
62 int16_t speechType[1]; | 61 int16_t speechType[1]; |
63 | 62 |
64 /* handling wrong input arguments in the command line */ | 63 /* handling wrong input arguments in the command line */ |
65 if (argc!=5) { | 64 if (argc!=5) { |
66 printf("\n\nWrong number of arguments or flag values.\n\n"); | 65 printf("\n\nWrong number of arguments or flag values.\n\n"); |
67 | 66 |
68 printf("\n"); | 67 printf("\n"); |
69 printf("Usage:\n\n"); | 68 printf("Usage:\n\n"); |
70 printf("./testG722.exe framelength infile outbitfile outspeechfile \n\n"
); | 69 printf("./testG722.exe framelength infile outbitfile outspeechfile \n\n"
); |
71 printf("with:\n"); | 70 printf("with:\n"); |
72 printf("framelength : Framelength in samples.\n\n"); | 71 printf("framelength : Framelength in samples.\n\n"); |
73 printf("infile : Normal speech input file\n\n"); | 72 printf("infile : Normal speech input file\n\n"); |
74 printf("outbitfile : Bitstream output file\n\n"); | 73 printf("outbitfile : Bitstream output file\n\n"); |
75 printf("outspeechfile: Speech output file\n\n"); | 74 printf("outspeechfile: Speech output file\n\n"); |
76 exit(0); | 75 exit(0); |
77 | 76 |
78 } | 77 } |
79 | 78 |
80 /* Get frame length */ | 79 /* Get frame length */ |
81 framelength = atoi(argv[1]); | 80 int framelength_int = atoi(argv[1]); |
82 if (framelength < 0) { | 81 if (framelength_int < 0) { |
83 printf(" G.722: Invalid framelength %d.\n", framelength); | 82 printf(" G.722: Invalid framelength %d.\n", framelength_int); |
84 exit(1); | 83 exit(1); |
85 } | 84 } |
| 85 framelength = static_cast<size_t>(framelength_int); |
86 | 86 |
87 /* Get Input and Output files */ | 87 /* Get Input and Output files */ |
88 sscanf(argv[2], "%s", inname); | 88 sscanf(argv[2], "%s", inname); |
89 sscanf(argv[3], "%s", outbit); | 89 sscanf(argv[3], "%s", outbit); |
90 sscanf(argv[4], "%s", outname); | 90 sscanf(argv[4], "%s", outname); |
91 | 91 |
92 if ((inp = fopen(inname,"rb")) == NULL) { | 92 if ((inp = fopen(inname,"rb")) == NULL) { |
93 printf(" G.722: Cannot read file %s.\n", inname); | 93 printf(" G.722: Cannot read file %s.\n", inname); |
94 exit(1); | 94 exit(1); |
95 } | 95 } |
(...skipping 21 matching lines...) Expand all Loading... |
117 framecnt++; | 117 framecnt++; |
118 | 118 |
119 /* Read speech block */ | 119 /* Read speech block */ |
120 endfile = readframe(shortdata, inp, framelength); | 120 endfile = readframe(shortdata, inp, framelength); |
121 | 121 |
122 /* Start clock before call to encoder and decoder */ | 122 /* Start clock before call to encoder and decoder */ |
123 starttime = clock()/(double)CLOCKS_PER_SEC_G722; | 123 starttime = clock()/(double)CLOCKS_PER_SEC_G722; |
124 | 124 |
125 /* G.722 encoding + decoding */ | 125 /* G.722 encoding + decoding */ |
126 stream_len = WebRtcG722_Encode((G722EncInst *)G722enc_inst, shortdata, f
ramelength, streamdata); | 126 stream_len = WebRtcG722_Encode((G722EncInst *)G722enc_inst, shortdata, f
ramelength, streamdata); |
127 err = WebRtcG722_Decode(G722dec_inst, streamdata, stream_len, decoded, | 127 WebRtcG722_Decode(G722dec_inst, streamdata, stream_len, decoded, |
128 speechType); | 128 speechType); |
129 | 129 |
130 /* Stop clock after call to encoder and decoder */ | 130 /* Stop clock after call to encoder and decoder */ |
131 runtime += (double)((clock()/(double)CLOCKS_PER_SEC_G722)-starttime); | 131 runtime += (double)((clock()/(double)CLOCKS_PER_SEC_G722)-starttime); |
132 | 132 |
133 if (stream_len < 0 || err < 0) { | 133 /* Write coded bits to file */ |
134 /* exit if returned with error */ | 134 if (fwrite(streamdata, sizeof(short), stream_len / 2, outbitp) != |
135 printf("Error in encoder/decoder\n"); | 135 stream_len / 2) { |
136 } else { | 136 return -1; |
137 /* Write coded bits to file */ | 137 } |
138 if (fwrite(streamdata, sizeof(short), stream_len / 2, outbitp) != | 138 /* Write coded speech to file */ |
139 static_cast<size_t>(stream_len / 2)) { | 139 if (fwrite(decoded, sizeof(short), framelength, outp) != |
140 return -1; | 140 framelength) { |
141 } | 141 return -1; |
142 /* Write coded speech to file */ | |
143 if (fwrite(decoded, sizeof(short), framelength, outp) != | |
144 static_cast<size_t>(framelength)) { | |
145 return -1; | |
146 } | |
147 } | 142 } |
148 } | 143 } |
149 | 144 |
150 WebRtcG722_FreeEncoder((G722EncInst *)G722enc_inst); | 145 WebRtcG722_FreeEncoder((G722EncInst *)G722enc_inst); |
151 WebRtcG722_FreeDecoder((G722DecInst *)G722dec_inst); | 146 WebRtcG722_FreeDecoder((G722DecInst *)G722dec_inst); |
152 | 147 |
153 length_file = ((double)framecnt*(double)framelength/16000); | 148 length_file = ((double)framecnt*(double)framelength/16000); |
154 printf("\n\nLength of speech file: %.1f s\n", length_file); | 149 printf("\n\nLength of speech file: %.1f s\n", length_file); |
155 printf("Time to run G.722: %.2f s (%.2f %% of realtime)\n\n", runtime,
(100*runtime/length_file)); | 150 printf("Time to run G.722: %.2f s (%.2f %% of realtime)\n\n", runtime,
(100*runtime/length_file)); |
156 printf("---------------------END----------------------\n"); | 151 printf("---------------------END----------------------\n"); |
157 | 152 |
158 fclose(inp); | 153 fclose(inp); |
159 fclose(outbitp); | 154 fclose(outbitp); |
160 fclose(outp); | 155 fclose(outp); |
161 | 156 |
162 return 0; | 157 return 0; |
163 } | 158 } |
OLD | NEW |