1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-11-09 14:43:57 +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,21 +1,24 @@
/* SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
* Licence for this file: LGPL v2.1 See LICENCE for details. */
/* Example 3a: extends example 2a with multiple channels, multiple datatypes,
/* Example 3b: extends example 2b with multiple channels, multiple datatypes,
* and other options.
*
* The seven arguments are:
* INPUT-RATE As example 2a
* The eight arguments are:
* INPUT-RATE As example 2b
* OUTPUT-RATE Ditto
* NUM-CHANNELS Number of interleaved channels
* IN-DATATYPE# 0:float32 1:float64 2:int32 3:int16
* OUT-DATATYPE# Ditto
* Q# Quality-recipe | (quality-flags << 16) (in hex) See soxr.h
* Q-RECIPE Quality recipe (in hex) See soxr.h
* Q-FLAGS Quality flags (in hex) See soxr.h
* USE-THREADS 1 to use multi-threading
*/
#include "util.h"
#include <soxr.h>
#include "examples-common.h"
#define iolen 8000
@@ -23,6 +26,7 @@ static size_t input_fn(void * p, soxr_cbuf_t * buf, size_t len)
{
static float * ibuf;
size_t isize = *(size_t *)p;
len = min(len, iolen);
*buf = ibuf = realloc(ibuf, isize * len);
if (!ibuf)
return 0;
@@ -46,6 +50,7 @@ int main(int n, char const * arg[])
soxr_datatype_t itype = n? --n, (soxr_datatype_t)atoi(*arg++) :SOXR_FLOAT32_I;
soxr_datatype_t otype = n? --n, (soxr_datatype_t)atoi(*arg++) :SOXR_FLOAT32_I;
unsigned long q_recipe= n? --n, strtoul(*arg++, 0, 16) : SOXR_HQ;
unsigned long q_flags = n? --n, strtoul(*arg++, 0, 16) : 0;
int use_threads = n? --n, atoi(*arg++) : 1;
size_t isize = soxr_datatype_size(itype) * chans;
@@ -53,7 +58,7 @@ int main(int n, char const * arg[])
size_t clips = 0;
soxr_error_t error;
soxr_quality_spec_t q_spec = soxr_quality_spec(q_recipe &65535, q_recipe>>16);
soxr_quality_spec_t q_spec = soxr_quality_spec(q_recipe, q_flags);
soxr_io_spec_t io_spec = soxr_io_spec(itype, otype);
soxr_runtime_spec_t runtime_spec = soxr_runtime_spec(!use_threads);
@@ -61,13 +66,12 @@ int main(int n, char const * arg[])
irate, orate, chans, &error, &io_spec, &q_spec, &runtime_spec);
if (!error) error = soxr_set_input_fn(resampler, input_fn, &isize);
STD_STDIO;
USE_STD_STDIO;
if (!error) {
#define olen 8000
void * resampled = malloc(osize * olen);
void * resampled = malloc(osize * iolen);
size_t actual;
do actual = soxr_output(resampler, resampled, olen);
do actual = soxr_output(resampler, resampled, iolen);
while (fwrite(resampled, osize, actual, stdout));
free(resampled);
@@ -75,7 +79,7 @@ int main(int n, char const * arg[])
clips = *soxr_num_clips(resampler); /* Can occur only with integer output.*/
soxr_delete(resampler);
}
fprintf(stderr, "%s %s; %lu clips; I/O: %s\n", arg0, soxr_strerror(error),
fprintf(stderr, "%-26s %s; %lu clips; I/O: %s\n", arg0, soxr_strerror(error),
(long unsigned)clips, errno? strerror(errno) : "no error");
return error || errno;
}