2011-07-07 08:21:25 +00:00
|
|
|
/*
|
2012-02-28 17:26:14 +00:00
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
2011-07-07 08:21:25 +00:00
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
2015-11-18 23:07:57 +01:00
|
|
|
#ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_CNG_WEBRTC_CNG_H_
|
|
|
|
|
#define WEBRTC_MODULES_AUDIO_CODING_CODECS_CNG_WEBRTC_CNG_H_
|
2011-07-07 08:21:25 +00:00
|
|
|
|
Use size_t more consistently for packet/payload lengths.
See design doc at https://docs.google.com/a/chromium.org/document/d/1I6nmE9D_BmCY-IoV6MDPY2V6WYpEI-dg2apWXTfZyUI/edit?usp=sharing for more information.
This CL was reviewed and approved in pieces in the following CLs:
https://webrtc-codereview.appspot.com/24209004/
https://webrtc-codereview.appspot.com/24229004/
https://webrtc-codereview.appspot.com/24259004/
https://webrtc-codereview.appspot.com/25109004/
https://webrtc-codereview.appspot.com/26099004/
https://webrtc-codereview.appspot.com/27069004/
https://webrtc-codereview.appspot.com/27969004/
https://webrtc-codereview.appspot.com/27989004/
https://webrtc-codereview.appspot.com/29009004/
https://webrtc-codereview.appspot.com/30929004/
https://webrtc-codereview.appspot.com/30939004/
https://webrtc-codereview.appspot.com/31999004/
Committing as TBR to the original reviewers.
BUG=chromium:81439
TEST=none
TBR=pthatcher,henrik.lundin,tina.legrand,stefan,tkchin,glaznev,kjellander,perkj,mflodman,henrika,asapersson,niklas.enbom
Review URL: https://webrtc-codereview.appspot.com/23129004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7726 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-11-20 22:28:14 +00:00
|
|
|
#include <stddef.h>
|
2014-09-04 13:28:48 +00:00
|
|
|
#include "webrtc/typedefs.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#define WEBRTC_CNG_MAX_LPC_ORDER 12
|
|
|
|
|
#define WEBRTC_CNG_MAX_OUTSIZE_ORDER 640
|
|
|
|
|
|
2012-09-28 07:12:00 +00:00
|
|
|
/* Define Error codes. */
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
/* 6100 Encoder */
|
|
|
|
|
#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_NOT_INITIATED 6220
|
|
|
|
|
|
2012-09-28 07:12:00 +00:00
|
|
|
typedef struct WebRtcCngEncInst CNG_enc_inst;
|
|
|
|
|
typedef struct WebRtcCngDecInst CNG_dec_inst;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* WebRtcCng_CreateEnc/Dec(...)
|
|
|
|
|
*
|
|
|
|
|
* These functions create an instance to the specified structure
|
|
|
|
|
*
|
|
|
|
|
* Input:
|
|
|
|
|
* - XXX_inst : Pointer to created instance that should be created
|
|
|
|
|
*
|
|
|
|
|
* Return value : 0 - Ok
|
|
|
|
|
* -1 - Error
|
|
|
|
|
*/
|
2012-09-28 07:12:00 +00:00
|
|
|
int16_t WebRtcCng_CreateEnc(CNG_enc_inst** cng_inst);
|
|
|
|
|
int16_t WebRtcCng_CreateDec(CNG_dec_inst** cng_inst);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* WebRtcCng_InitEnc/Dec(...)
|
|
|
|
|
*
|
|
|
|
|
* This function initializes a instance
|
|
|
|
|
*
|
|
|
|
|
* Input:
|
|
|
|
|
* - cng_inst : Instance that should be initialized
|
|
|
|
|
*
|
|
|
|
|
* - fs : 8000 for narrowband and 16000 for wideband
|
|
|
|
|
* - interval : generate SID data every interval ms
|
|
|
|
|
* - quality : Number of refl. coefs, maximum allowed is 12
|
|
|
|
|
*
|
|
|
|
|
* Output:
|
|
|
|
|
* - cng_inst : Initialized instance
|
|
|
|
|
*
|
|
|
|
|
* Return value : 0 - Ok
|
|
|
|
|
* -1 - Error
|
|
|
|
|
*/
|
|
|
|
|
|
Reland "Upconvert various types to int.", misc. codecs portion.
This reverts portions of commit cb180976dd0e9672cde4523d87b5f4857478b5e9, which
reverted commit 83ad33a8aed1fb00e422b6abd33c3e8942821c24. Specifically, the
files in webrtc/modules/audio_coding/codecs/ that are not in ilbc/ or isac/, as
well as webrtc/modules/audio_coding/main/test/opus_test.cc, are relanded.
The original commit message is below:
Upconvert various types to int.
Per comments from HL/kwiberg on https://webrtc-codereview.appspot.com/42569004 , when there is existing usage of mixed types (int16_t, int, etc.), we'd prefer to standardize on larger types like int and phase out use of int16_t.
Specifically, "Using int16 just because we're sure all reasonable values will fit in 16 bits isn't usually meaningful in C."
This converts some existing uses of int16_t (and, in a few cases, other types such as uint16_t) to int (or, in a few places, int32_t). Other locations will be converted to size_t in a separate change.
BUG=none
TBR=kwiberg
Review URL: https://codereview.webrtc.org/1179093003
Cr-Commit-Position: refs/heads/master@{#9424}
2015-06-11 19:02:46 -07:00
|
|
|
int WebRtcCng_InitEnc(CNG_enc_inst* cng_inst, int fs, int16_t interval,
|
|
|
|
|
int16_t quality);
|
2015-08-27 15:22:11 +02:00
|
|
|
void WebRtcCng_InitDec(CNG_dec_inst* cng_inst);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* WebRtcCng_FreeEnc/Dec(...)
|
|
|
|
|
*
|
|
|
|
|
* These functions frees the dynamic memory of a specified instance
|
|
|
|
|
*
|
|
|
|
|
* Input:
|
|
|
|
|
* - cng_inst : Pointer to created instance that should be freed
|
|
|
|
|
*
|
|
|
|
|
* Return value : 0 - Ok
|
|
|
|
|
* -1 - Error
|
|
|
|
|
*/
|
2012-09-28 07:12:00 +00:00
|
|
|
int16_t WebRtcCng_FreeEnc(CNG_enc_inst* cng_inst);
|
|
|
|
|
int16_t WebRtcCng_FreeDec(CNG_dec_inst* cng_inst);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* WebRtcCng_Encode(...)
|
|
|
|
|
*
|
|
|
|
|
* These functions analyzes background noise
|
|
|
|
|
*
|
|
|
|
|
* Input:
|
|
|
|
|
* - cng_inst : Pointer to created instance
|
|
|
|
|
* - speech : Signal to be analyzed
|
|
|
|
|
* - nrOfSamples : Size of speech vector
|
|
|
|
|
* - forceSID : not zero to force SID frame and reset
|
|
|
|
|
*
|
|
|
|
|
* Output:
|
|
|
|
|
* - bytesOut : Nr of bytes to transmit, might be 0
|
|
|
|
|
*
|
|
|
|
|
* Return value : 0 - Ok
|
|
|
|
|
* -1 - Error
|
|
|
|
|
*/
|
Reland "Upconvert various types to int.", misc. codecs portion.
This reverts portions of commit cb180976dd0e9672cde4523d87b5f4857478b5e9, which
reverted commit 83ad33a8aed1fb00e422b6abd33c3e8942821c24. Specifically, the
files in webrtc/modules/audio_coding/codecs/ that are not in ilbc/ or isac/, as
well as webrtc/modules/audio_coding/main/test/opus_test.cc, are relanded.
The original commit message is below:
Upconvert various types to int.
Per comments from HL/kwiberg on https://webrtc-codereview.appspot.com/42569004 , when there is existing usage of mixed types (int16_t, int, etc.), we'd prefer to standardize on larger types like int and phase out use of int16_t.
Specifically, "Using int16 just because we're sure all reasonable values will fit in 16 bits isn't usually meaningful in C."
This converts some existing uses of int16_t (and, in a few cases, other types such as uint16_t) to int (or, in a few places, int32_t). Other locations will be converted to size_t in a separate change.
BUG=none
TBR=kwiberg
Review URL: https://codereview.webrtc.org/1179093003
Cr-Commit-Position: refs/heads/master@{#9424}
2015-06-11 19:02:46 -07:00
|
|
|
int WebRtcCng_Encode(CNG_enc_inst* cng_inst, int16_t* speech,
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
size_t nrOfSamples, uint8_t* SIDdata,
|
|
|
|
|
size_t* bytesOut, int16_t forceSID);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* WebRtcCng_UpdateSid(...)
|
|
|
|
|
*
|
|
|
|
|
* These functions updates the CN state, when a new SID packet arrives
|
|
|
|
|
*
|
|
|
|
|
* Input:
|
|
|
|
|
* - cng_inst : Pointer to created instance that should be freed
|
|
|
|
|
* - SID : SID packet, all headers removed
|
|
|
|
|
* - length : Length in bytes of SID packet
|
|
|
|
|
*
|
|
|
|
|
* Return value : 0 - Ok
|
|
|
|
|
* -1 - Error
|
|
|
|
|
*/
|
2012-09-28 07:12:00 +00:00
|
|
|
int16_t WebRtcCng_UpdateSid(CNG_dec_inst* cng_inst, uint8_t* SID,
|
Use size_t more consistently for packet/payload lengths.
See design doc at https://docs.google.com/a/chromium.org/document/d/1I6nmE9D_BmCY-IoV6MDPY2V6WYpEI-dg2apWXTfZyUI/edit?usp=sharing for more information.
This CL was reviewed and approved in pieces in the following CLs:
https://webrtc-codereview.appspot.com/24209004/
https://webrtc-codereview.appspot.com/24229004/
https://webrtc-codereview.appspot.com/24259004/
https://webrtc-codereview.appspot.com/25109004/
https://webrtc-codereview.appspot.com/26099004/
https://webrtc-codereview.appspot.com/27069004/
https://webrtc-codereview.appspot.com/27969004/
https://webrtc-codereview.appspot.com/27989004/
https://webrtc-codereview.appspot.com/29009004/
https://webrtc-codereview.appspot.com/30929004/
https://webrtc-codereview.appspot.com/30939004/
https://webrtc-codereview.appspot.com/31999004/
Committing as TBR to the original reviewers.
BUG=chromium:81439
TEST=none
TBR=pthatcher,henrik.lundin,tina.legrand,stefan,tkchin,glaznev,kjellander,perkj,mflodman,henrika,asapersson,niklas.enbom
Review URL: https://webrtc-codereview.appspot.com/23129004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7726 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-11-20 22:28:14 +00:00
|
|
|
size_t length);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* WebRtcCng_Generate(...)
|
|
|
|
|
*
|
|
|
|
|
* These functions generates CN data when needed
|
|
|
|
|
*
|
|
|
|
|
* Input:
|
|
|
|
|
* - cng_inst : Pointer to created instance that should be freed
|
|
|
|
|
* - outData : pointer to area to write CN data
|
|
|
|
|
* - nrOfSamples : How much data to generate
|
|
|
|
|
* - new_period : >0 if a new period of CNG, will reset history
|
|
|
|
|
*
|
|
|
|
|
* Return value : 0 - Ok
|
|
|
|
|
* -1 - Error
|
|
|
|
|
*/
|
2012-09-28 07:12:00 +00:00
|
|
|
int16_t WebRtcCng_Generate(CNG_dec_inst* cng_inst, int16_t* outData,
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
size_t nrOfSamples, int16_t new_period);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
|
* WebRtcCng_GetErrorCodeEnc/Dec(...)
|
|
|
|
|
*
|
|
|
|
|
* This functions can be used to check the error code of a CNG instance. When
|
2015-11-18 23:07:57 +01:00
|
|
|
* a function returns -1 a error code will be set for that instance. The
|
2011-07-07 08:21:25 +00:00
|
|
|
* function below extract the code of the last error that occurred in the
|
|
|
|
|
* specified instance.
|
|
|
|
|
*
|
|
|
|
|
* Input:
|
|
|
|
|
* - CNG_inst : CNG enc/dec instance
|
|
|
|
|
*
|
|
|
|
|
* Return value : Error code
|
|
|
|
|
*/
|
2012-09-28 07:12:00 +00:00
|
|
|
int16_t WebRtcCng_GetErrorCodeEnc(CNG_enc_inst* cng_inst);
|
|
|
|
|
int16_t WebRtcCng_GetErrorCodeDec(CNG_dec_inst* cng_inst);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2015-11-18 23:07:57 +01:00
|
|
|
#endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_CNG_WEBRTC_CNG_H_
|