From 79e29e510f4e244beca5bf6e5ff4350d585b0b42 Mon Sep 17 00:00:00 2001 From: "tina.legrand@webrtc.org" Date: Fri, 17 Feb 2012 00:38:33 +0000 Subject: [PATCH] Adding option to change bitrate for Celt. I have updated the code so that Celt rate can be changed to any value between 48 and 128 kbps. Tests for both mono and stereo are updated.Updated tests for Celt mono. Review URL: https://webrtc-codereview.appspot.com/391014 git-svn-id: http://webrtc.googlecode.com/svn/trunk@1712 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../audio_coding/main/source/acm_celt.cc | 6 +++--- src/modules/audio_coding/main/source/acm_celt.h | 2 +- .../main/source/acm_codec_database.cc | 17 +++++++++++++++-- .../main/source/acm_codec_database.h | 1 + .../audio_coding/main/test/TestAllCodecs.cc | 6 ++++-- .../audio_coding/main/test/TestStereo.cc | 8 ++++++-- 6 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/modules/audio_coding/main/source/acm_celt.cc b/src/modules/audio_coding/main/source/acm_celt.cc index 1e467fe89..31af88d15 100644 --- a/src/modules/audio_coding/main/source/acm_celt.cc +++ b/src/modules/audio_coding/main/source/acm_celt.cc @@ -109,7 +109,7 @@ ACMCELT::ACMCELT(int16_t codecID) : enc_inst_ptr_(NULL), dec_inst_ptr_(NULL), sampling_freq_(32000), // Default sampling frequency. - bitrate_(48000), // Default rate. + bitrate_(64000), // Default rate. channels_(1), // Default send mono. dec_channels_(1) { // Default receive mono. // TODO(tlegrand): remove later when ACMGenericCodec has a new constructor. @@ -162,7 +162,7 @@ int16_t ACMCELT::DecodeSafe(uint8_t* /* bitStream */, } int16_t ACMCELT::InternalInitEncoder(WebRtcACMCodecParams* codecParams) { - // Set bitrate and check that it is withing the valid range. + // Set bitrate and check that it is within the valid range. int16_t status = SetBitRateSafe((codecParams->codecInstant).rate); if (status < 0) { return -1; @@ -302,7 +302,7 @@ bool ACMCELT::IsTrueStereoCodec() { int16_t ACMCELT::SetBitRateSafe(const int32_t rate) { // Check that rate is in the valid range. - if ((rate >= 48000) && (rate <= 96000)) { + if ((rate >= 48000) && (rate <= 128000)) { bitrate_ = rate; return 0; } else { diff --git a/src/modules/audio_coding/main/source/acm_celt.h b/src/modules/audio_coding/main/source/acm_celt.h index 2797a9e43..3f2e41d6b 100644 --- a/src/modules/audio_coding/main/source/acm_celt.h +++ b/src/modules/audio_coding/main/source/acm_celt.h @@ -62,7 +62,7 @@ class ACMCELT : public ACMGenericCodec { CELT_encinst_t_* enc_inst_ptr_; CELT_decinst_t_* dec_inst_ptr_; uint16_t sampling_freq_; - uint16_t bitrate_; + int32_t bitrate_; uint16_t channels_; uint16_t dec_channels_; }; diff --git a/src/modules/audio_coding/main/source/acm_codec_database.cc b/src/modules/audio_coding/main/source/acm_codec_database.cc index d75414df9..8ed25a510 100644 --- a/src/modules/audio_coding/main/source/acm_codec_database.cc +++ b/src/modules/audio_coding/main/source/acm_codec_database.cc @@ -117,7 +117,7 @@ const int kDynamicPayloadtypes[ACMCodecDB::kMaxNumCodecs] = { defined(WEBRTC_CODEC_AMR) || defined(WEBRTC_CODEC_AMRWB) || \ defined(WEBRTC_CODEC_CELT) || defined(WEBRTC_CODEC_G729_1) || \ defined(WEBRTC_CODEC_SPEEX) || defined(WEBRTC_CODEC_G722_1) || \ - defined(WEBRTC_CODEC_G722_1C)) + defined(WEBRTC_CODEC_G722_1C) || defined(WEBRTC_CODEC_CELT)) static int count_database = 0; #endif @@ -146,7 +146,7 @@ const CodecInst ACMCodecDB::database_[] = { {kDynamicPayloadtypes[count_database++], "AMR-WB", 16000, 320, 1, 20000}, #endif #ifdef WEBRTC_CODEC_CELT - {kDynamicPayloadtypes[count_database++], "CELT", 32000, 320, 1, 48000}, + {kDynamicPayloadtypes[count_database++], "CELT", 32000, 320, 1, 64000}, #endif #ifdef WEBRTC_CODEC_G722 {9, "G722", 16000, 320, 1, 64000}, @@ -492,6 +492,9 @@ int ACMCodecDB::CodecNumber(const CodecInst* codec_inst, int* mirror_id) { } else if (STR_CASE_CMP("speex", codec_inst->plname) == 0) { return IsSpeexRateValid(codec_inst->rate) ? codec_number : kInvalidRate; + } else if (STR_CASE_CMP("celt", codec_inst->plname) == 0) { + return IsCeltRateValid(codec_inst->rate) + ? codec_number : kInvalidRate; } return IsRateValid(codec_number, codec_inst->rate) ? @@ -965,6 +968,7 @@ bool ACMCodecDB::IsG7291RateValid(int rate) { } } } + // Checks if the bitrate is valid for Speex. bool ACMCodecDB::IsSpeexRateValid(int rate) { if (rate > 2000) { @@ -974,6 +978,15 @@ bool ACMCodecDB::IsSpeexRateValid(int rate) { } } +// Checks if the bitrate is valid for Celt. +bool ACMCodecDB::IsCeltRateValid(int rate) { + if ((rate >= 48000) && (rate <= 128000)) { + return true; + } else { + return false; + } +} + // Checks if the payload type is in the valid range. bool ACMCodecDB::ValidPayloadType(int payload_type) { if ((payload_type < 0) || (payload_type > 127)) { diff --git a/src/modules/audio_coding/main/source/acm_codec_database.h b/src/modules/audio_coding/main/source/acm_codec_database.h index 1752bbc40..6830e6590 100644 --- a/src/modules/audio_coding/main/source/acm_codec_database.h +++ b/src/modules/audio_coding/main/source/acm_codec_database.h @@ -282,6 +282,7 @@ class ACMCodecDB { static bool IsAMRwbRateValid(int rate); static bool IsG7291RateValid(int rate); static bool IsSpeexRateValid(int rate); + static bool IsCeltRateValid(int rate); // Check if the payload type is valid, meaning that it is in the valid range // of 0 to 127. diff --git a/src/modules/audio_coding/main/test/TestAllCodecs.cc b/src/modules/audio_coding/main/test/TestAllCodecs.cc index c64e269e3..9d7f1e32f 100644 --- a/src/modules/audio_coding/main/test/TestAllCodecs.cc +++ b/src/modules/audio_coding/main/test/TestAllCodecs.cc @@ -660,6 +660,10 @@ void TestAllCodecs::Perform() char codecCELT_32[] = "CELT"; RegisterSendCodec('A', codecCELT_32, 32000, 48000, 320, 0); Run(_channelA2B); + RegisterSendCodec('A', codecCELT_32, 32000, 64000, 320, 0); + Run(_channelA2B); + RegisterSendCodec('A', codecCELT_32, 32000, 128000, 320, 0); + Run(_channelA2B); _outFileB.Close(); #endif if(_testMode != 0) { @@ -669,8 +673,6 @@ void TestAllCodecs::Perform() } /* Print out all codecs that were not tested in the run */ - - if(_testMode != 0) { printf("The following codecs was not included in the test:\n"); #ifndef WEBRTC_CODEC_GSMAMR diff --git a/src/modules/audio_coding/main/test/TestStereo.cc b/src/modules/audio_coding/main/test/TestStereo.cc index 0b267ff39..2105d36fe 100644 --- a/src/modules/audio_coding/main/test/TestStereo.cc +++ b/src/modules/audio_coding/main/test/TestStereo.cc @@ -434,6 +434,10 @@ void TestStereo::Perform() char codecCELT[] = "CELT"; RegisterSendCodec('A', codecCELT, 32000, 48000, 320, codec_channels); Run(_channelA2B, audio_channels, codec_channels); + RegisterSendCodec('A', codecCELT, 32000, 64000, 320, codec_channels); + Run(_channelA2B, audio_channels, codec_channels); + RegisterSendCodec('A', codecCELT, 32000, 128000, 320, codec_channels); + Run(_channelA2B, audio_channels, codec_channels); _acmA->SetVAD(true, true, VADNormal); RegisterSendCodec('A', codecCELT, 32000, 48000, 320, codec_channels); Run(_channelA2B, audio_channels, codec_channels); @@ -516,7 +520,7 @@ void TestStereo::Perform() _testCntr++; _channelA2B->SetCodecType(4); OpenOutFile(_testCntr); - RegisterSendCodec('A', codecCELT, 32000, 48000, 320, codec_channels); + RegisterSendCodec('A', codecCELT, 32000, 64000, 320, codec_channels); Run(_channelA2B, audio_channels, codec_channels); _outFileB.Close(); #endif @@ -607,7 +611,7 @@ void TestStereo::Perform() } _testCntr++; OpenOutFile(_testCntr); - RegisterSendCodec('A', codecCELT, 32000, 48000, 320, codec_channels); + RegisterSendCodec('A', codecCELT, 32000, 64000, 320, codec_channels); Run(_channelA2B, audio_channels, codec_channels); _outFileB.Close(); #endif