1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-10-30 17:23:51 +01:00

Upgrade to libsoxr 0.0.2.

This commit is contained in:
v.audacity
2012-10-12 23:54:03 +00:00
parent 3cb679ccd8
commit 2416f94980
51 changed files with 1300 additions and 372 deletions

View File

@@ -1,7 +1,11 @@
# SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
# Licence for this file: LGPL v2.1 See LICENCE for details.
add_definitions (${PROJECT_DEFS} -DSOXR_LIB)
add_definitions (${PROJECT_C_FLAGS} -DSOXR_LIB)
# Libsoxr configuration:
set (RDFT32 fft4g32)
if (WITH_AVFFT AND AVCODEC_FOUND)
@@ -23,42 +27,82 @@ endif ()
if (HAVE_SIMD)
set (SIMD_SOURCES rate32s ${RDFT32S} simd)
foreach (source ${SIMD_SOURCES})
set_property(SOURCE ${source} PROPERTY COMPILE_FLAGS ${SIMD_C_FLAGS})
set_property (SOURCE ${source} PROPERTY COMPILE_FLAGS ${SIMD_C_FLAGS})
endforeach ()
endif ()
add_library(${PROJECT_NAME} ${LIB_TYPE} ${PROJECT_NAME} data-io dbesi0 filter fft4g64
# Libsoxr:
add_library (${PROJECT_NAME} ${LIB_TYPE} ${PROJECT_NAME}.c data-io dbesi0 filter fft4g64
${SP_SOURCES} ${DP_SOURCES} ${SIMD_SOURCES})
set_target_properties (${PROJECT_NAME} PROPERTIES SOVERSION "${VERSION}")
list (APPEND TARGET_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.h")
set_target_properties (${PROJECT_NAME} PROPERTIES
VERSION "${SO_VERSION}"
SOVERSION ${SO_VERSION_MAJOR}
INSTALL_NAME_DIR ${LIB_INSTALL_DIR}
LINK_INTERFACE_LIBRARIES ""
PUBLIC_HEADER "${PROJECT_NAME}.h")
if (BUILD_FRAMEWORK)
set_target_properties (${PROJECT_NAME} PROPERTIES FRAMEWORK TRUE)
elseif (NOT WIN32)
set (TARGET_PCS ${CMAKE_CURRENT_BINARY_DIR}/lib${PROJECT_NAME}.pc)
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/lib${PROJECT_NAME}.pc.in ${TARGET_PCS})
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/lib${PROJECT_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
endif ()
if (WITH_LSR_IF)
set (LSR samplerate)
# LSR bindings:
if (WITH_LSR_BINDINGS)
set (LSR ${PROJECT_NAME}-lsr)
add_library(${LSR} ${LIB_TYPE} lsr)
set (LSR_SO_VERSION 0.1.8)
set (LSR_SO_VERSION_MAJOR 0)
add_library (${LSR} ${LIB_TYPE} lsr)
target_link_libraries (${LSR} ${PROJECT_NAME})
set_target_properties (${LSR} PROPERTIES SOVERSION ${VERSION})
list (APPEND TARGET_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/${LSR}.h")
endif ()
install (TARGETS ${PROJECT_NAME} ${LSR} DESTINATION lib)
install (FILES ${TARGET_HEADERS} DESTINATION include)
# Packaging
get_property(LIB1 TARGET ${PROJECT_NAME} PROPERTY LOCATION)
if (BUILD_SHARED_LIBS)
set (LIB1 ${LIB1}.${VERSION})
endif ()
if (WITH_LSR_IF)
get_property(LIB2 TARGET ${LSR} PROPERTY LOCATION)
if (BUILD_SHARED_LIBS)
set (LIB2 ${LIB2}.${VERSION})
set_target_properties (${LSR} PROPERTIES
VERSION "${LSR_SO_VERSION}"
SOVERSION ${LSR_SO_VERSION_MAJOR}
INSTALL_NAME_DIR ${LIB_INSTALL_DIR}
LINK_INTERFACE_LIBRARIES ""
PUBLIC_HEADER "${LSR}.h")
if (BUILD_FRAMEWORK)
set_target_properties (${LSR} PROPERTIES FRAMEWORK TRUE)
elseif (NOT WIN32)
set (TARGET_PCS "${TARGET_PCS} ${CMAKE_CURRENT_BINARY_DIR}/lib${LSR}.pc")
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/lib${LSR}.pc.in ${CMAKE_CURRENT_BINARY_DIR}/lib${LSR}.pc)
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/lib${LSR}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
endif ()
endif ()
# Installation (from build from source):
install (TARGETS ${PROJECT_NAME} ${LSR}
FRAMEWORK DESTINATION ${FRAMEWORK_INSTALL_DIR}
LIBRARY DESTINATION ${LIB_INSTALL_DIR}
RUNTIME DESTINATION ${BIN_INSTALL_DIR}
ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
PUBLIC_HEADER DESTINATION ${INCLUDE_INSTALL_DIR})
# Packaging (for unix-like distributions):
get_property (LIB1 TARGET ${PROJECT_NAME} PROPERTY LOCATION)
if (BUILD_SHARED_LIBS)
set (LIB1 ${LIB1}.${SO_VERSION_MAJOR} ${LIB1}.${SO_VERSION})
endif ()
list (APPEND TARGET_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.h")
if (WITH_LSR_BINDINGS)
get_property (LIB2 TARGET ${LSR} PROPERTY LOCATION)
if (BUILD_SHARED_LIBS)
set (LIB2 ${LIB2}.${LSR_SO_VERSION_MAJOR} ${LIB2}.${LSR_SO_VERSION})
endif ()
list (APPEND TARGET_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/${LSR}.h")
endif ()
set (TARGET_LIBS ${LIB1} ${LIB2})
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libsoxr.src ${CMAKE_CURRENT_BINARY_DIR}/libsoxr.src)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libsoxr-dev.src ${CMAKE_CURRENT_BINARY_DIR}/libsoxr-dev.src)
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/libsoxr.src.in ${CMAKE_CURRENT_BINARY_DIR}/libsoxr.src)
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/libsoxr-dev.src.in ${CMAKE_CURRENT_BINARY_DIR}/libsoxr-dev.src)

