2011-07-07 08:21:25 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2011 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
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* decode.c
|
|
|
|
|
*
|
|
|
|
|
* This C file contains the internal decoding function.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
2018-02-01 14:12:55 +01:00
|
|
|
#include "modules/audio_coding/codecs/isac/fix/source/bandwidth_estimator.h"
|
|
|
|
|
#include "modules/audio_coding/codecs/isac/fix/source/codec.h"
|
|
|
|
|
#include "modules/audio_coding/codecs/isac/fix/source/entropy_coding.h"
|
|
|
|
|
#include "modules/audio_coding/codecs/isac/fix/source/pitch_estimator.h"
|
|
|
|
|
#include "modules/audio_coding/codecs/isac/fix/source/settings.h"
|
|
|
|
|
#include "modules/audio_coding/codecs/isac/fix/source/structs.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-07-22 15:17:22 -07:00
|
|
|
int WebRtcIsacfix_DecodeImpl(int16_t* signal_out16,
|
|
|
|
|
IsacFixDecoderInstance* ISACdec_obj,
|
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* current_framesamples)
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
|
|
|
|
int k;
|
|
|
|
|
int err;
|
2013-04-09 00:28:06 +00:00
|
|
|
int16_t BWno;
|
Reland "Upconvert various types to int.", isac portion.
This reverts portions of commit cb180976dd0e9672cde4523d87b5f4857478b5e9, which
reverted commit 83ad33a8aed1fb00e422b6abd33c3e8942821c24. Specifically, the
files in webrtc/modules/audio_coding/codecs/isac/ 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/1179093002
Cr-Commit-Position: refs/heads/master@{#9422}
2015-06-11 18:19:24 -07:00
|
|
|
int len = 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-04-09 00:28:06 +00:00
|
|
|
int16_t model;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
|
2013-04-09 00:28:06 +00:00
|
|
|
int16_t Vector_Word16_1[FRAMESAMPLES/2];
|
|
|
|
|
int16_t Vector_Word16_2[FRAMESAMPLES/2];
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-04-09 00:28:06 +00:00
|
|
|
int32_t Vector_Word32_1[FRAMESAMPLES/2];
|
|
|
|
|
int32_t Vector_Word32_2[FRAMESAMPLES/2];
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-04-09 00:28:06 +00:00
|
|
|
int16_t lofilt_coefQ15[ORDERLO*SUBFRAMES]; //refl. coeffs
|
|
|
|
|
int16_t hifilt_coefQ15[ORDERHI*SUBFRAMES]; //refl. coeffs
|
|
|
|
|
int32_t gain_lo_hiQ17[2*SUBFRAMES];
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-04-09 00:28:06 +00:00
|
|
|
int16_t PitchLags_Q7[PITCH_SUBFRAMES];
|
|
|
|
|
int16_t PitchGains_Q12[PITCH_SUBFRAMES];
|
|
|
|
|
int16_t AvgPitchGain_Q12;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-04-09 00:28:06 +00:00
|
|
|
int16_t tmp_1, tmp_2;
|
2014-10-28 13:05:43 +00:00
|
|
|
int32_t tmp32a;
|
2013-04-09 00:28:06 +00:00
|
|
|
int16_t gainQ13;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
|
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 frame_nb; /* counter */
|
|
|
|
|
size_t frame_mode; /* 0 for 30ms, 1 for 60ms */
|
|
|
|
|
static const size_t kProcessedSamples = 480; /* 480 (for both 30, 60 ms) */
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
/* PLC */
|
2013-04-09 00:28:06 +00:00
|
|
|
int16_t overlapWin[ 240 ];
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
(ISACdec_obj->bitstr_obj).W_upper = 0xFFFFFFFF;
|
|
|
|
|
(ISACdec_obj->bitstr_obj).streamval = 0;
|
|
|
|
|
(ISACdec_obj->bitstr_obj).stream_index = 0;
|
|
|
|
|
(ISACdec_obj->bitstr_obj).full = 1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* decode framelength and BW estimation - not used, only for stream pointer*/
|
|
|
|
|
err = WebRtcIsacfix_DecodeFrameLen(&ISACdec_obj->bitstr_obj, current_framesamples);
|
|
|
|
|
if (err<0) // error check
|
|
|
|
|
return err;
|
|
|
|
|
|
2014-08-28 12:57:32 +00:00
|
|
|
frame_mode = *current_framesamples / MAX_FRAMESAMPLES; /* 0, or 1 */
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
err = WebRtcIsacfix_DecodeSendBandwidth(&ISACdec_obj->bitstr_obj, &BWno);
|
|
|
|
|
if (err<0) // error check
|
|
|
|
|
return err;
|
|
|
|
|
|
2014-08-28 12:57:32 +00:00
|
|
|
/* one loop if it's one frame (30ms), two loops if two frames bundled together
|
|
|
|
|
* (60ms) */
|
2011-07-07 08:21:25 +00:00
|
|
|
for (frame_nb = 0; frame_nb <= frame_mode; frame_nb++) {
|
|
|
|
|
|
|
|
|
|
/* decode & dequantize pitch parameters */
|
|
|
|
|
err = WebRtcIsacfix_DecodePitchGain(&(ISACdec_obj->bitstr_obj), PitchGains_Q12);
|
|
|
|
|
if (err<0) // error check
|
|
|
|
|
return err;
|
|
|
|
|
|
|
|
|
|
err = WebRtcIsacfix_DecodePitchLag(&ISACdec_obj->bitstr_obj, PitchGains_Q12, PitchLags_Q7);
|
|
|
|
|
if (err<0) // error check
|
|
|
|
|
return err;
|
|
|
|
|
|
2013-04-09 00:28:06 +00:00
|
|
|
AvgPitchGain_Q12 = (int16_t)(((int32_t)PitchGains_Q12[0] + PitchGains_Q12[1] + PitchGains_Q12[2] + PitchGains_Q12[3])>>2);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
/* decode & dequantize FiltCoef */
|
|
|
|
|
err = WebRtcIsacfix_DecodeLpc(gain_lo_hiQ17, lofilt_coefQ15, hifilt_coefQ15,
|
|
|
|
|
&ISACdec_obj->bitstr_obj, &model);
|
|
|
|
|
|
|
|
|
|
if (err<0) // error check
|
|
|
|
|
return err;
|
|
|
|
|
|
|
|
|
|
/* decode & dequantize spectrum */
|
|
|
|
|
len = WebRtcIsacfix_DecodeSpec(&ISACdec_obj->bitstr_obj, Vector_Word16_1, Vector_Word16_2, AvgPitchGain_Q12);
|
|
|
|
|
if (len < 0) // error check
|
|
|
|
|
return len;
|
|
|
|
|
|
|
|
|
|
// Why does this need Q16 in and out? /JS
|
|
|
|
|
WebRtcIsacfix_Spec2Time(Vector_Word16_1, Vector_Word16_2, Vector_Word32_1, Vector_Word32_2);
|
|
|
|
|
|
|
|
|
|
for (k=0; k<FRAMESAMPLES/2; k++) {
|
2014-10-28 13:05:43 +00:00
|
|
|
// Q16 -> Q9.
|
|
|
|
|
Vector_Word16_1[k] = (int16_t)((Vector_Word32_1[k] + 64) >> 7);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ---- If this is recovery frame ---- */
|
|
|
|
|
if( (ISACdec_obj->plcstr_obj).used == PLC_WAS_USED )
|
|
|
|
|
{
|
|
|
|
|
(ISACdec_obj->plcstr_obj).used = PLC_NOT_USED;
|
|
|
|
|
if( (ISACdec_obj->plcstr_obj).B < 1000 )
|
|
|
|
|
{
|
|
|
|
|
(ISACdec_obj->plcstr_obj).decayCoeffPriodic = 4000;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ISACdec_obj->plcstr_obj.decayCoeffPriodic = WEBRTC_SPL_WORD16_MAX; /* DECAY_RATE is in Q15 */
|
|
|
|
|
ISACdec_obj->plcstr_obj.decayCoeffNoise = WEBRTC_SPL_WORD16_MAX; /* DECAY_RATE is in Q15 */
|
|
|
|
|
ISACdec_obj->plcstr_obj.pitchCycles = 0;
|
|
|
|
|
|
2015-04-10 08:06:45 +02:00
|
|
|
PitchGains_Q12[0] = (int16_t)(PitchGains_Q12[0] * 700 >> 10);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
/* ---- Add-overlap ---- */
|
|
|
|
|
WebRtcSpl_GetHanningWindow( overlapWin, RECOVERY_OVERLAP );
|
|
|
|
|
for( k = 0; k < RECOVERY_OVERLAP; k++ )
|
2014-08-25 07:44:52 +00:00
|
|
|
Vector_Word16_1[k] = WebRtcSpl_AddSatW16(
|
2015-04-10 08:06:45 +02:00
|
|
|
(int16_t)(ISACdec_obj->plcstr_obj.overlapLP[k] *
|
|
|
|
|
overlapWin[RECOVERY_OVERLAP - k - 1] >> 14),
|
|
|
|
|
(int16_t)(Vector_Word16_1[k] * overlapWin[k] >> 14));
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* --- Store side info --- */
|
|
|
|
|
if( frame_nb == frame_mode )
|
|
|
|
|
{
|
|
|
|
|
/* --- LPC info */
|
|
|
|
|
WEBRTC_SPL_MEMCPY_W16( (ISACdec_obj->plcstr_obj).lofilt_coefQ15, &lofilt_coefQ15[(SUBFRAMES-1)*ORDERLO], ORDERLO );
|
|
|
|
|
WEBRTC_SPL_MEMCPY_W16( (ISACdec_obj->plcstr_obj).hifilt_coefQ15, &hifilt_coefQ15[(SUBFRAMES-1)*ORDERHI], ORDERHI );
|
|
|
|
|
(ISACdec_obj->plcstr_obj).gain_lo_hiQ17[0] = gain_lo_hiQ17[(SUBFRAMES-1) * 2];
|
|
|
|
|
(ISACdec_obj->plcstr_obj).gain_lo_hiQ17[1] = gain_lo_hiQ17[(SUBFRAMES-1) * 2 + 1];
|
|
|
|
|
|
|
|
|
|
/* --- LTP info */
|
|
|
|
|
(ISACdec_obj->plcstr_obj).AvgPitchGain_Q12 = PitchGains_Q12[3];
|
|
|
|
|
(ISACdec_obj->plcstr_obj).lastPitchGain_Q12 = PitchGains_Q12[3];
|
|
|
|
|
(ISACdec_obj->plcstr_obj).lastPitchLag_Q7 = PitchLags_Q7[3];
|
|
|
|
|
|
|
|
|
|
if( PitchLags_Q7[3] < 3000 )
|
|
|
|
|
(ISACdec_obj->plcstr_obj).lastPitchLag_Q7 += PitchLags_Q7[3];
|
|
|
|
|
|
|
|
|
|
WEBRTC_SPL_MEMCPY_W16( (ISACdec_obj->plcstr_obj).prevPitchInvIn, Vector_Word16_1, FRAMESAMPLES/2 );
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
|
|
|
|
|
|
|
|
|
|
/* inverse pitch filter */
|
|
|
|
|
WebRtcIsacfix_PitchFilter(Vector_Word16_1, Vector_Word16_2, &ISACdec_obj->pitchfiltstr_obj, PitchLags_Q7, PitchGains_Q12, 4);
|
|
|
|
|
|
|
|
|
|
if( frame_nb == frame_mode )
|
|
|
|
|
{
|
|
|
|
|
WEBRTC_SPL_MEMCPY_W16( (ISACdec_obj->plcstr_obj).prevPitchInvOut, &(Vector_Word16_2[FRAMESAMPLES/2 - (PITCH_MAX_LAG + 10)]), PITCH_MAX_LAG );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* reduce gain to compensate for pitch enhancer */
|
|
|
|
|
/* gain = 1.0f - 0.45f * AvgPitchGain; */
|
2015-04-10 08:06:45 +02:00
|
|
|
tmp32a = AvgPitchGain_Q12 * 29; // Q18
|
2014-10-28 13:05:43 +00:00
|
|
|
gainQ13 = (int16_t)((262144 - tmp32a) >> 5); // Q18 -> Q13.
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
for (k = 0; k < FRAMESAMPLES/2; k++)
|
|
|
|
|
{
|
2016-05-23 03:28:28 -07:00
|
|
|
Vector_Word32_1[k] = (Vector_Word16_2[k] * gainQ13) * (1 << 3); // Q25
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* perceptual post-filtering (using normalized lattice filter) */
|
|
|
|
|
WebRtcIsacfix_NormLatticeFilterAr(ORDERLO, (ISACdec_obj->maskfiltstr_obj).PostStateLoGQ0,
|
|
|
|
|
Vector_Word32_1, lofilt_coefQ15, gain_lo_hiQ17, 0, Vector_Word16_1);
|
|
|
|
|
|
|
|
|
|
/* --- Store Highpass Residual --- */
|
|
|
|
|
for (k = 0; k < FRAMESAMPLES/2; k++)
|
2016-05-23 03:28:28 -07:00
|
|
|
Vector_Word32_1[k] = Vector_Word32_2[k] * (1 << 9); // Q16 -> Q25
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
for( k = 0; k < PITCH_MAX_LAG + 10; k++ )
|
|
|
|
|
(ISACdec_obj->plcstr_obj).prevHP[k] = Vector_Word32_1[FRAMESAMPLES/2 - (PITCH_MAX_LAG + 10) + k];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
WebRtcIsacfix_NormLatticeFilterAr(ORDERHI, (ISACdec_obj->maskfiltstr_obj).PostStateHiGQ0,
|
|
|
|
|
Vector_Word32_1, hifilt_coefQ15, gain_lo_hiQ17, 1, Vector_Word16_2);
|
|
|
|
|
|
|
|
|
|
/* recombine the 2 bands */
|
|
|
|
|
|
|
|
|
|
/* Form the polyphase signals, and compensate for DC offset */
|
|
|
|
|
for (k=0;k<FRAMESAMPLES/2;k++) {
|
2013-04-09 00:28:06 +00:00
|
|
|
tmp_1 = (int16_t)WebRtcSpl_SatW32ToW16(((int32_t)Vector_Word16_1[k]+Vector_Word16_2[k] + 1)); /* Construct a new upper channel signal*/
|
|
|
|
|
tmp_2 = (int16_t)WebRtcSpl_SatW32ToW16(((int32_t)Vector_Word16_1[k]-Vector_Word16_2[k])); /* Construct a new lower channel signal*/
|
2011-07-07 08:21:25 +00:00
|
|
|
Vector_Word16_1[k] = tmp_1;
|
|
|
|
|
Vector_Word16_2[k] = tmp_2;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-28 12:57:32 +00:00
|
|
|
WebRtcIsacfix_FilterAndCombine1(Vector_Word16_1,
|
|
|
|
|
Vector_Word16_2,
|
|
|
|
|
signal_out16 + frame_nb * kProcessedSamples,
|
|
|
|
|
&ISACdec_obj->postfiltbankstr_obj);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return len;
|
|
|
|
|
}
|