unsafe_libopus/celt/
modes.rs

1#[derive(Copy, Clone)]
2#[repr(C)]
3pub struct OpusCustomMode {
4    pub(crate) Fs: i32,
5    pub(crate) overlap: i32,
6    pub(crate) nbEBands: i32,
7    pub(crate) effEBands: i32,
8    pub(crate) preemph: [opus_val16; 4],
9    pub(crate) eBands: *const i16,
10    pub(crate) maxLM: i32,
11    pub(crate) nbShortMdcts: i32,
12    pub(crate) shortMdctSize: i32,
13    pub(crate) nbAllocVectors: i32,
14    pub(crate) allocVectors: *const u8,
15    pub(crate) logN: *const i16,
16    pub(crate) window: *const opus_val16,
17    pub(crate) mdct: mdct_lookup<'static>,
18    pub(crate) cache: PulseCache,
19}
20#[derive(Copy, Clone)]
21#[repr(C)]
22pub struct PulseCache {
23    pub size: i32,
24    pub index: *const i16,
25    pub bits: *const u8,
26    pub caps: *const u8,
27}
28pub const MAX_PERIOD: i32 = 1024;
29
30pub mod arch_h {
31    pub type opus_val16 = f32;
32}
33pub mod stddef_h {
34    pub const NULL: i32 = 0;
35}
36
37pub mod static_modes_float_h;
38
39pub use self::arch_h::opus_val16;
40pub use self::static_modes_float_h::{
41    cache_bits50, cache_caps50, cache_index50, fft_bitrev120, fft_bitrev240, fft_bitrev480,
42    fft_bitrev60, fft_twiddles48000_960, logN400, static_mode_list, window120,
43};
44pub use self::stddef_h::NULL;
45use crate::celt::mdct::mdct_lookup;
46use crate::src::opus_defines::{OPUS_BAD_ARG, OPUS_OK};
47
48static eband5ms: [i16; 22] = [
49    0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 34, 40, 48, 60, 78, 100,
50];
51static band_allocation: [u8; 231] = [
52    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 90, 80, 75, 69, 63, 56, 49, 40,
53    34, 29, 20, 18, 10, 0, 0, 0, 0, 0, 0, 0, 0, 110, 100, 90, 84, 78, 71, 65, 58, 51, 45, 39, 32,
54    26, 20, 12, 0, 0, 0, 0, 0, 0, 118, 110, 103, 93, 86, 80, 75, 70, 65, 59, 53, 47, 40, 31, 23,
55    15, 4, 0, 0, 0, 0, 126, 119, 112, 104, 95, 89, 83, 78, 72, 66, 60, 54, 47, 39, 32, 25, 17, 12,
56    1, 0, 0, 134, 127, 120, 114, 103, 97, 91, 85, 78, 72, 66, 60, 54, 47, 41, 35, 29, 23, 16, 10,
57    1, 144, 137, 130, 124, 113, 107, 101, 95, 88, 82, 76, 70, 64, 57, 51, 45, 39, 33, 26, 15, 1,
58    152, 145, 138, 132, 123, 117, 111, 105, 98, 92, 86, 80, 74, 67, 61, 55, 49, 43, 36, 20, 1, 162,
59    155, 148, 142, 133, 127, 121, 115, 108, 102, 96, 90, 84, 77, 71, 65, 59, 53, 46, 30, 1, 172,
60    165, 158, 152, 143, 137, 131, 125, 118, 112, 106, 100, 94, 87, 81, 75, 69, 63, 56, 45, 20, 200,
61    200, 200, 200, 200, 200, 200, 200, 198, 193, 188, 183, 178, 173, 168, 163, 158, 153, 148, 129,
62    104,
63];
64
65pub unsafe fn opus_custom_mode_create(
66    Fs: i32,
67    frame_size: i32,
68    error: *mut i32,
69) -> *const OpusCustomMode {
70    // TODO: make static_mode_list non-mutable (requires Sync)
71    // TODO: maybe return Result instead of error code?
72    for mode in static_mode_list {
73        for j in 0..4 {
74            if Fs == (*mode).Fs && frame_size << j == (*mode).shortMdctSize * (*mode).nbShortMdcts {
75                if !error.is_null() {
76                    *error = OPUS_OK;
77                }
78                return mode;
79            }
80        }
81    }
82    if !error.is_null() {
83        *error = OPUS_BAD_ARG;
84    }
85    return NULL as *mut OpusCustomMode;
86}