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_GetSyncSeq.c
16
17 ******************************************************************/
18
19 #include "modules/audio_coding/codecs/ilbc/get_sync_seq.h"
20
21 #include "modules/audio_coding/codecs/ilbc/constants.h"
22 #include "modules/audio_coding/codecs/ilbc/defines.h"
23 #include "modules/audio_coding/codecs/ilbc/nearest_neighbor.h"
24 #include "modules/audio_coding/codecs/ilbc/refiner.h"
25
26 /*----------------------------------------------------------------*
27 * get the pitch-synchronous sample sequence
28 *---------------------------------------------------------------*/
29
WebRtcIlbcfix_GetSyncSeq(int16_t * idata,size_t idatal,size_t centerStartPos,size_t * period,const size_t * plocs,size_t periodl,size_t hl,int16_t * surround)30 void WebRtcIlbcfix_GetSyncSeq(
31 int16_t *idata, /* (i) original data */
32 size_t idatal, /* (i) dimension of data */
33 size_t centerStartPos, /* (i) where current block starts */
34 size_t *period, /* (i) rough-pitch-period array (Q-2) */
35 const size_t *plocs, /* (i) where periods of period array are taken (Q-2) */
36 size_t periodl, /* (i) dimension period array */
37 size_t hl, /* (i) 2*hl+1 is the number of sequences */
38 int16_t *surround /* (i/o) The contribution from this sequence
39 summed with earlier contributions */
40 ){
41 size_t i, centerEndPos, q;
42 /* Stack based */
43 size_t lagBlock[2 * ENH_HL + 1];
44 size_t blockStartPos[2 * ENH_HL + 1]; /* The position to search around (Q2) */
45 size_t plocs2[ENH_PLOCSL];
46
47 centerEndPos = centerStartPos + ENH_BLOCKL - 1;
48
49 /* present (find predicted lag from this position) */
50
51 WebRtcIlbcfix_NearestNeighbor(lagBlock + hl,
52 plocs,
53 2 * (centerStartPos + centerEndPos),
54 periodl);
55
56 blockStartPos[hl] = 4 * centerStartPos;
57
58 /* past (find predicted position and perform a refined
59 search to find the best sequence) */
60
61 for (q = hl; q > 0; q--) {
62 size_t qq = q - 1;
63 size_t period_q = period[lagBlock[q]];
64 /* Stop if this sequence would be outside the buffer; that means all
65 further-past sequences would also be outside the buffer. */
66 if (blockStartPos[q] < period_q + (4 * ENH_OVERHANG))
67 break;
68 blockStartPos[qq] = blockStartPos[q] - period_q;
69
70 size_t value = blockStartPos[qq] + 4 * ENH_BLOCKL_HALF;
71 value = (value > period_q) ? (value - period_q) : 0;
72 WebRtcIlbcfix_NearestNeighbor(lagBlock + qq, plocs, value, periodl);
73
74 /* Find the best possible sequence in the 4 times upsampled
75 domain around blockStartPos+q */
76 WebRtcIlbcfix_Refiner(blockStartPos + qq, idata, idatal, centerStartPos,
77 blockStartPos[qq], surround,
78 WebRtcIlbcfix_kEnhWt[qq]);
79 }
80
81 /* future (find predicted position and perform a refined
82 search to find the best sequence) */
83
84 for (i = 0; i < periodl; i++) {
85 plocs2[i] = plocs[i] - period[i];
86 }
87
88 for (q = hl + 1; q <= (2 * hl); q++) {
89
90 WebRtcIlbcfix_NearestNeighbor(
91 lagBlock + q,
92 plocs2,
93 blockStartPos[q - 1] + 4 * ENH_BLOCKL_HALF,
94 periodl);
95
96 blockStartPos[q]=blockStartPos[q-1]+period[lagBlock[q]];
97
98 if (blockStartPos[q] + 4 * (ENH_BLOCKL + ENH_OVERHANG) < 4 * idatal) {
99
100 /* Find the best possible sequence in the 4 times upsampled
101 domain around blockStartPos+q */
102 WebRtcIlbcfix_Refiner(blockStartPos + q, idata, idatal, centerStartPos,
103 blockStartPos[q], surround,
104 WebRtcIlbcfix_kEnhWt[2 * hl - q]);
105
106 } else {
107 /* Don't add anything since this sequence would
108 be outside the buffer */
109 }
110 }
111 }
112