• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_GetCbVec.c
16 
17 ******************************************************************/
18 
19 #include "defines.h"
20 #include "constants.h"
21 #include "create_augmented_vec.h"
22 
23 /*----------------------------------------------------------------*
24  *  Construct codebook vector for given index.
25  *---------------------------------------------------------------*/
26 
WebRtcIlbcfix_GetCbVec(int16_t * cbvec,int16_t * mem,size_t index,size_t lMem,size_t cbveclen)27 void WebRtcIlbcfix_GetCbVec(
28     int16_t *cbvec,   /* (o) Constructed codebook vector */
29     int16_t *mem,   /* (i) Codebook buffer */
30     size_t index,   /* (i) Codebook index */
31     size_t lMem,   /* (i) Length of codebook buffer */
32     size_t cbveclen   /* (i) Codebook vector length */
33                             ){
34   size_t k, base_size;
35   size_t lag;
36   /* Stack based */
37   int16_t tempbuff2[SUBL+5];
38 
39   /* Determine size of codebook sections */
40 
41   base_size=lMem-cbveclen+1;
42 
43   if (cbveclen==SUBL) {
44     base_size += cbveclen / 2;
45   }
46 
47   /* No filter -> First codebook section */
48 
49   if (index<lMem-cbveclen+1) {
50 
51     /* first non-interpolated vectors */
52 
53     k=index+cbveclen;
54     /* get vector */
55     WEBRTC_SPL_MEMCPY_W16(cbvec, mem+lMem-k, cbveclen);
56 
57   } else if (index < base_size) {
58 
59     /* Calculate lag */
60 
61     k = (2 * (index - (lMem - cbveclen + 1))) + cbveclen;
62 
63     lag = k / 2;
64 
65     WebRtcIlbcfix_CreateAugmentedVec(lag, mem+lMem, cbvec);
66 
67   }
68 
69   /* Higher codebbok section based on filtering */
70 
71   else {
72 
73     size_t memIndTest;
74 
75     /* first non-interpolated vectors */
76 
77     if (index-base_size<lMem-cbveclen+1) {
78 
79       /* Set up filter memory, stuff zeros outside memory buffer */
80 
81       memIndTest = lMem-(index-base_size+cbveclen);
82 
83       WebRtcSpl_MemSetW16(mem-CB_HALFFILTERLEN, 0, CB_HALFFILTERLEN);
84       WebRtcSpl_MemSetW16(mem+lMem, 0, CB_HALFFILTERLEN);
85 
86       /* do filtering to get the codebook vector */
87 
88       WebRtcSpl_FilterMAFastQ12(
89           &mem[memIndTest+4], cbvec, (int16_t*)WebRtcIlbcfix_kCbFiltersRev,
90           CB_FILTERLEN, cbveclen);
91     }
92 
93     /* interpolated vectors */
94 
95     else {
96       /* Stuff zeros outside memory buffer  */
97       memIndTest = lMem-cbveclen-CB_FILTERLEN;
98       WebRtcSpl_MemSetW16(mem+lMem, 0, CB_HALFFILTERLEN);
99 
100       /* do filtering */
101       WebRtcSpl_FilterMAFastQ12(
102           &mem[memIndTest+7], tempbuff2, (int16_t*)WebRtcIlbcfix_kCbFiltersRev,
103           CB_FILTERLEN, cbveclen+5);
104 
105       /* Calculate lag index */
106       lag = (cbveclen<<1)-20+index-base_size-lMem-1;
107 
108       WebRtcIlbcfix_CreateAugmentedVec(lag, tempbuff2+SUBL+5, cbvec);
109     }
110   }
111 }
112