Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .nanparc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
packages livekit livekit-ffi livekit-protocol livekit-runtime livekit-api libwebrtc webrtc-sys webrtc-sys/build
packages livekit livekit-ffi livekit-protocol livekit-runtime livekit-api libwebrtc webrtc-sys webrtc-sys/build soxr-sys
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions soxr-sys/.nanparc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
version 0.1.0
language rust
32 changes: 32 additions & 0 deletions soxr-sys/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions soxr-sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "soxr-sys"
version = "0.1.0"
authors = ["Theo Monnom <theo.8bits@gmail.com"]
edition = "2021"

[dependencies]


[build-dependencies]
cc = "1.0"

[dev-dependencies]
hound = "3.4"
40 changes: 40 additions & 0 deletions soxr-sys/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
fn main() {
let mut build = cc::Build::new();

build.include("src");
build.define("SOXR_LIB", "0");

build
.flag_if_supported("-std=gnu89")
.flag_if_supported("-Wnested-externs")
.flag_if_supported("-Wmissing-prototypes")
.flag_if_supported("-Wstrict-prototypes")
.flag_if_supported("-Wconversion")
.flag_if_supported("-Wall")
.flag_if_supported("-Wextra")
.flag_if_supported("-pedantic")
.flag_if_supported("-Wundef")
.flag_if_supported("-Wpointer-arith")
.flag_if_supported("-Wno-long-long");

// TODO(theomonnom): Add SIMD support
let sources = [
"src/soxr.c",
"src/data-io.c",
"src/dbesi0.c",
"src/filter.c",
"src/cr.c",
"src/cr32.c",
"src/fft4g32.c",
"src/fft4g.c",
"src/fft4g64.c",
"src/vr32.c",
];

for source in &sources {
build.file(source);
}

build.compile("libsoxr.a");
println!("cargo:rustc-link-lib=m");
}
1 change: 1 addition & 0 deletions soxr-sys/generate_bindings.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bindgen --no-prepend-enum-name src/soxr.h -o src/soxr.rs
23 changes: 23 additions & 0 deletions soxr-sys/src/LICENCE
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
SoX Resampler Library Copyright (c) 2007-18 robs@users.sourceforge.net

This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or (at
your option) any later version.

This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with this library; if not, see <https://www.gnu.org/licenses/>.


Notes

