1 /*
2  *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 /******************************************************************
12 
13  iLBC Speech Coder ANSI-C Source Code
14 
15  WebRtcIlbcfix_DecoderInterpolateLsp.c
16 
17 ******************************************************************/
18 
19 #include "lsf_interpolate_to_poly_dec.h"
20 #include "bw_expand.h"
21 #include "defines.h"
22 #include "constants.h"
23 
24 /*----------------------------------------------------------------*
25  *  obtain synthesis and weighting filters form lsf coefficients
26  *---------------------------------------------------------------*/
27 
WebRtcIlbcfix_DecoderInterpolateLsp(int16_t * syntdenum,int16_t * weightdenum,int16_t * lsfdeq,int16_t length,IlbcDecoder * iLBCdec_inst)28 void WebRtcIlbcfix_DecoderInterpolateLsp(
29     int16_t *syntdenum,  /* (o) synthesis filter coefficients */
30     int16_t *weightdenum, /* (o) weighting denumerator
31                                    coefficients */
32     int16_t *lsfdeq,   /* (i) dequantized lsf coefficients */
33     int16_t length,   /* (i) length of lsf coefficient vector */
34     IlbcDecoder *iLBCdec_inst
35     /* (i) the decoder state structure */
36                                           ){
37   size_t i;
38   int pos, lp_length;
39   int16_t  lp[LPC_FILTERORDER + 1], *lsfdeq2;
40 
41   lsfdeq2 = lsfdeq + length;
42   lp_length = length + 1;
43 
44   if (iLBCdec_inst->mode==30) {
45     /* subframe 1: Interpolation between old and first LSF */
46 
47     WebRtcIlbcfix_LspInterpolate2PolyDec(lp, (*iLBCdec_inst).lsfdeqold, lsfdeq,
48                                          WebRtcIlbcfix_kLsfWeight30ms[0], length);
49     WEBRTC_SPL_MEMCPY_W16(syntdenum,lp,lp_length);
50     WebRtcIlbcfix_BwExpand(weightdenum, lp, (int16_t*)WebRtcIlbcfix_kLpcChirpSyntDenum, (int16_t)lp_length);
51 
52     /* subframes 2 to 6: interpolation between first and last LSF */
53 
54     pos = lp_length;
55     for (i = 1; i < 6; i++) {
56       WebRtcIlbcfix_LspInterpolate2PolyDec(lp, lsfdeq, lsfdeq2,
57                                            WebRtcIlbcfix_kLsfWeight30ms[i], length);
58       WEBRTC_SPL_MEMCPY_W16(syntdenum + pos,lp,lp_length);
59       WebRtcIlbcfix_BwExpand(weightdenum + pos, lp,
60                              (int16_t*)WebRtcIlbcfix_kLpcChirpSyntDenum, (int16_t)lp_length);
61       pos += lp_length;
62     }
63   } else { /* iLBCdec_inst->mode=20 */
64     /* subframes 1 to 4: interpolation between old and new LSF */
65     pos = 0;
66     for (i = 0; i < iLBCdec_inst->nsub; i++) {
67       WebRtcIlbcfix_LspInterpolate2PolyDec(lp, iLBCdec_inst->lsfdeqold, lsfdeq,
68                                            WebRtcIlbcfix_kLsfWeight20ms[i], length);
69       WEBRTC_SPL_MEMCPY_W16(syntdenum+pos,lp,lp_length);
70       WebRtcIlbcfix_BwExpand(weightdenum+pos, lp,
71                              (int16_t*)WebRtcIlbcfix_kLpcChirpSyntDenum, (int16_t)lp_length);
72       pos += lp_length;
73     }
74   }
75 
76   /* update memory */
77 
78   if (iLBCdec_inst->mode==30) {
79     WEBRTC_SPL_MEMCPY_W16(iLBCdec_inst->lsfdeqold, lsfdeq2, length);
80   } else {
81     WEBRTC_SPL_MEMCPY_W16(iLBCdec_inst->lsfdeqold, lsfdeq, length);
82   }
83 }
84