fork/rust-sdks
git clone https://git.julia.blue/fork/rust-sdks
2e4d385
livekit/livekit-ffi@0.13.0
1/* SoX Resampler Library Copyright (c) 2007-16 robs@users.sourceforge.net 2* Licence for this file: LGPL v2.1 See LICENCE for details. */ 3 4#if !definedsoxr_cr_included 5#define soxr_cr_included 6 7#define FIFO_SIZE_T int 8#include "fifo.h" 9 10typedef void real ;/* float or double */ 11struct stage ; 12typedef void (* stage_fn_t )(struct stage * input ,fifo_t * output ); 13typedef struct half_fir_info { 14int num_coefs ; 15real const * coefs ; 16stage_fn_t fn ,dfn ; 17float att ; 18}half_fir_info_t ; 19typedef struct {float scalar ;stage_fn_t fn ;}poly_fir1_t ; 20typedef struct {float beta ;poly_fir1_t interp [3 ];}poly_fir_t ; 21 22#define U100_l 42 23#define MULT32 (65536. * 65536.) 24 25/* Conceptually: coef_p is &coefs[num_phases][fir_len][interp_order+1]: */ 26#define coef (coef_p ,interp_order ,fir_len ,phase_num ,coef_interp_num ,fir_coef_num ) (coef_p)[\ 27 (fir_len) * ((interp_order) + 1) * (phase_num) + \ 28 ((interp_order) + 1) * (fir_coef_num) + \ 29 ((interp_order) - (coef_interp_num))] 30 31/* Conceptually: coef_p is &coefs[num_phases][fir_len/4][interp_order+1][4]: */ 32#define coef4 (coef_p ,interp_order ,fir_len ,phase_num ,coef_interp_num ,fir_coef_num ) (coef_p)[\ 33 (fir_len) * ((interp_order) + 1) * (phase_num) + \ 34 ((interp_order) + 1) * ((fir_coef_num) & ~3) + \ 35 4 * ((interp_order) - (coef_interp_num)) + \ 36 ((fir_coef_num) & 3)] 37 38typedef union {/* Int64 in parts */ 39#if HAVE_BIGENDIAN 40struct {int32_t ms ;uint32_t ls ;}parts ; 41#else 42struct {uint32_t ls ;int32_t ms ;}parts ; 43#endif 44int64_t all ; 45}int64p_t ; 46 47typedef union {/* Uint64 in parts */ 48#if HAVE_BIGENDIAN 49struct {uint32_t ms ,ls ;}parts ; 50#else 51struct {uint32_t ls ,ms ;}parts ; 52#endif 53uint64_t all ; 54}uint64p_t ; 55 56typedef struct { 57int dft_length ,num_taps ,post_peak ; 58void * dft_forward_setup ,* dft_backward_setup ; 59real * coefs ; 60}dft_filter_t ; 61 62typedef struct {/* So generated filter coefs may be shared between channels */ 63real * poly_fir_coefs ; 64dft_filter_t dft_filter [2 ]; 65}rate_shared_t ; 66 67typedef double float_step_t ;/* Or long double or __float128. */ 68 69typedef union {/* Fixed point arithmetic */ 70struct {uint64p_t ls ;int64p_t ms ;}fix ;/* Hi-prec has ~96 bits. */ 71float_step_t flt ; 72}step_t ; 73 74#define integer fix.ms.parts.ms 75#define fraction fix.ms.parts.ls 76#define whole fix.ms.all 77 78#define CORE_DBL 1 79#define CORE_SIMD_POLY 2 80#define CORE_SIMD_HALF 4 81#define CORE_SIMD_DFT 8 82#define LOG2_SIZEOF_REAL (core_flags ) (2 + ((core_flags) & 1)) 83 84typedef int core_flags_t ; 85 86#if definedSOXR_LIB 87#include "rdft_t.h" 88#else 89typedef void fn_t ; 90#endif 91 92typedef struct stage { 93int num ; 94 95/* Common to all stage types: */ 96core_flags_t core_flags ; 97stage_fn_t fn ; 98fifo_t fifo ; 99int pre ;/* Number of past samples to store */ 100int pre_post ;/* pre + number of future samples to store */ 101int preload ;/* Number of zero samples to pre-load the fifo */ 102double out_in_ratio ;/* For buffer management. */ 103int input_size ; 104bool is_input ; 105 106/* For a stage with variable (run-time generated) filter coefs: */ 107fn_t const * rdft_cb ; 108rate_shared_t * shared ; 109unsigned dft_filter_num ;/* Which, if any, of the 2 DFT filters to use */ 110real * dft_scratch ; 111float * dft_out ; 112real const * coefs ; 113 114/* For a stage with variable L/M: */ 115step_t at ,step ; 116bool use_hi_prec_clock ; 117int L ,remM ; 118int n ,phase_bits ,block_len ; 119double mult ,phase0 ; 120}stage_t ; 121 122#define stage_occupancy (s ) max(0, fifo_occupancy(&(s)->fifo) - (s)->pre_post) 123#define stage_read_p (s ) ((sample_t *)fifo_read_ptr(&(s)->fifo) + (s)->pre) 124 125#define lq_bw0 (1385/2048.)/* ~.67625, FP exact. */ 126 127typedef enum {rolloff_small ,rolloff_medium ,rolloff_none }rolloff_t ; 128 129typedef struct { 130void * (* alloc )(size_t ); 131void * (* calloc )(size_t ,size_t ); 132void (* free )(void * ); 133}alloc_t ; 134 135typedef struct { 136alloc_t mem ; 137half_fir_info_t const * half_firs ; 138size_t half_firs_len ; 139half_fir_info_t const * doub_firs ; 140size_t doub_firs_len ; 141stage_fn_t cubic_stage_fn ; 142poly_fir_t const * poly_firs ; 143fn_t * rdft_cb ; 144}cr_core_t ; 145 146typedef struct rate rate_t ; 147struct rate { 148cr_core_t const * core ; 149double io_ratio ; 150int64_t samples_in ,samples_out ; 151int num_stages ,flushing ; 152stage_t * stages ; 153}; 154 155#if definedSOXR_LIB 156 157#include "soxr.h" 158 159char const * _soxr_init ( 160rate_t * const p ,/* Per audio channel. */ 161rate_shared_t * const shared ,/* Between channels (undergoing same rate change)*/ 162double const io_ratio ,/* Input rate divided by output rate. */ 163soxr_quality_spec_t const * const q_spec , 164soxr_runtime_spec_t const * const r_spec , 165double multiplier ,/* Linear gain to apply during conversion. 1 */ 166cr_core_t const * const core , 167core_flags_t const ); 168 169void _soxr_process (struct rate * p ,size_t olen ); 170real * _soxr_input (struct rate * p ,real const * samples ,size_t n ); 171real const * _soxr_output (struct rate * p ,real * samples ,size_t * n0 ); 172void _soxr_flush (struct rate * p ); 173void _soxr_close (struct rate * p ); 174double _soxr_delay (struct rate * p ); 175void _soxr_sizes (size_t * shared ,size_t * channel ); 176#endif 177 178#endif