| OLD | NEW |
| 1 /* Copyright (c) 2007-2008 CSIRO | 1 /* Copyright (c) 2007-2008 CSIRO |
| 2 Copyright (c) 2007-2009 Xiph.Org Foundation | 2 Copyright (c) 2007-2009 Xiph.Org Foundation |
| 3 Written by Jean-Marc Valin */ | 3 Written by Jean-Marc Valin */ |
| 4 /* | 4 /* |
| 5 Redistribution and use in source and binary forms, with or without | 5 Redistribution and use in source and binary forms, with or without |
| 6 modification, are permitted provided that the following conditions | 6 modification, are permitted provided that the following conditions |
| 7 are met: | 7 are met: |
| 8 | 8 |
| 9 - Redistributions of source code must retain the above copyright | 9 - Redistributions of source code must retain the above copyright |
| 10 notice, this list of conditions and the following disclaimer. | 10 notice, this list of conditions and the following disclaimer. |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 ch[2] = (i>>8)&0xFF; | 72 ch[2] = (i>>8)&0xFF; |
| 73 ch[3] = i&0xFF; | 73 ch[3] = i&0xFF; |
| 74 } | 74 } |
| 75 | 75 |
| 76 static opus_uint32 char_to_int(unsigned char ch[4]) | 76 static opus_uint32 char_to_int(unsigned char ch[4]) |
| 77 { | 77 { |
| 78 return ((opus_uint32)ch[0]<<24) | ((opus_uint32)ch[1]<<16) | 78 return ((opus_uint32)ch[0]<<24) | ((opus_uint32)ch[1]<<16) |
| 79 | ((opus_uint32)ch[2]<< 8) | (opus_uint32)ch[3]; | 79 | ((opus_uint32)ch[2]<< 8) | (opus_uint32)ch[3]; |
| 80 } | 80 } |
| 81 | 81 |
| 82 static void check_decoder_option(int encode_only, const char *opt) | |
| 83 { | |
| 84 if (encode_only) | |
| 85 { | |
| 86 fprintf(stderr, "option %s is only for decoding\n", opt); | |
| 87 exit(EXIT_FAILURE); | |
| 88 } | |
| 89 } | |
| 90 | |
| 91 static void check_encoder_option(int decode_only, const char *opt) | 82 static void check_encoder_option(int decode_only, const char *opt) |
| 92 { | 83 { |
| 93 if (decode_only) | 84 if (decode_only) |
| 94 { | 85 { |
| 95 fprintf(stderr, "option %s is only for encoding\n", opt); | 86 fprintf(stderr, "option %s is only for encoding\n", opt); |
| 96 exit(EXIT_FAILURE); | 87 exit(EXIT_FAILURE); |
| 97 } | 88 } |
| 98 } | 89 } |
| 99 | 90 |
| 100 static const int silk8_test[][4] = { | 91 static const int silk8_test[][4] = { |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 application = OPUS_APPLICATION_RESTRICTED_LOWDELAY; | 301 application = OPUS_APPLICATION_RESTRICTED_LOWDELAY; |
| 311 else if (strcmp(argv[args], "audio")!=0) { | 302 else if (strcmp(argv[args], "audio")!=0) { |
| 312 fprintf(stderr, "unknown application: %s\n", argv[args]); | 303 fprintf(stderr, "unknown application: %s\n", argv[args]); |
| 313 print_usage(argv); | 304 print_usage(argv); |
| 314 return EXIT_FAILURE; | 305 return EXIT_FAILURE; |
| 315 } | 306 } |
| 316 args++; | 307 args++; |
| 317 } | 308 } |
| 318 sampling_rate = (opus_int32)atol(argv[args]); | 309 sampling_rate = (opus_int32)atol(argv[args]); |
| 319 args++; | 310 args++; |
| 320 channels = atoi(argv[args]); | |
| 321 args++; | |
| 322 if (!decode_only) | |
| 323 { | |
| 324 bitrate_bps = (opus_int32)atol(argv[args]); | |
| 325 args++; | |
| 326 } | |
| 327 | 311 |
| 328 if (sampling_rate != 8000 && sampling_rate != 12000 | 312 if (sampling_rate != 8000 && sampling_rate != 12000 |
| 329 && sampling_rate != 16000 && sampling_rate != 24000 | 313 && sampling_rate != 16000 && sampling_rate != 24000 |
| 330 && sampling_rate != 48000) | 314 && sampling_rate != 48000) |
| 331 { | 315 { |
| 332 fprintf(stderr, "Supported sampling rates are 8000, 12000, " | 316 fprintf(stderr, "Supported sampling rates are 8000, 12000, " |
| 333 "16000, 24000 and 48000.\n"); | 317 "16000, 24000 and 48000.\n"); |
| 334 return EXIT_FAILURE; | 318 return EXIT_FAILURE; |
| 335 } | 319 } |
| 336 frame_size = sampling_rate/50; | 320 frame_size = sampling_rate/50; |
| 337 | 321 |
| 322 channels = atoi(argv[args]); |
| 323 args++; |
| 324 |
| 325 if (channels < 1 || channels > 2) |
| 326 { |
| 327 fprintf(stderr, "Opus_demo supports only 1 or 2 channels.\n"); |
| 328 return EXIT_FAILURE; |
| 329 } |
| 330 |
| 331 if (!decode_only) |
| 332 { |
| 333 bitrate_bps = (opus_int32)atol(argv[args]); |
| 334 args++; |
| 335 } |
| 336 |
| 338 /* defaults: */ | 337 /* defaults: */ |
| 339 use_vbr = 1; | 338 use_vbr = 1; |
| 340 bandwidth = OPUS_AUTO; | 339 bandwidth = OPUS_AUTO; |
| 341 max_payload_bytes = MAX_PACKET; | 340 max_payload_bytes = MAX_PACKET; |
| 342 complexity = 10; | 341 complexity = 10; |
| 343 use_inbandfec = 0; | 342 use_inbandfec = 0; |
| 344 forcechannels = OPUS_AUTO; | 343 forcechannels = OPUS_AUTO; |
| 345 use_dtx = 0; | 344 use_dtx = 0; |
| 346 packet_loss_perc = 0; | 345 packet_loss_perc = 0; |
| 347 max_frame_size = 2*48000; | 346 max_frame_size = 2*48000; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 args++; | 417 args++; |
| 419 } else if( strcmp( argv[ args ], "-delayed-decision" ) == 0 ) { | 418 } else if( strcmp( argv[ args ], "-delayed-decision" ) == 0 ) { |
| 420 check_encoder_option(decode_only, "-delayed-decision"); | 419 check_encoder_option(decode_only, "-delayed-decision"); |
| 421 delayed_decision = 1; | 420 delayed_decision = 1; |
| 422 args++; | 421 args++; |
| 423 } else if( strcmp( argv[ args ], "-dtx") == 0 ) { | 422 } else if( strcmp( argv[ args ], "-dtx") == 0 ) { |
| 424 check_encoder_option(decode_only, "-dtx"); | 423 check_encoder_option(decode_only, "-dtx"); |
| 425 use_dtx = 1; | 424 use_dtx = 1; |
| 426 args++; | 425 args++; |
| 427 } else if( strcmp( argv[ args ], "-loss" ) == 0 ) { | 426 } else if( strcmp( argv[ args ], "-loss" ) == 0 ) { |
| 428 check_decoder_option(encode_only, "-loss"); | |
| 429 packet_loss_perc = atoi( argv[ args + 1 ] ); | 427 packet_loss_perc = atoi( argv[ args + 1 ] ); |
| 430 args += 2; | 428 args += 2; |
| 431 } else if( strcmp( argv[ args ], "-sweep" ) == 0 ) { | 429 } else if( strcmp( argv[ args ], "-sweep" ) == 0 ) { |
| 432 check_encoder_option(decode_only, "-sweep"); | 430 check_encoder_option(decode_only, "-sweep"); |
| 433 sweep_bps = atoi( argv[ args + 1 ] ); | 431 sweep_bps = atoi( argv[ args + 1 ] ); |
| 434 args += 2; | 432 args += 2; |
| 435 } else if( strcmp( argv[ args ], "-random_framesize" ) == 0 ) { | 433 } else if( strcmp( argv[ args ], "-random_framesize" ) == 0 ) { |
| 436 check_encoder_option(decode_only, "-random_framesize"); | 434 check_encoder_option(decode_only, "-random_framesize"); |
| 437 random_framesize = 1; | 435 random_framesize = 1; |
| 438 args++; | 436 args++; |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 730 return EXIT_FAILURE; | 728 return EXIT_FAILURE; |
| 731 } | 729 } |
| 732 curr_mode_count += frame_size; | 730 curr_mode_count += frame_size; |
| 733 if (curr_mode_count > mode_switch_time && curr_mode < nb_modes_in_li
st-1) | 731 if (curr_mode_count > mode_switch_time && curr_mode < nb_modes_in_li
st-1) |
| 734 { | 732 { |
| 735 curr_mode++; | 733 curr_mode++; |
| 736 curr_mode_count = 0; | 734 curr_mode_count = 0; |
| 737 } | 735 } |
| 738 } | 736 } |
| 739 | 737 |
| 738 #if 0 /* This is for testing the padding code, do not enable by default */ |
| 739 if (len[toggle]<1275) |
| 740 { |
| 741 int new_len = len[toggle]+rand()%(max_payload_bytes-len[toggle]); |
| 742 if ((err = opus_packet_pad(data[toggle], len[toggle], new_len)) != OP
US_OK) |
| 743 { |
| 744 fprintf(stderr, "padding failed: %s\n", opus_strerror(err)); |
| 745 return EXIT_FAILURE; |
| 746 } |
| 747 len[toggle] = new_len; |
| 748 } |
| 749 #endif |
| 740 if (encode_only) | 750 if (encode_only) |
| 741 { | 751 { |
| 742 unsigned char int_field[4]; | 752 unsigned char int_field[4]; |
| 743 int_to_char(len[toggle], int_field); | 753 int_to_char(len[toggle], int_field); |
| 744 if (fwrite(int_field, 1, 4, fout) != 4) { | 754 if (fwrite(int_field, 1, 4, fout) != 4) { |
| 745 fprintf(stderr, "Error writing.\n"); | 755 fprintf(stderr, "Error writing.\n"); |
| 746 return EXIT_FAILURE; | 756 return EXIT_FAILURE; |
| 747 } | 757 } |
| 748 int_to_char(enc_final_range[toggle], int_field); | 758 int_to_char(enc_final_range[toggle], int_field); |
| 749 if (fwrite(int_field, 1, 4, fout) != 4) { | 759 if (fwrite(int_field, 1, 4, fout) != 4) { |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 866 free(data[0]); | 876 free(data[0]); |
| 867 if (use_inbandfec) | 877 if (use_inbandfec) |
| 868 free(data[1]); | 878 free(data[1]); |
| 869 fclose(fin); | 879 fclose(fin); |
| 870 fclose(fout); | 880 fclose(fout); |
| 871 free(in); | 881 free(in); |
| 872 free(out); | 882 free(out); |
| 873 free(fbytes); | 883 free(fbytes); |
| 874 return EXIT_SUCCESS; | 884 return EXIT_SUCCESS; |
| 875 } | 885 } |
| OLD | NEW |