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_CreateAugmentedVec.c
16
17 ******************************************************************/
18
19 #include "modules/audio_coding/codecs/ilbc/defines.h"
20 #include "modules/audio_coding/codecs/ilbc/constants.h"
21 #include "rtc_base/sanitizer.h"
22 #include "common_audio/signal_processing/include/signal_processing_library.h"
23
24 /*----------------------------------------------------------------*
25 * Recreate a specific codebook vector from the augmented part.
26 *
27 *----------------------------------------------------------------*/
28
WebRtcIlbcfix_CreateAugmentedVec(size_t index,const int16_t * buffer,int16_t * cbVec)29 void WebRtcIlbcfix_CreateAugmentedVec(
30 size_t index, /* (i) Index for the augmented vector to be
31 created */
32 const int16_t* buffer, /* (i) Pointer to the end of the codebook memory
33 that is used for creation of the augmented
34 codebook */
35 int16_t* cbVec) { /* (o) The constructed codebook vector */
36 size_t ilow;
37 const int16_t *ppo, *ppi;
38 int16_t cbVecTmp[4];
39 /* Interpolation starts 4 elements before cbVec+index, but must not start
40 outside |cbVec|; clamping interp_len to stay within |cbVec|.
41 */
42 size_t interp_len = WEBRTC_SPL_MIN(index, 4);
43
44 rtc_MsanCheckInitialized(buffer - index - interp_len, sizeof(buffer[0]),
45 index + interp_len);
46
47 ilow = index - interp_len;
48
49 /* copy the first noninterpolated part */
50 ppo = buffer-index;
51 WEBRTC_SPL_MEMCPY_W16(cbVec, ppo, index);
52
53 /* interpolation */
54 ppo = buffer - interp_len;
55 ppi = buffer - index - interp_len;
56
57 /* perform cbVec[ilow+k] = ((ppi[k]*alphaTbl[k])>>15) +
58 ((ppo[k]*alphaTbl[interp_len-1-k])>>15);
59 for k = 0..interp_len-1
60 */
61 WebRtcSpl_ElementwiseVectorMult(&cbVec[ilow], ppi, WebRtcIlbcfix_kAlpha,
62 interp_len, 15);
63 WebRtcSpl_ReverseOrderMultArrayElements(
64 cbVecTmp, ppo, &WebRtcIlbcfix_kAlpha[interp_len - 1], interp_len, 15);
65 WebRtcSpl_AddVectorsAndShift(&cbVec[ilow], &cbVec[ilow], cbVecTmp, interp_len,
66 0);
67
68 /* copy the second noninterpolated part */
69 ppo = buffer - index;
70 /* |tempbuff2| is declared in WebRtcIlbcfix_GetCbVec and is SUBL+5 elements
71 long. |buffer| points one element past the end of that vector, i.e., at
72 tempbuff2+SUBL+5. Since ppo=buffer-index, we cannot read any more than
73 |index| elements from |ppo|.
74
75 |cbVec| is declared to be SUBL elements long in WebRtcIlbcfix_CbConstruct.
76 Therefore, we can only write SUBL-index elements to cbVec+index.
77
78 These two conditions limit the number of elements to copy.
79 */
80 WEBRTC_SPL_MEMCPY_W16(cbVec+index, ppo, WEBRTC_SPL_MIN(SUBL-index, index));
81 }
82