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 |
11 /* | 11 /* |
12 * testG711.cpp : Defines the entry point for the console application. | 12 * testG711.cpp : Defines the entry point for the console application. |
13 */ | 13 */ |
14 | 14 |
15 #include <stdio.h> | 15 #include <stdio.h> |
16 #include <stdlib.h> | 16 #include <stdlib.h> |
17 #include <string.h> | 17 #include <string.h> |
18 | 18 |
19 /* include API */ | 19 /* include API */ |
20 #include "g711_interface.h" | 20 #include "g711_interface.h" |
21 | 21 |
22 /* Runtime statistics */ | 22 /* Runtime statistics */ |
23 #include <time.h> | 23 #include <time.h> |
24 #define CLOCKS_PER_SEC_G711 1000 | 24 #define CLOCKS_PER_SEC_G711 1000 |
25 | 25 |
26 /* function for reading audio data from PCM file */ | 26 /* function for reading audio data from PCM file */ |
27 int readframe(int16_t* data, FILE* inp, int length) { | 27 bool readframe(int16_t* data, FILE* inp, int length) { |
28 | 28 short rlen = (short) fread(data, sizeof(int16_t), length, inp); |
29 short k, rlen, status = 0; | 29 if (rlen >= length) |
30 | 30 return false; |
31 rlen = (short) fread(data, sizeof(int16_t), length, inp); | 31 memset(data + rlen, 0, (length - rlen) * sizeof(int16_t)); |
32 if (rlen < length) { | 32 return true; |
33 for (k = rlen; k < length; k++) | |
34 data[k] = 0; | |
35 status = 1; | |
36 } | |
37 | |
38 return status; | |
39 } | 33 } |
40 | 34 |
41 int main(int argc, char* argv[]) { | 35 int main(int argc, char* argv[]) { |
42 char inname[80], outname[40], bitname[40]; | 36 char inname[80], outname[40], bitname[40]; |
43 FILE* inp; | 37 FILE* inp; |
44 FILE* outp; | 38 FILE* outp; |
45 FILE* bitp = NULL; | 39 FILE* bitp = NULL; |
46 int framecnt, endfile; | 40 int framecnt; |
| 41 bool endfile; |
47 | 42 |
48 int16_t framelength = 80; | 43 int16_t framelength = 80; |
49 | 44 |
50 int err; | 45 int err; |
51 | 46 |
52 /* Runtime statistics */ | 47 /* Runtime statistics */ |
53 double starttime; | 48 double starttime; |
54 double runtime; | 49 double runtime; |
55 double length_file; | 50 double length_file; |
56 | 51 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 } | 110 } |
116 printf("\nInput: %s\nOutput: %s\n", inname, outname); | 111 printf("\nInput: %s\nOutput: %s\n", inname, outname); |
117 if (argc == 6) { | 112 if (argc == 6) { |
118 printf("\nBitfile: %s\n", bitname); | 113 printf("\nBitfile: %s\n", bitname); |
119 } | 114 } |
120 | 115 |
121 starttime = clock() / (double) CLOCKS_PER_SEC_G711; /* Runtime statistics */ | 116 starttime = clock() / (double) CLOCKS_PER_SEC_G711; /* Runtime statistics */ |
122 | 117 |
123 /* Initialize encoder and decoder */ | 118 /* Initialize encoder and decoder */ |
124 framecnt = 0; | 119 framecnt = 0; |
125 endfile = 0; | 120 endfile = false; |
126 while (endfile == 0) { | 121 while (!endfile) { |
127 framecnt++; | 122 framecnt++; |
128 /* Read speech block */ | 123 /* Read speech block */ |
129 endfile = readframe(shortdata, inp, framelength); | 124 endfile = readframe(shortdata, inp, framelength); |
130 | 125 |
131 /* G.711 encoding */ | 126 /* G.711 encoding */ |
132 if (!strcmp(law, "A")) { | 127 if (!strcmp(law, "A")) { |
133 /* A-law encoding */ | 128 /* A-law encoding */ |
134 stream_len = WebRtcG711_EncodeA(shortdata, framelength, streamdata); | 129 stream_len = WebRtcG711_EncodeA(shortdata, framelength, streamdata); |
135 if (argc == 6) { | 130 if (argc == 6) { |
136 /* Write bits to file */ | 131 /* Write bits to file */ |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 printf("Time to run G.711: %.2f s (%.2f %% of realtime)\n\n", | 169 printf("Time to run G.711: %.2f s (%.2f %% of realtime)\n\n", |
175 runtime, | 170 runtime, |
176 (100 * runtime / length_file)); | 171 (100 * runtime / length_file)); |
177 printf("---------------------END----------------------\n"); | 172 printf("---------------------END----------------------\n"); |
178 | 173 |
179 fclose(inp); | 174 fclose(inp); |
180 fclose(outp); | 175 fclose(outp); |
181 | 176 |
182 return 0; | 177 return 0; |
183 } | 178 } |
OLD | NEW |