mirror of
https://github.com/AxioDL/boo.git
synced 2025-12-17 00:47:01 +00:00
Update soxr to 0.1.3; make wasm compatible
This commit is contained in:
@@ -25,7 +25,7 @@ const float in[] = { /* Input: 12 cycles of a sine wave with freq. = irate/4 */
|
||||
|
||||
int main(int argc, char const * arg[])
|
||||
{
|
||||
double irate = argc > 1? atof(arg[1]) : 1; /* Default to upsampling */
|
||||
double irate = argc > 1? atof(arg[1]) : 1; /* Default to interpolation */
|
||||
double orate = argc > 2? atof(arg[2]) : 2; /* by a factor of 2. */
|
||||
|
||||
size_t olen = (size_t)(AL(in) * orate / irate + .5); /* Assay output len. */
|
||||
|
||||
@@ -12,7 +12,7 @@ float in[] = { /* Input: 12 cycles of a sine wave with freq. = irate/4 */
|
||||
|
||||
int main(int argc, char const * arg[])
|
||||
{
|
||||
double irate = argc > 1? atof(arg[1]) : 1; /* Default to upsampling */
|
||||
double irate = argc > 1? atof(arg[1]) : 1; /* Default to interpolation */
|
||||
double orate = argc > 2? atof(arg[2]) : 2; /* by a factor of 2. */
|
||||
|
||||
size_t olen = (size_t)(AL(in) * orate / irate + .5); /* Assay output len. */
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
|
||||
/* SoX Resampler Library Copyright (c) 2007-16 robs@users.sourceforge.net
|
||||
* Licence for this file: LGPL v2.1 See LICENCE for details. */
|
||||
|
||||
/* Example 3: extends example 2 with multiple channels, multiple datatypes,
|
||||
@@ -14,7 +14,7 @@
|
||||
* OUTPUT-RATE Ditto
|
||||
* NUM-CHANNELS Number of interleaved channels
|
||||
* IN-DATATYPE# 0:float32 1:float64 2:int32 3:int16
|
||||
* OUT-DATATYPE# Ditto
|
||||
* OUT-DATATYPE# Ditto; or 11 for un-dithered int16
|
||||
* Q-RECIPE Quality recipe (in hex) See soxr.h
|
||||
* Q-FLAGS Quality flags (in hex) See soxr.h
|
||||
* PASSBAND-END %
|
||||
@@ -42,7 +42,7 @@ static size_t input_fn(input_context_t * p, soxr_cbuf_t * buf, size_t len)
|
||||
|
||||
int main(int n, char const * arg[])
|
||||
{
|
||||
char const * const arg0 = n? --n, *arg++ : "";
|
||||
char const * const arg0 = n? --n, *arg++ : "", * engine = "";
|
||||
double const irate = n? --n, atof(*arg++) : 96000.;
|
||||
double const orate = n? --n, atof(*arg++) : 44100.;
|
||||
unsigned const chans = n? --n, (unsigned)atoi(*arg++) : 1;
|
||||
@@ -94,6 +94,7 @@ int main(int n, char const * arg[])
|
||||
}
|
||||
|
||||
if (!error) { /* If all is well, run the resampler: */
|
||||
engine = soxr_engine(soxr);
|
||||
USE_STD_STDIO;
|
||||
/* Resample in blocks: */
|
||||
do odone = soxr_output(soxr, obuf, olen);
|
||||
@@ -106,8 +107,8 @@ int main(int n, char const * arg[])
|
||||
soxr_delete(soxr);
|
||||
free(obuf), free(ibuf);
|
||||
/* Diagnostics: */
|
||||
fprintf(stderr, "%-26s %s; %lu clips; I/O: %s\n",
|
||||
fprintf(stderr, "%-26s %s; %lu clips; I/O: %s (%s)\n",
|
||||
arg0, soxr_strerror(error), (long unsigned)clips,
|
||||
ferror(stdin) || ferror(stdout)? strerror(errno) : "no error");
|
||||
ferror(stdin) || ferror(stdout)? strerror(errno) : "no error", engine);
|
||||
return !!error;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
|
||||
/* SoX Resampler Library Copyright (c) 2007-18 robs@users.sourceforge.net
|
||||
* Licence for this file: LGPL v2.1 See LICENCE for details. */
|
||||
|
||||
/* Example 4: variant of examples 2 & 3, demonstrating I/O with split channels.
|
||||
@@ -13,6 +13,8 @@
|
||||
*
|
||||
* Note also (not shown in the examples) that split/interleaved channels may
|
||||
* be used for input and output independently.
|
||||
*
|
||||
* Arguments are as example 3.
|
||||
*/
|
||||
|
||||
#include <soxr.h>
|
||||
@@ -73,13 +75,17 @@ int main(int n, char const * arg[])
|
||||
double const orate = n? --n, atof(*arg++) : 44100.;
|
||||
unsigned const chans = n? --n, (unsigned)atoi(*arg++) : 1;
|
||||
soxr_datatype_t const itype = n? --n, (soxr_datatype_t)atoi(*arg++) : 0;
|
||||
soxr_datatype_t const otype = n? --n, (soxr_datatype_t)atoi(*arg++) : 0;
|
||||
unsigned const ospec = n? --n, (soxr_datatype_t)atoi(*arg++) : 0;
|
||||
unsigned long const q_recipe= n? --n, strtoul(*arg++, 0, 16) : SOXR_HQ;
|
||||
unsigned long const q_flags = n? --n, strtoul(*arg++, 0, 16) : 0;
|
||||
double const passband_end = n? --n, atof(*arg++) : 0;
|
||||
double const stopband_begin = n? --n, atof(*arg++) : 0;
|
||||
double const phase_response = n? --n, atof(*arg++) : -1;
|
||||
int const use_threads = n? --n, atoi(*arg++) : 1;
|
||||
soxr_datatype_t const otype = ospec & 3;
|
||||
|
||||
soxr_quality_spec_t const q_spec = soxr_quality_spec(q_recipe, q_flags);
|
||||
soxr_io_spec_t const io_spec=soxr_io_spec(itype|SOXR_SPLIT, otype|SOXR_SPLIT);
|
||||
soxr_quality_spec_t q_spec = soxr_quality_spec(q_recipe, q_flags);
|
||||
soxr_io_spec_t io_spec=soxr_io_spec(itype|SOXR_SPLIT, otype|SOXR_SPLIT);
|
||||
soxr_runtime_spec_t const runtime_spec = soxr_runtime_spec(!use_threads);
|
||||
|
||||
/* Allocate resampling input and output buffers in proportion to the input
|
||||
@@ -102,11 +108,18 @@ int main(int n, char const * arg[])
|
||||
|
||||
size_t odone, written, need_input = 1, clips = 0;
|
||||
soxr_error_t error;
|
||||
soxr_t soxr;
|
||||
unsigned i;
|
||||
|
||||
soxr_t soxr = soxr_create(
|
||||
/* Overrides (if given): */
|
||||
if (passband_end > 0) q_spec.passband_end = passband_end / 100;
|
||||
if (stopband_begin > 0) q_spec.stopband_begin = stopband_begin / 100;
|
||||
if (phase_response >=0) q_spec.phase_response = phase_response;
|
||||
io_spec.flags = ospec & ~7u;
|
||||
|
||||
soxr = soxr_create(
|
||||
irate, orate, chans, &error, &io_spec, &q_spec, &runtime_spec);
|
||||
|
||||
unsigned i;
|
||||
for (i = 0; i < chans; ++i) {
|
||||
ibuf_ptrs[i] = iptr;
|
||||
obuf_ptrs[i] = optr;
|
||||
|
||||
@@ -1,25 +1,23 @@
|
||||
# SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
|
||||
# SoX Resampler Library Copyright (c) 2007-16 robs@users.sourceforge.net
|
||||
# Licence for this file: LGPL v2.1 See LICENCE for details.
|
||||
|
||||
if (${BUILD_EXAMPLES})
|
||||
project (soxr) # Adds c++ compiler
|
||||
file (GLOB SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/[1-9]-*.[cC])
|
||||
elseif (${BUILD_TESTS})
|
||||
file (GLOB SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/3*.c)
|
||||
endif ()
|
||||
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${PROJECT_C_FLAGS}")
|
||||
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${PROJECT_CXX_FLAGS}")
|
||||
link_libraries (${PROJECT_NAME} ${LIBM_LIBRARIES})
|
||||
|
||||
if (${BUILD_EXAMPLES} OR ${BUILD_TESTS})
|
||||
set (SOURCES 3-options-input-fn)
|
||||
if (${WITH_LSR_BINDINGS})
|
||||
set (LSR_SOURCES 1a-lsr.c)
|
||||
set (LSR_SOURCES 1a-lsr)
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
if (NOT BUILD_SHARED_LIBS AND OPENMP_FOUND)
|
||||
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_C_FLAGS}")
|
||||
if (${BUILD_EXAMPLES})
|
||||
list (APPEND SOURCES 1-single-block 2-stream 4-split-channels)
|
||||
if (${WITH_VR32})
|
||||
list (APPEND SOURCES 5-variable-rate)
|
||||
endif ()
|
||||
endif ()
|
||||
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${PROJECT_C_FLAGS}")
|
||||
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${PROJECT_CXX_FLAGS}")
|
||||
link_libraries (soxr)
|
||||
|
||||
foreach (fe ${SOURCES} ${LSR_SOURCES})
|
||||
get_filename_component (f ${fe} NAME_WE)
|
||||
@@ -34,4 +32,5 @@ if (${BUILD_TESTS} AND ${WITH_LSR_BINDINGS})
|
||||
endif ()
|
||||
|
||||
file (GLOB INSTALL_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.[cCh])
|
||||
install (FILES ${INSTALL_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/README DESTINATION ${DOC_INSTALL_DIR}/examples)
|
||||
install (FILES ${INSTALL_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/README
|
||||
DESTINATION ${DOC_INSTALL_DIR}/examples)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
|
||||
/* SoX Resampler Library Copyright (c) 2007-18 robs@users.sourceforge.net
|
||||
* Licence for this file: LGPL v2.1 See LICENCE for details. */
|
||||
|
||||
/* Common includes etc. for the examples. */
|
||||
@@ -17,10 +17,7 @@
|
||||
#include <io.h>
|
||||
#include <fcntl.h>
|
||||
#define USE_STD_STDIO _setmode(_fileno(stdout), _O_BINARY), \
|
||||
_setmode(_fileno(stdin ), _O_BINARY);
|
||||
/* Sometimes missing, so ensure that it is defined: */
|
||||
#undef M_PI
|
||||
#define M_PI 3.14159265358979323846
|
||||
_setmode(_fileno(stdin ), _O_BINARY)
|
||||
#else
|
||||
#define USE_STD_STDIO
|
||||
#endif
|
||||
@@ -38,8 +35,13 @@
|
||||
#endif
|
||||
|
||||
#undef min
|
||||
#undef max
|
||||
#define min(x,y) ((x)<(y)?(x):(y))
|
||||
|
||||
#undef max
|
||||
#define max(x,y) ((x)>(y)?(x):(y))
|
||||
|
||||
#undef AL
|
||||
#define AL(a) (sizeof(a)/sizeof((a)[0])) /* Array Length */
|
||||
|
||||
#undef M_PI /* Sometimes missing, so ensure that it is defined: */
|
||||
#define M_PI 3.14159265358979323846
|
||||
|
||||
Reference in New Issue
Block a user