improve test coverage of split-channel IO; common arguments for examples 3&4

master
Rob Sykes 2016-03-02 21:36:28 +00:00
parent e064aba6ac
commit 70bf36a1e3
3 changed files with 28 additions and 10 deletions

View File

@ -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 %

View File

@ -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 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.
*
* Aguments 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,8 +108,15 @@ int main(int n, char const * arg[])
size_t odone, written, need_input = 1, clips = 0;
soxr_error_t error;
soxr_t soxr;
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;

View File

@ -1,7 +1,7 @@
#!/bin/bash
set -e
# SoX Resampler Library Copyright (c) 2007-15 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.
# Tests IO
@ -20,8 +20,13 @@ types=(f32 f64 s32 s16)
zs=(180 180 180 180 180 120 120 120 120)
do_one() {
$tool $ir $or $c $1 $2 $3 < $c.${types[$1]} |
sox -t ${types[`expr $2 % 4`]} -r $or -c $c - -n spectrogram -X50 -hwk -z${zs[$n]} -o io$c$n.png -c "io-test i:${types[$1]} o:${types[`expr $2 % 4`]} ($2) q:$3"
it=${types[$1]}; ot=${types[`expr $2 % 4 || true`]}
$tool $ir $or $c $1 $2 $3 < $c.$it > a.$ot
sox -r $or -c $c a.$ot -n spectrogram -X50 -hwk -z${zs[$n]} -o io$c$n.png -c "io-test i:$it o:$ot ($2) q:$3"
./4-split-channels $ir $or $c $1 $2 $3 < $c.$it > b.$ot
[ $2 != 3 ] && cmp a.$ot b.$ot ||
test $(sox -mv-1 -r$or -c$c a.$ot -r$or -c$c b.$ot -n stats 2>&1 |grep Pk\ l|tr ' ' '\n'|grep '[0-9]'|uniq) = -84.29
rm [ab].$ot
n=`expr $n + 1`
}