| 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 bool readframe(int16_t* data, FILE* inp, int length) { | 27 bool readframe(int16_t* data, FILE* inp, size_t length) { |
| 28 short rlen = (short) fread(data, sizeof(int16_t), length, inp); | 28 size_t rlen = fread(data, sizeof(int16_t), length, inp); |
| 29 if (rlen >= length) | 29 if (rlen >= length) |
| 30 return false; | 30 return false; |
| 31 memset(data + rlen, 0, (length - rlen) * sizeof(int16_t)); | 31 memset(data + rlen, 0, (length - rlen) * sizeof(int16_t)); |
| 32 return true; | 32 return true; |
| 33 } | 33 } |
| 34 | 34 |
| 35 int main(int argc, char* argv[]) { | 35 int main(int argc, char* argv[]) { |
| 36 char inname[80], outname[40], bitname[40]; | 36 char inname[80], outname[40], bitname[40]; |
| 37 FILE* inp; | 37 FILE* inp; |
| 38 FILE* outp; | 38 FILE* outp; |
| 39 FILE* bitp = NULL; | 39 FILE* bitp = NULL; |
| 40 int framecnt; | 40 int framecnt; |
| 41 bool endfile; | 41 bool endfile; |
| 42 | 42 |
| 43 int16_t framelength = 80; | 43 size_t framelength = 80; |
| 44 | |
| 45 int err; | |
| 46 | 44 |
| 47 /* Runtime statistics */ | 45 /* Runtime statistics */ |
| 48 double starttime; | 46 double starttime; |
| 49 double runtime; | 47 double runtime; |
| 50 double length_file; | 48 double length_file; |
| 51 | 49 |
| 52 int16_t stream_len = 0; | 50 size_t stream_len = 0; |
| 53 int16_t shortdata[480]; | 51 int16_t shortdata[480]; |
| 54 int16_t decoded[480]; | 52 int16_t decoded[480]; |
| 55 uint8_t streamdata[1000]; | 53 uint8_t streamdata[1000]; |
| 56 int16_t speechType[1]; | 54 int16_t speechType[1]; |
| 57 char law[2]; | 55 char law[2]; |
| 58 char versionNumber[40]; | 56 char versionNumber[40]; |
| 59 | 57 |
| 60 /* handling wrong input arguments in the command line */ | 58 /* handling wrong input arguments in the command line */ |
| 61 if ((argc != 5) && (argc != 6)) { | 59 if ((argc != 5) && (argc != 6)) { |
| 62 printf("\n\nWrong number of arguments or flag values.\n\n"); | 60 printf("\n\nWrong number of arguments or flag values.\n\n"); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 73 exit(0); | 71 exit(0); |
| 74 | 72 |
| 75 } | 73 } |
| 76 | 74 |
| 77 /* Get version and print */ | 75 /* Get version and print */ |
| 78 WebRtcG711_Version(versionNumber, 40); | 76 WebRtcG711_Version(versionNumber, 40); |
| 79 | 77 |
| 80 printf("-----------------------------------\n"); | 78 printf("-----------------------------------\n"); |
| 81 printf("G.711 version: %s\n\n", versionNumber); | 79 printf("G.711 version: %s\n\n", versionNumber); |
| 82 /* Get frame length */ | 80 /* Get frame length */ |
| 83 framelength = atoi(argv[1]); | 81 int framelength_int = atoi(argv[1]); |
| 84 if (framelength < 0) { | 82 if (framelength_int < 0) { |
| 85 printf(" G.711: Invalid framelength %d.\n", framelength); | 83 printf(" G.722: Invalid framelength %d.\n", framelength_int); |
| 86 exit(1); | 84 exit(1); |
| 87 } | 85 } |
| 86 framelength = static_cast<size_t>(framelength_int); |
| 88 | 87 |
| 89 /* Get compression law */ | 88 /* Get compression law */ |
| 90 strcpy(law, argv[2]); | 89 strcpy(law, argv[2]); |
| 91 | 90 |
| 92 /* Get Input and Output files */ | 91 /* Get Input and Output files */ |
| 93 sscanf(argv[3], "%s", inname); | 92 sscanf(argv[3], "%s", inname); |
| 94 sscanf(argv[4], "%s", outname); | 93 sscanf(argv[4], "%s", outname); |
| 95 if (argc == 6) { | 94 if (argc == 6) { |
| 96 sscanf(argv[5], "%s", bitname); | 95 sscanf(argv[5], "%s", bitname); |
| 97 if ((bitp = fopen(bitname, "wb")) == NULL) { | 96 if ((bitp = fopen(bitname, "wb")) == NULL) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 123 /* Read speech block */ | 122 /* Read speech block */ |
| 124 endfile = readframe(shortdata, inp, framelength); | 123 endfile = readframe(shortdata, inp, framelength); |
| 125 | 124 |
| 126 /* G.711 encoding */ | 125 /* G.711 encoding */ |
| 127 if (!strcmp(law, "A")) { | 126 if (!strcmp(law, "A")) { |
| 128 /* A-law encoding */ | 127 /* A-law encoding */ |
| 129 stream_len = WebRtcG711_EncodeA(shortdata, framelength, streamdata); | 128 stream_len = WebRtcG711_EncodeA(shortdata, framelength, streamdata); |
| 130 if (argc == 6) { | 129 if (argc == 6) { |
| 131 /* Write bits to file */ | 130 /* Write bits to file */ |
| 132 if (fwrite(streamdata, sizeof(unsigned char), stream_len, bitp) != | 131 if (fwrite(streamdata, sizeof(unsigned char), stream_len, bitp) != |
| 133 static_cast<size_t>(stream_len)) { | 132 stream_len) { |
| 134 return -1; | 133 return -1; |
| 135 } | 134 } |
| 136 } | 135 } |
| 137 err = WebRtcG711_DecodeA(streamdata, stream_len, decoded, | 136 WebRtcG711_DecodeA(streamdata, stream_len, decoded, speechType); |
| 138 speechType); | |
| 139 } else if (!strcmp(law, "u")) { | 137 } else if (!strcmp(law, "u")) { |
| 140 /* u-law encoding */ | 138 /* u-law encoding */ |
| 141 stream_len = WebRtcG711_EncodeU(shortdata, framelength, streamdata); | 139 stream_len = WebRtcG711_EncodeU(shortdata, framelength, streamdata); |
| 142 if (argc == 6) { | 140 if (argc == 6) { |
| 143 /* Write bits to file */ | 141 /* Write bits to file */ |
| 144 if (fwrite(streamdata, sizeof(unsigned char), stream_len, bitp) != | 142 if (fwrite(streamdata, sizeof(unsigned char), stream_len, bitp) != |
| 145 static_cast<size_t>(stream_len)) { | 143 stream_len) { |
| 146 return -1; | 144 return -1; |
| 147 } | 145 } |
| 148 } | 146 } |
| 149 err = WebRtcG711_DecodeU(streamdata, stream_len, decoded, speechType); | 147 WebRtcG711_DecodeU(streamdata, stream_len, decoded, speechType); |
| 150 } else { | 148 } else { |
| 151 printf("Wrong law mode\n"); | 149 printf("Wrong law mode\n"); |
| 152 exit(1); | 150 exit(1); |
| 153 } | 151 } |
| 154 if (stream_len < 0 || err < 0) { | 152 /* Write coded speech to file */ |
| 155 /* exit if returned with error */ | 153 if (fwrite(decoded, sizeof(short), framelength, outp) != framelength) { |
| 156 printf("Error in encoder/decoder\n"); | 154 return -1; |
| 157 } else { | |
| 158 /* Write coded speech to file */ | |
| 159 if (fwrite(decoded, sizeof(short), framelength, outp) != | |
| 160 static_cast<size_t>(framelength)) { | |
| 161 return -1; | |
| 162 } | |
| 163 } | 155 } |
| 164 } | 156 } |
| 165 | 157 |
| 166 runtime = (double)(clock() / (double) CLOCKS_PER_SEC_G711 - starttime); | 158 runtime = (double)(clock() / (double) CLOCKS_PER_SEC_G711 - starttime); |
| 167 length_file = ((double) framecnt * (double) framelength / 8000); | 159 length_file = ((double) framecnt * (double) framelength / 8000); |
| 168 printf("\n\nLength of speech file: %.1f s\n", length_file); | 160 printf("\n\nLength of speech file: %.1f s\n", length_file); |
| 169 printf("Time to run G.711: %.2f s (%.2f %% of realtime)\n\n", | 161 printf("Time to run G.711: %.2f s (%.2f %% of realtime)\n\n", |
| 170 runtime, | 162 runtime, |
| 171 (100 * runtime / length_file)); | 163 (100 * runtime / length_file)); |
| 172 printf("---------------------END----------------------\n"); | 164 printf("---------------------END----------------------\n"); |
| 173 | 165 |
| 174 fclose(inp); | 166 fclose(inp); |
| 175 fclose(outp); | 167 fclose(outp); |
| 176 | 168 |
| 177 return 0; | 169 return 0; |
| 178 } | 170 } |
| OLD | NEW |