View File

@@ -1,30 +1,37 @@
/* SoX Resampler Library Copyright (c) 2007-12 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 _soxr_cdft
#define lsx_cdft_f _soxr_cdft_f
#define lsx_clear_fft_cache _soxr_clear_fft_cache
#define lsx_clear_fft_cache_f _soxr_clear_fft_cache_f
#define lsx_ddct _soxr_ddct
#define lsx_ddct_f _soxr_ddct_f
#define lsx_ddst _soxr_ddst
#define lsx_ddst_f _soxr_ddst_f
#define lsx_design_lpf _soxr_design_lpf
#define lsx_dfct _soxr_dfct
#define lsx_dfct_f _soxr_dfct_f
#define lsx_dfst _soxr_dfst
#define lsx_dfst_f _soxr_dfst_f
#define lsx_fir_to_phase _soxr_fir_to_phase
#define lsx_init_fft_cache _soxr_init_fft_cache
#define lsx_init_fft_cache_f _soxr_init_fft_cache_f
#define lsx_kaiser_beta _soxr_kaiser_beta
#define lsx_kaiser_params _soxr_kaiser_params
#define lsx_make_lpf _soxr_make_lpf
#define lsx_rdft _soxr_rdft
#define lsx_rdft_f _soxr_rdft_f
#define lsx_safe_cdft _soxr_safe_cdft
#define lsx_safe_cdft_f _soxr_safe_cdft_f
#define lsx_safe_rdft _soxr_safe_rdft
#define lsx_safe_rdft_f _soxr_safe_rdft_f
#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_init_fft_cache_f _soxr_init_fft_cache_f
#define lsx_init_fft_cache _soxr_init_fft_cache
#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

View File

@@ -44,7 +44,9 @@ static bool UPDATE_FFT_CACHE(int len)
LSX_FFT_SC = realloc(LSX_FFT_SC, dft_sc_len(FFT_LEN) * sizeof(*LSX_FFT_SC));
if (!old_n) {
LSX_FFT_BR[0] = 0;
#if SOXR_LIB
atexit(LSX_CLEAR_FFT_CACHE);
#endif
}
return true;
}

View File

@@ -48,17 +48,17 @@
#include "fft4g_cache.h"
#endif
#if HAVE_DOUBLE_PRECISION
#if HAVE_DOUBLE_PRECISION || !SOXR_LIB
#define DFT_FLOAT double
#define ORDERED_CONVOLVE _soxr_ordered_convolve
#define ORDERED_PARTIAL_CONVOLVE _soxr_ordered_partial_convolve
#define ORDERED_CONVOLVE lsx_ordered_convolve
#define ORDERED_PARTIAL_CONVOLVE lsx_ordered_partial_convolve
#include "rdft.h"
#endif
#if HAVE_SINGLE_PRECISION
#define DFT_FLOAT float
#define ORDERED_CONVOLVE _soxr_ordered_convolve_f
#define ORDERED_PARTIAL_CONVOLVE _soxr_ordered_partial_convolve_f
#define ORDERED_CONVOLVE lsx_ordered_convolve_f
#define ORDERED_PARTIAL_CONVOLVE lsx_ordered_partial_convolve_f
#include "rdft.h"
#endif

View File

@@ -7,7 +7,6 @@
#include "aliases.h"
double lsx_bessel_I_0(double x);
int lsx_set_dft_length(int num_taps, int min, int large);
void lsx_init_fft_cache(void);
void lsx_clear_fft_cache(void);
void lsx_init_fft_cache_f(void);
@@ -17,10 +16,10 @@ void lsx_safe_rdft(int len, int type, double * d);
void lsx_safe_cdft(int len, int type, double * d);
void lsx_safe_rdft_f(int len, int type, float * d);
void lsx_safe_cdft_f(int len, int type, float * d);
void _soxr_ordered_convolve(int n, void * not_used, double * a, const double * b);
void _soxr_ordered_convolve_f(int n, void * not_used, float * a, const float * b);
void _soxr_ordered_partial_convolve(int n, double * a, const double * b);
void _soxr_ordered_partial_convolve_f(int n, float * a, const float * b);
void lsx_ordered_convolve(int n, void * not_used, double * a, const double * b);
void lsx_ordered_convolve_f(int n, void * not_used, float * a, const float * b);
void lsx_ordered_partial_convolve(int n, double * a, const double * b);
void lsx_ordered_partial_convolve_f(int n, float * a, const float * b);
double lsx_kaiser_beta(double att, double tr_bw);
double * lsx_make_lpf(int num_taps, double Fc, double beta, double rho,

View File

@@ -1 +1,2 @@
set(TARGET_HEADERS "@TARGET_HEADERS@")
set(TARGET_PCS "@TARGET_PCS@")

View File

@@ -0,0 +1,11 @@
prefix=${CMAKE_INSTALL_PREFIX}
exec_prefix=${CMAKE_INSTALL_PREFIX}
libdir=${LIB_INSTALL_DIR}
includedir=${INCLUDE_INSTALL_DIR}
Name: lib${LSR}
Description: ${DESCRIPTION_SUMMARY} (with libsamplerate-like bindings)
Requires: libsoxr
Version: ${PROJECT_VERSION}
Libs: -L${LIB_INSTALL_DIR} -l${LSR}
Cflags: -I${INCLUDE_INSTALL_DIR}

View File

@@ -0,0 +1,11 @@
prefix=${CMAKE_INSTALL_PREFIX}
exec_prefix=${CMAKE_INSTALL_PREFIX}
libdir=${LIB_INSTALL_DIR}
includedir=${INCLUDE_INSTALL_DIR}
Name: lib${PROJECT_NAME}
Description: ${DESCRIPTION_SUMMARY}
Requires:
Version: ${PROJECT_VERSION}
Libs: -L${LIB_INSTALL_DIR} -l${PROJECT_NAME}
Cflags: -I${INCLUDE_INSTALL_DIR}

View File

@@ -1,2 +1 @@
set(TARGET_LIBS "@TARGET_LIBS@")

View File

@@ -11,7 +11,7 @@
typedef struct io_t {
float *in,*out; long ilen,olen,idone,odone; int eoi; double oi_ratio;} io_t;
#define SRC_DATA io_t
typedef struct soxr_t SRC_STATE;
typedef struct soxr SRC_STATE;
#define src_callback_t soxr_input_fn_t
#define SRC_ERROR soxr_error_t
#define SRC_SRCTYPE unsigned
@@ -62,10 +62,8 @@ soxr_error_t src_process(soxr_t p, io_t * io)
soxr_set_error(p, soxr_set_oi_ratio(p, io->oi_ratio));
{ size_t idone , odone;
if (io->eoi)
io->ilen = -io->ilen; /* hack */
soxr_process(p,
io->in, (size_t)io->ilen, &idone, io->out, (size_t)io->olen, &odone);
soxr_process(p, io->in, (size_t)(io->eoi? ~io->ilen : io->ilen), /* hack */
&idone, io->out, (size_t)io->olen, &odone);
io->idone = (long)idone, io->odone = (long)odone;
return soxr_error(p); }
}

