This CL contains some refactoring. Spectrum coding is main place that is affected. Therefore, I have bit-exactness test, test_spectrum_

coding.c, to be sure about the changelist. You can go through the test to be sure the changes are tested. However, I don't intend to commi
t the test, as it would be a source of confusion and requires hack to iSAC to be able to run the test. It is basically a one-time test. 

The part which not covered in this test is where we limit payload for super-wideband bit-stream. I'll add a test for that as well. 

I kept format changes at minimum in all files except isac.c, which was in bad shape, and coding changes were minimum. I'm planning to uplo
ad following patches to this CL where I try to address formatting issues. But I don't intend to change variable names, for the moment. 

The refactoring is not yet finished, so you would find part of the code which could be cleaned up, especially KLT transforms in entropy_co
ding.c
Review URL: https://webrtc-codereview.appspot.com/580004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@2359 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
turaj@webrtc.org 2012-06-04 20:04:58 +00:00
parent 2cc55096d5
commit ba108aee21
7 changed files with 2666 additions and 4116 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
*
* 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
@ -21,57 +21,39 @@
#include "structs.h"
int WebRtcIsac_EstimateBandwidth(
BwEstimatorstr* bwest_str,
Bitstr* streamdata,
WebRtc_Word32 packet_size,
WebRtc_UWord16 rtp_seq_number,
WebRtc_UWord32 send_ts,
WebRtc_UWord32 arr_ts,
enum IsacSamplingRate encoderSampRate,
enum IsacSamplingRate decoderSampRate);
int WebRtcIsac_DecodeLb(
float* signal_out,
ISACLBDecStruct* ISACdec_obj,
WebRtc_Word16* current_framesamples,
WebRtc_Word16 isRCUPayload);
void WebRtcIsac_ResetBitstream(Bitstr* bit_stream);
int WebRtcIsac_DecodeRcuLb(
float* signal_out,
ISACLBDecStruct* ISACdec_obj,
WebRtc_Word16* current_framesamples);
int WebRtcIsac_EstimateBandwidth(BwEstimatorstr* bwest_str, Bitstr* streamdata,
WebRtc_Word32 packet_size,
WebRtc_UWord16 rtp_seq_number,
WebRtc_UWord32 send_ts, WebRtc_UWord32 arr_ts,
enum IsacSamplingRate encoderSampRate,
enum IsacSamplingRate decoderSampRate);
int WebRtcIsac_EncodeLb(
float* in,
ISACLBEncStruct* ISACencLB_obj,
WebRtc_Word16 codingMode,
WebRtc_Word16 bottleneckIndex);
int WebRtcIsac_DecodeLb(float* signal_out, ISACLBDecStruct* ISACdec_obj,
WebRtc_Word16* current_framesamples,
WebRtc_Word16 isRCUPayload);
int WebRtcIsac_EncodeStoredDataLb(
const ISAC_SaveEncData_t* ISACSavedEnc_obj,
Bitstr* ISACBitStr_obj,
int BWnumber,
float scale);
int WebRtcIsac_DecodeRcuLb(float* signal_out, ISACLBDecStruct* ISACdec_obj,
WebRtc_Word16* current_framesamples);
int WebRtcIsac_EncodeLb(float* in, ISACLBEncStruct* ISACencLB_obj,
WebRtc_Word16 codingMode, WebRtc_Word16
bottleneckIndex);
int WebRtcIsac_EncodeStoredDataUb12(
const ISACUBSaveEncDataStruct* ISACSavedEnc_obj,
Bitstr* bitStream,
WebRtc_Word32 jitterInfo,
float scale);
int WebRtcIsac_EncodeStoredDataUb16(
const ISACUBSaveEncDataStruct* ISACSavedEnc_obj,
Bitstr* bitStream,
WebRtc_Word32 jitterInfo,
float scale);
int WebRtcIsac_EncodeStoredDataLb(const ISAC_SaveEncData_t* ISACSavedEnc_obj,
Bitstr* ISACBitStr_obj, int BWnumber,
float scale);
int WebRtcIsac_EncodeStoredDataUb(
const ISACUBSaveEncDataStruct* ISACSavedEnc_obj, Bitstr* bitStream,
WebRtc_Word32 jitterInfo, float scale, enum ISACBandwidth bandwidth);
WebRtc_Word16 WebRtcIsac_GetRedPayloadUb(
const ISACUBSaveEncDataStruct* ISACSavedEncObj,
Bitstr* bitStreamObj,
enum ISACBandwidth bandwidth);
const ISACUBSaveEncDataStruct* ISACSavedEncObj, Bitstr* bitStreamObj,
enum ISACBandwidth bandwidth);
/******************************************************************************
* WebRtcIsac_RateAllocation()
* Internal function to perform a rate-allocation for upper and lower-band,
@ -90,12 +72,10 @@ WebRtc_Word16 WebRtcIsac_GetRedPayloadUb(
* -1 if failed to allocate rates.
*/
WebRtc_Word16
WebRtcIsac_RateAllocation(
WebRtc_Word32 inRateBitPerSec,
double* rateLBBitPerSec,
double* rateUBBitPerSec,
enum ISACBandwidth* bandwidthKHz);
WebRtc_Word16 WebRtcIsac_RateAllocation(WebRtc_Word32 inRateBitPerSec,
double* rateLBBitPerSec,
double* rateUBBitPerSec,
enum ISACBandwidth* bandwidthKHz);
/******************************************************************************
@ -113,10 +93,8 @@ WebRtcIsac_RateAllocation(
* Return value : >0 number of decoded bytes.
* <0 if an error occurred.
*/
int WebRtcIsac_DecodeUb16(
float* signal_out,
ISACUBDecStruct* ISACdec_obj,
WebRtc_Word16 isRCUPayload);
int WebRtcIsac_DecodeUb16(float* signal_out, ISACUBDecStruct* ISACdec_obj,
WebRtc_Word16 isRCUPayload);
/******************************************************************************
@ -134,10 +112,8 @@ int WebRtcIsac_DecodeUb16(
* Return value : >0 number of decoded bytes.
* <0 if an error occurred.
*/
int WebRtcIsac_DecodeUb12(
float* signal_out,
ISACUBDecStruct* ISACdec_obj,
WebRtc_Word16 isRCUPayload);
int WebRtcIsac_DecodeUb12(float* signal_out, ISACUBDecStruct* ISACdec_obj,
WebRtc_Word16 isRCUPayload);
/******************************************************************************
@ -155,10 +131,8 @@ int WebRtcIsac_DecodeUb12(
* Return value : >0 number of encoded bytes.
* <0 if an error occurred.
*/
int WebRtcIsac_EncodeUb16(
float* in,
ISACUBEncStruct* ISACenc_obj,
WebRtc_Word32 jitterInfo);
int WebRtcIsac_EncodeUb16(float* in, ISACUBEncStruct* ISACenc_obj,
WebRtc_Word32 jitterInfo);
/******************************************************************************
@ -176,117 +150,68 @@ int WebRtcIsac_EncodeUb16(
* Return value : >0 number of encoded bytes.
* <0 if an error occurred.
*/
int WebRtcIsac_EncodeUb12(
float* in,
ISACUBEncStruct* ISACenc_obj,
WebRtc_Word32 jitterInfo);
int WebRtcIsac_EncodeUb12(float* in, ISACUBEncStruct* ISACenc_obj,
WebRtc_Word32 jitterInfo);
/************************** initialization functions *************************/
void WebRtcIsac_InitMasking(MaskFiltstr *maskdata);
void WebRtcIsac_InitMasking(MaskFiltstr* maskdata);
void WebRtcIsac_InitPreFilterbank(PreFiltBankstr *prefiltdata);
void WebRtcIsac_InitPreFilterbank(PreFiltBankstr* prefiltdata);
void WebRtcIsac_InitPostFilterbank(PostFiltBankstr *postfiltdata);
void WebRtcIsac_InitPostFilterbank(PostFiltBankstr* postfiltdata);
void WebRtcIsac_InitPitchFilter(PitchFiltstr *pitchfiltdata);
void WebRtcIsac_InitPitchFilter(PitchFiltstr* pitchfiltdata);
void WebRtcIsac_InitPitchAnalysis(PitchAnalysisStruct *State);
void WebRtcIsac_InitPitchAnalysis(PitchAnalysisStruct* State);
/**************************** transform functions ****************************/
void WebRtcIsac_InitTransform();
void WebRtcIsac_Time2Spec(double *inre1,
double *inre2,
WebRtc_Word16 *outre,
WebRtc_Word16 *outim,
FFTstr *fftstr_obj);
void WebRtcIsac_Time2Spec(double* inre1, double* inre2, WebRtc_Word16* outre,
WebRtc_Word16* outim, FFTstr* fftstr_obj);
void WebRtcIsac_Spec2time(double *inre,
double *inim,
double *outre1,
double *outre2,
FFTstr *fftstr_obj);
void WebRtcIsac_Spec2time(double* inre, double* inim, double* outre1,
double* outre2, FFTstr* fftstr_obj);
/******************************* filter functions ****************************/
void WebRtcIsac_AllPoleFilter(double *InOut,
double *Coef,
int lengthInOut,
int orderCoef);
void WebRtcIsac_AllPoleFilter(double* InOut, double* Coef, int lengthInOut,
int orderCoef);
void WebRtcIsac_AllZeroFilter(double *In,
double *Coef,
int lengthInOut,
int orderCoef,
double *Out);
void WebRtcIsac_AllZeroFilter(double* In, double* Coef, int lengthInOut,
int orderCoef, double* Out);
void WebRtcIsac_ZeroPoleFilter(double *In,
double *ZeroCoef,
double *PoleCoef,
int lengthInOut,
int orderCoef,
double *Out);
void WebRtcIsac_ZeroPoleFilter(double* In, double* ZeroCoef, double* PoleCoef,
int lengthInOut, int orderCoef, double* Out);
/***************************** filterbank functions **************************/
void WebRtcIsac_SplitAndFilter(double *in,
double *LP,
double *HP,
double *LP_la,
double *HP_la,
PreFiltBankstr *prefiltdata);
void WebRtcIsac_SplitAndFilterFloat(float* in, float* LP, float* HP,
double* LP_la, double* HP_la,
PreFiltBankstr* prefiltdata);
void WebRtcIsac_FilterAndCombine(double *InLP,
double *InHP,
double *Out,
PostFiltBankstr *postfiltdata);
void WebRtcIsac_SplitAndFilterFloat(float *in,
float *LP,
float *HP,
double *LP_la,
double *HP_la,
PreFiltBankstr *prefiltdata);
void WebRtcIsac_FilterAndCombineFloat(float *InLP,
float *InHP,
float *Out,
PostFiltBankstr *postfiltdata);
void WebRtcIsac_FilterAndCombineFloat(float* InLP, float* InHP, float* Out,
PostFiltBankstr* postfiltdata);
/************************* normalized lattice filters ************************/
void WebRtcIsac_NormLatticeFilterMa(int orderCoef,
float *stateF,
float *stateG,
float *lat_in,
double *filtcoeflo,
double *lat_out);
void WebRtcIsac_NormLatticeFilterMa(int orderCoef, float* stateF, float* stateG,
float* lat_in, double* filtcoeflo,
double* lat_out);
void WebRtcIsac_NormLatticeFilterAr(int orderCoef,
float *stateF,
float *stateG,
double *lat_in,
double *lo_filt_coef,
float *lat_out);
void WebRtcIsac_NormLatticeFilterAr(int orderCoef, float* stateF, float* stateG,
double* lat_in, double* lo_filt_coef,
float* lat_out);
void WebRtcIsac_Dir2Lat(double *a,
int orderCoef,
float *sth,
float *cth);
void WebRtcIsac_Dir2Lat(double* a, int orderCoef, float* sth, float* cth);
void WebRtcIsac_AutoCorr(double *r,
const double *x,
int N,
int order);
void WebRtcIsac_AutoCorr(double* r, const double* x, int N, int order);
#endif /* WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_CODEC_H_ */