1. Re software in the `examples' directory: works that are not resampling
examples but are based on the given examples -- for example, applications using
the library -- shall not be considered to be derivative works of the examples.

2. If building with pffft.c, see the licence embedded in that file.
39 changes: 39 additions & 0 deletions soxr-sys/src/aliases.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* SoX Resampler Library Copyright (c) 2007-16 robs@users.sourceforge.net
* Licence for this file: LGPL v2.1 See LICENCE for details. */

#if defined SOXR_LIB

#define lsx_bessel_I_0 _soxr_bessel_I_0
#define lsx_cdft_f _soxr_cdft_f
#define lsx_cdft _soxr_cdft
#define lsx_clear_fft_cache_f _soxr_clear_fft_cache_f
#define lsx_clear_fft_cache _soxr_clear_fft_cache
#define lsx_ddct_f _soxr_ddct_f
#define lsx_ddct _soxr_ddct
#define lsx_ddst_f _soxr_ddst_f
#define lsx_ddst _soxr_ddst
#define lsx_design_lpf _soxr_design_lpf
#define lsx_dfct_f _soxr_dfct_f
#define lsx_dfct _soxr_dfct
#define lsx_dfst_f _soxr_dfst_f
#define lsx_dfst _soxr_dfst
#define lsx_fir_to_phase _soxr_fir_to_phase
#define lsx_f_resp _soxr_f_resp
#define lsx_init_fft_cache_f _soxr_init_fft_cache_f
#define lsx_init_fft_cache _soxr_init_fft_cache
#define lsx_inv_f_resp _soxr_inv_f_resp
#define lsx_kaiser_beta _soxr_kaiser_beta
#define lsx_kaiser_params _soxr_kaiser_params
#define lsx_make_lpf _soxr_make_lpf
#define lsx_ordered_convolve_f _soxr_ordered_convolve_f
#define lsx_ordered_convolve _soxr_ordered_convolve
#define lsx_ordered_partial_convolve_f _soxr_ordered_partial_convolve_f
#define lsx_ordered_partial_convolve _soxr_ordered_partial_convolve
#define lsx_rdft_f _soxr_rdft_f
#define lsx_rdft _soxr_rdft
#define lsx_safe_cdft_f _soxr_safe_cdft_f
#define lsx_safe_cdft _soxr_safe_cdft
#define lsx_safe_rdft_f _soxr_safe_rdft_f
#define lsx_safe_rdft _soxr_safe_rdft

#endif
33 changes: 33 additions & 0 deletions soxr-sys/src/avfft32.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
* Licence for this file: LGPL v2.1 See LICENCE for details. */

#include <stdlib.h>
#include <math.h>
#include <libavcodec/avfft.h>
#include "filter.h"
#include "rdft_t.h"

static void * forward_setup(int len) {return av_rdft_init((int)(log(len)/log(2)+.5),DFT_R2C);}
static void * backward_setup(int len) {return av_rdft_init((int)(log(len)/log(2)+.5),IDFT_C2R);}
static void rdft(int length, void * setup, float * h) {av_rdft_calc(setup, h); (void)length;}
static int multiplier(void) {return 2;}
static void nothing(void) {}
static int flags(void) {return 0;}

fn_t _soxr_rdft32_cb[] = {
(fn_t)forward_setup,
(fn_t)backward_setup,
(fn_t)av_rdft_end,
(fn_t)rdft,
(fn_t)rdft,
(fn_t)rdft,
(fn_t)rdft,
(fn_t)_soxr_ordered_convolve_f,
(fn_t)_soxr_ordered_partial_convolve_f,
(fn_t)multiplier,
(fn_t)nothing,
(fn_t)malloc,
(fn_t)calloc,
(fn_t)free,
(fn_t)flags,
};
32 changes: 32 additions & 0 deletions soxr-sys/src/avfft32s.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
* Licence for this file: LGPL v2.1 See LICENCE for details. */

#include <math.h>
#include <libavcodec/avfft.h>
#include "util32s.h"
#include "rdft_t.h"

static void * forward_setup(int len) {return av_rdft_init((int)(log(len)/log(2)+.5),DFT_R2C);}
static void * backward_setup(int len) {return av_rdft_init((int)(log(len)/log(2)+.5),IDFT_C2R);}
static void rdft(int length, void * setup, float * h) {av_rdft_calc(setup, h); (void)length;}
static int multiplier(void) {return 2;}
static void nothing(void) {}
static int flags(void) {return RDFT_IS_SIMD;}

fn_t _soxr_rdft32s_cb[] = {
(fn_t)forward_setup,
(fn_t)backward_setup,
(fn_t)av_rdft_end,
(fn_t)rdft,
(fn_t)rdft,
(fn_t)rdft,
(fn_t)rdft,
(fn_t)ORDERED_CONVOLVE_SIMD,
(fn_t)ORDERED_PARTIAL_CONVOLVE_SIMD,
(fn_t)multiplier,
(fn_t)nothing,
(fn_t)SIMD_ALIGNED_MALLOC,
(fn_t)SIMD_ALIGNED_CALLOC,
(fn_t)SIMD_ALIGNED_FREE,
(fn_t)flags,
};
75 changes: 75 additions & 0 deletions soxr-sys/src/ccrw2.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/* SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
* Licence for this file: LGPL v2.1 See LICENCE for details. */

/* Concurrent Control with "Readers" and "Writers", P.J. Courtois et al, 1971 */

#if !defined soxr_ccrw2_included
#define soxr_ccrw2_included

#if defined SOXR_LIB
#include "internal.h"
#endif

#if defined _OPENMP

#include <omp.h>

typedef struct {
int readcount, writecount; /* initial value = 0 */
omp_lock_t mutex_1, mutex_2, mutex_3, w, r; /* initial value = 1 */
} ccrw2_t; /* Problem #2: `writers-preference' */

#define ccrw2_become_reader(p) do {\
omp_set_lock(&p.mutex_3);\
omp_set_lock(&p.r);\
omp_set_lock(&p.mutex_1);\
if (++p.readcount == 1) omp_set_lock(&p.w);\
omp_unset_lock(&p.mutex_1);\
omp_unset_lock(&p.r);\
omp_unset_lock(&p.mutex_3);\
} while (0)
#define ccrw2_cease_reading(p) do {\
omp_set_lock(&p.mutex_1);\
if (!--p.readcount) omp_unset_lock(&p.w);\
omp_unset_lock(&p.mutex_1);\
} while (0)
#define ccrw2_become_writer(p) do {\
omp_set_lock(&p.mutex_2);\
if (++p.writecount == 1) omp_set_lock(&p.r);\
omp_unset_lock(&p.mutex_2);\
omp_set_lock(&p.w);\
} while (0)
#define ccrw2_cease_writing(p) do {\
omp_unset_lock(&p.w);\
omp_set_lock(&p.mutex_2);\
if (!--p.writecount) omp_unset_lock(&p.r);\
omp_unset_lock(&p.mutex_2);\
} while (0)
#define ccrw2_init(p) do {\
omp_init_lock(&p.mutex_1);\
omp_init_lock(&p.mutex_2);\
omp_init_lock(&p.mutex_3);\
omp_init_lock(&p.w);\
omp_init_lock(&p.r);\
} while (0)
#define ccrw2_clear(p) do {\
omp_destroy_lock(&p.r);\
omp_destroy_lock(&p.w);\
omp_destroy_lock(&p.mutex_3);\
omp_destroy_lock(&p.mutex_2);\
omp_destroy_lock(&p.mutex_1);\
} while (0)

#else

typedef int ccrw2_t;
#define ccrw2_become_reader(x) (void)(x)
#define ccrw2_cease_reading(x) (void)(x)
#define ccrw2_become_writer(x) (void)(x)
#define ccrw2_cease_writing(x) (void)(x)
#define ccrw2_init(x) (void)(x)
#define ccrw2_clear(x) (void)(x)

#endif /* _OPENMP */

#endif
Loading