diff options
author | Peter Kasting <pkasting@google.com> | 2015-08-24 14:52:23 -0700 |
---|---|---|
committer | Peter Kasting <pkasting@google.com> | 2015-08-24 21:52:45 +0000 |
commit | dce40cf804019a9898b6ab8d8262466b697c56e0 (patch) | |
tree | 83ae06d5acc897bbf2fe73ea0c944b5ea4a0414d /webrtc/modules/audio_coding/codecs/g711/test/testG711.cc | |
parent | b594041ec8a3ae9f501260e2456d9d5ce6482819 (diff) | |
download | webrtc-dce40cf804019a9898b6ab8d8262466b697c56e0.tar.gz |
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
Diffstat (limited to 'webrtc/modules/audio_coding/codecs/g711/test/testG711.cc')
-rw-r--r-- | webrtc/modules/audio_coding/codecs/g711/test/testG711.cc | 40 |
1 files changed, 16 insertions, 24 deletions
diff --git a/webrtc/modules/audio_coding/codecs/g711/test/testG711.cc b/webrtc/modules/audio_coding/codecs/g711/test/testG711.cc index 49c671c5a0..94248f7a66 100644 --- a/webrtc/modules/audio_coding/codecs/g711/test/testG711.cc +++ b/webrtc/modules/audio_coding/codecs/g711/test/testG711.cc @@ -24,8 +24,8 @@ #define CLOCKS_PER_SEC_G711 1000 /* function for reading audio data from PCM file */ -bool readframe(int16_t* data, FILE* inp, int length) { - short rlen = (short) fread(data, sizeof(int16_t), length, inp); +bool readframe(int16_t* data, FILE* inp, size_t length) { + size_t rlen = fread(data, sizeof(int16_t), length, inp); if (rlen >= length) return false; memset(data + rlen, 0, (length - rlen) * sizeof(int16_t)); @@ -40,16 +40,14 @@ int main(int argc, char* argv[]) { int framecnt; bool endfile; - int16_t framelength = 80; - - int err; + size_t framelength = 80; /* Runtime statistics */ double starttime; double runtime; double length_file; - int16_t stream_len = 0; + size_t stream_len = 0; int16_t shortdata[480]; int16_t decoded[480]; uint8_t streamdata[1000]; @@ -80,11 +78,12 @@ int main(int argc, char* argv[]) { printf("-----------------------------------\n"); printf("G.711 version: %s\n\n", versionNumber); /* Get frame length */ - framelength = atoi(argv[1]); - if (framelength < 0) { - printf(" G.711: Invalid framelength %d.\n", framelength); - exit(1); + int framelength_int = atoi(argv[1]); + if (framelength_int < 0) { + printf(" G.722: Invalid framelength %d.\n", framelength_int); + exit(1); } + framelength = static_cast<size_t>(framelength_int); /* Get compression law */ strcpy(law, argv[2]); @@ -130,36 +129,29 @@ int main(int argc, char* argv[]) { if (argc == 6) { /* Write bits to file */ if (fwrite(streamdata, sizeof(unsigned char), stream_len, bitp) != - static_cast<size_t>(stream_len)) { + stream_len) { return -1; } } - err = WebRtcG711_DecodeA(streamdata, stream_len, decoded, - speechType); + WebRtcG711_DecodeA(streamdata, stream_len, decoded, speechType); } else if (!strcmp(law, "u")) { /* u-law encoding */ stream_len = WebRtcG711_EncodeU(shortdata, framelength, streamdata); if (argc == 6) { /* Write bits to file */ if (fwrite(streamdata, sizeof(unsigned char), stream_len, bitp) != - static_cast<size_t>(stream_len)) { + stream_len) { return -1; } } - err = WebRtcG711_DecodeU(streamdata, stream_len, decoded, speechType); + WebRtcG711_DecodeU(streamdata, stream_len, decoded, speechType); } else { printf("Wrong law mode\n"); exit(1); } - if (stream_len < 0 || err < 0) { - /* exit if returned with error */ - printf("Error in encoder/decoder\n"); - } else { - /* Write coded speech to file */ - if (fwrite(decoded, sizeof(short), framelength, outp) != - static_cast<size_t>(framelength)) { - return -1; - } + /* Write coded speech to file */ + if (fwrite(decoded, sizeof(short), framelength, outp) != framelength) { + return -1; } } |