View File

@ -35,13 +35,9 @@
* function to decode the bitstream
* returns the total number of bytes in the stream
*/
int
WebRtcIsac_DecodeLb(
float* signal_out,
ISACLBDecStruct* ISACdecLB_obj,
WebRtc_Word16* current_framesamples,
WebRtc_Word16 isRCUPayload)
{
int WebRtcIsac_DecodeLb(float* signal_out, ISACLBDecStruct* ISACdecLB_obj,
WebRtc_Word16* current_framesamples,
WebRtc_Word16 isRCUPayload) {
int k;
int len, err;
WebRtc_Word16 bandwidthInd;
@ -53,8 +49,8 @@ WebRtcIsac_DecodeLb(
double HPw[FRAMESAMPLES_HALF];
double LPw_pf[FRAMESAMPLES_HALF];
double lo_filt_coef[(ORDERLO+1)*SUBFRAMES];
double hi_filt_coef[(ORDERHI+1)*SUBFRAMES];
double lo_filt_coef[(ORDERLO + 1)*SUBFRAMES];
double hi_filt_coef[(ORDERHI + 1)*SUBFRAMES];
double real_f[FRAMESAMPLES_HALF];
double imag_f[FRAMESAMPLES_HALF];
@ -68,104 +64,98 @@ WebRtcIsac_DecodeLb(
float gain;
int frame_nb; /* counter */
int frame_mode; /* 0 for 20ms and 30ms, 1 for 60ms */
int processed_samples;
int frame_mode; /* 0 30ms, 1 for 60ms */
/* Processed_samples: 480 (30, 60 ms). Cannot take other values. */
(ISACdecLB_obj->bitstr_obj).W_upper = 0xFFFFFFFF;
(ISACdecLB_obj->bitstr_obj).streamval = 0;
(ISACdecLB_obj->bitstr_obj).stream_index = 0;
WebRtcIsac_ResetBitstream(&(ISACdecLB_obj->bitstr_obj));
len = 0;
/* decode framelength and BW estimation - not used,
/* Decode framelength and BW estimation - not used,
only for stream pointer*/
err = WebRtcIsac_DecodeFrameLen(&ISACdecLB_obj->bitstr_obj,
current_framesamples);
if (err < 0) { // error check
if (err < 0) {
return err;
}
/* frame_mode: 0, or 1 */
frame_mode = *current_framesamples/MAX_FRAMESAMPLES;
/* processed_samples: either 320 (20ms) or 480 (30, 60 ms) */
processed_samples = *current_framesamples/(frame_mode+1);
/* Frame_mode:
* 0: indicates 30 ms frame (480 samples)
* 1: indicates 60 ms frame (960 samples) */
frame_mode = *current_framesamples / MAX_FRAMESAMPLES;
err = WebRtcIsac_DecodeSendBW(&ISACdecLB_obj->bitstr_obj, &bandwidthInd);
if (err < 0) { // error check
if (err < 0) {
return err;
}
/* one loop if it's one frame (20 or 30ms), 2 loops if 2 frames
bundled together (60ms) */
/* One loop if it's one frame (20 or 30ms), 2 loops if 2 frames
bundled together (60ms). */
for (frame_nb = 0; frame_nb <= frame_mode; frame_nb++) {
/* decode & dequantize pitch parameters */
err = WebRtcIsac_DecodePitchGain(&(ISACdecLB_obj->bitstr_obj),
/* Decode & de-quantize pitch parameters */
err = WebRtcIsac_DecodePitchGain(&ISACdecLB_obj->bitstr_obj,
PitchGains_Q12);
if (err < 0) { // error check
if (err < 0) {
return err;
}
err = WebRtcIsac_DecodePitchLag(&ISACdecLB_obj->bitstr_obj,
PitchGains_Q12, PitchLags);
if (err < 0) { // error check
err = WebRtcIsac_DecodePitchLag(&ISACdecLB_obj->bitstr_obj, PitchGains_Q12,
PitchLags);
if (err < 0) {
return err;
}
AvgPitchGain_Q12 = (PitchGains_Q12[0] + PitchGains_Q12[1] +
PitchGains_Q12[2] + PitchGains_Q12[3])>>2;
PitchGains_Q12[2] + PitchGains_Q12[3]) >> 2;
/* decode & dequantize FiltCoef */
err = WebRtcIsac_DecodeLpc(&ISACdecLB_obj->bitstr_obj,
lo_filt_coef,hi_filt_coef);
if (err < 0) { // error check
/* Decode & de-quantize filter coefficients. */
err = WebRtcIsac_DecodeLpc(&ISACdecLB_obj->bitstr_obj, lo_filt_coef,
hi_filt_coef);
if (err < 0) {
return err;
}
/* decode & dequantize spectrum */
len = WebRtcIsac_DecodeSpecLb(&ISACdecLB_obj->bitstr_obj,
real_f, imag_f, AvgPitchGain_Q12);
if (len < 0) { // error check
/* Decode & de-quantize spectrum. */
len = WebRtcIsac_DecodeSpec(&ISACdecLB_obj->bitstr_obj, AvgPitchGain_Q12,
kIsacLowerBand, real_f, imag_f);
if (len < 0) {
return len;
}
/* inverse transform */
/* Inverse transform. */
WebRtcIsac_Spec2time(real_f, imag_f, LPw, HPw,
&ISACdecLB_obj->fftstr_obj);
&ISACdecLB_obj->fftstr_obj);
/* convert PitchGains back to FLOAT for pitchfilter_post */
/* Convert PitchGains back to float for pitchfilter_post */
for (k = 0; k < 4; k++) {
PitchGains[k] = ((float)PitchGains_Q12[k])/4096;
PitchGains[k] = ((float)PitchGains_Q12[k]) / 4096;
}
if(isRCUPayload)
{
if (isRCUPayload) {
for (k = 0; k < 240; k++) {
LPw[k] *= RCU_TRANSCODING_SCALE_INVERSE;
HPw[k] *= RCU_TRANSCODING_SCALE_INVERSE;
}
}
/* inverse pitch filter */
WebRtcIsac_PitchfilterPost(LPw, LPw_pf,
&ISACdecLB_obj->pitchfiltstr_obj, PitchLags, PitchGains);
/* convert AvgPitchGain back to FLOAT for computation of gain */
AvgPitchGain = ((float)AvgPitchGain_Q12)/4096;
/* Inverse pitch filter. */
WebRtcIsac_PitchfilterPost(LPw, LPw_pf, &ISACdecLB_obj->pitchfiltstr_obj,
PitchLags, PitchGains);
/* Convert AvgPitchGain back to float for computation of gain. */
AvgPitchGain = ((float)AvgPitchGain_Q12) / 4096;
gain = 1.0f - 0.45f * (float)AvgPitchGain;
for (k = 0; k < FRAMESAMPLES_HALF; k++) {
/* reduce gain to compensate for pitch enhancer */
LPw_pf[ k ] *= gain;
/* Reduce gain to compensate for pitch enhancer. */
LPw_pf[k] *= gain;
}
if(isRCUPayload)
{
if (isRCUPayload) {
for (k = 0; k < FRAMESAMPLES_HALF; k++) {
/* compensation for transcoding gain changes*/
/* Compensation for transcoding gain changes. */
LPw_pf[k] *= RCU_TRANSCODING_SCALE;
HPw[k] *= RCU_TRANSCODING_SCALE;
HPw[k] *= RCU_TRANSCODING_SCALE;
}
}
/* perceptual post-filtering (using normalized lattice filter) */
/* Perceptual post-filtering (using normalized lattice filter). */
WebRtcIsac_NormLatticeFilterAr(
ORDERLO, ISACdecLB_obj->maskfiltstr_obj.PostStateLoF,
(ISACdecLB_obj->maskfiltstr_obj).PostStateLoG, LPw_pf, lo_filt_coef,
@ -175,12 +165,11 @@ WebRtcIsac_DecodeLb(
(ISACdecLB_obj->maskfiltstr_obj).PostStateHiG, HPw, hi_filt_coef,
HP_dec_float);
/* recombine the 2 bands */
/* Recombine the 2 bands. */
WebRtcIsac_FilterAndCombineFloat(LP_dec_float, HP_dec_float,
signal_out + frame_nb * processed_samples,
signal_out + frame_nb * FRAMESAMPLES,
&ISACdecLB_obj->postfiltbankstr_obj);
}
return len;
}
@ -192,63 +181,56 @@ WebRtcIsac_DecodeLb(
* Contrary to lower-band, the upper-band (8-16 kHz) is not split in
* frequency, but split to 12 sub-frames, i.e. twice as lower-band.
*/
int
WebRtcIsac_DecodeUb16(
float* signal_out,
ISACUBDecStruct* ISACdecUB_obj,
WebRtc_Word16 isRCUPayload)
{
int WebRtcIsac_DecodeUb16(float* signal_out, ISACUBDecStruct* ISACdecUB_obj,
WebRtc_Word16 isRCUPayload) {
int len, err;
double halfFrameFirst[FRAMESAMPLES_HALF];
double halfFrameSecond[FRAMESAMPLES_HALF];
double percepFilterParam[(UB_LPC_ORDER+1) * (SUBFRAMES<<1) +
(UB_LPC_ORDER+1)];
double percepFilterParam[(UB_LPC_ORDER + 1) * (SUBFRAMES << 1) +
(UB_LPC_ORDER + 1)];
double real_f[FRAMESAMPLES_HALF];
double imag_f[FRAMESAMPLES_HALF];
const WebRtc_Word16 kAveragePitchGain = 0; /* No pitch-gain for upper-band. */
len = 0;
/* decode & dequantize FiltCoef */
/* Decode & de-quantize filter coefficients. */
memset(percepFilterParam, 0, sizeof(percepFilterParam));
err = WebRtcIsac_DecodeInterpolLpcUb(&ISACdecUB_obj->bitstr_obj,
percepFilterParam, isac16kHz);
if (err < 0) { // error check
if (err < 0) {
return err;
}
/* decode & dequantize spectrum */
len = WebRtcIsac_DecodeSpecUB16(&ISACdecUB_obj->bitstr_obj, real_f,
imag_f);
if (len < 0) { // error check
/* Decode & de-quantize spectrum. */
len = WebRtcIsac_DecodeSpec(&ISACdecUB_obj->bitstr_obj, kAveragePitchGain,
kIsacUpperBand16, real_f, imag_f);
if (len < 0) {
return len;
}
if(isRCUPayload)
{
if (isRCUPayload) {
int n;
for(n = 0; n < 240; n++)
{
for (n = 0; n < 240; n++) {
real_f[n] *= RCU_TRANSCODING_SCALE_UB_INVERSE;
imag_f[n] *= RCU_TRANSCODING_SCALE_UB_INVERSE;
}
}
/* inverse transform */
/* Inverse transform. */
WebRtcIsac_Spec2time(real_f, imag_f, halfFrameFirst, halfFrameSecond,
&ISACdecUB_obj->fftstr_obj);
&ISACdecUB_obj->fftstr_obj);
/* perceptual post-filtering (using normalized lattice filter) */
/* Perceptual post-filtering (using normalized lattice filter). */
WebRtcIsac_NormLatticeFilterAr(
UB_LPC_ORDER, ISACdecUB_obj->maskfiltstr_obj.PostStateLoF,
(ISACdecUB_obj->maskfiltstr_obj).PostStateLoG, halfFrameFirst,
&percepFilterParam[(UB_LPC_ORDER+1)], signal_out);
&percepFilterParam[(UB_LPC_ORDER + 1)], signal_out);
WebRtcIsac_NormLatticeFilterAr(
UB_LPC_ORDER, ISACdecUB_obj->maskfiltstr_obj.PostStateLoF,
(ISACdecUB_obj->maskfiltstr_obj).PostStateLoG, halfFrameSecond,
&percepFilterParam[(UB_LPC_ORDER + 1) * SUBFRAMES + (UB_LPC_ORDER+1)],
&percepFilterParam[(UB_LPC_ORDER + 1) * SUBFRAMES + (UB_LPC_ORDER + 1)],
&signal_out[FRAMESAMPLES_HALF]);
return len;
@ -263,12 +245,8 @@ WebRtcIsac_DecodeUb16(
* reconstructed and 12-16 kHz replaced with zeros. Then two bands
* are combined, to reconstruct the upperband 8-16 kHz.
*/
int
WebRtcIsac_DecodeUb12(
float* signal_out,
ISACUBDecStruct* ISACdecUB_obj,
WebRtc_Word16 isRCUPayload)
{
int WebRtcIsac_DecodeUb12(float* signal_out, ISACUBDecStruct* ISACdecUB_obj,
WebRtc_Word16 isRCUPayload) {
int len, err;
float LP_dec_float[FRAMESAMPLES_HALF];
@ -277,54 +255,45 @@ WebRtcIsac_DecodeUb12(
double LPw[FRAMESAMPLES_HALF];
double HPw[FRAMESAMPLES_HALF];
double percepFilterParam[(UB_LPC_ORDER+1)*SUBFRAMES];
double percepFilterParam[(UB_LPC_ORDER + 1)*SUBFRAMES];
double real_f[FRAMESAMPLES_HALF];
double imag_f[FRAMESAMPLES_HALF];
const WebRtc_Word16 kAveragePitchGain = 0; /* No pitch-gain for upper-band. */
len = 0;
/* decode & dequantize FiltCoef */
/* Decode & dequantize filter coefficients. */
err = WebRtcIsac_DecodeInterpolLpcUb(&ISACdecUB_obj->bitstr_obj,
percepFilterParam, isac12kHz);
if(err < 0) { // error check
if (err < 0) {
return err;
}
/* decode & dequantize spectrum */
len = WebRtcIsac_DecodeSpecUB12(&ISACdecUB_obj->bitstr_obj,
real_f, imag_f);
if(len < 0) { // error check
/* Decode & de-quantize spectrum. */
len = WebRtcIsac_DecodeSpec(&ISACdecUB_obj->bitstr_obj, kAveragePitchGain,
kIsacUpperBand12, real_f, imag_f);
if (len < 0) {
return len;
}
if(isRCUPayload)
{
if (isRCUPayload) {
int n;
for(n = 0; n < 240; n++)
{
for (n = 0; n < 240; n++) {
real_f[n] *= RCU_TRANSCODING_SCALE_UB_INVERSE;
imag_f[n] *= RCU_TRANSCODING_SCALE_UB_INVERSE;
}
}
/* inverse transform */
/* Inverse transform. */
WebRtcIsac_Spec2time(real_f, imag_f, LPw, HPw, &ISACdecUB_obj->fftstr_obj);
/* perceptual post-filtering (using normalized lattice filter) */
WebRtcIsac_NormLatticeFilterAr(UB_LPC_ORDER,
ISACdecUB_obj->maskfiltstr_obj.PostStateLoF,
(ISACdecUB_obj->maskfiltstr_obj).PostStateLoG,
LPw, percepFilterParam, LP_dec_float);
/* Zerro for upper-band */
/* Zero for 12-16 kHz. */
memset(HP_dec_float, 0, sizeof(float) * (FRAMESAMPLES_HALF));
/* recombine the 2 bands */
/* Recombine the 2 bands. */
WebRtcIsac_FilterAndCombineFloat(HP_dec_float, LP_dec_float, signal_out,
&ISACdecUB_obj->postfiltbankstr_obj);
return len;
}

File diff suppressed because it is too large Load Diff

View File

@ -19,18 +19,12 @@
#ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_ENTROPY_CODING_H_
#define WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_ENTROPY_CODING_H_
#include "settings.h"
#include "structs.h"
/* decode complex spectrum (return number of bytes in stream) */
int WebRtcIsac_DecodeSpecLb(Bitstr *streamdata,
double *fr,
double *fi,
WebRtc_Word16 AvgPitchGain_Q12);
/******************************************************************************
* WebRtcIsac_DecodeSpecUB16()
* WebRtcIsac_DecodeSpec()
* Decode real and imaginary part of the DFT coefficients, given a bit-stream.
* This function is called when the codec is in 0-16 kHz bandwidth.
* The decoded DFT coefficient can be transformed to time domain by
* WebRtcIsac_Time2Spec().
*
@ -38,68 +32,37 @@ int WebRtcIsac_DecodeSpecLb(Bitstr *streamdata,
* - streamdata : pointer to a stucture containg the encoded
* data and theparameters needed for entropy
* coding.
* - AvgPitchGain_Q12 : average pitch-gain of the frame. This is only
* relevant for 0-4 kHz band, and the input value is
* not used in other bands.
* - band : specifies which band's DFT should be decoded.
*
* Output:
* -*fr : pointer to a buffer where the real part of DFT
* - *fr : pointer to a buffer where the real part of DFT
* coefficients are written to.
* -*fi : pointer to a buffer where the imaginary part
* - *fi : pointer to a buffer where the imaginary part
* of DFT coefficients are written to.
*
* Return value : < 0 if an error occures
* 0 if succeeded.
*/
int WebRtcIsac_DecodeSpecUB16(
Bitstr* streamdata,
double* fr,
double* fi);
int WebRtcIsac_DecodeSpec(Bitstr* streamdata, WebRtc_Word16 AvgPitchGain_Q12,
enum ISACBand band, double* fr, double* fi);
/******************************************************************************
* WebRtcIsac_DecodeSpecUB12()
* Decode real and imaginary part of the DFT coefficients, given a bit-stream.
* This function is called when the codec is in 0-12 kHz bandwidth.
* The decoded DFT coefficient can be transformed to time domain by
* WebRtcIsac_Time2Spec().
* WebRtcIsac_EncodeSpec()
* Encode real and imaginary part of the DFT coefficients into the given
* bit-stream.
*
* Input:
* - streamdata : pointer to a stucture containg the encoded
* data and theparameters needed for entropy
* coding.
*
* Output:
* -*fr : pointer to a buffer where the real part of DFT
* - *fr : pointer to a buffer where the real part of DFT
* coefficients are written to.
* -*fi : pointer to a buffer where the imaginary part
* - *fi : pointer to a buffer where the imaginary part
* of DFT coefficients are written to.
*
* Return value : < 0 if an error occures
* 0 if succeeded.
*/
int WebRtcIsac_DecodeSpecUB12(
Bitstr* streamdata,
double* fr,
double* fi);
/* encode complex spectrum */
int WebRtcIsac_EncodeSpecLb(const WebRtc_Word16* fr,
const WebRtc_Word16* fi,
Bitstr* streamdata,
WebRtc_Word16 AvgPitchGain_Q12);
/******************************************************************************
* WebRtcIsac_EncodeSpecUB16()
* Quantize and encode real and imaginary part of the DFT coefficients.
* This function is called when the codec is in 0-16 kHz bandwidth.
* The real and imaginary part are computed by calling WebRtcIsac_Time2Spec().
*
*
* Input:
* -*fr : pointer to a buffer where the real part of DFT
* coefficients are stored.
* -*fi : pointer to a buffer where the imaginary part
* of DFT coefficients are stored.
* - AvgPitchGain_Q12 : average pitch-gain of the frame. This is only
* relevant for 0-4 kHz band, and the input value is
* not used in other bands.
* - band : specifies which band's DFT should be decoded.
*
* Output:
* - streamdata : pointer to a stucture containg the encoded
@ -109,55 +72,25 @@ int WebRtcIsac_EncodeSpecLb(const WebRtc_Word16* fr,
* Return value : < 0 if an error occures
* 0 if succeeded.
*/
int WebRtcIsac_EncodeSpecUB16(
const WebRtc_Word16* fr,
const WebRtc_Word16* fi,
Bitstr* streamdata);
/******************************************************************************
* WebRtcIsac_EncodeSpecUB12()
* Quantize and encode real and imaginary part of the DFT coefficients.
* This function is called when the codec is in 0-12 kHz bandwidth.
* The real and imaginary part are computed by calling WebRtcIsac_Time2Spec().
*
*
* Input:
* -*fr : pointer to a buffer where the real part of DFT
* coefficients are stored.
* -*fi : pointer to a buffer where the imaginary part
* of DFT coefficients are stored.
*
* Output:
* - streamdata : pointer to a stucture containg the encoded
* data and theparameters needed for entropy
* coding.
*
* Return value : < 0 if an error occures
* 0 if succeeded.
*/
int WebRtcIsac_EncodeSpecUB12(
const WebRtc_Word16* fr,
const WebRtc_Word16* fi,
Bitstr* streamdata);
int WebRtcIsac_EncodeSpec(const WebRtc_Word16* fr, const WebRtc_Word16* fi,
WebRtc_Word16 AvgPitchGain_Q12, enum ISACBand band,
Bitstr* streamdata);
/* decode & dequantize LPC Coef */
int WebRtcIsac_DecodeLpcCoef(Bitstr *streamdata, double *LPCCoef);
int WebRtcIsac_DecodeLpcCoefUB(
Bitstr* streamdata,
double* lpcVecs,
double* percepFilterGains,
WebRtc_Word16 bandwidth);
int WebRtcIsac_DecodeLpcCoef(Bitstr* streamdata, double* LPCCoef);
int WebRtcIsac_DecodeLpcCoefUB(Bitstr* streamdata, double* lpcVecs,
double* percepFilterGains,
WebRtc_Word16 bandwidth);
int WebRtcIsac_DecodeLpc(Bitstr *streamdata, double *LPCCoef_lo,
double *LPCCoef_hi);
int WebRtcIsac_DecodeLpc(Bitstr* streamdata, double* LPCCoef_lo,
double* LPCCoef_hi);
/* quantize & code LPC Coef */
void WebRtcIsac_EncodeLpcLb(double *LPCCoef_lo, double *LPCCoef_hi,
Bitstr *streamdata, ISAC_SaveEncData_t* encData);
void WebRtcIsac_EncodeLpcGainLb(double *LPCCoef_lo, double *LPCCoef_hi,
Bitstr *streamdata,
void WebRtcIsac_EncodeLpcLb(double* LPCCoef_lo, double* LPCCoef_hi,
Bitstr* streamdata, ISAC_SaveEncData_t* encData);
void WebRtcIsac_EncodeLpcGainLb(double* LPCCoef_lo, double* LPCCoef_hi,
Bitstr* streamdata,
ISAC_SaveEncData_t* encData);
/******************************************************************************
@ -175,8 +108,8 @@ void WebRtcIsac_EncodeLpcGainLb(double *LPCCoef_lo, double *LPCCoef_hi,
* or 0-16 kHz mode.
*
* Input/output:
* - streamdata : pointer to a stucture containg the encoded
* data and theparameters needed for entropy
* - streamdata : pointer to a structure containing the encoded
* data and the parameters needed for entropy
* coding.
*
* Output:
@ -193,12 +126,10 @@ void WebRtcIsac_EncodeLpcGainLb(double *LPCCoef_lo, double *LPCCoef_hi,
* Return value : 0 if encoding is successful,
* <0 if failed to encode.
*/
WebRtc_Word16 WebRtcIsac_EncodeLpcUB(
double* lpcCoeff,
Bitstr* streamdata,
double* interpolLPCCoeff,
WebRtc_Word16 bandwidth,
ISACUBSaveEncDataStruct* encData);
WebRtc_Word16 WebRtcIsac_EncodeLpcUB(double* lpcCoeff, Bitstr* streamdata,
double* interpolLPCCoeff,
WebRtc_Word16 bandwidth,
ISACUBSaveEncDataStruct* encData);
/******************************************************************************
* WebRtcIsac_DecodeInterpolLpcUb()
@ -228,22 +159,21 @@ WebRtc_Word16 WebRtcIsac_EncodeLpcUB(
* Return value : 0 if encoding is successful,
* <0 if failed to encode.
*/
WebRtc_Word16 WebRtcIsac_DecodeInterpolLpcUb(
Bitstr* streamdata,
double* percepFilterParam,
WebRtc_Word16 bandwidth);
WebRtc_Word16 WebRtcIsac_DecodeInterpolLpcUb(Bitstr* streamdata,
double* percepFilterParam,
WebRtc_Word16 bandwidth);
/* decode & dequantize RC */
int WebRtcIsac_DecodeRc(Bitstr *streamdata, WebRtc_Word16 *RCQ15);
/* Decode & dequantize RC */
int WebRtcIsac_DecodeRc(Bitstr* streamdata, WebRtc_Word16* RCQ15);
/* quantize & code RC */
void WebRtcIsac_EncodeRc(WebRtc_Word16 *RCQ15, Bitstr *streamdata);
/* Quantize & code RC */
void WebRtcIsac_EncodeRc(WebRtc_Word16* RCQ15, Bitstr* streamdata);
/* decode & dequantize squared Gain */
int WebRtcIsac_DecodeGain2(Bitstr *streamdata, WebRtc_Word32 *Gain2);
/* Decode & dequantize squared Gain */
int WebRtcIsac_DecodeGain2(Bitstr* streamdata, WebRtc_Word32* Gain2);
/* quantize & code squared Gain (input is squared gain) */
int WebRtcIsac_EncodeGain2(WebRtc_Word32 *gain2, Bitstr *streamdata);
/* Quantize & code squared Gain (input is squared gain) */
int WebRtcIsac_EncodeGain2(WebRtc_Word32* gain2, Bitstr* streamdata);
void WebRtcIsac_EncodePitchGain(WebRtc_Word16* PitchGains_Q12,
Bitstr* streamdata,
@ -252,24 +182,24 @@ void WebRtcIsac_EncodePitchGain(WebRtc_Word16* PitchGains_Q12,
void WebRtcIsac_EncodePitchLag(double* PitchLags, WebRtc_Word16* PitchGain_Q12,
Bitstr* streamdata, ISAC_SaveEncData_t* encData);
int WebRtcIsac_DecodePitchGain(Bitstr *streamdata,
WebRtc_Word16 *PitchGain_Q12);
int WebRtcIsac_DecodePitchLag(Bitstr *streamdata, WebRtc_Word16 *PitchGain_Q12,
double *PitchLag);
int WebRtcIsac_DecodePitchGain(Bitstr* streamdata,
WebRtc_Word16* PitchGain_Q12);
int WebRtcIsac_DecodePitchLag(Bitstr* streamdata, WebRtc_Word16* PitchGain_Q12,
double* PitchLag);
int WebRtcIsac_DecodeFrameLen(Bitstr *streamdata, WebRtc_Word16 *framelength);
int WebRtcIsac_EncodeFrameLen(WebRtc_Word16 framelength, Bitstr *streamdata);
int WebRtcIsac_DecodeSendBW(Bitstr *streamdata, WebRtc_Word16 *BWno);
void WebRtcIsac_EncodeReceiveBw(int *BWno, Bitstr *streamdata);
int WebRtcIsac_DecodeFrameLen(Bitstr* streamdata, WebRtc_Word16* framelength);
int WebRtcIsac_EncodeFrameLen(WebRtc_Word16 framelength, Bitstr* streamdata);
int WebRtcIsac_DecodeSendBW(Bitstr* streamdata, WebRtc_Word16* BWno);
void WebRtcIsac_EncodeReceiveBw(int* BWno, Bitstr* streamdata);
/* step-down */
void WebRtcIsac_Poly2Rc(double *a, int N, double *RC);
/* Step-down */
void WebRtcIsac_Poly2Rc(double* a, int N, double* RC);
/* step-up */
void WebRtcIsac_Rc2Poly(double *RC, int N, double *a);
/* Step-up */
void WebRtcIsac_Rc2Poly(double* RC, int N, double* a);
void WebRtcIsac_TranscodeLPCCoef(double *LPCCoef_lo, double *LPCCoef_hi,
int *index_g);
void WebRtcIsac_TranscodeLPCCoef(double* LPCCoef_lo, double* LPCCoef_hi,
int* index_g);
/******************************************************************************
@ -288,10 +218,8 @@ void WebRtcIsac_TranscodeLPCCoef(double *LPCCoef_lo, double *LPCCoef_hi,
* - lpcGainIndex : quantization indices for lpc gains, these will
* be stored to be used for FEC.
*/
void WebRtcIsac_EncodeLpcGainUb(
double* lpGains,
Bitstr* streamdata,
int* lpcGainIndex);
void WebRtcIsac_EncodeLpcGainUb(double* lpGains, Bitstr* streamdata,
int* lpcGainIndex);
/******************************************************************************
@ -307,9 +235,7 @@ void WebRtcIsac_EncodeLpcGainUb(
* coding.
*
*/
void WebRtcIsac_StoreLpcGainUb(
double* lpGains,
Bitstr* streamdata);
void WebRtcIsac_StoreLpcGainUb(double* lpGains, Bitstr* streamdata);
/******************************************************************************
@ -327,9 +253,7 @@ void WebRtcIsac_StoreLpcGainUb(
* Return value : 0 if succeeded.
* <0 if failed.
*/
WebRtc_Word16 WebRtcIsac_DecodeLpcGainUb(
double* lpGains,
Bitstr* streamdata);
WebRtc_Word16 WebRtcIsac_DecodeLpcGainUb(double* lpGains, Bitstr* streamdata);
/******************************************************************************
@ -348,9 +272,8 @@ WebRtc_Word16 WebRtcIsac_DecodeLpcGainUb(
* Return value : 0 if succeeded.
* <0 if failed.
*/
WebRtc_Word16 WebRtcIsac_EncodeBandwidth(
enum ISACBandwidth bandwidth,
Bitstr* streamData);
WebRtc_Word16 WebRtcIsac_EncodeBandwidth(enum ISACBandwidth bandwidth,
Bitstr* streamData);
/******************************************************************************
@ -370,9 +293,8 @@ WebRtc_Word16 WebRtcIsac_EncodeBandwidth(
* Return value : 0 if succeeded.
* <0 if failed.
*/
WebRtc_Word16 WebRtcIsac_DecodeBandwidth(
Bitstr* streamData,
enum ISACBandwidth* bandwidth);
WebRtc_Word16 WebRtcIsac_DecodeBandwidth(Bitstr* streamData,
enum ISACBandwidth* bandwidth);
/******************************************************************************
@ -392,9 +314,8 @@ WebRtc_Word16 WebRtcIsac_DecodeBandwidth(
* Return value : 0 if succeeded.
* <0 if failed.
*/
WebRtc_Word16 WebRtcIsac_EncodeJitterInfo(
WebRtc_Word32 jitterIndex,
Bitstr* streamData);
WebRtc_Word16 WebRtcIsac_EncodeJitterInfo(WebRtc_Word32 jitterIndex,
Bitstr* streamData);
/******************************************************************************
@ -414,8 +335,7 @@ WebRtc_Word16 WebRtcIsac_EncodeJitterInfo(
* Return value : 0 if succeeded.
* <0 if failed.
*/
WebRtc_Word16 WebRtcIsac_DecodeJitterInfo(
Bitstr* streamData,
WebRtc_Word32* jitterInfo);
WebRtc_Word16 WebRtcIsac_DecodeJitterInfo(Bitstr* streamData,
WebRtc_Word32* jitterInfo);
#endif /* WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_ENTROPY_CODING_H_ */

File diff suppressed because it is too large Load Diff

View File

@ -81,7 +81,7 @@
#define UB16_INTERPOL_SEGMENTS 3
#define LB_TOTAL_DELAY_SAMPLES 48
enum ISACBandwidth {isac8kHz = 8, isac12kHz = 12, isac16kHz = 16};
enum ISACBand{isacLowerBand = 0, isacUpperBand = 1};
enum ISACBand {kIsacLowerBand = 0, kIsacUpperBand12 = 1, kIsacUpperBand16 = 2};
#define UB_LPC_GAIN_DIM SUBFRAMES
#define FB_STATE_SIZE_WORD32 6