Skip to content

Commit 23b3805

Browse files
committed
Decimate QEXT PLC pitch search by 4 instead of 2
Reduces the PLC complexity
1 parent 913cac3 commit 23b3805

File tree

4 files changed

+31
-31
lines changed

4 files changed

+31
-31
lines changed

celt/celt_decoder.c

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -542,8 +542,6 @@ static void tf_decode(int start, int end, int isTransient, int *tf_res, int LM,
542542
static int celt_plc_pitch_search(CELTDecoder *st, celt_sig *decode_mem[2], int C, int arch)
543543
{
544544
int pitch_index;
545-
int decode_buffer_size;
546-
int plc_pitch_lag_max, plc_pitch_lag_min;
547545
#ifdef ENABLE_QEXT
548546
int qext_scale;
549547
#endif
@@ -552,18 +550,15 @@ static int celt_plc_pitch_search(CELTDecoder *st, celt_sig *decode_mem[2], int C
552550
#ifdef ENABLE_QEXT
553551
qext_scale = st->qext_scale;
554552
#endif
555-
decode_buffer_size = QEXT_SCALE(DECODE_BUFFER_SIZE);
556-
plc_pitch_lag_max = QEXT_SCALE(PLC_PITCH_LAG_MAX);
557-
plc_pitch_lag_min = QEXT_SCALE(PLC_PITCH_LAG_MIN);
558-
ALLOC( lp_pitch_buf, decode_buffer_size>>1, opus_val16 );
553+
ALLOC( lp_pitch_buf, DECODE_BUFFER_SIZE>>1, opus_val16 );
559554
pitch_downsample(decode_mem, lp_pitch_buf,
560-
decode_buffer_size, C, arch);
561-
pitch_search(lp_pitch_buf+(plc_pitch_lag_max>>1), lp_pitch_buf,
562-
decode_buffer_size-plc_pitch_lag_max,
563-
plc_pitch_lag_max-plc_pitch_lag_min, &pitch_index, arch);
564-
pitch_index = plc_pitch_lag_max-pitch_index;
555+
DECODE_BUFFER_SIZE>>1, C, QEXT_SCALE(2), arch);
556+
pitch_search(lp_pitch_buf+(PLC_PITCH_LAG_MAX>>1), lp_pitch_buf,
557+
DECODE_BUFFER_SIZE-PLC_PITCH_LAG_MAX,
558+
PLC_PITCH_LAG_MAX-PLC_PITCH_LAG_MIN, &pitch_index, arch);
559+
pitch_index = PLC_PITCH_LAG_MAX-pitch_index;
565560
RESTORE_STACK;
566-
return pitch_index;
561+
return QEXT_SCALE(pitch_index);
567562
}
568563

569564
static void prefilter_and_fold(CELTDecoder * OPUS_RESTRICT st, int N)

celt/celt_encoder.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1450,7 +1450,7 @@ static int run_prefilter(CELTEncoder *st, celt_sig *in, celt_sig *prefilter_mem,
14501450
VARDECL(opus_val16, pitch_buf);
14511451
ALLOC(pitch_buf, (max_period+N)>>1, opus_val16);
14521452

1453-
pitch_downsample(pre, pitch_buf, max_period+N, CC, st->arch);
1453+
pitch_downsample(pre, pitch_buf, (max_period+N)>>1, CC, 2, st->arch);
14541454
/* Don't search for the fir last 1.5 octave of the range because
14551455
there's too many false-positives due to short-term correlation */
14561456
pitch_search(pitch_buf+(max_period>>1), pitch_buf, N,

celt/pitch.c

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -138,20 +138,25 @@ static void celt_fir5(opus_val16 *x,
138138

139139

140140
void pitch_downsample(celt_sig * OPUS_RESTRICT x[], opus_val16 * OPUS_RESTRICT x_lp,
141-
int len, int C, int arch)
141+
int len, int C, int factor, int arch)
142142
{
143143
int i;
144144
opus_val32 ac[5];
145145
opus_val16 tmp=Q15ONE;
146146
opus_val16 lpc[4];
147147
opus_val16 lpc2[5];
148148
opus_val16 c1 = QCONST16(.8f,15);
149+
int offset;
149150
#ifdef FIXED_POINT
150151
int shift;
151-
opus_val32 maxabs = celt_maxabs32(x[0], len);
152+
opus_val32 maxabs;
153+
#endif
154+
offset = factor/2;
155+
#ifdef FIXED_POINT
156+
maxabs = celt_maxabs32(x[0], len*factor);
152157
if (C==2)
153158
{
154-
opus_val32 maxabs_1 = celt_maxabs32(x[1], len);
159+
opus_val32 maxabs_1 = celt_maxabs32(x[1], len*factor);
155160
maxabs = MAX32(maxabs, maxabs_1);
156161
}
157162
if (maxabs<1)
@@ -161,28 +166,28 @@ void pitch_downsample(celt_sig * OPUS_RESTRICT x[], opus_val16 * OPUS_RESTRICT x
161166
shift=0;
162167
if (C==2)
163168
shift++;
164-
for (i=1;i<len>>1;i++)
165-
x_lp[i] = SHR32(x[0][(2*i-1)], shift+2) + SHR32(x[0][(2*i+1)], shift+2) + SHR32(x[0][2*i], shift+1);
166-
x_lp[0] = SHR32(x[0][1], shift+2) + SHR32(x[0][0], shift+1);
169+
for (i=1;i<len;i++)
170+
x_lp[i] = SHR32(x[0][(factor*i-offset)], shift+2) + SHR32(x[0][(factor*i+offset)], shift+2) + SHR32(x[0][factor*i], shift+1);
171+
x_lp[0] = SHR32(x[0][offset], shift+2) + SHR32(x[0][0], shift+1);
167172
if (C==2)
168173
{
169-
for (i=1;i<len>>1;i++)
170-
x_lp[i] += SHR32(x[1][(2*i-1)], shift+2) + SHR32(x[1][(2*i+1)], shift+2) + SHR32(x[1][2*i], shift+1);
171-
x_lp[0] += SHR32(x[1][1], shift+2) + SHR32(x[1][0], shift+1);
174+
for (i=1;i<len;i++)
175+
x_lp[i] += SHR32(x[1][(factor*i-offset)], shift+2) + SHR32(x[1][(factor*i+offset)], shift+2) + SHR32(x[1][factor*i], shift+1);
176+
x_lp[0] += SHR32(x[1][offset], shift+2) + SHR32(x[1][0], shift+1);
172177
}
173178
#else
174-
for (i=1;i<len>>1;i++)
175-
x_lp[i] = .25f*x[0][(2*i-1)] + .25f*x[0][(2*i+1)] + .5f*x[0][2*i];
176-
x_lp[0] = .25f*x[0][1] + .5f*x[0][0];
179+
for (i=1;i<len;i++)
180+
x_lp[i] = .25f*x[0][(factor*i-offset)] + .25f*x[0][(factor*i+offset)] + .5f*x[0][factor*i];
181+
x_lp[0] = .25f*x[0][offset] + .5f*x[0][0];
177182
if (C==2)
178183
{
179-
for (i=1;i<len>>1;i++)
180-
x_lp[i] += .25f*x[1][(2*i-1)] + .25f*x[1][(2*i+1)] + .5f*x[1][2*i];
181-
x_lp[0] += .25f*x[1][1] + .5f*x[1][0];
184+
for (i=1;i<len;i++)
185+
x_lp[i] += .25f*x[1][(factor*i-offset)] + .25f*x[1][(factor*i+offset)] + .5f*x[1][factor*i];
186+
x_lp[0] += .25f*x[1][offset] + .5f*x[1][0];
182187
}
183188
#endif
184189
_celt_autocorr(x_lp, ac, NULL, 0,
185-
4, len>>1, arch);
190+
4, len, arch);
186191

187192
/* Noise floor -40 dB */
188193
#ifdef FIXED_POINT
@@ -213,7 +218,7 @@ void pitch_downsample(celt_sig * OPUS_RESTRICT x[], opus_val16 * OPUS_RESTRICT x
213218
lpc2[2] = lpc[2] + MULT16_16_Q15(c1,lpc[1]);
214219
lpc2[3] = lpc[3] + MULT16_16_Q15(c1,lpc[2]);
215220
lpc2[4] = MULT16_16_Q15(c1,lpc[3]);
216-
celt_fir5(x_lp, lpc2, len>>1);
221+
celt_fir5(x_lp, lpc2, len);
217222
}
218223

219224
/* Pure C implementation. */

celt/pitch.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
#endif
5252

5353
void pitch_downsample(celt_sig * OPUS_RESTRICT x[], opus_val16 * OPUS_RESTRICT x_lp,
54-
int len, int C, int arch);
54+
int len, int C, int factor, int arch);
5555

5656
void pitch_search(const opus_val16 * OPUS_RESTRICT x_lp, opus_val16 * OPUS_RESTRICT y,
5757
int len, int max_pitch, int *pitch, int arch);

0 commit comments

Comments
 (0)