├── src ├── silk │ ├── debug.rs │ ├── mathops.rs │ ├── float │ │ ├── bwexpander_FLP.rs │ │ ├── energy_FLP.rs │ │ ├── k2a_FLP.rs │ │ ├── autocorrelation_FLP.rs │ │ ├── scale_copy_vector_FLP.rs │ │ ├── SigProc_FLP.rs │ │ ├── apply_sine_window_FLP.rs │ │ ├── schur_FLP.rs │ │ ├── sort_FLP.rs │ │ ├── LTP_scale_ctrl_FLP.rs │ │ ├── warped_autocorrelation_FLP.rs │ │ ├── structs_FLP.rs │ │ ├── LTP_analysis_filter_FLP.rs │ │ ├── residual_energy_FLP.rs │ │ └── find_LTP_FLP.rs │ ├── tables_gain.rs │ ├── inner_prod_aligned.rs │ ├── lin2log.rs │ ├── resampler │ │ ├── ar2.rs │ │ ├── down2.rs │ │ └── rom.rs │ ├── interpolate.rs │ ├── bwexpander_32.rs │ ├── tables_pitch_lag.rs │ ├── sigm_Q15.rs │ ├── bwexpander.rs │ ├── table_LSF_cos.rs │ ├── NLSF_unpack.rs │ ├── init_encoder.rs │ ├── macros.rs │ ├── log2lin.rs │ ├── stereo_encode_pred.rs │ ├── init_decoder.rs │ ├── sort.rs │ ├── LPC_analysis_filter.rs │ ├── NLSF_VQ.rs │ ├── sum_sqr_shift.rs │ ├── biquad_alt.rs │ ├── NLSF_VQ_weights_laroia.rs │ ├── decode_pitch.rs │ ├── LPC_fit.rs │ ├── stereo_decode_pred.rs │ ├── tables_other.rs │ ├── stereo_quant_pred.rs │ ├── pitch_est_tables.rs │ └── ana_filt_bank_1.rs ├── util │ ├── mod.rs │ └── nalgebra.rs ├── src │ ├── mlp │ │ └── mod.rs │ └── opus_private.rs └── celt │ ├── float_cast.rs │ └── tests │ └── test_unit_types.rs ├── upstream-libopus ├── opus │ ├── NEWS │ ├── ChangeLog │ ├── config.h.cmake.in │ ├── tests │ │ └── opus_decode_fuzzer.options │ ├── opus_headers.mk │ ├── AUTHORS │ ├── training │ │ ├── txt2hdf5.py │ │ └── rnn_dump.py │ ├── opus-uninstalled.pc.in │ ├── opus_sources.mk │ ├── opus.pc.in │ ├── .travis.yml │ ├── autogen.sh │ ├── win32 │ │ ├── VS2015 │ │ │ ├── test_opus_api.vcxproj.filters │ │ │ ├── test_opus_decode.vcxproj.filters │ │ │ ├── test_opus_encode.vcxproj.filters │ │ │ └── opus_demo.vcxproj.filters │ │ └── genversion.bat │ ├── OpusConfig.cmake.in │ ├── LICENSE_PLEASE_READ.txt │ ├── doc │ │ ├── footer.html │ │ ├── Makefile.am │ │ ├── release.txt │ │ ├── opus_in_isobmff.css │ │ ├── header.html │ │ ├── build_isobmff.sh │ │ └── build_oggdraft.sh │ ├── opus_buildtype.cmake │ ├── .appveyor.yml │ ├── m4 │ │ ├── opus-intrinsics.m4 │ │ └── ax_add_fortify_source.m4 │ ├── celt_sources.mk │ ├── silk_headers.mk │ ├── celt_headers.mk │ ├── opus_config.cmake │ ├── celt │ │ ├── arm │ │ │ ├── fixed_arm64.h │ │ │ ├── armopts.s.in │ │ │ ├── fft_arm.h │ │ │ └── armcpu.h │ │ ├── dump_modes │ │ │ └── dump_modes_arch.h │ │ ├── tests │ │ │ └── test_unit_types.c │ │ ├── cwrs.h │ │ ├── x86 │ │ │ ├── vq_sse.h │ │ │ └── celt_lpc_sse.h │ │ ├── laplace.h │ │ ├── mfrngcod.h │ │ ├── fixed_c6x.h │ │ ├── celt_lpc.h │ │ ├── cpu_support.h │ │ └── modes.h │ ├── silk │ │ ├── arm │ │ │ ├── macros_arm64.h │ │ │ ├── SigProc_FIX_armv4.h │ │ │ └── SigProc_FIX_armv5e.h │ │ ├── lin2log.c │ │ ├── mips │ │ │ └── sigproc_fix_mipsr1.h │ │ ├── float │ │ │ ├── scale_vector_FLP.c │ │ │ ├── bwexpander_FLP.c │ │ │ ├── regularize_correlations_FLP.c │ │ │ ├── scale_copy_vector_FLP.c │ │ │ ├── energy_FLP.c │ │ │ ├── inner_product_FLP.c │ │ │ ├── k2a_FLP.c │ │ │ └── autocorrelation_FLP.c │ │ ├── init_decoder.c │ │ ├── inner_prod_aligned.c │ │ ├── bwexpander_32.c │ │ ├── tables_gain.c │ │ ├── interpolate.c │ │ └── fixed │ │ │ └── regularize_correlations_FIX.c │ ├── COPYING │ ├── scripts │ │ ├── dump_rnn.py │ │ └── rnn_train.py │ ├── opus_sources.cmake │ ├── src │ │ ├── mlp.h │ │ └── tansig_table.h │ └── README.draft ├── src │ └── wrapper.h ├── README.md └── Cargo.toml ├── .gitignore ├── unsafe-libopus-tools ├── src │ ├── lib.rs │ └── bin │ │ ├── opus_compare.rs │ │ └── opus_demo │ │ └── main.rs └── Cargo.toml ├── Cargo.toml ├── LICENSE └── .github └── workflows └── test.yml /src/silk/debug.rs: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /upstream-libopus/opus/NEWS: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /upstream-libopus/opus/ChangeLog: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/util/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod nalgebra; 2 | -------------------------------------------------------------------------------- /upstream-libopus/src/wrapper.h: -------------------------------------------------------------------------------- 1 | #include "../opus/include/opus_multistream.h" 2 | -------------------------------------------------------------------------------- /upstream-libopus/opus/config.h.cmake.in: -------------------------------------------------------------------------------- 1 | #cmakedefine PACKAGE_VERSION "@PACKAGE_VERSION@" -------------------------------------------------------------------------------- /upstream-libopus/opus/tests/opus_decode_fuzzer.options: -------------------------------------------------------------------------------- 1 | [libfuzzer] 2 | max_len = 1000000 3 | -------------------------------------------------------------------------------- /src/silk/mathops.rs: -------------------------------------------------------------------------------- 1 | pub fn silk_exp2(x: f32) -> f32 { 2 | 2f64.powf(x as f64) as f32 3 | } 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | /Cargo.lock 3 | .idea 4 | 5 | logs_*.txt 6 | tmp.out 7 | aboba.tmp 8 | dump 9 | -------------------------------------------------------------------------------- /upstream-libopus/README.md: -------------------------------------------------------------------------------- 1 | This crate builds and provides bindings to opus 1.3.1 with the same configuration as the translated library 2 | -------------------------------------------------------------------------------- /src/src/mlp/mod.rs: -------------------------------------------------------------------------------- 1 | #![forbid( 2 | unsafe_code, 3 | non_camel_case_types, 4 | non_snake_case, 5 | non_upper_case_globals, 6 | unused_assignments 7 | )] 8 | 9 | pub mod analysis_mlp; 10 | mod layers; 11 | mod tansig; 12 | -------------------------------------------------------------------------------- /upstream-libopus/opus/opus_headers.mk: -------------------------------------------------------------------------------- 1 | OPUS_HEAD = \ 2 | include/opus.h \ 3 | include/opus_multistream.h \ 4 | include/opus_projection.h \ 5 | src/opus_private.h \ 6 | src/analysis.h \ 7 | src/mapping_matrix.h \ 8 | src/mlp.h \ 9 | src/tansig_table.h 10 | -------------------------------------------------------------------------------- /upstream-libopus/opus/AUTHORS: -------------------------------------------------------------------------------- 1 | Jean-Marc Valin (jmvalin@jmvalin.ca) 2 | Koen Vos (koenvos74@gmail.com) 3 | Timothy Terriberry (tterribe@xiph.org) 4 | Karsten Vandborg Sorensen (karsten.vandborg.sorensen@skype.net) 5 | Soren Skak Jensen (ssjensen@gn.com) 6 | Gregory Maxwell (greg@xiph.org) 7 | -------------------------------------------------------------------------------- /unsafe-libopus-tools/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! Utilities for testing opus 2 | //! 3 | //! This crate contains opus test utilities converted to functions 4 | //! Binaries are also available 5 | 6 | mod compare; 7 | pub mod demo; 8 | 9 | pub use compare::{opus_compare, CompareParams, CompareResult}; 10 | -------------------------------------------------------------------------------- /upstream-libopus/opus/training/txt2hdf5.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | from __future__ import print_function 4 | 5 | import numpy as np 6 | import h5py 7 | import sys 8 | 9 | data = np.loadtxt(sys.argv[1], dtype='float32') 10 | h5f = h5py.File(sys.argv[2], 'w'); 11 | h5f.create_dataset('data', data=data) 12 | h5f.close() 13 | -------------------------------------------------------------------------------- /upstream-libopus/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "upstream-libopus" 3 | version = "0.1.0" 4 | edition = "2021" 5 | publish = false 6 | 7 | [dependencies] 8 | 9 | [build-dependencies] 10 | cc = "1.0.99" 11 | bindgen = { version = "0.69.4", optional = true } 12 | 13 | [features] 14 | default = [] 15 | generate_binding = ["bindgen"] 16 | -------------------------------------------------------------------------------- /src/celt/float_cast.rs: -------------------------------------------------------------------------------- 1 | pub const CELT_SIG_SCALE: f32 = 32768.0f32; 2 | 3 | #[inline] 4 | pub fn FLOAT2INT16(x: f32) -> i16 { 5 | let x = x * CELT_SIG_SCALE; 6 | let x = x.max(-32768.0); 7 | let x = x.min(32767.0); 8 | float2int(x) as i16 9 | } 10 | #[inline] 11 | pub fn float2int(x: f32) -> i32 { 12 | (x + 0.5).floor() as i32 13 | } 14 | -------------------------------------------------------------------------------- /src/silk/float/bwexpander_FLP.rs: -------------------------------------------------------------------------------- 1 | pub unsafe fn silk_bwexpander_FLP(ar: *mut f32, d: i32, chirp: f32) { 2 | let mut i: i32 = 0; 3 | let mut cfac: f32 = chirp; 4 | i = 0; 5 | while i < d - 1 { 6 | *ar.offset(i as isize) *= cfac; 7 | cfac *= chirp; 8 | i += 1; 9 | } 10 | *ar.offset((d - 1) as isize) *= cfac; 11 | } 12 | -------------------------------------------------------------------------------- /upstream-libopus/opus/opus-uninstalled.pc.in: -------------------------------------------------------------------------------- 1 | # Opus codec reference implementation uninstalled pkg-config file 2 | 3 | libdir=${pcfiledir}/.libs 4 | includedir=${pcfiledir} 5 | 6 | Name: opus uninstalled 7 | Description: Opus IETF audio codec (not installed, @PC_BUILD@) 8 | Version: @VERSION@ 9 | Requires: 10 | Conflicts: 11 | Libs: ${libdir}/libopus.la @LIBM@ 12 | Cflags: -I${pcfiledir}/@top_srcdir@/include 13 | -------------------------------------------------------------------------------- /src/silk/float/energy_FLP.rs: -------------------------------------------------------------------------------- 1 | use ndarray::aview1; 2 | 3 | /// Sum of squares of a float array, with result as a double 4 | pub fn silk_energy_FLP(data: &[f32]) -> f64 { 5 | let data_view = aview1(data); 6 | 7 | // opus sources unfold it manually, but LLVM seems to be able to 4x unfold it by itself 8 | // SIMD might still be nice idk 9 | data_view.fold(0.0f64, |acc, &x| acc + x as f64 * x as f64) 10 | } 11 | -------------------------------------------------------------------------------- /src/silk/tables_gain.rs: -------------------------------------------------------------------------------- 1 | pub static silk_gain_iCDF: [[u8; 8]; 3] = [ 2 | [224, 112, 44, 15, 3, 2, 1, 0], 3 | [254, 237, 192, 132, 70, 23, 4, 0], 4 | [255, 252, 226, 155, 61, 11, 2, 0], 5 | ]; 6 | pub static silk_delta_gain_iCDF: [u8; 41] = [ 7 | 250, 245, 234, 203, 71, 50, 42, 38, 35, 33, 31, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 8 | 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 9 | ]; 10 | -------------------------------------------------------------------------------- /upstream-libopus/opus/opus_sources.mk: -------------------------------------------------------------------------------- 1 | OPUS_SOURCES = \ 2 | src/opus.c \ 3 | src/opus_decoder.c \ 4 | src/opus_encoder.c \ 5 | src/opus_multistream.c \ 6 | src/opus_multistream_encoder.c \ 7 | src/opus_multistream_decoder.c \ 8 | src/repacketizer.c \ 9 | src/opus_projection_encoder.c \ 10 | src/opus_projection_decoder.c \ 11 | src/mapping_matrix.c 12 | 13 | OPUS_SOURCES_FLOAT = \ 14 | src/analysis.c \ 15 | src/mlp.c \ 16 | src/mlp_data.c 17 | -------------------------------------------------------------------------------- /upstream-libopus/opus/opus.pc.in: -------------------------------------------------------------------------------- 1 | # Opus codec reference implementation pkg-config file 2 | 3 | prefix=@prefix@ 4 | exec_prefix=@exec_prefix@ 5 | libdir=@libdir@ 6 | includedir=@includedir@ 7 | 8 | Name: Opus 9 | Description: Opus IETF audio codec (@PC_BUILD@ build) 10 | URL: https://opus-codec.org/ 11 | Version: @VERSION@ 12 | Requires: 13 | Conflicts: 14 | Libs: -L${libdir} -lopus 15 | Libs.private: @LIBM@ 16 | Cflags: -I${includedir}/opus 17 | -------------------------------------------------------------------------------- /upstream-libopus/opus/.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | 3 | compiler: 4 | - gcc 5 | - clang 6 | 7 | os: 8 | - linux 9 | - osx 10 | 11 | env: 12 | - CONFIG="" 13 | - CONFIG="--enable-assertions" 14 | - CONFIG="--enable-fixed-point" 15 | - CONFIG="--enable-fixed-point --disable-float-api" 16 | - CONFIG="--enable-fixed-point --enable-assertions" 17 | 18 | script: 19 | - ./autogen.sh 20 | - ./configure $CONFIG 21 | - make distcheck 22 | -------------------------------------------------------------------------------- /src/silk/inner_prod_aligned.rs: -------------------------------------------------------------------------------- 1 | pub unsafe fn silk_inner_prod_aligned_scale( 2 | inVec1: *const i16, 3 | inVec2: *const i16, 4 | scale: i32, 5 | len: i32, 6 | ) -> i32 { 7 | let mut i: i32 = 0; 8 | let mut sum: i32 = 0; 9 | i = 0; 10 | while i < len { 11 | sum = 12 | sum + (*inVec1.offset(i as isize) as i32 * *inVec2.offset(i as isize) as i32 >> scale); 13 | i += 1; 14 | } 15 | return sum; 16 | } 17 | -------------------------------------------------------------------------------- /upstream-libopus/opus/autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Copyright (c) 2010-2015 Xiph.Org Foundation and contributors. 3 | # Use of this source code is governed by a BSD-style license that can be 4 | # found in the COPYING file. 5 | 6 | # Run this to set up the build system: configure, makefiles, etc. 7 | set -e 8 | 9 | srcdir=`dirname $0` 10 | test -n "$srcdir" && cd "$srcdir" 11 | 12 | echo "Updating build configuration files, please wait...." 13 | 14 | autoreconf -isf 15 | -------------------------------------------------------------------------------- /src/silk/lin2log.rs: -------------------------------------------------------------------------------- 1 | use crate::silk::Inlines::silk_CLZ_FRAC; 2 | 3 | // Approximation of 128 * log2() (very close inverse of silk_log2lin()) 4 | // Convert input to a log scale 5 | pub fn silk_lin2log(inLin: i32) -> i32 { 6 | let mut lz: i32 = 0; 7 | let mut frac_Q7: i32 = 0; 8 | silk_CLZ_FRAC(inLin, &mut lz, &mut frac_Q7); 9 | /* Piece-wise parabolic approximation */ 10 | (frac_Q7 as i64 + ((frac_Q7 * (128 - frac_Q7)) as i64 * 179 as i64 >> 16)) as i32 11 | + (((31 - lz) as u32) << 7) as i32 12 | } 13 | -------------------------------------------------------------------------------- /src/src/opus_private.rs: -------------------------------------------------------------------------------- 1 | pub const MODE_SILK_ONLY: i32 = 1000; 2 | pub const MODE_HYBRID: i32 = 1001; 3 | pub const MODE_CELT_ONLY: i32 = 1002; 4 | 5 | pub const OPUS_SET_VOICE_RATIO_REQUEST: i32 = 11018; 6 | pub const OPUS_GET_VOICE_RATIO_REQUEST: i32 = 11019; 7 | pub const OPUS_SET_FORCE_MODE_REQUEST: i32 = 11002; 8 | 9 | #[inline] 10 | pub fn align(i: i32) -> i32 { 11 | let alignment: u32 = 8 as u64 as u32; 12 | return (i as u32) 13 | .wrapping_add(alignment) 14 | .wrapping_sub(1) 15 | .wrapping_div(alignment) 16 | .wrapping_mul(alignment) as i32; 17 | } 18 | -------------------------------------------------------------------------------- /upstream-libopus/opus/win32/VS2015/test_opus_api.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | 10 | 11 | Source Files 12 | 13 | 14 | -------------------------------------------------------------------------------- /upstream-libopus/opus/win32/VS2015/test_opus_decode.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4a0dd677-931f-4728-afe5-b761149fc7eb} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | 10 | 11 | Source Files 12 | 13 | 14 | -------------------------------------------------------------------------------- /upstream-libopus/opus/OpusConfig.cmake.in: -------------------------------------------------------------------------------- 1 | set(OPUS_VERSION @PROJECT_VERSION@) 2 | set(OPUS_VERSION_STRING @PROJECT_VERSION@) 3 | set(OPUS_VERSION_MAJOR @PROJECT_VERSION_MAJOR@) 4 | set(OPUS_VERSION_MINOR @PROJECT_VERSION_MINOR@) 5 | set(OPUS_VERSION_PATCH @PROJECT_VERSION_PATCH@) 6 | 7 | @PACKAGE_INIT@ 8 | 9 | set_and_check(OPUS_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@") 10 | set_and_check(OPUS_INCLUDE_DIRS "@PACKAGE_INCLUDE_INSTALL_DIR@") 11 | 12 | include(${CMAKE_CURRENT_LIST_DIR}/OpusTargets.cmake) 13 | 14 | set(OPUS_LIBRARY Opus::opus) 15 | set(OPUS_LIBRARIES Opus::opus) 16 | 17 | check_required_components(Opus) 18 | 19 | set(OPUS_FOUND 1) 20 | -------------------------------------------------------------------------------- /src/silk/resampler/ar2.rs: -------------------------------------------------------------------------------- 1 | /* Second order AR filter with single delay elements */ 2 | pub fn silk_resampler_private_AR2( 3 | state: &mut [i32; 2], 4 | out_Q8: &mut [i32], 5 | in_0: &[i16], 6 | A_Q14: &[i16], 7 | ) { 8 | assert_eq!(out_Q8.len(), in_0.len()); 9 | 10 | for k in 0..in_0.len() { 11 | let out32 = state[0] + ((in_0[k] as i32 as u32) << 8) as i32; 12 | out_Q8[k] = out32; 13 | 14 | let out32 = ((out32 as u32) << 2) as i32; 15 | state[0] = (state[1] as i64 + ((out32 as i64 * A_Q14[0] as i64) >> 16)) as i32; 16 | state[1] = ((out32 as i64 * A_Q14[1] as i64) >> 16) as i32; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /unsafe-libopus-tools/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "unsafe-libopus-tools" 3 | version = "0.1.0" 4 | edition = "2021" 5 | publish = false 6 | 7 | [dependencies] 8 | unsafe-libopus = { path = ".." } 9 | upstream-libopus = { path = "../upstream-libopus" } 10 | 11 | byteorder = { version = "1.4.3" } 12 | 13 | clap = { version = "4.3.23", features = ["derive"] } 14 | 15 | rayon = { version = "1.7.0" } 16 | itertools = { version = "0.11.0" } 17 | indicatif = { version = "0.17.6", features = ["rayon"] } 18 | 19 | [[bin]] 20 | name = "opus_compare" 21 | 22 | [[bin]] 23 | name = "opus_demo" 24 | 25 | [[bin]] 26 | name = "repacketizer_demo" 27 | 28 | [[bin]] 29 | name = "run_vectors2" 30 | -------------------------------------------------------------------------------- /src/silk/float/k2a_FLP.rs: -------------------------------------------------------------------------------- 1 | pub unsafe fn silk_k2a_FLP(A: *mut f32, rc: *const f32, order: i32) { 2 | let mut k: i32 = 0; 3 | let mut n: i32 = 0; 4 | let mut rck: f32 = 0.; 5 | let mut tmp1: f32 = 0.; 6 | let mut tmp2: f32 = 0.; 7 | k = 0; 8 | while k < order { 9 | rck = *rc.offset(k as isize); 10 | n = 0; 11 | while n < k + 1 >> 1 { 12 | tmp1 = *A.offset(n as isize); 13 | tmp2 = *A.offset((k - n - 1) as isize); 14 | *A.offset(n as isize) = tmp1 + tmp2 * rck; 15 | *A.offset((k - n - 1) as isize) = tmp2 + tmp1 * rck; 16 | n += 1; 17 | } 18 | *A.offset(k as isize) = -rck; 19 | k += 1; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/silk/interpolate.rs: -------------------------------------------------------------------------------- 1 | use ndarray::{aview1, aview_mut1, azip}; 2 | 3 | // Interpolate two vectors 4 | pub fn silk_interpolate( 5 | xi: &mut [i16], 6 | x0: &[i16], 7 | x1: &[i16], 8 | // interp. factor, weight on 2nd vector 9 | ifact_Q2: i32, 10 | ) { 11 | assert_eq!(xi.len(), x0.len()); 12 | assert_eq!(xi.len(), x1.len()); 13 | 14 | assert!((0..=4).contains(&ifact_Q2)); 15 | 16 | let xi = aview_mut1(xi); 17 | let x0 = aview1(x0); 18 | let x1 = aview1(x1); 19 | 20 | azip!((xi in xi, &x0 in x0, &x1 in x1) { 21 | let x0 = x0 as i32; 22 | let x1 = x1 as i32; 23 | *xi = (x0 24 | + (((x1 - x0) as i16 as i32 * ifact_Q2 as i16 as i32) >> 2)) 25 | as i16; 26 | }); 27 | } 28 | -------------------------------------------------------------------------------- /upstream-libopus/opus/win32/VS2015/test_opus_encode.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {546c8d9a-103e-4f78-972b-b44e8d3c8aba} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | 10 | 11 | Source Files 12 | 13 | 14 | Source Files 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/silk/bwexpander_32.rs: -------------------------------------------------------------------------------- 1 | use crate::silk::macros::silk_SMULWW; 2 | use crate::silk::SigProc_FIX::silk_RSHIFT_ROUND; 3 | 4 | /// Chirp (bandwidth expand) LP AR filter 5 | /// 6 | /// ```text 7 | /// ar I/O AR filter to be expanded (without leading 1) 8 | /// d I Length of ar 9 | /// chirp_Q16 I Chirp factor in Q16 10 | /// ``` 11 | pub fn silk_bwexpander_32(ar: &mut [i32], mut chirp_Q16: i32) { 12 | let d = ar.len(); 13 | 14 | let chirp_minus_one_Q16: i32 = chirp_Q16 - 65536; 15 | 16 | for ar in ar.iter_mut().take(d - 1) { 17 | *ar = silk_SMULWW(chirp_Q16, *ar); 18 | chirp_Q16 += silk_RSHIFT_ROUND(chirp_Q16 * chirp_minus_one_Q16, 16) 19 | } 20 | 21 | ar[d - 1] = silk_SMULWW(chirp_Q16, ar[d - 1]); 22 | } 23 | -------------------------------------------------------------------------------- /src/silk/float/autocorrelation_FLP.rs: -------------------------------------------------------------------------------- 1 | use crate::silk::float::inner_product_FLP::silk_inner_product_FLP; 2 | 3 | /// Compute autocorrelation 4 | /// 5 | /// ```text 6 | /// results O result (length correlationCount) 7 | /// inputData I input data to correlate 8 | /// inputDataSize I length of input 9 | /// correlationCount I number of correlation taps to compute 10 | /// ``` 11 | pub fn silk_autocorrelation_FLP(results: &mut [f32], input: &[f32]) { 12 | let results = if results.len() > input.len() { 13 | &mut results[0..input.len()] 14 | } else { 15 | results 16 | }; 17 | 18 | for (i, y) in (0..).zip(results.iter_mut()) { 19 | let tail = &input[i..]; 20 | let head = &input[..tail.len()]; 21 | *y = silk_inner_product_FLP(head, tail) as f32; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /upstream-libopus/opus/LICENSE_PLEASE_READ.txt: -------------------------------------------------------------------------------- 1 | Contributions to the collaboration shall not be considered confidential. 2 | 3 | Each contributor represents and warrants that it has the right and 4 | authority to license copyright in its contributions to the collaboration. 5 | 6 | Each contributor agrees to license the copyright in the contributions 7 | under the Modified (2-clause or 3-clause) BSD License or the Clear BSD License. 8 | 9 | Please see the IPR statements submitted to the IETF for the complete 10 | patent licensing details: 11 | 12 | Xiph.Org Foundation: 13 | https://datatracker.ietf.org/ipr/1524/ 14 | 15 | Microsoft Corporation: 16 | https://datatracker.ietf.org/ipr/1914/ 17 | 18 | Skype Limited: 19 | https://datatracker.ietf.org/ipr/1602/ 20 | 21 | Broadcom Corporation: 22 | https://datatracker.ietf.org/ipr/1526/ 23 | -------------------------------------------------------------------------------- /src/silk/float/scale_copy_vector_FLP.rs: -------------------------------------------------------------------------------- 1 | pub unsafe fn silk_scale_copy_vector_FLP( 2 | data_out: *mut f32, 3 | data_in: *const f32, 4 | gain: f32, 5 | dataSize: i32, 6 | ) { 7 | let mut i: i32 = 0; 8 | let mut dataSize4: i32 = 0; 9 | dataSize4 = dataSize & 0xfffc; 10 | i = 0; 11 | while i < dataSize4 { 12 | *data_out.offset((i + 0) as isize) = gain * *data_in.offset((i + 0) as isize); 13 | *data_out.offset((i + 1) as isize) = gain * *data_in.offset((i + 1) as isize); 14 | *data_out.offset((i + 2) as isize) = gain * *data_in.offset((i + 2) as isize); 15 | *data_out.offset((i + 3) as isize) = gain * *data_in.offset((i + 3) as isize); 16 | i += 4; 17 | } 18 | while i < dataSize { 19 | *data_out.offset(i as isize) = gain * *data_in.offset(i as isize); 20 | i += 1; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/silk/tables_pitch_lag.rs: -------------------------------------------------------------------------------- 1 | pub static silk_pitch_lag_iCDF: [u8; 32] = [ 2 | 253, 250, 244, 233, 212, 182, 150, 131, 120, 110, 98, 85, 72, 60, 49, 40, 32, 25, 19, 15, 13, 3 | 11, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 4 | ]; 5 | pub static silk_pitch_delta_iCDF: [u8; 21] = [ 6 | 210, 208, 206, 203, 199, 193, 183, 168, 142, 104, 74, 52, 37, 27, 20, 14, 10, 6, 4, 2, 0, 7 | ]; 8 | pub static silk_pitch_contour_iCDF: [u8; 34] = [ 9 | 223, 201, 183, 167, 152, 138, 124, 111, 98, 88, 79, 70, 62, 56, 50, 44, 39, 35, 31, 27, 24, 21, 10 | 18, 16, 14, 12, 10, 8, 6, 4, 3, 2, 1, 0, 11 | ]; 12 | pub static silk_pitch_contour_NB_iCDF: [u8; 11] = [188, 176, 155, 138, 119, 97, 67, 43, 26, 10, 0]; 13 | pub static silk_pitch_contour_10_ms_iCDF: [u8; 12] = 14 | [165, 119, 80, 61, 47, 35, 27, 20, 14, 9, 4, 0]; 15 | pub static silk_pitch_contour_10_ms_NB_iCDF: [u8; 3] = [113, 63, 0]; 16 | -------------------------------------------------------------------------------- /upstream-libopus/opus/doc/footer.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 16 | 23 | 24 | 25 |
14 | For more information visit the Opus Website. 15 | 17 | 22 |
26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /upstream-libopus/opus/opus_buildtype.cmake: -------------------------------------------------------------------------------- 1 | # Set a default build type if none was specified 2 | 3 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) 4 | if(CMAKE_C_FLAGS) 5 | message(STATUS "CMAKE_C_FLAGS: " ${CMAKE_C_FLAGS}) 6 | else() 7 | set(default_build_type "Release") 8 | message( 9 | STATUS 10 | "Setting build type to '${default_build_type}' as none was specified and no CFLAGS was exported." 11 | ) 12 | set(CMAKE_BUILD_TYPE "${default_build_type}" 13 | CACHE STRING "Choose the type of build." 14 | FORCE) 15 | # Set the possible values of build type for cmake-gui 16 | set_property(CACHE CMAKE_BUILD_TYPE 17 | PROPERTY STRINGS 18 | "Debug" 19 | "Release" 20 | "MinSizeRel" 21 | "RelWithDebInfo") 22 | endif() 23 | endif() 24 | -------------------------------------------------------------------------------- /src/silk/sigm_Q15.rs: -------------------------------------------------------------------------------- 1 | static mut sigm_LUT_slope_Q10: [i32; 6] = [237, 153, 73, 30, 12, 7]; 2 | static mut sigm_LUT_pos_Q15: [i32; 6] = [16384, 23955, 28861, 31213, 32178, 32548]; 3 | static mut sigm_LUT_neg_Q15: [i32; 6] = [16384, 8812, 3906, 1554, 589, 219]; 4 | pub unsafe fn silk_sigm_Q15(mut in_Q5: i32) -> i32 { 5 | let mut ind: i32 = 0; 6 | if in_Q5 < 0 { 7 | in_Q5 = -in_Q5; 8 | if in_Q5 >= 6 * 32 { 9 | return 0; 10 | } else { 11 | ind = in_Q5 >> 5; 12 | return sigm_LUT_neg_Q15[ind as usize] 13 | - sigm_LUT_slope_Q10[ind as usize] as i16 as i32 * (in_Q5 & 0x1f) as i16 as i32; 14 | } 15 | } else if in_Q5 >= 6 * 32 { 16 | return 32767; 17 | } else { 18 | ind = in_Q5 >> 5; 19 | return sigm_LUT_pos_Q15[ind as usize] 20 | + sigm_LUT_slope_Q10[ind as usize] as i16 as i32 * (in_Q5 & 0x1f) as i16 as i32; 21 | }; 22 | } 23 | -------------------------------------------------------------------------------- /src/silk/bwexpander.rs: -------------------------------------------------------------------------------- 1 | use crate::silk::SigProc_FIX::silk_RSHIFT_ROUND; 2 | 3 | /// Chirp (bandwidth expand) LP AR filter 4 | /// 5 | /// `ar`: I/O AR filter to be expanded (without leading 1) 6 | /// `d`: I number of parameters in the AR filter 7 | /// `chirp_Q16`: I chirp factor (typically in the range 0 to 1) 8 | pub fn silk_bwexpander(ar: &mut [i16], mut chirp_Q16: i32) { 9 | let d = ar.len(); 10 | 11 | let chirp_minus_one_Q16: i32 = chirp_Q16 - 65536; 12 | 13 | /* NB: Dont use silk_SMULWB, instead of silk_RSHIFT_ROUND( silk_MUL(), 16 ), below. */ 14 | /* Bias in silk_SMULWB can lead to unstable filters */ 15 | for i in 0..d - 1 { 16 | ar[i] = silk_RSHIFT_ROUND(chirp_Q16 * ar[i] as i32, 16) as i16; 17 | chirp_Q16 += silk_RSHIFT_ROUND(chirp_Q16 * chirp_minus_one_Q16, 16); 18 | } 19 | 20 | ar[d - 1] = silk_RSHIFT_ROUND(chirp_Q16 * ar[d - 1] as i32, 16) as i16; 21 | } 22 | -------------------------------------------------------------------------------- /src/silk/table_LSF_cos.rs: -------------------------------------------------------------------------------- 1 | pub static silk_LSFCosTab_FIX_Q12: [i16; 129] = [ 2 | 8192, 8190, 8182, 8170, 8152, 8130, 8104, 8072, 8034, 7994, 7946, 7896, 7840, 7778, 7714, 7644, 3 | 7568, 7490, 7406, 7318, 7226, 7128, 7026, 6922, 6812, 6698, 6580, 6458, 6332, 6204, 6070, 5934, 4 | 5792, 5648, 5502, 5352, 5198, 5040, 4880, 4718, 4552, 4382, 4212, 4038, 3862, 3684, 3502, 3320, 5 | 3136, 2948, 2760, 2570, 2378, 2186, 1990, 1794, 1598, 1400, 1202, 1002, 802, 602, 402, 202, 0, 6 | -202, -402, -602, -802, -1002, -1202, -1400, -1598, -1794, -1990, -2186, -2378, -2570, -2760, 7 | -2948, -3136, -3320, -3502, -3684, -3862, -4038, -4212, -4382, -4552, -4718, -4880, -5040, 8 | -5198, -5352, -5502, -5648, -5792, -5934, -6070, -6204, -6332, -6458, -6580, -6698, -6812, 9 | -6922, -7026, -7128, -7226, -7318, -7406, -7490, -7568, -7644, -7714, -7778, -7840, -7896, 10 | -7946, -7994, -8034, -8072, -8104, -8130, -8152, -8170, -8182, -8190, -8192, 11 | ]; 12 | -------------------------------------------------------------------------------- /upstream-libopus/opus/.appveyor.yml: -------------------------------------------------------------------------------- 1 | image: Visual Studio 2015 2 | configuration: 3 | - Debug 4 | - DebugDLL 5 | - DebugDLL_fixed 6 | - Release 7 | - ReleaseDLL 8 | - ReleaseDLL_fixed 9 | 10 | platform: 11 | - Win32 12 | - x64 13 | 14 | environment: 15 | api_key: 16 | secure: kR3Ac0NjGwFnTmXdFrR8d6VXjdk5F7L4F/BilC4nvaM= 17 | 18 | build: 19 | project: win32\VS2015\opus.sln 20 | parallel: true 21 | verbosity: minimal 22 | 23 | after_build: 24 | - cd %APPVEYOR_BUILD_FOLDER% 25 | - 7z a opus.zip win32\VS2015\%PLATFORM%\%CONFIGURATION%\opus.??? include\*.h 26 | 27 | test_script: 28 | - cd %APPVEYOR_BUILD_FOLDER%\win32\VS2015\%PLATFORM%\%CONFIGURATION% 29 | - test_opus_api.exe 30 | - test_opus_decode.exe 31 | - test_opus_encode.exe 32 | 33 | artifacts: 34 | - path: opus.zip 35 | 36 | on_success: 37 | - ps: if ($env:api_key -and "$env:configuration/$env:platform" -eq "ReleaseDLL_fixed/x64") { Start-AppveyorBuild -ApiKey $env:api_key -ProjectSlug 'opus-tools' } 38 | -------------------------------------------------------------------------------- /src/silk/NLSF_unpack.rs: -------------------------------------------------------------------------------- 1 | use crate::silk::structs::silk_NLSF_CB_struct; 2 | 3 | pub fn silk_NLSF_unpack( 4 | ec_ix: &mut [i16], 5 | pred_Q8: &mut [u8], 6 | psNLSF_CB: &silk_NLSF_CB_struct, 7 | CB1_index: i32, 8 | ) { 9 | let mut entry: u8 = 0; 10 | let mut ec_sel_ptr = &psNLSF_CB.ec_sel[(CB1_index * psNLSF_CB.order as i32 / 2) as usize..]; 11 | let mut i = 0usize; 12 | while i < psNLSF_CB.order as usize { 13 | entry = ec_sel_ptr[0]; 14 | ec_sel_ptr = &ec_sel_ptr[1..]; 15 | ec_ix[i] = ((entry as i32 >> 1 & 7) as i16 as i32 * (2 * 4 + 1) as i16 as i32) as i16; 16 | pred_Q8[i] = psNLSF_CB.pred_Q8[i + (entry as usize & 1) * (psNLSF_CB.order as usize - 1)]; 17 | ec_ix[i + 1] = ((entry as i32 >> 5 & 7) as i16 as i32 * (2 * 4 + 1) as i16 as i32) as i16; 18 | pred_Q8[i + 1] = 19 | psNLSF_CB.pred_Q8[i + (entry as usize >> 4 & 1) * (psNLSF_CB.order as usize - 1) + 1]; 20 | i += 2; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/silk/float/SigProc_FLP.rs: -------------------------------------------------------------------------------- 1 | use crate::celt::float_cast::float2int; 2 | use crate::silk::SigProc_FIX::silk_SAT16; 3 | 4 | #[inline] 5 | pub fn silk_float2int(x: f32) -> i32 { 6 | float2int(x) 7 | } 8 | 9 | #[inline] 10 | pub fn silk_float2short_array(out: &mut [i16], input: &[f32]) { 11 | let length = out.len(); 12 | assert_eq!(length, input.len()); 13 | 14 | for k in (0..length).rev() { 15 | out[k] = silk_SAT16(float2int(input[k])) as i16; 16 | } 17 | } 18 | 19 | #[inline] 20 | pub fn silk_short2float_array(out: &mut [f32], input: &[i16]) { 21 | let length = out.len(); 22 | assert_eq!(length, input.len()); 23 | 24 | for k in (0..length).rev() { 25 | out[k] = input[k] as f32; 26 | } 27 | } 28 | 29 | #[inline] 30 | pub fn silk_log2(x: f64) -> f32 { 31 | return (std::f64::consts::LOG2_10 * x.log10()) as f32; 32 | } 33 | 34 | #[inline] 35 | pub fn silk_sigmoid(x: f32) -> f32 { 36 | return (1.0f64 / (1.0f64 + (-x as f64).exp())) as f32; 37 | } 38 | -------------------------------------------------------------------------------- /src/silk/init_encoder.rs: -------------------------------------------------------------------------------- 1 | use crate::externs::memset; 2 | use crate::silk::float::structs_FLP::silk_encoder_state_FLP; 3 | use crate::silk::lin2log::silk_lin2log; 4 | use crate::silk::tuning_parameters::VARIABLE_HP_MIN_CUTOFF_HZ; 5 | use crate::silk::VAD::silk_VAD_Init; 6 | 7 | pub unsafe fn silk_init_encoder(psEnc: *mut silk_encoder_state_FLP, arch: i32) -> i32 { 8 | let mut ret: i32 = 0; 9 | memset( 10 | psEnc as *mut core::ffi::c_void, 11 | 0, 12 | ::core::mem::size_of::() as u64, 13 | ); 14 | (*psEnc).sCmn.arch = arch; 15 | (*psEnc).sCmn.variable_HP_smth1_Q15 = 16 | (((silk_lin2log(((VARIABLE_HP_MIN_CUTOFF_HZ * ((1) << 16)) as f64 + 0.5f64) as i32) 17 | - ((16) << 7)) as u32) 18 | << 8) as i32; 19 | (*psEnc).sCmn.variable_HP_smth2_Q15 = (*psEnc).sCmn.variable_HP_smth1_Q15; 20 | (*psEnc).sCmn.first_frame_after_reset = 1; 21 | ret += silk_VAD_Init(&mut (*psEnc).sCmn.sVAD); 22 | return ret; 23 | } 24 | -------------------------------------------------------------------------------- /upstream-libopus/opus/win32/genversion.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | setlocal enableextensions enabledelayedexpansion 4 | 5 | for /f %%v in ('cd "%~dp0.." ^&^& git status ^>NUL 2^>NUL ^&^& git describe --tags --match "v*" --dirty 2^>NUL') do set version=%%v 6 | 7 | if not "%version%"=="" set version=!version:~1! && goto :gotversion 8 | 9 | if exist "%~dp0..\package_version" goto :getversion 10 | 11 | echo Git cannot be found, nor can package_version. Generating unknown version. 12 | 13 | set version=unknown 14 | 15 | goto :gotversion 16 | 17 | :getversion 18 | 19 | for /f "delims== tokens=2" %%v in (%~dps0..\package_version) do set version=%%v 20 | set version=!version:"=! 21 | 22 | :gotversion 23 | 24 | set version=!version: =! 25 | set version_out=#define %~2 "%version%" 26 | 27 | echo %version_out%> "%~1_temp" 28 | 29 | echo n | comp "%~1_temp" "%~1" > NUL 2> NUL 30 | 31 | if not errorlevel 1 goto exit 32 | 33 | copy /y "%~1_temp" "%~1" 34 | 35 | :exit 36 | 37 | del "%~1_temp" 38 | -------------------------------------------------------------------------------- /upstream-libopus/opus/m4/opus-intrinsics.m4: -------------------------------------------------------------------------------- 1 | dnl opus-intrinsics.m4 2 | dnl macro for testing for support for compiler intrinsics, either by default or with a compiler flag 3 | 4 | dnl OPUS_CHECK_INTRINSICS(NAME-OF-INTRINSICS, COMPILER-FLAG-FOR-INTRINSICS, VAR-IF-PRESENT, VAR-IF-DEFAULT, TEST-PROGRAM-HEADER, TEST-PROGRAM-BODY) 5 | AC_DEFUN([OPUS_CHECK_INTRINSICS], 6 | [ 7 | AC_MSG_CHECKING([if compiler supports $1 intrinsics]) 8 | AC_LINK_IFELSE( 9 | [AC_LANG_PROGRAM($5, $6)], 10 | [ 11 | $3=1 12 | $4=1 13 | AC_MSG_RESULT([yes]) 14 | ],[ 15 | $4=0 16 | AC_MSG_RESULT([no]) 17 | AC_MSG_CHECKING([if compiler supports $1 intrinsics with $2]) 18 | save_CFLAGS="$CFLAGS"; CFLAGS="$CFLAGS $2" 19 | AC_LINK_IFELSE([AC_LANG_PROGRAM($5, $6)], 20 | [ 21 | AC_MSG_RESULT([yes]) 22 | $3=1 23 | ],[ 24 | AC_MSG_RESULT([no]) 25 | $3=0 26 | ]) 27 | CFLAGS="$save_CFLAGS" 28 | ]) 29 | ]) 30 | -------------------------------------------------------------------------------- /upstream-libopus/opus/win32/VS2015/opus_demo.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | -------------------------------------------------------------------------------- /upstream-libopus/opus/celt_sources.mk: -------------------------------------------------------------------------------- 1 | CELT_SOURCES = \ 2 | celt/bands.c \ 3 | celt/celt.c \ 4 | celt/celt_encoder.c \ 5 | celt/celt_decoder.c \ 6 | celt/cwrs.c \ 7 | celt/entcode.c \ 8 | celt/entdec.c \ 9 | celt/entenc.c \ 10 | celt/kiss_fft.c \ 11 | celt/laplace.c \ 12 | celt/mathops.c \ 13 | celt/mdct.c \ 14 | celt/modes.c \ 15 | celt/pitch.c \ 16 | celt/celt_lpc.c \ 17 | celt/quant_bands.c \ 18 | celt/rate.c \ 19 | celt/vq.c 20 | 21 | CELT_SOURCES_SSE = \ 22 | celt/x86/x86cpu.c \ 23 | celt/x86/x86_celt_map.c \ 24 | celt/x86/pitch_sse.c 25 | 26 | CELT_SOURCES_SSE2 = \ 27 | celt/x86/pitch_sse2.c \ 28 | celt/x86/vq_sse2.c 29 | 30 | CELT_SOURCES_SSE4_1 = \ 31 | celt/x86/celt_lpc_sse4_1.c \ 32 | celt/x86/pitch_sse4_1.c 33 | 34 | CELT_SOURCES_ARM = \ 35 | celt/arm/armcpu.c \ 36 | celt/arm/arm_celt_map.c 37 | 38 | CELT_SOURCES_ARM_ASM = \ 39 | celt/arm/celt_pitch_xcorr_arm.s 40 | 41 | CELT_AM_SOURCES_ARM_ASM = \ 42 | celt/arm/armopts.s.in 43 | 44 | CELT_SOURCES_ARM_NEON_INTR = \ 45 | celt/arm/celt_neon_intr.c \ 46 | celt/arm/pitch_neon_intr.c 47 | 48 | CELT_SOURCES_ARM_NE10 = \ 49 | celt/arm/celt_fft_ne10.c \ 50 | celt/arm/celt_mdct_ne10.c 51 | -------------------------------------------------------------------------------- /src/silk/macros.rs: -------------------------------------------------------------------------------- 1 | pub const EC_CLZ0: i32 = 32; 2 | 3 | #[inline] 4 | pub fn silk_CLZ32(in32: i32) -> i32 { 5 | return if in32 != 0 { 6 | 32 - (EC_CLZ0 - (in32.leading_zeros() as i32)) 7 | } else { 8 | 32 9 | }; 10 | } 11 | 12 | /// (a32 * (opus_int32)((opus_int16)(b32))) >> 16 output have to be 32bit int 13 | #[inline] 14 | pub fn silk_SMULWB(a32: i32, b32: i32) -> i32 { 15 | ((a32 as i64 * b32 as i16 as i64) >> 16) as i32 16 | } 17 | 18 | /// a32 + (b32 * (opus_int32)((opus_int16)(c32))) >> 16 output have to be 32bit int 19 | #[inline] 20 | pub fn silk_SMLAWB(a32: i32, b32: i32, c32: i32) -> i32 { 21 | (a32 as i64 + ((b32 as i64 * c32 as i16 as i64) >> 16)) as i32 22 | } 23 | 24 | /// (opus_int32)((opus_int16)(a3))) * (opus_int32)((opus_int16)(b32)) output have to be 32bit int 25 | #[inline] 26 | pub fn silk_SMULBB(a32: i32, b32: i32) -> i32 { 27 | a32 as i16 as i32 * b32 as i16 as i32 28 | } 29 | 30 | /// a32 + (b32 * (opus_int32)((opus_int16)(c32))) >> 16 output have to be 32bit int 31 | #[inline] 32 | pub fn silk_SMULWW(a32: i32, b32: i32) -> i32 { 33 | ((a32 as i64 * b32 as i64) >> 16) as i32 34 | } 35 | -------------------------------------------------------------------------------- /src/silk/float/apply_sine_window_FLP.rs: -------------------------------------------------------------------------------- 1 | pub unsafe fn silk_apply_sine_window_FLP( 2 | px_win: *mut f32, 3 | px: *const f32, 4 | win_type: i32, 5 | length: i32, 6 | ) { 7 | let mut k: i32 = 0; 8 | let mut freq: f32 = 0.; 9 | let mut c: f32 = 0.; 10 | let mut S0: f32 = 0.; 11 | let mut S1: f32 = 0.; 12 | assert!(win_type == 1 || win_type == 2); 13 | assert!(length & 3 == 0); 14 | freq = std::f32::consts::PI / (length + 1) as f32; 15 | c = 2.0f32 - freq * freq; 16 | if win_type < 2 { 17 | S0 = 0.0f32; 18 | S1 = freq; 19 | } else { 20 | S0 = 1.0f32; 21 | S1 = 0.5f32 * c; 22 | } 23 | k = 0; 24 | while k < length { 25 | *px_win.offset((k + 0) as isize) = *px.offset((k + 0) as isize) * 0.5f32 * (S0 + S1); 26 | *px_win.offset((k + 1) as isize) = *px.offset((k + 1) as isize) * S1; 27 | S0 = c * S1 - S0; 28 | *px_win.offset((k + 2) as isize) = *px.offset((k + 2) as isize) * 0.5f32 * (S1 + S0); 29 | *px_win.offset((k + 3) as isize) = *px.offset((k + 3) as isize) * S0; 30 | S1 = c * S0 - S1; 31 | k += 4; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/celt/tests/test_unit_types.rs: -------------------------------------------------------------------------------- 1 | pub mod stddef_h { 2 | pub type size_t = u64; 3 | } 4 | pub mod stdio_h { 5 | use super::FILE_h::FILE; 6 | { 7 | pub static mut stderr: *mut FILE; 8 | pub fn fprintf(_: *mut FILE, _: *const i8, _: ...) -> i32; 9 | } 10 | } 11 | pub use self::stddef_h::size_t; 12 | 13 | use self::stdio_h::{fprintf, stderr}; 14 | pub use self::struct_FILE_h::{_IO_codecvt, _IO_lock_t, _IO_marker, _IO_wide_data, _IO_FILE}; 15 | 16 | pub use self::FILE_h::FILE; 17 | unsafe fn main_0() -> i32 { 18 | let mut i: i16 = 1; 19 | i = ((i as i32) << 14) as i16; 20 | if i as i32 >> 14 != 1 { 21 | fprintf( 22 | stderr(), 23 | b"i16 isn't 16 bits\n\0" as *const u8 as *const i8, 24 | ); 25 | return 1; 26 | } 27 | if (::core::mem::size_of::() as u64) 28 | .wrapping_mul(2) 29 | != ::core::mem::size_of::() as u64 30 | { 31 | fprintf( 32 | stderr(), 33 | b"16*2 != 32\n\0" as *const u8 as *const i8, 34 | ); 35 | return 1; 36 | } 37 | return 0; 38 | } 39 | pub fn main() { 40 | unsafe { ::std::process::exit(main_0() as i32) } 41 | } 42 | -------------------------------------------------------------------------------- /src/silk/log2lin.rs: -------------------------------------------------------------------------------- 1 | pub mod typedef_h { 2 | pub const silk_int32_MAX: i32 = i32::MAX; 3 | } 4 | 5 | pub use self::typedef_h::silk_int32_MAX; 6 | 7 | /// Approximation of 2^() (very close inverse of silk_lin2log()) */ 8 | /// Convert input to a linear scale 9 | pub fn silk_log2lin(inLog_Q7: i32) -> i32 { 10 | let mut out: i32 = 0; 11 | let mut frac_Q7: i32 = 0; 12 | if inLog_Q7 < 0 { 13 | return 0; 14 | } else { 15 | if inLog_Q7 >= 3967 { 16 | return silk_int32_MAX; 17 | } 18 | } 19 | out = ((1) << (inLog_Q7 >> 7)) as i32; 20 | frac_Q7 = inLog_Q7 & 0x7f; 21 | if inLog_Q7 < 2048 { 22 | out = out 23 | + (out 24 | * (frac_Q7 as i64 25 | + ((frac_Q7 as i16 as i32 * (128 - frac_Q7) as i16 as i32) as i64 26 | * -(174) as i16 as i64 27 | >> 16)) as i32 28 | >> 7); 29 | } else { 30 | out = out 31 | + (out >> 7) 32 | * (frac_Q7 as i64 33 | + ((frac_Q7 as i16 as i32 * (128 - frac_Q7) as i16 as i32) as i64 34 | * -(174) as i16 as i64 35 | >> 16)) as i32; 36 | } 37 | return out; 38 | } 39 | -------------------------------------------------------------------------------- /upstream-libopus/opus/silk_headers.mk: -------------------------------------------------------------------------------- 1 | SILK_HEAD = \ 2 | silk/debug.h \ 3 | silk/control.h \ 4 | silk/errors.h \ 5 | silk/API.h \ 6 | silk/typedef.h \ 7 | silk/define.h \ 8 | silk/main.h \ 9 | silk/x86/main_sse.h \ 10 | silk/PLC.h \ 11 | silk/structs.h \ 12 | silk/tables.h \ 13 | silk/tuning_parameters.h \ 14 | silk/Inlines.h \ 15 | silk/MacroCount.h \ 16 | silk/MacroDebug.h \ 17 | silk/macros.h \ 18 | silk/NSQ.h \ 19 | silk/pitch_est_defines.h \ 20 | silk/resampler_private.h \ 21 | silk/resampler_rom.h \ 22 | silk/resampler_structs.h \ 23 | silk/SigProc_FIX.h \ 24 | silk/x86/SigProc_FIX_sse.h \ 25 | silk/arm/biquad_alt_arm.h \ 26 | silk/arm/LPC_inv_pred_gain_arm.h \ 27 | silk/arm/macros_armv4.h \ 28 | silk/arm/macros_armv5e.h \ 29 | silk/arm/macros_arm64.h \ 30 | silk/arm/SigProc_FIX_armv4.h \ 31 | silk/arm/SigProc_FIX_armv5e.h \ 32 | silk/arm/NSQ_del_dec_arm.h \ 33 | silk/arm/NSQ_neon.h \ 34 | silk/fixed/main_FIX.h \ 35 | silk/fixed/structs_FIX.h \ 36 | silk/fixed/arm/warped_autocorrelation_FIX_arm.h \ 37 | silk/fixed/mips/noise_shape_analysis_FIX_mipsr1.h \ 38 | silk/fixed/mips/warped_autocorrelation_FIX_mipsr1.h \ 39 | silk/float/main_FLP.h \ 40 | silk/float/structs_FLP.h \ 41 | silk/float/SigProc_FLP.h \ 42 | silk/mips/macros_mipsr1.h \ 43 | silk/mips/NSQ_del_dec_mipsr1.h \ 44 | silk/mips/sigproc_fix_mipsr1.h 45 | -------------------------------------------------------------------------------- /upstream-libopus/opus/celt_headers.mk: -------------------------------------------------------------------------------- 1 | CELT_HEAD = \ 2 | celt/arch.h \ 3 | celt/bands.h \ 4 | celt/celt.h \ 5 | celt/cpu_support.h \ 6 | include/opus_types.h \ 7 | include/opus_defines.h \ 8 | include/opus_custom.h \ 9 | celt/cwrs.h \ 10 | celt/ecintrin.h \ 11 | celt/entcode.h \ 12 | celt/entdec.h \ 13 | celt/entenc.h \ 14 | celt/fixed_debug.h \ 15 | celt/fixed_generic.h \ 16 | celt/float_cast.h \ 17 | celt/_kiss_fft_guts.h \ 18 | celt/kiss_fft.h \ 19 | celt/laplace.h \ 20 | celt/mathops.h \ 21 | celt/mdct.h \ 22 | celt/mfrngcod.h \ 23 | celt/modes.h \ 24 | celt/os_support.h \ 25 | celt/pitch.h \ 26 | celt/celt_lpc.h \ 27 | celt/x86/celt_lpc_sse.h \ 28 | celt/quant_bands.h \ 29 | celt/rate.h \ 30 | celt/stack_alloc.h \ 31 | celt/vq.h \ 32 | celt/static_modes_float.h \ 33 | celt/static_modes_fixed.h \ 34 | celt/static_modes_float_arm_ne10.h \ 35 | celt/static_modes_fixed_arm_ne10.h \ 36 | celt/arm/armcpu.h \ 37 | celt/arm/fixed_armv4.h \ 38 | celt/arm/fixed_armv5e.h \ 39 | celt/arm/fixed_arm64.h \ 40 | celt/arm/kiss_fft_armv4.h \ 41 | celt/arm/kiss_fft_armv5e.h \ 42 | celt/arm/pitch_arm.h \ 43 | celt/arm/fft_arm.h \ 44 | celt/arm/mdct_arm.h \ 45 | celt/mips/celt_mipsr1.h \ 46 | celt/mips/fixed_generic_mipsr1.h \ 47 | celt/mips/kiss_fft_mipsr1.h \ 48 | celt/mips/mdct_mipsr1.h \ 49 | celt/mips/pitch_mipsr1.h \ 50 | celt/mips/vq_mipsr1.h \ 51 | celt/x86/pitch_sse.h \ 52 | celt/x86/vq_sse.h \ 53 | celt/x86/x86cpu.h 54 | -------------------------------------------------------------------------------- /upstream-libopus/opus/opus_config.cmake: -------------------------------------------------------------------------------- 1 | include(opus_functions.cmake) 2 | 3 | configure_file(config.h.cmake.in config.h @ONLY) 4 | add_definitions(-DHAVE_CONFIG_H) 5 | 6 | set_property(GLOBAL PROPERTY USE_FOLDERS ON) 7 | set_property(GLOBAL PROPERTY C_STANDARD 99) 8 | 9 | if(MSVC) 10 | add_definitions(-D_CRT_SECURE_NO_WARNINGS) 11 | endif() 12 | 13 | include(CheckLibraryExists) 14 | check_library_exists(m floor "" HAVE_LIBM) 15 | if(HAVE_LIBM) 16 | list(APPEND OPUS_REQUIRED_LIBRARIES m) 17 | endif() 18 | 19 | if(CMAKE_SYSTEM_PROCESSOR MATCHES "(i[0-9]86|x86|X86|amd64|AMD64|x86_64)") 20 | if(CMAKE_SIZEOF_VOID_P EQUAL 8) 21 | set(OPUS_CPU_X64 1) 22 | else() 23 | set(OPUS_CPU_X86 1) 24 | endif() 25 | elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "arm") 26 | set(OPUS_CPU_ARM 1) 27 | endif() 28 | 29 | opus_supports_cpu_detection(RUNTIME_CPU_CAPABILITY_DETECTION) 30 | 31 | if(OPUS_CPU_X86 OR OPUS_CPU_X64) 32 | opus_detect_sse(COMPILER_SUPPORT_SIMD) 33 | elseif(OPUS_CPU_ARM) 34 | opus_detect_neon(COMPILER_SUPPORT_NEON) 35 | if(COMPILER_SUPPORT_NEON) 36 | option(OPUS_USE_NEON "Option to turn off SSE" ON) 37 | option(OPUS_MAY_SUPPORT_NEON "Does runtime check for neon support" ON) 38 | option(OPUS_PRESUME_NEON "Assume target CPU has NEON support" OFF) 39 | if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64") 40 | set(OPUS_PRESUME_NEON ON) 41 | endif() 42 | endif() 43 | endif() 44 | -------------------------------------------------------------------------------- /src/silk/stereo_encode_pred.rs: -------------------------------------------------------------------------------- 1 | use crate::celt::entenc::{ec_enc, ec_enc_icdf}; 2 | use crate::silk::tables_other::{ 3 | silk_stereo_only_code_mid_iCDF, silk_stereo_pred_joint_iCDF, silk_uniform3_iCDF, 4 | silk_uniform5_iCDF, 5 | }; 6 | 7 | pub unsafe fn silk_stereo_encode_pred(psRangeEnc: &mut ec_enc, ix: *mut [i8; 3]) { 8 | let mut n: i32 = 0; 9 | n = 5 * (*ix.offset(0 as isize))[2 as usize] as i32 10 | + (*ix.offset(1 as isize))[2 as usize] as i32; 11 | assert!(n < 25); 12 | ec_enc_icdf(psRangeEnc, n, &silk_stereo_pred_joint_iCDF, 8); 13 | n = 0; 14 | while n < 2 { 15 | assert!(((*ix.offset(n as isize))[0 as usize] as i32) < 3); 16 | assert!(((*ix.offset(n as isize))[1 as usize] as i32) < 5); 17 | ec_enc_icdf( 18 | psRangeEnc, 19 | (*ix.offset(n as isize))[0 as usize] as i32, 20 | &silk_uniform3_iCDF, 21 | 8, 22 | ); 23 | ec_enc_icdf( 24 | psRangeEnc, 25 | (*ix.offset(n as isize))[1 as usize] as i32, 26 | &silk_uniform5_iCDF, 27 | 8, 28 | ); 29 | n += 1; 30 | } 31 | } 32 | pub unsafe fn silk_stereo_encode_mid_only(psRangeEnc: &mut ec_enc, mid_only_flag: i8) { 33 | ec_enc_icdf( 34 | psRangeEnc, 35 | mid_only_flag as i32, 36 | &silk_stereo_only_code_mid_iCDF, 37 | 8, 38 | ); 39 | } 40 | -------------------------------------------------------------------------------- /src/silk/float/schur_FLP.rs: -------------------------------------------------------------------------------- 1 | pub unsafe fn silk_schur_FLP(refl_coef: *mut f32, auto_corr: *const f32, order: i32) -> f32 { 2 | let mut k: i32 = 0; 3 | let mut n: i32 = 0; 4 | let mut C: [[f64; 2]; 25] = [[0.; 2]; 25]; 5 | let mut Ctmp1: f64 = 0.; 6 | let mut Ctmp2: f64 = 0.; 7 | let mut rc_tmp: f64 = 0.; 8 | assert!(order >= 0 && order <= 24); 9 | k = 0; 10 | loop { 11 | C[k as usize][1 as usize] = *auto_corr.offset(k as isize) as f64; 12 | C[k as usize][0 as usize] = C[k as usize][1 as usize]; 13 | k += 1; 14 | if !(k <= order) { 15 | break; 16 | } 17 | } 18 | k = 0; 19 | while k < order { 20 | rc_tmp = -C[(k + 1) as usize][0 as usize] 21 | / (if C[0 as usize][1 as usize] > 1e-9f32 as f64 { 22 | C[0 as usize][1 as usize] 23 | } else { 24 | 1e-9f32 as f64 25 | }); 26 | *refl_coef.offset(k as isize) = rc_tmp as f32; 27 | n = 0; 28 | while n < order - k { 29 | Ctmp1 = C[(n + k + 1) as usize][0 as usize]; 30 | Ctmp2 = C[n as usize][1 as usize]; 31 | C[(n + k + 1) as usize][0 as usize] = Ctmp1 + Ctmp2 * rc_tmp; 32 | C[n as usize][1 as usize] = Ctmp2 + Ctmp1 * rc_tmp; 33 | n += 1; 34 | } 35 | k += 1; 36 | } 37 | return C[0 as usize][1 as usize] as f32; 38 | } 39 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "unsafe-libopus" 3 | authors = ["DCNick3"] 4 | version = "0.2.0" 5 | edition = "2021" 6 | 7 | repository = "https://github.com/DCNick3/unsafe-libopus" 8 | description = "libopus transpiled to rust by c2rust" 9 | 10 | license = "BSD-3-Clause" 11 | 12 | [workspace] 13 | members = [ 14 | "upstream-libopus", 15 | "unsafe-libopus-tools", 16 | ] 17 | 18 | [profile.release] 19 | debug = true 20 | 21 | [dependencies] 22 | # for complex numbers impl 23 | num-traits = "0.2.16" 24 | num-complex = { version = "0.4.1", features = ["bytemuck"] } 25 | 26 | # for casting slices between different types 27 | bytemuck = "1.16.1" 28 | 29 | # for slicing arrays to other arrays 30 | arrayref = "0.3.7" 31 | const-chunks = "0.3.0" 32 | 33 | # better abstractions for multidimensional arrays 34 | ndarray = "0.15.6" 35 | # better abstractions for multidimensional arrays, another crate (I should probably choose one 💀) 36 | nalgebra = "0.33.0" 37 | 38 | # iterate over stuff 39 | itertools = "0.13.0" 40 | 41 | # for dumping data in ent-dump 42 | hex = { version = "0.4.3", optional = true } 43 | 44 | [dev-dependencies] 45 | getrandom = "0.2.15" 46 | insta = "1.29.0" 47 | 48 | [features] 49 | # dumps calls to entropy coder to console for easier upstream divergence debugging 50 | # (it's not _only_ entropy coder actually, there are some additional prints where it was found necessary) 51 | ent-dump = [ 52 | "hex" 53 | ] 54 | -------------------------------------------------------------------------------- /src/silk/float/sort_FLP.rs: -------------------------------------------------------------------------------- 1 | pub unsafe fn silk_insertion_sort_decreasing_FLP(a: *mut f32, idx: *mut i32, L: i32, K: i32) { 2 | let mut value: f32 = 0.; 3 | let mut i: i32 = 0; 4 | let mut j: i32 = 0; 5 | assert!(K > 0); 6 | assert!(L > 0); 7 | assert!(L >= K); 8 | i = 0; 9 | while i < K { 10 | *idx.offset(i as isize) = i; 11 | i += 1; 12 | } 13 | i = 1; 14 | while i < K { 15 | value = *a.offset(i as isize); 16 | j = i - 1; 17 | while j >= 0 && value > *a.offset(j as isize) { 18 | *a.offset((j + 1) as isize) = *a.offset(j as isize); 19 | *idx.offset((j + 1) as isize) = *idx.offset(j as isize); 20 | j -= 1; 21 | } 22 | *a.offset((j + 1) as isize) = value; 23 | *idx.offset((j + 1) as isize) = i; 24 | i += 1; 25 | } 26 | i = K; 27 | while i < L { 28 | value = *a.offset(i as isize); 29 | if value > *a.offset((K - 1) as isize) { 30 | j = K - 2; 31 | while j >= 0 && value > *a.offset(j as isize) { 32 | *a.offset((j + 1) as isize) = *a.offset(j as isize); 33 | *idx.offset((j + 1) as isize) = *idx.offset(j as isize); 34 | j -= 1; 35 | } 36 | *a.offset((j + 1) as isize) = value; 37 | *idx.offset((j + 1) as isize) = i; 38 | } 39 | i += 1; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/util/nalgebra.rs: -------------------------------------------------------------------------------- 1 | use nalgebra::{Dim, Matrix, ViewStorage, ViewStorageMut, U1}; 2 | 3 | // provide type-aliases for row-major views and functions for their construction 4 | 5 | // pub type VectorViewR<'a, T, D, RStride = D, CStride = U1> = 6 | // Matrix>; 7 | // 8 | // pub type VectorViewRMut<'a, T, D, RStride = D, CStride = U1> = 9 | // Matrix>; 10 | 11 | pub type MatrixViewR<'a, T, R, C, RStride = C, CStride = U1> = 12 | Matrix>; 13 | 14 | pub type MatrixViewRMut<'a, T, R, C, RStride = C, CStride = U1> = 15 | Matrix>; 16 | 17 | pub fn make_viewr_mut_generic(slice: &mut [T], rows: R, cols: C) -> MatrixViewRMut 18 | where 19 | R: Dim, 20 | C: Dim, 21 | { 22 | assert!(slice.len() >= rows.value() * cols.value()); 23 | Matrix::from_data(unsafe { 24 | ViewStorageMut::from_raw_parts(slice.as_mut_ptr(), (rows, cols), (cols, U1)) 25 | }) 26 | } 27 | 28 | pub fn make_viewr_generic(slice: &[T], rows: R, cols: C) -> MatrixViewR 29 | where 30 | R: Dim, 31 | C: Dim, 32 | { 33 | assert!(slice.len() >= rows.value() * cols.value()); 34 | Matrix::from_data(unsafe { 35 | ViewStorage::from_raw_parts(slice.as_ptr(), (rows, cols), (cols, U1)) 36 | }) 37 | } 38 | -------------------------------------------------------------------------------- /upstream-libopus/opus/doc/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake to produce Makefile.in 2 | 3 | DOCINPUTS = $(top_srcdir)/include/opus.h \ 4 | $(top_srcdir)/include/opus_multistream.h \ 5 | $(top_srcdir)/include/opus_defines.h \ 6 | $(top_srcdir)/include/opus_types.h \ 7 | $(top_srcdir)/include/opus_custom.h \ 8 | $(top_srcdir)/doc/header.html \ 9 | $(top_srcdir)/doc/footer.html \ 10 | $(top_srcdir)/doc/customdoxygen.css 11 | 12 | EXTRA_DIST = customdoxygen.css Doxyfile.in footer.html header.html \ 13 | opus_logo.svg trivial_example.c 14 | 15 | 16 | if HAVE_DOXYGEN 17 | 18 | all-local: doxygen-build.stamp 19 | 20 | doxygen-build.stamp: Doxyfile $(DOCINPUTS) 21 | doxygen 22 | touch $@ 23 | 24 | install-data-local: 25 | $(INSTALL) -d $(DESTDIR)$(docdir)/html/search 26 | for f in `find html -type f \! -name "installdox"`; do \ 27 | $(INSTALL_DATA) $$f $(DESTDIR)$(docdir)/$$f; \ 28 | done 29 | 30 | $(INSTALL) -d $(DESTDIR)$(mandir)/man3 31 | cd man && find man3 -type f -name opus_*.3 \ 32 | -exec $(INSTALL_DATA) \{} $(DESTDIR)$(mandir)/man3 \; 33 | 34 | clean-local: 35 | $(RM) -r html 36 | $(RM) -r latex 37 | $(RM) -r man 38 | $(RM) doxygen-build.stamp 39 | $(RM) doxygen_sqlite3.db 40 | 41 | uninstall-local: 42 | $(RM) -r $(DESTDIR)$(docdir)/html 43 | $(RM) $(DESTDIR)$(mandir)/man3/opus_*.3 $(DESTDIR)$(mandir)/man3/opus.h.3 44 | 45 | endif 46 | -------------------------------------------------------------------------------- /src/silk/float/LTP_scale_ctrl_FLP.rs: -------------------------------------------------------------------------------- 1 | use crate::silk::define::CODE_INDEPENDENTLY; 2 | use crate::silk::float::structs_FLP::{silk_encoder_control_FLP, silk_encoder_state_FLP}; 3 | use crate::silk::tables_other::silk_LTPScales_table_Q14; 4 | 5 | pub unsafe fn silk_LTP_scale_ctrl_FLP( 6 | psEnc: *mut silk_encoder_state_FLP, 7 | psEncCtrl: *mut silk_encoder_control_FLP, 8 | condCoding: i32, 9 | ) { 10 | let mut round_loss: i32 = 0; 11 | if condCoding == CODE_INDEPENDENTLY { 12 | round_loss = (*psEnc).sCmn.PacketLoss_perc + (*psEnc).sCmn.nFramesPerPacket; 13 | (*psEnc).sCmn.indices.LTP_scaleIndex = (if 0.0f32 > 2.0f32 { 14 | if round_loss as f32 * (*psEncCtrl).LTPredCodGain * 0.1f32 > 0.0f32 { 15 | 0.0f32 16 | } else if round_loss as f32 * (*psEncCtrl).LTPredCodGain * 0.1f32 < 2.0f32 { 17 | 2.0f32 18 | } else { 19 | round_loss as f32 * (*psEncCtrl).LTPredCodGain * 0.1f32 20 | } 21 | } else if round_loss as f32 * (*psEncCtrl).LTPredCodGain * 0.1f32 > 2.0f32 { 22 | 2.0f32 23 | } else if round_loss as f32 * (*psEncCtrl).LTPredCodGain * 0.1f32 < 0.0f32 { 24 | 0.0f32 25 | } else { 26 | round_loss as f32 * (*psEncCtrl).LTPredCodGain * 0.1f32 27 | }) as i8; 28 | } else { 29 | (*psEnc).sCmn.indices.LTP_scaleIndex = 0; 30 | } 31 | (*psEncCtrl).LTP_scale = 32 | silk_LTPScales_table_Q14[(*psEnc).sCmn.indices.LTP_scaleIndex as usize] as f32 / 16384.0f32; 33 | } 34 | -------------------------------------------------------------------------------- /src/silk/float/warped_autocorrelation_FLP.rs: -------------------------------------------------------------------------------- 1 | pub unsafe fn silk_warped_autocorrelation_FLP( 2 | corr: *mut f32, 3 | input: *const f32, 4 | warping: f32, 5 | length: i32, 6 | order: i32, 7 | ) { 8 | let mut n: i32 = 0; 9 | let mut i: i32 = 0; 10 | let mut tmp1: f64 = 0.; 11 | let mut tmp2: f64 = 0.; 12 | let mut state: [f64; 25] = [ 13 | 0 as f64, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 14 | 0., 0., 0., 0., 15 | ]; 16 | let mut C: [f64; 25] = [ 17 | 0 as f64, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 18 | 0., 0., 0., 0., 19 | ]; 20 | assert!(order & 1 == 0); 21 | n = 0; 22 | while n < length { 23 | tmp1 = *input.offset(n as isize) as f64; 24 | i = 0; 25 | while i < order { 26 | tmp2 = state[i as usize] + warping as f64 * (state[(i + 1) as usize] - tmp1); 27 | state[i as usize] = tmp1; 28 | C[i as usize] += state[0 as usize] * tmp1; 29 | tmp1 = state[(i + 1) as usize] + warping as f64 * (state[(i + 2) as usize] - tmp2); 30 | state[(i + 1) as usize] = tmp2; 31 | C[(i + 1) as usize] += state[0 as usize] * tmp2; 32 | i += 2; 33 | } 34 | state[order as usize] = tmp1; 35 | C[order as usize] += state[0 as usize] * tmp1; 36 | n += 1; 37 | } 38 | i = 0; 39 | while i < order + 1 { 40 | *corr.offset(i as isize) = C[i as usize] as f32; 41 | i += 1; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/silk/init_decoder.rs: -------------------------------------------------------------------------------- 1 | use crate::silk::resampler::ResamplerState; 2 | use crate::silk::structs::{silk_CNG_struct, silk_PLC_struct, silk_decoder_state, SideInfoIndices}; 3 | use crate::silk::tables_NLSF_CB_WB::silk_NLSF_CB_WB; 4 | use crate::silk::CNG::silk_CNG_Reset; 5 | use crate::silk::PLC::silk_PLC_Reset; 6 | 7 | pub fn silk_init_decoder() -> silk_decoder_state { 8 | let mut dec = silk_decoder_state { 9 | prev_gain_Q16: 65536, 10 | exc_Q14: [0; 320], 11 | sLPC_Q14_buf: [0; 16], 12 | outBuf: [0; 480], 13 | lagPrev: 0, 14 | LastGainIndex: 0, 15 | fs_kHz: 0, 16 | fs_API_hz: 0, 17 | nb_subfr: 0, 18 | frame_length: 0, 19 | subfr_length: 0, 20 | ltp_mem_length: 0, 21 | LPC_order: 0, 22 | prevNLSF_Q15: [0; 16], 23 | first_frame_after_reset: 1, 24 | pitch_lag_low_bits_iCDF: &[], 25 | pitch_contour_iCDF: &[], 26 | nFramesDecoded: 0, 27 | nFramesPerPacket: 0, 28 | ec_prevSignalType: 0, 29 | ec_prevLagIndex: 0, 30 | VAD_flags: [0; 3], 31 | LBRR_flag: 0, 32 | LBRR_flags: [0; 3], 33 | resampler_state: ResamplerState::default(), 34 | psNLSF_CB: &silk_NLSF_CB_WB, 35 | indices: SideInfoIndices::default(), 36 | sCNG: silk_CNG_struct::default(), 37 | lossCnt: 0, 38 | prevSignalType: 0, 39 | arch: 0, 40 | sPLC: silk_PLC_struct::default(), 41 | }; 42 | 43 | silk_CNG_Reset(&mut dec); 44 | silk_PLC_Reset(&mut dec); 45 | 46 | dec 47 | } 48 | -------------------------------------------------------------------------------- /upstream-libopus/opus/doc/release.txt: -------------------------------------------------------------------------------- 1 | = Release checklist = 2 | 3 | == Source release == 4 | 5 | - Check for uncommitted changes to master. 6 | - Update OPUS_LT_* API versioning in configure.ac. 7 | - Tag the release commit with 'git tag -s vN.M'. 8 | - Include release notes in the tag annotation. 9 | - Verify 'make distcheck' produces a tarball with 10 | the desired name. 11 | - Push tag to public repo. 12 | - Upload source package 'opus-${version}.tar.gz' 13 | - Add to https://svn.xiph.org/releases/opus/ 14 | - Update checksum files 15 | - svn commit 16 | - Copy to archive.mozilla.org/pub/opus/ 17 | - Update checksum files there as well. 18 | - Add release notes to https://git.xiph.org/opus-website.git 19 | - Update links and checksums on the downloads page. 20 | - Add a copy of the documentation to 21 | and update the links. 22 | - Update /topic in #opus IRC channel. 23 | 24 | Releases are commited to https://svn.xiph.org/releases/opus/ 25 | which propagates to downloads.xiph.org, and copied manually 26 | to https://archive.mozilla.org/pub/opus/ 27 | 28 | Website updates are committed to https://git.xiph.org/opus-website.git 29 | which propagates to https://opus-codec.org/ 30 | 31 | == Binary release == 32 | 33 | We usually build opus-tools binaries for MacOS and Windows. 34 | 35 | Binary releases are copied manually to 36 | https://archive.mozilla.org/pub/opus/win32/ 37 | 38 | For Mac, submit a pull request to homebrew. 39 | 40 | == Website updates == 41 | 42 | For major releases, recreate the files on https://opus-codec.org/examples/ 43 | with the next encoder. 44 | -------------------------------------------------------------------------------- /upstream-libopus/opus/doc/opus_in_isobmff.css: -------------------------------------------------------------------------------- 1 | /* Normal links */ 2 | .normal_link a:link 3 | { 4 | color : yellow; 5 | } 6 | .normal_link a:visited 7 | { 8 | color : green; 9 | } 10 | 11 | /* Boxes */ 12 | .pre 13 | { 14 | white-space: pre; /* CSS 2.0 */ 15 | white-space: pre-wrap; /* CSS 2.1 */ 16 | white-space: -pre-wrap; /* Opera 4-6 */ 17 | white-space: -o-pre-wrap; /* Opera 7 */ 18 | white-space: -moz-pre-wrap; /* Mozilla */ 19 | white-space: -hp-pre-wrap; /* HP Printers */ 20 | word-wrap : break-word; /* IE 5+ */ 21 | } 22 | 23 | .title_box 24 | { 25 | width : 470px; 26 | height : 70px; 27 | margin : 2px 50px 2px 2px; 28 | padding : 10px; 29 | border : 1px solid black; 30 | background-color : #666666; 31 | white-space : pre; 32 | float : left; 33 | text-align : center; 34 | color : #C0C0C0; 35 | font-size : 50pt; 36 | font-style : italic; 37 | } 38 | 39 | .subindex_box 40 | { 41 | margin : 5px; 42 | padding : 14px 22px; 43 | border : 1px solid black; 44 | background-color : #778877; 45 | float : left; 46 | text-align : center; 47 | color : #115555; 48 | font-size : 32pt; 49 | } 50 | 51 | .frame_box 52 | { 53 | margin : 10px; 54 | padding : 10px; 55 | border : 0px; 56 | background-color : #084040; 57 | text-align : left; 58 | color : #C0C0C0; 59 | font-family : monospace; 60 | } 61 | -------------------------------------------------------------------------------- /src/silk/float/structs_FLP.rs: -------------------------------------------------------------------------------- 1 | use crate::silk::structs::{silk_encoder_state, stereo_enc_state}; 2 | 3 | #[derive(Copy, Clone)] 4 | #[repr(C)] 5 | pub struct silk_encoder { 6 | pub state_Fxx: [silk_encoder_state_FLP; 2], 7 | pub sStereo: stereo_enc_state, 8 | pub nBitsUsedLBRR: i32, 9 | pub nBitsExceeded: i32, 10 | pub nChannelsAPI: i32, 11 | pub nChannelsInternal: i32, 12 | pub nPrevChannelsInternal: i32, 13 | pub timeSinceSwitchAllowed_ms: i32, 14 | pub allowBandwidthSwitch: i32, 15 | pub prev_decode_only_middle: i32, 16 | } 17 | #[derive(Copy, Clone)] 18 | #[repr(C)] 19 | pub struct silk_encoder_state_FLP { 20 | pub sCmn: silk_encoder_state, 21 | pub sShape: silk_shape_state_FLP, 22 | pub x_buf: [f32; 720], 23 | pub LTPCorr: f32, 24 | } 25 | #[derive(Copy, Clone)] 26 | #[repr(C)] 27 | pub struct silk_shape_state_FLP { 28 | pub LastGainIndex: i8, 29 | pub HarmShapeGain_smth: f32, 30 | pub Tilt_smth: f32, 31 | } 32 | #[derive(Copy, Clone)] 33 | #[repr(C)] 34 | pub struct silk_encoder_control_FLP { 35 | pub Gains: [f32; 4], 36 | pub PredCoef: [[f32; 16]; 2], 37 | pub LTPCoef: [f32; 20], 38 | pub LTP_scale: f32, 39 | pub pitchL: [i32; 4], 40 | pub AR: [f32; 96], 41 | pub LF_MA_shp: [f32; 4], 42 | pub LF_AR_shp: [f32; 4], 43 | pub Tilt: [f32; 4], 44 | pub HarmShapeGain: [f32; 4], 45 | pub Lambda: f32, 46 | pub input_quality: f32, 47 | pub coding_quality: f32, 48 | pub predGain: f32, 49 | pub LTPredCodGain: f32, 50 | pub ResNrg: [f32; 4], 51 | pub GainsUnq_Q16: [i32; 4], 52 | pub lastGainIndexPrev: i8, 53 | } 54 | -------------------------------------------------------------------------------- /upstream-libopus/opus/celt/arm/fixed_arm64.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2015 Vidyo */ 2 | /* 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions 5 | are met: 6 | 7 | - Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 10 | - Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 15 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 16 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 17 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 18 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 21 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 22 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 23 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef FIXED_ARM64_H 28 | #define FIXED_ARM64_H 29 | 30 | #include 31 | 32 | #undef SIG2WORD16 33 | #define SIG2WORD16(x) (vqmovns_s32(PSHR32((x), SIG_SHIFT))) 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /src/silk/sort.rs: -------------------------------------------------------------------------------- 1 | pub unsafe fn silk_insertion_sort_increasing(a: *mut i32, idx: *mut i32, L: i32, K: i32) { 2 | let mut value: i32 = 0; 3 | let mut i: i32 = 0; 4 | let mut j: i32 = 0; 5 | assert!(K > 0); 6 | assert!(L > 0); 7 | assert!(L >= K); 8 | i = 0; 9 | while i < K { 10 | *idx.offset(i as isize) = i; 11 | i += 1; 12 | } 13 | i = 1; 14 | while i < K { 15 | value = *a.offset(i as isize); 16 | j = i - 1; 17 | while j >= 0 && value < *a.offset(j as isize) { 18 | *a.offset((j + 1) as isize) = *a.offset(j as isize); 19 | *idx.offset((j + 1) as isize) = *idx.offset(j as isize); 20 | j -= 1; 21 | } 22 | *a.offset((j + 1) as isize) = value; 23 | *idx.offset((j + 1) as isize) = i; 24 | i += 1; 25 | } 26 | i = K; 27 | while i < L { 28 | value = *a.offset(i as isize); 29 | if value < *a.offset((K - 1) as isize) { 30 | j = K - 2; 31 | while j >= 0 && value < *a.offset(j as isize) { 32 | *a.offset((j + 1) as isize) = *a.offset(j as isize); 33 | *idx.offset((j + 1) as isize) = *idx.offset(j as isize); 34 | j -= 1; 35 | } 36 | *a.offset((j + 1) as isize) = value; 37 | *idx.offset((j + 1) as isize) = i; 38 | } 39 | i += 1; 40 | } 41 | } 42 | 43 | pub fn silk_insertion_sort_increasing_all_values_int16(a: &mut [i16]) { 44 | for i in 1..a.len() { 45 | let mut j = i; 46 | while j > 0 && a[j] < a[j - 1] { 47 | a.swap(j, j - 1); 48 | j -= 1; 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/silk/LPC_analysis_filter.rs: -------------------------------------------------------------------------------- 1 | use ndarray::{aview1, azip, s}; 2 | 3 | use crate::silk::SigProc_FIX::{silk_RSHIFT_ROUND, silk_SAT16}; 4 | 5 | /// LPC analysis filter 6 | /// 7 | /// NB! State is kept internally and the 8 | /// filter always starts with zero state 9 | /// first d output samples are set to zero 10 | /// 11 | /// ```text 12 | /// out O Output signal 13 | /// in I Input signal 14 | /// B I MA prediction coefficients, Q12 [order] 15 | /// len I Signal length 16 | /// d I Filter order 17 | /// ``` 18 | pub fn silk_LPC_analysis_filter(out: &mut [i16], input: &[i16], B: &[i16]) { 19 | let len = input.len(); 20 | let d = B.len(); 21 | 22 | assert!(d >= 6); 23 | assert_eq!(d % 2, 0); 24 | assert!(d <= len); 25 | assert_eq!(out.len(), len); 26 | 27 | let input = aview1(input); 28 | let B = aview1(B); 29 | 30 | azip!((out in &mut out[d..], w in input.windows(d + 1)) { 31 | let in_ptr = w.slice(s![..d;-1]); 32 | 33 | let mut out32_Q12 = 0i32; 34 | /* Allowing wrap around so that two wraps can cancel each other. The rare 35 | cases where the result wraps around can only be triggered by invalid streams*/ 36 | azip!((&x in in_ptr, &b in B ) { 37 | out32_Q12 = out32_Q12.wrapping_add(x as i32 * b as i32); 38 | }); 39 | /* Subtract prediction */ 40 | out32_Q12 = ((w[d] as i32) << 12).wrapping_sub(out32_Q12); 41 | 42 | /* Scale to Q0 */ 43 | let out32 = silk_RSHIFT_ROUND(out32_Q12, 12); 44 | 45 | /* Saturate output */ 46 | *out = silk_SAT16(out32) as i16; 47 | }); 48 | 49 | /* Set first d output samples to zero */ 50 | out[..d].fill(0); 51 | } 52 | -------------------------------------------------------------------------------- /unsafe-libopus-tools/src/bin/opus_compare.rs: -------------------------------------------------------------------------------- 1 | //! A utility to compare PCM data 2 | //! 3 | //! It is used to run opus test vectors 4 | 5 | #![forbid(unsafe_code)] 6 | 7 | use clap::Parser; 8 | use unsafe_libopus_tools::demo::{Channels, SampleRate}; 9 | use unsafe_libopus_tools::{opus_compare, CompareParams, CompareResult}; 10 | 11 | #[derive(Parser)] 12 | struct Args { 13 | /// Whether to compare in stereo or mono 14 | #[arg(short)] 15 | stereo: bool, 16 | 17 | /// The sampling rate to use 18 | #[arg(short = 'r')] 19 | sample_rate: SampleRate, 20 | 21 | /// The true file to compare to 22 | true_file: std::path::PathBuf, 23 | 24 | /// The tested file to compare 25 | tested_file: std::path::PathBuf, 26 | } 27 | 28 | fn main() { 29 | let args: Args = Args::parse(); 30 | 31 | let params = CompareParams { 32 | sample_rate: args.sample_rate, 33 | channels: if args.stereo { 34 | Channels::Stereo 35 | } else { 36 | Channels::Mono 37 | }, 38 | }; 39 | 40 | let fin1 = std::fs::read(args.true_file).expect("Could not read true file"); 41 | let fin2 = std::fs::read(args.tested_file).expect("Could not read comparing file"); 42 | 43 | let CompareResult { error, quality } = opus_compare(params, &fin1, &fin2); 44 | 45 | if quality < 0f64 { 46 | eprintln!("Test vector FAILS"); 47 | eprintln!("Internal weighted error is {}", error); 48 | std::process::exit(1); 49 | } else { 50 | eprintln!("Test vector PASSES"); 51 | eprintln!( 52 | "Opus quality metric: {} % (internal weighted error is {})", 53 | quality, error 54 | ); 55 | }; 56 | } 57 | -------------------------------------------------------------------------------- /src/silk/resampler/down2.rs: -------------------------------------------------------------------------------- 1 | pub mod typedef_h { 2 | pub const silk_int16_MIN: i32 = i16::MIN as i32; 3 | pub const silk_int16_MAX: i32 = i16::MAX as i32; 4 | } 5 | pub use self::typedef_h::{silk_int16_MAX, silk_int16_MIN}; 6 | use super::rom::{silk_resampler_down2_0, silk_resampler_down2_1}; 7 | 8 | pub fn silk_resampler_down2(S: &mut [i32; 2], out: &mut [i16], in_0: &[i16]) { 9 | assert_eq!(out.len() * 2, in_0.len()); 10 | 11 | assert!(silk_resampler_down2_0 as i32 > 0); 12 | assert!((silk_resampler_down2_1 as i32) < 0); 13 | for k in 0..out.len() { 14 | let in32 = ((in_0[2 * k] as i32 as u32) << 10) as i32; 15 | let Y = in32 - S[0]; 16 | let X = (Y as i64 + ((Y as i64 * silk_resampler_down2_1 as i64) >> 16)) as i32; 17 | let mut out32 = S[0] + X; 18 | S[0] = in32 + X; 19 | 20 | let in32 = ((in_0[2 * k + 1] as i32 as u32) << 10) as i32; 21 | let Y = in32 - S[1]; 22 | let X = (Y as i64 * silk_resampler_down2_0 as i64 >> 16) as i32; 23 | out32 += S[1]; 24 | out32 += X; 25 | S[1] = in32 + X; 26 | 27 | out[k] = (if (if 11 == 1 { 28 | (out32 >> 1) + (out32 & 1) 29 | } else { 30 | (out32 >> 11 - 1) + 1 >> 1 31 | }) > silk_int16_MAX 32 | { 33 | silk_int16_MAX 34 | } else if (if 11 == 1 { 35 | (out32 >> 1) + (out32 & 1) 36 | } else { 37 | (out32 >> 11 - 1) + 1 >> 1 38 | }) < silk_int16_MIN 39 | { 40 | silk_int16_MIN 41 | } else if 11 == 1 { 42 | (out32 >> 1) + (out32 & 1) 43 | } else { 44 | (out32 >> 11 - 1) + 1 >> 1 45 | }) as i16; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/silk/float/LTP_analysis_filter_FLP.rs: -------------------------------------------------------------------------------- 1 | use crate::silk::define::LTP_ORDER; 2 | pub unsafe fn silk_LTP_analysis_filter_FLP( 3 | LTP_res: *mut f32, 4 | x: *const f32, 5 | B: *const f32, 6 | pitchL: *const i32, 7 | invGains: *const f32, 8 | subfr_length: i32, 9 | nb_subfr: i32, 10 | pre_length: i32, 11 | ) { 12 | let mut x_ptr: *const f32 = 0 as *const f32; 13 | let mut x_lag_ptr: *const f32 = 0 as *const f32; 14 | let mut Btmp: [f32; 5] = [0.; 5]; 15 | let mut LTP_res_ptr: *mut f32 = 0 as *mut f32; 16 | let mut inv_gain: f32 = 0.; 17 | let mut k: i32 = 0; 18 | let mut i: i32 = 0; 19 | let mut j: i32 = 0; 20 | x_ptr = x; 21 | LTP_res_ptr = LTP_res; 22 | k = 0; 23 | while k < nb_subfr { 24 | x_lag_ptr = x_ptr.offset(-(*pitchL.offset(k as isize) as isize)); 25 | inv_gain = *invGains.offset(k as isize); 26 | i = 0; 27 | while i < LTP_ORDER as i32 { 28 | Btmp[i as usize] = *B.offset((k * LTP_ORDER as i32 + i) as isize); 29 | i += 1; 30 | } 31 | i = 0; 32 | while i < subfr_length + pre_length { 33 | *LTP_res_ptr.offset(i as isize) = *x_ptr.offset(i as isize); 34 | j = 0; 35 | while j < LTP_ORDER as i32 { 36 | *LTP_res_ptr.offset(i as isize) -= 37 | Btmp[j as usize] * *x_lag_ptr.offset((LTP_ORDER as i32 / 2 - j) as isize); 38 | j += 1; 39 | } 40 | *LTP_res_ptr.offset(i as isize) *= inv_gain; 41 | x_lag_ptr = x_lag_ptr.offset(1); 42 | i += 1; 43 | } 44 | LTP_res_ptr = LTP_res_ptr.offset((subfr_length + pre_length) as isize); 45 | x_ptr = x_ptr.offset(subfr_length as isize); 46 | k += 1; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/silk/NLSF_VQ.rs: -------------------------------------------------------------------------------- 1 | /// Compute quantization errors for an LPC_order element input vector for a VQ codebook 2 | pub fn silk_NLSF_VQ( 3 | // Quantization errors [K] 4 | err_Q24: &mut [i32], 5 | // Input vectors to be quantized [LPC_order] 6 | in_Q15: &[i16], 7 | // Codebook vectors [K*LPC_order] 8 | pCB_Q8: &[u8], 9 | // Codebook weights [K*LPC_order] 10 | pWght_Q9: &[i16], 11 | // Number of codebook vectors 12 | K: usize, 13 | // Number of LPCs 14 | LPC_order: usize, 15 | ) { 16 | assert_eq!(err_Q24.len(), K); 17 | assert_eq!(in_Q15.len(), LPC_order); 18 | assert_eq!(pCB_Q8.len(), K * LPC_order); 19 | assert_eq!(pWght_Q9.len(), K * LPC_order); 20 | 21 | assert_eq!(LPC_order & 1, 0); 22 | 23 | let mut diff_Q15: i32 = 0; 24 | let mut diffw_Q24: i32 = 0; 25 | let mut sum_error_Q24: i32 = 0; 26 | let mut pred_Q24: i32 = 0; 27 | let mut cb_Q8_ptr = pCB_Q8; 28 | let mut w_Q9_ptr = pWght_Q9; 29 | 30 | for i in 0..K { 31 | sum_error_Q24 = 0; 32 | pred_Q24 = 0; 33 | 34 | for m in (0..=LPC_order - 2).rev().step_by(2) { 35 | diff_Q15 = in_Q15[m + 1] as i32 - ((cb_Q8_ptr[m + 1] as i32 as u32) << 7) as i32; 36 | diffw_Q24 = diff_Q15 as i16 as i32 * w_Q9_ptr[m + 1] as i32; 37 | sum_error_Q24 += (diffw_Q24 - (pred_Q24 >> 1)).abs(); 38 | pred_Q24 = diffw_Q24; 39 | diff_Q15 = in_Q15[m] as i32 - ((cb_Q8_ptr[m] as i32 as u32) << 7) as i32; 40 | diffw_Q24 = diff_Q15 as i16 as i32 * w_Q9_ptr[m] as i32; 41 | sum_error_Q24 += (diffw_Q24 - (pred_Q24 >> 1)).abs(); 42 | pred_Q24 = diffw_Q24; 43 | } 44 | err_Q24[i] = sum_error_Q24; 45 | cb_Q8_ptr = &cb_Q8_ptr[LPC_order..]; 46 | w_Q9_ptr = &w_Q9_ptr[LPC_order..]; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/silk/sum_sqr_shift.rs: -------------------------------------------------------------------------------- 1 | use crate::silk::macros::{silk_CLZ32, silk_SMULBB}; 2 | use crate::silk::SigProc_FIX::silk_max_32; 3 | 4 | fn silk_sum_sqr_shift_inner(mut nrg: i32, shft: i32, x: &[i16]) -> i32 { 5 | let len = x.len(); 6 | 7 | let mut i = 0; 8 | while i < len - 1 { 9 | let nrg_tmp = silk_SMULBB(x[i] as i32, x[i] as i32) as u32; 10 | let nrg_tmp = nrg_tmp.wrapping_add(silk_SMULBB(x[i + 1] as i32, x[i + 1] as i32) as u32); 11 | nrg = nrg.wrapping_add((nrg_tmp >> shft) as i32); 12 | i += 2; 13 | } 14 | if i < len { 15 | /* One sample left to process */ 16 | let nrg_tmp = silk_SMULBB(x[i] as i32, x[i] as i32) as u32; 17 | nrg = nrg.wrapping_add((nrg_tmp >> shft) as i32); 18 | } 19 | 20 | debug_assert!(nrg >= 0); 21 | 22 | nrg 23 | } 24 | 25 | /// Compute number of bits to right shift the sum of squares of a vector of int16s to make it fit in an int32 26 | /// 27 | /// ```text 28 | /// energy O Energy of x, after shifting to the right 29 | /// shift O Number of bits right shift applied to energy 30 | /// x I Input vector 31 | /// len I Length of input vector 32 | /// ``` 33 | pub fn silk_sum_sqr_shift(energy: &mut i32, shift: &mut i32, x: &[i16]) { 34 | let len = x.len(); 35 | 36 | /* Do a first run with the maximum shift we could have. */ 37 | let shft = 31 - silk_CLZ32(len as i32); 38 | /* Let's be conservative with rounding and start with nrg=len. */ 39 | let nrg = silk_sum_sqr_shift_inner(len as i32, shft, x); 40 | 41 | /* Make sure the result will fit in a 32-bit signed integer with two bits 42 | of headroom. */ 43 | let shft = silk_max_32(0, shft + 3 - silk_CLZ32(nrg)); 44 | let nrg = silk_sum_sqr_shift_inner(0, shft, x); 45 | 46 | /* Output arguments */ 47 | *shift = shft; 48 | *energy = nrg; 49 | } 50 | -------------------------------------------------------------------------------- /src/silk/biquad_alt.rs: -------------------------------------------------------------------------------- 1 | use crate::silk::macros::{silk_SMLAWB, silk_SMULWB}; 2 | use crate::silk::SigProc_FIX::{silk_RSHIFT_ROUND, silk_SAT16}; 3 | use ndarray::azip; 4 | 5 | /// Second order ARMA filter, alternative implementation 6 | /// 7 | /// Slower than biquad() but uses more precise coefficients. 8 | /// Can handle (slowly) varying coefficients. 9 | /// 10 | /// ```text 11 | /// B_Q28 I MA coefficients [3] 12 | /// A_Q28 I AR coefficients [2] 13 | /// S I/O State vector [2] 14 | /// in I/O input/output signal, length must be even 15 | /// ``` 16 | pub fn silk_biquad_alt_stride1( 17 | B_Q28: &[i32; 3], 18 | A_Q28: &[i32; 2], 19 | S: &mut [i32; 2], 20 | signal: &mut [i16], 21 | ) { 22 | /* DIRECT FORM II TRANSPOSED (uses 2 element state vector) */ 23 | 24 | /* Negate A_Q28 values and split in two parts */ 25 | let A0_L_Q28 = -A_Q28[0] & 0x3fff; 26 | let A0_U_Q28 = -A_Q28[0] >> 14; 27 | let A1_L_Q28 = -A_Q28[1] & 0x3fff; 28 | let A1_U_Q28 = -A_Q28[1] >> 14; 29 | 30 | assert_eq!(signal.len() % 2, 0); 31 | 32 | azip!( 33 | (signal in signal) { 34 | let inval = *signal as i32; 35 | 36 | /* S[ 0 ], S[ 1 ]: Q12 */ 37 | let out32_Q14 = silk_SMLAWB(S[0], B_Q28[0], inval) << 2; 38 | 39 | S[0] = S[1] + silk_RSHIFT_ROUND(silk_SMULWB(out32_Q14, A0_L_Q28), 14); 40 | S[0] = silk_SMLAWB(S[0], out32_Q14, A0_U_Q28); 41 | S[0] = silk_SMLAWB(S[0], B_Q28[1], inval); 42 | 43 | S[1] = silk_RSHIFT_ROUND(silk_SMULWB(out32_Q14, A1_L_Q28), 14); 44 | S[1] = silk_SMLAWB(S[1], out32_Q14, A1_U_Q28); 45 | S[1] = silk_SMLAWB(S[1], B_Q28[2], inval); 46 | 47 | /* Scale back to Q0 and saturate */ 48 | *signal = silk_SAT16((out32_Q14 + (1 << 14) - 1) >> 14) as i16; 49 | } 50 | ); 51 | } 52 | -------------------------------------------------------------------------------- /upstream-libopus/opus/celt/arm/armopts.s.in: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Mozilla Corporation */ 2 | /* 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions 5 | are met: 6 | 7 | - Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 10 | - Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 15 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 16 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 17 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 18 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 21 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 22 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 23 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | ; Set the following to 1 if we have EDSP instructions 28 | ; (LDRD/STRD, etc., ARMv5E and later). 29 | OPUS_ARM_MAY_HAVE_EDSP * @OPUS_ARM_MAY_HAVE_EDSP@ 30 | 31 | ; Set the following to 1 if we have ARMv6 media instructions. 32 | OPUS_ARM_MAY_HAVE_MEDIA * @OPUS_ARM_MAY_HAVE_MEDIA@ 33 | 34 | ; Set the following to 1 if we have NEON (some ARMv7) 35 | OPUS_ARM_MAY_HAVE_NEON * @OPUS_ARM_MAY_HAVE_NEON@ 36 | 37 | END 38 | -------------------------------------------------------------------------------- /upstream-libopus/opus/m4/ax_add_fortify_source.m4: -------------------------------------------------------------------------------- 1 | # =========================================================================== 2 | # Modified from https://www.gnu.org/software/autoconf-archive/ax_add_fortify_source.html 3 | # =========================================================================== 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_ADD_FORTIFY_SOURCE 8 | # 9 | # DESCRIPTION 10 | # 11 | # Check whether -D_FORTIFY_SOURCE=2 can be added to CFLAGS without macro 12 | # redefinition warnings. Some distributions (such as Gentoo Linux) enable 13 | # _FORTIFY_SOURCE globally in their compilers, leading to unnecessary 14 | # warnings in the form of 15 | # 16 | # :0:0: error: "_FORTIFY_SOURCE" redefined [-Werror] 17 | # : note: this is the location of the previous definition 18 | # 19 | # which is a problem if -Werror is enabled. This macro checks whether 20 | # _FORTIFY_SOURCE is already defined, and if not, adds -D_FORTIFY_SOURCE=2 21 | # to CFLAGS. 22 | # 23 | # LICENSE 24 | # 25 | # Copyright (c) 2017 David Seifert 26 | # 27 | # Copying and distribution of this file, with or without modification, are 28 | # permitted in any medium without royalty provided the copyright notice 29 | # and this notice are preserved. This file is offered as-is, without any 30 | # warranty. 31 | 32 | #serial 1 33 | 34 | AC_DEFUN([AX_ADD_FORTIFY_SOURCE],[ 35 | AC_MSG_CHECKING([whether to add -D_FORTIFY_SOURCE=2 to CFLAGS]) 36 | AC_LINK_IFELSE([ 37 | AC_LANG_SOURCE( 38 | [[ 39 | int main() { 40 | #ifndef _FORTIFY_SOURCE 41 | return 0; 42 | #else 43 | this_is_an_error; 44 | #endif 45 | } 46 | ]] 47 | )], [ 48 | AC_MSG_RESULT([yes]) 49 | CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=2" 50 | ], [ 51 | AC_MSG_RESULT([no]) 52 | ]) 53 | ]) 54 | -------------------------------------------------------------------------------- /upstream-libopus/opus/celt/dump_modes/dump_modes_arch.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2015 Xiph.Org Foundation 2 | Written by Viswanath Puttagunta */ 3 | /* 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | - Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | - Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 19 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 22 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 23 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 24 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef DUMP_MODE_ARCH_H 29 | #define DUMP_MODE_ARCH_H 30 | 31 | void dump_modes_arch_init(); 32 | void dump_mode_arch(CELTMode *mode); 33 | void dump_modes_arch_finalize(); 34 | 35 | #if !defined(FIXED_POINT) 36 | #define ARM_NE10_ARCH_FILE_NAME "static_modes_float_arm_ne10.h" 37 | #else 38 | #define ARM_NE10_ARCH_FILE_NAME "static_modes_fixed_arm_ne10.h" 39 | #endif 40 | 41 | #if defined(HAVE_ARM_NE10) 42 | #define OVERRIDE_FFT (1) 43 | #endif 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /upstream-libopus/opus/celt/tests/test_unit_types.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2008-2011 Xiph.Org Foundation 2 | Written by Jean-Marc Valin */ 3 | /* 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | - Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | - Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 19 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 22 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 23 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 24 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifdef HAVE_CONFIG_H 29 | #include "config.h" 30 | #endif 31 | 32 | #include "opus_types.h" 33 | #include 34 | 35 | int main(void) 36 | { 37 | opus_int16 i = 1; 38 | i <<= 14; 39 | if (i>>14 != 1) 40 | { 41 | fprintf(stderr, "opus_int16 isn't 16 bits\n"); 42 | return 1; 43 | } 44 | if (sizeof(opus_int16)*2 != sizeof(opus_int32)) 45 | { 46 | fprintf(stderr, "16*2 != 32\n"); 47 | return 1; 48 | } 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /src/silk/NLSF_VQ_weights_laroia.rs: -------------------------------------------------------------------------------- 1 | pub mod typedef_h { 2 | pub const silk_int16_MAX: i32 = i16::MAX as i32; 3 | } 4 | pub use self::typedef_h::silk_int16_MAX; 5 | use crate::silk::SigProc_FIX::{silk_max_int, silk_min_int}; 6 | 7 | const NLSF_W_Q: i32 = 2; 8 | 9 | /// Laroia low complexity NLSF weights 10 | /// 11 | /// R. Laroia, N. Phamdo and N. Farvardin, "Robust and Efficient Quantization of Speech LSP 12 | /// Parameters Using Structured Vector Quantization", Proc. IEEE Int. Conf. Acoust., Speech, 13 | /// Signal Processing, pp. 641-644, 1991. 14 | pub fn silk_NLSF_VQ_weights_laroia(pNLSFW_Q_OUT: &mut [i16], pNLSF_Q15: &[i16]) { 15 | let mut tmp1_int: i32 = 0; 16 | let mut tmp2_int: i32 = 0; 17 | 18 | assert_eq!(pNLSF_Q15.len(), pNLSFW_Q_OUT.len()); 19 | let D = pNLSF_Q15.len(); 20 | 21 | assert!(D > 0); 22 | assert_eq!(D & 1, 0); 23 | 24 | // First value 25 | tmp1_int = silk_max_int(pNLSF_Q15[0] as i32, 1); 26 | tmp1_int = (1 << (15 + NLSF_W_Q)) / tmp1_int; 27 | tmp2_int = silk_max_int(pNLSF_Q15[1] as i32 - pNLSF_Q15[0] as i32, 1); 28 | tmp2_int = (1 << (15 + NLSF_W_Q)) / tmp2_int; 29 | pNLSFW_Q_OUT[0] = silk_min_int(tmp1_int + tmp2_int, silk_int16_MAX) as i16; 30 | 31 | // Main loop 32 | let mut k = 1; 33 | while k < D - 1 { 34 | tmp1_int = silk_max_int(pNLSF_Q15[k + 1] as i32 - pNLSF_Q15[k] as i32, 1); 35 | tmp1_int = (1 << (15 + NLSF_W_Q)) / tmp1_int; 36 | pNLSFW_Q_OUT[k] = silk_min_int(tmp1_int + tmp2_int, silk_int16_MAX) as i16; 37 | tmp2_int = silk_max_int(pNLSF_Q15[k + 2] as i32 - pNLSF_Q15[k + 1] as i32, 1); 38 | tmp2_int = (1 << (15 + NLSF_W_Q)) / tmp2_int; 39 | pNLSFW_Q_OUT[k + 1] = silk_min_int(tmp1_int + tmp2_int, silk_int16_MAX) as i16; 40 | k += 2; 41 | } 42 | 43 | // Last value 44 | tmp1_int = silk_max_int((1 << 15) - pNLSF_Q15[D - 1] as i32, 1); 45 | tmp1_int = (1 << (15 + NLSF_W_Q)) / tmp1_int; 46 | pNLSFW_Q_OUT[D - 1] = silk_min_int(tmp1_int + tmp2_int, silk_int16_MAX) as i16; 47 | } 48 | -------------------------------------------------------------------------------- /upstream-libopus/opus/silk/arm/macros_arm64.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (C) 2015 Vidyo 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions 5 | are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 12 | names of specific contributors, may be used to endorse or promote 13 | products derived from this software without specific prior written 14 | permission. 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #ifndef SILK_MACROS_ARM64_H 29 | #define SILK_MACROS_ARM64_H 30 | 31 | #include 32 | 33 | #undef silk_ADD_SAT32 34 | #define silk_ADD_SAT32(a, b) (vqadds_s32((a), (b))) 35 | 36 | #undef silk_SUB_SAT32 37 | #define silk_SUB_SAT32(a, b) (vqsubs_s32((a), (b))) 38 | 39 | #endif /* SILK_MACROS_ARM64_H */ 40 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2001-2011 Xiph.Org, Skype Limited, Octasic, 2 | Jean-Marc Valin, Timothy B. Terriberry, 3 | CSIRO, Gregory Maxwell, Mark Borgerding, 4 | Erik de Castro Lopo 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 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 18 | names of specific contributors, may be used to endorse or promote 19 | products derived from this software without specific prior written 20 | permission. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 26 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 27 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 28 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 30 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 31 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | 34 | Opus is subject to the royalty-free patent licenses which are 35 | specified at: 36 | 37 | Xiph.Org Foundation: 38 | https://datatracker.ietf.org/ipr/1524/ 39 | 40 | Microsoft Corporation: 41 | https://datatracker.ietf.org/ipr/1914/ 42 | 43 | Broadcom Corporation: 44 | https://datatracker.ietf.org/ipr/1526/ -------------------------------------------------------------------------------- /upstream-libopus/opus/celt/cwrs.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2007-2008 CSIRO 2 | Copyright (c) 2007-2009 Xiph.Org Foundation 3 | Copyright (c) 2007-2009 Timothy B. Terriberry 4 | Written by Timothy B. Terriberry and Jean-Marc Valin */ 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 | #ifndef CWRS_H 31 | #define CWRS_H 32 | 33 | #include "arch.h" 34 | #include "stack_alloc.h" 35 | #include "entenc.h" 36 | #include "entdec.h" 37 | 38 | #ifdef CUSTOM_MODES 39 | int log2_frac(opus_uint32 val, int frac); 40 | #endif 41 | 42 | void get_required_bits(opus_int16 *bits, int N, int K, int frac); 43 | 44 | void encode_pulses(const int *_y, int N, int K, ec_enc *enc); 45 | 46 | opus_val32 decode_pulses(int *_y, int N, int K, ec_dec *dec); 47 | 48 | #endif /* CWRS_H */ 49 | -------------------------------------------------------------------------------- /upstream-libopus/opus/COPYING: -------------------------------------------------------------------------------- 1 | Copyright 2001-2011 Xiph.Org, Skype Limited, Octasic, 2 | Jean-Marc Valin, Timothy B. Terriberry, 3 | CSIRO, Gregory Maxwell, Mark Borgerding, 4 | Erik de Castro Lopo 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 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 18 | names of specific contributors, may be used to endorse or promote 19 | products derived from this software without specific prior written 20 | permission. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 26 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 27 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 28 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 30 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 31 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | 34 | Opus is subject to the royalty-free patent licenses which are 35 | specified at: 36 | 37 | Xiph.Org Foundation: 38 | https://datatracker.ietf.org/ipr/1524/ 39 | 40 | Microsoft Corporation: 41 | https://datatracker.ietf.org/ipr/1914/ 42 | 43 | Broadcom Corporation: 44 | https://datatracker.ietf.org/ipr/1526/ 45 | -------------------------------------------------------------------------------- /upstream-libopus/opus/doc/header.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | $projectname: $title 7 | $title 8 | 9 | 10 | $treeview 11 | $search 12 | $mathjax 13 | 14 | 15 |
16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 29 | 37 | 38 | 39 | 40 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 |
27 |
Opus
28 |
30 | 33 | 35 |
31 |
$projectbrief
32 |
$projectnumber 34 |
36 |
41 |
$projectbrief
42 |
$searchbox
53 |
54 | 55 | -------------------------------------------------------------------------------- /upstream-libopus/opus/scripts/dump_rnn.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | from __future__ import print_function 4 | 5 | from keras.models import Sequential 6 | from keras.layers import Dense 7 | from keras.layers import LSTM 8 | from keras.layers import GRU 9 | from keras.models import load_model 10 | from keras import backend as K 11 | 12 | import numpy as np 13 | 14 | def printVector(f, vector, name): 15 | v = np.reshape(vector, (-1)); 16 | #print('static const float ', name, '[', len(v), '] = \n', file=f) 17 | f.write('static const opus_int16 {}[{}] = {{\n '.format(name, len(v))) 18 | for i in range(0, len(v)): 19 | f.write('{}'.format(int(round(8192*v[i])))) 20 | if (i!=len(v)-1): 21 | f.write(',') 22 | else: 23 | break; 24 | if (i%8==7): 25 | f.write("\n ") 26 | else: 27 | f.write(" ") 28 | #print(v, file=f) 29 | f.write('\n};\n\n') 30 | return; 31 | 32 | def binary_crossentrop2(y_true, y_pred): 33 | return K.mean(2*K.abs(y_true-0.5) * K.binary_crossentropy(y_pred, y_true), axis=-1) 34 | 35 | 36 | model = load_model("weights.hdf5", custom_objects={'binary_crossentrop2': binary_crossentrop2}) 37 | 38 | weights = model.get_weights() 39 | 40 | f = open('rnn_weights.c', 'w') 41 | 42 | f.write('/*This file is automatically generated from a Keras model*/\n\n') 43 | f.write('#ifdef HAVE_CONFIG_H\n#include "config.h"\n#endif\n\n#include "mlp.h"\n\n') 44 | 45 | printVector(f, weights[0], 'layer0_weights') 46 | printVector(f, weights[1], 'layer0_bias') 47 | printVector(f, weights[2], 'layer1_weights') 48 | printVector(f, weights[3], 'layer1_recur_weights') 49 | printVector(f, weights[4], 'layer1_bias') 50 | printVector(f, weights[5], 'layer2_weights') 51 | printVector(f, weights[6], 'layer2_bias') 52 | 53 | f.write('const DenseLayer layer0 = {\n layer0_bias,\n layer0_weights,\n 25, 16, 0\n};\n\n') 54 | f.write('const GRULayer layer1 = {\n layer1_bias,\n layer1_weights,\n layer1_recur_weights,\n 16, 12\n};\n\n') 55 | f.write('const DenseLayer layer2 = {\n layer2_bias,\n layer2_weights,\n 12, 2, 1\n};\n\n') 56 | 57 | f.close() 58 | -------------------------------------------------------------------------------- /src/silk/decode_pitch.rs: -------------------------------------------------------------------------------- 1 | use crate::silk::pitch_est_tables::{ 2 | silk_CB_lags_stage2, silk_CB_lags_stage2_10_ms, silk_CB_lags_stage3, silk_CB_lags_stage3_10_ms, 3 | PE_MAX_LAG_MS, PE_MAX_NB_SUBFR, PE_MAX_NB_SUBFR_OVER_2, PE_MIN_LAG_MS, PE_NB_CBKS_STAGE2_10MS, 4 | PE_NB_CBKS_STAGE2_EXT, PE_NB_CBKS_STAGE3_10MS, PE_NB_CBKS_STAGE3_MAX, 5 | }; 6 | use crate::silk::SigProc_FIX::silk_LIMIT; 7 | use ndarray::{azip, ArrayView2}; 8 | 9 | /// Pitch analyzer function 10 | /// 11 | /// ```text 12 | /// lagIndex I 13 | /// contourIndex O 14 | /// pitch_lags[] O 4 pitch values 15 | /// Fs_kHz I sampling frequency (kHz) 16 | /// nb_subfr I number of sub frames 17 | /// ``` 18 | pub fn silk_decode_pitch(lagIndex: i16, contourIndex: i8, pitch_lags: &mut [i32], Fs_kHz: i32) { 19 | let nb_subfr = pitch_lags.len(); 20 | 21 | let Lag_CB_ptr = match (Fs_kHz, nb_subfr) { 22 | (8, PE_MAX_NB_SUBFR) => ArrayView2::from_shape( 23 | (PE_MAX_NB_SUBFR, PE_NB_CBKS_STAGE2_EXT), 24 | &silk_CB_lags_stage2, 25 | ), 26 | (8, PE_MAX_NB_SUBFR_OVER_2) => ArrayView2::from_shape( 27 | (PE_MAX_NB_SUBFR / 2, PE_NB_CBKS_STAGE2_10MS), 28 | &silk_CB_lags_stage2_10_ms, 29 | ), 30 | (12 | 16, PE_MAX_NB_SUBFR) => ArrayView2::from_shape( 31 | (PE_MAX_NB_SUBFR, PE_NB_CBKS_STAGE3_MAX), 32 | &silk_CB_lags_stage3, 33 | ), 34 | (12 | 16, PE_MAX_NB_SUBFR_OVER_2) => ArrayView2::from_shape( 35 | (PE_MAX_NB_SUBFR / 2, PE_NB_CBKS_STAGE3_10MS), 36 | &silk_CB_lags_stage3_10_ms, 37 | ), 38 | (Fs_kHz, nb_subfr) => { 39 | unreachable!("Fs_kHz: {}, nb_subfr: {}", Fs_kHz, nb_subfr) 40 | } 41 | } 42 | .unwrap(); 43 | 44 | let min_lag = PE_MIN_LAG_MS * Fs_kHz as i16 as i32; 45 | let max_lag = PE_MAX_LAG_MS * Fs_kHz as i16 as i32; 46 | let lag = min_lag + lagIndex as i32; 47 | 48 | azip!((out_lag in pitch_lags, lag_cb in Lag_CB_ptr.rows()) { 49 | let lag = lag + lag_cb[contourIndex as usize] as i32; 50 | *out_lag = silk_LIMIT(lag, min_lag, max_lag); 51 | }); 52 | } 53 | -------------------------------------------------------------------------------- /upstream-libopus/opus/celt/x86/vq_sse.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2016 Jean-Marc Valin */ 2 | /* 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions 5 | are met: 6 | 7 | - Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 10 | - Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 15 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 16 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 17 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 18 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 21 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 22 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 23 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef VQ_SSE_H 28 | #define VQ_SSE_H 29 | 30 | #if defined(OPUS_X86_MAY_HAVE_SSE2) && !defined(FIXED_POINT) 31 | #define OVERRIDE_OP_PVQ_SEARCH 32 | 33 | opus_val16 op_pvq_search_sse2(celt_norm *_X, int *iy, int K, int N, int arch); 34 | 35 | #if defined(OPUS_X86_PRESUME_SSE2) 36 | #define op_pvq_search(x, iy, K, N, arch) \ 37 | (op_pvq_search_sse2(x, iy, K, N, arch)) 38 | 39 | #else 40 | 41 | extern opus_val16 (*const OP_PVQ_SEARCH_IMPL[OPUS_ARCHMASK + 1])( 42 | celt_norm *_X, int *iy, int K, int N, int arch); 43 | 44 | # define op_pvq_search(X, iy, K, N, arch) \ 45 | ((*OP_PVQ_SEARCH_IMPL[(arch) & OPUS_ARCHMASK])(X, iy, K, N, arch)) 46 | 47 | #endif 48 | #endif 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /unsafe-libopus-tools/src/bin/opus_demo/main.rs: -------------------------------------------------------------------------------- 1 | #![allow(non_camel_case_types)] 2 | #![allow(non_snake_case)] 3 | #![allow(non_upper_case_globals)] 4 | #![allow(unused_assignments)] 5 | #![allow(unused_mut)] 6 | 7 | mod cli; 8 | 9 | use crate::cli::{Cli, Mode}; 10 | use unsafe_libopus::opus_get_version_string; 11 | use unsafe_libopus_tools::demo::{ 12 | opus_demo_adjust_length, opus_demo_decode, opus_demo_encode, DecodeArgs, 13 | }; 14 | 15 | pub fn main() { 16 | let cli = Cli::parse(); 17 | 18 | eprintln!("{}", opus_get_version_string()); 19 | 20 | let backend = cli.backend; 21 | 22 | match cli.mode { 23 | Mode::EncodeDecode(args) => { 24 | let fin = std::fs::read(&cli.input).expect("failed to read input file"); 25 | let (encoded, pre_skip) = opus_demo_encode(backend, &fin, args); 26 | let mut decoded = opus_demo_decode( 27 | backend, 28 | &encoded, 29 | DecodeArgs { 30 | sample_rate: args.sample_rate, 31 | channels: args.channels, 32 | options: args.options.common, 33 | }, 34 | ); 35 | opus_demo_adjust_length( 36 | &mut decoded, 37 | pre_skip, 38 | fin.len(), 39 | args.sample_rate, 40 | args.channels, 41 | ); 42 | std::fs::write(&cli.output, &decoded).expect("failed to write output file"); 43 | // TODO: write statistics 44 | } 45 | Mode::EncodeOnly(args) => { 46 | let fin = std::fs::read(&cli.input).expect("failed to read input file"); 47 | let (output, _pre_skip) = opus_demo_encode(backend, &fin, args); 48 | std::fs::write(&cli.output, &output).expect("failed to write output file"); 49 | // TODO: write statistics 50 | } 51 | Mode::DecodeOnly(args) => { 52 | let fin = std::fs::read(&cli.input).expect("failed to read input file"); 53 | let output = opus_demo_decode(backend, &fin, args); 54 | std::fs::write(&cli.output, &output).expect("failed to write output file"); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/silk/LPC_fit.rs: -------------------------------------------------------------------------------- 1 | use crate::silk::bwexpander_32::silk_bwexpander_32; 2 | use crate::silk::SigProc_FIX::{silk_RSHIFT_ROUND, silk_SAT16, SILK_FIX_CONST}; 3 | use ndarray::azip; 4 | 5 | /// Convert int32 coefficients to int16 coefs and make sure there's no wrap-around 6 | /// 7 | /// ```text 8 | /// a_QOUT O Output signal 9 | /// a_QIN I/O Input signal 10 | /// QOUT I Input Q domain 11 | /// QIN I Input Q domain 12 | /// d I Filter order 13 | /// ``` 14 | pub fn silk_LPC_fit(a_QOUT: &mut [i16], a_QIN: &mut [i32], QOUT: i32, QIN: i32) { 15 | let d = a_QOUT.len(); 16 | assert_eq!(a_QIN.len(), d); 17 | 18 | /* Limit the maximum absolute value of the prediction coefficients, so that they'll fit in int16 */ 19 | let mut i = 0; 20 | while i < 10 { 21 | /* Find maximum absolute value and its index */ 22 | let mut maxabs = 0; 23 | let mut idx = 0; 24 | let mut k = 0; 25 | while k < d { 26 | let absval = a_QIN[k].abs(); 27 | if absval > maxabs { 28 | maxabs = absval; 29 | idx = k; 30 | } 31 | k += 1; 32 | } 33 | maxabs = silk_RSHIFT_ROUND(maxabs, QIN - QOUT); 34 | 35 | if maxabs > i16::MAX as i32 { 36 | /* Reduce magnitude of prediction coefficients */ 37 | maxabs = std::cmp::min(maxabs, 163838); /* ( silk_int32_MAX >> 14 ) + silk_int16_MAX = 163838 */ 38 | let chirp_Q16 = SILK_FIX_CONST!(0.999f64, 16) 39 | - ((maxabs - i16::MAX as i32) << 14) / ((maxabs * (idx as i32 + 1)) >> 2); 40 | silk_bwexpander_32(a_QIN, chirp_Q16); 41 | } else { 42 | break; 43 | } 44 | 45 | i += 1; 46 | } 47 | 48 | if i == 10 { 49 | /* Reached the last iteration, clip the coefficients */ 50 | azip!((out in a_QOUT, input in a_QIN) { 51 | *out = silk_SAT16(silk_RSHIFT_ROUND(*input, QIN - QOUT)) as i16; 52 | *input = (*out as i32) << (QIN - QOUT); 53 | }); 54 | } else { 55 | azip!((out in a_QOUT, &mut input in a_QIN) { 56 | *out = silk_RSHIFT_ROUND(input, QIN - QOUT) as i16; 57 | }); 58 | }; 59 | } 60 | -------------------------------------------------------------------------------- /upstream-libopus/opus/opus_sources.cmake: -------------------------------------------------------------------------------- 1 | include(opus_functions.cmake) 2 | 3 | get_opus_sources(SILK_SOURCES silk_sources.mk silk_sources) 4 | get_opus_sources(SILK_SOURCES_FLOAT silk_sources.mk silk_sources_float) 5 | get_opus_sources(SILK_SOURCES_FIXED silk_sources.mk silk_sources_fixed) 6 | get_opus_sources(SILK_SOURCES_SSE4_1 silk_sources.mk silk_sources_sse4_1) 7 | get_opus_sources(SILK_SOURCES_FIXED_SSE4_1 silk_sources.mk 8 | silk_sources_fixed_sse4_1) 9 | get_opus_sources(SILK_SOURCES_ARM_NEON_INTR silk_sources.mk 10 | silk_sources_arm_neon_intr) 11 | get_opus_sources(SILK_SOURCES_FIXED_ARM_NEON_INTR silk_sources.mk 12 | silk_sources_fixed_arm_neon_intr) 13 | 14 | get_opus_sources(OPUS_SOURCES opus_sources.mk opus_sources) 15 | get_opus_sources(OPUS_SOURCES_FLOAT opus_sources.mk opus_sources_float) 16 | 17 | get_opus_sources(CELT_SOURCES celt_sources.mk celt_sources) 18 | get_opus_sources(CELT_SOURCES_SSE celt_sources.mk celt_sources_sse) 19 | get_opus_sources(CELT_SOURCES_SSE2 celt_sources.mk celt_sources_sse2) 20 | get_opus_sources(CELT_SOURCES_SSE4_1 celt_sources.mk celt_sources_sse4_1) 21 | get_opus_sources(CELT_SOURCES_ARM celt_sources.mk celt_sources_arm) 22 | get_opus_sources(CELT_SOURCES_ARM_ASM celt_sources.mk celt_sources_arm_asm) 23 | get_opus_sources(CELT_AM_SOURCES_ARM_ASM celt_sources.mk 24 | celt_am_sources_arm_asm) 25 | get_opus_sources(CELT_SOURCES_ARM_NEON_INTR celt_sources.mk 26 | celt_sources_arm_neon_intr) 27 | get_opus_sources(CELT_SOURCES_ARM_NE10 celt_sources.mk celt_sources_arm_ne10) 28 | 29 | get_opus_sources(opus_demo_SOURCES Makefile.am opus_demo_sources) 30 | get_opus_sources(opus_custom_demo_SOURCES Makefile.am opus_custom_demo_sources) 31 | get_opus_sources(opus_compare_SOURCES Makefile.am opus_compare_sources) 32 | get_opus_sources(tests_test_opus_api_SOURCES Makefile.am test_opus_api_sources) 33 | get_opus_sources(tests_test_opus_encode_SOURCES Makefile.am 34 | test_opus_encode_sources) 35 | get_opus_sources(tests_test_opus_decode_SOURCES Makefile.am 36 | test_opus_decode_sources) 37 | get_opus_sources(tests_test_opus_padding_SOURCES Makefile.am 38 | test_opus_padding_sources) 39 | -------------------------------------------------------------------------------- /src/silk/stereo_decode_pred.rs: -------------------------------------------------------------------------------- 1 | use crate::celt::entdec::{ec_dec, ec_dec_icdf}; 2 | use crate::silk::define::STEREO_QUANT_SUB_STEPS; 3 | use crate::silk::macros::silk_SMULWB; 4 | use crate::silk::tables_other::{ 5 | silk_stereo_only_code_mid_iCDF, silk_stereo_pred_joint_iCDF, silk_stereo_pred_quant_Q13, 6 | silk_uniform3_iCDF, silk_uniform5_iCDF, 7 | }; 8 | use crate::silk::SigProc_FIX::SILK_FIX_CONST; 9 | 10 | /// Decode mid/side predictors 11 | /// 12 | /// ```text 13 | /// psRangeDec I/O Compressor data structure 14 | /// pred_Q13[] O Predictors 15 | /// ``` 16 | pub fn silk_stereo_decode_pred(psRangeDec: &mut ec_dec, pred_Q13: &mut [i32; 2]) { 17 | let n = ec_dec_icdf(psRangeDec, &silk_stereo_pred_joint_iCDF, 8) as usize; 18 | 19 | let mut ix: [[usize; 3]; 2] = [[0; 3]; 2]; 20 | ix[0][2] = n / 5; 21 | ix[1][2] = n - 5 * ix[0][2]; 22 | 23 | /* Entropy decoding */ 24 | let mut n = 0; 25 | while n < 2 { 26 | ix[n][0] = ec_dec_icdf(psRangeDec, &silk_uniform3_iCDF, 8) as usize; 27 | ix[n][1] = ec_dec_icdf(psRangeDec, &silk_uniform5_iCDF, 8) as usize; 28 | n += 1; 29 | } 30 | 31 | /* Dequantize */ 32 | let mut n = 0; 33 | while n < 2 { 34 | ix[n][0] += 3 * ix[n][2]; 35 | let low_Q13 = silk_stereo_pred_quant_Q13[ix[n][0]] as i32; 36 | let step_Q13 = silk_SMULWB( 37 | silk_stereo_pred_quant_Q13[ix[n][0] + 1] as i32 - low_Q13, 38 | SILK_FIX_CONST!(0.5 / STEREO_QUANT_SUB_STEPS as f64, 16), 39 | ); 40 | 41 | pred_Q13[n] = low_Q13 + step_Q13 as i16 as i32 * (2 * ix[n][1] + 1) as i16 as i32; 42 | n += 1; 43 | } 44 | 45 | /* Subtract second from first predictor (helps when actually applying these) */ 46 | pred_Q13[0] -= pred_Q13[1]; 47 | } 48 | 49 | /// Decode mid-only flag 50 | /// 51 | /// ```text 52 | /// psRangeDec I/O Compressor data structure 53 | /// decode_only_mid O Flag that only mid channel has been coded 54 | /// ``` 55 | pub fn silk_stereo_decode_mid_only(psRangeDec: &mut ec_dec, decode_only_mid: &mut bool) { 56 | /* Decode flag that only mid channel is coded */ 57 | *decode_only_mid = ec_dec_icdf(psRangeDec, &silk_stereo_only_code_mid_iCDF, 8) != 0; 58 | } 59 | -------------------------------------------------------------------------------- /upstream-libopus/opus/silk/arm/SigProc_FIX_armv4.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (C) 2013 Xiph.Org Foundation and contributors 3 | Copyright (c) 2013 Parrot 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | - Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | - Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 13 | names of specific contributors, may be used to endorse or promote 14 | products derived from this software without specific prior written 15 | permission. 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | POSSIBILITY OF SUCH DAMAGE. 27 | ***********************************************************************/ 28 | 29 | #ifndef SILK_SIGPROC_FIX_ARMv4_H 30 | #define SILK_SIGPROC_FIX_ARMv4_H 31 | 32 | #undef silk_MLA 33 | static OPUS_INLINE opus_int32 silk_MLA_armv4(opus_int32 a, opus_int32 b, 34 | opus_int32 c) 35 | { 36 | opus_int32 res; 37 | __asm__( 38 | "#silk_MLA\n\t" 39 | "mla %0, %1, %2, %3\n\t" 40 | : "=&r"(res) 41 | : "r"(b), "r"(c), "r"(a) 42 | ); 43 | return res; 44 | } 45 | #define silk_MLA(a, b, c) (silk_MLA_armv4(a, b, c)) 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /upstream-libopus/opus/src/mlp.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 Jean-Marc Valin */ 2 | /* 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions 5 | are met: 6 | 7 | - Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 10 | - Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 15 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 16 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 17 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR 18 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 21 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 22 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 23 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef _MLP_H_ 28 | #define _MLP_H_ 29 | 30 | #include "opus_types.h" 31 | 32 | #define WEIGHTS_SCALE (1.f/128) 33 | 34 | #define MAX_NEURONS 32 35 | 36 | typedef struct { 37 | const opus_int8 *bias; 38 | const opus_int8 *input_weights; 39 | int nb_inputs; 40 | int nb_neurons; 41 | int sigmoid; 42 | } DenseLayer; 43 | 44 | typedef struct { 45 | const opus_int8 *bias; 46 | const opus_int8 *input_weights; 47 | const opus_int8 *recurrent_weights; 48 | int nb_inputs; 49 | int nb_neurons; 50 | } GRULayer; 51 | 52 | extern const DenseLayer layer0; 53 | extern const GRULayer layer1; 54 | extern const DenseLayer layer2; 55 | 56 | void compute_dense(const DenseLayer *layer, float *output, const float *input); 57 | 58 | void compute_gru(const GRULayer *gru, float *state, const float *input); 59 | 60 | #endif /* _MLP_H_ */ 61 | -------------------------------------------------------------------------------- /upstream-libopus/opus/doc/build_isobmff.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Copyright (c) 2014 Xiph.Org Foundation and Mozilla Foundation 4 | # 5 | # Redistribution and use in source and binary forms, with or without 6 | # modification, are permitted provided that the following conditions 7 | # are met: 8 | # 9 | # - Redistributions of source code must retain the above copyright 10 | # notice, this list of conditions and the following disclaimer. 11 | # 12 | # - Redistributions in binary form must reproduce the above copyright 13 | # notice, this list of conditions and the following disclaimer in the 14 | # documentation and/or other materials provided with the distribution. 15 | # 16 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 20 | # OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 21 | # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 | # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 24 | # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #Stop on errors 29 | set -e 30 | #Set the CWD to the location of this script 31 | [ -n "${0%/*}" ] && cd "${0%/*}" 32 | 33 | HTML=opus_in_isobmff.html 34 | 35 | echo downloading updates... 36 | CSS=${HTML%%.html}.css 37 | wget -q http://vfrmaniac.fushizen.eu/contents/${HTML} -O ${HTML} 38 | wget -q http://vfrmaniac.fushizen.eu/style.css -O ${CSS} 39 | 40 | echo updating links... 41 | cat ${HTML} | sed -e "s/\\.\\.\\/style.css/${CSS}/" > ${HTML}+ && mv ${HTML}+ ${HTML} 42 | 43 | echo stripping... 44 | cat ${HTML} | sed -e 's///g' > ${HTML}+ && mv ${HTML}+ ${HTML} 45 | cat ${HTML} | sed -e 's/ *$//g' > ${HTML}+ && mv ${HTML}+ ${HTML} 46 | cat ${CSS} | sed -e 's/ *$//g' > ${CSS}+ && mv ${CSS}+ ${CSS} 47 | 48 | 49 | VERSION=$(fgrep Version ${HTML} | sed 's/.*Version \([0-9]\.[0-9]\.[0-9]\).*/\1/') 50 | echo Now at version ${VERSION} 51 | -------------------------------------------------------------------------------- /upstream-libopus/opus/celt/laplace.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2007 CSIRO 2 | Copyright (c) 2007-2009 Xiph.Org Foundation 3 | Written by Jean-Marc Valin */ 4 | /* 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | - Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | - Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 20 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 21 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 24 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #include "entenc.h" 30 | #include "entdec.h" 31 | 32 | /** Encode a value that is assumed to be the realisation of a 33 | Laplace-distributed random process 34 | @param enc Entropy encoder state 35 | @param value Value to encode 36 | @param fs Probability of 0, multiplied by 32768 37 | @param decay Probability of the value +/- 1, multiplied by 16384 38 | */ 39 | void ec_laplace_encode(ec_enc *enc, int *value, unsigned fs, int decay); 40 | 41 | /** Decode a value that is assumed to be the realisation of a 42 | Laplace-distributed random process 43 | @param dec Entropy decoder state 44 | @param fs Probability of 0, multiplied by 32768 45 | @param decay Probability of the value +/- 1, multiplied by 16384 46 | @return Value decoded 47 | */ 48 | int ec_laplace_decode(ec_dec *dec, unsigned fs, int decay); 49 | -------------------------------------------------------------------------------- /upstream-libopus/opus/README.draft: -------------------------------------------------------------------------------- 1 | To build this source code, simply type: 2 | 3 | % make 4 | 5 | If this does not work, or if you want to change the default configuration 6 | (e.g., to compile for a fixed-point architecture), simply edit the options 7 | in the Makefile. 8 | 9 | An up-to-date implementation conforming to this standard is available in a 10 | Git repository at https://git.xiph.org/opus.git or on a website at: 11 | https://opus-codec.org/ 12 | However, although that implementation is expected to remain conformant 13 | with the standard, it is the code in this RFC that shall remain normative. 14 | To build from the git repository instead of using this RFC, follow these 15 | steps: 16 | 17 | 1) Clone the repository (latest implementation of this standard at the time 18 | of publication) 19 | 20 | % git clone https://git.xiph.org/opus.git 21 | % cd opus 22 | 23 | 2) Compile 24 | 25 | % ./autogen.sh 26 | % ./configure 27 | % make 28 | 29 | Once you have compiled the codec, there will be a opus_demo executable in 30 | the top directory. 31 | 32 | Usage: opus_demo [-e] 33 | [options] 34 | opus_demo -d [options] 35 | 36 | 37 | mode: voip | audio | restricted-lowdelay 38 | options: 39 | -e : only runs the encoder (output the bit-stream) 40 | -d : only runs the decoder (reads the bit-stream as input) 41 | -cbr : enable constant bitrate; default: variable bitrate 42 | -cvbr : enable constrained variable bitrate; default: unconstrained 43 | -bandwidth : audio bandwidth (from narrowband to fullband); 44 | default: sampling rate 45 | -framesize <2.5|5|10|20|40|60> : frame size in ms; default: 20 46 | -max_payload : maximum payload size in bytes, default: 1024 47 | -complexity : complexity, 0 (lowest) ... 10 (highest); default: 10 48 | -inbandfec : enable SILK inband FEC 49 | -forcemono : force mono encoding, even for stereo input 50 | -dtx : enable SILK DTX 51 | -loss : simulate packet loss, in percent (0-100); default: 0 52 | 53 | input and output are little endian signed 16-bit PCM files or opus bitstreams 54 | with simple opus_demo proprietary framing. 55 | -------------------------------------------------------------------------------- /src/silk/float/residual_energy_FLP.rs: -------------------------------------------------------------------------------- 1 | use crate::silk::define::MAX_NB_SUBFR; 2 | use crate::silk::float::energy_FLP::silk_energy_FLP; 3 | use crate::silk::float::LPC_analysis_filter_FLP::silk_LPC_analysis_filter_FLP; 4 | 5 | pub unsafe fn silk_residual_energy_FLP( 6 | nrgs: *mut f32, 7 | x: *const f32, 8 | a: *mut [f32; 16], 9 | gains: *const f32, 10 | subfr_length: i32, 11 | nb_subfr: i32, 12 | LPC_order: i32, 13 | ) { 14 | let mut shift: i32 = 0; 15 | let mut LPC_res_ptr: *mut f32 = 0 as *mut f32; 16 | let mut LPC_res: [f32; 192] = [0.; 192]; 17 | LPC_res_ptr = LPC_res.as_mut_ptr().offset(LPC_order as isize); 18 | shift = LPC_order + subfr_length; 19 | silk_LPC_analysis_filter_FLP( 20 | LPC_res.as_mut_ptr(), 21 | (*a.offset(0 as isize)).as_mut_ptr() as *const f32, 22 | x.offset((0 * shift) as isize), 23 | 2 * shift, 24 | LPC_order, 25 | ); 26 | *nrgs.offset(0 as isize) = ((*gains.offset(0 as isize) * *gains.offset(0 as isize)) as f64 27 | * silk_energy_FLP(std::slice::from_raw_parts( 28 | LPC_res_ptr.offset((0 * shift) as isize), 29 | subfr_length as usize, 30 | ))) as f32; 31 | *nrgs.offset(1 as isize) = ((*gains.offset(1 as isize) * *gains.offset(1 as isize)) as f64 32 | * silk_energy_FLP(std::slice::from_raw_parts( 33 | LPC_res_ptr.offset((1 * shift) as isize), 34 | subfr_length as usize, 35 | ))) as f32; 36 | if nb_subfr == MAX_NB_SUBFR as i32 { 37 | silk_LPC_analysis_filter_FLP( 38 | LPC_res.as_mut_ptr(), 39 | (*a.offset(1 as isize)).as_mut_ptr() as *const f32, 40 | x.offset((2 * shift) as isize), 41 | 2 * shift, 42 | LPC_order, 43 | ); 44 | *nrgs.offset(2 as isize) = ((*gains.offset(2 as isize) * *gains.offset(2 as isize)) as f64 45 | * silk_energy_FLP(std::slice::from_raw_parts( 46 | LPC_res_ptr.offset((0 * shift) as isize), 47 | subfr_length as usize, 48 | ))) as f32; 49 | *nrgs.offset(3 as isize) = ((*gains.offset(3 as isize) * *gains.offset(3 as isize)) as f64 50 | * silk_energy_FLP(std::slice::from_raw_parts( 51 | LPC_res_ptr.offset((1 * shift) as isize), 52 | subfr_length as usize, 53 | ))) as f32; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /upstream-libopus/opus/doc/build_oggdraft.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Copyright (c) 2012 Xiph.Org Foundation and Mozilla Corporation 4 | # 5 | # This file is extracted from RFC6716. Please see that RFC for additional 6 | # information. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | # 12 | # - Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # 15 | # - Redistributions in binary form must reproduce the above copyright 16 | # notice, this list of conditions and the following disclaimer in the 17 | # documentation and/or other materials provided with the distribution. 18 | # 19 | # - Neither the name of Internet Society, IETF or IETF Trust, nor the 20 | # names of specific contributors, may be used to endorse or promote 21 | # products derived from this software without specific prior written 22 | # permission. 23 | # 24 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 28 | # OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 29 | # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 30 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 31 | # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 32 | # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 33 | # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 34 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | #Stop on errors 37 | set -e 38 | #Set the CWD to the location of this script 39 | [ -n "${0%/*}" ] && cd "${0%/*}" 40 | 41 | if test -z `which xml2rfc 2> /dev/null`; then 42 | echo "Error: couldn't find xml2rfc." 43 | echo 44 | echo "Please install xml2rfc version 2 or later." 45 | echo "E.g. 'pip install xml2rfc' or follow the instructions" 46 | echo "on http://pypi.python.org/pypi/xml2rfc/ or tools.ietf.org." 47 | exit 1 48 | fi 49 | 50 | echo running xml2rfc 51 | # version 2 syntax 52 | xml2rfc draft-ietf-codec-oggopus.xml --text --html 53 | -------------------------------------------------------------------------------- /upstream-libopus/opus/silk/lin2log.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2011, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions 5 | are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 12 | names of specific contributors, may be used to endorse or promote 13 | products derived from this software without specific prior written 14 | permission. 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #ifdef HAVE_CONFIG_H 29 | #include "config.h" 30 | #endif 31 | 32 | #include "SigProc_FIX.h" 33 | /* Approximation of 128 * log2() (very close inverse of silk_log2lin()) */ 34 | /* Convert input to a log scale */ 35 | opus_int32 silk_lin2log( 36 | const opus_int32 inLin /* I input in linear scale */ 37 | ) 38 | { 39 | opus_int32 lz, frac_Q7; 40 | 41 | silk_CLZ_FRAC( inLin, &lz, &frac_Q7 ); 42 | 43 | /* Piece-wise parabolic approximation */ 44 | return silk_ADD_LSHIFT32( silk_SMLAWB( frac_Q7, silk_MUL( frac_Q7, 128 - frac_Q7 ), 179 ), 31 - lz, 7 ); 45 | } 46 | 47 | -------------------------------------------------------------------------------- /src/silk/tables_other.rs: -------------------------------------------------------------------------------- 1 | use crate::silk::define::{ 2 | OFFSET_UVH_Q10, OFFSET_UVL_Q10, OFFSET_VH_Q10, OFFSET_VL_Q10, TRANSITION_INT_NUM, 3 | TRANSITION_NA, TRANSITION_NB, 4 | }; 5 | 6 | pub static silk_stereo_pred_quant_Q13: [i16; 16] = [ 7 | -13732, -10050, -8266, -7526, -6500, -5000, -2950, -820, 820, 2950, 5000, 6500, 7526, 8266, 8 | 10050, 13732, 9 | ]; 10 | pub static silk_stereo_pred_joint_iCDF: [u8; 25] = [ 11 | 249, 247, 246, 245, 244, 234, 210, 202, 201, 200, 197, 174, 82, 59, 56, 55, 54, 46, 22, 12, 11, 12 | 10, 9, 7, 0, 13 | ]; 14 | pub static silk_stereo_only_code_mid_iCDF: [u8; 2] = [64, 0]; 15 | static silk_LBRR_flags_2_iCDF: [u8; 3] = [203, 150, 0]; 16 | static silk_LBRR_flags_3_iCDF: [u8; 7] = [215, 195, 166, 125, 110, 82, 0]; 17 | pub static silk_LBRR_flags_iCDF_ptr: [&[u8]; 2] = 18 | [&silk_LBRR_flags_2_iCDF, &silk_LBRR_flags_3_iCDF]; 19 | pub static silk_lsb_iCDF: [u8; 2] = [120, 0]; 20 | pub static silk_LTPscale_iCDF: [u8; 3] = [128, 64, 0]; 21 | pub static silk_type_offset_VAD_iCDF: [u8; 4] = [232, 158, 10, 0]; 22 | pub static silk_type_offset_no_VAD_iCDF: [u8; 2] = [230, 0]; 23 | pub static silk_NLSF_interpolation_factor_iCDF: [u8; 5] = [243, 221, 192, 181, 0]; 24 | pub static silk_Quantization_Offsets_Q10: [[i16; 2]; 2] = [ 25 | [OFFSET_UVL_Q10 as i16, OFFSET_UVH_Q10 as i16], 26 | [OFFSET_VL_Q10 as i16, OFFSET_VH_Q10 as i16], 27 | ]; 28 | pub static silk_LTPScales_table_Q14: [i16; 3] = [15565, 12288, 8192]; 29 | pub static silk_uniform3_iCDF: [u8; 3] = [171, 85, 0]; 30 | pub static silk_uniform4_iCDF: [u8; 4] = [192, 128, 64, 0]; 31 | pub static silk_uniform5_iCDF: [u8; 5] = [205, 154, 102, 51, 0]; 32 | pub static silk_uniform6_iCDF: [u8; 6] = [213, 171, 128, 85, 43, 0]; 33 | pub static silk_uniform8_iCDF: [u8; 8] = [224, 192, 160, 128, 96, 64, 32, 0]; 34 | pub static silk_NLSF_EXT_iCDF: [u8; 7] = [100, 40, 16, 7, 3, 1, 0]; 35 | pub static silk_Transition_LP_B_Q28: [[i32; TRANSITION_NB]; TRANSITION_INT_NUM] = [ 36 | [250767114, 501534038, 250767114], 37 | [209867381, 419732057, 209867381], 38 | [170987846, 341967853, 170987846], 39 | [131531482, 263046905, 131531482], 40 | [89306658, 178584282, 89306658], 41 | ]; 42 | pub static silk_Transition_LP_A_Q28: [[i32; TRANSITION_NA]; TRANSITION_INT_NUM] = [ 43 | [506393414, 239854379], 44 | [411067935, 169683996], 45 | [306733530, 116694253], 46 | [185807084, 77959395], 47 | [35497197, 57401098], 48 | ]; 49 | -------------------------------------------------------------------------------- /upstream-libopus/opus/celt/mfrngcod.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2001-2008 Timothy B. Terriberry 2 | Copyright (c) 2008-2009 Xiph.Org Foundation */ 3 | /* 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | - Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | - Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 19 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 22 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 23 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 24 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #if !defined(_mfrngcode_H) 29 | # define _mfrngcode_H (1) 30 | # include "entcode.h" 31 | 32 | /*Constants used by the entropy encoder/decoder.*/ 33 | 34 | /*The number of bits to output at a time.*/ 35 | # define EC_SYM_BITS (8) 36 | /*The total number of bits in each of the state registers.*/ 37 | # define EC_CODE_BITS (32) 38 | /*The maximum symbol value.*/ 39 | # define EC_SYM_MAX ((1U<>EC_SYM_BITS) 46 | /*The number of bits available for the last, partial symbol in the code field.*/ 47 | # define EC_CODE_EXTRA ((EC_CODE_BITS-2)%EC_SYM_BITS+1) 48 | #endif 49 | -------------------------------------------------------------------------------- /upstream-libopus/opus/scripts/rnn_train.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | from __future__ import print_function 4 | 5 | from keras.models import Sequential 6 | from keras.models import Model 7 | from keras.layers import Input 8 | from keras.layers import Dense 9 | from keras.layers import LSTM 10 | from keras.layers import GRU 11 | from keras.layers import SimpleRNN 12 | from keras.layers import Dropout 13 | from keras import losses 14 | import h5py 15 | 16 | from keras import backend as K 17 | import numpy as np 18 | 19 | def binary_crossentrop2(y_true, y_pred): 20 | return K.mean(2*K.abs(y_true-0.5) * K.binary_crossentropy(y_pred, y_true), axis=-1) 21 | 22 | print('Build model...') 23 | #model = Sequential() 24 | #model.add(Dense(16, activation='tanh', input_shape=(None, 25))) 25 | #model.add(GRU(12, dropout=0.0, recurrent_dropout=0.0, activation='tanh', recurrent_activation='sigmoid', return_sequences=True)) 26 | #model.add(Dense(2, activation='sigmoid')) 27 | 28 | main_input = Input(shape=(None, 25), name='main_input') 29 | x = Dense(16, activation='tanh')(main_input) 30 | x = GRU(12, dropout=0.1, recurrent_dropout=0.1, activation='tanh', recurrent_activation='sigmoid', return_sequences=True)(x) 31 | x = Dense(2, activation='sigmoid')(x) 32 | model = Model(inputs=main_input, outputs=x) 33 | 34 | batch_size = 64 35 | 36 | print('Loading data...') 37 | with h5py.File('features.h5', 'r') as hf: 38 | all_data = hf['features'][:] 39 | print('done.') 40 | 41 | window_size = 1500 42 | 43 | nb_sequences = len(all_data)/window_size 44 | print(nb_sequences, ' sequences') 45 | x_train = all_data[:nb_sequences*window_size, :-2] 46 | x_train = np.reshape(x_train, (nb_sequences, window_size, 25)) 47 | 48 | y_train = np.copy(all_data[:nb_sequences*window_size, -2:]) 49 | y_train = np.reshape(y_train, (nb_sequences, window_size, 2)) 50 | 51 | all_data = 0; 52 | x_train = x_train.astype('float32') 53 | y_train = y_train.astype('float32') 54 | 55 | print(len(x_train), 'train sequences. x shape =', x_train.shape, 'y shape = ', y_train.shape) 56 | 57 | # try using different optimizers and different optimizer configs 58 | model.compile(loss=binary_crossentrop2, 59 | optimizer='adam', 60 | metrics=['binary_accuracy']) 61 | 62 | print('Train...') 63 | model.fit(x_train, y_train, 64 | batch_size=batch_size, 65 | epochs=200, 66 | validation_data=(x_train, y_train)) 67 | model.save("newweights.hdf5") 68 | -------------------------------------------------------------------------------- /src/silk/stereo_quant_pred.rs: -------------------------------------------------------------------------------- 1 | pub mod typedef_h { 2 | pub const silk_int32_MAX: i32 = i32::MAX; 3 | } 4 | pub use self::typedef_h::silk_int32_MAX; 5 | use crate::silk::define::{STEREO_QUANT_SUB_STEPS, STEREO_QUANT_TAB_SIZE}; 6 | use crate::silk::tables_other::silk_stereo_pred_quant_Q13; 7 | 8 | pub unsafe fn silk_stereo_quant_pred(pred_Q13: *mut i32, ix: *mut [i8; 3]) { 9 | let mut i: i32 = 0; 10 | let mut j: i32 = 0; 11 | let mut n: i32 = 0; 12 | let mut low_Q13: i32 = 0; 13 | let mut step_Q13: i32 = 0; 14 | let mut lvl_Q13: i32 = 0; 15 | let mut err_min_Q13: i32 = 0; 16 | let mut err_Q13: i32 = 0; 17 | let mut quant_pred_Q13: i32 = 0; 18 | n = 0; 19 | while n < 2 { 20 | err_min_Q13 = silk_int32_MAX; 21 | i = 0; 22 | 's_18: while i < STEREO_QUANT_TAB_SIZE - 1 { 23 | low_Q13 = silk_stereo_pred_quant_Q13[i as usize] as i32; 24 | step_Q13 = ((silk_stereo_pred_quant_Q13[(i + 1) as usize] as i32 - low_Q13) as i64 25 | * (0.5f64 / 5 as f64 * ((1) << 16) as f64 + 0.5f64) as i32 as i16 as i64 26 | >> 16) as i32; 27 | j = 0; 28 | while j < STEREO_QUANT_SUB_STEPS { 29 | lvl_Q13 = low_Q13 + step_Q13 as i16 as i32 * (2 * j + 1) as i16 as i32; 30 | err_Q13 = if *pred_Q13.offset(n as isize) - lvl_Q13 > 0 { 31 | *pred_Q13.offset(n as isize) - lvl_Q13 32 | } else { 33 | -(*pred_Q13.offset(n as isize) - lvl_Q13) 34 | }; 35 | if !(err_Q13 < err_min_Q13) { 36 | break 's_18; 37 | } 38 | err_min_Q13 = err_Q13; 39 | quant_pred_Q13 = lvl_Q13; 40 | (*ix.offset(n as isize))[0 as usize] = i as i8; 41 | (*ix.offset(n as isize))[1 as usize] = j as i8; 42 | j += 1; 43 | } 44 | i += 1; 45 | } 46 | (*ix.offset(n as isize))[2 as usize] = 47 | ((*ix.offset(n as isize))[0 as usize] as i32 / 3) as i8; 48 | let ref mut fresh0 = (*ix.offset(n as isize))[0 as usize]; 49 | *fresh0 = (*fresh0 as i32 - (*ix.offset(n as isize))[2 as usize] as i32 * 3) as i8; 50 | *pred_Q13.offset(n as isize) = quant_pred_Q13; 51 | n += 1; 52 | } 53 | let ref mut fresh1 = *pred_Q13.offset(0 as isize); 54 | *fresh1 -= *pred_Q13.offset(1 as isize); 55 | } 56 | -------------------------------------------------------------------------------- /upstream-libopus/opus/silk/mips/sigproc_fix_mipsr1.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2011, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions 5 | are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 12 | names of specific contributors, may be used to endorse or promote 13 | products derived from this software without specific prior written 14 | permission. 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #ifndef SILK_SIGPROC_FIX_MIPSR1_H 29 | #define SILK_SIGPROC_FIX_MIPSR1_H 30 | 31 | #undef silk_SAT16 32 | static inline short int silk_SAT16(int a) 33 | { 34 | int c; 35 | c = __builtin_mips_shll_s_w(a, 16); 36 | c = c>>16; 37 | 38 | return c; 39 | } 40 | 41 | #undef silk_LSHIFT_SAT32 42 | static inline int silk_LSHIFT_SAT32(int a, int shift) 43 | { 44 | int r; 45 | 46 | r = __builtin_mips_shll_s_w(a, shift); 47 | 48 | return r; 49 | } 50 | 51 | #undef silk_RSHIFT_ROUND 52 | static inline int silk_RSHIFT_ROUND(int a, int shift) 53 | { 54 | int r; 55 | 56 | r = __builtin_mips_shra_r_w(a, shift); 57 | return r; 58 | } 59 | 60 | #endif /* SILK_SIGPROC_FIX_MIPSR1_H */ 61 | -------------------------------------------------------------------------------- /upstream-libopus/opus/src/tansig_table.h: -------------------------------------------------------------------------------- 1 | /* This file is auto-generated by gen_tables */ 2 | 3 | static const float tansig_table[201] = { 4 | 0.000000f, 0.039979f, 0.079830f, 0.119427f, 0.158649f, 5 | 0.197375f, 0.235496f, 0.272905f, 0.309507f, 0.345214f, 6 | 0.379949f, 0.413644f, 0.446244f, 0.477700f, 0.507977f, 7 | 0.537050f, 0.564900f, 0.591519f, 0.616909f, 0.641077f, 8 | 0.664037f, 0.685809f, 0.706419f, 0.725897f, 0.744277f, 9 | 0.761594f, 0.777888f, 0.793199f, 0.807569f, 0.821040f, 10 | 0.833655f, 0.845456f, 0.856485f, 0.866784f, 0.876393f, 11 | 0.885352f, 0.893698f, 0.901468f, 0.908698f, 0.915420f, 12 | 0.921669f, 0.927473f, 0.932862f, 0.937863f, 0.942503f, 13 | 0.946806f, 0.950795f, 0.954492f, 0.957917f, 0.961090f, 14 | 0.964028f, 0.966747f, 0.969265f, 0.971594f, 0.973749f, 15 | 0.975743f, 0.977587f, 0.979293f, 0.980869f, 0.982327f, 16 | 0.983675f, 0.984921f, 0.986072f, 0.987136f, 0.988119f, 17 | 0.989027f, 0.989867f, 0.990642f, 0.991359f, 0.992020f, 18 | 0.992631f, 0.993196f, 0.993718f, 0.994199f, 0.994644f, 19 | 0.995055f, 0.995434f, 0.995784f, 0.996108f, 0.996407f, 20 | 0.996682f, 0.996937f, 0.997172f, 0.997389f, 0.997590f, 21 | 0.997775f, 0.997946f, 0.998104f, 0.998249f, 0.998384f, 22 | 0.998508f, 0.998623f, 0.998728f, 0.998826f, 0.998916f, 23 | 0.999000f, 0.999076f, 0.999147f, 0.999213f, 0.999273f, 24 | 0.999329f, 0.999381f, 0.999428f, 0.999472f, 0.999513f, 25 | 0.999550f, 0.999585f, 0.999617f, 0.999646f, 0.999673f, 26 | 0.999699f, 0.999722f, 0.999743f, 0.999763f, 0.999781f, 27 | 0.999798f, 0.999813f, 0.999828f, 0.999841f, 0.999853f, 28 | 0.999865f, 0.999875f, 0.999885f, 0.999893f, 0.999902f, 29 | 0.999909f, 0.999916f, 0.999923f, 0.999929f, 0.999934f, 30 | 0.999939f, 0.999944f, 0.999948f, 0.999952f, 0.999956f, 31 | 0.999959f, 0.999962f, 0.999965f, 0.999968f, 0.999970f, 32 | 0.999973f, 0.999975f, 0.999977f, 0.999978f, 0.999980f, 33 | 0.999982f, 0.999983f, 0.999984f, 0.999986f, 0.999987f, 34 | 0.999988f, 0.999989f, 0.999990f, 0.999990f, 0.999991f, 35 | 0.999992f, 0.999992f, 0.999993f, 0.999994f, 0.999994f, 36 | 0.999994f, 0.999995f, 0.999995f, 0.999996f, 0.999996f, 37 | 0.999996f, 0.999997f, 0.999997f, 0.999997f, 0.999997f, 38 | 0.999997f, 0.999998f, 0.999998f, 0.999998f, 0.999998f, 39 | 0.999998f, 0.999998f, 0.999999f, 0.999999f, 0.999999f, 40 | 0.999999f, 0.999999f, 0.999999f, 0.999999f, 0.999999f, 41 | 0.999999f, 0.999999f, 0.999999f, 0.999999f, 0.999999f, 42 | 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 43 | 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 44 | 1.000000f, 45 | }; 46 | -------------------------------------------------------------------------------- /upstream-libopus/opus/celt/fixed_c6x.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2008 CSIRO */ 2 | /** 3 | @file fixed_c6x.h 4 | @brief Fixed-point operations for the TI C6x DSP family 5 | */ 6 | /* 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | - Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | - Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 22 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef FIXED_C6X_H 32 | #define FIXED_C6X_H 33 | 34 | #undef MULT16_16SU 35 | #define MULT16_16SU(a,b) _mpysu(a,b) 36 | 37 | #undef MULT_16_16 38 | #define MULT_16_16(a,b) _mpy(a,b) 39 | 40 | #define celt_ilog2(x) (30 - _norm(x)) 41 | #define OVERRIDE_CELT_ILOG2 42 | 43 | #undef MULT16_32_Q15 44 | #define MULT16_32_Q15(a,b) (_mpylill(a, b) >> 15) 45 | 46 | #if 0 47 | #include "dsplib.h" 48 | 49 | #undef MAX16 50 | #define MAX16(a,b) _max(a,b) 51 | 52 | #undef MIN16 53 | #define MIN16(a,b) _min(a,b) 54 | 55 | #undef MAX32 56 | #define MAX32(a,b) _lmax(a,b) 57 | 58 | #undef MIN32 59 | #define MIN32(a,b) _lmin(a,b) 60 | 61 | #undef VSHR32 62 | #define VSHR32(a, shift) _lshl(a,-(shift)) 63 | 64 | #undef MULT16_16_Q15 65 | #define MULT16_16_Q15(a,b) (_smpy(a,b)) 66 | 67 | #define celt_maxabs16(x, len) MAX32(EXTEND32(maxval((DATA *)x, len)),-EXTEND32(minval((DATA *)x, len))) 68 | #define OVERRIDE_CELT_MAXABS16 69 | 70 | #endif /* FIXED_C6X_H */ 71 | -------------------------------------------------------------------------------- /upstream-libopus/opus/celt/celt_lpc.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2009-2010 Xiph.Org Foundation 2 | Written by Jean-Marc Valin */ 3 | /* 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | - Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | - Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 19 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 22 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 23 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 24 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef PLC_H 29 | #define PLC_H 30 | 31 | #include "arch.h" 32 | #include "cpu_support.h" 33 | 34 | #if defined(OPUS_X86_MAY_HAVE_SSE4_1) 35 | #include "x86/celt_lpc_sse.h" 36 | #endif 37 | 38 | #define LPC_ORDER 24 39 | 40 | void _celt_lpc(opus_val16 *_lpc, const opus_val32 *ac, int p); 41 | 42 | void celt_fir_c( 43 | const opus_val16 *x, 44 | const opus_val16 *num, 45 | opus_val16 *y, 46 | int N, 47 | int ord, 48 | int arch); 49 | 50 | #if !defined(OVERRIDE_CELT_FIR) 51 | #define celt_fir(x, num, y, N, ord, arch) \ 52 | (celt_fir_c(x, num, y, N, ord, arch)) 53 | #endif 54 | 55 | void celt_iir(const opus_val32 *x, 56 | const opus_val16 *den, 57 | opus_val32 *y, 58 | int N, 59 | int ord, 60 | opus_val16 *mem, 61 | int arch); 62 | 63 | int _celt_autocorr(const opus_val16 *x, opus_val32 *ac, 64 | const opus_val16 *window, int overlap, int lag, int n, int arch); 65 | 66 | #endif /* PLC_H */ 67 | -------------------------------------------------------------------------------- /upstream-libopus/opus/silk/float/scale_vector_FLP.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2011, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions 5 | are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 12 | names of specific contributors, may be used to endorse or promote 13 | products derived from this software without specific prior written 14 | permission. 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #ifdef HAVE_CONFIG_H 29 | #include "config.h" 30 | #endif 31 | 32 | #include "SigProc_FLP.h" 33 | 34 | /* multiply a vector by a constant */ 35 | void silk_scale_vector_FLP( 36 | silk_float *data1, 37 | silk_float gain, 38 | opus_int dataSize 39 | ) 40 | { 41 | opus_int i, dataSize4; 42 | 43 | /* 4x unrolled loop */ 44 | dataSize4 = dataSize & 0xFFFC; 45 | for( i = 0; i < dataSize4; i += 4 ) { 46 | data1[ i + 0 ] *= gain; 47 | data1[ i + 1 ] *= gain; 48 | data1[ i + 2 ] *= gain; 49 | data1[ i + 3 ] *= gain; 50 | } 51 | 52 | /* any remaining elements */ 53 | for( ; i < dataSize; i++ ) { 54 | data1[ i ] *= gain; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /upstream-libopus/opus/celt/x86/celt_lpc_sse.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2014, Cisco Systems, INC 2 | Written by XiangMingZhu WeiZhou MinPeng YanWang 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | - Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | - Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 19 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 22 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 23 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 24 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef CELT_LPC_SSE_H 29 | #define CELT_LPC_SSE_H 30 | 31 | #ifdef HAVE_CONFIG_H 32 | #include "config.h" 33 | #endif 34 | 35 | #if defined(OPUS_X86_MAY_HAVE_SSE4_1) && defined(FIXED_POINT) 36 | #define OVERRIDE_CELT_FIR 37 | 38 | void celt_fir_sse4_1( 39 | const opus_val16 *x, 40 | const opus_val16 *num, 41 | opus_val16 *y, 42 | int N, 43 | int ord, 44 | int arch); 45 | 46 | #if defined(OPUS_X86_PRESUME_SSE4_1) 47 | #define celt_fir(x, num, y, N, ord, arch) \ 48 | ((void)arch, celt_fir_sse4_1(x, num, y, N, ord, arch)) 49 | 50 | #else 51 | 52 | extern void (*const CELT_FIR_IMPL[OPUS_ARCHMASK + 1])( 53 | const opus_val16 *x, 54 | const opus_val16 *num, 55 | opus_val16 *y, 56 | int N, 57 | int ord, 58 | int arch); 59 | 60 | # define celt_fir(x, num, y, N, ord, arch) \ 61 | ((*CELT_FIR_IMPL[(arch) & OPUS_ARCHMASK])(x, num, y, N, ord, arch)) 62 | 63 | #endif 64 | #endif 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /upstream-libopus/opus/silk/float/bwexpander_FLP.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2011, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions 5 | are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 12 | names of specific contributors, may be used to endorse or promote 13 | products derived from this software without specific prior written 14 | permission. 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #ifdef HAVE_CONFIG_H 29 | #include "config.h" 30 | #endif 31 | 32 | #include "SigProc_FLP.h" 33 | 34 | /* Chirp (bw expand) LP AR filter */ 35 | void silk_bwexpander_FLP( 36 | silk_float *ar, /* I/O AR filter to be expanded (without leading 1) */ 37 | const opus_int d, /* I length of ar */ 38 | const silk_float chirp /* I chirp factor (typically in range (0..1) ) */ 39 | ) 40 | { 41 | opus_int i; 42 | silk_float cfac = chirp; 43 | 44 | for( i = 0; i < d - 1; i++ ) { 45 | ar[ i ] *= cfac; 46 | cfac *= chirp; 47 | } 48 | ar[ d - 1 ] *= cfac; 49 | } 50 | -------------------------------------------------------------------------------- /src/silk/float/find_LTP_FLP.rs: -------------------------------------------------------------------------------- 1 | use crate::silk::float::corrMatrix_FLP::{silk_corrMatrix_FLP, silk_corrVector_FLP}; 2 | use crate::silk::float::energy_FLP::silk_energy_FLP; 3 | use crate::silk::tuning_parameters::LTP_CORR_INV_MAX; 4 | use crate::util::nalgebra::MatrixViewRMut; 5 | use nalgebra::{Const, Dim, DimMul, DimProd, Dyn, VectorView}; 6 | 7 | const LTP_ORDER: usize = crate::silk::define::LTP_ORDER as usize; 8 | type LTP_ORDER = Const<{ LTP_ORDER }>; 9 | 10 | /// LTP analysis 11 | /// 12 | /// ```text 13 | /// XX[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ] /* O Weight for LTP quantization 14 | /// xX[ MAX_NB_SUBFR * LTP_ORDER ] /* O Weight for LTP quantization 15 | /// r_ptr[] /* I LPC residual 16 | /// lag[ MAX_NB_SUBFR ] /* I LTP lags 17 | /// subfr_length /* I Subframe length 18 | /// nb_subfr /* I number of subframes 19 | /// ``` 20 | pub fn silk_find_LTP_FLP( 21 | XX: &mut MatrixViewRMut, LTP_ORDER>, 22 | xX: &mut MatrixViewRMut, 23 | r: &[f32], 24 | mut r_ptr: usize, 25 | lag: &VectorView, 26 | subfr_length: usize, 27 | ) where 28 | NbSubfr: Dim, 29 | NbSubfr: DimMul, 30 | { 31 | let (nb_subfr_x_order, _) = XX.shape_generic(); 32 | let (nb_subfr, _) = xX.shape_generic(); 33 | 34 | assert_eq!(nb_subfr_x_order.value(), nb_subfr.value() * LTP_ORDER); 35 | assert_eq!(lag.shape().0, nb_subfr.value()); 36 | 37 | for k in 0..nb_subfr.value() { 38 | let r_frame = VectorView::::from_slice(&r[r_ptr..], subfr_length); 39 | let lag_frame = VectorView::::from_slice( 40 | &r[r_ptr - lag[k] as usize - LTP_ORDER / 2..], 41 | subfr_length + LTP_ORDER - 1, 42 | ); 43 | 44 | let mut XX_ptr = XX.fixed_view_mut::<{ LTP_ORDER }, { LTP_ORDER }>(k * LTP_ORDER, 0); 45 | let mut xX_ptr = xX.fixed_view_mut::<1, { LTP_ORDER }>(k, 0); 46 | 47 | silk_corrMatrix_FLP(&lag_frame, Dyn(subfr_length), &mut XX_ptr); 48 | silk_corrVector_FLP(&lag_frame, &r_frame, &mut xX_ptr); 49 | 50 | let xx = silk_energy_FLP(&r[r_ptr..][..subfr_length + LTP_ORDER]) as f32; 51 | let temp = 1.0 / xx.max(LTP_CORR_INV_MAX * 0.5 * (XX_ptr[(0, 0)] + XX_ptr[(4, 4)]) + 1.0); 52 | XX_ptr *= temp; 53 | xX_ptr *= temp; 54 | 55 | r_ptr += subfr_length; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /upstream-libopus/opus/training/rnn_dump.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | from __future__ import print_function 4 | 5 | from keras.models import Sequential 6 | from keras.models import Model 7 | from keras.layers import Input 8 | from keras.layers import Dense 9 | from keras.layers import LSTM 10 | from keras.layers import GRU 11 | from keras.models import load_model 12 | from keras import backend as K 13 | import sys 14 | 15 | import numpy as np 16 | 17 | def printVector(f, vector, name): 18 | v = np.reshape(vector, (-1)); 19 | #print('static const float ', name, '[', len(v), '] = \n', file=f) 20 | f.write('static const opus_int8 {}[{}] = {{\n '.format(name, len(v))) 21 | for i in range(0, len(v)): 22 | f.write('{}'.format(max(-128,min(127,int(round(128*v[i])))))) 23 | if (i!=len(v)-1): 24 | f.write(',') 25 | else: 26 | break; 27 | if (i%8==7): 28 | f.write("\n ") 29 | else: 30 | f.write(" ") 31 | #print(v, file=f) 32 | f.write('\n};\n\n') 33 | return; 34 | 35 | def binary_crossentrop2(y_true, y_pred): 36 | return K.mean(2*K.abs(y_true-0.5) * K.binary_crossentropy(y_pred, y_true), axis=-1) 37 | 38 | 39 | #model = load_model(sys.argv[1], custom_objects={'binary_crossentrop2': binary_crossentrop2}) 40 | main_input = Input(shape=(None, 25), name='main_input') 41 | x = Dense(32, activation='tanh')(main_input) 42 | x = GRU(24, activation='tanh', recurrent_activation='sigmoid', return_sequences=True)(x) 43 | x = Dense(2, activation='sigmoid')(x) 44 | model = Model(inputs=main_input, outputs=x) 45 | model.load_weights(sys.argv[1]) 46 | 47 | weights = model.get_weights() 48 | 49 | f = open(sys.argv[2], 'w') 50 | 51 | f.write('/*This file is automatically generated from a Keras model*/\n\n') 52 | f.write('#ifdef HAVE_CONFIG_H\n#include "config.h"\n#endif\n\n#include "mlp.h"\n\n') 53 | 54 | printVector(f, weights[0], 'layer0_weights') 55 | printVector(f, weights[1], 'layer0_bias') 56 | printVector(f, weights[2], 'layer1_weights') 57 | printVector(f, weights[3], 'layer1_recur_weights') 58 | printVector(f, weights[4], 'layer1_bias') 59 | printVector(f, weights[5], 'layer2_weights') 60 | printVector(f, weights[6], 'layer2_bias') 61 | 62 | f.write('const DenseLayer layer0 = {\n layer0_bias,\n layer0_weights,\n 25, 32, 0\n};\n\n') 63 | f.write('const GRULayer layer1 = {\n layer1_bias,\n layer1_weights,\n layer1_recur_weights,\n 32, 24\n};\n\n') 64 | f.write('const DenseLayer layer2 = {\n layer2_bias,\n layer2_weights,\n 24, 2, 1\n};\n\n') 65 | 66 | f.close() 67 | -------------------------------------------------------------------------------- /src/silk/pitch_est_tables.rs: -------------------------------------------------------------------------------- 1 | pub const PE_NB_CBKS_STAGE3_MIN: i32 = 16; 2 | pub const PE_NB_CBKS_STAGE3_MID: i32 = 24; 3 | pub const PE_NB_CBKS_STAGE3_MAX: usize = 34; 4 | pub const PE_NB_CBKS_STAGE3_10MS: usize = 12; 5 | pub const PE_NB_STAGE3_LAGS: i32 = 5; 6 | pub const PE_NB_CBKS_STAGE2_EXT: usize = 11; 7 | pub const PE_NB_CBKS_STAGE2_10MS: usize = 3; 8 | pub const PE_MAX_NB_SUBFR: usize = 4; 9 | pub const PE_MAX_NB_SUBFR_OVER_2: usize = PE_MAX_NB_SUBFR / 2; 10 | pub const PE_SUBFR_LENGTH_MS: i32 = 5; 11 | pub const PE_LTP_MEM_LENGTH_MS: i32 = 4 * PE_SUBFR_LENGTH_MS; 12 | pub const PE_MAX_LAG_MS: i32 = 18; 13 | pub const PE_MIN_LAG_MS: i32 = 2; 14 | pub const PE_NB_CBKS_STAGE2: i32 = 3; 15 | 16 | pub const SILK_PE_MIN_COMPLEX: i32 = 0; 17 | pub const SILK_PE_MID_COMPLEX: i32 = 1; 18 | pub const SILK_PE_MAX_COMPLEX: usize = 2; 19 | 20 | pub const PE_SHORTLAG_BIAS: f32 = 0.2f32; 21 | pub const PE_PREVLAG_BIAS: f32 = 0.2f32; 22 | pub const PE_FLATCONTOUR_BIAS: f32 = 0.05f32; 23 | 24 | pub static silk_CB_lags_stage2_10_ms: [i8; PE_MAX_NB_SUBFR / 2 * 3] = [0, 1, 0, 0, 0, 1]; 25 | pub static silk_CB_lags_stage3_10_ms: [i8; PE_MAX_NB_SUBFR / 2 * 12] = [ 26 | 0, 0, 1, -1, 1, -1, 2, -2, 2, -2, 3, -3, 0, 1, 0, 1, -1, 2, -1, 2, -2, 3, -2, 3, 27 | ]; 28 | pub static silk_Lag_range_stage3_10_ms: [[i8; 2]; PE_MAX_NB_SUBFR / 2] = [[-3, 7], [-2, 7]]; 29 | pub static silk_CB_lags_stage2: [i8; PE_MAX_NB_SUBFR * PE_NB_CBKS_STAGE2_EXT] = [ 30 | 0, 2, -1, -1, -1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 31 | 0, 0, 0, -1, 2, 1, 0, 1, 1, 0, 0, -1, -1, 32 | ]; 33 | pub static silk_CB_lags_stage3: [i8; PE_MAX_NB_SUBFR * PE_NB_CBKS_STAGE3_MAX] = [ 34 | 0, 0, 1, -1, 0, 1, -1, 0, -1, 1, -2, 2, -2, -2, 2, -3, 2, 3, -3, -4, 3, -4, 4, 4, -5, 5, -6, 35 | -5, 6, -7, 6, 5, 8, -9, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, -1, 1, 0, 0, 1, -1, 0, 1, -1, -1, 1, -1, 36 | 2, 1, -1, 2, -2, -2, 2, -2, 2, 2, 3, -3, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, -1, 1, 0, 0, 37 | 2, 1, -1, 2, -1, -1, 2, -1, 2, 2, -1, 3, -2, -2, -2, 3, 0, 1, 0, 0, 1, 0, 1, -1, 2, -1, 2, -1, 38 | 2, 3, -2, 3, -2, -2, 4, 4, -3, 5, -3, -4, 6, -4, 6, 5, -5, 8, -6, -5, -7, 9, 39 | ]; 40 | pub static silk_Lag_range_stage3: [[[i8; 2]; PE_MAX_NB_SUBFR]; SILK_PE_MAX_COMPLEX + 1] = [ 41 | [[-5, 8], [-1, 6], [-1, 6], [-4, 10]], 42 | [[-6, 10], [-2, 6], [-1, 6], [-5, 10]], 43 | [[-9, 12], [-3, 7], [-2, 7], [-7, 13]], 44 | ]; 45 | pub static silk_nb_cbk_searchs_stage3: [i8; SILK_PE_MAX_COMPLEX + 1] = [ 46 | PE_NB_CBKS_STAGE3_MIN as i8, 47 | PE_NB_CBKS_STAGE3_MID as i8, 48 | PE_NB_CBKS_STAGE3_MAX as i8, 49 | ]; 50 | -------------------------------------------------------------------------------- /upstream-libopus/opus/silk/init_decoder.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2011, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions 5 | are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 12 | names of specific contributors, may be used to endorse or promote 13 | products derived from this software without specific prior written 14 | permission. 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #ifdef HAVE_CONFIG_H 29 | #include "config.h" 30 | #endif 31 | 32 | #include "main.h" 33 | 34 | /************************/ 35 | /* Init Decoder State */ 36 | /************************/ 37 | opus_int silk_init_decoder( 38 | silk_decoder_state *psDec /* I/O Decoder state pointer */ 39 | ) 40 | { 41 | /* Clear the entire encoder state, except anything copied */ 42 | silk_memset( psDec, 0, sizeof( silk_decoder_state ) ); 43 | 44 | /* Used to deactivate LSF interpolation */ 45 | psDec->first_frame_after_reset = 1; 46 | psDec->prev_gain_Q16 = 65536; 47 | psDec->arch = opus_select_arch(); 48 | 49 | /* Reset CNG state */ 50 | silk_CNG_Reset( psDec ); 51 | 52 | /* Reset PLC state */ 53 | silk_PLC_Reset( psDec ); 54 | 55 | return(0); 56 | } 57 | 58 | -------------------------------------------------------------------------------- /upstream-libopus/opus/silk/inner_prod_aligned.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2011, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions 5 | are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 12 | names of specific contributors, may be used to endorse or promote 13 | products derived from this software without specific prior written 14 | permission. 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #ifdef HAVE_CONFIG_H 29 | #include "config.h" 30 | #endif 31 | 32 | #include "SigProc_FIX.h" 33 | 34 | opus_int32 silk_inner_prod_aligned_scale( 35 | const opus_int16 *const inVec1, /* I input vector 1 */ 36 | const opus_int16 *const inVec2, /* I input vector 2 */ 37 | const opus_int scale, /* I number of bits to shift */ 38 | const opus_int len /* I vector lengths */ 39 | ) 40 | { 41 | opus_int i; 42 | opus_int32 sum = 0; 43 | for( i = 0; i < len; i++ ) { 44 | sum = silk_ADD_RSHIFT32( sum, silk_SMULBB( inVec1[ i ], inVec2[ i ] ), scale ); 45 | } 46 | return sum; 47 | } 48 | -------------------------------------------------------------------------------- /upstream-libopus/opus/silk/float/regularize_correlations_FLP.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2011, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions 5 | are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 12 | names of specific contributors, may be used to endorse or promote 13 | products derived from this software without specific prior written 14 | permission. 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #ifdef HAVE_CONFIG_H 29 | #include "config.h" 30 | #endif 31 | 32 | #include "main_FLP.h" 33 | 34 | /* Add noise to matrix diagonal */ 35 | void silk_regularize_correlations_FLP( 36 | silk_float *XX, /* I/O Correlation matrices */ 37 | silk_float *xx, /* I/O Correlation values */ 38 | const silk_float noise, /* I Noise energy to add */ 39 | const opus_int D /* I Dimension of XX */ 40 | ) 41 | { 42 | opus_int i; 43 | 44 | for( i = 0; i < D; i++ ) { 45 | matrix_ptr( &XX[ 0 ], i, i, D ) += noise; 46 | } 47 | xx[ 0 ] += noise; 48 | } 49 | -------------------------------------------------------------------------------- /upstream-libopus/opus/silk/arm/SigProc_FIX_armv5e.h: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2011, Skype Limited. All rights reserved. 3 | Copyright (c) 2013 Parrot 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | - Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | - Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 13 | names of specific contributors, may be used to endorse or promote 14 | products derived from this software without specific prior written 15 | permission. 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | POSSIBILITY OF SUCH DAMAGE. 27 | ***********************************************************************/ 28 | 29 | #ifndef SILK_SIGPROC_FIX_ARMv5E_H 30 | #define SILK_SIGPROC_FIX_ARMv5E_H 31 | 32 | #undef silk_SMULTT 33 | static OPUS_INLINE opus_int32 silk_SMULTT_armv5e(opus_int32 a, opus_int32 b) 34 | { 35 | opus_int32 res; 36 | __asm__( 37 | "#silk_SMULTT\n\t" 38 | "smultt %0, %1, %2\n\t" 39 | : "=r"(res) 40 | : "%r"(a), "r"(b) 41 | ); 42 | return res; 43 | } 44 | #define silk_SMULTT(a, b) (silk_SMULTT_armv5e(a, b)) 45 | 46 | #undef silk_SMLATT 47 | static OPUS_INLINE opus_int32 silk_SMLATT_armv5e(opus_int32 a, opus_int32 b, 48 | opus_int32 c) 49 | { 50 | opus_int32 res; 51 | __asm__( 52 | "#silk_SMLATT\n\t" 53 | "smlatt %0, %1, %2, %3\n\t" 54 | : "=r"(res) 55 | : "%r"(b), "r"(c), "r"(a) 56 | ); 57 | return res; 58 | } 59 | #define silk_SMLATT(a, b, c) (silk_SMLATT_armv5e(a, b, c)) 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /upstream-libopus/opus/silk/float/scale_copy_vector_FLP.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2011, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions 5 | are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 12 | names of specific contributors, may be used to endorse or promote 13 | products derived from this software without specific prior written 14 | permission. 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #ifdef HAVE_CONFIG_H 29 | #include "config.h" 30 | #endif 31 | 32 | #include "SigProc_FLP.h" 33 | 34 | /* copy and multiply a vector by a constant */ 35 | void silk_scale_copy_vector_FLP( 36 | silk_float *data_out, 37 | const silk_float *data_in, 38 | silk_float gain, 39 | opus_int dataSize 40 | ) 41 | { 42 | opus_int i, dataSize4; 43 | 44 | /* 4x unrolled loop */ 45 | dataSize4 = dataSize & 0xFFFC; 46 | for( i = 0; i < dataSize4; i += 4 ) { 47 | data_out[ i + 0 ] = gain * data_in[ i + 0 ]; 48 | data_out[ i + 1 ] = gain * data_in[ i + 1 ]; 49 | data_out[ i + 2 ] = gain * data_in[ i + 2 ]; 50 | data_out[ i + 3 ] = gain * data_in[ i + 3 ]; 51 | } 52 | 53 | /* any remaining elements */ 54 | for( ; i < dataSize; i++ ) { 55 | data_out[ i ] = gain * data_in[ i ]; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | on: [ push, pull_request ] 2 | 3 | name: Run opus tests 4 | 5 | jobs: 6 | test-basic: 7 | runs-on: ${{ matrix.os }} 8 | strategy: 9 | matrix: 10 | # TODO: test 32-bit targets 11 | # TODO: test aarch64 targets 12 | os: 13 | - ubuntu-latest 14 | - macos-13 # x86 15 | - macos-14 # arm64 16 | - windows-latest 17 | profile: [ release, dev ] 18 | fail-fast: false 19 | 20 | steps: 21 | - uses: actions/checkout@v2 22 | 23 | - name: Install toolchain 24 | uses: actions-rs/toolchain@v1 25 | with: 26 | toolchain: stable 27 | override: true 28 | profile: minimal 29 | 30 | - name: Execute tests 31 | uses: actions-rs/cargo@v1 32 | with: 33 | command: test 34 | args: --all --profile=${{ matrix.profile }} -- --nocapture 35 | test-vectors: 36 | runs-on: ${{ matrix.os }} 37 | strategy: 38 | matrix: 39 | os: 40 | - ubuntu-latest 41 | - macos-13 # x86 42 | - macos-14 # arm64 43 | - windows-latest 44 | fail-fast: false 45 | 46 | steps: 47 | - uses: actions/checkout@v2 48 | 49 | - name: Install Rust toolchain 50 | uses: actions-rs/toolchain@v1 51 | with: 52 | toolchain: stable 53 | override: true 54 | profile: minimal 55 | 56 | - name: Setup clang 57 | # macOS has clang already 58 | if: runner.os != 'macos' 59 | uses: aminya/setup-cpp@v1 60 | with: 61 | compiler: llvm 62 | 63 | - name: Build (release) 64 | uses: actions-rs/cargo@v1 65 | with: 66 | command: build 67 | args: --release 68 | 69 | - name: Download test vectors from IETF site 70 | run: | 71 | curl https://www.ietf.org/proceedings/98/slides/materials-98-codec-opus-newvectors-00.tar.gz -o materials-98-codec-opus-newvectors-00.tar.gz 72 | tar -xzf materials-98-codec-opus-newvectors-00.tar.gz 73 | # the vectors are now extracted to opus_newvectors 74 | 75 | - name: Run test vectors 76 | uses: actions-rs/cargo@v1 77 | with: 78 | command: run 79 | args: --release -p unsafe-libopus-tools --bin run_vectors2 -- opus_newvectors 80 | 81 | # TODO: upload a dump? 800M feels a bit too much for gha though.. 82 | # - name: Upload logs 83 | # if: always() # always upload logs, even if the test fails 84 | # uses: actions/upload-artifact@v3 85 | # with: 86 | # name: test-logs 87 | # path: logs_*.txt 88 | -------------------------------------------------------------------------------- /upstream-libopus/opus/celt/cpu_support.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2010 Xiph.Org Foundation 2 | * Copyright (c) 2013 Parrot */ 3 | /* 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | - Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | - Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 19 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 22 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 23 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 24 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef CPU_SUPPORT_H 29 | #define CPU_SUPPORT_H 30 | 31 | #include "opus_types.h" 32 | #include "opus_defines.h" 33 | 34 | #if defined(OPUS_HAVE_RTCD) && \ 35 | (defined(OPUS_ARM_ASM) || defined(OPUS_ARM_MAY_HAVE_NEON_INTR)) 36 | #include "arm/armcpu.h" 37 | 38 | /* We currently support 4 ARM variants: 39 | * arch[0] -> ARMv4 40 | * arch[1] -> ARMv5E 41 | * arch[2] -> ARMv6 42 | * arch[3] -> NEON 43 | */ 44 | #define OPUS_ARCHMASK 3 45 | 46 | #elif (defined(OPUS_X86_MAY_HAVE_SSE) && !defined(OPUS_X86_PRESUME_SSE)) || \ 47 | (defined(OPUS_X86_MAY_HAVE_SSE2) && !defined(OPUS_X86_PRESUME_SSE2)) || \ 48 | (defined(OPUS_X86_MAY_HAVE_SSE4_1) && !defined(OPUS_X86_PRESUME_SSE4_1)) || \ 49 | (defined(OPUS_X86_MAY_HAVE_AVX) && !defined(OPUS_X86_PRESUME_AVX)) 50 | 51 | #include "x86/x86cpu.h" 52 | /* We currently support 5 x86 variants: 53 | * arch[0] -> non-sse 54 | * arch[1] -> sse 55 | * arch[2] -> sse2 56 | * arch[3] -> sse4.1 57 | * arch[4] -> avx 58 | */ 59 | #define OPUS_ARCHMASK 7 60 | int opus_select_arch(void); 61 | 62 | #else 63 | #define OPUS_ARCHMASK 0 64 | 65 | static OPUS_INLINE int opus_select_arch(void) 66 | { 67 | return 0; 68 | } 69 | #endif 70 | #endif 71 | -------------------------------------------------------------------------------- /upstream-libopus/opus/silk/float/energy_FLP.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2011, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions 5 | are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 12 | names of specific contributors, may be used to endorse or promote 13 | products derived from this software without specific prior written 14 | permission. 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #ifdef HAVE_CONFIG_H 29 | #include "config.h" 30 | #endif 31 | 32 | #include "SigProc_FLP.h" 33 | 34 | /* sum of squares of a silk_float array, with result as double */ 35 | double silk_energy_FLP( 36 | const silk_float *data, 37 | opus_int dataSize 38 | ) 39 | { 40 | opus_int i; 41 | double result; 42 | 43 | /* 4x unrolled loop */ 44 | result = 0.0; 45 | for( i = 0; i < dataSize - 3; i += 4 ) { 46 | result += data[ i + 0 ] * (double)data[ i + 0 ] + 47 | data[ i + 1 ] * (double)data[ i + 1 ] + 48 | data[ i + 2 ] * (double)data[ i + 2 ] + 49 | data[ i + 3 ] * (double)data[ i + 3 ]; 50 | } 51 | 52 | /* add any remaining products */ 53 | for( ; i < dataSize; i++ ) { 54 | result += data[ i ] * (double)data[ i ]; 55 | } 56 | 57 | silk_assert( result >= 0.0 ); 58 | return result; 59 | } 60 | -------------------------------------------------------------------------------- /upstream-libopus/opus/silk/bwexpander_32.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2011, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions 5 | are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 12 | names of specific contributors, may be used to endorse or promote 13 | products derived from this software without specific prior written 14 | permission. 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #ifdef HAVE_CONFIG_H 29 | #include "config.h" 30 | #endif 31 | 32 | #include "SigProc_FIX.h" 33 | 34 | /* Chirp (bandwidth expand) LP AR filter */ 35 | void silk_bwexpander_32( 36 | opus_int32 *ar, /* I/O AR filter to be expanded (without leading 1) */ 37 | const opus_int d, /* I Length of ar */ 38 | opus_int32 chirp_Q16 /* I Chirp factor in Q16 */ 39 | ) 40 | { 41 | opus_int i; 42 | opus_int32 chirp_minus_one_Q16 = chirp_Q16 - 65536; 43 | 44 | for( i = 0; i < d - 1; i++ ) { 45 | ar[ i ] = silk_SMULWW( chirp_Q16, ar[ i ] ); 46 | chirp_Q16 += silk_RSHIFT_ROUND( silk_MUL( chirp_Q16, chirp_minus_one_Q16 ), 16 ); 47 | } 48 | ar[ d - 1 ] = silk_SMULWW( chirp_Q16, ar[ d - 1 ] ); 49 | } 50 | 51 | -------------------------------------------------------------------------------- /upstream-libopus/opus/silk/float/inner_product_FLP.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2011, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions 5 | are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 12 | names of specific contributors, may be used to endorse or promote 13 | products derived from this software without specific prior written 14 | permission. 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #ifdef HAVE_CONFIG_H 29 | #include "config.h" 30 | #endif 31 | 32 | #include "SigProc_FLP.h" 33 | 34 | /* inner product of two silk_float arrays, with result as double */ 35 | double silk_inner_product_FLP( 36 | const silk_float *data1, 37 | const silk_float *data2, 38 | opus_int dataSize 39 | ) 40 | { 41 | opus_int i; 42 | double result; 43 | 44 | /* 4x unrolled loop */ 45 | result = 0.0; 46 | for( i = 0; i < dataSize - 3; i += 4 ) { 47 | result += data1[ i + 0 ] * (double)data2[ i + 0 ] + 48 | data1[ i + 1 ] * (double)data2[ i + 1 ] + 49 | data1[ i + 2 ] * (double)data2[ i + 2 ] + 50 | data1[ i + 3 ] * (double)data2[ i + 3 ]; 51 | } 52 | 53 | /* add any remaining products */ 54 | for( ; i < dataSize; i++ ) { 55 | result += data1[ i ] * (double)data2[ i ]; 56 | } 57 | 58 | return result; 59 | } 60 | -------------------------------------------------------------------------------- /upstream-libopus/opus/celt/arm/fft_arm.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2015 Xiph.Org Foundation 2 | Written by Viswanath Puttagunta */ 3 | /** 4 | @file fft_arm.h 5 | @brief ARM Neon Intrinsic optimizations for fft using NE10 library 6 | */ 7 | 8 | /* 9 | Redistribution and use in source and binary forms, with or without 10 | modification, are permitted provided that the following conditions 11 | are met: 12 | 13 | - Redistributions of source code must retain the above copyright 14 | notice, this list of conditions and the following disclaimer. 15 | 16 | - Redistributions in binary form must reproduce the above copyright 17 | notice, this list of conditions and the following disclaimer in the 18 | documentation and/or other materials provided with the distribution. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 24 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | 34 | #if !defined(FFT_ARM_H) 35 | #define FFT_ARM_H 36 | 37 | #include "kiss_fft.h" 38 | 39 | #if defined(HAVE_ARM_NE10) 40 | 41 | int opus_fft_alloc_arm_neon(kiss_fft_state *st); 42 | void opus_fft_free_arm_neon(kiss_fft_state *st); 43 | 44 | void opus_fft_neon(const kiss_fft_state *st, 45 | const kiss_fft_cpx *fin, 46 | kiss_fft_cpx *fout); 47 | 48 | void opus_ifft_neon(const kiss_fft_state *st, 49 | const kiss_fft_cpx *fin, 50 | kiss_fft_cpx *fout); 51 | 52 | #if !defined(OPUS_HAVE_RTCD) 53 | #define OVERRIDE_OPUS_FFT (1) 54 | 55 | #define opus_fft_alloc_arch(_st, arch) \ 56 | ((void)(arch), opus_fft_alloc_arm_neon(_st)) 57 | 58 | #define opus_fft_free_arch(_st, arch) \ 59 | ((void)(arch), opus_fft_free_arm_neon(_st)) 60 | 61 | #define opus_fft(_st, _fin, _fout, arch) \ 62 | ((void)(arch), opus_fft_neon(_st, _fin, _fout)) 63 | 64 | #define opus_ifft(_st, _fin, _fout, arch) \ 65 | ((void)(arch), opus_ifft_neon(_st, _fin, _fout)) 66 | 67 | #endif /* OPUS_HAVE_RTCD */ 68 | 69 | #endif /* HAVE_ARM_NE10 */ 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /src/silk/ana_filt_bank_1.rs: -------------------------------------------------------------------------------- 1 | pub mod typedef_h { 2 | pub const silk_int16_MIN: i32 = i16::MIN as i32; 3 | pub const silk_int16_MAX: i32 = i16::MAX as i32; 4 | } 5 | 6 | pub use self::typedef_h::{silk_int16_MAX, silk_int16_MIN}; 7 | 8 | static mut A_fb1_20: i16 = ((5394) << 1) as i16; 9 | static mut A_fb1_21: i16 = -(24290) as i16; 10 | pub unsafe fn silk_ana_filt_bank_1( 11 | in_0: *const i16, 12 | S: *mut i32, 13 | outL: *mut i16, 14 | outH: *mut i16, 15 | N: i32, 16 | ) { 17 | let mut k: i32 = 0; 18 | let N2: i32 = N >> 1; 19 | let mut in32: i32 = 0; 20 | let mut X: i32 = 0; 21 | let mut Y: i32 = 0; 22 | let mut out_1: i32 = 0; 23 | let mut out_2: i32 = 0; 24 | k = 0; 25 | while k < N2 { 26 | in32 = ((*in_0.offset((2 * k) as isize) as i32 as u32) << 10) as i32; 27 | Y = in32 - *S.offset(0 as isize); 28 | X = (Y as i64 + (Y as i64 * A_fb1_21 as i64 >> 16)) as i32; 29 | out_1 = *S.offset(0 as isize) + X; 30 | *S.offset(0 as isize) = in32 + X; 31 | in32 = ((*in_0.offset((2 * k + 1) as isize) as i32 as u32) << 10) as i32; 32 | Y = in32 - *S.offset(1 as isize); 33 | X = (Y as i64 * A_fb1_20 as i64 >> 16) as i32; 34 | out_2 = *S.offset(1 as isize) + X; 35 | *S.offset(1 as isize) = in32 + X; 36 | *outL.offset(k as isize) = (if (if 11 == 1 { 37 | (out_2 + out_1 >> 1) + (out_2 + out_1 & 1) 38 | } else { 39 | (out_2 + out_1 >> 11 - 1) + 1 >> 1 40 | }) > silk_int16_MAX 41 | { 42 | silk_int16_MAX 43 | } else if (if 11 == 1 { 44 | (out_2 + out_1 >> 1) + (out_2 + out_1 & 1) 45 | } else { 46 | (out_2 + out_1 >> 11 - 1) + 1 >> 1 47 | }) < silk_int16_MIN 48 | { 49 | silk_int16_MIN 50 | } else if 11 == 1 { 51 | (out_2 + out_1 >> 1) + (out_2 + out_1 & 1) 52 | } else { 53 | (out_2 + out_1 >> 11 - 1) + 1 >> 1 54 | }) as i16; 55 | *outH.offset(k as isize) = (if (if 11 == 1 { 56 | (out_2 - out_1 >> 1) + (out_2 - out_1 & 1) 57 | } else { 58 | (out_2 - out_1 >> 11 - 1) + 1 >> 1 59 | }) > silk_int16_MAX 60 | { 61 | silk_int16_MAX 62 | } else if (if 11 == 1 { 63 | (out_2 - out_1 >> 1) + (out_2 - out_1 & 1) 64 | } else { 65 | (out_2 - out_1 >> 11 - 1) + 1 >> 1 66 | }) < silk_int16_MIN 67 | { 68 | silk_int16_MIN 69 | } else if 11 == 1 { 70 | (out_2 - out_1 >> 1) + (out_2 - out_1 & 1) 71 | } else { 72 | (out_2 - out_1 >> 11 - 1) + 1 >> 1 73 | }) as i16; 74 | k += 1; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /upstream-libopus/opus/celt/modes.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2007-2008 CSIRO 2 | Copyright (c) 2007-2009 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 | #ifndef MODES_H 31 | #define MODES_H 32 | 33 | #include "opus_types.h" 34 | #include "celt.h" 35 | #include "arch.h" 36 | #include "mdct.h" 37 | #include "entenc.h" 38 | #include "entdec.h" 39 | 40 | #define MAX_PERIOD 1024 41 | 42 | typedef struct { 43 | int size; 44 | const opus_int16 *index; 45 | const unsigned char *bits; 46 | const unsigned char *caps; 47 | } PulseCache; 48 | 49 | /** Mode definition (opaque) 50 | @brief Mode definition 51 | */ 52 | struct OpusCustomMode { 53 | opus_int32 Fs; 54 | int overlap; 55 | 56 | int nbEBands; 57 | int effEBands; 58 | opus_val16 preemph[4]; 59 | const opus_int16 *eBands; /**< Definition for each "pseudo-critical band" */ 60 | 61 | int maxLM; 62 | int nbShortMdcts; 63 | int shortMdctSize; 64 | 65 | int nbAllocVectors; /**< Number of lines in the matrix below */ 66 | const unsigned char *allocVectors; /**< Number of bits in each band for several rates */ 67 | const opus_int16 *logN; 68 | 69 | const opus_val16 *window; 70 | mdct_lookup mdct; 71 | PulseCache cache; 72 | }; 73 | 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /upstream-libopus/opus/silk/float/k2a_FLP.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2011, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions 5 | are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 12 | names of specific contributors, may be used to endorse or promote 13 | products derived from this software without specific prior written 14 | permission. 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #ifdef HAVE_CONFIG_H 29 | #include "config.h" 30 | #endif 31 | 32 | #include "SigProc_FLP.h" 33 | 34 | /* step up function, converts reflection coefficients to prediction coefficients */ 35 | void silk_k2a_FLP( 36 | silk_float *A, /* O prediction coefficients [order] */ 37 | const silk_float *rc, /* I reflection coefficients [order] */ 38 | opus_int32 order /* I prediction order */ 39 | ) 40 | { 41 | opus_int k, n; 42 | silk_float rck, tmp1, tmp2; 43 | 44 | for( k = 0; k < order; k++ ) { 45 | rck = rc[ k ]; 46 | for( n = 0; n < (k + 1) >> 1; n++ ) { 47 | tmp1 = A[ n ]; 48 | tmp2 = A[ k - n - 1 ]; 49 | A[ n ] = tmp1 + tmp2 * rck; 50 | A[ k - n - 1 ] = tmp2 + tmp1 * rck; 51 | } 52 | A[ k ] = -rck; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /upstream-libopus/opus/silk/float/autocorrelation_FLP.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2011, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions 5 | are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 12 | names of specific contributors, may be used to endorse or promote 13 | products derived from this software without specific prior written 14 | permission. 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #ifdef HAVE_CONFIG_H 29 | #include "config.h" 30 | #endif 31 | 32 | #include "typedef.h" 33 | #include "SigProc_FLP.h" 34 | 35 | /* compute autocorrelation */ 36 | void silk_autocorrelation_FLP( 37 | silk_float *results, /* O result (length correlationCount) */ 38 | const silk_float *inputData, /* I input data to correlate */ 39 | opus_int inputDataSize, /* I length of input */ 40 | opus_int correlationCount /* I number of correlation taps to compute */ 41 | ) 42 | { 43 | opus_int i; 44 | 45 | if( correlationCount > inputDataSize ) { 46 | correlationCount = inputDataSize; 47 | } 48 | 49 | for( i = 0; i < correlationCount; i++ ) { 50 | results[ i ] = (silk_float)silk_inner_product_FLP( inputData, inputData + i, inputDataSize - i ); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /upstream-libopus/opus/silk/tables_gain.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2011, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions 5 | are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 12 | names of specific contributors, may be used to endorse or promote 13 | products derived from this software without specific prior written 14 | permission. 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #ifdef HAVE_CONFIG_H 29 | #include "config.h" 30 | #endif 31 | 32 | #include "tables.h" 33 | 34 | #ifdef __cplusplus 35 | extern "C" 36 | { 37 | #endif 38 | 39 | const opus_uint8 silk_gain_iCDF[ 3 ][ N_LEVELS_QGAIN / 8 ] = 40 | { 41 | { 42 | 224, 112, 44, 15, 3, 2, 1, 0 43 | }, 44 | { 45 | 254, 237, 192, 132, 70, 23, 4, 0 46 | }, 47 | { 48 | 255, 252, 226, 155, 61, 11, 2, 0 49 | } 50 | }; 51 | 52 | const opus_uint8 silk_delta_gain_iCDF[ MAX_DELTA_GAIN_QUANT - MIN_DELTA_GAIN_QUANT + 1 ] = { 53 | 250, 245, 234, 203, 71, 50, 42, 38, 54 | 35, 33, 31, 29, 28, 27, 26, 25, 55 | 24, 23, 22, 21, 20, 19, 18, 17, 56 | 16, 15, 14, 13, 12, 11, 10, 9, 57 | 8, 7, 6, 5, 4, 3, 2, 1, 58 | 0 59 | }; 60 | 61 | #ifdef __cplusplus 62 | } 63 | #endif 64 | -------------------------------------------------------------------------------- /upstream-libopus/opus/silk/interpolate.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2011, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions 5 | are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 12 | names of specific contributors, may be used to endorse or promote 13 | products derived from this software without specific prior written 14 | permission. 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #ifdef HAVE_CONFIG_H 29 | #include "config.h" 30 | #endif 31 | 32 | #include "main.h" 33 | 34 | /* Interpolate two vectors */ 35 | void silk_interpolate( 36 | opus_int16 xi[ MAX_LPC_ORDER ], /* O interpolated vector */ 37 | const opus_int16 x0[ MAX_LPC_ORDER ], /* I first vector */ 38 | const opus_int16 x1[ MAX_LPC_ORDER ], /* I second vector */ 39 | const opus_int ifact_Q2, /* I interp. factor, weight on 2nd vector */ 40 | const opus_int d /* I number of parameters */ 41 | ) 42 | { 43 | opus_int i; 44 | 45 | celt_assert( ifact_Q2 >= 0 ); 46 | celt_assert( ifact_Q2 <= 4 ); 47 | 48 | for( i = 0; i < d; i++ ) { 49 | xi[ i ] = (opus_int16)silk_ADD_RSHIFT( x0[ i ], silk_SMULBB( x1[ i ] - x0[ i ], ifact_Q2 ), 2 ); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /upstream-libopus/opus/celt/arm/armcpu.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2010 Xiph.Org Foundation 2 | * Copyright (c) 2013 Parrot */ 3 | /* 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | - Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | - Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 19 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 22 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 23 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 24 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #if !defined(ARMCPU_H) 29 | # define ARMCPU_H 30 | 31 | # if defined(OPUS_ARM_MAY_HAVE_EDSP) 32 | # define MAY_HAVE_EDSP(name) name ## _edsp 33 | # else 34 | # define MAY_HAVE_EDSP(name) name ## _c 35 | # endif 36 | 37 | # if defined(OPUS_ARM_MAY_HAVE_MEDIA) 38 | # define MAY_HAVE_MEDIA(name) name ## _media 39 | # else 40 | # define MAY_HAVE_MEDIA(name) MAY_HAVE_EDSP(name) 41 | # endif 42 | 43 | # if defined(OPUS_ARM_MAY_HAVE_NEON) 44 | # define MAY_HAVE_NEON(name) name ## _neon 45 | # else 46 | # define MAY_HAVE_NEON(name) MAY_HAVE_MEDIA(name) 47 | # endif 48 | 49 | # if defined(OPUS_ARM_PRESUME_EDSP) 50 | # define PRESUME_EDSP(name) name ## _edsp 51 | # else 52 | # define PRESUME_EDSP(name) name ## _c 53 | # endif 54 | 55 | # if defined(OPUS_ARM_PRESUME_MEDIA) 56 | # define PRESUME_MEDIA(name) name ## _media 57 | # else 58 | # define PRESUME_MEDIA(name) PRESUME_EDSP(name) 59 | # endif 60 | 61 | # if defined(OPUS_ARM_PRESUME_NEON) 62 | # define PRESUME_NEON(name) name ## _neon 63 | # else 64 | # define PRESUME_NEON(name) PRESUME_MEDIA(name) 65 | # endif 66 | 67 | # if defined(OPUS_HAVE_RTCD) 68 | int opus_select_arch(void); 69 | 70 | #define OPUS_ARCH_ARM_V4 (0) 71 | #define OPUS_ARCH_ARM_EDSP (1) 72 | #define OPUS_ARCH_ARM_MEDIA (2) 73 | #define OPUS_ARCH_ARM_NEON (3) 74 | 75 | # endif 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /src/silk/resampler/rom.rs: -------------------------------------------------------------------------------- 1 | pub const RESAMPLER_DOWN_ORDER_FIR2: usize = 36; 2 | pub const RESAMPLER_DOWN_ORDER_FIR1: usize = 24; 3 | pub const RESAMPLER_DOWN_ORDER_FIR0: usize = 18; 4 | pub const RESAMPLER_ORDER_FIR_12: usize = 8; 5 | 6 | /* Tables for 2x downsampler */ 7 | pub const silk_resampler_down2_0: i16 = 9872; 8 | pub const silk_resampler_down2_1: i16 = (39809 - 65536) as i16; 9 | 10 | /* Tables for 2x upsampler, high quality */ 11 | pub const silk_resampler_up2_hq_0: [i16; 3] = [1746, 14986, (39083 - 65536) as i16]; 12 | pub const silk_resampler_up2_hq_1: [i16; 3] = [6854, 25769, (55542 - 65536) as i16]; 13 | 14 | /* Matlab code for the notch filter coefficients: */ 15 | /* B = [1, 0.147, 1]; A = [1, 0.107, 0.89]; G = 0.93; freqz(G * B, A, 2^14, 16e3); axis([0, 8000, -10, 1]) */ 16 | /* fprintf('\t%6d, %6d, %6d, %6d\n', round(B(2)*2^16), round(-A(2)*2^16), round((1-A(3))*2^16), round(G*2^15)) */ 17 | /* const opus_int16 silk_resampler_up2_hq_notch[ 4 ] = { 9634, -7012, 7209, 30474 }; */ 18 | 19 | /* Tables with IIR and FIR coefficients for fractional downsamplers (123 Words) */ 20 | 21 | pub static silk_Resampler_3_4_COEFS: [i16; 29] = [ 22 | -20694, -13867, -49, 64, 17, -157, 353, -496, 163, 11047, 22205, -39, 6, 91, -170, 186, 23, 23 | -896, 6336, 19928, -19, -36, 102, -89, -24, 328, -951, 2568, 15909, 24 | ]; 25 | pub static silk_Resampler_2_3_COEFS: [i16; 20] = [ 26 | -14457, -14019, 64, 128, -122, 36, 310, -768, 584, 9267, 17733, 12, 128, 18, -142, 288, -117, 27 | -865, 4123, 14459, 28 | ]; 29 | pub static silk_Resampler_1_2_COEFS: [i16; 14] = [ 30 | 616, -14323, -10, 39, 58, -46, -84, 120, 184, -315, -541, 1284, 5380, 9024, 31 | ]; 32 | pub static silk_Resampler_1_3_COEFS: [i16; 20] = [ 33 | 16102, -15162, -13, 0, 20, 26, 5, -31, -43, -4, 65, 90, 7, -157, -248, -44, 593, 1583, 2612, 34 | 3271, 35 | ]; 36 | pub static silk_Resampler_1_4_COEFS: [i16; 20] = [ 37 | 22500, -15099, 3, -14, -20, -15, 2, 25, 37, 25, -16, -71, -107, -79, 50, 292, 623, 982, 1288, 38 | 1464, 39 | ]; 40 | pub static silk_Resampler_1_6_COEFS: [i16; 20] = [ 41 | 27540, -15257, 17, 12, 8, 1, -10, -22, -30, -32, -22, 3, 44, 100, 168, 243, 317, 381, 429, 455, 42 | ]; 43 | pub static silk_Resampler_2_3_COEFS_LQ: [i16; 6] = [-2797, -6507, 4697, 10739, 1567, 8276]; 44 | 45 | /* Table with interplation fractions of 1/24, 3/24, ..., 23/24 */ 46 | pub static silk_resampler_frac_FIR_12: [[i16; 4]; 12] = [ 47 | [189, -600, 617, 30567], 48 | [117, -159, -1070, 29704], 49 | [52, 221, -2392, 28276], 50 | [-4, 529, -3350, 26341], 51 | [-48, 758, -3956, 23973], 52 | [-80, 905, -4235, 21254], 53 | [-99, 972, -4222, 18278], 54 | [-107, 967, -3957, 15143], 55 | [-103, 896, -3487, 11950], 56 | [-91, 773, -2865, 8798], 57 | [-71, 611, -2143, 5784], 58 | [-46, 425, -1375, 2996], 59 | ]; 60 | -------------------------------------------------------------------------------- /upstream-libopus/opus/silk/fixed/regularize_correlations_FIX.c: -------------------------------------------------------------------------------- 1 | /*********************************************************************** 2 | Copyright (c) 2006-2011, Skype Limited. All rights reserved. 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions 5 | are met: 6 | - Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | - Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | - Neither the name of Internet Society, IETF or IETF Trust, nor the 12 | names of specific contributors, may be used to endorse or promote 13 | products derived from this software without specific prior written 14 | permission. 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | POSSIBILITY OF SUCH DAMAGE. 26 | ***********************************************************************/ 27 | 28 | #ifdef HAVE_CONFIG_H 29 | #include "config.h" 30 | #endif 31 | 32 | #include "main_FIX.h" 33 | 34 | /* Add noise to matrix diagonal */ 35 | void silk_regularize_correlations_FIX( 36 | opus_int32 *XX, /* I/O Correlation matrices */ 37 | opus_int32 *xx, /* I/O Correlation values */ 38 | opus_int32 noise, /* I Noise to add */ 39 | opus_int D /* I Dimension of XX */ 40 | ) 41 | { 42 | opus_int i; 43 | for( i = 0; i < D; i++ ) { 44 | matrix_ptr( &XX[ 0 ], i, i, D ) = silk_ADD32( matrix_ptr( &XX[ 0 ], i, i, D ), noise ); 45 | } 46 | xx[ 0 ] += noise; 47 | } 48 | --------------------------------------------------------------------------------