Chromium Code Reviews| Index: webrtc/modules/audio_coding/codecs/cng/cng_unittest.cc |
| diff --git a/webrtc/modules/audio_coding/codecs/cng/cng_unittest.cc b/webrtc/modules/audio_coding/codecs/cng/cng_unittest.cc |
| index 1061dca69aca4d37326601ebb9571ef0d5511f97..b5fd56e06ad4ad866127b35ac2b7871e81ce8b2b 100644 |
| --- a/webrtc/modules/audio_coding/codecs/cng/cng_unittest.cc |
| +++ b/webrtc/modules/audio_coding/codecs/cng/cng_unittest.cc |
| @@ -7,11 +7,12 @@ |
| * in the file PATENTS. All contributing project authors may |
| * be found in the AUTHORS file in the root of the source tree. |
| */ |
| +#include <memory> |
| #include <string> |
| #include "testing/gtest/include/gtest/gtest.h" |
| #include "webrtc/test/testsupport/fileutils.h" |
| -#include "webrtc_cng.h" |
| +#include "webrtc/modules/audio_coding/codecs/cng/webrtc_cng.h" |
| namespace webrtc { |
| @@ -35,19 +36,13 @@ enum { |
| class CngTest : public ::testing::Test { |
| protected: |
| - CngTest(); |
| virtual void SetUp(); |
| - CNG_enc_inst* cng_enc_inst_; |
| - CNG_dec_inst* cng_dec_inst_; |
| + std::unique_ptr<ComfortNoiseEncoder> cng_encoder_; |
|
hlundin-webrtc
2016/04/13 07:05:23
Does it make sense to keep the encoder and decoder
ossu
2016/04/13 11:57:06
Yeah, it's probably neater to put them into the te
kwiberg-webrtc
2016/04/14 09:42:47
Good. Test fixtures are a good idea much more seld
|
| + std::unique_ptr<ComfortNoiseDecoder> cng_decoder_; |
| int16_t speech_data_[640]; // Max size of CNG internal buffers. |
| }; |
| -CngTest::CngTest() |
| - : cng_enc_inst_(NULL), |
| - cng_dec_inst_(NULL) { |
| -} |
| - |
| void CngTest::SetUp() { |
| FILE* input_file; |
| const std::string file_name = |
| @@ -60,289 +55,162 @@ void CngTest::SetUp() { |
| input_file = NULL; |
| } |
| -// Test failing Create. |
| -TEST_F(CngTest, CngCreateFail) { |
| - // Test to see that an invalid pointer is caught. |
| - EXPECT_EQ(-1, WebRtcCng_CreateEnc(NULL)); |
| - EXPECT_EQ(-1, WebRtcCng_CreateDec(NULL)); |
| -} |
| - |
| -// Test normal Create. |
| -TEST_F(CngTest, CngCreate) { |
| - EXPECT_EQ(0, WebRtcCng_CreateEnc(&cng_enc_inst_)); |
| - EXPECT_EQ(0, WebRtcCng_CreateDec(&cng_dec_inst_)); |
| - EXPECT_TRUE(cng_enc_inst_ != NULL); |
| - EXPECT_TRUE(cng_dec_inst_ != NULL); |
| - // Free encoder and decoder memory. |
| - EXPECT_EQ(0, WebRtcCng_FreeEnc(cng_enc_inst_)); |
| - EXPECT_EQ(0, WebRtcCng_FreeDec(cng_dec_inst_)); |
| -} |
| - |
| -// Create CNG encoder, init with faulty values, free CNG encoder. |
| -TEST_F(CngTest, CngInitFail) { |
| - // Create encoder memory. |
| - EXPECT_EQ(0, WebRtcCng_CreateEnc(&cng_enc_inst_)); |
| - |
| - // Call with too few parameters. |
| - EXPECT_EQ(-1, WebRtcCng_InitEnc(cng_enc_inst_, 8000, kSidNormalIntervalUpdate, |
| - kCNGNumParamsLow)); |
| - EXPECT_EQ(6130, WebRtcCng_GetErrorCodeEnc(cng_enc_inst_)); |
| - |
| - // Call with too many parameters. |
| - EXPECT_EQ(-1, WebRtcCng_InitEnc(cng_enc_inst_, 8000, kSidNormalIntervalUpdate, |
| - kCNGNumParamsTooHigh)); |
| - EXPECT_EQ(6130, WebRtcCng_GetErrorCodeEnc(cng_enc_inst_)); |
| - |
| - // Free encoder memory. |
| - EXPECT_EQ(0, WebRtcCng_FreeEnc(cng_enc_inst_)); |
| -} |
| - |
| TEST_F(CngTest, CngEncode) { |
| uint8_t sid_data[WEBRTC_CNG_MAX_LPC_ORDER + 1]; |
| - size_t number_bytes; |
| - |
| - // Create encoder memory. |
| - EXPECT_EQ(0, WebRtcCng_CreateEnc(&cng_enc_inst_)); |
| // 8 kHz, Normal number of parameters |
| - EXPECT_EQ(0, WebRtcCng_InitEnc(cng_enc_inst_, 8000, kSidNormalIntervalUpdate, |
| - kCNGNumParamsNormal)); |
| - EXPECT_EQ(0, WebRtcCng_Encode(cng_enc_inst_, speech_data_, 80, sid_data, |
| - &number_bytes, kNoSid)); |
| - EXPECT_EQ(kCNGNumParamsNormal + 1, WebRtcCng_Encode( |
| - cng_enc_inst_, speech_data_, 80, sid_data, &number_bytes, kForceSid)); |
| + cng_encoder_.reset(new ComfortNoiseEncoder(8000, kSidNormalIntervalUpdate, |
| + kCNGNumParamsNormal)); |
| + EXPECT_EQ(0, cng_encoder_->Encode( |
| + rtc::ArrayView<const int16_t>(speech_data_, 80), sid_data, kNoSid)); |
| + EXPECT_EQ(kCNGNumParamsNormal + 1, cng_encoder_->Encode( |
| + rtc::ArrayView<const int16_t>(speech_data_, 80), sid_data, kForceSid)); |
| // 16 kHz, Normal number of parameters |
| - EXPECT_EQ(0, WebRtcCng_InitEnc(cng_enc_inst_, 16000, kSidNormalIntervalUpdate, |
| - kCNGNumParamsNormal)); |
| - EXPECT_EQ(0, WebRtcCng_Encode(cng_enc_inst_, speech_data_, 160, sid_data, |
| - &number_bytes, kNoSid)); |
| - EXPECT_EQ(kCNGNumParamsNormal + 1, WebRtcCng_Encode( |
| - cng_enc_inst_, speech_data_, 160, sid_data, &number_bytes, kForceSid)); |
| + cng_encoder_.reset(new ComfortNoiseEncoder(16000, kSidNormalIntervalUpdate, |
| + kCNGNumParamsNormal)); |
| + EXPECT_EQ(0, cng_encoder_->Encode( |
| + rtc::ArrayView<const int16_t>(speech_data_, 160), sid_data, kNoSid)); |
| + EXPECT_EQ(kCNGNumParamsNormal + 1, cng_encoder_->Encode( |
| + rtc::ArrayView<const int16_t>(speech_data_, 160), sid_data, kForceSid)); |
| // 32 kHz, Max number of parameters |
| - EXPECT_EQ(0, WebRtcCng_InitEnc(cng_enc_inst_, 32000, kSidNormalIntervalUpdate, |
| - kCNGNumParamsHigh)); |
| - EXPECT_EQ(0, WebRtcCng_Encode(cng_enc_inst_, speech_data_, 320, sid_data, |
| - &number_bytes, kNoSid)); |
| - EXPECT_EQ(kCNGNumParamsHigh + 1, WebRtcCng_Encode( |
| - cng_enc_inst_, speech_data_, 320, sid_data, &number_bytes, kForceSid)); |
| + cng_encoder_.reset(new ComfortNoiseEncoder(32000, kSidNormalIntervalUpdate, |
| + kCNGNumParamsHigh)); |
| + EXPECT_EQ(0, cng_encoder_->Encode( |
| + rtc::ArrayView<const int16_t>(speech_data_, 320), sid_data, kNoSid)); |
| + EXPECT_EQ(kCNGNumParamsHigh + 1, cng_encoder_->Encode( |
| + rtc::ArrayView<const int16_t>(speech_data_, 320), sid_data, kForceSid)); |
| // 48 kHz, Normal number of parameters |
| - EXPECT_EQ(0, WebRtcCng_InitEnc(cng_enc_inst_, 48000, kSidNormalIntervalUpdate, |
| - kCNGNumParamsNormal)); |
| - EXPECT_EQ(0, WebRtcCng_Encode(cng_enc_inst_, speech_data_, 480, sid_data, |
| - &number_bytes, kNoSid)); |
| - EXPECT_EQ(kCNGNumParamsNormal + 1, WebRtcCng_Encode( |
| - cng_enc_inst_, speech_data_, 480, sid_data, &number_bytes, kForceSid)); |
| + cng_encoder_.reset(new ComfortNoiseEncoder(48000, kSidNormalIntervalUpdate, |
| + kCNGNumParamsNormal)); |
| + EXPECT_EQ(0, cng_encoder_->Encode( |
| + rtc::ArrayView<const int16_t>(speech_data_, 480), sid_data, kNoSid)); |
| + EXPECT_EQ(kCNGNumParamsNormal + 1, cng_encoder_->Encode( |
| + rtc::ArrayView<const int16_t>(speech_data_, 480), sid_data, kForceSid)); |
| // 64 kHz, Normal number of parameters |
| - EXPECT_EQ(0, WebRtcCng_InitEnc(cng_enc_inst_, 64000, kSidNormalIntervalUpdate, |
| - kCNGNumParamsNormal)); |
| - EXPECT_EQ(0, WebRtcCng_Encode(cng_enc_inst_, speech_data_, 640, sid_data, |
| - &number_bytes, kNoSid)); |
| - EXPECT_EQ(kCNGNumParamsNormal + 1, WebRtcCng_Encode( |
| - cng_enc_inst_, speech_data_, 640, sid_data, &number_bytes, kForceSid)); |
| - |
| - // Free encoder memory. |
| - EXPECT_EQ(0, WebRtcCng_FreeEnc(cng_enc_inst_)); |
| + cng_encoder_.reset(new ComfortNoiseEncoder(64000, kSidNormalIntervalUpdate, |
| + kCNGNumParamsNormal)); |
| + EXPECT_EQ(0, cng_encoder_->Encode( |
| + rtc::ArrayView<const int16_t>(speech_data_, 640), sid_data, kNoSid)); |
| + EXPECT_EQ(kCNGNumParamsNormal + 1, cng_encoder_->Encode( |
| + rtc::ArrayView<const int16_t>(speech_data_, 640), sid_data, kForceSid)); |
| } |
| // Encode Cng with too long input vector. |
| TEST_F(CngTest, CngEncodeTooLong) { |
| uint8_t sid_data[WEBRTC_CNG_MAX_LPC_ORDER + 1]; |
| - size_t number_bytes; |
| - // Create and init encoder memory. |
| - EXPECT_EQ(0, WebRtcCng_CreateEnc(&cng_enc_inst_)); |
| - EXPECT_EQ(0, WebRtcCng_InitEnc(cng_enc_inst_, 8000, kSidNormalIntervalUpdate, |
| - kCNGNumParamsNormal)); |
| + // Create encoder. |
| + cng_encoder_.reset(new ComfortNoiseEncoder(8000, kSidNormalIntervalUpdate, |
| + kCNGNumParamsNormal)); |
| // Run encoder with too much data. |
| - EXPECT_EQ(-1, WebRtcCng_Encode(cng_enc_inst_, speech_data_, 641, sid_data, |
| - &number_bytes, kNoSid)); |
| - EXPECT_EQ(6140, WebRtcCng_GetErrorCodeEnc(cng_enc_inst_)); |
| - |
| - // Free encoder memory. |
| - EXPECT_EQ(0, WebRtcCng_FreeEnc(cng_enc_inst_)); |
| -} |
| - |
| -// Call encode without calling init. |
| -TEST_F(CngTest, CngEncodeNoInit) { |
| - uint8_t sid_data[WEBRTC_CNG_MAX_LPC_ORDER + 1]; |
| - size_t number_bytes; |
| - |
| - // Create encoder memory. |
| - EXPECT_EQ(0, WebRtcCng_CreateEnc(&cng_enc_inst_)); |
| - |
| - // Run encoder without calling init. |
| - EXPECT_EQ(-1, WebRtcCng_Encode(cng_enc_inst_, speech_data_, 640, sid_data, |
| - &number_bytes, kNoSid)); |
| - EXPECT_EQ(6120, WebRtcCng_GetErrorCodeEnc(cng_enc_inst_)); |
| - |
| - // Free encoder memory. |
| - EXPECT_EQ(0, WebRtcCng_FreeEnc(cng_enc_inst_)); |
| + EXPECT_EQ(-1, cng_encoder_->Encode( |
| + rtc::ArrayView<const int16_t>(speech_data_, 641), |
| + sid_data, kNoSid)); |
| } |
| // Update SID parameters, for both 9 and 16 parameters. |
| TEST_F(CngTest, CngUpdateSid) { |
| uint8_t sid_data[WEBRTC_CNG_MAX_LPC_ORDER + 1]; |
| - size_t number_bytes; |
| - // Create and initialize encoder and decoder memory. |
| - EXPECT_EQ(0, WebRtcCng_CreateEnc(&cng_enc_inst_)); |
| - EXPECT_EQ(0, WebRtcCng_CreateDec(&cng_dec_inst_)); |
| - EXPECT_EQ(0, WebRtcCng_InitEnc(cng_enc_inst_, 16000, kSidNormalIntervalUpdate, |
| - kCNGNumParamsNormal)); |
| - WebRtcCng_InitDec(cng_dec_inst_); |
| + // Create and initialize encoder and decoder. |
| + cng_encoder_.reset(new ComfortNoiseEncoder(16000, kSidNormalIntervalUpdate, |
| + kCNGNumParamsNormal)); |
| + cng_decoder_.reset(new ComfortNoiseDecoder); |
| + cng_decoder_->Reset(); |
| // Run normal Encode and UpdateSid. |
| - EXPECT_EQ(kCNGNumParamsNormal + 1, WebRtcCng_Encode( |
| - cng_enc_inst_, speech_data_, 160, sid_data, &number_bytes, kForceSid)); |
| - EXPECT_EQ(0, WebRtcCng_UpdateSid(cng_dec_inst_, sid_data, |
| - kCNGNumParamsNormal + 1)); |
| + EXPECT_EQ(kCNGNumParamsNormal + 1, cng_encoder_->Encode( |
| + rtc::ArrayView<const int16_t>(speech_data_, 160), sid_data, kForceSid)); |
| + cng_decoder_->UpdateSid( |
| + rtc::ArrayView<const uint8_t>(sid_data, kCNGNumParamsNormal + 1)); |
| // Reinit with new length. |
| - EXPECT_EQ(0, WebRtcCng_InitEnc(cng_enc_inst_, 16000, kSidNormalIntervalUpdate, |
| - kCNGNumParamsHigh)); |
| - WebRtcCng_InitDec(cng_dec_inst_); |
| + cng_encoder_->Reset(16000, kSidNormalIntervalUpdate, kCNGNumParamsHigh); |
| + cng_decoder_->Reset(); |
| // Expect 0 because of unstable parameters after switching length. |
| - EXPECT_EQ(0, WebRtcCng_Encode(cng_enc_inst_, speech_data_, 160, sid_data, |
| - &number_bytes, kForceSid)); |
| - EXPECT_EQ(kCNGNumParamsHigh + 1, WebRtcCng_Encode( |
| - cng_enc_inst_, speech_data_ + 160, 160, sid_data, &number_bytes, |
| + EXPECT_EQ(0, cng_encoder_->Encode( |
| + rtc::ArrayView<const int16_t>(speech_data_, 160), |
| + sid_data, kForceSid)); |
| + EXPECT_EQ(kCNGNumParamsHigh + 1, cng_encoder_->Encode( |
| + rtc::ArrayView<const int16_t>(speech_data_ + 160, 160), sid_data, |
| kForceSid)); |
| - EXPECT_EQ(0, WebRtcCng_UpdateSid(cng_dec_inst_, sid_data, |
| - kCNGNumParamsNormal + 1)); |
| - |
| - // Free encoder and decoder memory. |
| - EXPECT_EQ(0, WebRtcCng_FreeEnc(cng_enc_inst_)); |
| - EXPECT_EQ(0, WebRtcCng_FreeDec(cng_dec_inst_)); |
| -} |
| - |
| -// Update SID parameters, with wrong parameters or without calling decode. |
| -TEST_F(CngTest, CngUpdateSidErroneous) { |
| - uint8_t sid_data[WEBRTC_CNG_MAX_LPC_ORDER + 1]; |
| - size_t number_bytes; |
| - |
| - // Create encoder and decoder memory. |
| - EXPECT_EQ(0, WebRtcCng_CreateEnc(&cng_enc_inst_)); |
| - EXPECT_EQ(0, WebRtcCng_CreateDec(&cng_dec_inst_)); |
| - |
| - // Encode. |
| - EXPECT_EQ(0, WebRtcCng_InitEnc(cng_enc_inst_, 16000, kSidNormalIntervalUpdate, |
| - kCNGNumParamsNormal)); |
| - EXPECT_EQ(kCNGNumParamsNormal + 1, WebRtcCng_Encode( |
| - cng_enc_inst_, speech_data_, 160, sid_data, &number_bytes, kForceSid)); |
| - |
| - // Update Sid before initializing decoder. |
| - EXPECT_EQ(-1, WebRtcCng_UpdateSid(cng_dec_inst_, sid_data, |
| - kCNGNumParamsNormal + 1)); |
| - EXPECT_EQ(6220, WebRtcCng_GetErrorCodeDec(cng_dec_inst_)); |
| - |
| - // Initialize decoder. |
| - WebRtcCng_InitDec(cng_dec_inst_); |
| - |
| - // First run with valid parameters, then with too many CNG parameters. |
| - // The function will operate correctly by only reading the maximum number of |
| - // parameters, skipping the extra. |
| - EXPECT_EQ(0, WebRtcCng_UpdateSid(cng_dec_inst_, sid_data, |
| - kCNGNumParamsNormal + 1)); |
| - EXPECT_EQ(0, WebRtcCng_UpdateSid(cng_dec_inst_, sid_data, |
| - kCNGNumParamsTooHigh + 1)); |
| - |
| - // Free encoder and decoder memory. |
| - EXPECT_EQ(0, WebRtcCng_FreeEnc(cng_enc_inst_)); |
| - EXPECT_EQ(0, WebRtcCng_FreeDec(cng_dec_inst_)); |
| + cng_decoder_->UpdateSid( |
| + rtc::ArrayView<const uint8_t>(sid_data, kCNGNumParamsNormal + 1)); |
| } |
| // Test to generate cng data, by forcing SID. Both normal and faulty condition. |
| TEST_F(CngTest, CngGenerate) { |
| uint8_t sid_data[WEBRTC_CNG_MAX_LPC_ORDER + 1]; |
| int16_t out_data[640]; |
| - size_t number_bytes; |
| - // Create and initialize encoder and decoder memory. |
| - EXPECT_EQ(0, WebRtcCng_CreateEnc(&cng_enc_inst_)); |
| - EXPECT_EQ(0, WebRtcCng_CreateDec(&cng_dec_inst_)); |
| - EXPECT_EQ(0, WebRtcCng_InitEnc(cng_enc_inst_, 16000, kSidNormalIntervalUpdate, |
| - kCNGNumParamsNormal)); |
| - WebRtcCng_InitDec(cng_dec_inst_); |
| + // Create and initialize encoder and decoder. |
| + cng_encoder_.reset(new ComfortNoiseEncoder(16000, kSidNormalIntervalUpdate, |
| + kCNGNumParamsNormal)); |
| + cng_decoder_.reset(new ComfortNoiseDecoder); |
| // Normal Encode. |
| - EXPECT_EQ(kCNGNumParamsNormal + 1, WebRtcCng_Encode( |
| - cng_enc_inst_, speech_data_, 160, sid_data, &number_bytes, kForceSid)); |
| + EXPECT_EQ(kCNGNumParamsNormal + 1, cng_encoder_->Encode( |
| + rtc::ArrayView<const int16_t>(speech_data_, 160), sid_data, kForceSid)); |
| // Normal UpdateSid. |
| - EXPECT_EQ(0, WebRtcCng_UpdateSid(cng_dec_inst_, sid_data, |
| - kCNGNumParamsNormal + 1)); |
| + cng_decoder_->UpdateSid( |
| + rtc::ArrayView<const uint8_t>(sid_data, kCNGNumParamsNormal + 1)); |
| // Two normal Generate, one with new_period. |
| - EXPECT_EQ(0, WebRtcCng_Generate(cng_dec_inst_, out_data, 640, 1)); |
| - EXPECT_EQ(0, WebRtcCng_Generate(cng_dec_inst_, out_data, 640, 0)); |
| + EXPECT_TRUE(cng_decoder_->Generate( |
| + rtc::ArrayView<int16_t>(out_data, 640), 1)); |
| + EXPECT_TRUE(cng_decoder_->Generate( |
| + rtc::ArrayView<int16_t>(out_data, 640), 0)); |
| // Call Genereate with too much data. |
| - EXPECT_EQ(-1, WebRtcCng_Generate(cng_dec_inst_, out_data, 641, 0)); |
| - EXPECT_EQ(6140, WebRtcCng_GetErrorCodeDec(cng_dec_inst_)); |
| - |
| - // Free encoder and decoder memory. |
| - EXPECT_EQ(0, WebRtcCng_FreeEnc(cng_enc_inst_)); |
| - EXPECT_EQ(0, WebRtcCng_FreeDec(cng_dec_inst_)); |
| + EXPECT_FALSE(cng_decoder_->Generate( |
| + rtc::ArrayView<int16_t>(out_data, 641), 0)); |
| } |
| // Test automatic SID. |
| TEST_F(CngTest, CngAutoSid) { |
| uint8_t sid_data[WEBRTC_CNG_MAX_LPC_ORDER + 1]; |
| - size_t number_bytes; |
| - // Create and initialize encoder and decoder memory. |
| - EXPECT_EQ(0, WebRtcCng_CreateEnc(&cng_enc_inst_)); |
| - EXPECT_EQ(0, WebRtcCng_CreateDec(&cng_dec_inst_)); |
| - EXPECT_EQ(0, WebRtcCng_InitEnc(cng_enc_inst_, 16000, kSidNormalIntervalUpdate, |
| - kCNGNumParamsNormal)); |
| - WebRtcCng_InitDec(cng_dec_inst_); |
| + // Create and initialize encoder and decoder. |
| + cng_encoder_.reset(new ComfortNoiseEncoder(16000, kSidNormalIntervalUpdate, |
| + kCNGNumParamsNormal)); |
| + cng_decoder_.reset(new ComfortNoiseDecoder); |
| // Normal Encode, 100 msec, where no SID data should be generated. |
| for (int i = 0; i < 10; i++) { |
| - EXPECT_EQ(0, WebRtcCng_Encode(cng_enc_inst_, speech_data_, 160, sid_data, |
| - &number_bytes, kNoSid)); |
| + EXPECT_EQ(0, cng_encoder_->Encode( |
| + rtc::ArrayView<const int16_t>(speech_data_, 160), sid_data, kNoSid)); |
| } |
| // We have reached 100 msec, and SID data should be generated. |
| - EXPECT_EQ(kCNGNumParamsNormal + 1, WebRtcCng_Encode( |
| - cng_enc_inst_, speech_data_, 160, sid_data, &number_bytes, kNoSid)); |
| - |
| - // Free encoder and decoder memory. |
| - EXPECT_EQ(0, WebRtcCng_FreeEnc(cng_enc_inst_)); |
| - EXPECT_EQ(0, WebRtcCng_FreeDec(cng_dec_inst_)); |
| + EXPECT_EQ(kCNGNumParamsNormal + 1, cng_encoder_->Encode( |
| + rtc::ArrayView<const int16_t>(speech_data_, 160), sid_data, kNoSid)); |
| } |
| // Test automatic SID, with very short interval. |
| TEST_F(CngTest, CngAutoSidShort) { |
| uint8_t sid_data[WEBRTC_CNG_MAX_LPC_ORDER + 1]; |
| - size_t number_bytes; |
| - // Create and initialize encoder and decoder memory. |
| - EXPECT_EQ(0, WebRtcCng_CreateEnc(&cng_enc_inst_)); |
| - EXPECT_EQ(0, WebRtcCng_CreateDec(&cng_dec_inst_)); |
| - EXPECT_EQ(0, WebRtcCng_InitEnc(cng_enc_inst_, 16000, kSidShortIntervalUpdate, |
| - kCNGNumParamsNormal)); |
| - WebRtcCng_InitDec(cng_dec_inst_); |
| + // Create and initialize encoder and decoder. |
| + cng_encoder_.reset(new ComfortNoiseEncoder(16000, kSidShortIntervalUpdate, |
| + kCNGNumParamsNormal)); |
| + cng_decoder_.reset(new ComfortNoiseDecoder); |
| // First call will never generate SID, unless forced to. |
| - EXPECT_EQ(0, WebRtcCng_Encode(cng_enc_inst_, speech_data_, 160, sid_data, |
| - &number_bytes, kNoSid)); |
| + EXPECT_EQ(0, cng_encoder_->Encode( |
| + rtc::ArrayView<const int16_t>(speech_data_, 160), sid_data, kNoSid)); |
| // Normal Encode, 100 msec, SID data should be generated all the time. |
| for (int i = 0; i < 10; i++) { |
| - EXPECT_EQ(kCNGNumParamsNormal + 1, WebRtcCng_Encode( |
| - cng_enc_inst_, speech_data_, 160, sid_data, &number_bytes, kNoSid)); |
| + EXPECT_EQ(kCNGNumParamsNormal + 1, cng_encoder_->Encode( |
| + rtc::ArrayView<const int16_t>(speech_data_, 160), sid_data, kNoSid)); |
| } |
| - |
| - // Free encoder and decoder memory. |
| - EXPECT_EQ(0, WebRtcCng_FreeEnc(cng_enc_inst_)); |
| - EXPECT_EQ(0, WebRtcCng_FreeDec(cng_dec_inst_)); |
| } |
| } // namespace webrtc |