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

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: 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;
kwiberg-webrtc 2015/06/10 11:58:32 Comment return value. Namespace.
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;
kwiberg-webrtc 2015/06/10 11:58:32 Move to first use?
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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 101
106 /* Create and init */ 102 /* Create and init */
107 WebRtcG722_CreateEncoder((G722EncInst **)&G722enc_inst); 103 WebRtcG722_CreateEncoder((G722EncInst **)&G722enc_inst);
108 WebRtcG722_CreateDecoder((G722DecInst **)&G722dec_inst); 104 WebRtcG722_CreateDecoder((G722DecInst **)&G722dec_inst);
109 WebRtcG722_EncoderInit((G722EncInst *)G722enc_inst); 105 WebRtcG722_EncoderInit((G722EncInst *)G722enc_inst);
110 WebRtcG722_DecoderInit((G722DecInst *)G722dec_inst); 106 WebRtcG722_DecoderInit((G722DecInst *)G722dec_inst);
111 107
112 108
113 /* Initialize encoder and decoder */ 109 /* Initialize encoder and decoder */
114 framecnt = 0; 110 framecnt = 0;
115 endfile = 0; 111 endfile = false;
116 while (endfile == 0) { 112 while (!endfile) {
117 framecnt++; 113 framecnt++;
118 114
119 /* Read speech block */ 115 /* Read speech block */
120 endfile = readframe(shortdata, inp, framelength); 116 endfile = readframe(shortdata, inp, framelength);
121 117
122 /* Start clock before call to encoder and decoder */ 118 /* Start clock before call to encoder and decoder */
123 starttime = clock()/(double)CLOCKS_PER_SEC_G722; 119 starttime = clock()/(double)CLOCKS_PER_SEC_G722;
124 120
125 /* G.722 encoding + decoding */ 121 /* G.722 encoding + decoding */
126 stream_len = WebRtcG722_Encode((G722EncInst *)G722enc_inst, shortdata, f ramelength, streamdata); 122 stream_len = WebRtcG722_Encode((G722EncInst *)G722enc_inst, shortdata, f ramelength, streamdata);
127 err = WebRtcG722_Decode(G722dec_inst, streamdata, stream_len, decoded, 123 err = WebRtcG722_Decode(G722dec_inst, streamdata, stream_len, decoded,
128 speechType); 124 speechType);
129 125
130 /* Stop clock after call to encoder and decoder */ 126 /* Stop clock after call to encoder and decoder */
131 runtime += (double)((clock()/(double)CLOCKS_PER_SEC_G722)-starttime); 127 runtime += (double)((clock()/(double)CLOCKS_PER_SEC_G722)-starttime);
132 128
133 if (stream_len < 0 || err < 0) { 129 if (stream_len < 0 || err < 0) {
134 /* exit if returned with error */ 130 /* exit if returned with error */
135 printf("Error in encoder/decoder\n"); 131 printf("Error in encoder/decoder\n");
136 } else { 132 } else {
137 /* Write coded bits to file */ 133 /* Write coded bits to file */
138 if (fwrite(streamdata, sizeof(short), stream_len/2, 134 if (fwrite(streamdata, sizeof(short), stream_len / 2, outbitp) !=
139 outbitp) != static_cast<size_t>(stream_len/2)) { 135 static_cast<size_t>(stream_len / 2)) {
140 return -1; 136 return -1;
141 } 137 }
142 /* Write coded speech to file */ 138 /* Write coded speech to file */
143 if (fwrite(decoded, sizeof(short), framelength, 139 if (fwrite(decoded, sizeof(short), framelength, outp) !=
144 outp) != static_cast<size_t>(framelength)) { 140 static_cast<size_t>(framelength)) {
145 return -1; 141 return -1;
146 } 142 }
147 } 143 }
148 } 144 }
149 145
150 WebRtcG722_FreeEncoder((G722EncInst *)G722enc_inst); 146 WebRtcG722_FreeEncoder((G722EncInst *)G722enc_inst);
151 WebRtcG722_FreeDecoder((G722DecInst *)G722dec_inst); 147 WebRtcG722_FreeDecoder((G722DecInst *)G722dec_inst);
152 148
153 length_file = ((double)framecnt*(double)framelength/16000); 149 length_file = ((double)framecnt*(double)framelength/16000);
154 printf("\n\nLength of speech file: %.1f s\n", length_file); 150 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)); 151 printf("Time to run G.722: %.2f s (%.2f %% of realtime)\n\n", runtime, (100*runtime/length_file));
156 printf("---------------------END----------------------\n"); 152 printf("---------------------END----------------------\n");
157 153
158 fclose(inp); 154 fclose(inp);
159 fclose(outbitp); 155 fclose(outbitp);
160 fclose(outp); 156 fclose(outp);
161 157
162 return 0; 158 return 0;
163 } 159 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698