Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(328)

Side by Side Diff: webrtc/modules/audio_coding/codecs/g722/test/testG722.cc

Issue 1172163004: Reformat existing code. There should be no functional effects. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Resync Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 int readframe(int16_t *data, FILE *inp, int length) 32 bool readframe(int16_t *data, FILE *inp, int length)
33 { 33 {
34 short k, rlen, status = 0; 34 short rlen = (short)fread(data, sizeof(int16_t), length, inp);
35 35 if (rlen >= length)
36 rlen = (short)fread(data, sizeof(int16_t), length, inp); 36 return false;
37 if (rlen < length) { 37 memset(data + rlen, 0, (length - rlen) * sizeof(int16_t));
38 for (k = rlen; k < length; k++) 38 return true;
39 data[k] = 0;
40 status = 1;
41 }
42
43 return status;
44 } 39 }
45 40
46 int main(int argc, char* argv[]) 41 int main(int argc, char* argv[])
47 { 42 {
48 char inname[60], outbit[40], outname[40]; 43 char inname[60], outbit[40], outname[40];
49 FILE *inp, *outbitp, *outp; 44 FILE *inp, *outbitp, *outp;
50 45
51 int framecnt, endfile; 46 int framecnt;
47 bool endfile;
52 int16_t framelength = 160; 48 int16_t framelength = 160;
53 G722EncInst *G722enc_inst; 49 G722EncInst *G722enc_inst;
54 G722DecInst *G722dec_inst; 50 G722DecInst *G722dec_inst;
55 int err; 51 int err;
56 52
57 /* Runtime statistics */ 53 /* Runtime statistics */
58 double starttime; 54 double starttime;
59 double runtime = 0; 55 double runtime = 0;
60 double length_file; 56 double length_file;
61 57
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 105
110 /* Create and init */ 106 /* Create and init */
111 WebRtcG722_CreateEncoder((G722EncInst **)&G722enc_inst); 107 WebRtcG722_CreateEncoder((G722EncInst **)&G722enc_inst);
112 WebRtcG722_CreateDecoder((G722DecInst **)&G722dec_inst); 108 WebRtcG722_CreateDecoder((G722DecInst **)&G722dec_inst);
113 WebRtcG722_EncoderInit((G722EncInst *)G722enc_inst); 109 WebRtcG722_EncoderInit((G722EncInst *)G722enc_inst);
114 WebRtcG722_DecoderInit((G722DecInst *)G722dec_inst); 110 WebRtcG722_DecoderInit((G722DecInst *)G722dec_inst);
115 111
116 112
117 /* Initialize encoder and decoder */ 113 /* Initialize encoder and decoder */
118 framecnt = 0; 114 framecnt = 0;
119 endfile = 0; 115 endfile = false;
120 while (endfile == 0) { 116 while (!endfile) {
121 framecnt++; 117 framecnt++;
122 118
123 /* Read speech block */ 119 /* Read speech block */
124 endfile = readframe(shortdata, inp, framelength); 120 endfile = readframe(shortdata, inp, framelength);
125 121
126 /* Start clock before call to encoder and decoder */ 122 /* Start clock before call to encoder and decoder */
127 starttime = clock()/(double)CLOCKS_PER_SEC_G722; 123 starttime = clock()/(double)CLOCKS_PER_SEC_G722;
128 124
129 /* G.722 encoding + decoding */ 125 /* G.722 encoding + decoding */
130 stream_len = WebRtcG722_Encode((G722EncInst *)G722enc_inst, shortdata, f ramelength, streamdata); 126 stream_len = WebRtcG722_Encode((G722EncInst *)G722enc_inst, shortdata, f ramelength, streamdata);
131 err = WebRtcG722_Decode(G722dec_inst, streamdata, stream_len, decoded, 127 err = WebRtcG722_Decode(G722dec_inst, streamdata, stream_len, decoded,
132 speechType); 128 speechType);
133 129
134 /* Stop clock after call to encoder and decoder */ 130 /* Stop clock after call to encoder and decoder */
135 runtime += (double)((clock()/(double)CLOCKS_PER_SEC_G722)-starttime); 131 runtime += (double)((clock()/(double)CLOCKS_PER_SEC_G722)-starttime);
136 132
137 if (stream_len < 0 || err < 0) { 133 if (stream_len < 0 || err < 0) {
138 /* exit if returned with error */ 134 /* exit if returned with error */
139 printf("Error in encoder/decoder\n"); 135 printf("Error in encoder/decoder\n");
140 } else { 136 } else {
141 /* Write coded bits to file */ 137 /* Write coded bits to file */
142 if (fwrite(streamdata, sizeof(short), stream_len/2, 138 if (fwrite(streamdata, sizeof(short), stream_len / 2, outbitp) !=
143 outbitp) != static_cast<size_t>(stream_len/2)) { 139 static_cast<size_t>(stream_len / 2)) {
144 return -1; 140 return -1;
145 } 141 }
146 /* Write coded speech to file */ 142 /* Write coded speech to file */
147 if (fwrite(decoded, sizeof(short), framelength, 143 if (fwrite(decoded, sizeof(short), framelength, outp) !=
148 outp) != static_cast<size_t>(framelength)) { 144 static_cast<size_t>(framelength)) {
149 return -1; 145 return -1;
150 } 146 }
151 } 147 }
152 } 148 }
153 149
154 WebRtcG722_FreeEncoder((G722EncInst *)G722enc_inst); 150 WebRtcG722_FreeEncoder((G722EncInst *)G722enc_inst);
155 WebRtcG722_FreeDecoder((G722DecInst *)G722dec_inst); 151 WebRtcG722_FreeDecoder((G722DecInst *)G722dec_inst);
156 152
157 length_file = ((double)framecnt*(double)framelength/16000); 153 length_file = ((double)framecnt*(double)framelength/16000);
158 printf("\n\nLength of speech file: %.1f s\n", length_file); 154 printf("\n\nLength of speech file: %.1f s\n", length_file);
159 printf("Time to run G.722: %.2f s (%.2f %% of realtime)\n\n", runtime, (100*runtime/length_file)); 155 printf("Time to run G.722: %.2f s (%.2f %% of realtime)\n\n", runtime, (100*runtime/length_file));
160 printf("---------------------END----------------------\n"); 156 printf("---------------------END----------------------\n");
161 157
162 fclose(inp); 158 fclose(inp);
163 fclose(outbitp); 159 fclose(outbitp);
164 fclose(outp); 160 fclose(outp);
165 161
166 return 0; 162 return 0;
167 } 163 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698