Bug Summary

File:root/firefox-clang/media/libopus/celt/celt_decoder.c
Warning:line 1028, column 19
The right operand of '*' is a garbage value

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -O2 -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name celt_decoder.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=all -relaxed-aliasing -ffp-contract=off -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/media/libopus -fcoverage-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/media/libopus -resource-dir /usr/lib/llvm-23/lib/clang/23 -include /root/firefox-clang/obj-x86_64-pc-linux-gnu/mozilla-config.h -U _FORTIFY_SOURCE -D _FORTIFY_SOURCE=2 -D DEBUG=1 -D OPUS_BUILD -D OPUS_VERSION=0145a6248c2171bb6c4e03fb54fe016b5123e37e -D USE_ALLOCA -D ENABLE_HARDENING -D OPUS_EXPORT= -D ENABLE_ASSERTIONS -D HAVE_LRINTF -D OPUS_HAVE_RTCD -D CPU_INFO_BY_ASM -D OPUS_X86_MAY_HAVE_SSE -D OPUS_X86_MAY_HAVE_SSE2 -D OPUS_X86_MAY_HAVE_SSE4_1 -D OPUS_X86_MAY_HAVE_AVX -D MOZ_HAS_MOZGLUE -I /root/firefox-clang/media/libopus -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/media/libopus -I /root/firefox-clang/media/libopus/celt -I /root/firefox-clang/media/libopus/include -I /root/firefox-clang/media/libopus/silk -I /root/firefox-clang/media/libopus/silk/fixed -I /root/firefox-clang/media/libopus/silk/float -I /root/firefox-clang/media/libopus/src -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/nspr -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/nss -D MOZILLA_CLIENT -internal-isystem /usr/lib/llvm-23/lib/clang/23/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wno-error=tautological-type-limit-compare -Wno-range-loop-analysis -Wno-error=deprecated-declarations -Wno-error=array-bounds -Wno-error=free-nonheap-object -Wno-error=atomic-alignment -Wno-error=deprecated-builtins -Wno-psabi -Wno-error=builtin-macro-redefined -Wno-unknown-warning-option -Wno-character-conversion -Wno-#pragma-messages -ferror-limit 19 -fstrict-flex-arrays=1 -stack-protector 2 -fstack-clash-protection -ftrivial-auto-var-init=pattern -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fdiagnostics-absolute-paths -vectorize-loops -vectorize-slp -analyzer-checker optin.performance.Padding -analyzer-output=html -analyzer-config stable-report-filename=true -mllvm -dwarf-linkage-names=Abstract -faddrsig -fdwarf2-cfi-asm -o /tmp/scan-build-2026-11-12-001017-1011516-1 -x c /root/firefox-clang/media/libopus/celt/celt_decoder.c
1/* Copyright (c) 2007-2008 CSIRO
2 Copyright (c) 2007-2010 Xiph.Org Foundation
3 Copyright (c) 2008 Gregory Maxwell
4 Written by Jean-Marc Valin and Gregory Maxwell */
5/*
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
8 are met:
9
10 - Redistributions of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
12
13 - Redistributions in binary form must reproduce the above copyright
14 notice, this list of conditions and the following disclaimer in the
15 documentation and/or other materials provided with the distribution.
16
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*/
29
30#ifdef HAVE_CONFIG_H
31#include "config.h"
32#endif
33
34#define CELT_DECODER_C
35
36#include "cpu_support.h"
37#include "os_support.h"
38#include "mdct.h"
39#include <math.h>
40#include "celt.h"
41#include "pitch.h"
42#include "bands.h"
43#include "modes.h"
44#include "entcode.h"
45#include "quant_bands.h"
46#include "rate.h"
47#include "stack_alloc.h"
48#include "mathops.h"
49#include "float_cast.h"
50#include <stdarg.h>
51#include "celt_lpc.h"
52#include "vq.h"
53
54#ifdef ENABLE_DEEP_PLC
55#include "lpcnet.h"
56#include "lpcnet_private.h"
57#endif
58
59/* The maximum pitch lag to allow in the pitch-based PLC. It's possible to save
60 CPU time in the PLC pitch search by making this smaller than MAX_PERIOD. The
61 current value corresponds to a pitch of 66.67 Hz. */
62#define PLC_PITCH_LAG_MAX(720) (720)
63/* The minimum pitch lag to allow in the pitch-based PLC. This corresponds to a
64 pitch of 480 Hz. */
65#define PLC_PITCH_LAG_MIN(100) (100)
66
67#define FRAME_NONE0 0
68#define FRAME_NORMAL1 1
69#define FRAME_PLC_NOISE2 2
70#define FRAME_PLC_PERIODIC3 3
71#define FRAME_PLC_NEURAL4 4
72#define FRAME_DRED5 5
73
74/**********************************************************************/
75/* */
76/* DECODER */
77/* */
78/**********************************************************************/
79#define DECODE_BUFFER_SIZE2048 DEC_PITCH_BUF_SIZE2048
80
81#define PLC_UPDATE_FRAMES4 4
82#define PLC_UPDATE_SAMPLES(4*FRAME_SIZE) (PLC_UPDATE_FRAMES4*FRAME_SIZE)
83
84/** Decoder state
85 @brief Decoder state
86 */
87struct OpusCustomDecoder {
88 const OpusCustomMode *mode;
89 int overlap;
90 int channels;
91 int stream_channels;
92
93 int downsample;
94 int start, end;
95 int signalling;
96 int disable_inv;
97 int complexity;
98 int arch;
99#ifdef ENABLE_QEXT
100 int qext_scale;
101#endif
102
103 /* Everything beyond this point gets cleared on a reset */
104#define DECODER_RESET_STARTrng rng
105
106 opus_uint32 rng;
107 int error;
108 int last_pitch_index;
109 opus_val16 plc_decay[2];
110 int loss_duration;
111 int plc_duration;
112 int last_frame_type;
113 int skip_plc;
114 int postfilter_period;
115 int postfilter_period_old;
116 opus_val16 postfilter_gain;
117 opus_val16 postfilter_gain_old;
118 int postfilter_tapset;
119 int postfilter_tapset_old;
120 int prefilter_and_fold;
121
122 celt_sig preemph_memD[2];
123
124#ifdef ENABLE_DEEP_PLC
125 opus_int16 plc_pcm[PLC_UPDATE_SAMPLES(4*FRAME_SIZE)];
126 int plc_fill;
127 float plc_preemphasis_mem;
128#endif
129
130#ifdef ENABLE_QEXT
131 celt_glog qext_oldBandE[2*NB_QEXT_BANDS];
132#endif
133
134 celt_sig _decode_mem[1]; /* Size = channels*(DECODE_BUFFER_SIZE+mode->overlap) */
135 /* celt_glog oldEBands[], Size = 2*mode->nbEBands */
136 /* celt_glog oldLogE[], Size = 2*mode->nbEBands */
137 /* celt_glog oldLogE2[], Size = 2*mode->nbEBands */
138 /* celt_glog backgroundLogE[], Size = 2*mode->nbEBands */
139 /* opus_val16 lpc[], Size = channels*CELT_LPC_ORDER */
140};
141
142#if defined(ENABLE_HARDENING1) || defined(ENABLE_ASSERTIONS1)
143/* Make basic checks on the CELT state to ensure we don't end
144 up writing all over memory. */
145void validate_celt_decoder(CELTDecoderOpusCustomDecoder *st)
146{
147#if !defined(CUSTOM_MODES) && !defined(ENABLE_OPUS_CUSTOM_API) && !defined(ENABLE_QEXT)
148 celt_assert(st->mode == opus_custom_mode_create(48000, 960, NULL)){if (!(st->mode == opus_custom_mode_create(48000, 960, ((void
*)0)))) {celt_fatal("assertion failed: " "st->mode == opus_custom_mode_create(48000, 960, NULL)"
, "/root/firefox-clang/media/libopus/celt/celt_decoder.c", 148
);}}
;
149 celt_assert(st->overlap == 120){if (!(st->overlap == 120)) {celt_fatal("assertion failed: "
"st->overlap == 120", "/root/firefox-clang/media/libopus/celt/celt_decoder.c"
, 149);}}
;
150 celt_assert(st->end <= 21){if (!(st->end <= 21)) {celt_fatal("assertion failed: "
"st->end <= 21", "/root/firefox-clang/media/libopus/celt/celt_decoder.c"
, 150);}}
;
151#else
152/* From Section 4.3 in the spec: "The normal CELT layer uses 21 of those bands,
153 though Opus Custom (see Section 6.2) may use a different number of bands"
154
155 Check if it's within the maximum number of Bark frequency bands instead */
156 celt_assert(st->end <= 25){if (!(st->end <= 25)) {celt_fatal("assertion failed: "
"st->end <= 25", "/root/firefox-clang/media/libopus/celt/celt_decoder.c"
, 156);}}
;
157#endif
158 celt_assert(st->channels == 1 || st->channels == 2){if (!(st->channels == 1 || st->channels == 2)) {celt_fatal
("assertion failed: " "st->channels == 1 || st->channels == 2"
, "/root/firefox-clang/media/libopus/celt/celt_decoder.c", 158
);}}
;
159 celt_assert(st->stream_channels == 1 || st->stream_channels == 2){if (!(st->stream_channels == 1 || st->stream_channels ==
2)) {celt_fatal("assertion failed: " "st->stream_channels == 1 || st->stream_channels == 2"
, "/root/firefox-clang/media/libopus/celt/celt_decoder.c", 159
);}}
;
160 celt_assert(st->downsample > 0){if (!(st->downsample > 0)) {celt_fatal("assertion failed: "
"st->downsample > 0", "/root/firefox-clang/media/libopus/celt/celt_decoder.c"
, 160);}}
;
161 celt_assert(st->start == 0 || st->start == 17){if (!(st->start == 0 || st->start == 17)) {celt_fatal(
"assertion failed: " "st->start == 0 || st->start == 17"
, "/root/firefox-clang/media/libopus/celt/celt_decoder.c", 161
);}}
;
162 celt_assert(st->start < st->end){if (!(st->start < st->end)) {celt_fatal("assertion failed: "
"st->start < st->end", "/root/firefox-clang/media/libopus/celt/celt_decoder.c"
, 162);}}
;
163#ifdef OPUS_ARCHMASK7
164 celt_assert(st->arch >= 0){if (!(st->arch >= 0)) {celt_fatal("assertion failed: "
"st->arch >= 0", "/root/firefox-clang/media/libopus/celt/celt_decoder.c"
, 164);}}
;
165 celt_assert(st->arch <= OPUS_ARCHMASK){if (!(st->arch <= 7)) {celt_fatal("assertion failed: "
"st->arch <= OPUS_ARCHMASK", "/root/firefox-clang/media/libopus/celt/celt_decoder.c"
, 165);}}
;
166#endif
167#ifndef ENABLE_QEXT
168 celt_assert(st->last_pitch_index <= PLC_PITCH_LAG_MAX){if (!(st->last_pitch_index <= (720))) {celt_fatal("assertion failed: "
"st->last_pitch_index <= PLC_PITCH_LAG_MAX", "/root/firefox-clang/media/libopus/celt/celt_decoder.c"
, 168);}}
;
169 celt_assert(st->last_pitch_index >= PLC_PITCH_LAG_MIN || st->last_pitch_index == 0){if (!(st->last_pitch_index >= (100) || st->last_pitch_index
== 0)) {celt_fatal("assertion failed: " "st->last_pitch_index >= PLC_PITCH_LAG_MIN || st->last_pitch_index == 0"
, "/root/firefox-clang/media/libopus/celt/celt_decoder.c", 169
);}}
;
170#endif
171 celt_assert(st->postfilter_period < MAX_PERIOD){if (!(st->postfilter_period < 1024)) {celt_fatal("assertion failed: "
"st->postfilter_period < MAX_PERIOD", "/root/firefox-clang/media/libopus/celt/celt_decoder.c"
, 171);}}
;
172 celt_assert(st->postfilter_period >= COMBFILTER_MINPERIOD || st->postfilter_period == 0){if (!(st->postfilter_period >= 15 || st->postfilter_period
== 0)) {celt_fatal("assertion failed: " "st->postfilter_period >= COMBFILTER_MINPERIOD || st->postfilter_period == 0"
, "/root/firefox-clang/media/libopus/celt/celt_decoder.c", 172
);}}
;
173 celt_assert(st->postfilter_period_old < MAX_PERIOD){if (!(st->postfilter_period_old < 1024)) {celt_fatal("assertion failed: "
"st->postfilter_period_old < MAX_PERIOD", "/root/firefox-clang/media/libopus/celt/celt_decoder.c"
, 173);}}
;
174 celt_assert(st->postfilter_period_old >= COMBFILTER_MINPERIOD || st->postfilter_period_old == 0){if (!(st->postfilter_period_old >= 15 || st->postfilter_period_old
== 0)) {celt_fatal("assertion failed: " "st->postfilter_period_old >= COMBFILTER_MINPERIOD || st->postfilter_period_old == 0"
, "/root/firefox-clang/media/libopus/celt/celt_decoder.c", 174
);}}
;
175 celt_assert(st->postfilter_tapset <= 2){if (!(st->postfilter_tapset <= 2)) {celt_fatal("assertion failed: "
"st->postfilter_tapset <= 2", "/root/firefox-clang/media/libopus/celt/celt_decoder.c"
, 175);}}
;
176 celt_assert(st->postfilter_tapset >= 0){if (!(st->postfilter_tapset >= 0)) {celt_fatal("assertion failed: "
"st->postfilter_tapset >= 0", "/root/firefox-clang/media/libopus/celt/celt_decoder.c"
, 176);}}
;
177 celt_assert(st->postfilter_tapset_old <= 2){if (!(st->postfilter_tapset_old <= 2)) {celt_fatal("assertion failed: "
"st->postfilter_tapset_old <= 2", "/root/firefox-clang/media/libopus/celt/celt_decoder.c"
, 177);}}
;
178 celt_assert(st->postfilter_tapset_old >= 0){if (!(st->postfilter_tapset_old >= 0)) {celt_fatal("assertion failed: "
"st->postfilter_tapset_old >= 0", "/root/firefox-clang/media/libopus/celt/celt_decoder.c"
, 178);}}
;
179}
180#endif
181
182int celt_decoder_get_size(int channels)
183{
184#ifdef ENABLE_QEXT
185 const CELTModeOpusCustomMode *mode = opus_custom_mode_create(96000, 960, NULL((void*)0));
186#else
187 const CELTModeOpusCustomMode *mode = opus_custom_mode_create(48000, 960, NULL((void*)0));
188#endif
189 return opus_custom_decoder_get_size(mode, channels);
190}
191
192OPUS_CUSTOM_NOSTATICstatic inline int opus_custom_decoder_get_size(const CELTModeOpusCustomMode *mode, int channels)
193{
194 int size;
195#ifdef ENABLE_QEXT
196 int qext_scale;
197 if (mode->Fs == 96000 && (mode->shortMdctSize==240 || mode->shortMdctSize==180)) {
198 qext_scale = 2;
199 } else qext_scale = 1;
200#endif
201 size = sizeof(struct CELTDecoderOpusCustomDecoder)
202 + (channels*(QEXT_SCALE(DECODE_BUFFER_SIZE)(2048)+mode->overlap)-1)*sizeof(celt_sig)
203 + 4*2*mode->nbEBands*sizeof(celt_glog)
204 + channels*CELT_LPC_ORDER24*sizeof(opus_val16);
205 return size;
206}
207
208#if defined(CUSTOM_MODES) || defined(ENABLE_OPUS_CUSTOM_API)
209CELTDecoderOpusCustomDecoder *opus_custom_decoder_create(const CELTModeOpusCustomMode *mode, int channels, int *error)
210{
211 int ret;
212 CELTDecoderOpusCustomDecoder *st = (CELTDecoderOpusCustomDecoder *)opus_alloc(opus_custom_decoder_get_size(mode, channels));
213 ret = opus_custom_decoder_init(st, mode, channels);
214 if (ret != OPUS_OK0)
215 {
216 opus_custom_decoder_destroy(st);
217 st = NULL((void*)0);
218 }
219 if (error)
220 *error = ret;
221 return st;
222}
223#endif /* CUSTOM_MODES */
224
225int celt_decoder_init(CELTDecoderOpusCustomDecoder *st, opus_int32 sampling_rate, int channels)
226{
227 int ret;
228#ifdef ENABLE_QEXT
229 if (sampling_rate == 96000) {
230 return opus_custom_decoder_init(st, opus_custom_mode_create(96000, 960, NULL((void*)0)), channels);
231 }
232#endif
233 ret = opus_custom_decoder_init(st, opus_custom_mode_create(48000, 960, NULL((void*)0)), channels);
234 if (ret != OPUS_OK0)
235 return ret;
236 st->downsample = resampling_factor(sampling_rate);
237 if (st->downsample==0)
238 return OPUS_BAD_ARG-1;
239 else
240 return OPUS_OK0;
241}
242
243OPUS_CUSTOM_NOSTATICstatic inline int opus_custom_decoder_init(CELTDecoderOpusCustomDecoder *st, const CELTModeOpusCustomMode *mode, int channels)
244{
245 if (channels < 0 || channels > 2)
246 return OPUS_BAD_ARG-1;
247
248 if (st==NULL((void*)0))
249 return OPUS_ALLOC_FAIL-7;
250
251 OPUS_CLEAR((char*)st, opus_custom_decoder_get_size(mode, channels))(memset(((char*)st), 0, (opus_custom_decoder_get_size(mode, channels
))*sizeof(*((char*)st))))
;
252
253 st->mode = mode;
254 st->overlap = mode->overlap;
255 st->stream_channels = st->channels = channels;
256
257 st->downsample = 1;
258 st->start = 0;
259 st->end = st->mode->effEBands;
260 st->signalling = 1;
261#ifndef DISABLE_UPDATE_DRAFT
262 st->disable_inv = channels == 1;
263#else
264 st->disable_inv = 0;
265#endif
266 st->arch = opus_select_arch();
267
268#ifdef ENABLE_QEXT
269 if (st->mode->Fs == 96000 && (mode->shortMdctSize==240 || mode->shortMdctSize==180)) st->qext_scale = 2;
270 else st->qext_scale = 1;
271#endif
272
273 opus_custom_decoder_ctl(st, OPUS_RESET_STATE4028);
274
275 return OPUS_OK0;
276}
277
278#if defined(CUSTOM_MODES) || defined(ENABLE_OPUS_CUSTOM_API)
279void opus_custom_decoder_destroy(CELTDecoderOpusCustomDecoder *st)
280{
281 opus_free(st);
282}
283#endif /* CUSTOM_MODES */
284
285/* Single-channel de-emphasis scalar reference (mono, downsample==1, !accum).
286 Matches the inner loop used inside deemphasis() below; non-static so the
287 runtime dispatch table can take its address. */
288opus_val32 celt_deemphasis_c(opus_res *y, const opus_val32 *x, opus_val16 coef0,
289 opus_val32 m, int N)
290{
291 int j;
292 for (j=0;j<N;j++)
293 {
294 celt_sig tmp = SATURATE(x[j] + VERY_SMALL + m, SIG_SAT)(x[j] + 1e-30f + m);
295 m = MULT16_32_Q15(coef0, tmp)((coef0)*(tmp));
296 y[j] = SIG2RES(tmp)((1/32768.f)*(tmp));
297 }
298 return m;
299}
300
301/* Special case for stereo with no downsampling and no accumulation. This is
302 quite common and we can make it faster by processing both channels in the
303 same loop, reducing overhead due to the dependency loop in the IIR filter.
304 Non-static so the runtime dispatch table can take its address. */
305void deemphasis_stereo_simple_c(celt_sig *in[], opus_res *pcm, int N, opus_val16 coef0,
306 celt_sig *mem)
307{
308 celt_sig * OPUS_RESTRICTrestrict x0;
309 celt_sig * OPUS_RESTRICTrestrict x1;
310 celt_sig m0, m1;
311 int j;
312 x0=in[0];
313 x1=in[1];
314 m0 = mem[0];
315 m1 = mem[1];
316 for (j=0;j<N;j++)
317 {
318 celt_sig tmp0, tmp1;
319 /* Add VERY_SMALL to x[] first to reduce dependency chain. */
320 tmp0 = SATURATE(x0[j] + VERY_SMALL + m0, SIG_SAT)(x0[j] + 1e-30f + m0);
321 tmp1 = SATURATE(x1[j] + VERY_SMALL + m1, SIG_SAT)(x1[j] + 1e-30f + m1);
322 m0 = MULT16_32_Q15(coef0, tmp0)((coef0)*(tmp0));
323 m1 = MULT16_32_Q15(coef0, tmp1)((coef0)*(tmp1));
324 pcm[2*j ] = SIG2RES(tmp0)((1/32768.f)*(tmp0));
325 pcm[2*j+1] = SIG2RES(tmp1)((1/32768.f)*(tmp1));
326 }
327 mem[0] = m0;
328 mem[1] = m1;
329}
330
331#ifndef RESYNTH
332static
333#endif
334void deemphasis(celt_sig *in[], opus_res *pcm, int N, int C, int downsample, const opus_val16 *coef,
335 celt_sig *mem, int accum, int arch)
336{
337 int c;
338 int Nd;
339 int apply_downsampling=0;
340 opus_val16 coef0;
341 VARDECL(celt_sig, scratch)celt_sig *scratch;
342 SAVE_STACK;
343#if !defined(CUSTOM_MODES) && !defined(ENABLE_OPUS_CUSTOM_API) && !defined(ENABLE_QEXT)
344 /* Short version for common case. */
345 if (downsample == 1 && C == 2 && !accum)
346 {
347 deemphasis_stereo_simple(in, pcm, N, coef[0], mem, arch)((void)(arch), deemphasis_stereo_simple_c(in, pcm, N, coef[0]
, mem))
;
348 return;
349 }
350#endif
351 (void)arch;
352 ALLOC(scratch, N, celt_sig)scratch = ((celt_sig*)__builtin_alloca (sizeof(celt_sig)*(N))
)
;
353 coef0 = coef[0];
354 Nd = N/downsample;
355 c=0; do {
356 int j;
357 celt_sig * OPUS_RESTRICTrestrict x;
358 opus_res * OPUS_RESTRICTrestrict y;
359 celt_sig m = mem[c];
360 x =in[c];
361 y = pcm+c;
362#if defined(CUSTOM_MODES) || defined(ENABLE_OPUS_CUSTOM_API) || defined(ENABLE_QEXT)
363 if (coef[1] != 0)
364 {
365 opus_val16 coef1 = coef[1];
366 opus_val16 coef3 = coef[3];
367 for (j=0;j<N;j++)
368 {
369 celt_sig tmp = SATURATE(x[j] + m + VERY_SMALL, SIG_SAT)(x[j] + m + 1e-30f);
370 m = MULT16_32_Q15(coef0, tmp)((coef0)*(tmp))
371 - MULT16_32_Q15(coef1, x[j])((coef1)*(x[j]));
372 tmp = SHL32(MULT16_32_Q15(coef3, tmp), 2)(((coef3)*(tmp)));
373 scratch[j] = tmp;
374 }
375 apply_downsampling=1;
376 } else
377#endif
378 if (downsample>1)
379 {
380 /* Shortcut for the standard (non-custom modes) case */
381 for (j=0;j<N;j++)
382 {
383 celt_sig tmp = SATURATE(x[j] + VERY_SMALL + m, SIG_SAT)(x[j] + 1e-30f + m);
384 m = MULT16_32_Q15(coef0, tmp)((coef0)*(tmp));
385 scratch[j] = tmp;
386 }
387 apply_downsampling=1;
388 } else {
389 /* Shortcut for the standard (non-custom modes) case */
390 if (accum)
391 {
392 for (j=0;j<N;j++)
393 {
394 celt_sig tmp = SATURATE(x[j] + m + VERY_SMALL, SIG_SAT)(x[j] + m + 1e-30f);
395 m = MULT16_32_Q15(coef0, tmp)((coef0)*(tmp));
396 y[j*C] = ADD_RES(y[j*C], SIG2RES(tmp))((y[j*C])+(((1/32768.f)*(tmp))));
397 }
398 } else if (C == 1)
399 {
400 /* Mono: contiguous output, dispatch through celt_deemphasis()
401 so the ARM NEON kernel can be used on aarch64. */
402 m = celt_deemphasis(y, x, coef0, m, N, arch)((void)(arch), celt_deemphasis_c(y, x, coef0, m, N));
403 } else
404 {
405 for (j=0;j<N;j++)
406 {
407 celt_sig tmp = SATURATE(x[j] + VERY_SMALL + m, SIG_SAT)(x[j] + 1e-30f + m);
408 m = MULT16_32_Q15(coef0, tmp)((coef0)*(tmp));
409 y[j*C] = SIG2RES(tmp)((1/32768.f)*(tmp));
410 }
411 }
412 }
413 mem[c] = m;
414
415 if (apply_downsampling)
416 {
417 /* Perform down-sampling */
418 if (accum)
419 {
420 for (j=0;j<Nd;j++)
421 y[j*C] = ADD_RES(y[j*C], SIG2RES(scratch[j*downsample]))((y[j*C])+(((1/32768.f)*(scratch[j*downsample]))));
422 } else
423 {
424 for (j=0;j<Nd;j++)
425 y[j*C] = SIG2RES(scratch[j*downsample])((1/32768.f)*(scratch[j*downsample]));
426 }
427 }
428 } while (++c<C);
429 RESTORE_STACK;
430}
431
432#ifndef RESYNTH
433static
434#endif
435void celt_synthesis(const CELTModeOpusCustomMode *mode, celt_norm *X, celt_sig * out_syn[],
436 celt_glog *oldBandE, int start, int effEnd, int C, int CC,
437 int isTransient, int LM, int downsample,
438 int silence, int arch ARG_QEXT(const CELTMode *qext_mode) ARG_QEXT(const celt_glog *qext_bandLogE) ARG_QEXT(int qext_end))
439{
440 int c, i;
441 int M;
442 int b;
443 int B;
444 int N, NB;
445 int shift;
446 int nbEBands;
447 int overlap;
448 VARDECL(celt_sig, freq)celt_sig *freq;
449 SAVE_STACK;
450
451 overlap = mode->overlap;
452 nbEBands = mode->nbEBands;
453 N = mode->shortMdctSize<<LM;
454 ALLOC(freq, N, celt_sig)freq = ((celt_sig*)__builtin_alloca (sizeof(celt_sig)*(N))); /**< Interleaved signal MDCTs */
455 M = 1<<LM;
456#ifdef ENABLE_QEXT
457 if (mode->Fs != 96000) qext_end=2;
458#endif
459
460 if (isTransient)
461 {
462 B = M;
463 NB = mode->shortMdctSize;
464 shift = mode->maxLM;
465 } else {
466 B = 1;
467 NB = mode->shortMdctSize<<LM;
468 shift = mode->maxLM-LM;
469 }
470
471 if (CC==2&&C==1)
472 {
473 /* Copying a mono streams to two channels */
474 celt_sig *freq2;
475 denormalise_bands(mode, X, freq, oldBandE, start, effEnd, M,
476 downsample, silence);
477#ifdef ENABLE_QEXT
478 if (qext_mode)
479 denormalise_bands(qext_mode, X, freq, qext_bandLogE, 0, qext_end, M,
480 downsample, silence);
481#endif
482 /* Store a temporary copy in the output buffer because the IMDCT destroys its input. */
483 freq2 = out_syn[1]+overlap/2;
484 OPUS_COPY(freq2, freq, N)(memcpy((freq2), (freq), (N)*sizeof(*(freq2)) + 0*((freq2)-(freq
)) ))
;
485 for (b=0;b<B;b++)
486 clt_mdct_backward(&mode->mdct, &freq2[b], out_syn[0]+NB*b, mode->window, overlap, shift, B, arch)clt_mdct_backward_c(&mode->mdct, &freq2[b], out_syn
[0]+NB*b, mode->window, overlap, shift, B, arch)
;
487 for (b=0;b<B;b++)
488 clt_mdct_backward(&mode->mdct, &freq[b], out_syn[1]+NB*b, mode->window, overlap, shift, B, arch)clt_mdct_backward_c(&mode->mdct, &freq[b], out_syn
[1]+NB*b, mode->window, overlap, shift, B, arch)
;
489 } else if (CC==1&&C==2)
490 {
491 /* Downmixing a stereo stream to mono */
492 celt_sig *freq2;
493 freq2 = out_syn[0]+overlap/2;
494 denormalise_bands(mode, X, freq, oldBandE, start, effEnd, M,
495 downsample, silence);
496 /* Use the output buffer as temp array before downmixing. */
497 denormalise_bands(mode, X+N, freq2, oldBandE+nbEBands, start, effEnd, M,
498 downsample, silence);
499#ifdef ENABLE_QEXT
500 if (qext_mode)
501 {
502 denormalise_bands(qext_mode, X, freq, qext_bandLogE, 0, qext_end, M,
503 downsample, silence);
504 denormalise_bands(qext_mode, X+N, freq2, qext_bandLogE+NB_QEXT_BANDS, 0, qext_end, M,
505 downsample, silence);
506 }
507#endif
508 for (i=0;i<N;i++)
509 freq[i] = ADD32(HALF32(freq[i]), HALF32(freq2[i]))(((.5f*(freq[i])))+((.5f*(freq2[i]))));
510 for (b=0;b<B;b++)
511 clt_mdct_backward(&mode->mdct, &freq[b], out_syn[0]+NB*b, mode->window, overlap, shift, B, arch)clt_mdct_backward_c(&mode->mdct, &freq[b], out_syn
[0]+NB*b, mode->window, overlap, shift, B, arch)
;
512 } else {
513 /* Normal case (mono or stereo) */
514 c=0; do {
515 denormalise_bands(mode, X+c*N, freq, oldBandE+c*nbEBands, start, effEnd, M,
516 downsample, silence);
517#ifdef ENABLE_QEXT
518 if (qext_mode)
519 denormalise_bands(qext_mode, X+c*N, freq, qext_bandLogE+c*NB_QEXT_BANDS, 0, qext_end, M,
520 downsample, silence);
521#endif
522 for (b=0;b<B;b++)
523 clt_mdct_backward(&mode->mdct, &freq[b], out_syn[c]+NB*b, mode->window, overlap, shift, B, arch)clt_mdct_backward_c(&mode->mdct, &freq[b], out_syn
[c]+NB*b, mode->window, overlap, shift, B, arch)
;
524 } while (++c<CC);
525 }
526 /* Saturate IMDCT output so that we can't overflow in the pitch postfilter
527 or in the */
528 c=0; do {
529 for (i=0;i<N;i++)
530 out_syn[c][i] = SATURATE(out_syn[c][i], SIG_SAT)(out_syn[c][i]);
531 } while (++c<CC);
532 RESTORE_STACK;
533}
534
535static void tf_decode(int start, int end, int isTransient, int *tf_res, int LM, ec_dec *dec)
536{
537 int i, curr, tf_select;
538 int tf_select_rsv;
539 int tf_changed;
540 int logp;
541 opus_uint32 budget;
542 opus_uint32 tell;
543
544 budget = dec->storage*8;
545 tell = ec_tell(dec);
546 logp = isTransient ? 2 : 4;
547 tf_select_rsv = LM>0 && tell+logp+1<=budget;
548 budget -= tf_select_rsv;
549 tf_changed = curr = 0;
550 for (i=start;i<end;i++)
551 {
552 if (tell+logp<=budget)
553 {
554 curr ^= ec_dec_bit_logp(dec, logp);
555 tell = ec_tell(dec);
556 tf_changed |= curr;
557 }
558 tf_res[i] = curr;
559 logp = isTransient ? 4 : 5;
560 }
561 tf_select = 0;
562 if (tf_select_rsv &&
563 tf_select_table[LM][4*isTransient+0+tf_changed] !=
564 tf_select_table[LM][4*isTransient+2+tf_changed])
565 {
566 tf_select = ec_dec_bit_logp(dec, 1);
567 }
568 for (i=start;i<end;i++)
569 {
570 tf_res[i] = tf_select_table[LM][4*isTransient+2*tf_select+tf_res[i]];
571 }
572}
573
574static int celt_plc_pitch_search(CELTDecoderOpusCustomDecoder *st, celt_sig *decode_mem[2], int C, int arch)
575{
576 int pitch_index;
577#ifdef ENABLE_QEXT
578 int qext_scale;
579#endif
580 VARDECL( opus_val16, lp_pitch_buf )opus_val16 *lp_pitch_buf;
581 SAVE_STACK;
582#ifdef ENABLE_QEXT
583 qext_scale = st->qext_scale;
584#else
585 (void)st;
586#endif
587 ALLOC( lp_pitch_buf, DECODE_BUFFER_SIZE>>1, opus_val16 )lp_pitch_buf = ((opus_val16*)__builtin_alloca (sizeof(opus_val16
)*(2048>>1)))
;
588 pitch_downsample(decode_mem, lp_pitch_buf,
589 DECODE_BUFFER_SIZE2048>>1, C, QEXT_SCALE(2)(2), arch);
590 pitch_search(lp_pitch_buf+(PLC_PITCH_LAG_MAX(720)>>1), lp_pitch_buf,
591 DECODE_BUFFER_SIZE2048-PLC_PITCH_LAG_MAX(720),
592 PLC_PITCH_LAG_MAX(720)-PLC_PITCH_LAG_MIN(100), &pitch_index, arch);
593 pitch_index = PLC_PITCH_LAG_MAX(720)-pitch_index;
594 RESTORE_STACK;
595 return QEXT_SCALE(pitch_index)(pitch_index);
596}
597
598static void prefilter_and_fold(CELTDecoderOpusCustomDecoder * OPUS_RESTRICTrestrict st, int N)
599{
600 int c;
601 int CC;
602 int i;
603 int overlap;
604 celt_sig *decode_mem[2];
605 const OpusCustomMode *mode;
606 int decode_buffer_size;
607#ifdef ENABLE_QEXT
608 int qext_scale;
609#endif
610 VARDECL(opus_val32, etmp)opus_val32 *etmp;
611 SAVE_STACK
612#ifdef ENABLE_QEXT
613 qext_scale = st->qext_scale;
614#endif
615 decode_buffer_size = QEXT_SCALE(DECODE_BUFFER_SIZE)(2048);
616 mode = st->mode;
617 overlap = st->overlap;
618 CC = st->channels;
619 ALLOC(etmp, overlap, opus_val32)etmp = ((opus_val32*)__builtin_alloca (sizeof(opus_val32)*(overlap
)))
;
620 c=0; do {
621 decode_mem[c] = st->_decode_mem + c*(decode_buffer_size+overlap);
622 } while (++c<CC);
623
624 c=0; do {
625 /* Apply the pre-filter to the MDCT overlap for the next frame because
626 the post-filter will be re-applied in the decoder after the MDCT
627 overlap. */
628 comb_filter(etmp, decode_mem[c]+decode_buffer_size-N,
629 st->postfilter_period_old, st->postfilter_period, overlap,
630 -st->postfilter_gain_old, -st->postfilter_gain,
631 st->postfilter_tapset_old, st->postfilter_tapset, NULL((void*)0), 0, st->arch ARG_QEXT(qext_scale));
632
633 /* Simulate TDAC on the concealed audio so that it blends with the
634 MDCT of the next frame. */
635 for (i=0;i<overlap/2;i++)
636 {
637 decode_mem[c][decode_buffer_size-N+i] =
638 MULT16_32_Q15(COEF2VAL16(mode->window[i]), etmp[overlap-1-i])(((mode->window[i]))*(etmp[overlap-1-i]))
639 + MULT16_32_Q15 (COEF2VAL16(mode->window[overlap-i-1]), etmp[i])(((mode->window[overlap-i-1]))*(etmp[i]));
640 }
641 } while (++c<CC);
642 RESTORE_STACK;
643}
644
645#ifdef ENABLE_DEEP_PLC
646
647#define SINC_ORDER 48
648/* h=cos(pi/2*abs(sin([-24:24]/48*pi*23./24)).^2);
649 b=sinc([-24:24]/3*1.02).*h;
650 b=b/sum(b); */
651static const float sinc_filter[SINC_ORDER+1] = {
652 4.2931e-05f, -0.000190293f, -0.000816132f, -0.000637162f, 0.00141662f, 0.00354764f, 0.00184368f, -0.00428274f,
653 -0.00856105f, -0.0034003f, 0.00930201f, 0.0159616f, 0.00489785f, -0.0169649f, -0.0259484f, -0.00596856f,
654 0.0286551f, 0.0405872f, 0.00649994f, -0.0509284f, -0.0716655f, -0.00665212f, 0.134336f, 0.278927f,
655 0.339995f, 0.278927f, 0.134336f, -0.00665212f, -0.0716655f, -0.0509284f, 0.00649994f, 0.0405872f,
656 0.0286551f, -0.00596856f, -0.0259484f, -0.0169649f, 0.00489785f, 0.0159616f, 0.00930201f, -0.0034003f,
657 -0.00856105f, -0.00428274f, 0.00184368f, 0.00354764f, 0.00141662f, -0.000637162f, -0.000816132f, -0.000190293f,
658 4.2931e-05f
659};
660
661void update_plc_state(LPCNetPLCState *lpcnet, celt_sig *decode_mem[2], float *plc_preemphasis_mem, int CC)
662{
663 int i;
664 int tmp_read_post, tmp_fec_skip;
665 int offset;
666 VARDECL(celt_sig, buf48k)celt_sig *buf48k;
667 VARDECL(opus_int16, buf16k)opus_int16 *buf16k;
668 SAVE_STACK;
669 ALLOC(buf48k, DECODE_BUFFER_SIZE, celt_sig)buf48k = ((celt_sig*)__builtin_alloca (sizeof(celt_sig)*(2048
)))
;
670 ALLOC(buf16k, PLC_UPDATE_SAMPLES, opus_int16)buf16k = ((opus_int16*)__builtin_alloca (sizeof(opus_int16)*(
(4*FRAME_SIZE))))
;
671 if (CC == 1) OPUS_COPY(buf48k, decode_mem[0], DECODE_BUFFER_SIZE)(memcpy((buf48k), (decode_mem[0]), (2048)*sizeof(*(buf48k)) +
0*((buf48k)-(decode_mem[0])) ))
;
672 else {
673 for (i=0;i<DECODE_BUFFER_SIZE2048;i++) {
674 buf48k[i] = .5*(decode_mem[0][i] + decode_mem[1][i]);
675 }
676 }
677 /* Down-sample the last 40 ms. */
678 for (i=1;i<DECODE_BUFFER_SIZE2048;i++) buf48k[i] += PREEMPHASIS*buf48k[i-1];
679 *plc_preemphasis_mem = buf48k[DECODE_BUFFER_SIZE2048-1];
680 offset = DECODE_BUFFER_SIZE2048-SINC_ORDER-1 - 3*(PLC_UPDATE_SAMPLES(4*FRAME_SIZE)-1);
681 celt_assert(3*(PLC_UPDATE_SAMPLES-1) + SINC_ORDER + offset == DECODE_BUFFER_SIZE-1){if (!(3*((4*FRAME_SIZE)-1) + SINC_ORDER + offset == 2048 -1)
) {celt_fatal("assertion failed: " "3*(PLC_UPDATE_SAMPLES-1) + SINC_ORDER + offset == DECODE_BUFFER_SIZE-1"
, "/root/firefox-clang/media/libopus/celt/celt_decoder.c", 681
);}}
;
682 for (i=0;i<PLC_UPDATE_SAMPLES(4*FRAME_SIZE);i++) {
683 int j;
684 float sum = 0;
685 for (j=0;j<SINC_ORDER+1;j++) {
686 sum += buf48k[3*i + j + offset]*sinc_filter[j];
687 }
688 buf16k[i] = float2int(MIN32(32767.f, MAX32(-32767.f, sum))((32767.f) < (((-32767.f) > (sum) ? (-32767.f) : (sum))
) ? (32767.f) : (((-32767.f) > (sum) ? (-32767.f) : (sum))
))
);
689 }
690 tmp_read_post = lpcnet->fec_read_pos;
691 tmp_fec_skip = lpcnet->fec_skip;
692 for (i=0;i<PLC_UPDATE_FRAMES4;i++) {
693 lpcnet_plc_update(lpcnet, &buf16k[FRAME_SIZE*i]);
694 }
695 lpcnet->fec_read_pos = tmp_read_post;
696 lpcnet->fec_skip = tmp_fec_skip;
697 RESTORE_STACK;
698}
699#endif
700
701static void celt_decode_lost(CELTDecoderOpusCustomDecoder * OPUS_RESTRICTrestrict st, int N, int LM
702#ifdef ENABLE_DEEP_PLC
703 ,LPCNetPLCState *lpcnet
704#endif
705 )
706{
707 int c;
708 int i;
709 const int C = st->channels;
710 celt_sig *decode_mem[2];
711 celt_sig *out_syn[2];
712 opus_val16 *lpc;
713 celt_glog *oldBandE, *oldLogE, *oldLogE2, *backgroundLogE;
714 const OpusCustomMode *mode;
715 int nbEBands;
716 int overlap;
717 int start;
718 int loss_duration;
719 int curr_frame_type;
720 const opus_int16 *eBands;
721 int decode_buffer_size;
722 int max_period;
723#ifdef ENABLE_QEXT
724 int qext_scale;
725#endif
726 SAVE_STACK;
727#ifdef ENABLE_QEXT
728 qext_scale = st->qext_scale;
729#endif
730 decode_buffer_size = QEXT_SCALE(DECODE_BUFFER_SIZE)(2048);
731 max_period = QEXT_SCALE(MAX_PERIOD)(1024);
732 mode = st->mode;
733 nbEBands = mode->nbEBands;
734 overlap = mode->overlap;
735 eBands = mode->eBands;
736
737 c=0; do {
2
Loop condition is false. Exiting loop
738 decode_mem[c] = st->_decode_mem + c*(decode_buffer_size+overlap);
739 out_syn[c] = decode_mem[c]+decode_buffer_size-N;
740 } while (++c<C);
1
Assuming the condition is false
741 oldBandE = (celt_glog*)(st->_decode_mem+(decode_buffer_size+overlap)*C);
742 oldLogE = oldBandE + 2*nbEBands;
743 oldLogE2 = oldLogE + 2*nbEBands;
744 backgroundLogE = oldLogE2 + 2*nbEBands;
745 lpc = (opus_val16*)(backgroundLogE + 2*nbEBands);
746
747 loss_duration = st->loss_duration;
748 start = st->start;
749 curr_frame_type = FRAME_PLC_PERIODIC3;
750 if (st->plc_duration >= 40 || start != 0 || st->skip_plc)
3
Assuming field 'plc_duration' is < 40
4
Assuming 'start' is equal to 0
5
Assuming field 'skip_plc' is 0
6
Taking false branch
751 curr_frame_type = FRAME_PLC_NOISE2;
752#ifdef ENABLE_DEEP_PLC
753 if (start == 0 && lpcnet != NULL((void*)0) && st->mode->Fs != 96000 && lpcnet->loaded)
754 {
755 if (st->complexity >= 5 && st->plc_duration < 80 && !st->skip_plc)
756 curr_frame_type = FRAME_PLC_NEURAL4;
757#ifdef ENABLE_DRED
758 if (lpcnet->fec_fill_pos > lpcnet->fec_read_pos)
759 curr_frame_type = FRAME_DRED5;
760#endif
761 }
762#endif
763
764 if (curr_frame_type
6.1
'curr_frame_type' is not equal to FRAME_PLC_NOISE
== FRAME_PLC_NOISE2)
7
Taking false branch
765 {
766 /* Noise-based PLC/CNG */
767 VARDECL(celt_norm, X)celt_norm *X;
768 opus_uint32 seed;
769 int end;
770 int effEnd;
771 celt_glog decay;
772 end = st->end;
773 effEnd = IMAX(start, IMIN(end, mode->effEBands))((start) > (((end) < (mode->effEBands) ? (end) : (mode
->effEBands))) ? (start) : (((end) < (mode->effEBands
) ? (end) : (mode->effEBands))))
;
774
775 ALLOC(X, C*N, celt_norm)X = ((celt_norm*)__builtin_alloca (sizeof(celt_norm)*(C*N))); /**< Interleaved normalised MDCTs */
776 c=0; do {
777 OPUS_MOVE(decode_mem[c], decode_mem[c]+N,(memmove((decode_mem[c]), (decode_mem[c]+N), (decode_buffer_size
-N+overlap)*sizeof(*(decode_mem[c])) + 0*((decode_mem[c])-(decode_mem
[c]+N)) ))
778 decode_buffer_size-N+overlap)(memmove((decode_mem[c]), (decode_mem[c]+N), (decode_buffer_size
-N+overlap)*sizeof(*(decode_mem[c])) + 0*((decode_mem[c])-(decode_mem
[c]+N)) ))
;
779 } while (++c<C);
780
781 if (st->prefilter_and_fold) {
782 prefilter_and_fold(st, N);
783 }
784
785 /* Energy decay */
786 decay = (1<<LM)*GCONST(.0625f)(.0625f);
787 if (st->last_frame_type != FRAME_PLC_NOISE2)
788 decay += MAXG(GCONST(1.f), IMIN(160, loss_duration)*GCONST(.0625f))(((1.f)) > (((160) < (loss_duration) ? (160) : (loss_duration
))*(.0625f)) ? ((1.f)) : (((160) < (loss_duration) ? (160)
: (loss_duration))*(.0625f)))
;
789 c=0; do
790 {
791 for (i=start;i<end;i++)
792 oldBandE[c*nbEBands+i] = MAXG(backgroundLogE[c*nbEBands+i], oldBandE[c*nbEBands+i] - decay)((backgroundLogE[c*nbEBands+i]) > (oldBandE[c*nbEBands+i] -
decay) ? (backgroundLogE[c*nbEBands+i]) : (oldBandE[c*nbEBands
+i] - decay))
;
793 } while (++c<C);
794 seed = st->rng;
795 for (c=0;c<C;c++)
796 {
797 for (i=start;i<effEnd;i++)
798 {
799 int j;
800 int boffs;
801 int blen;
802 boffs = N*c+(eBands[i]<<LM);
803 blen = (eBands[i+1]-eBands[i])<<LM;
804 for (j=0;j<blen;j++)
805 {
806 seed = celt_lcg_rand(seed);
807 X[boffs+j] = SHL32((celt_norm)((opus_int32)seed>>20), NORM_SHIFT-14)((celt_norm)((opus_int32)seed>>20));
808 }
809 renormalise_vector(X+boffs, blen, Q31ONE1.0f, st->arch);
810 }
811 }
812 st->rng = seed;
813
814 celt_synthesis(mode, X, out_syn, oldBandE, start, effEnd, C, C, 0, LM, st->downsample, 0, st->arch ARG_QEXT(NULL) ARG_QEXT(NULL) ARG_QEXT(0));
815
816 /* Run the postfilter with the last parameters. */
817 c=0; do {
818 st->postfilter_period=IMAX(st->postfilter_period, COMBFILTER_MINPERIOD)((st->postfilter_period) > (15) ? (st->postfilter_period
) : (15))
;
819 st->postfilter_period_old=IMAX(st->postfilter_period_old, COMBFILTER_MINPERIOD)((st->postfilter_period_old) > (15) ? (st->postfilter_period_old
) : (15))
;
820 comb_filter(out_syn[c], out_syn[c], st->postfilter_period_old, st->postfilter_period, mode->shortMdctSize,
821 st->postfilter_gain_old, st->postfilter_gain, st->postfilter_tapset_old, st->postfilter_tapset,
822 mode->window, overlap, st->arch ARG_QEXT(qext_scale));
823 if (LM!=0)
824 comb_filter(out_syn[c]+mode->shortMdctSize, out_syn[c]+mode->shortMdctSize, st->postfilter_period, st->postfilter_period, N-mode->shortMdctSize,
825 st->postfilter_gain, st->postfilter_gain, st->postfilter_tapset, st->postfilter_tapset,
826 mode->window, overlap, st->arch ARG_QEXT(qext_scale));
827
828 } while (++c<C);
829 st->postfilter_period_old = st->postfilter_period;
830 st->postfilter_gain_old = st->postfilter_gain;
831 st->postfilter_tapset_old = st->postfilter_tapset;
832
833 st->prefilter_and_fold = 0;
834 /* Skip regular PLC until we get two consecutive packets. */
835 st->skip_plc = 1;
836 } else {
837 int exc_length;
838 /* Pitch-based PLC */
839 const celt_coef *window;
840 opus_val16 *sig;
841 opus_val16 fade = Q15ONE1.0f;
842 int pitch_index;
843 int curr_neural;
844 int last_neural;
845 VARDECL(opus_val16, _sig)opus_val16 *_sig;
846 VARDECL(opus_val16, exc)opus_val16 *exc;
847 VARDECL(celt_sig, old_overlap)celt_sig *old_overlap;
848 VARDECL(opus_val32, etmp)opus_val32 *etmp;
849
850 curr_neural = curr_frame_type
7.1
'curr_frame_type' is not equal to FRAME_PLC_NEURAL
== FRAME_PLC_NEURAL4 || curr_frame_type == FRAME_DRED5;
851 last_neural = st->last_frame_type == FRAME_PLC_NEURAL4 || st->last_frame_type == FRAME_DRED5;
8
Assuming field 'last_frame_type' is not equal to FRAME_PLC_NEURAL
9
Assuming field 'last_frame_type' is not equal to FRAME_DRED
852 if (st->last_frame_type != FRAME_PLC_PERIODIC3 && !(last_neural && curr_neural))
10
Assuming field 'last_frame_type' is equal to FRAME_PLC_PERIODIC
853 {
854 st->last_pitch_index = pitch_index = celt_plc_pitch_search(st, decode_mem, C, st->arch);
855 } else {
856 pitch_index = st->last_pitch_index;
857 if (st->plc_duration*mode->shortMdctSize >= pitch_index)
11
Assuming the condition is false
858 fade = QCONST16(.8f,15)(.8f);
859 }
860#ifdef ENABLE_DEEP_PLC
861 if (curr_neural && !last_neural) update_plc_state(lpcnet, decode_mem, &st->plc_preemphasis_mem, C);
862#endif
863
864 /* We want the excitation for 2 pitch periods in order to look for a
865 decaying signal, and at least max_period to search for pitch multiples. */
866 exc_length = IMAX(max_period, 2*pitch_index)((max_period) > (2*pitch_index) ? (max_period) : (2*pitch_index
))
;
12
Taking false branch
13
Assuming the condition is false
14
'?' condition is false
867
868 ALLOC(_sig, exc_length+CELT_LPC_ORDER, opus_val16)_sig = ((opus_val16*)__builtin_alloca (sizeof(opus_val16)*(exc_length
+24)))
;
869 ALLOC(exc, exc_length, opus_val16)exc = ((opus_val16*)__builtin_alloca (sizeof(opus_val16)*(exc_length
)))
;
870 ALLOC(old_overlap, overlap>>1, celt_sig)old_overlap = ((celt_sig*)__builtin_alloca (sizeof(celt_sig)*
(overlap>>1)))
;
871 ALLOC(etmp, overlap, opus_val32)etmp = ((opus_val32*)__builtin_alloca (sizeof(opus_val32)*(overlap
)))
;
872 sig = _sig+CELT_LPC_ORDER24;
873 window = mode->window;
874 c=0; do {
875 opus_val16 decay;
876 opus_val16 attenuation;
877 opus_val32 S1=0;
878 celt_sig *buf;
879 int extrapolation_offset;
880 int extrapolation_len;
881 int j;
882#ifdef FIXED_POINT
883 int shift1;
884#endif
885
886 pitch_index = st->last_pitch_index;
887 buf = decode_mem[c];
888 for (i=0;i<exc_length+CELT_LPC_ORDER24;i++)
15
Assuming the condition is false
889 sig[i-CELT_LPC_ORDER24] = SROUND16(buf[decode_buffer_size-exc_length-CELT_LPC_ORDER+i], SIG_SHIFT)(buf[decode_buffer_size-exc_length-24 +i]);
890
891 if (st->last_frame_type
15.1
Field 'last_frame_type' is equal to FRAME_PLC_PERIODIC
!= FRAME_PLC_PERIODIC3 && !(last_neural && curr_neural))
892 {
893 opus_val32 ac[CELT_LPC_ORDER24+1];
894 /* Compute LPC coefficients for the last max_period samples before
895 the first loss so we can work in the excitation-filter domain. */
896 _celt_autocorr(sig+exc_length-max_period, ac, window, overlap,
897 CELT_LPC_ORDER24, max_period, st->arch);
898 /* Add a noise floor of -40 dB. */
899#ifdef FIXED_POINT
900 ac[0] += SHR32(ac[0],13)(ac[0]);
901#else
902 ac[0] *= 1.0001f;
903#endif
904 /* Use lag windowing to stabilize the Levinson-Durbin recursion. */
905 for (i=1;i<=CELT_LPC_ORDER24;i++)
906 {
907 /*ac[i] *= exp(-.5*(2*M_PI*.002*i)*(2*M_PI*.002*i));*/
908#ifdef FIXED_POINT
909 ac[i] -= MULT16_32_Q15(2*i*i, ac[i])((2*i*i)*(ac[i]));
910#else
911 ac[i] -= ac[i]*(0.008f*0.008f)*i*i;
912#endif
913 }
914 _celt_lpc(lpc+c*CELT_LPC_ORDER24, ac, CELT_LPC_ORDER24);
915#ifdef FIXED_POINT
916 /* For fixed-point, apply bandwidth expansion until we can guarantee that
917 no overflow can happen in the IIR filter. This means:
918 32768*sum(abs(filter)) < 2^31 */
919 while (1) {
920 opus_val16 tmp=Q15ONE1.0f;
921 opus_val32 sum=QCONST16(1., SIG_SHIFT)(1.);
922 for (i=0;i<CELT_LPC_ORDER24;i++)
923 sum += ABS16(lpc[c*CELT_LPC_ORDER+i])((float)fabs(lpc[c*24 +i]));
924 if (sum < 65535) break;
925 for (i=0;i<CELT_LPC_ORDER24;i++)
926 {
927 tmp = MULT16_16_Q15(QCONST16(.99f,15), tmp)(((.99f))*(tmp));
928 lpc[c*CELT_LPC_ORDER24+i] = MULT16_16_Q15(lpc[c*CELT_LPC_ORDER+i], tmp)((lpc[c*24 +i])*(tmp));
929 }
930 }
931#endif
932 }
933 /* Initialize the LPC history with the samples just before the start
934 of the region for which we're computing the excitation. */
935 celt_fir(sig, lpc+c*CELT_LPC_ORDER, exc, exc_length, CELT_LPC_ORDER, st->arch)(celt_fir_c(sig, lpc+c*24, exc, exc_length, 24, st->arch));
936
937 /* Check if the waveform is decaying, and if so how fast.
938 We do this to avoid adding energy when concealing in a segment
939 with decaying energy. */
940 if (st->last_frame_type
15.2
Field 'last_frame_type' is equal to FRAME_PLC_PERIODIC
!= FRAME_PLC_PERIODIC3 && !(last_neural && curr_neural))
941 {
942 opus_val32 E1=1, E2=1;
943#ifdef FIXED_POINT
944 int shift = IMAX(0,2*celt_zlog2(celt_maxabs16(&exc[exc_length-2*pitch_index], 2*pitch_index))-19)((0) > (2*celt_zlog2(celt_maxabs16(&exc[exc_length-2*pitch_index
], 2*pitch_index))-19) ? (0) : (2*celt_zlog2(celt_maxabs16(&
exc[exc_length-2*pitch_index], 2*pitch_index))-19))
;
945#ifdef ENABLE_QEXT
946 if (st->qext_scale==2) shift++;
947#endif
948#endif
949 for (i=0;i<pitch_index;i++)
950 {
951 opus_val16 e;
952 e = exc[exc_length-pitch_index+i];
953 E1 += SHR32(MULT16_16(e, e), shift)(((opus_val32)(e)*(opus_val32)(e)));
954 e = exc[exc_length-2*pitch_index+i];
955 E2 += SHR32(MULT16_16(e, e), shift)(((opus_val32)(e)*(opus_val32)(e)));
956 }
957 E1 = MIN32(E1, E2)((E1) < (E2) ? (E1) : (E2));
958 st->plc_decay[c] = decay = celt_sqrt(frac_div32(SHR32(E1, 1), E2))((float)sqrt(((float)((E1))/(E2))));
959 } else {
960 decay = st->plc_decay[c];
961 }
962 /* Use a large integer multiple of the pitch period to avoid repeating
963 a short sequence too many times, stopping before any >6 dB change. */
964 {
965 int k, K;
966 opus_val32 E0=1;
967#ifdef FIXED_POINT
968 int shift = IMAX(0, 2*celt_zlog2(celt_maxabs16(exc, exc_length))-19)((0) > (2*celt_zlog2(celt_maxabs16(exc, exc_length))-19) ?
(0) : (2*celt_zlog2(celt_maxabs16(exc, exc_length))-19))
;
969#ifdef ENABLE_QEXT
970 if (st->qext_scale==2) shift++;
971#endif
972#endif
973 K = exc_length/pitch_index;
974 for (i=0;i<pitch_index;i++)
16
Assuming 'i' is >= 'pitch_index'
17
Loop condition is false. Execution continues on line 979
975 {
976 opus_val16 e = exc[exc_length-pitch_index+i];
977 E0 += SHR32(MULT16_16(e, e), shift)(((opus_val32)(e)*(opus_val32)(e)));
978 }
979 for (k=2;k<=K;k++)
18
Assuming 'k' is <= 'K'
19
Loop condition is true. Entering loop body
23
Assuming 'k' is > 'K'
24
Loop condition is false. Execution continues on line 991
980 {
981 opus_val32 Ek=1;
982 for (i=0;i
19.1
'i' is >= 'pitch_index'
<pitch_index;i++)
983 {
984 opus_val16 e = exc[exc_length-k*pitch_index+i];
985 Ek += SHR32(MULT16_16(e, e), shift)(((opus_val32)(e)*(opus_val32)(e)));
986 }
987 if (Ek < MULT16_32_Q15(QCONST16(.25f, 15), E0)(((.25f))*(E0))
20
Assuming the condition is false
22
Taking false branch
988 || E0 < MULT16_32_Q15(QCONST16(.25f, 15), Ek)(((.25f))*(Ek)))
21
Assuming the condition is false
989 break;
990 }
991 pitch_index *= k-1;
992 }
993
994 /* Save the folded right-overlap tail from the previous MDCT frame before
995 moving the decoder memory one frame to the left. */
996 if (st->last_frame_type
24.1
Field 'last_frame_type' is not equal to FRAME_NORMAL
== FRAME_NORMAL1)
25
Taking false branch
997 OPUS_COPY(old_overlap, &buf[decode_buffer_size], overlap>>1)(memcpy((old_overlap), (&buf[decode_buffer_size]), (overlap
>>1)*sizeof(*(old_overlap)) + 0*((old_overlap)-(&buf
[decode_buffer_size])) ))
;
998 OPUS_MOVE(buf, buf+N, decode_buffer_size-N)(memmove((buf), (buf+N), (decode_buffer_size-N)*sizeof(*(buf)
) + 0*((buf)-(buf+N)) ))
;
999
1000 /* Extrapolate from the end of the excitation with a period of
1001 "pitch_index", scaling down each period by an additional factor of
1002 "decay". */
1003 extrapolation_offset = exc_length-pitch_index;
1004 /* We need to extrapolate enough samples to cover a complete MDCT
1005 window (including overlap/2 samples on both sides). */
1006 extrapolation_len = N+overlap;
1007 /* We also apply fading if this is not the first loss. */
1008 attenuation = MULT16_16_Q15(fade, decay)((fade)*(decay));
1009#ifdef FIXED_POINT
1010 shift1 = IMAX(0, 2*celt_zlog2(MULT16_16_Q15(attenuation,((0) > (2*celt_zlog2(((attenuation)*(celt_maxabs16(&sig
[extrapolation_offset], pitch_index))))-18) ? (0) : (2*celt_zlog2
(((attenuation)*(celt_maxabs16(&sig[extrapolation_offset]
, pitch_index))))-18))
1011 celt_maxabs16(&sig[extrapolation_offset], pitch_index)))-18)((0) > (2*celt_zlog2(((attenuation)*(celt_maxabs16(&sig
[extrapolation_offset], pitch_index))))-18) ? (0) : (2*celt_zlog2
(((attenuation)*(celt_maxabs16(&sig[extrapolation_offset]
, pitch_index))))-18))
;
1012#ifdef ENABLE_QEXT
1013 if (st->qext_scale==2) shift1++;
1014#endif
1015#endif
1016 for (i=j=0;i<extrapolation_len;i++,j++)
26
Assuming 'i' is < 'extrapolation_len'
27
Loop condition is true. Entering loop body
1017 {
1018 opus_val16 tmp;
1019 if (j
27.1
'j' is < 'pitch_index'
>= pitch_index) {
28
Taking false branch
1020 j -= pitch_index;
1021 attenuation = MULT16_16_Q15(attenuation, decay)((attenuation)*(decay));
1022 }
1023 buf[decode_buffer_size-N+i] =
1024 SHL32(EXTEND32(MULT16_16_Q15(attenuation,((((attenuation)*(exc[extrapolation_offset+j]))))
1025 exc[extrapolation_offset+j])), SIG_SHIFT)((((attenuation)*(exc[extrapolation_offset+j]))));
1026 /* Compute the expected energy of the attenuated signal whose
1027 excitation we're copying. */
1028 tmp = MULT16_16_Q15(attenuation, sig[extrapolation_offset+j])((attenuation)*(sig[extrapolation_offset+j]));
29
The right operand of '*' is a garbage value
1029 S1 += SHR32(MULT16_16(tmp, tmp), shift1)(((opus_val32)(tmp)*(opus_val32)(tmp)));
1030 }
1031 {
1032 opus_val16 lpc_mem[CELT_LPC_ORDER24];
1033 /* Copy the last decoded samples (prior to the overlap region) to
1034 synthesis filter memory so we can have a continuous signal. */
1035 for (i=0;i<CELT_LPC_ORDER24;i++)
1036 lpc_mem[i] = SROUND16(buf[decode_buffer_size-N-1-i], SIG_SHIFT)(buf[decode_buffer_size-N-1-i]);
1037 /* Apply the synthesis filter to convert the excitation back into
1038 the signal domain. */
1039 celt_iir(buf+decode_buffer_size-N, lpc+c*CELT_LPC_ORDER24,
1040 buf+decode_buffer_size-N, extrapolation_len, CELT_LPC_ORDER24,
1041 lpc_mem, st->arch);
1042#ifdef FIXED_POINT
1043 for (i=0; i < extrapolation_len; i++)
1044 buf[decode_buffer_size-N+i] = SATURATE(buf[decode_buffer_size-N+i], SIG_SAT)(buf[decode_buffer_size-N+i]);
1045#endif
1046 }
1047
1048 /* Check if the synthesis energy is higher than expected, which can
1049 happen with the signal changes during our window. If so,
1050 attenuate. */
1051 {
1052 opus_val32 S2=0;
1053#ifdef FIXED_POINT
1054 int shift2 = IMAX(0, 2*celt_zlog2(SROUND16(celt_maxabs32(((0) > (2*celt_zlog2((celt_maxabs16(buf+decode_buffer_size
-N,extrapolation_len)))-18) ? (0) : (2*celt_zlog2((celt_maxabs16
(buf+decode_buffer_size-N,extrapolation_len)))-18))
1055 buf+decode_buffer_size-N, extrapolation_len), SIG_SHIFT))-18)((0) > (2*celt_zlog2((celt_maxabs16(buf+decode_buffer_size
-N,extrapolation_len)))-18) ? (0) : (2*celt_zlog2((celt_maxabs16
(buf+decode_buffer_size-N,extrapolation_len)))-18))
;
1056#ifdef ENABLE_QEXT
1057 if (st->qext_scale==2) shift2++;
1058#endif
1059 shift2 = IMAX(shift1, shift2)((shift1) > (shift2) ? (shift1) : (shift2));
1060 S1 = SHR32(S1, shift2-shift1)(S1);
1061#endif
1062 for (i=0;i<extrapolation_len;i++)
1063 {
1064 opus_val16 tmp = SROUND16(buf[decode_buffer_size-N+i], SIG_SHIFT)(buf[decode_buffer_size-N+i]);
1065 S2 += SHR32(MULT16_16(tmp, tmp), shift2)(((opus_val32)(tmp)*(opus_val32)(tmp)));
1066 }
1067 /* This checks for an "explosion" in the synthesis. */
1068#ifdef FIXED_POINT
1069 if (!(S1 > SHR32(S2,2)(S2)))
1070#else
1071 /* The float test is written this way to catch NaNs in the output
1072 of the IIR filter at the same time. */
1073 if (!(S1 > 0.2f*S2))
1074#endif
1075 {
1076 for (i=0;i<extrapolation_len;i++)
1077 buf[decode_buffer_size-N+i] = 0;
1078 } else if (S1 < S2)
1079 {
1080 opus_val16 ratio = celt_sqrt(frac_div32(SHR32(S1,1)+1,S2+1))((float)sqrt(((float)((S1)+1)/(S2+1))));
1081 for (i=0;i<overlap;i++)
1082 {
1083 opus_val16 tmp_g = Q15ONE1.0f
1084 - MULT16_16_Q15(COEF2VAL16(window[i]), Q15ONE-ratio)(((window[i]))*(1.0f -ratio));
1085 buf[decode_buffer_size-N+i] =
1086 MULT16_32_Q15(tmp_g, buf[decode_buffer_size-N+i])((tmp_g)*(buf[decode_buffer_size-N+i]));
1087 }
1088 for (i=overlap;i<extrapolation_len;i++)
1089 {
1090 buf[decode_buffer_size-N+i] =
1091 MULT16_32_Q15(ratio, buf[decode_buffer_size-N+i])((ratio)*(buf[decode_buffer_size-N+i]));
1092 }
1093 }
1094 }
1095
1096 if (st->last_frame_type == FRAME_NORMAL1)
1097 {
1098 comb_filter(etmp, buf+decode_buffer_size-N,
1099 st->postfilter_period_old, st->postfilter_period_old, overlap,
1100 -st->postfilter_gain_old, -st->postfilter_gain_old,
1101 st->postfilter_tapset_old, st->postfilter_tapset_old,
1102 NULL((void*)0), 0, st->arch ARG_QEXT(qext_scale));
1103 for (i=0;i<overlap/2;i++)
1104 {
1105 opus_val16 w1 = COEF2VAL16(window[i])(window[i]);
1106 opus_val16 w2 = COEF2VAL16(window[overlap-1-i])(window[overlap-1-i]);
1107 celt_sig x2 = old_overlap[i];
1108 celt_sig x1 = SUB32(MULT16_32_Q15(w2, etmp[overlap-1-i]),((((w2)*(etmp[overlap-1-i])))-(((w1)*(etmp[i]))))
1109 MULT16_32_Q15(w1, etmp[i]))((((w2)*(etmp[overlap-1-i])))-(((w1)*(etmp[i]))));
1110 buf[decode_buffer_size-N+i] = SATURATE((((((w2)*(x2)))-(((w1)*(x1)))))
1111 SUB32(MULT16_32_Q15(w2, x2), MULT16_32_Q15(w1, x1)),(((((w2)*(x2)))-(((w1)*(x1)))))
1112 SIG_SAT)(((((w2)*(x2)))-(((w1)*(x1)))));
1113 buf[decode_buffer_size-N+overlap-1-i] = SATURATE((((((w1)*(x2)))+(((w2)*(x1)))))
1114 ADD32(MULT16_32_Q15(w1, x2), MULT16_32_Q15(w2, x1)),(((((w1)*(x2)))+(((w2)*(x1)))))
1115 SIG_SAT)(((((w1)*(x2)))+(((w2)*(x1)))));
1116 }
1117 comb_filter(buf+decode_buffer_size-N, buf+decode_buffer_size-N,
1118 st->postfilter_period_old, st->postfilter_period_old, overlap,
1119 st->postfilter_gain_old, st->postfilter_gain_old,
1120 st->postfilter_tapset_old, st->postfilter_tapset_old,
1121 NULL((void*)0), 0, st->arch ARG_QEXT(qext_scale));
1122 }
1123
1124 } while (++c<C);
1125
1126#ifdef ENABLE_DEEP_PLC
1127 if (curr_neural) {
1128 float overlap_mem;
1129 int samples_needed16k;
1130 celt_sig *buf;
1131 VARDECL(float, buf_copy)float *buf_copy;
1132 buf = decode_mem[0];
1133 ALLOC(buf_copy, C*overlap, float)buf_copy = ((float*)__builtin_alloca (sizeof(float)*(C*overlap
)))
;
1134 c=0; do {
1135 OPUS_COPY(buf_copy+c*overlap, &decode_mem[c][decode_buffer_size-N], overlap)(memcpy((buf_copy+c*overlap), (&decode_mem[c][decode_buffer_size
-N]), (overlap)*sizeof(*(buf_copy+c*overlap)) + 0*((buf_copy+
c*overlap)-(&decode_mem[c][decode_buffer_size-N])) ))
;
1136 } while (++c<C);
1137
1138 /* Need enough samples from the PLC to cover the frame size, resampling delay,
1139 and the overlap at the end. */
1140 samples_needed16k = (N+SINC_ORDER+overlap)/3;
1141 if (!last_neural) {
1142 st->plc_fill = 0;
1143 }
1144 while (st->plc_fill < samples_needed16k) {
1145 lpcnet_plc_conceal(lpcnet, &st->plc_pcm[st->plc_fill]);
1146 st->plc_fill += FRAME_SIZE;
1147 }
1148 /* Resample to 48 kHz. */
1149 for (i=0;i<(N+overlap)/3;i++) {
1150 int j;
1151 float sum;
1152 for (sum=0, j=0;j<17;j++) sum += 3*st->plc_pcm[i+j]*sinc_filter[3*j];
1153 buf[decode_buffer_size-N+3*i] = sum;
1154 for (sum=0, j=0;j<16;j++) sum += 3*st->plc_pcm[i+j+1]*sinc_filter[3*j+2];
1155 buf[decode_buffer_size-N+3*i+1] = sum;
1156 for (sum=0, j=0;j<16;j++) sum += 3*st->plc_pcm[i+j+1]*sinc_filter[3*j+1];
1157 buf[decode_buffer_size-N+3*i+2] = sum;
1158 }
1159 OPUS_MOVE(st->plc_pcm, &st->plc_pcm[N/3], st->plc_fill-N/3)(memmove((st->plc_pcm), (&st->plc_pcm[N/3]), (st->
plc_fill-N/3)*sizeof(*(st->plc_pcm)) + 0*((st->plc_pcm)
-(&st->plc_pcm[N/3])) ))
;
1160 st->plc_fill -= N/3;
1161 for (i=0;i<N;i++) {
1162 float tmp = buf[decode_buffer_size-N+i];
1163 buf[decode_buffer_size-N+i] -= PREEMPHASIS*st->plc_preemphasis_mem;
1164 st->plc_preemphasis_mem = tmp;
1165 }
1166 overlap_mem = st->plc_preemphasis_mem;
1167 for (i=0;i<overlap;i++) {
1168 float tmp = buf[decode_buffer_size+i];
1169 buf[decode_buffer_size+i] -= PREEMPHASIS*overlap_mem;
1170 overlap_mem = tmp;
1171 }
1172 /* For now, we just do mono PLC. */
1173 if (C==2) OPUS_COPY(decode_mem[1], decode_mem[0], decode_buffer_size+overlap)(memcpy((decode_mem[1]), (decode_mem[0]), (decode_buffer_size
+overlap)*sizeof(*(decode_mem[1])) + 0*((decode_mem[1])-(decode_mem
[0])) ))
;
1174 c=0; do {
1175 /* Cross-fade with 48-kHz non-neural PLC for the first 2.5 ms to avoid a discontinuity. */
1176 if (!last_neural) {
1177 for (i=0;i<overlap;i++) decode_mem[c][decode_buffer_size-N+i] = (1-window[i])*buf_copy[c*overlap+i] + (window[i])*decode_mem[c][decode_buffer_size-N+i];
1178 }
1179 } while (++c<C);
1180 }
1181#endif
1182 st->prefilter_and_fold = 1;
1183 }
1184
1185 /* Saturate to something large to avoid wrap-around. */
1186 st->loss_duration = IMIN(10000, loss_duration+(1<<LM))((10000) < (loss_duration+(1<<LM)) ? (10000) : (loss_duration
+(1<<LM)))
;
1187 st->plc_duration = IMIN(10000, st->plc_duration+(1<<LM))((10000) < (st->plc_duration+(1<<LM)) ? (10000) :
(st->plc_duration+(1<<LM)))
;
1188#ifdef ENABLE_DRED
1189 if (curr_frame_type == FRAME_DRED5) {
1190 st->plc_duration = 0;
1191 st->skip_plc = 0;
1192 }
1193#endif
1194 st->last_frame_type = curr_frame_type;
1195 RESTORE_STACK;
1196}
1197
1198#ifdef ENABLE_QEXT
1199static void decode_qext_stereo_params(ec_dec *ec, int qext_end, int *qext_intensity, int *qext_dual_stereo) {
1200 *qext_intensity = ec_dec_uint(ec, qext_end+1);
1201 if (*qext_intensity != 0) *qext_dual_stereo = ec_dec_bit_logp(ec, 1);
1202 else *qext_dual_stereo = 0;
1203}
1204#endif
1205
1206int celt_decode_with_ec_dred(CELTDecoderOpusCustomDecoder * OPUS_RESTRICTrestrict st, const unsigned char *data,
1207 int len, opus_res * OPUS_RESTRICTrestrict pcm, int frame_size, ec_dec *dec, int accum
1208#ifdef ENABLE_DEEP_PLC
1209 ,LPCNetPLCState *lpcnet
1210#endif
1211 ARG_QEXT(const unsigned char *qext_payload) ARG_QEXT(int qext_payload_len)
1212 )
1213{
1214 int c, i, N;
1215 int spread_decision;
1216 opus_int32 bits;
1217 ec_dec _dec;
1218 VARDECL(celt_norm, X)celt_norm *X;
1219 VARDECL(int, fine_quant)int *fine_quant;
1220 VARDECL(int, pulses)int *pulses;
1221 VARDECL(int, cap)int *cap;
1222 VARDECL(int, offsets)int *offsets;
1223 VARDECL(int, fine_priority)int *fine_priority;
1224 VARDECL(int, tf_res)int *tf_res;
1225 VARDECL(unsigned char, collapse_masks)unsigned char *collapse_masks;
1226 celt_sig *decode_mem[2];
1227 celt_sig *out_syn[2];
1228 celt_glog *oldBandE, *oldLogE, *oldLogE2, *backgroundLogE;
1229
1230 int shortBlocks;
1231 int isTransient;
1232 int intra_ener;
1233 const int CC = st->channels;
1234 int LM, M;
1235 int start;
1236 int end;
1237 int effEnd;
1238 int codedBands;
1239 int alloc_trim;
1240 int postfilter_pitch;
1241 opus_val16 postfilter_gain;
1242 int intensity=0;
1243 int dual_stereo=0;
1244 opus_int32 total_bits;
1245 opus_int32 balance;
1246 opus_int32 tell;
1247 int dynalloc_logp;
1248 int postfilter_tapset;
1249 int anti_collapse_rsv;
1250 int anti_collapse_on=0;
1251 int silence;
1252 int C = st->stream_channels;
1253 const OpusCustomMode *mode;
1254 int nbEBands;
1255 int overlap;
1256 const opus_int16 *eBands;
1257 celt_glog max_background_increase;
1258 int decode_buffer_size;
1259#ifdef ENABLE_QEXT
1260 opus_int32 qext_bits;
1261 ec_dec ext_dec;
1262 int qext_bytes0=0;
1263 int qext_end=0;
1264 int qext_intensity=0;
1265 int qext_dual_stereo=0;
1266 VARDECL(int, extra_quant)int *extra_quant;
1267 VARDECL(int, extra_pulses)int *extra_pulses;
1268 const CELTModeOpusCustomMode *qext_mode = NULL((void*)0);
1269 CELTModeOpusCustomMode qext_mode_struct;
1270 int qext_scale;
1271#else
1272# define qext_bytes0 0
1273#endif
1274 ALLOC_STACK;
1275#ifdef ENABLE_QEXT
1276 qext_scale = st->qext_scale;
1277#endif
1278 decode_buffer_size = QEXT_SCALE(DECODE_BUFFER_SIZE)(2048);
1279
1280 VALIDATE_CELT_DECODER(st)validate_celt_decoder(st);
1281 mode = st->mode;
1282 nbEBands = mode->nbEBands;
1283 overlap = mode->overlap;
1284 eBands = mode->eBands;
1285 start = st->start;
1286 end = st->end;
1287 frame_size *= st->downsample;
1288
1289 oldBandE = (celt_glog*)(st->_decode_mem+(decode_buffer_size+overlap)*CC);
1290 oldLogE = oldBandE + 2*nbEBands;
1291 oldLogE2 = oldLogE + 2*nbEBands;
1292 backgroundLogE = oldLogE2 + 2*nbEBands;
1293
1294#ifdef ENABLE_QEXT
1295 /* Ignore absurdly large payloads (see QEXT_PAYLOAD_SIZE_CAP). */
1296 if (qext_payload && qext_payload_len <= QEXT_PAYLOAD_SIZE_CAP) {
1297 ec_dec_init(&ext_dec, (unsigned char*)qext_payload, qext_payload_len);
1298 qext_bytes0 = qext_payload_len;
1299 } else {
1300 ec_dec_init(&ext_dec, NULL((void*)0), 0);
1301 }
1302#endif
1303#if defined(CUSTOM_MODES) || defined(ENABLE_OPUS_CUSTOM_API)
1304 if (st->signalling && data!=NULL((void*)0))
1305 {
1306 int data0=data[0];
1307 /* Convert "standard mode" to Opus header */
1308# ifndef ENABLE_QEXT
1309 if (mode->Fs==48000 && mode->shortMdctSize==120)
1310# endif
1311 {
1312 data0 = fromOpus(data0);
1313 if (data0<0)
1314 return OPUS_INVALID_PACKET-4;
1315 }
1316 st->end = end = IMAX(1, mode->effEBands-2*(data0>>5))((1) > (mode->effEBands-2*(data0>>5)) ? (1) : (mode
->effEBands-2*(data0>>5)))
;
1317 LM = (data0>>3)&0x3;
1318 C = 1 + ((data0>>2)&0x1);
1319 if ((data[0] & 0x03) == 0x03) {
1320 data++;
1321 len--;
1322 if (len<=0)
1323 return OPUS_INVALID_PACKET-4;
1324 if (data[0] & 0x40) {
1325 int p;
1326 int padding=0;
1327 data++;
1328 len--;
1329 do {
1330 int tmp;
1331 if (len<=0)
1332 return OPUS_INVALID_PACKET-4;
1333 p = *data++;
1334 len--;
1335 tmp = p==255 ? 254: p;
1336 len -= tmp;
1337 padding += tmp;
1338 } while (p==255);
1339 padding--;
1340 if (len <= 0 || padding<0) return OPUS_INVALID_PACKET-4;
1341#ifdef ENABLE_QEXT
1342 qext_bytes0 = padding;
1343 if (data[len] != QEXT_EXTENSION_ID124<<1 || qext_bytes0 > QEXT_PAYLOAD_SIZE_CAP)
1344 qext_bytes0=0;
1345 ec_dec_init(&ext_dec, (unsigned char*)data+len+1, qext_bytes0);
1346#endif
1347 }
1348 } else
1349 {
1350 data++;
1351 len--;
1352 }
1353 if (LM>mode->maxLM)
1354 return OPUS_INVALID_PACKET-4;
1355 if (frame_size < mode->shortMdctSize<<LM)
1356 return OPUS_BUFFER_TOO_SMALL-2;
1357 else
1358 frame_size = mode->shortMdctSize<<LM;
1359 } else {
1360#else
1361 {
1362#endif
1363 for (LM=0;LM<=mode->maxLM;LM++)
1364 if (mode->shortMdctSize<<LM==frame_size)
1365 break;
1366 if (LM>mode->maxLM)
1367 return OPUS_BAD_ARG-1;
1368 }
1369 M=1<<LM;
1370
1371 if (len<0 || len>1275 || pcm==NULL((void*)0))
1372 return OPUS_BAD_ARG-1;
1373
1374 N = M*mode->shortMdctSize;
1375 c=0; do {
1376 decode_mem[c] = st->_decode_mem + c*(decode_buffer_size+overlap);
1377 out_syn[c] = decode_mem[c]+decode_buffer_size-N;
1378 } while (++c<CC);
1379
1380 effEnd = end;
1381 if (effEnd > mode->effEBands)
1382 effEnd = mode->effEBands;
1383
1384 if (data == NULL((void*)0) || len<=1)
1385 {
1386 celt_decode_lost(st, N, LM
1387#ifdef ENABLE_DEEP_PLC
1388 , lpcnet
1389#endif
1390 );
1391 deemphasis(out_syn, pcm, N, CC, st->downsample, mode->preemph, st->preemph_memD, accum, st->arch);
1392 RESTORE_STACK;
1393 return frame_size/st->downsample;
1394 }
1395#ifdef ENABLE_DEEP_PLC
1396 else {
1397 /* FIXME: This is a bit of a hack just to make sure opus_decode_native() knows we're no longer in PLC. */
1398 if (lpcnet) lpcnet->blend = 0;
1399 }
1400#endif
1401
1402 /* Check if there are at least two packets received consecutively before
1403 * turning on the pitch-based PLC */
1404 if (st->loss_duration == 0) st->skip_plc = 0;
1405
1406 if (dec == NULL((void*)0))
1407 {
1408 ec_dec_init(&_dec,(unsigned char*)data,len);
1409 dec = &_dec;
1410 }
1411
1412 if (C==1)
1413 {
1414 for (i=0;i<nbEBands;i++)
1415 oldBandE[i]=MAXG(oldBandE[i],oldBandE[nbEBands+i])((oldBandE[i]) > (oldBandE[nbEBands+i]) ? (oldBandE[i]) : (
oldBandE[nbEBands+i]))
;
1416 }
1417
1418 total_bits = len*8;
1419 tell = ec_tell(dec);
1420
1421 if (tell >= total_bits)
1422 silence = 1;
1423 else if (tell==1)
1424 silence = ec_dec_bit_logp(dec, 15);
1425 else
1426 silence = 0;
1427 if (silence)
1428 {
1429 /* Pretend we've read all the remaining bits */
1430 tell = len*8;
1431 dec->nbits_total+=tell-ec_tell(dec);
1432 }
1433
1434 postfilter_gain = 0;
1435 postfilter_pitch = 0;
1436 postfilter_tapset = 0;
1437 if (start==0 && tell+16 <= total_bits)
1438 {
1439 if(ec_dec_bit_logp(dec, 1))
1440 {
1441 int qg, octave;
1442 octave = ec_dec_uint(dec, 6);
1443 postfilter_pitch = (16<<octave)+ec_dec_bits(dec, 4+octave)-1;
1444 qg = ec_dec_bits(dec, 3);
1445 if (ec_tell(dec)+2<=total_bits)
1446 postfilter_tapset = ec_dec_icdf(dec, tapset_icdf, 2);
1447 postfilter_gain = QCONST16(.09375f,15)(.09375f)*(qg+1);
1448 }
1449 tell = ec_tell(dec);
1450 }
1451
1452 if (LM > 0 && tell+3 <= total_bits)
1453 {
1454 isTransient = ec_dec_bit_logp(dec, 3);
1455 tell = ec_tell(dec);
1456 }
1457 else
1458 isTransient = 0;
1459
1460 if (isTransient)
1461 shortBlocks = M;
1462 else
1463 shortBlocks = 0;
1464
1465 /* Decode the global flags (first symbols in the stream) */
1466 intra_ener = tell+3<=total_bits ? ec_dec_bit_logp(dec, 3) : 0;
1467 /* If recovering from packet loss, make sure we make the energy prediction safe to reduce the
1468 risk of getting loud artifacts. */
1469 if (!intra_ener && st->loss_duration != 0) {
1470 c=0; do
1471 {
1472 celt_glog safety = 0;
1473 int missing = IMIN(10, st->loss_duration>>LM)((10) < (st->loss_duration>>LM) ? (10) : (st->
loss_duration>>LM))
;
1474 if (LM==0) safety = GCONST(1.5f)(1.5f);
1475 else if (LM==1) safety = GCONST(.5f)(.5f);
1476 for (i=start;i<end;i++)
1477 {
1478 if (oldBandE[c*nbEBands+i] < MAXG(oldLogE[c*nbEBands+i], oldLogE2[c*nbEBands+i])((oldLogE[c*nbEBands+i]) > (oldLogE2[c*nbEBands+i]) ? (oldLogE
[c*nbEBands+i]) : (oldLogE2[c*nbEBands+i]))
) {
1479 /* If energy is going down already, continue the trend. */
1480 opus_val32 slope;
1481 opus_val32 E0, E1, E2;
1482 E0 = oldBandE[c*nbEBands+i];
1483 E1 = oldLogE[c*nbEBands+i];
1484 E2 = oldLogE2[c*nbEBands+i];
1485 slope = MAX32(E1 - E0, HALF32(E2 - E0))((E1 - E0) > ((.5f*(E2 - E0))) ? (E1 - E0) : ((.5f*(E2 - E0
))))
;
1486 slope = MING(slope, GCONST(2.f))((slope) < ((2.f)) ? (slope) : ((2.f)));
1487 E0 -= MAX32(0, (1+missing)*slope)((0) > ((1+missing)*slope) ? (0) : ((1+missing)*slope));
1488 oldBandE[c*nbEBands+i] = MAX32(-GCONST(20.f), E0)((-(20.f)) > (E0) ? (-(20.f)) : (E0));
1489 } else {
1490 /* Otherwise take the min of the last frames. */
1491 oldBandE[c*nbEBands+i] = MING(MING(oldBandE[c*nbEBands+i], oldLogE[c*nbEBands+i]), oldLogE2[c*nbEBands+i])((((oldBandE[c*nbEBands+i]) < (oldLogE[c*nbEBands+i]) ? (oldBandE
[c*nbEBands+i]) : (oldLogE[c*nbEBands+i]))) < (oldLogE2[c*
nbEBands+i]) ? (((oldBandE[c*nbEBands+i]) < (oldLogE[c*nbEBands
+i]) ? (oldBandE[c*nbEBands+i]) : (oldLogE[c*nbEBands+i]))) :
(oldLogE2[c*nbEBands+i]))
;
1492 }
1493 /* Shorter frames have more natural fluctuations -- play it safe. */
1494 oldBandE[c*nbEBands+i] -= safety;
1495 }
1496 } while (++c<2);
1497 }
1498 /* Get band energies */
1499 unquant_coarse_energy(mode, start, end, oldBandE,
1500 intra_ener, dec, C, LM);
1501
1502 ALLOC(tf_res, nbEBands, int)tf_res = ((int*)__builtin_alloca (sizeof(int)*(nbEBands)));
1503 tf_decode(start, end, isTransient, tf_res, LM, dec);
1504
1505 tell = ec_tell(dec);
1506 spread_decision = SPREAD_NORMAL(2);
1507 if (tell+4 <= total_bits)
1508 spread_decision = ec_dec_icdf(dec, spread_icdf, 5);
1509
1510 ALLOC(cap, nbEBands, int)cap = ((int*)__builtin_alloca (sizeof(int)*(nbEBands)));
1511
1512 init_caps(mode,cap,LM,C);
1513
1514 ALLOC(offsets, nbEBands, int)offsets = ((int*)__builtin_alloca (sizeof(int)*(nbEBands)));
1515
1516 dynalloc_logp = 6;
1517 total_bits<<=BITRES3;
1518 tell = ec_tell_frac(dec);
1519 for (i=start;i<end;i++)
1520 {
1521 int width, quanta;
1522 int dynalloc_loop_logp;
1523 int boost;
1524 width = C*(eBands[i+1]-eBands[i])<<LM;
1525 /* quanta is 6 bits, but no more than 1 bit/sample
1526 and no less than 1/8 bit/sample */
1527 quanta = IMIN(width<<BITRES, IMAX(6<<BITRES, width))((width<<3) < (((6<<3) > (width) ? (6<<
3) : (width))) ? (width<<3) : (((6<<3) > (width
) ? (6<<3) : (width))))
;
1528 dynalloc_loop_logp = dynalloc_logp;
1529 boost = 0;
1530 while (tell+(dynalloc_loop_logp<<BITRES3) < total_bits && boost < cap[i])
1531 {
1532 int flag;
1533 flag = ec_dec_bit_logp(dec, dynalloc_loop_logp);
1534 tell = ec_tell_frac(dec);
1535 if (!flag)
1536 break;
1537 boost += quanta;
1538 total_bits -= quanta;
1539 dynalloc_loop_logp = 1;
1540 }
1541 offsets[i] = boost;
1542 /* Making dynalloc more likely */
1543 if (boost>0)
1544 dynalloc_logp = IMAX(2, dynalloc_logp-1)((2) > (dynalloc_logp-1) ? (2) : (dynalloc_logp-1));
1545 }
1546
1547 ALLOC(fine_quant, nbEBands, int)fine_quant = ((int*)__builtin_alloca (sizeof(int)*(nbEBands))
)
;
1548 alloc_trim = tell+(6<<BITRES3) <= total_bits ?
1549 ec_dec_icdf(dec, trim_icdf, 7) : 5;
1550
1551 bits = (((opus_int32)len*8)<<BITRES3) - (opus_int32)ec_tell_frac(dec) - 1;
1552 anti_collapse_rsv = isTransient&&LM>=2&&bits>=((LM+2)<<BITRES3) ? (1<<BITRES3) : 0;
1553 bits -= anti_collapse_rsv;
1554
1555 ALLOC(pulses, nbEBands, int)pulses = ((int*)__builtin_alloca (sizeof(int)*(nbEBands)));
1556 ALLOC(fine_priority, nbEBands, int)fine_priority = ((int*)__builtin_alloca (sizeof(int)*(nbEBands
)))
;
1557
1558 codedBands = clt_compute_allocation(mode, start, end, offsets, cap,
1559 alloc_trim, &intensity, &dual_stereo, bits, &balance, pulses,
1560 fine_quant, fine_priority, C, LM, dec, 0, 0, 0);
1561
1562 unquant_fine_energy(mode, start, end, oldBandE, NULL((void*)0), fine_quant, dec, C);
1563
1564 ALLOC(X, C*N, celt_norm)X = ((celt_norm*)__builtin_alloca (sizeof(celt_norm)*(C*N))); /**< Interleaved normalised MDCTs */
1565
1566#ifdef ENABLE_QEXT
1567 if (qext_bytes0 && end == nbEBands &&
1568 ((mode->Fs == 48000 && (mode->shortMdctSize==120 || mode->shortMdctSize==90))
1569 || (mode->Fs == 96000 && (mode->shortMdctSize==240 || mode->shortMdctSize==180)))) {
1570 int qext_intra_ener;
1571 compute_qext_mode(&qext_mode_struct, mode);
1572 qext_mode = &qext_mode_struct;
1573 qext_end = ec_dec_bit_logp(&ext_dec, 1) ? NB_QEXT_BANDS : 2;
1574 if (C==2) decode_qext_stereo_params(&ext_dec, qext_end, &qext_intensity, &qext_dual_stereo);
1575 qext_intra_ener = ec_tell(&ext_dec)+3<=qext_bytes0*8 ? ec_dec_bit_logp(&ext_dec, 3) : 0;
1576 unquant_coarse_energy(qext_mode, 0, qext_end, st->qext_oldBandE,
1577 qext_intra_ener, &ext_dec, C, LM);
1578 }
1579 ALLOC(extra_quant, nbEBands+NB_QEXT_BANDS, int)extra_quant = ((int*)__builtin_alloca (sizeof(int)*(nbEBands+
NB_QEXT_BANDS)))
;
1580 ALLOC(extra_pulses, nbEBands+NB_QEXT_BANDS, int)extra_pulses = ((int*)__builtin_alloca (sizeof(int)*(nbEBands
+NB_QEXT_BANDS)))
;
1581 qext_bits = ((opus_int32)qext_bytes0*8<<BITRES3) - (opus_int32)ec_tell_frac(&ext_dec) - 1;
1582 clt_compute_extra_allocation(mode, qext_mode, start, end, qext_end, NULL((void*)0), NULL((void*)0),
1583 qext_bits, extra_pulses, extra_quant, C, LM, &ext_dec, 0, 0, 0);
1584 if (qext_bytes0 > 0) {
1585 unquant_fine_energy(mode, start, end, oldBandE, fine_quant, extra_quant, &ext_dec, C);
1586 }
1587#endif
1588
1589 c=0; do {
1590 OPUS_MOVE(decode_mem[c], decode_mem[c]+N, decode_buffer_size-N+overlap)(memmove((decode_mem[c]), (decode_mem[c]+N), (decode_buffer_size
-N+overlap)*sizeof(*(decode_mem[c])) + 0*((decode_mem[c])-(decode_mem
[c]+N)) ))
;
1591 } while (++c<CC);
1592
1593 /* Decode fixed codebook */
1594 ALLOC(collapse_masks, C*nbEBands, unsigned char)collapse_masks = ((unsigned char*)__builtin_alloca (sizeof(unsigned
char)*(C*nbEBands)))
;
1595
1596 quant_all_bands(0, mode, start, end, X, C==2 ? X+N : NULL((void*)0), collapse_masks,
1597 NULL((void*)0), pulses, shortBlocks, spread_decision, dual_stereo, intensity, tf_res,
1598 len*(8<<BITRES3)-anti_collapse_rsv, balance, dec, LM, codedBands, &st->rng, 0,
1599 st->arch, st->disable_inv
1600 ARG_QEXT(&ext_dec) ARG_QEXT(extra_pulses)
1601 ARG_QEXT(qext_bytes*(8<<BITRES)) ARG_QEXT(cap));
1602
1603#ifdef ENABLE_QEXT
1604 if (qext_mode) {
1605 VARDECL(int, zeros)int *zeros;
1606 VARDECL(unsigned char, qext_collapse_masks)unsigned char *qext_collapse_masks;
1607 ec_dec dummy_dec;
1608 int ext_balance;
1609 ALLOC(zeros, nbEBands, int)zeros = ((int*)__builtin_alloca (sizeof(int)*(nbEBands)));
1610 ALLOC(qext_collapse_masks, C*NB_QEXT_BANDS, unsigned char)qext_collapse_masks = ((unsigned char*)__builtin_alloca (sizeof
(unsigned char)*(C*NB_QEXT_BANDS)))
;
1611 ec_dec_init(&dummy_dec, NULL((void*)0), 0);
1612 OPUS_CLEAR(zeros, end)(memset((zeros), 0, (end)*sizeof(*(zeros))));
1613 ext_balance = qext_bytes0*(8<<BITRES3) - ec_tell_frac(&ext_dec);
1614 for (i=0;i<qext_end;i++) ext_balance -= extra_pulses[nbEBands+i] + C*(extra_quant[nbEBands+i]<<BITRES3);
1615 unquant_fine_energy(qext_mode, 0, qext_end, st->qext_oldBandE, NULL((void*)0), &extra_quant[nbEBands], &ext_dec, C);
1616 quant_all_bands(0, qext_mode, 0, qext_end, X, C==2 ? X+N : NULL((void*)0), qext_collapse_masks,
1617 NULL((void*)0), &extra_pulses[nbEBands], shortBlocks, spread_decision, qext_dual_stereo, qext_intensity, zeros,
1618 qext_bytes0*(8<<BITRES3), ext_balance, &ext_dec, LM, qext_end, &st->rng, 0,
1619 st->arch, st->disable_inv, &dummy_dec, zeros, 0, NULL((void*)0));
1620 }
1621#endif
1622
1623 if (anti_collapse_rsv > 0)
1624 {
1625 anti_collapse_on = ec_dec_bits(dec, 1);
1626 }
1627 unquant_energy_finalise(mode, start, end, (qext_bytes0 > 0) ? NULL((void*)0) : oldBandE,
1628 fine_quant, fine_priority, len*8-ec_tell(dec), dec, C);
1629 if (anti_collapse_on)
1630 anti_collapse(mode, X, collapse_masks, LM, C, N,
1631 start, end, oldBandE, oldLogE, oldLogE2, pulses, st->rng, 0, st->arch);
1632
1633 if (silence)
1634 {
1635 for (i=0;i<C*nbEBands;i++)
1636 oldBandE[i] = -GCONST(28.f)(28.f);
1637 }
1638 if (st->prefilter_and_fold) {
1639 prefilter_and_fold(st, N);
1640 }
1641 celt_synthesis(mode, X, out_syn, oldBandE, start, effEnd,
1642 C, CC, isTransient, LM, st->downsample, silence, st->arch ARG_QEXT(qext_mode) ARG_QEXT(st->qext_oldBandE) ARG_QEXT(qext_end));
1643
1644 c=0; do {
1645 st->postfilter_period=IMAX(st->postfilter_period, COMBFILTER_MINPERIOD)((st->postfilter_period) > (15) ? (st->postfilter_period
) : (15))
;
1646 st->postfilter_period_old=IMAX(st->postfilter_period_old, COMBFILTER_MINPERIOD)((st->postfilter_period_old) > (15) ? (st->postfilter_period_old
) : (15))
;
1647 comb_filter(out_syn[c], out_syn[c], st->postfilter_period_old, st->postfilter_period, mode->shortMdctSize,
1648 st->postfilter_gain_old, st->postfilter_gain, st->postfilter_tapset_old, st->postfilter_tapset,
1649 mode->window, overlap, st->arch ARG_QEXT(qext_scale));
1650 if (LM!=0)
1651 comb_filter(out_syn[c]+mode->shortMdctSize, out_syn[c]+mode->shortMdctSize, st->postfilter_period, postfilter_pitch, N-mode->shortMdctSize,
1652 st->postfilter_gain, postfilter_gain, st->postfilter_tapset, postfilter_tapset,
1653 mode->window, overlap, st->arch ARG_QEXT(qext_scale));
1654
1655 } while (++c<CC);
1656 st->postfilter_period_old = st->postfilter_period;
1657 st->postfilter_gain_old = st->postfilter_gain;
1658 st->postfilter_tapset_old = st->postfilter_tapset;
1659 st->postfilter_period = postfilter_pitch;
1660 st->postfilter_gain = postfilter_gain;
1661 st->postfilter_tapset = postfilter_tapset;
1662 if (LM!=0)
1663 {
1664 st->postfilter_period_old = st->postfilter_period;
1665 st->postfilter_gain_old = st->postfilter_gain;
1666 st->postfilter_tapset_old = st->postfilter_tapset;
1667 }
1668
1669 if (C==1)
1670 OPUS_COPY(&oldBandE[nbEBands], oldBandE, nbEBands)(memcpy((&oldBandE[nbEBands]), (oldBandE), (nbEBands)*sizeof
(*(&oldBandE[nbEBands])) + 0*((&oldBandE[nbEBands])-(
oldBandE)) ))
;
1671
1672 if (!isTransient)
1673 {
1674 OPUS_COPY(oldLogE2, oldLogE, 2*nbEBands)(memcpy((oldLogE2), (oldLogE), (2*nbEBands)*sizeof(*(oldLogE2
)) + 0*((oldLogE2)-(oldLogE)) ))
;
1675 OPUS_COPY(oldLogE, oldBandE, 2*nbEBands)(memcpy((oldLogE), (oldBandE), (2*nbEBands)*sizeof(*(oldLogE)
) + 0*((oldLogE)-(oldBandE)) ))
;
1676 } else {
1677 for (i=0;i<2*nbEBands;i++)
1678 oldLogE[i] = MING(oldLogE[i], oldBandE[i])((oldLogE[i]) < (oldBandE[i]) ? (oldLogE[i]) : (oldBandE[i
]))
;
1679 }
1680 /* In normal circumstances, we only allow the noise floor to increase by
1681 up to 2.4 dB/second, but when we're in DTX we give the weight of
1682 all missing packets to the update packet. */
1683 max_background_increase = IMIN(160, st->loss_duration+M)((160) < (st->loss_duration+M) ? (160) : (st->loss_duration
+M))
*GCONST(0.001f)(0.001f);
1684 for (i=0;i<2*nbEBands;i++)
1685 backgroundLogE[i] = MING(backgroundLogE[i] + max_background_increase, oldBandE[i])((backgroundLogE[i] + max_background_increase) < (oldBandE
[i]) ? (backgroundLogE[i] + max_background_increase) : (oldBandE
[i]))
;
1686 /* In case start or end were to change */
1687 c=0; do
1688 {
1689 for (i=0;i<start;i++)
1690 {
1691 oldBandE[c*nbEBands+i]=0;
1692 oldLogE[c*nbEBands+i]=oldLogE2[c*nbEBands+i]=-GCONST(28.f)(28.f);
1693 }
1694 for (i=end;i<nbEBands;i++)
1695 {
1696 oldBandE[c*nbEBands+i]=0;
1697 oldLogE[c*nbEBands+i]=oldLogE2[c*nbEBands+i]=-GCONST(28.f)(28.f);
1698 }
1699 } while (++c<2);
1700 st->rng = dec->rng;
1701#ifdef ENABLE_QEXT
1702 if (qext_bytes0) st->rng = st->rng ^ ext_dec.rng;
1703#endif
1704
1705 deemphasis(out_syn, pcm, N, CC, st->downsample, mode->preemph, st->preemph_memD, accum, st->arch);
1706 st->loss_duration = 0;
1707 st->plc_duration = 0;
1708 st->last_frame_type = FRAME_NORMAL1;
1709 st->prefilter_and_fold = 0;
1710 RESTORE_STACK;
1711 if (ec_tell(dec) > 8*len)
1712 return OPUS_INTERNAL_ERROR-3;
1713#ifdef ENABLE_QEXT
1714 if (qext_bytes0 != 0 && ec_tell(&ext_dec) > 8*qext_bytes0)
1715 return OPUS_INTERNAL_ERROR-3;
1716#endif
1717 if(ec_get_error(dec))
1718 st->error = 1;
1719 return frame_size/st->downsample;
1720}
1721
1722int celt_decode_with_ec(CELTDecoderOpusCustomDecoder * OPUS_RESTRICTrestrict st, const unsigned char *data,
1723 int len, opus_res * OPUS_RESTRICTrestrict pcm, int frame_size, ec_dec *dec, int accum)
1724{
1725 return celt_decode_with_ec_dred(st, data, len, pcm, frame_size, dec, accum
1726#ifdef ENABLE_DEEP_PLC
1727 , NULL((void*)0)
1728#endif
1729 ARG_QEXT(NULL) ARG_QEXT(0)
1730 );
1731}
1732
1733#if defined(CUSTOM_MODES) || defined(ENABLE_OPUS_CUSTOM_API)
1734
1735#if defined(FIXED_POINT) && !defined(ENABLE_RES24)
1736int opus_custom_decode(CELTDecoderOpusCustomDecoder * OPUS_RESTRICTrestrict st, const unsigned char *data, int len, opus_int16 * OPUS_RESTRICTrestrict pcm, int frame_size)
1737{
1738 return celt_decode_with_ec(st, data, len, pcm, frame_size, NULL((void*)0), 0);
1739}
1740#else
1741int opus_custom_decode(CELTDecoderOpusCustomDecoder * OPUS_RESTRICTrestrict st, const unsigned char *data, int len, opus_int16 * OPUS_RESTRICTrestrict pcm, int frame_size)
1742{
1743 int j, ret, C, N;
1744 VARDECL(opus_res, out)opus_res *out;
1745 ALLOC_STACK;
1746
1747 if (pcm==NULL((void*)0))
1748 return OPUS_BAD_ARG-1;
1749
1750 C = st->channels;
1751 N = frame_size;
1752
1753 ALLOC(out, C*N, opus_res)out = ((opus_res*)__builtin_alloca (sizeof(opus_res)*(C*N)));
1754 ret = celt_decode_with_ec(st, data, len, out, frame_size, NULL((void*)0), 0);
1755 if (ret>0)
1756 for (j=0;j<C*ret;j++)
1757 pcm[j]=RES2INT16(out[j])FLOAT2INT16(out[j]);
1758
1759 RESTORE_STACK;
1760 return ret;
1761}
1762#endif
1763
1764#if defined(FIXED_POINT) && defined(ENABLE_RES24)
1765int opus_custom_decode24(CELTDecoderOpusCustomDecoder * OPUS_RESTRICTrestrict st, const unsigned char *data, int len, opus_int32 * OPUS_RESTRICTrestrict pcm, int frame_size)
1766{
1767 return celt_decode_with_ec(st, data, len, pcm, frame_size, NULL((void*)0), 0);
1768}
1769#else
1770int opus_custom_decode24(CELTDecoderOpusCustomDecoder * OPUS_RESTRICTrestrict st, const unsigned char *data, int len, opus_int32 * OPUS_RESTRICTrestrict pcm, int frame_size)
1771{
1772 int j, ret, C, N;
1773 VARDECL(opus_res, out)opus_res *out;
1774 ALLOC_STACK;
1775
1776 if (pcm==NULL((void*)0))
1777 return OPUS_BAD_ARG-1;
1778
1779 C = st->channels;
1780 N = frame_size;
1781
1782 ALLOC(out, C*N, opus_res)out = ((opus_res*)__builtin_alloca (sizeof(opus_res)*(C*N)));
1783 ret = celt_decode_with_ec(st, data, len, out, frame_size, NULL((void*)0), 0);
1784 if (ret>0)
1785 for (j=0;j<C*ret;j++)
1786 pcm[j]=RES2INT24(out[j])FLOAT2INT24(out[j]);
1787
1788 RESTORE_STACK;
1789 return ret;
1790}
1791#endif
1792
1793
1794#ifndef DISABLE_FLOAT_API
1795
1796# if !defined(FIXED_POINT)
1797int opus_custom_decode_float(CELTDecoderOpusCustomDecoder * OPUS_RESTRICTrestrict st, const unsigned char *data, int len, float * OPUS_RESTRICTrestrict pcm, int frame_size)
1798{
1799 return celt_decode_with_ec(st, data, len, pcm, frame_size, NULL((void*)0), 0);
1800}
1801# else
1802int opus_custom_decode_float(CELTDecoderOpusCustomDecoder * OPUS_RESTRICTrestrict st, const unsigned char *data, int len, float * OPUS_RESTRICTrestrict pcm, int frame_size)
1803{
1804 int j, ret, C, N;
1805 VARDECL(opus_res, out)opus_res *out;
1806 ALLOC_STACK;
1807
1808 if (pcm==NULL((void*)0))
1809 return OPUS_BAD_ARG-1;
1810
1811 C = st->channels;
1812 N = frame_size;
1813
1814 ALLOC(out, C*N, opus_res)out = ((opus_res*)__builtin_alloca (sizeof(opus_res)*(C*N)));
1815 ret=celt_decode_with_ec(st, data, len, out, frame_size, NULL((void*)0), 0);
1816 if (ret>0)
1817 for (j=0;j<C*ret;j++)
1818 pcm[j]=RES2FLOAT(out[j])(out[j]);
1819
1820 RESTORE_STACK;
1821 return ret;
1822}
1823# endif
1824
1825#endif
1826
1827#endif /* CUSTOM_MODES */
1828
1829int opus_custom_decoder_ctl(CELTDecoderOpusCustomDecoder * OPUS_RESTRICTrestrict st, int request, ...)
1830{
1831 va_list ap;
1832
1833 va_start(ap, request)__builtin_va_start(ap, request);
1834 switch (request)
1835 {
1836 case OPUS_SET_COMPLEXITY_REQUEST4010:
1837 {
1838 opus_int32 value = va_arg(ap, opus_int32)__builtin_va_arg(ap, opus_int32);
1839 if(value<0 || value>10)
1840 {
1841 goto bad_arg;
1842 }
1843 st->complexity = value;
1844 }
1845 break;
1846 case OPUS_GET_COMPLEXITY_REQUEST4011:
1847 {
1848 opus_int32 *value = va_arg(ap, opus_int32*)__builtin_va_arg(ap, opus_int32*);
1849 if (!value)
1850 {
1851 goto bad_arg;
1852 }
1853 *value = st->complexity;
1854 }
1855 break;
1856 case CELT_SET_START_BAND_REQUEST10010:
1857 {
1858 opus_int32 value = va_arg(ap, opus_int32)__builtin_va_arg(ap, opus_int32);
1859 if (value<0 || value>=st->mode->nbEBands)
1860 goto bad_arg;
1861 st->start = value;
1862 }
1863 break;
1864 case CELT_SET_END_BAND_REQUEST10012:
1865 {
1866 opus_int32 value = va_arg(ap, opus_int32)__builtin_va_arg(ap, opus_int32);
1867 if (value<1 || value>st->mode->nbEBands)
1868 goto bad_arg;
1869 st->end = value;
1870 }
1871 break;
1872 case CELT_SET_CHANNELS_REQUEST10008:
1873 {
1874 opus_int32 value = va_arg(ap, opus_int32)__builtin_va_arg(ap, opus_int32);
1875 if (value<1 || value>2)
1876 goto bad_arg;
1877 st->stream_channels = value;
1878 }
1879 break;
1880 case CELT_GET_AND_CLEAR_ERROR_REQUEST10007:
1881 {
1882 opus_int32 *value = va_arg(ap, opus_int32*)__builtin_va_arg(ap, opus_int32*);
1883 if (value==NULL((void*)0))
1884 goto bad_arg;
1885 *value=st->error;
1886 st->error = 0;
1887 }
1888 break;
1889 case OPUS_GET_LOOKAHEAD_REQUEST4027:
1890 {
1891 opus_int32 *value = va_arg(ap, opus_int32*)__builtin_va_arg(ap, opus_int32*);
1892 if (value==NULL((void*)0))
1893 goto bad_arg;
1894 *value = st->overlap/st->downsample;
1895 }
1896 break;
1897 case OPUS_RESET_STATE4028:
1898 {
1899 int i;
1900 celt_glog *oldBandE, *oldLogE, *oldLogE2;
1901 int decode_buffer_size;
1902#ifdef ENABLE_QEXT
1903 int qext_scale = st->qext_scale;
1904#endif
1905 decode_buffer_size = QEXT_SCALE(DECODE_BUFFER_SIZE)(2048);
1906 oldBandE = (celt_glog*)(st->_decode_mem+(decode_buffer_size+st->overlap)*st->channels);
1907 oldLogE = oldBandE + 2*st->mode->nbEBands;
1908 oldLogE2 = oldLogE + 2*st->mode->nbEBands;
1909 OPUS_CLEAR((char*)&st->DECODER_RESET_START,(memset(((char*)&st->rng), 0, (opus_custom_decoder_get_size
(st->mode, st->channels)- ((char*)&st->rng - (char
*)st))*sizeof(*((char*)&st->rng))))
1910 opus_custom_decoder_get_size(st->mode, st->channels)-(memset(((char*)&st->rng), 0, (opus_custom_decoder_get_size
(st->mode, st->channels)- ((char*)&st->rng - (char
*)st))*sizeof(*((char*)&st->rng))))
1911 ((char*)&st->DECODER_RESET_START - (char*)st))(memset(((char*)&st->rng), 0, (opus_custom_decoder_get_size
(st->mode, st->channels)- ((char*)&st->rng - (char
*)st))*sizeof(*((char*)&st->rng))))
;
1912 for (i=0;i<2*st->mode->nbEBands;i++)
1913 oldLogE[i]=oldLogE2[i]=-GCONST(28.f)(28.f);
1914 st->skip_plc = 1;
1915 st->last_frame_type = FRAME_NONE0;
1916 }
1917 break;
1918 case OPUS_GET_PITCH_REQUEST4033:
1919 {
1920 opus_int32 *value = va_arg(ap, opus_int32*)__builtin_va_arg(ap, opus_int32*);
1921 if (value==NULL((void*)0))
1922 goto bad_arg;
1923 *value = st->postfilter_period;
1924 }
1925 break;
1926 case CELT_GET_MODE_REQUEST10015:
1927 {
1928 const CELTModeOpusCustomMode ** value = va_arg(ap, const CELTMode**)__builtin_va_arg(ap, const OpusCustomMode**);
1929 if (value==0)
1930 goto bad_arg;
1931 *value=st->mode;
1932 }
1933 break;
1934 case CELT_SET_SIGNALLING_REQUEST10016:
1935 {
1936 opus_int32 value = va_arg(ap, opus_int32)__builtin_va_arg(ap, opus_int32);
1937 st->signalling = value;
1938 }
1939 break;
1940 case OPUS_GET_FINAL_RANGE_REQUEST4031:
1941 {
1942 opus_uint32 * value = va_arg(ap, opus_uint32 *)__builtin_va_arg(ap, opus_uint32 *);
1943 if (value==0)
1944 goto bad_arg;
1945 *value=st->rng;
1946 }
1947 break;
1948 case OPUS_SET_PHASE_INVERSION_DISABLED_REQUEST4046:
1949 {
1950 opus_int32 value = va_arg(ap, opus_int32)__builtin_va_arg(ap, opus_int32);
1951 if(value<0 || value>1)
1952 {
1953 goto bad_arg;
1954 }
1955 st->disable_inv = value;
1956 }
1957 break;
1958 case OPUS_GET_PHASE_INVERSION_DISABLED_REQUEST4047:
1959 {
1960 opus_int32 *value = va_arg(ap, opus_int32*)__builtin_va_arg(ap, opus_int32*);
1961 if (!value)
1962 {
1963 goto bad_arg;
1964 }
1965 *value = st->disable_inv;
1966 }
1967 break;
1968 default:
1969 goto bad_request;
1970 }
1971 va_end(ap)__builtin_va_end(ap);
1972 return OPUS_OK0;
1973bad_arg:
1974 va_end(ap)__builtin_va_end(ap);
1975 return OPUS_BAD_ARG-1;
1976bad_request:
1977 va_end(ap)__builtin_va_end(ap);
1978 return OPUS_UNIMPLEMENTED-5;
1979}