unsafe-libopus 0.2.0

libopus transpiled to rust by c2rust
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
#[derive(Copy, Clone)]
#[repr(C)]
pub struct silk_DecControlStruct {
    pub nChannelsAPI: i32,
    pub nChannelsInternal: i32,
    pub API_sampleRate: i32,
    pub internalSampleRate: i32,
    pub payloadSize_ms: i32,
    pub prevPitchLag: i32,
}
pub const FLAG_DECODE_NORMAL: i32 = 0;
pub const FLAG_DECODE_LBRR: i32 = 2;
pub const FLAG_PACKET_LOST: i32 = 1;
pub mod errors_h {
    pub const SILK_DEC_INVALID_SAMPLING_FREQUENCY: i32 = -(200);
    pub const SILK_NO_ERROR: i32 = 0;
    #[allow(unused)]
    pub const SILK_DEC_INVALID_FRAME_SIZE: i32 = -(203);
}
use self::errors_h::{SILK_DEC_INVALID_SAMPLING_FREQUENCY, SILK_NO_ERROR};
use crate::celt::entdec::{ec_dec, ec_dec_bit_logp, ec_dec_icdf};
use crate::externs::{memcpy, memset};
use crate::silk::decode_frame::silk_decode_frame;
use crate::silk::decode_indices::silk_decode_indices;
use crate::silk::decode_pulses::silk_decode_pulses;
use crate::silk::decoder_set_fs::silk_decoder_set_fs;
use crate::silk::define::{
    CODE_CONDITIONALLY, CODE_INDEPENDENTLY, CODE_INDEPENDENTLY_NO_LTP_SCALING,
    DECODER_NUM_CHANNELS, MAX_API_FS_KHZ, TYPE_NO_VOICE_ACTIVITY, TYPE_VOICED,
};
use crate::silk::init_decoder::silk_init_decoder;
use crate::silk::resampler::silk_resampler;
use crate::silk::resampler::ResamplerState;
use crate::silk::stereo_MS_to_LR::silk_stereo_MS_to_LR;
use crate::silk::stereo_decode_pred::{silk_stereo_decode_mid_only, silk_stereo_decode_pred};
use crate::silk::structs::{silk_decoder_state, stereo_dec_state};
use crate::silk::tables_other::silk_LBRR_flags_iCDF_ptr;

