From a4f9ba6a3f627f80408c2f43b81992d8158f41f2 Mon Sep 17 00:00:00 2001 From: "tina.legrand@webrtc.org" Date: Fri, 28 Sep 2012 07:12:00 +0000 Subject: [PATCH] Refactor and unittest for CNG. Patch Set 1: - Formatted file. - Fixed format of comments. - Removed: - WebRtcCng_Version, - WebRtcCng_AssignSizeEnc - WebRtcCng_AssignSizeDec. - Changed type of input variable |fs| in WebRtcCng_InitEnc to unsigned. - Added extra check in WebRtcCng_CreateEnc and WebRtcCng_CreateDec. - Added extra check in WebRtcCng_InitEnc for |quality|. - Removed () on return values. Patch Set 2: - Formatted cng_helpfunc.*. - Added tests for Encoder. - Added calls to WebRtcSpl_Init(); Patch Set 3: - Added tests for WebRtcCng_UpdateSid. - Added tests for WebRtcCng_Generate. Patch Set 4: - More comments. - Re-ordered some lines. - Adding calls to WebRtcCng_GetErrorCodeEnc and WebRtcCng_GetErrorCodeDec. TEST=cng_unittests Review URL: https://webrtc-codereview.appspot.com/822004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@2837 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../audio_coding/codecs/cng/cng_helpfuns.c | 80 +- .../audio_coding/codecs/cng/cng_helpfuns.h | 13 +- .../audio_coding/codecs/cng/cng_unittest.cc | 339 +++++- .../codecs/cng/include/webrtc_cng.h | 112 +- .../audio_coding/codecs/cng/webrtc_cng.c | 982 ++++++++---------- 5 files changed, 817 insertions(+), 709 deletions(-) diff --git a/src/modules/audio_coding/codecs/cng/cng_helpfuns.c b/src/modules/audio_coding/codecs/cng/cng_helpfuns.c index 2e9029f0d4..ba35850164 100644 --- a/src/modules/audio_coding/codecs/cng/cng_helpfuns.c +++ b/src/modules/audio_coding/codecs/cng/cng_helpfuns.c @@ -8,57 +8,43 @@ * be found in the AUTHORS file in the root of the source tree. */ - -#include "webrtc_cng.h" -#include "signal_processing_library.h" -#include "typedefs.h" #include "cng_helpfuns.h" +#include "signal_processing_library.h" +#include "typedefs.h" +#include "webrtc_cng.h" -#ifdef __cplusplus -extern "C" { -#endif +/* Values in |k| are Q15, and |a| Q12. */ +void WebRtcCng_K2a16(int16_t* k, int useOrder, int16_t* a) { + int16_t any[WEBRTC_SPL_MAX_LPC_ORDER + 1]; + int16_t *aptr, *aptr2, *anyptr; + const int16_t *kptr; + int m, i; + kptr = k; + *a = 4096; /* i.e., (Word16_MAX >> 3) + 1 */ + *any = *a; + a[1] = (*k + 4) >> 3; + for (m = 1; m < useOrder; m++) { + kptr++; + aptr = a; + aptr++; + aptr2 = &a[m]; + anyptr = any; + anyptr++; -void WebRtcCng_K2a16( - WebRtc_Word16 *k, /* Q15. */ - int useOrder, - WebRtc_Word16 *a /* Q12. */ -) -{ - WebRtc_Word16 any[WEBRTC_SPL_MAX_LPC_ORDER+1]; - WebRtc_Word16 *aptr, *aptr2, *anyptr; - G_CONST WebRtc_Word16 *kptr; - int m, i; - - kptr = k; - *a = 4096; /* i.e., (Word16_MAX >> 3)+1 */ - *any = *a; - a[1] = (*k+4) >> 3; - for( m=1; m> 3; - for( i=0; i> 15); - } - - aptr = a; - anyptr = any; - for( i=0; i<(m+2); i++ ){ - *aptr++ = *anyptr++; - } + any[m + 1] = (*kptr + 4) >> 3; + for (i = 0; i < m; i++) { + *anyptr++ = (*aptr++) + + (WebRtc_Word16)( + (((WebRtc_Word32)(*aptr2--) * (WebRtc_Word32) * kptr) + 16384) + >> 15); } + + aptr = a; + anyptr = any; + for (i = 0; i < (m + 2); i++) { + *aptr++ = *anyptr++; + } + } } - - -#ifdef __cplusplus -} -#endif - diff --git a/src/modules/audio_coding/codecs/cng/cng_helpfuns.h b/src/modules/audio_coding/codecs/cng/cng_helpfuns.h index fd8d6dcbce..de9e0d0a30 100644 --- a/src/modules/audio_coding/codecs/cng/cng_helpfuns.h +++ b/src/modules/audio_coding/codecs/cng/cng_helpfuns.h @@ -7,22 +7,19 @@ * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree. */ +#ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_CNG_CNG_HELPFUNS_H_ +#define WEBRTC_MODULES_AUDIO_CODING_CODECS_CNG_CNG_HELPFUNS_H_ - -#ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_CNG_MAIN_SOURCE_CNG_HELPFUNS_H_ -#define WEBRTC_MODULES_AUDIO_CODING_CODECS_CNG_MAIN_SOURCE_CNG_HELPFUNS_H_ - -extern WebRtc_Word32 lpc_lagwinTbl_fixw32[WEBRTC_CNG_MAX_LPC_ORDER + 1]; +#include "typedefs.h" #ifdef __cplusplus extern "C" { #endif - -void WebRtcCng_K2a16(WebRtc_Word16 *k, int useOrder, WebRtc_Word16 *a); +void WebRtcCng_K2a16(int16_t* k, int useOrder, int16_t* a); #ifdef __cplusplus } #endif -#endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_CNG_MAIN_SOURCE_CNG_HELPFUNS_H_ +#endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_CNG_CNG_HELPFUNS_H_ diff --git a/src/modules/audio_coding/codecs/cng/cng_unittest.cc b/src/modules/audio_coding/codecs/cng/cng_unittest.cc index 6a4edc0705..71817e48d8 100644 --- a/src/modules/audio_coding/codecs/cng/cng_unittest.cc +++ b/src/modules/audio_coding/codecs/cng/cng_unittest.cc @@ -7,11 +7,340 @@ * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree. */ +#include -/* - * Empty test just to get code coverage metrics for this dir. - */ -#include "webrtc_cng.h" #include "gtest/gtest.h" +#include "testsupport/fileutils.h" +#include "webrtc_cng.h" -TEST(CngTest, EmptyTestToGetCodeCoverage) {} +namespace webrtc { + +enum { + kSidShortIntervalUpdate = 1, + kSidNormalIntervalUpdate = 100, + kSidLongIntervalUpdate = 10000 +}; + +enum { + kCNGNumParamsLow = 0, + kCNGNumParamsNormal = 8, + kCNGNumParamsHigh = WEBRTC_CNG_MAX_LPC_ORDER, + kCNGNumParamsTooHigh = WEBRTC_CNG_MAX_LPC_ORDER + 1 +}; + +enum { + kNoSid, + kForceSid +}; + +class CngTest : public ::testing::Test { + protected: + CngTest(); + virtual void SetUp(); + + CNG_enc_inst* cng_enc_inst_; + CNG_dec_inst* cng_dec_inst_; + 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 = + webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm"); + input_file = fopen(file_name.c_str(), "rb"); + ASSERT_TRUE(input_file != NULL); + ASSERT_EQ(480, static_cast(fread(speech_data_, sizeof(int16_t), + 480, input_file))); + fclose(input_file); + 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]; + int16_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)); + + // 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)); + + // 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)); + + // 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)); + + // 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_)); +} + +// Encode Cng with too long input vector. +TEST_F(CngTest, CngEncodeTooLong) { + uint8_t sid_data[WEBRTC_CNG_MAX_LPC_ORDER + 1]; + int16_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)); + + // 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]; + int16_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_)); +} + +// Update SID parameters, for both 9 and 16 parameters. +TEST_F(CngTest, CngUpdateSid) { + uint8_t sid_data[WEBRTC_CNG_MAX_LPC_ORDER + 1]; + int16_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)); + EXPECT_EQ(0, WebRtcCng_InitDec(cng_dec_inst_)); + + // 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)); + + // Reinit with new length. + EXPECT_EQ(0, WebRtcCng_InitEnc(cng_enc_inst_, 16000, kSidNormalIntervalUpdate, + kCNGNumParamsHigh)); + EXPECT_EQ(0, WebRtcCng_InitDec(cng_dec_inst_)); + + // 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, + 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]; + int16_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. + EXPECT_EQ(0, 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_)); +} + +// 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]; + int16_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)); + EXPECT_EQ(0, WebRtcCng_InitDec(cng_dec_inst_)); + + // Normal Encode. + EXPECT_EQ(kCNGNumParamsNormal + 1, WebRtcCng_Encode( + cng_enc_inst_, speech_data_, 160, sid_data, &number_bytes, kForceSid)); + + // Normal UpdateSid. + EXPECT_EQ(0, WebRtcCng_UpdateSid(cng_dec_inst_, 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)); + + // 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_)); +} + +// Test automatic SID. +TEST_F(CngTest, CngAutoSid) { + uint8_t sid_data[WEBRTC_CNG_MAX_LPC_ORDER + 1]; + int16_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)); + EXPECT_EQ(0, WebRtcCng_InitDec(cng_dec_inst_)); + + // 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)); + } + + // 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_)); +} + +// Test automatic SID, with very short interval. +TEST_F(CngTest, CngAutoSidShort) { + uint8_t sid_data[WEBRTC_CNG_MAX_LPC_ORDER + 1]; + int16_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)); + EXPECT_EQ(0, WebRtcCng_InitDec(cng_dec_inst_)); + + // 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)); + + // 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)); + } + + // Free encoder and decoder memory. + EXPECT_EQ(0, WebRtcCng_FreeEnc(cng_enc_inst_)); +} + +} // namespace webrtc diff --git a/src/modules/audio_coding/codecs/cng/include/webrtc_cng.h b/src/modules/audio_coding/codecs/cng/include/webrtc_cng.h index d405e3a439..6030f8ebe7 100644 --- a/src/modules/audio_coding/codecs/cng/include/webrtc_cng.h +++ b/src/modules/audio_coding/codecs/cng/include/webrtc_cng.h @@ -21,71 +21,18 @@ extern "C" { #define WEBRTC_CNG_MAX_LPC_ORDER 12 #define WEBRTC_CNG_MAX_OUTSIZE_ORDER 640 -/* Define Error codes */ +/* Define Error codes. */ /* 6100 Encoder */ -#define CNG_ENCODER_MEMORY_ALLOCATION_FAILED 6110 #define CNG_ENCODER_NOT_INITIATED 6120 #define CNG_DISALLOWED_LPC_ORDER 6130 #define CNG_DISALLOWED_FRAME_SIZE 6140 #define CNG_DISALLOWED_SAMPLING_FREQUENCY 6150 /* 6200 Decoder */ -#define CNG_DECODER_MEMORY_ALLOCATION_FAILED 6210 #define CNG_DECODER_NOT_INITIATED 6220 - -typedef struct WebRtcCngEncInst CNG_enc_inst; -typedef struct WebRtcCngDecInst CNG_dec_inst; - - -/**************************************************************************** - * WebRtcCng_Version(...) - * - * These functions returns the version name (string must be at least - * 500 characters long) - * - * Output: - * - version : Pointer to character string - * - * Return value : 0 - Ok - * -1 - Error - */ - -WebRtc_Word16 WebRtcCng_Version(char *version); - -/**************************************************************************** - * WebRtcCng_AssignSizeEnc/Dec(...) - * - * These functions get the size needed for storing the instance for encoder - * and decoder, respectively - * - * Input/Output: - * - sizeinbytes : Pointer to integer where the size is returned - * - * Return value : 0 - */ - -WebRtc_Word16 WebRtcCng_AssignSizeEnc(int *sizeinbytes); -WebRtc_Word16 WebRtcCng_AssignSizeDec(int *sizeinbytes); - - -/**************************************************************************** - * WebRtcCng_AssignEnc/Dec(...) - * - * These functions Assignes memory for the instances. - * - * Input: - * - CNG_inst_Addr : Adress to where to assign memory - * Output: - * - inst : Pointer to the instance that should be created - * - * Return value : 0 - Ok - * -1 - Error - */ - -WebRtc_Word16 WebRtcCng_AssignEnc(CNG_enc_inst **inst, void *CNG_inst_Addr); -WebRtc_Word16 WebRtcCng_AssignDec(CNG_dec_inst **inst, void *CNG_inst_Addr); - +typedef struct WebRtcCngEncInst CNG_enc_inst; +typedef struct WebRtcCngDecInst CNG_dec_inst; /**************************************************************************** * WebRtcCng_CreateEnc/Dec(...) @@ -98,10 +45,8 @@ WebRtc_Word16 WebRtcCng_AssignDec(CNG_dec_inst **inst, void *CNG_inst_Addr); * Return value : 0 - Ok * -1 - Error */ - -WebRtc_Word16 WebRtcCng_CreateEnc(CNG_enc_inst **cng_inst); -WebRtc_Word16 WebRtcCng_CreateDec(CNG_dec_inst **cng_inst); - +int16_t WebRtcCng_CreateEnc(CNG_enc_inst** cng_inst); +int16_t WebRtcCng_CreateDec(CNG_dec_inst** cng_inst); /**************************************************************************** * WebRtcCng_InitEnc/Dec(...) @@ -122,13 +67,10 @@ WebRtc_Word16 WebRtcCng_CreateDec(CNG_dec_inst **cng_inst); * -1 - Error */ -WebRtc_Word16 WebRtcCng_InitEnc(CNG_enc_inst *cng_inst, - WebRtc_Word16 fs, - WebRtc_Word16 interval, - WebRtc_Word16 quality); -WebRtc_Word16 WebRtcCng_InitDec(CNG_dec_inst *cng_dec_inst); +int16_t WebRtcCng_InitEnc(CNG_enc_inst* cng_inst, uint16_t fs, int16_t interval, + int16_t quality); +int16_t WebRtcCng_InitDec(CNG_dec_inst* cng_inst); - /**************************************************************************** * WebRtcCng_FreeEnc/Dec(...) * @@ -140,12 +82,8 @@ WebRtc_Word16 WebRtcCng_InitDec(CNG_dec_inst *cng_dec_inst); * Return value : 0 - Ok * -1 - Error */ - - -WebRtc_Word16 WebRtcCng_FreeEnc(CNG_enc_inst *cng_inst); -WebRtc_Word16 WebRtcCng_FreeDec(CNG_dec_inst *cng_inst); - - +int16_t WebRtcCng_FreeEnc(CNG_enc_inst* cng_inst); +int16_t WebRtcCng_FreeDec(CNG_dec_inst* cng_inst); /**************************************************************************** * WebRtcCng_Encode(...) @@ -164,14 +102,9 @@ WebRtc_Word16 WebRtcCng_FreeDec(CNG_dec_inst *cng_inst); * Return value : 0 - Ok * -1 - Error */ - -WebRtc_Word16 WebRtcCng_Encode(CNG_enc_inst *cng_inst, - WebRtc_Word16 *speech, - WebRtc_Word16 nrOfSamples, - WebRtc_UWord8* SIDdata, - WebRtc_Word16 *bytesOut, - WebRtc_Word16 forceSID); - +int16_t WebRtcCng_Encode(CNG_enc_inst* cng_inst, int16_t* speech, + int16_t nrOfSamples, uint8_t* SIDdata, + int16_t* bytesOut, int16_t forceSID); /**************************************************************************** * WebRtcCng_UpdateSid(...) @@ -186,10 +119,8 @@ WebRtc_Word16 WebRtcCng_Encode(CNG_enc_inst *cng_inst, * Return value : 0 - Ok * -1 - Error */ -WebRtc_Word16 WebRtcCng_UpdateSid(CNG_dec_inst *cng_inst, - WebRtc_UWord8 *SID, - WebRtc_Word16 length); - +int16_t WebRtcCng_UpdateSid(CNG_dec_inst* cng_inst, uint8_t* SID, + int16_t length); /**************************************************************************** * WebRtcCng_Generate(...) @@ -205,11 +136,8 @@ WebRtc_Word16 WebRtcCng_UpdateSid(CNG_dec_inst *cng_inst, * Return value : 0 - Ok * -1 - Error */ -WebRtc_Word16 WebRtcCng_Generate(CNG_dec_inst *cng_inst, - WebRtc_Word16 * outData, - WebRtc_Word16 nrOfSamples, - WebRtc_Word16 new_period); - +int16_t WebRtcCng_Generate(CNG_dec_inst* cng_inst, int16_t* outData, + int16_t nrOfSamples, int16_t new_period); /***************************************************************************** * WebRtcCng_GetErrorCodeEnc/Dec(...) @@ -224,10 +152,8 @@ WebRtc_Word16 WebRtcCng_Generate(CNG_dec_inst *cng_inst, * * Return value : Error code */ - -WebRtc_Word16 WebRtcCng_GetErrorCodeEnc(CNG_enc_inst *cng_inst); -WebRtc_Word16 WebRtcCng_GetErrorCodeDec(CNG_dec_inst *cng_inst); - +int16_t WebRtcCng_GetErrorCodeEnc(CNG_enc_inst* cng_inst); +int16_t WebRtcCng_GetErrorCodeDec(CNG_dec_inst* cng_inst); #ifdef __cplusplus } diff --git a/src/modules/audio_coding/codecs/cng/webrtc_cng.c b/src/modules/audio_coding/codecs/cng/webrtc_cng.c index 6d95f1152d..7cc6cb9e58 100644 --- a/src/modules/audio_coding/codecs/cng/webrtc_cng.c +++ b/src/modules/audio_coding/codecs/cng/webrtc_cng.c @@ -8,162 +8,68 @@ * be found in the AUTHORS file in the root of the source tree. */ +#include "webrtc_cng.h" #include #include -#include "webrtc_cng.h" -#include "signal_processing_library.h" #include "cng_helpfuns.h" -#include "stdio.h" - +#include "signal_processing_library.h" typedef struct WebRtcCngDecInst_t_ { - - WebRtc_UWord32 dec_seed; - WebRtc_Word32 dec_target_energy; - WebRtc_Word32 dec_used_energy; - WebRtc_Word16 dec_target_reflCoefs[WEBRTC_CNG_MAX_LPC_ORDER+1]; - WebRtc_Word16 dec_used_reflCoefs[WEBRTC_CNG_MAX_LPC_ORDER+1]; - WebRtc_Word16 dec_filtstate[WEBRTC_CNG_MAX_LPC_ORDER+1]; - WebRtc_Word16 dec_filtstateLow[WEBRTC_CNG_MAX_LPC_ORDER+1]; - WebRtc_Word16 dec_Efiltstate[WEBRTC_CNG_MAX_LPC_ORDER+1]; - WebRtc_Word16 dec_EfiltstateLow[WEBRTC_CNG_MAX_LPC_ORDER+1]; - WebRtc_Word16 dec_order; - WebRtc_Word16 dec_target_scale_factor; /*Q29*/ - WebRtc_Word16 dec_used_scale_factor; /*Q29*/ - WebRtc_Word16 target_scale_factor; /* Q13 */ - WebRtc_Word16 errorcode; - WebRtc_Word16 initflag; - + uint32_t dec_seed; + int32_t dec_target_energy; + int32_t dec_used_energy; + int16_t dec_target_reflCoefs[WEBRTC_CNG_MAX_LPC_ORDER + 1]; + int16_t dec_used_reflCoefs[WEBRTC_CNG_MAX_LPC_ORDER + 1]; + int16_t dec_filtstate[WEBRTC_CNG_MAX_LPC_ORDER + 1]; + int16_t dec_filtstateLow[WEBRTC_CNG_MAX_LPC_ORDER + 1]; + int16_t dec_Efiltstate[WEBRTC_CNG_MAX_LPC_ORDER + 1]; + int16_t dec_EfiltstateLow[WEBRTC_CNG_MAX_LPC_ORDER + 1]; + int16_t dec_order; + int16_t dec_target_scale_factor; /* Q29 */ + int16_t dec_used_scale_factor; /* Q29 */ + int16_t target_scale_factor; /* Q13 */ + int16_t errorcode; + int16_t initflag; } WebRtcCngDecInst_t; - typedef struct WebRtcCngEncInst_t_ { - - WebRtc_Word16 enc_nrOfCoefs; - WebRtc_Word16 enc_sampfreq; - WebRtc_Word16 enc_interval; - WebRtc_Word16 enc_msSinceSID; - WebRtc_Word32 enc_Energy; - WebRtc_Word16 enc_reflCoefs[WEBRTC_CNG_MAX_LPC_ORDER+1]; - WebRtc_Word32 enc_corrVector[WEBRTC_CNG_MAX_LPC_ORDER+1]; - WebRtc_Word16 enc_filtstate[WEBRTC_CNG_MAX_LPC_ORDER+1]; - WebRtc_Word16 enc_filtstateLow[WEBRTC_CNG_MAX_LPC_ORDER+1]; - WebRtc_UWord32 enc_seed; - WebRtc_Word16 errorcode; - WebRtc_Word16 initflag; - + int16_t enc_nrOfCoefs; + int16_t enc_sampfreq; + int16_t enc_interval; + int16_t enc_msSinceSID; + int32_t enc_Energy; + int16_t enc_reflCoefs[WEBRTC_CNG_MAX_LPC_ORDER + 1]; + int32_t enc_corrVector[WEBRTC_CNG_MAX_LPC_ORDER + 1]; + uint32_t enc_seed; + int16_t errorcode; + int16_t initflag; } WebRtcCngEncInst_t; -const WebRtc_Word32 WebRtcCng_kDbov[94]={ - 1081109975, 858756178, 682134279, 541838517, 430397633, 341876992, - 271562548, 215709799, 171344384, 136103682, 108110997, 85875618, - 68213428, 54183852, 43039763, 34187699, 27156255, 21570980, - 17134438, 13610368, 10811100, 8587562, 6821343, 5418385, - 4303976, 3418770, 2715625, 2157098, 1713444, 1361037, - 1081110, 858756, 682134, 541839, 430398, 341877, - 271563, 215710, 171344, 136104, 108111, 85876, - 68213, 54184, 43040, 34188, 27156, 21571, - 17134, 13610, 10811, 8588, 6821, 5418, - 4304, 3419, 2716, 2157, 1713, 1361, - 1081, 859, 682, 542, 430, 342, - 272, 216, 171, 136, 108, 86, - 68, 54, 43, 34, 27, 22, - 17, 14, 11, 9, 7, 5, - 4, 3, 3, 2, 2, 1, - 1, 1, 1, 1 +const int32_t WebRtcCng_kDbov[94] = { + 1081109975, 858756178, 682134279, 541838517, 430397633, 341876992, + 271562548, 215709799, 171344384, 136103682, 108110997, 85875618, + 68213428, 54183852, 43039763, 34187699, 27156255, 21570980, + 17134438, 13610368, 10811100, 8587562, 6821343, 5418385, + 4303976, 3418770, 2715625, 2157098, 1713444, 1361037, + 1081110, 858756, 682134, 541839, 430398, 341877, + 271563, 215710, 171344, 136104, 108111, 85876, + 68213, 54184, 43040, 34188, 27156, 21571, + 17134, 13610, 10811, 8588, 6821, 5418, + 4304, 3419, 2716, 2157, 1713, 1361, + 1081, 859, 682, 542, 430, 342, + 272, 216, 171, 136, 108, 86, + 68, 54, 43, 34, 27, 22, + 17, 14, 11, 9, 7, 5, + 4, 3, 3, 2, 2, 1, + 1, 1, 1, 1 }; -const WebRtc_Word16 WebRtcCng_kCorrWindow[WEBRTC_CNG_MAX_LPC_ORDER] = { - 32702, 32636, 32570, 32505, 32439, 32374, - 32309, 32244, 32179, 32114, 32049, 31985 -}; - -/**************************************************************************** - * WebRtcCng_Version(...) - * - * These functions returns the version name (string must be at least - * 500 characters long) - * - * Output: - * - version : Pointer to character string - * - * Return value : 0 - Ok - * -1 - Error - */ - -WebRtc_Word16 WebRtcCng_Version(char *version) -{ - strcpy((char*)version,(const char*)"1.2.0\n"); - return(0); -} - - -/**************************************************************************** - * WebRtcCng_AssignSizeEnc/Dec(...) - * - * These functions get the size needed for storing the instance for encoder - * and decoder, respectively - * - * Input/Output: - * - sizeinbytes : Pointer to integer where the size is returned - * - * Return value : 0 - */ - -WebRtc_Word16 WebRtcCng_AssignSizeEnc(int *sizeinbytes) -{ - *sizeinbytes=sizeof(WebRtcCngEncInst_t)*2/sizeof(WebRtc_Word16); - return(0); -} - -WebRtc_Word16 WebRtcCng_AssignSizeDec(int *sizeinbytes) -{ - *sizeinbytes=sizeof(WebRtcCngDecInst_t)*2/sizeof(WebRtc_Word16); - return(0); -} - - -/**************************************************************************** - * WebRtcCng_AssignEnc/Dec(...) - * - * These functions Assignes memory for the instances. - * - * Input: - * - CNG_inst_Addr : Adress to where to assign memory - * Output: - * - inst : Pointer to the instance that should be created - * - * Return value : 0 - Ok - * -1 - Error - */ - -WebRtc_Word16 WebRtcCng_AssignEnc(CNG_enc_inst **inst, void *CNG_inst_Addr) -{ - if (CNG_inst_Addr!=NULL) { - *inst = (CNG_enc_inst*)CNG_inst_Addr; - (*(WebRtcCngEncInst_t**) inst)->errorcode = 0; - (*(WebRtcCngEncInst_t**) inst)->initflag = 0; - return(0); - } else { - /* The memory could not be allocated */ - return(-1); - } -} - -WebRtc_Word16 WebRtcCng_AssignDec(CNG_dec_inst **inst, void *CNG_inst_Addr) -{ - if (CNG_inst_Addr!=NULL) { - *inst = (CNG_dec_inst*)CNG_inst_Addr; - (*(WebRtcCngDecInst_t**) inst)->errorcode = 0; - (*(WebRtcCngDecInst_t**) inst)->initflag = 0; - return(0); - } else { - /* The memory could not be allocated */ - return(-1); - } -} +const int16_t WebRtcCng_kCorrWindow[WEBRTC_CNG_MAX_LPC_ORDER] = { + 32702, 32636, 32570, 32505, 32439, 32374, + 32309, 32244, 32179, 32114, 32049, 31985 +}; /**************************************************************************** * WebRtcCng_CreateEnc/Dec(...) @@ -176,35 +82,47 @@ WebRtc_Word16 WebRtcCng_AssignDec(CNG_dec_inst **inst, void *CNG_inst_Addr) * Return value : 0 - Ok * -1 - Error */ +int16_t WebRtcCng_CreateEnc(CNG_enc_inst** cng_inst) { + if (cng_inst != NULL) { + *cng_inst = (CNG_enc_inst*) malloc(sizeof(WebRtcCngEncInst_t)); + if (*cng_inst != NULL) { + (*(WebRtcCngEncInst_t**) cng_inst)->errorcode = 0; + (*(WebRtcCngEncInst_t**) cng_inst)->initflag = 0; -WebRtc_Word16 WebRtcCng_CreateEnc(CNG_enc_inst **cng_inst) -{ - *cng_inst=(CNG_enc_inst*)malloc(sizeof(WebRtcCngEncInst_t)); - if(*cng_inst!=NULL) { - (*(WebRtcCngEncInst_t**) cng_inst)->errorcode = 0; - (*(WebRtcCngEncInst_t**) cng_inst)->initflag = 0; - return(0); - } - else { - /* The memory could not be allocated */ - return(-1); + /* Needed to get the right function pointers in SPLIB. */ + WebRtcSpl_Init(); + + return 0; + } else { + /* The memory could not be allocated. */ + return -1; } + } else { + /* The input pointer is invalid (NULL). */ + return -1; + } } -WebRtc_Word16 WebRtcCng_CreateDec(CNG_dec_inst **cng_inst) -{ - *cng_inst=(CNG_dec_inst*)malloc(sizeof(WebRtcCngDecInst_t)); - if(*cng_inst!=NULL) { - (*(WebRtcCngDecInst_t**) cng_inst)->errorcode = 0; - (*(WebRtcCngDecInst_t**) cng_inst)->initflag = 0; - return(0); - } - else { - /* The memory could not be allocated */ - return(-1); - } -} +int16_t WebRtcCng_CreateDec(CNG_dec_inst** cng_inst) { + if (cng_inst != NULL ) { + *cng_inst = (CNG_dec_inst*) malloc(sizeof(WebRtcCngDecInst_t)); + if (*cng_inst != NULL ) { + (*(WebRtcCngDecInst_t**) cng_inst)->errorcode = 0; + (*(WebRtcCngDecInst_t**) cng_inst)->initflag = 0; + /* Needed to get the right function pointers in SPLIB. */ + WebRtcSpl_Init(); + + return 0; + } else { + /* The memory could not be allocated */ + return -1; + } + } else { + /* The input pointer is invalid (NULL). */ + return -1; + } +} /**************************************************************************** * WebRtcCng_InitEnc/Dec(...) @@ -224,68 +142,54 @@ WebRtc_Word16 WebRtcCng_CreateDec(CNG_dec_inst **cng_inst) * Return value : 0 - Ok * -1 - Error */ +int16_t WebRtcCng_InitEnc(CNG_enc_inst* cng_inst, uint16_t fs, int16_t interval, + int16_t quality) { + int i; + WebRtcCngEncInst_t* inst = (WebRtcCngEncInst_t*) cng_inst; + memset(inst, 0, sizeof(WebRtcCngEncInst_t)); + /* Check LPC order */ + if (quality > WEBRTC_CNG_MAX_LPC_ORDER || quality <= 0) { + inst->errorcode = CNG_DISALLOWED_LPC_ORDER; + return -1; + } -WebRtc_Word16 WebRtcCng_InitEnc(CNG_enc_inst *cng_inst, - WebRtc_Word16 fs, - WebRtc_Word16 interval, - WebRtc_Word16 quality) -{ - int i; + inst->enc_sampfreq = fs; + inst->enc_interval = interval; + inst->enc_nrOfCoefs = quality; + inst->enc_msSinceSID = 0; + inst->enc_seed = 7777; /* For debugging only. */ + inst->enc_Energy = 0; + for (i = 0; i < (WEBRTC_CNG_MAX_LPC_ORDER + 1); i++) { + inst->enc_reflCoefs[i] = 0; + inst->enc_corrVector[i] = 0; + } + inst->initflag = 1; - WebRtcCngEncInst_t* inst=(WebRtcCngEncInst_t*)cng_inst; - - memset(inst, 0, sizeof(WebRtcCngEncInst_t)); - - /* Check LPC order */ - - if (quality>WEBRTC_CNG_MAX_LPC_ORDER) { - inst->errorcode = CNG_DISALLOWED_LPC_ORDER; - return (-1); - } - - if (fs<=0) { - inst->errorcode = CNG_DISALLOWED_SAMPLING_FREQUENCY; - return (-1); - } - - inst->enc_sampfreq=fs; - inst->enc_interval=interval; - inst->enc_nrOfCoefs=quality; - inst->enc_msSinceSID=0; - inst->enc_seed=7777; /*For debugging only*/ - inst->enc_Energy=0; - for(i=0;i<(WEBRTC_CNG_MAX_LPC_ORDER+1);i++){ - inst->enc_reflCoefs[i]=0; - inst->enc_corrVector[i]=0; - } - inst->initflag=1; - - return(0); + return 0; } -WebRtc_Word16 WebRtcCng_InitDec(CNG_dec_inst *cng_inst) -{ - int i; +int16_t WebRtcCng_InitDec(CNG_dec_inst* cng_inst) { + int i; - WebRtcCngDecInst_t* inst=(WebRtcCngDecInst_t*)cng_inst; + WebRtcCngDecInst_t* inst = (WebRtcCngDecInst_t*) cng_inst; - memset(inst, 0, sizeof(WebRtcCngDecInst_t)); - inst->dec_seed=7777; /*For debugging only*/ - inst->dec_order=5; - inst->dec_target_scale_factor=0; - inst->dec_used_scale_factor=0; - for(i=0;i<(WEBRTC_CNG_MAX_LPC_ORDER+1);i++){ - inst->dec_filtstate[i]=0; - inst->dec_target_reflCoefs[i]=0; - inst->dec_used_reflCoefs[i]=0; - } - inst->dec_target_reflCoefs[0]=0; - inst->dec_used_reflCoefs[0]=0; - inst ->dec_used_energy=0; - inst->initflag=1; + memset(inst, 0, sizeof(WebRtcCngDecInst_t)); + inst->dec_seed = 7777; /* For debugging only. */ + inst->dec_order = 5; + inst->dec_target_scale_factor = 0; + inst->dec_used_scale_factor = 0; + for (i = 0; i < (WEBRTC_CNG_MAX_LPC_ORDER + 1); i++) { + inst->dec_filtstate[i] = 0; + inst->dec_target_reflCoefs[i] = 0; + inst->dec_used_reflCoefs[i] = 0; + } + inst->dec_target_reflCoefs[0] = 0; + inst->dec_used_reflCoefs[0] = 0; + inst->dec_used_energy = 0; + inst->initflag = 1; - return(0); + return 0; } /**************************************************************************** @@ -299,22 +203,16 @@ WebRtc_Word16 WebRtcCng_InitDec(CNG_dec_inst *cng_inst) * Return value : 0 - Ok * -1 - Error */ - - -WebRtc_Word16 WebRtcCng_FreeEnc(CNG_enc_inst *cng_inst) -{ - free(cng_inst); - return(0); +int16_t WebRtcCng_FreeEnc(CNG_enc_inst* cng_inst) { + free(cng_inst); + return 0; } -WebRtc_Word16 WebRtcCng_FreeDec(CNG_dec_inst *cng_inst) -{ - free(cng_inst); - return(0); +int16_t WebRtcCng_FreeDec(CNG_dec_inst* cng_inst) { + free(cng_inst); + return 0; } - - /**************************************************************************** * WebRtcCng_Encode(...) * @@ -329,181 +227,176 @@ WebRtc_Word16 WebRtcCng_FreeDec(CNG_dec_inst *cng_inst) * Return value : 0 - Ok * -1 - Error */ -WebRtc_Word16 WebRtcCng_Encode(CNG_enc_inst *cng_inst, - WebRtc_Word16 *speech, - WebRtc_Word16 nrOfSamples, - WebRtc_UWord8* SIDdata, - WebRtc_Word16* bytesOut, - WebRtc_Word16 forceSID) -{ - WebRtcCngEncInst_t* inst=(WebRtcCngEncInst_t*)cng_inst; +int16_t WebRtcCng_Encode(CNG_enc_inst* cng_inst, int16_t* speech, + int16_t nrOfSamples, uint8_t* SIDdata, + int16_t* bytesOut, int16_t forceSID) { + WebRtcCngEncInst_t* inst = (WebRtcCngEncInst_t*) cng_inst; - WebRtc_Word16 arCoefs[WEBRTC_CNG_MAX_LPC_ORDER+1]; - WebRtc_Word32 corrVector[WEBRTC_CNG_MAX_LPC_ORDER+1]; - WebRtc_Word16 refCs[WEBRTC_CNG_MAX_LPC_ORDER+1]; - WebRtc_Word16 hanningW[WEBRTC_CNG_MAX_OUTSIZE_ORDER]; - WebRtc_Word16 ReflBeta=19661; /*0.6 in q15*/ - WebRtc_Word16 ReflBetaComp=13107; /*0.4 in q15*/ - WebRtc_Word32 outEnergy; - int outShifts; - int i, stab; - int acorrScale; - int index; - WebRtc_Word16 ind,factor; - WebRtc_Word32 *bptr, blo, bhi; - WebRtc_Word16 negate; - const WebRtc_Word16 *aptr; + int16_t arCoefs[WEBRTC_CNG_MAX_LPC_ORDER + 1]; + int32_t corrVector[WEBRTC_CNG_MAX_LPC_ORDER + 1]; + int16_t refCs[WEBRTC_CNG_MAX_LPC_ORDER + 1]; + int16_t hanningW[WEBRTC_CNG_MAX_OUTSIZE_ORDER]; + int16_t ReflBeta = 19661; /* 0.6 in q15. */ + int16_t ReflBetaComp = 13107; /* 0.4 in q15. */ + int32_t outEnergy; + int outShifts; + int i, stab; + int acorrScale; + int index; + int16_t ind, factor; + int32_t* bptr; + int32_t blo, bhi; + int16_t negate; + const int16_t* aptr; + int16_t speechBuf[WEBRTC_CNG_MAX_OUTSIZE_ORDER]; - WebRtc_Word16 speechBuf[WEBRTC_CNG_MAX_OUTSIZE_ORDER]; + /* Check if encoder initiated. */ + if (inst->initflag != 1) { + inst->errorcode = CNG_ENCODER_NOT_INITIATED; + return -1; + } + /* Check framesize. */ + if (nrOfSamples > WEBRTC_CNG_MAX_OUTSIZE_ORDER) { + inst->errorcode = CNG_DISALLOWED_FRAME_SIZE; + return -1; + } - /* check if encoder initiated */ - if (inst->initflag != 1) { - inst->errorcode = CNG_ENCODER_NOT_INITIATED; - return (-1); + for (i = 0; i < nrOfSamples; i++) { + speechBuf[i] = speech[i]; + } + + factor = nrOfSamples; + + /* Calculate energy and a coefficients. */ + outEnergy = WebRtcSpl_Energy(speechBuf, nrOfSamples, &outShifts); + while (outShifts > 0) { + /* We can only do 5 shifts without destroying accuracy in + * division factor. */ + if (outShifts > 5) { + outEnergy <<= (outShifts - 5); + outShifts = 5; + } else { + factor /= 2; + outShifts--; + } + } + outEnergy = WebRtcSpl_DivW32W16(outEnergy, factor); + + if (outEnergy > 1) { + /* Create Hanning Window. */ + WebRtcSpl_GetHanningWindow(hanningW, nrOfSamples / 2); + for (i = 0; i < (nrOfSamples / 2); i++) + hanningW[nrOfSamples - i - 1] = hanningW[i]; + + WebRtcSpl_ElementwiseVectorMult(speechBuf, hanningW, speechBuf, nrOfSamples, + 14); + + WebRtcSpl_AutoCorrelation(speechBuf, nrOfSamples, inst->enc_nrOfCoefs, + corrVector, &acorrScale); + + if (*corrVector == 0) + *corrVector = WEBRTC_SPL_WORD16_MAX; + + /* Adds the bandwidth expansion. */ + aptr = WebRtcCng_kCorrWindow; + bptr = corrVector; + + /* (zzz) lpc16_1 = 17+1+820+2+2 = 842 (ordo2=700). */ + for (ind = 0; ind < inst->enc_nrOfCoefs; ind++) { + /* The below code multiplies the 16 b corrWindow values (Q15) with + * the 32 b corrvector (Q0) and shifts the result down 15 steps. */ + negate = *bptr < 0; + if (negate) + *bptr = -*bptr; + + blo = (int32_t) * aptr * (*bptr & 0xffff); + bhi = ((blo >> 16) & 0xffff) + + ((int32_t)(*aptr++) * ((*bptr >> 16) & 0xffff)); + blo = (blo & 0xffff) | ((bhi & 0xffff) << 16); + + *bptr = (((bhi >> 16) & 0x7fff) << 17) | ((uint32_t) blo >> 15); + if (negate) + *bptr = -*bptr; + bptr++; + } + /* End of bandwidth expansion. */ + + stab = WebRtcSpl_LevinsonDurbin(corrVector, arCoefs, refCs, + inst->enc_nrOfCoefs); + + if (!stab) { + /* Disregard from this frame */ + *bytesOut = 0; + return 0; } + } else { + for (i = 0; i < inst->enc_nrOfCoefs; i++) + refCs[i] = 0; + } - /* check framesize */ - if (nrOfSamples>WEBRTC_CNG_MAX_OUTSIZE_ORDER) { - inst->errorcode = CNG_DISALLOWED_FRAME_SIZE; - return (-1); + if (forceSID) { + /* Read instantaneous values instead of averaged. */ + for (i = 0; i < inst->enc_nrOfCoefs; i++) + inst->enc_reflCoefs[i] = refCs[i]; + inst->enc_Energy = outEnergy; + } else { + /* Average history with new values. */ + for (i = 0; i < (inst->enc_nrOfCoefs); i++) { + inst->enc_reflCoefs[i] = (int16_t) WEBRTC_SPL_MUL_16_16_RSFT( + inst->enc_reflCoefs[i], ReflBeta, 15); + inst->enc_reflCoefs[i] += (int16_t) WEBRTC_SPL_MUL_16_16_RSFT( + refCs[i], ReflBetaComp, 15); + } + inst->enc_Energy = (outEnergy >> 2) + (inst->enc_Energy >> 1) + + (inst->enc_Energy >> 2); + } + + if (inst->enc_Energy < 1) { + inst->enc_Energy = 1; + } + + if ((inst->enc_msSinceSID > (inst->enc_interval - 1)) || forceSID) { + + /* Search for best dbov value. */ + index = 0; + for (i = 1; i < 93; i++) { + /* Always round downwards. */ + if ((inst->enc_Energy - WebRtcCng_kDbov[i]) > 0) { + index = i; + break; + } + } + if ((i == 93) && (index == 0)) + index = 94; + SIDdata[0] = index; + + /* Quantize coefficients with tweak for WebRtc implementation of RFC3389. */ + if (inst->enc_nrOfCoefs == WEBRTC_CNG_MAX_LPC_ORDER) { + for (i = 0; i < inst->enc_nrOfCoefs; i++) { + /* Q15 to Q7 with rounding. */ + SIDdata[i + 1] = ((inst->enc_reflCoefs[i] + 128) >> 8); + } + } else { + for (i = 0; i < inst->enc_nrOfCoefs; i++) { + /* Q15 to Q7 with rounding. */ + SIDdata[i + 1] = (127 + ((inst->enc_reflCoefs[i] + 128) >> 8)); + } } + inst->enc_msSinceSID = 0; + *bytesOut = inst->enc_nrOfCoefs + 1; - for(i=0;i0){ - if(outShifts>5){ /*We can only do 5 shifts without destroying accuracy in division factor*/ - outEnergy<<=(outShifts-5); - outShifts=5; - } - else{ - factor/=2; - outShifts--; - } - } - outEnergy=WebRtcSpl_DivW32W16(outEnergy,factor); - - if (outEnergy > 1){ - /* Create Hanning Window */ - WebRtcSpl_GetHanningWindow(hanningW, nrOfSamples/2); - for( i=0;i<(nrOfSamples/2);i++ ) - hanningW[nrOfSamples-i-1]=hanningW[i]; - - WebRtcSpl_ElementwiseVectorMult(speechBuf, hanningW, speechBuf, nrOfSamples, 14); - - WebRtcSpl_AutoCorrelation( speechBuf, nrOfSamples, inst->enc_nrOfCoefs, corrVector, &acorrScale ); - - if( *corrVector==0 ) - *corrVector = WEBRTC_SPL_WORD16_MAX; - - /* Adds the bandwidth expansion */ - aptr = WebRtcCng_kCorrWindow; - bptr = corrVector; - - // (zzz) lpc16_1 = 17+1+820+2+2 = 842 (ordo2=700) - for( ind=0; indenc_nrOfCoefs; ind++ ) - { - // The below code multiplies the 16 b corrWindow values (Q15) with - // the 32 b corrvector (Q0) and shifts the result down 15 steps. - - negate = *bptr<0; - if( negate ) - *bptr = -*bptr; - - blo = (WebRtc_Word32)*aptr * (*bptr & 0xffff); - bhi = ((blo >> 16) & 0xffff) + ((WebRtc_Word32)(*aptr++) * ((*bptr >> 16) & 0xffff)); - blo = (blo & 0xffff) | ((bhi & 0xffff) << 16); - - *bptr = (( (bhi>>16) & 0x7fff) << 17) | ((WebRtc_UWord32)blo >> 15); - if( negate ) - *bptr = -*bptr; - bptr++; - } - - // end of bandwidth expansion - - stab=WebRtcSpl_LevinsonDurbin(corrVector, arCoefs, refCs, inst->enc_nrOfCoefs); - - if(!stab){ - // disregard from this frame - *bytesOut=0; - return(0); - } - - } - else { - for(i=0;ienc_nrOfCoefs; i++) - refCs[i]=0; - } - - if(forceSID){ - /*Read instantaneous values instead of averaged*/ - for(i=0;ienc_nrOfCoefs;i++) - inst->enc_reflCoefs[i]=refCs[i]; - inst->enc_Energy=outEnergy; - } - else{ - /*Average history with new values*/ - for(i=0;i<(inst->enc_nrOfCoefs);i++){ - inst->enc_reflCoefs[i]=(WebRtc_Word16)WEBRTC_SPL_MUL_16_16_RSFT(inst->enc_reflCoefs[i],ReflBeta,15); - inst->enc_reflCoefs[i]+=(WebRtc_Word16)WEBRTC_SPL_MUL_16_16_RSFT(refCs[i],ReflBetaComp,15); - } - inst->enc_Energy=(outEnergy>>2)+(inst->enc_Energy>>1)+(inst->enc_Energy>>2); - } - - - if(inst->enc_Energy<1){ - inst->enc_Energy=1; - } - - if((inst->enc_msSinceSID>(inst->enc_interval-1))||forceSID){ - - /* Search for best dbov value */ - index=0; - for(i=1;i<93;i++){ - /* Always round downwards */ - if((inst->enc_Energy-WebRtcCng_kDbov[i])>0){ - index=i; - break; - } - } - if((i==93)&&(index==0)) - index=94; - SIDdata[0]=index; - - - /* Quantize coefs with tweak for WebRtc implementation of RFC3389 */ - if(inst->enc_nrOfCoefs==WEBRTC_CNG_MAX_LPC_ORDER){ - for(i=0;ienc_nrOfCoefs;i++){ - SIDdata[i+1]=((inst->enc_reflCoefs[i]+128)>>8); /* Q15 to Q7*/ /* +127 */ - } - }else{ - for(i=0;ienc_nrOfCoefs;i++){ - SIDdata[i+1]=(127+((inst->enc_reflCoefs[i]+128)>>8)); /* Q15 to Q7*/ /* +127 */ - } - } - - inst->enc_msSinceSID=0; - *bytesOut=inst->enc_nrOfCoefs+1; - - inst->enc_msSinceSID+=(1000*nrOfSamples)/inst->enc_sampfreq; - return(inst->enc_nrOfCoefs+1); - }else{ - inst->enc_msSinceSID+=(1000*nrOfSamples)/inst->enc_sampfreq; - *bytesOut=0; - return(0); - } + inst->enc_msSinceSID += (1000 * nrOfSamples) / inst->enc_sampfreq; + return inst->enc_nrOfCoefs + 1; + } else { + inst->enc_msSinceSID += (1000 * nrOfSamples) / inst->enc_sampfreq; + *bytesOut = 0; + return 0; + } } - /**************************************************************************** * WebRtcCng_UpdateSid(...) * @@ -517,59 +410,55 @@ WebRtc_Word16 WebRtcCng_Encode(CNG_enc_inst *cng_inst, * Return value : 0 - Ok * -1 - Error */ +int16_t WebRtcCng_UpdateSid(CNG_dec_inst* cng_inst, uint8_t* SID, + int16_t length) { -WebRtc_Word16 WebRtcCng_UpdateSid(CNG_dec_inst *cng_inst, - WebRtc_UWord8 *SID, - WebRtc_Word16 length) -{ + WebRtcCngDecInst_t* inst = (WebRtcCngDecInst_t*) cng_inst; + int16_t refCs[WEBRTC_CNG_MAX_LPC_ORDER]; + int32_t targetEnergy; + int i; - WebRtcCngDecInst_t* inst=(WebRtcCngDecInst_t*)cng_inst; - WebRtc_Word16 refCs[WEBRTC_CNG_MAX_LPC_ORDER]; - WebRtc_Word32 targetEnergy; - int i; + if (inst->initflag != 1) { + inst->errorcode = CNG_DECODER_NOT_INITIATED; + return -1; + } - if (inst->initflag != 1) { - inst->errorcode = CNG_DECODER_NOT_INITIATED; - return (-1); + /* Throw away reflection coefficients of higher order than we can handle. */ + if (length > (WEBRTC_CNG_MAX_LPC_ORDER + 1)) + length = WEBRTC_CNG_MAX_LPC_ORDER + 1; + + inst->dec_order = length - 1; + + if (SID[0] > 93) + SID[0] = 93; + targetEnergy = WebRtcCng_kDbov[SID[0]]; + /* Take down target energy to 75%. */ + targetEnergy = targetEnergy >> 1; + targetEnergy += targetEnergy >> 2; + + inst->dec_target_energy = targetEnergy; + + /* Reconstruct coeffs with tweak for WebRtc implementation of RFC3389. */ + if (inst->dec_order == WEBRTC_CNG_MAX_LPC_ORDER) { + for (i = 0; i < (inst->dec_order); i++) { + refCs[i] = SID[i + 1] << 8; /* Q7 to Q15*/ + inst->dec_target_reflCoefs[i] = refCs[i]; } - - /*Throw away reflection coefficients of higher order than we can handle*/ - if(length> (WEBRTC_CNG_MAX_LPC_ORDER+1)) - length=WEBRTC_CNG_MAX_LPC_ORDER+1; - - inst->dec_order=length-1; - - if(SID[0]>93) - SID[0]=93; - targetEnergy=WebRtcCng_kDbov[SID[0]]; - /* Take down target energy to 75% */ - targetEnergy=targetEnergy>>1; - targetEnergy+=targetEnergy>>2; - - inst->dec_target_energy=targetEnergy; - - /* Reconstruct coeffs with tweak for WebRtc implementation of RFC3389 */ - if(inst->dec_order==WEBRTC_CNG_MAX_LPC_ORDER){ - for(i=0;i<(inst->dec_order);i++){ - refCs[i]=SID[i+1]<<8; /* Q7 to Q15*/ - inst->dec_target_reflCoefs[i]=refCs[i]; - } - }else{ - for(i=0;i<(inst->dec_order);i++){ - refCs[i]=(SID[i+1]-127)<<8; /* Q7 to Q15*/ - inst->dec_target_reflCoefs[i]=refCs[i]; - } + } else { + for (i = 0; i < (inst->dec_order); i++) { + refCs[i] = (SID[i + 1] - 127) << 8; /* Q7 to Q15. */ + inst->dec_target_reflCoefs[i] = refCs[i]; } - - for(i=(inst->dec_order);idec_target_reflCoefs[i]=refCs[i]; - } + } - return(0); + for (i = (inst->dec_order); i < WEBRTC_CNG_MAX_LPC_ORDER; i++) { + refCs[i] = 0; + inst->dec_target_reflCoefs[i] = refCs[i]; + } + + return 0; } - /**************************************************************************** * WebRtcCng_Generate(...) * @@ -583,122 +472,110 @@ WebRtc_Word16 WebRtcCng_UpdateSid(CNG_dec_inst *cng_inst, * Return value : 0 - Ok * -1 - Error */ -WebRtc_Word16 WebRtcCng_Generate(CNG_dec_inst *cng_inst, - WebRtc_Word16 *outData, - WebRtc_Word16 nrOfSamples, - WebRtc_Word16 new_period) -{ - WebRtcCngDecInst_t* inst=(WebRtcCngDecInst_t*)cng_inst; - - int i; - WebRtc_Word16 excitation[WEBRTC_CNG_MAX_OUTSIZE_ORDER]; - WebRtc_Word16 low[WEBRTC_CNG_MAX_OUTSIZE_ORDER]; - WebRtc_Word16 lpPoly[WEBRTC_CNG_MAX_LPC_ORDER+1]; - WebRtc_Word16 ReflBetaStd=26214; /*0.8 in q15*/ - WebRtc_Word16 ReflBetaCompStd=6553; /*0.2in q15*/ - WebRtc_Word16 ReflBetaNewP=19661; /*0.6 in q15*/ - WebRtc_Word16 ReflBetaCompNewP=13107; /*0.4 in q15*/ - WebRtc_Word16 Beta,BetaC, tmp1, tmp2, tmp3; - WebRtc_Word32 targetEnergy; - WebRtc_Word16 En; - WebRtc_Word16 temp16; +int16_t WebRtcCng_Generate(CNG_dec_inst* cng_inst, int16_t* outData, + int16_t nrOfSamples, int16_t new_period) { + WebRtcCngDecInst_t* inst = (WebRtcCngDecInst_t*) cng_inst; - if (nrOfSamples>WEBRTC_CNG_MAX_OUTSIZE_ORDER) { - inst->errorcode = CNG_DISALLOWED_FRAME_SIZE; - return (-1); - } + int i; + int16_t excitation[WEBRTC_CNG_MAX_OUTSIZE_ORDER]; + int16_t low[WEBRTC_CNG_MAX_OUTSIZE_ORDER]; + int16_t lpPoly[WEBRTC_CNG_MAX_LPC_ORDER + 1]; + int16_t ReflBetaStd = 26214; /* 0.8 in q15. */ + int16_t ReflBetaCompStd = 6553; /* 0.2 in q15. */ + int16_t ReflBetaNewP = 19661; /* 0.6 in q15. */ + int16_t ReflBetaCompNewP = 13107; /* 0.4 in q15. */ + int16_t Beta, BetaC, tmp1, tmp2, tmp3; + int32_t targetEnergy; + int16_t En; + int16_t temp16; + + if (nrOfSamples > WEBRTC_CNG_MAX_OUTSIZE_ORDER) { + inst->errorcode = CNG_DISALLOWED_FRAME_SIZE; + return -1; + } + + if (new_period) { + inst->dec_used_scale_factor = inst->dec_target_scale_factor; + Beta = ReflBetaNewP; + BetaC = ReflBetaCompNewP; + } else { + Beta = ReflBetaStd; + BetaC = ReflBetaCompStd; + } + + /* Here we use a 0.5 weighting, should possibly be modified to 0.6. */ + tmp1 = inst->dec_used_scale_factor << 2; /* Q13->Q15 */ + tmp2 = inst->dec_target_scale_factor << 2; /* Q13->Q15 */ + tmp3 = (int16_t) WEBRTC_SPL_MUL_16_16_RSFT(tmp1, Beta, 15); + tmp3 += (int16_t) WEBRTC_SPL_MUL_16_16_RSFT(tmp2, BetaC, 15); + inst->dec_used_scale_factor = tmp3 >> 2; /* Q15->Q13 */ + + inst->dec_used_energy = inst->dec_used_energy >> 1; + inst->dec_used_energy += inst->dec_target_energy >> 1; + + /* Do the same for the reflection coeffs. */ + for (i = 0; i < WEBRTC_CNG_MAX_LPC_ORDER; i++) { + inst->dec_used_reflCoefs[i] = (int16_t) WEBRTC_SPL_MUL_16_16_RSFT( + inst->dec_used_reflCoefs[i], Beta, 15); + inst->dec_used_reflCoefs[i] += (int16_t) WEBRTC_SPL_MUL_16_16_RSFT( + inst->dec_target_reflCoefs[i], BetaC, 15); + } + + /* Compute the polynomial coefficients. */ + WebRtcCng_K2a16(inst->dec_used_reflCoefs, WEBRTC_CNG_MAX_LPC_ORDER, lpPoly); - if (new_period) { - inst->dec_used_scale_factor=inst->dec_target_scale_factor; - Beta=ReflBetaNewP; - BetaC=ReflBetaCompNewP; - } else { - Beta=ReflBetaStd; - BetaC=ReflBetaCompStd; - } + targetEnergy = inst->dec_used_energy; - /*Here we use a 0.5 weighting, should possibly be modified to 0.6*/ - tmp1=inst->dec_used_scale_factor<<2; /* Q13->Q15 */ - tmp2=inst->dec_target_scale_factor<<2; /* Q13->Q15 */ - tmp3=(WebRtc_Word16)WEBRTC_SPL_MUL_16_16_RSFT(tmp1,Beta,15); - tmp3+=(WebRtc_Word16)WEBRTC_SPL_MUL_16_16_RSFT(tmp2,BetaC,15); - inst->dec_used_scale_factor=tmp3>>2; /* Q15->Q13 */ + /* Calculate scaling factor based on filter energy. */ + En = 8192; /* 1.0 in Q13. */ + for (i = 0; i < (WEBRTC_CNG_MAX_LPC_ORDER); i++) { - inst->dec_used_energy=inst->dec_used_energy>>1; - inst->dec_used_energy+=inst->dec_target_energy>>1; + /* Floating point value for reference. + E *= 1.0 - (inst->dec_used_reflCoefs[i] / 32768.0) * + (inst->dec_used_reflCoefs[i] / 32768.0); + */ - - /* Do the same for the reflection coeffs */ - for (i=0;idec_used_reflCoefs[i]=(WebRtc_Word16)WEBRTC_SPL_MUL_16_16_RSFT(inst->dec_used_reflCoefs[i],Beta,15); - inst->dec_used_reflCoefs[i]+=(WebRtc_Word16)WEBRTC_SPL_MUL_16_16_RSFT(inst->dec_target_reflCoefs[i],BetaC,15); - } + /* Same in fixed point. */ + /* K(i).^2 in Q15. */ + temp16 = (int16_t) WEBRTC_SPL_MUL_16_16_RSFT( + inst->dec_used_reflCoefs[i], inst->dec_used_reflCoefs[i], 15); + /* 1 - K(i).^2 in Q15. */ + temp16 = 0x7fff - temp16; + En = (int16_t) WEBRTC_SPL_MUL_16_16_RSFT(En, temp16, 15); + } - /* Compute the polynomial coefficients */ - WebRtcCng_K2a16(inst->dec_used_reflCoefs, WEBRTC_CNG_MAX_LPC_ORDER, lpPoly); + /* float scaling= sqrt(E * inst->dec_target_energy / (1 << 24)); */ - /***/ + /* Calculate sqrt(En * target_energy / excitation energy) */ + targetEnergy = WebRtcSpl_Sqrt(inst->dec_used_energy); - targetEnergy=inst->dec_used_energy; + En = (int16_t) WebRtcSpl_Sqrt(En) << 6; + En = (En * 3) >> 1; /* 1.5 estimates sqrt(2). */ + inst->dec_used_scale_factor = (int16_t)((En * targetEnergy) >> 12); - // Calculate scaling factor based on filter energy - En=8192; //1.0 in Q13 - for (i=0; i<(WEBRTC_CNG_MAX_LPC_ORDER); i++) { + /* Generate excitation. */ + /* Excitation energy per sample is 2.^24 - Q13 N(0,1). */ + for (i = 0; i < nrOfSamples; i++) { + excitation[i] = WebRtcSpl_RandN(&inst->dec_seed) >> 1; + } - // Floating point value for reference - // E*=1.0-((float)inst->dec_used_reflCoefs[i]/32768.0)*((float)inst->dec_used_reflCoefs[i]/32768.0); + /* Scale to correct energy. */ + WebRtcSpl_ScaleVector(excitation, excitation, inst->dec_used_scale_factor, + nrOfSamples, 13); - // Same in fixed point - temp16=(WebRtc_Word16)WEBRTC_SPL_MUL_16_16_RSFT(inst->dec_used_reflCoefs[i],inst->dec_used_reflCoefs[i],15); // K(i).^2 in Q15 - temp16=0x7fff - temp16; // 1 - K(i).^2 in Q15 - En=(WebRtc_Word16)WEBRTC_SPL_MUL_16_16_RSFT(En,temp16,15); - - } - - //float scaling= sqrt(E*inst->dec_target_energy/((1<<24))); - - //Calculate sqrt(En*target_energy/exctiation energy) - - targetEnergy=WebRtcSpl_Sqrt(inst->dec_used_energy); - - En=(WebRtc_Word16)WebRtcSpl_Sqrt(En)<<6; //We are missing a factor sqrt(2) here - En=(En*3)>>1; //1.5 estimates sqrt(2) - - inst->dec_used_scale_factor=(WebRtc_Word16)((En*targetEnergy)>>12); - - - /***/ - - /*Generate excitation*/ - /*Excitation energy per sample is 2.^24 - Q13 N(0,1) */ - for(i=0;idec_seed)>>1; - } - - /*Scale to correct energy*/ - WebRtcSpl_ScaleVector(excitation, excitation, inst->dec_used_scale_factor, nrOfSamples, 13); - - WebRtcSpl_FilterAR( - lpPoly, /* Coefficients in Q12 */ - WEBRTC_CNG_MAX_LPC_ORDER+1, - excitation, /* Speech samples */ - nrOfSamples, - inst->dec_filtstate, /* State preservation */ - WEBRTC_CNG_MAX_LPC_ORDER, - inst->dec_filtstateLow, /* State preservation */ - WEBRTC_CNG_MAX_LPC_ORDER, - outData, /* Filtered speech samples */ - low, - nrOfSamples - ); - - return(0); + /* |lpPoly| - Coefficients in Q12. + * |excitation| - Speech samples. + * |nst->dec_filtstate| - State preservation. + * |outData| - Filtered speech samples. */ + WebRtcSpl_FilterAR(lpPoly, WEBRTC_CNG_MAX_LPC_ORDER + 1, excitation, + nrOfSamples, inst->dec_filtstate, WEBRTC_CNG_MAX_LPC_ORDER, + inst->dec_filtstateLow, WEBRTC_CNG_MAX_LPC_ORDER, outData, + low, nrOfSamples); + return 0; } - - /**************************************************************************** * WebRtcCng_GetErrorCodeEnc/Dec(...) * @@ -712,21 +589,14 @@ WebRtc_Word16 WebRtcCng_Generate(CNG_dec_inst *cng_inst, * * Return value : Error code */ - -WebRtc_Word16 WebRtcCng_GetErrorCodeEnc(CNG_enc_inst *cng_inst) -{ - - /* typecast pointer to real structure */ - WebRtcCngEncInst_t* inst=(WebRtcCngEncInst_t*)cng_inst; - - return inst->errorcode; +int16_t WebRtcCng_GetErrorCodeEnc(CNG_enc_inst* cng_inst) { + /* Typecast pointer to real structure. */ + WebRtcCngEncInst_t* inst = (WebRtcCngEncInst_t*) cng_inst; + return inst->errorcode; } -WebRtc_Word16 WebRtcCng_GetErrorCodeDec(CNG_dec_inst *cng_inst) -{ - - /* typecast pointer to real structure */ - WebRtcCngDecInst_t* inst=(WebRtcCngDecInst_t*)cng_inst; - - return inst->errorcode; +int16_t WebRtcCng_GetErrorCodeDec(CNG_dec_inst* cng_inst) { + /* Typecast pointer to real structure. */ + WebRtcCngDecInst_t* inst = (WebRtcCngDecInst_t*) cng_inst; + return inst->errorcode; }