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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
|
|
|
|
|
|
iLBC Speech Coder ANSI-C Source Code
|
|
|
|
|
|
|
|
|
|
WebRtcIlbcfix_DecodeResidual.c
|
|
|
|
|
|
|
|
|
|
******************************************************************/
|
|
|
|
|
|
2016-08-24 02:46:44 -07:00
|
|
|
#include "decode_residual.h"
|
|
|
|
|
|
2014-08-20 10:09:34 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
#include "defines.h"
|
|
|
|
|
#include "state_construct.h"
|
|
|
|
|
#include "cb_construct.h"
|
|
|
|
|
#include "index_conv_dec.h"
|
|
|
|
|
#include "do_plc.h"
|
|
|
|
|
#include "constants.h"
|
|
|
|
|
#include "enhancer_interface.h"
|
|
|
|
|
#include "xcorr_coef.h"
|
|
|
|
|
#include "lsf_check.h"
|
|
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------*
|
|
|
|
|
* frame residual decoder function (subrutine to iLBC_decode)
|
|
|
|
|
*---------------------------------------------------------------*/
|
|
|
|
|
|
2016-08-24 02:46:44 -07:00
|
|
|
bool WebRtcIlbcfix_DecodeResidual(
|
2014-12-17 15:23:29 +00:00
|
|
|
IlbcDecoder *iLBCdec_inst,
|
2011-07-07 08:21:25 +00:00
|
|
|
/* (i/o) the decoder state structure */
|
|
|
|
|
iLBC_bits *iLBC_encbits, /* (i/o) Encoded bits, which are used
|
|
|
|
|
for the decoding */
|
2013-04-09 00:28:06 +00:00
|
|
|
int16_t *decresidual, /* (o) decoded residual frame */
|
|
|
|
|
int16_t *syntdenum /* (i) the decoded synthesis filter
|
2011-07-07 08:21:25 +00:00
|
|
|
coefficients */
|
|
|
|
|
) {
|
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 meml_gotten, diff, start_pos;
|
|
|
|
|
size_t subcount, subframe;
|
2013-04-09 00:28:06 +00:00
|
|
|
int16_t *reverseDecresidual = iLBCdec_inst->enh_buf; /* Reversed decoded data, used for decoding backwards in time (reuse memory in state) */
|
|
|
|
|
int16_t *memVec = iLBCdec_inst->prevResidual; /* Memory for codebook and filter state (reuse memory in state) */
|
|
|
|
|
int16_t *mem = &memVec[CB_HALFFILTERLEN]; /* Memory for codebook */
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
diff = STATE_LEN - iLBCdec_inst->state_short_len;
|
|
|
|
|
|
|
|
|
|
if (iLBC_encbits->state_first == 1) {
|
|
|
|
|
start_pos = (iLBC_encbits->startIdx-1)*SUBL;
|
|
|
|
|
} else {
|
|
|
|
|
start_pos = (iLBC_encbits->startIdx-1)*SUBL + diff;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* decode scalar part of start state */
|
|
|
|
|
|
|
|
|
|
WebRtcIlbcfix_StateConstruct(iLBC_encbits->idxForMax,
|
|
|
|
|
iLBC_encbits->idxVec, &syntdenum[(iLBC_encbits->startIdx-1)*(LPC_FILTERORDER+1)],
|
|
|
|
|
&decresidual[start_pos], iLBCdec_inst->state_short_len
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (iLBC_encbits->state_first) { /* put adaptive part in the end */
|
|
|
|
|
|
|
|
|
|
/* setup memory */
|
|
|
|
|
|
Match existing type usage better.
This makes a variety of small changes to synchronize bits of code using different types, remove useless code or casts, and add explicit casts in some places previously doing implicit ones. For example:
* Change a few type declarations to better match how the majority of code uses those objects.
* Eliminate "< 0" check for unsigned values.
* Replace "(float)sin(x)", where |x| is also a float, with "sinf(x)", and similar.
* Add casts to uint32_t in many places timestamps were used and the existing code stored signed values into the unsigned objects.
* Remove downcasts when the results would be passed to a larger type, e.g. calling "foo((int16_t)x)" with an int |x| when foo() takes an int instead of an int16_t.
* Similarly, add casts when passing a larger type to a function taking a smaller one.
* Add casts to int16_t when doing something like "int16_t = int16_t + int16_t" as the "+" operation would implicitly upconvert to int, and similar.
* Use "false" instead of "0" for setting a bool.
* Shift a few temp types when doing a multi-stage calculation involving typecasts, so as to put the most logical/semantically correct type possible into the temps. For example, when doing "int foo = int + int; size_t bar = (size_t)foo + size_t;", we might change |foo| to a size_t and move the cast if it makes more sense for |foo| to be represented as a size_t.
BUG=none
R=andrew@webrtc.org, asapersson@webrtc.org, henrika@webrtc.org, juberti@webrtc.org, kwiberg@webrtc.org
TBR=andrew, asapersson, henrika
Review URL: https://codereview.webrtc.org/1168753002
Cr-Commit-Position: refs/heads/master@{#9419}
2015-06-11 12:55:50 -07:00
|
|
|
WebRtcSpl_MemSetW16(mem, 0, CB_MEML - iLBCdec_inst->state_short_len);
|
2011-07-07 08:21:25 +00:00
|
|
|
WEBRTC_SPL_MEMCPY_W16(mem+CB_MEML-iLBCdec_inst->state_short_len, decresidual+start_pos,
|
|
|
|
|
iLBCdec_inst->state_short_len);
|
|
|
|
|
|
|
|
|
|
/* construct decoded vector */
|
|
|
|
|
|
2016-08-24 02:46:44 -07:00
|
|
|
if (!WebRtcIlbcfix_CbConstruct(
|
|
|
|
|
&decresidual[start_pos + iLBCdec_inst->state_short_len],
|
|
|
|
|
iLBC_encbits->cb_index, iLBC_encbits->gain_index,
|
|
|
|
|
mem + CB_MEML - ST_MEM_L_TBL, ST_MEM_L_TBL, diff))
|
|
|
|
|
return false; // Error.
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else {/* put adaptive part in the beginning */
|
|
|
|
|
|
|
|
|
|
/* setup memory */
|
|
|
|
|
|
|
|
|
|
meml_gotten = iLBCdec_inst->state_short_len;
|
|
|
|
|
WebRtcSpl_MemCpyReversedOrder(mem+CB_MEML-1,
|
|
|
|
|
decresidual+start_pos, meml_gotten);
|
Match existing type usage better.
This makes a variety of small changes to synchronize bits of code using different types, remove useless code or casts, and add explicit casts in some places previously doing implicit ones. For example:
* Change a few type declarations to better match how the majority of code uses those objects.
* Eliminate "< 0" check for unsigned values.
* Replace "(float)sin(x)", where |x| is also a float, with "sinf(x)", and similar.
* Add casts to uint32_t in many places timestamps were used and the existing code stored signed values into the unsigned objects.
* Remove downcasts when the results would be passed to a larger type, e.g. calling "foo((int16_t)x)" with an int |x| when foo() takes an int instead of an int16_t.
* Similarly, add casts when passing a larger type to a function taking a smaller one.
* Add casts to int16_t when doing something like "int16_t = int16_t + int16_t" as the "+" operation would implicitly upconvert to int, and similar.
* Use "false" instead of "0" for setting a bool.
* Shift a few temp types when doing a multi-stage calculation involving typecasts, so as to put the most logical/semantically correct type possible into the temps. For example, when doing "int foo = int + int; size_t bar = (size_t)foo + size_t;", we might change |foo| to a size_t and move the cast if it makes more sense for |foo| to be represented as a size_t.
BUG=none
R=andrew@webrtc.org, asapersson@webrtc.org, henrika@webrtc.org, juberti@webrtc.org, kwiberg@webrtc.org
TBR=andrew, asapersson, henrika
Review URL: https://codereview.webrtc.org/1168753002
Cr-Commit-Position: refs/heads/master@{#9419}
2015-06-11 12:55:50 -07:00
|
|
|
WebRtcSpl_MemSetW16(mem, 0, CB_MEML - meml_gotten);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
/* construct decoded vector */
|
|
|
|
|
|
2016-08-24 02:46:44 -07:00
|
|
|
if (!WebRtcIlbcfix_CbConstruct(reverseDecresidual, iLBC_encbits->cb_index,
|
|
|
|
|
iLBC_encbits->gain_index,
|
|
|
|
|
mem + CB_MEML - ST_MEM_L_TBL, ST_MEM_L_TBL,
|
|
|
|
|
diff))
|
|
|
|
|
return false; // Error.
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
/* get decoded residual from reversed vector */
|
|
|
|
|
|
|
|
|
|
WebRtcSpl_MemCpyReversedOrder(&decresidual[start_pos-1],
|
|
|
|
|
reverseDecresidual, diff);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* counter for predicted subframes */
|
|
|
|
|
|
|
|
|
|
subcount=1;
|
|
|
|
|
|
|
|
|
|
/* forward prediction of subframes */
|
|
|
|
|
|
2015-06-10 21:15:38 -07:00
|
|
|
if (iLBCdec_inst->nsub > iLBC_encbits->startIdx + 1) {
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
/* setup memory */
|
|
|
|
|
WebRtcSpl_MemSetW16(mem, 0, CB_MEML-STATE_LEN);
|
|
|
|
|
WEBRTC_SPL_MEMCPY_W16(mem+CB_MEML-STATE_LEN,
|
|
|
|
|
decresidual+(iLBC_encbits->startIdx-1)*SUBL, STATE_LEN);
|
|
|
|
|
|
|
|
|
|
/* loop over subframes to encode */
|
|
|
|
|
|
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 Nfor = iLBCdec_inst->nsub - iLBC_encbits->startIdx - 1;
|
2011-07-07 08:21:25 +00:00
|
|
|
for (subframe=0; subframe<Nfor; subframe++) {
|
|
|
|
|
|
|
|
|
|
/* construct decoded vector */
|
2016-08-24 02:46:44 -07:00
|
|
|
if (!WebRtcIlbcfix_CbConstruct(
|
|
|
|
|
&decresidual[(iLBC_encbits->startIdx + 1 + subframe) * SUBL],
|
|
|
|
|
iLBC_encbits->cb_index + subcount * CB_NSTAGES,
|
|
|
|
|
iLBC_encbits->gain_index + subcount * CB_NSTAGES, mem, MEM_LF_TBL,
|
|
|
|
|
SUBL))
|
|
|
|
|
return false; // Error;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
/* update memory */
|
2014-08-20 10:09:34 +00:00
|
|
|
memmove(mem, mem + SUBL, (CB_MEML - SUBL) * sizeof(*mem));
|
2011-07-07 08:21:25 +00:00
|
|
|
WEBRTC_SPL_MEMCPY_W16(mem+CB_MEML-SUBL,
|
|
|
|
|
&decresidual[(iLBC_encbits->startIdx+1+subframe)*SUBL], SUBL);
|
|
|
|
|
|
|
|
|
|
subcount++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* backward prediction of subframes */
|
|
|
|
|
|
2015-06-10 21:15:38 -07:00
|
|
|
if (iLBC_encbits->startIdx > 1) {
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
/* setup memory */
|
|
|
|
|
|
|
|
|
|
meml_gotten = SUBL*(iLBCdec_inst->nsub+1-iLBC_encbits->startIdx);
|
|
|
|
|
if( meml_gotten > CB_MEML ) {
|
|
|
|
|
meml_gotten=CB_MEML;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WebRtcSpl_MemCpyReversedOrder(mem+CB_MEML-1,
|
|
|
|
|
decresidual+(iLBC_encbits->startIdx-1)*SUBL, meml_gotten);
|
Match existing type usage better.
This makes a variety of small changes to synchronize bits of code using different types, remove useless code or casts, and add explicit casts in some places previously doing implicit ones. For example:
* Change a few type declarations to better match how the majority of code uses those objects.
* Eliminate "< 0" check for unsigned values.
* Replace "(float)sin(x)", where |x| is also a float, with "sinf(x)", and similar.
* Add casts to uint32_t in many places timestamps were used and the existing code stored signed values into the unsigned objects.
* Remove downcasts when the results would be passed to a larger type, e.g. calling "foo((int16_t)x)" with an int |x| when foo() takes an int instead of an int16_t.
* Similarly, add casts when passing a larger type to a function taking a smaller one.
* Add casts to int16_t when doing something like "int16_t = int16_t + int16_t" as the "+" operation would implicitly upconvert to int, and similar.
* Use "false" instead of "0" for setting a bool.
* Shift a few temp types when doing a multi-stage calculation involving typecasts, so as to put the most logical/semantically correct type possible into the temps. For example, when doing "int foo = int + int; size_t bar = (size_t)foo + size_t;", we might change |foo| to a size_t and move the cast if it makes more sense for |foo| to be represented as a size_t.
BUG=none
R=andrew@webrtc.org, asapersson@webrtc.org, henrika@webrtc.org, juberti@webrtc.org, kwiberg@webrtc.org
TBR=andrew, asapersson, henrika
Review URL: https://codereview.webrtc.org/1168753002
Cr-Commit-Position: refs/heads/master@{#9419}
2015-06-11 12:55:50 -07:00
|
|
|
WebRtcSpl_MemSetW16(mem, 0, CB_MEML - meml_gotten);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
/* loop over subframes to decode */
|
|
|
|
|
|
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 Nback = iLBC_encbits->startIdx - 1;
|
2011-07-07 08:21:25 +00:00
|
|
|
for (subframe=0; subframe<Nback; subframe++) {
|
|
|
|
|
|
|
|
|
|
/* construct decoded vector */
|
2016-08-24 02:46:44 -07:00
|
|
|
if (!WebRtcIlbcfix_CbConstruct(
|
|
|
|
|
&reverseDecresidual[subframe * SUBL],
|
|
|
|
|
iLBC_encbits->cb_index + subcount * CB_NSTAGES,
|
|
|
|
|
iLBC_encbits->gain_index + subcount * CB_NSTAGES, mem, MEM_LF_TBL,
|
|
|
|
|
SUBL))
|
|
|
|
|
return false; // Error.
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
/* update memory */
|
2014-08-20 10:09:34 +00:00
|
|
|
memmove(mem, mem + SUBL, (CB_MEML - SUBL) * sizeof(*mem));
|
2011-07-07 08:21:25 +00:00
|
|
|
WEBRTC_SPL_MEMCPY_W16(mem+CB_MEML-SUBL,
|
|
|
|
|
&reverseDecresidual[subframe*SUBL], SUBL);
|
|
|
|
|
|
|
|
|
|
subcount++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* get decoded residual from reversed vector */
|
|
|
|
|
WebRtcSpl_MemCpyReversedOrder(decresidual+SUBL*Nback-1,
|
|
|
|
|
reverseDecresidual, SUBL*Nback);
|
|
|
|
|
}
|
2016-08-24 02:46:44 -07:00
|
|
|
|
|
|
|
|
return true; // Success.
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|