Bug Summary

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