View File

@@ -9,6 +9,8 @@
#include "filter.h"
#include "internal.h"
#if defined SOXR_LIB
extern struct {
void * (* forward_setup)(int);
void * (* backward_setup)(int);
@@ -35,6 +37,8 @@ extern struct {
#define rdft_multiplier (*RDFT_CB.multiplier)
#define rdft_reorder_back (*RDFT_CB.reorder_back)
#endif
#if RATE_SIMD /* Align for SIMD: */
#include "simd.h"
#if 0 /* Not using this yet. */
@@ -606,9 +610,8 @@ static void rate_process(rate_t * p)
static sample_t * rate_input(rate_t * p, sample_t const * samples, size_t n)
{
fifo_t * fifo = &p->stages[0].fifo;
p->samples_in += n;
return fifo_write(fifo, (int)n, samples);
return fifo_write(&p->stages[0].fifo, (int)n, samples);
}
static sample_t const * rate_output(rate_t * p, sample_t * samples, size_t * n)
@@ -626,13 +629,12 @@ static void rate_flush(rate_t * p)
#else
uint64_t samples_out = (uint64_t)((double)p->samples_in / p->factor + .5);
#endif
size_t remaining = (size_t)(samples_out - p->samples_out), idone;
size_t remaining = (size_t)(samples_out - p->samples_out);
sample_t * buff = calloc(1024, sizeof(*buff));
if ((int)remaining > 0) {
while ((size_t)fifo_occupancy(fifo) < remaining) {
idone = 1024;
rate_input(p, buff, idone);
rate_input(p, buff, 1024);
rate_process(p);
}
fifo_trim_to(fifo, (int)remaining);

View File

@@ -26,18 +26,18 @@
#if defined SOXR_DLL
#if defined soxr_lsr_EXPORTS
#define _ __declspec(dllexport)
#define SOXR __declspec(dllexport)
#else
#define _ __declspec(dllimport)
#define SOXR __declspec(dllimport)
#endif
#else
#define _
#define SOXR
#endif
typedef float SRC_SAMPLE;
#if !defined SOXR_LIB
enum SRC_SRCTYPE{SRC_SINC_BEST_QUALITY,SRC_SINC_MEDIUM_QUALITY,SRC_SINC_FASTEST,
SRC_ZERO_ORDER_HOLD, SRC_LINEAR};
enum SRC_SRCTYPE_e {SRC_SINC_BEST_QUALITY, SRC_SINC_MEDIUM_QUALITY,
SRC_SINC_FASTEST, SRC_ZERO_ORDER_HOLD, SRC_LINEAR};
typedef int SRC_SRCTYPE;
typedef int SRC_ERROR;
typedef long (* src_callback_t)(void *, SRC_SAMPLE * *);
@@ -50,28 +50,28 @@ typedef struct SRC_DATA {
double src_ratio;
} SRC_DATA;
#endif
_ SRC_STATE * src_new(SRC_SRCTYPE, int num_channels, SRC_ERROR *);
_ SRC_ERROR src_process (SRC_STATE *, SRC_DATA *);
_ SRC_ERROR src_set_ratio(SRC_STATE *, double);
_ SRC_ERROR src_reset (SRC_STATE *);
_ SRC_ERROR src_error (SRC_STATE *);
_ SRC_STATE * src_delete (SRC_STATE *);
_ SRC_STATE * src_callback_new(
SOXR SRC_STATE * src_new(SRC_SRCTYPE, int num_channels, SRC_ERROR *);
SOXR SRC_ERROR src_process (SRC_STATE *, SRC_DATA *);
SOXR SRC_ERROR src_set_ratio(SRC_STATE *, double);
SOXR SRC_ERROR src_reset (SRC_STATE *);
SOXR SRC_ERROR src_error (SRC_STATE *);
SOXR SRC_STATE * src_delete (SRC_STATE *);
SOXR SRC_STATE * src_callback_new(
src_callback_t, SRC_SRCTYPE, int, SRC_ERROR *, void *);
_ long src_callback_read(
SOXR long src_callback_read(
SRC_STATE *, double src_ratio, long, SRC_SAMPLE *);
_ SRC_ERROR src_simple(SRC_DATA *, SRC_SRCTYPE, int);
_ char const * src_get_name(SRC_SRCTYPE);
_ char const * src_get_description(SRC_SRCTYPE);
_ char const * src_get_version(void);
_ char const * src_strerror(SRC_ERROR);
_ int src_is_valid_ratio(double);
_ void src_short_to_float_array(short const *, float *, int);
_ void src_float_to_short_array(float const *, short *, int);
_ void src_int_to_float_array(int const *, float *, int);
_ void src_float_to_int_array(float const *, int *, int);
SOXR SRC_ERROR src_simple(SRC_DATA *, SRC_SRCTYPE, int);
SOXR char const * src_get_name(SRC_SRCTYPE);
SOXR char const * src_get_description(SRC_SRCTYPE);
SOXR char const * src_get_version(void);
SOXR char const * src_strerror(SRC_ERROR);
SOXR int src_is_valid_ratio(double);
SOXR void src_short_to_float_array(short const *, float *, int);
SOXR void src_float_to_short_array(float const *, short *, int);
SOXR void src_int_to_float_array(int const *, float *, int);
SOXR void src_float_to_int_array(float const *, int *, int);
#undef _
#undef SOXR
#if defined __cplusplus
}
#endif

View File

@@ -55,7 +55,7 @@ typedef void (* deinterleave_t)(sample_t * * dest,
typedef size_t (* interleave_t)(soxr_datatype_t data_type, void * * dest,
sample_t const * const * src, size_t, unsigned, unsigned long *);
struct soxr_t {
struct soxr {
unsigned num_channels;
double oi_ratio;
soxr_error_t error;
@@ -405,7 +405,7 @@ void soxr_delete(soxr_t p)
soxr_error_t soxr_clear(soxr_t p) /* TODO: this, properly. */
{
if (p) {
struct soxr_t tmp = *p;
struct soxr tmp = *p;
soxr_delete0(p);
memset(p, 0, sizeof(*p));
p->input_fn = tmp.input_fn;
@@ -464,9 +464,9 @@ static size_t soxr_output_1ch(soxr_t p, unsigned i, soxr_buf_t dest, size_t len,
resampler_process(p->resamplers[i]);
src = resampler_output(p->resamplers[i], NULL, &len);
if (separated)
p->clips += (p->interleave)(p->io_spec.otype, &dest, &src,
p->clips += (p->interleave)(p->io_spec.otype, &dest, &src,
len, 1, (p->io_spec.flags & SOXR_NO_DITHER)? 0 : &p->seed);
else p->channel_ptrs[i] = (void /* const */ *)src;;
else p->channel_ptrs[i] = (void /* const */ *)src;
return len;
}
@@ -502,6 +502,7 @@ size_t soxr_output(soxr_t p, void * out, size_t len0)
{
size_t odone, odone0 = 0, olen = len0, osize, idone;
void const * in = out; /* Set to !=0, so that caller may leave unset. */
bool was_flushing;
if (!p || p->error) return 0;
if (!out && len0) {p->error = "null output buffer pointer"; return 0;}
@@ -516,10 +517,11 @@ size_t soxr_output(soxr_t p, void * out, size_t len0)
out = (char *)out + osize * odone;
olen -= odone;
idone = p->input_fn(p->input_fn_state, &in, (size_t)ceil((double)olen /p->oi_ratio));
was_flushing = p->flushing;
if (!in)
p->error = "input function reported failure";
else soxr_input(p, in, idone);
} while (in && (odone || idone));
} while (odone || idone || (!was_flushing && p->flushing));
return odone0;
}
@@ -561,7 +563,7 @@ soxr_error_t soxr_process(soxr_t p,
flush_requested = true, ilen = ilen0 = 0;
else {
if ((ptrdiff_t)ilen0 < 0)
flush_requested = true, ilen0 = 1 + ~ilen0;
flush_requested = true, ilen0 = ~ilen0;
if (1 || flush_requested)
ilen = soxr_i_for_o(p, olen, ilen0);
else
@@ -592,7 +594,7 @@ soxr_error_t soxr_process(soxr_t p,
idone = ilen;
}
else {
idone = soxr_input (p, in , ilen);
idone = ilen? soxr_input (p, in , ilen) : 0;
odone = soxr_output(p, out, olen);
}
if (idone0) *idone0 = idone;
@@ -621,8 +623,7 @@ soxr_error_t soxr_oneshot(
&error, io_spec, q_spec, runtime_spec);
}
if (!error) {
ilen = 1 + ~ilen;
error = soxr_process(resampler, in, ilen, idone, out, olen, odone);
error = soxr_process(resampler, in, ~ilen, idone, out, olen, odone);
soxr_delete(resampler);
}
return error;

View File

@@ -32,17 +32,17 @@
#if defined SOXR_DLL
#if defined soxr_EXPORTS
#define _ __declspec(dllexport)
#define SOXR __declspec(dllexport)
#else
#define _ __declspec(dllimport)
#define SOXR __declspec(dllimport)
#endif
#else
#define _
#define SOXR
#endif
typedef struct soxr_io_spec_t soxr_io_spec_t;
typedef struct soxr_quality_spec_t soxr_quality_spec_t;
typedef struct soxr_runtime_spec_t soxr_runtime_spec_t;
typedef struct soxr_io_spec soxr_io_spec_t;
typedef struct soxr_quality_spec soxr_quality_spec_t;
typedef struct soxr_runtime_spec soxr_runtime_spec_t;
@@ -60,8 +60,8 @@ input or output (e.g. ilen, olen). */
/* --------------------------- Type declarations ---------------------------- */
typedef struct soxr_t * soxr_t; /* A resampler for 1 or more channels. */
typedef char const * soxr_error_t; /* 0:no-error; non-0:error. */
typedef struct soxr * soxr_t; /* A resampler for 1 or more channels. */
typedef char const * soxr_error_t; /* 0:no-error; non-0:error. */
typedef void * soxr_buf_t; /* 1 buffer of channel-interleaved samples. */
typedef void const * soxr_cbuf_t; /* Ditto; read-only. */
@@ -78,7 +78,7 @@ typedef void * soxr_out_t; /* Either a soxr_buf_t or soxr_bufs_t,
/* --------------------------- API main functions --------------------------- */
_ char const * soxr_version(void); /* Query library version: "x.y.z". */
SOXR char const * soxr_version(void); /* Query library version: "x.y.z". */
#define soxr_strerror(e) /* Soxr counterpart to strerror. */ \
((e)?(e):"no error")
@@ -86,7 +86,7 @@ _ char const * soxr_version(void); /* Query library version: "x.y.z". */
/* Create a stream resampler: */
_ soxr_t soxr_create(
SOXR soxr_t soxr_create(
double input_rate, /* Input sample-rate. */
double output_rate, /* Output sample-rate. */
unsigned num_channels, /* Number of channels to be used. */
@@ -101,16 +101,20 @@ _ soxr_t soxr_create(
/* If not using an app-supplied input function, after creating a stream
* resampler, repeatedly call: */
_ soxr_error_t soxr_process(
SOXR soxr_error_t soxr_process(
soxr_t resampler, /* As returned by soxr_create. */
/* Input (to be resampled): */
soxr_in_t in, /* Interleaved or split input buffer(s). */
soxr_in_t in, /* Input buffer(s); may be NULL (see below). */
size_t ilen, /* Input buf. length (samples per channel). */
size_t * idone, /* To return actual # samples used (<= ilen). */
/* Output (resampled): */
soxr_out_t out, /* Interleaved or split output buffer(s).*/
soxr_out_t out, /* Output buffer(s).*/
size_t olen, /* Output buf. length (samples per channel). */
size_t * odone); /* To return actual # samples out (<= olen). */
size_t * odone); /* To return actual # samples out (<= olen).
Note that no special meaning is associated with ilen or olen equal to
zero. End-of-input (i.e. no data is available nor shall be available)
may be indicated by seting in to zero. */
@@ -118,7 +122,7 @@ _ soxr_error_t soxr_process(
typedef size_t /* data_len */
(* soxr_input_fn_t)( /* Supply data to be resampled. */
void * input_fn_state, /* As given to soxr_set_input_fn. */
void * input_fn_state, /* As given to soxr_set_input_fn (below). */
soxr_in_t * data, /* Returned data; see below. N.B. ptr to ptr(s)*/
size_t requested_len); /* Samples per channel, >= returned data_len.
@@ -133,14 +137,14 @@ typedef size_t /* data_len */
/* and be registered with a previously created stream resampler using: */
_ soxr_error_t soxr_set_input_fn(/* Set (or reset) an input function.*/
SOXR soxr_error_t soxr_set_input_fn(/* Set (or reset) an input function.*/
soxr_t resampler, /* As returned by soxr_create. */
soxr_input_fn_t, /* Function to supply data to be resampled.*/
void * input_fn_state); /* If needed by the input function. */
/* then repeatedly call: */
_ size_t /*odone*/ soxr_output(/* Resample and output a portion of the signal.*/
SOXR size_t /*odone*/ soxr_output(/* Resample and output a block of data.*/
soxr_t resampler, /* As returned by soxr_create. */
soxr_out_t data, /* App-supplied buffer(s) for resampled data.*/
size_t olen); /* Amount of data to output; >= odone. */
@@ -149,20 +153,20 @@ _ size_t /*odone*/ soxr_output(/* Resample and output a portion of the signal.*/
/* Common stream resampler operations: */
_ soxr_error_t soxr_error(soxr_t); /* Query error status. */
_ size_t * soxr_num_clips(soxr_t); /* Query int. clip counter (for R/W). */
_ double soxr_delay(soxr_t); /* Query current delay in output samples.*/
_ char const * soxr_engine(soxr_t p);/* Query resampling engine name. */
SOXR soxr_error_t soxr_error(soxr_t); /* Query error status. */
SOXR size_t * soxr_num_clips(soxr_t); /* Query int. clip counter (for R/W). */
SOXR double soxr_delay(soxr_t); /* Query current delay in output samples.*/
SOXR char const * soxr_engine(soxr_t p);/* Query resampling engine name. */
_ soxr_error_t soxr_clear(soxr_t); /* Ready for fresh signal, same config. */
_ void soxr_delete(soxr_t); /* Free resources. */
SOXR soxr_error_t soxr_clear(soxr_t); /* Ready for fresh signal, same config. */
SOXR void soxr_delete(soxr_t); /* Free resources. */
/* `Short-cut', single call to resample a (probably short) signal held entirely
* in memory. See soxr_create and soxr_process above for parameter details. */
_ soxr_error_t soxr_oneshot(
SOXR soxr_error_t soxr_oneshot(
double input_rate,
double output_rate,
unsigned num_channels,
@@ -193,7 +197,7 @@ typedef enum { /* Datatypes supported for I/O to/from the resampler: */
struct soxr_io_spec_t { /* Typically */
struct soxr_io_spec { /* Typically */
soxr_datatype_t itype; /* Input datatype. SOXR_FLOAT32_I */
soxr_datatype_t otype; /* Output datatype. SOXR_FLOAT32_I */
double scale; /* Linear gain to apply during resampling. 1 */
@@ -206,7 +210,7 @@ struct soxr_io_spec_t { /* Typically */
struct soxr_quality_spec_t { /* Typically */
struct soxr_quality_spec { /* Typically */
double bits; /* Required bit-accuracy (pass + stop). 20 */
double phase; /* Linear/minimum etc. phase. [0,100] 50 */
double bw_pc; /* Pass-band % (0dB pt.) to preserve. 91.3 */
@@ -225,7 +229,7 @@ struct soxr_quality_spec_t { /* Typically */
struct soxr_runtime_spec_t { /* Typically */
struct soxr_runtime_spec { /* Typically */
unsigned log2_min_dft_size;/* For DFT efficiency. [8,15] 10 */
unsigned log2_large_dft_size;/* For DFT efficiency. [16,20] 17 */
unsigned coef_size_kbytes; /* For SOXR_COEF_INTERP_AUTO (below). 400 */
@@ -249,7 +253,7 @@ struct soxr_runtime_spec_t { /* Typically */
* parameters, with other parameters being given default values. The default
* values may then be overridden, directly in the structure, if needed. */
_ soxr_quality_spec_t soxr_quality_spec(
SOXR soxr_quality_spec_t soxr_quality_spec(
unsigned long recipe, /* Per the #defines immediately below. */
unsigned long flags); /* As soxr_quality_spec_t.flags. */
@@ -278,12 +282,12 @@ _ soxr_quality_spec_t soxr_quality_spec(
_ soxr_runtime_spec_t soxr_runtime_spec(
SOXR soxr_runtime_spec_t soxr_runtime_spec(
unsigned num_threads);
_ soxr_io_spec_t soxr_io_spec(
SOXR soxr_io_spec_t soxr_io_spec(
soxr_datatype_t itype,
soxr_datatype_t otype);
@@ -291,14 +295,14 @@ _ soxr_io_spec_t soxr_io_spec(
/* --------------------------- Internal use only ---------------------------- */
_ soxr_error_t soxr_set_error(soxr_t, soxr_error_t);
_ soxr_error_t soxr_set_num_channels(soxr_t, unsigned);
_ soxr_error_t soxr_set_oi_ratio(soxr_t, double);
_ soxr_error_t soxr_set_pitch(soxr_t, long);
SOXR soxr_error_t soxr_set_error(soxr_t, soxr_error_t);
SOXR soxr_error_t soxr_set_num_channels(soxr_t, unsigned);
SOXR soxr_error_t soxr_set_oi_ratio(soxr_t, double);
SOXR soxr_error_t soxr_set_pitch(soxr_t, long);
#undef _
#undef SOXR
#if defined __cplusplus
}