#[derive(Copy, Clone)]
#[repr(C)]
pub struct silk_decoder {
    pub channel_state: [silk_decoder_state; 2],
    pub sStereo: stereo_dec_state,
    pub nChannelsAPI: i32,
    pub nChannelsInternal: i32,
    pub prev_decode_only_middle: i32,
}
pub unsafe fn silk_Get_Decoder_Size(decSizeBytes: *mut i32) -> i32 {
    let ret: i32 = SILK_NO_ERROR;
    *decSizeBytes = ::core::mem::size_of::<silk_decoder>() as u64 as i32;
    return ret;
}
pub unsafe fn silk_InitDecoder(decState: *mut core::ffi::c_void) -> i32 {
    let mut n: i32 = 0;
    let mut ret: i32 = SILK_NO_ERROR;
    let channel_state: *mut silk_decoder_state =
        ((*(decState as *mut silk_decoder)).channel_state).as_mut_ptr();
    n = 0;
    while n < DECODER_NUM_CHANNELS {
        ret = silk_init_decoder(&mut *channel_state.offset(n as isize));
        n += 1;
    }
    memset(
        &mut (*(decState as *mut silk_decoder)).sStereo as *mut stereo_dec_state
            as *mut core::ffi::c_void,
        0,
        ::core::mem::size_of::<stereo_dec_state>() as u64,
    );
    (*(decState as *mut silk_decoder)).prev_decode_only_middle = 0;
    return ret;
}
pub unsafe fn silk_Decode(
    decState: *mut core::ffi::c_void,
    decControl: *mut silk_DecControlStruct,
    lostFlag: i32,
    newPacketFlag: i32,
    psRangeDec: &mut ec_dec,
    samplesOut: *mut i16,
    nSamplesOut: *mut i32,
    arch: i32,
) -> i32 {
    let mut i: i32 = 0;
    let mut n: i32 = 0;
    let mut decode_only_middle: i32 = 0;
    let mut ret: i32 = SILK_NO_ERROR;
    let mut nSamplesOutDec: i32 = 0;
    let mut LBRR_symbol: i32 = 0;
    let mut samplesOut1_tmp: [*mut i16; 2] = [0 as *mut i16; 2];
    let mut MS_pred_Q13: [i32; 2] = [0, 0];
    let psDec: *mut silk_decoder = decState as *mut silk_decoder;
    let channel_state: *mut silk_decoder_state = ((*psDec).channel_state).as_mut_ptr();
    let mut has_side: i32 = 0;
    let mut stereo_to_mono: i32 = 0;
    let mut delay_stack_alloc: i32 = 0;
    assert!((*decControl).nChannelsInternal == 1 || (*decControl).nChannelsInternal == 2);
    if newPacketFlag != 0 {
        n = 0;
        while n < (*decControl).nChannelsInternal {
            (*channel_state.offset(n as isize)).nFramesDecoded = 0;
            n += 1;
        }
    }
    if (*decControl).nChannelsInternal > (*psDec).nChannelsInternal {
        ret += silk_init_decoder(&mut *channel_state.offset(1 as isize));
    }
    stereo_to_mono = ((*decControl).nChannelsInternal == 1
        && (*psDec).nChannelsInternal == 2
        && (*decControl).internalSampleRate == 1000 * (*channel_state.offset(0 as isize)).fs_kHz)
        as i32;
    if (*channel_state.offset(0 as isize)).nFramesDecoded == 0 {
        n = 0;
        while n < (*decControl).nChannelsInternal {
            let mut fs_kHz_dec: i32 = 0;
            if (*decControl).payloadSize_ms == 0 {
                (*channel_state.offset(n as isize)).nFramesPerPacket = 1;
                (*channel_state.offset(n as isize)).nb_subfr = 2;
            } else if (*decControl).payloadSize_ms == 10 {
                (*channel_state.offset(n as isize)).nFramesPerPacket = 1;
                (*channel_state.offset(n as isize)).nb_subfr = 2;
            } else if (*decControl).payloadSize_ms == 20 {
                (*channel_state.offset(n as isize)).nFramesPerPacket = 1;
                (*channel_state.offset(n as isize)).nb_subfr = 4;
            } else if (*decControl).payloadSize_ms == 40 {
                (*channel_state.offset(n as isize)).nFramesPerPacket = 2;
                (*channel_state.offset(n as isize)).nb_subfr = 4;
            } else if (*decControl).payloadSize_ms == 60 {
                (*channel_state.offset(n as isize)).nFramesPerPacket = 3;
                (*channel_state.offset(n as isize)).nb_subfr = 4;
            } else {
                // see comments in `[unsafe_libopus::silk::check_control_input]`
                panic!("libopus: assert(0) called");
                // return SILK_DEC_INVALID_FRAME_SIZE;
            }
            fs_kHz_dec = ((*decControl).internalSampleRate >> 10) + 1;
            if fs_kHz_dec != 8 && fs_kHz_dec != 12 && fs_kHz_dec != 16 {
                panic!("libopus: assert(0) called");
                // return SILK_DEC_INVALID_SAMPLING_FREQUENCY;
            }
            ret += silk_decoder_set_fs(
                &mut *channel_state.offset(n as isize),
                fs_kHz_dec,
                (*decControl).API_sampleRate,
            );
            n += 1;
        }
    }
    if (*decControl).nChannelsAPI == 2
        && (*decControl).nChannelsInternal == 2
        && ((*psDec).nChannelsAPI == 1 || (*psDec).nChannelsInternal == 1)
    {
        memset(
            ((*psDec).sStereo.pred_prev_Q13).as_mut_ptr() as *mut core::ffi::c_void,
            0,
            ::core::mem::size_of::<[i16; 2]>() as u64,
        );
        memset(
            ((*psDec).sStereo.sSide).as_mut_ptr() as *mut core::ffi::c_void,
            0,
            ::core::mem::size_of::<[i16; 2]>() as u64,
        );
        memcpy(
            &mut (*channel_state.offset(1 as isize)).resampler_state as *mut ResamplerState
                as *mut core::ffi::c_void,
            &mut (*channel_state.offset(0 as isize)).resampler_state as *mut ResamplerState
                as *const core::ffi::c_void,
            ::core::mem::size_of::<ResamplerState>() as u64,
        );
    }
    (*psDec).nChannelsAPI = (*decControl).nChannelsAPI;
    (*psDec).nChannelsInternal = (*decControl).nChannelsInternal;
    if (*decControl).API_sampleRate > MAX_API_FS_KHZ * 1000 || (*decControl).API_sampleRate < 8000 {
        ret = SILK_DEC_INVALID_SAMPLING_FREQUENCY;
        return ret;
    }
    if lostFlag != FLAG_PACKET_LOST && (*channel_state.offset(0 as isize)).nFramesDecoded == 0 {
        n = 0;
        while n < (*decControl).nChannelsInternal {
            i = 0;
            while i < (*channel_state.offset(n as isize)).nFramesPerPacket {
                (*channel_state.offset(n as isize)).VAD_flags[i as usize] =
                    ec_dec_bit_logp(psRangeDec, 1);
                i += 1;
            }
            (*channel_state.offset(n as isize)).LBRR_flag = ec_dec_bit_logp(psRangeDec, 1);
            n += 1;
        }
        n = 0;
        while n < (*decControl).nChannelsInternal {
            memset(
                ((*channel_state.offset(n as isize)).LBRR_flags).as_mut_ptr()
                    as *mut core::ffi::c_void,
                0,
                ::core::mem::size_of::<[i32; 3]>() as u64,
            );
            if (*channel_state.offset(n as isize)).LBRR_flag != 0 {
                if (*channel_state.offset(n as isize)).nFramesPerPacket == 1 {
                    (*channel_state.offset(n as isize)).LBRR_flags[0 as usize] = 1;
                } else {
                    LBRR_symbol = ec_dec_icdf(
                        psRangeDec,
                        silk_LBRR_flags_iCDF_ptr
                            [((*channel_state.offset(n as isize)).nFramesPerPacket - 2) as usize],
                        8,
                    ) + 1;
                    i = 0;
                    while i < (*channel_state.offset(n as isize)).nFramesPerPacket {
                        (*channel_state.offset(n as isize)).LBRR_flags[i as usize] =
                            LBRR_symbol >> i & 1;
                        i += 1;
                    }
                }
            }
            n += 1;
        }
        if lostFlag == FLAG_DECODE_NORMAL {
            i = 0;
            while i < (*channel_state.offset(0 as isize)).nFramesPerPacket {
                n = 0;
                while n < (*decControl).nChannelsInternal {
                    if (*channel_state.offset(n as isize)).LBRR_flags[i as usize] != 0 {
                        let mut pulses: [i16; 320] = [0; 320];
                        let mut condCoding: i32 = 0;
                        if (*decControl).nChannelsInternal == 2 && n == 0 {
                            silk_stereo_decode_pred(psRangeDec, MS_pred_Q13.as_mut_ptr());
                            if (*channel_state.offset(1 as isize)).LBRR_flags[i as usize] == 0 {
                                silk_stereo_decode_mid_only(psRangeDec, &mut decode_only_middle);
                            }
                        }
                        if i > 0
                            && (*channel_state.offset(n as isize)).LBRR_flags[(i - 1) as usize] != 0
                        {
                            condCoding = CODE_CONDITIONALLY;
                        } else {
                            condCoding = CODE_INDEPENDENTLY;
                        }
                        silk_decode_indices(
                            &mut *channel_state.offset(n as isize),
                            psRangeDec,
                            i,
                            1,
                            condCoding,
                        );
                        silk_decode_pulses(
                            psRangeDec,
                            pulses.as_mut_ptr(),
                            (*channel_state.offset(n as isize)).indices.signalType as i32,
                            (*channel_state.offset(n as isize)).indices.quantOffsetType as i32,
                            (*channel_state.offset(n as isize)).frame_length,
                        );
                    }
                    n += 1;
                }
                i += 1;
            }
        }
    }
    if (*decControl).nChannelsInternal == 2 {
        if lostFlag == FLAG_DECODE_NORMAL
            || lostFlag == FLAG_DECODE_LBRR
                && (*channel_state.offset(0 as isize)).LBRR_flags
                    [(*channel_state.offset(0 as isize)).nFramesDecoded as usize]
                    == 1
        {
            silk_stereo_decode_pred(psRangeDec, MS_pred_Q13.as_mut_ptr());
            if lostFlag == FLAG_DECODE_NORMAL
                && (*channel_state.offset(1 as isize)).VAD_flags
                    [(*channel_state.offset(0 as isize)).nFramesDecoded as usize]
                    == 0
                || lostFlag == FLAG_DECODE_LBRR
                    && (*channel_state.offset(1 as isize)).LBRR_flags
                        [(*channel_state.offset(0 as isize)).nFramesDecoded as usize]
                        == 0
            {
                silk_stereo_decode_mid_only(psRangeDec, &mut decode_only_middle);
            } else {
                decode_only_middle = 0;
            }
        } else {
            n = 0;
            while n < 2 {
                MS_pred_Q13[n as usize] = (*psDec).sStereo.pred_prev_Q13[n as usize] as i32;
                n += 1;
            }
        }
    }
    if (*decControl).nChannelsInternal == 2
        && decode_only_middle == 0
        && (*psDec).prev_decode_only_middle == 1
    {
        memset(
            ((*psDec).channel_state[1 as usize].outBuf).as_mut_ptr() as *mut core::ffi::c_void,
            0,
            ::core::mem::size_of::<[i16; 480]>() as u64,
        );
        memset(
            ((*psDec).channel_state[1 as usize].sLPC_Q14_buf).as_mut_ptr()
                as *mut core::ffi::c_void,
            0,
            ::core::mem::size_of::<[i32; 16]>() as u64,
        );
        (*psDec).channel_state[1 as usize].lagPrev = 100;
        (*psDec).channel_state[1 as usize].LastGainIndex = 10;
        (*psDec).channel_state[1 as usize].prevSignalType = TYPE_NO_VOICE_ACTIVITY;
        (*psDec).channel_state[1 as usize].first_frame_after_reset = 1;
    }
    delay_stack_alloc = ((*decControl).internalSampleRate * (*decControl).nChannelsInternal
        < (*decControl).API_sampleRate * (*decControl).nChannelsAPI) as i32;
    let vla = (if delay_stack_alloc != 0 {
        1
    } else {
        (*decControl).nChannelsInternal * ((*channel_state.offset(0 as isize)).frame_length + 2)
    }) as usize;
    let mut samplesOut1_tmp_storage1: Vec<i16> = ::std::vec::from_elem(0, vla);
    if delay_stack_alloc != 0 {
        samplesOut1_tmp[0 as usize] = samplesOut;
        samplesOut1_tmp[1 as usize] = samplesOut
            .offset((*channel_state.offset(0 as isize)).frame_length as isize)
            .offset(2 as isize);
    } else {
        samplesOut1_tmp[0 as usize] = samplesOut1_tmp_storage1.as_mut_ptr();
        samplesOut1_tmp[1 as usize] = samplesOut1_tmp_storage1
            .as_mut_ptr()
            .offset((*channel_state.offset(0 as isize)).frame_length as isize)
            .offset(2 as isize);
    }
    if lostFlag == FLAG_DECODE_NORMAL {
        has_side = (decode_only_middle == 0) as i32;
    } else {
        has_side = ((*psDec).prev_decode_only_middle == 0
            || (*decControl).nChannelsInternal == 2
                && lostFlag == FLAG_DECODE_LBRR
                && (*channel_state.offset(1 as isize)).LBRR_flags
                    [(*channel_state.offset(1 as isize)).nFramesDecoded as usize]
                    == 1) as i32;
    }
    n = 0;
    while n < (*decControl).nChannelsInternal {
        if n == 0 || has_side != 0 {
            let mut FrameIndex: i32 = 0;
            let mut condCoding_0: i32 = 0;
            FrameIndex = (*channel_state.offset(0 as isize)).nFramesDecoded - n;
            if FrameIndex <= 0 {
                condCoding_0 = CODE_INDEPENDENTLY;
            } else if lostFlag == FLAG_DECODE_LBRR {
                condCoding_0 = if (*channel_state.offset(n as isize)).LBRR_flags
                    [(FrameIndex - 1) as usize]
                    != 0
                {
                    CODE_CONDITIONALLY
                } else {
                    CODE_INDEPENDENTLY
                };
            } else if n > 0 && (*psDec).prev_decode_only_middle != 0 {
                condCoding_0 = CODE_INDEPENDENTLY_NO_LTP_SCALING;
            } else {
                condCoding_0 = CODE_CONDITIONALLY;
            }
            ret += silk_decode_frame(
                &mut *channel_state.offset(n as isize),
                psRangeDec,
                &mut *(*samplesOut1_tmp.as_mut_ptr().offset(n as isize)).offset(2 as isize),
                &mut nSamplesOutDec,
                lostFlag,
                condCoding_0,
                arch,
            );
        } else {
            memset(
                &mut *(*samplesOut1_tmp.as_mut_ptr().offset(n as isize)).offset(2 as isize)
                    as *mut i16 as *mut core::ffi::c_void,
                0,
                (nSamplesOutDec as u64).wrapping_mul(::core::mem::size_of::<i16>() as u64),
            );
        }
        let ref mut fresh0 = (*channel_state.offset(n as isize)).nFramesDecoded;
        *fresh0 += 1;
        n += 1;
    }
    if (*decControl).nChannelsAPI == 2 && (*decControl).nChannelsInternal == 2 {
        silk_stereo_MS_to_LR(
            &mut (*psDec).sStereo,
            samplesOut1_tmp[0 as usize],
            samplesOut1_tmp[1 as usize],
            MS_pred_Q13.as_mut_ptr() as *const i32,
            (*channel_state.offset(0 as isize)).fs_kHz,
            nSamplesOutDec,
        );
    } else {
        memcpy(
            samplesOut1_tmp[0 as usize] as *mut core::ffi::c_void,
            ((*psDec).sStereo.sMid).as_mut_ptr() as *const core::ffi::c_void,
            2_u64.wrapping_mul(::core::mem::size_of::<i16>() as u64),
        );
        memcpy(
            ((*psDec).sStereo.sMid).as_mut_ptr() as *mut core::ffi::c_void,
            &mut *(*samplesOut1_tmp.as_mut_ptr().offset(0 as isize)).offset(nSamplesOutDec as isize)
                as *mut i16 as *const core::ffi::c_void,
            2_u64.wrapping_mul(::core::mem::size_of::<i16>() as u64),
        );
    }
    *nSamplesOut = nSamplesOutDec * (*decControl).API_sampleRate
        / ((*channel_state.offset(0 as isize)).fs_kHz as i16 as i32 * 1000);

    let vla_0 = (if (*decControl).nChannelsAPI == 2 {
        *nSamplesOut
    } else {
        1
    }) as usize;
    let mut samplesOut2_tmp: Vec<i16> = ::std::vec::from_elem(0, vla_0);

    let resample_out_ptr = if (*decControl).nChannelsAPI == 2 {
        samplesOut2_tmp.as_mut_slice()
    } else {
        std::slice::from_raw_parts_mut(samplesOut, *nSamplesOut as usize)
    };

    let vla_1 = (if delay_stack_alloc != 0 {
        (*decControl).nChannelsInternal * ((*channel_state.offset(0 as isize)).frame_length + 2)
    } else {
        1
    }) as usize;
    let mut samplesOut1_tmp_storage2: Vec<i16> = ::std::vec::from_elem(0, vla_1);
    if delay_stack_alloc != 0 {
        memcpy(
            samplesOut1_tmp_storage2.as_mut_ptr() as *mut core::ffi::c_void,
            samplesOut as *const core::ffi::c_void,
            (((*decControl).nChannelsInternal
                * ((*channel_state.offset(0 as isize)).frame_length + 2)) as u64)
                .wrapping_mul(::core::mem::size_of::<i16>() as u64)
                .wrapping_add(
                    (0 * samplesOut1_tmp_storage2
                        .as_mut_ptr()
                        .offset_from(samplesOut) as i64) as u64,
                ),
        );
        samplesOut1_tmp[0 as usize] = samplesOut1_tmp_storage2.as_mut_ptr();
        samplesOut1_tmp[1 as usize] = samplesOut1_tmp_storage2
            .as_mut_ptr()
            .offset((*channel_state.offset(0 as isize)).frame_length as isize)
            .offset(2 as isize);
    }
    n = 0;
    while n
        < (if (*decControl).nChannelsAPI < (*decControl).nChannelsInternal {
            (*decControl).nChannelsAPI
        } else {
            (*decControl).nChannelsInternal
        })
    {
        /* Resample decoded signal to API_sampleRate */
        ret += silk_resampler(
            &mut (*channel_state.offset(n as isize)).resampler_state,
            resample_out_ptr,
            std::slice::from_raw_parts(
                &mut *samplesOut1_tmp[n as usize].offset(1 as isize) as *mut i16 as *const i16,
                nSamplesOutDec as usize,
            ),
        );
        if (*decControl).nChannelsAPI == 2 {
            i = 0;
            while i < *nSamplesOut {
                *samplesOut.offset((n + 2 * i) as isize) = resample_out_ptr[i as usize];
                i += 1;
            }
        }
        n += 1;
    }

    /* Create two channel output from mono stream */
    if (*decControl).nChannelsAPI == 2 && (*decControl).nChannelsInternal == 1 {
        if stereo_to_mono != 0 {
            /* Resample right channel for newly collapsed stereo just in case
            we weren't doing collapsing when switching to mono */
            ret += silk_resampler(
                &mut (*channel_state.offset(1 as isize)).resampler_state,
                resample_out_ptr,
                std::slice::from_raw_parts(
                    &mut *samplesOut1_tmp[0].offset(1 as isize) as *mut i16 as *const i16,
                    nSamplesOutDec as usize,
                ),
            );
            i = 0;
            while i < *nSamplesOut {
                *samplesOut.offset((1 + 2 * i) as isize) = resample_out_ptr[i as usize];
                i += 1;
            }
        } else {
            i = 0;
            while i < *nSamplesOut {
                *samplesOut.offset((1 + 2 * i) as isize) = *samplesOut.offset((0 + 2 * i) as isize);
                i += 1;
            }
        }
    }
    if (*channel_state.offset(0 as isize)).prevSignalType == TYPE_VOICED {
        let mult_tab: [i32; 3] = [6, 4, 3];
        (*decControl).prevPitchLag = (*channel_state.offset(0 as isize)).lagPrev
            * mult_tab[((*channel_state.offset(0 as isize)).fs_kHz - 8 >> 2) as usize];
    } else {
        (*decControl).prevPitchLag = 0;
    }
    if lostFlag == FLAG_PACKET_LOST {
        i = 0;
        while i < (*psDec).nChannelsInternal {
            (*psDec).channel_state[i as usize].LastGainIndex = 10;
            i += 1;
        }
    } else {
        (*psDec).prev_decode_only_middle = decode_only_middle;
    }
    return ret;
}