1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-10-10 16:43:33 +02:00

Update libsoxr to 0.1.1

This commit is contained in:
lllucius
2013-11-05 04:24:24 +00:00
parent 0413de548b
commit f510d21218
119 changed files with 9812 additions and 14927 deletions

View File

@@ -1,50 +1,50 @@
# 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_C_FLAGS})
link_libraries (${PROJECT_NAME})
file (GLOB SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.c)
foreach (fe ${SOURCES})
get_filename_component (f ${fe} NAME_WE)
add_executable (${f} ${fe})
endforeach ()
enable_testing ()
set (sweep_to_freq 22050)
set (leader 1)
set (len 16)
math (EXPR base_rate "${sweep_to_freq} + ${sweep_to_freq}")
macro (add_vector r)
set (output ${CMAKE_CURRENT_BINARY_DIR}/ref-${r}.s32)
add_custom_command (OUTPUT ${output} DEPENDS vector-gen ${CMAKE_CURRENT_LIST_FILE}
COMMAND vector-gen ${r} ${leader} ${len} ${sweep_to_freq} 1 ${output})
set (vectors ${output} ${vectors})
endmacro ()
macro (add_cmp_test from to bits)
set (name ${bits}-bit-perfect-${from}-${to})
add_test (NAME ${name} COMMAND ${CMAKE_COMMAND} -Dbits=${bits} -DBIN=${BIN} -DEXAMPLES_BIN=${EXAMPLES_BIN} -Dleader=${leader} -Dto=${to}
-Dfrom=${from} -Dlen=${len} -P ${CMAKE_CURRENT_SOURCE_DIR}/cmp-test.cmake)
add_vector (${from})
add_vector (${to})
endmacro ()
unset (test_bits)
if (WITH_SINGLE_PRECISION)
set (test_bits 20)
endif ()
if (WITH_DOUBLE_PRECISION)
set (test_bits ${test_bits} 24)
endif ()
foreach (b ${test_bits})
foreach (r 96000 65537)
add_cmp_test (${base_rate} ${r} ${b})
add_cmp_test (${r} ${base_rate} ${b})
endforeach ()
endforeach ()
add_custom_target (test-vectors ALL DEPENDS ${vectors})
# SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
# Licence for this file: LGPL v2.1 See LICENCE for details.
add_definitions (${PROJECT_C_FLAGS})
link_libraries (${PROJECT_NAME})
file (GLOB SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.c)
foreach (fe ${SOURCES})
get_filename_component (f ${fe} NAME_WE)
add_executable (${f} ${fe})
endforeach ()
enable_testing ()
set (sweep_to_freq 22050)
set (leader 1)
set (len 16)
math (EXPR base_rate "${sweep_to_freq} + ${sweep_to_freq}")
macro (add_vector r)
set (output ${CMAKE_CURRENT_BINARY_DIR}/ref-${r}.s32)
add_custom_command (OUTPUT ${output} DEPENDS vector-gen ${CMAKE_CURRENT_LIST_FILE}
COMMAND vector-gen ${r} ${leader} ${len} ${sweep_to_freq} 1 ${output})
set (vectors ${output} ${vectors})
endmacro ()
macro (add_cmp_test from to bits)
set (name ${bits}-bit-perfect-${from}-${to})
add_test (NAME ${name} COMMAND ${CMAKE_COMMAND} -Dbits=${bits} -DBIN=${BIN} -DEXAMPLES_BIN=${EXAMPLES_BIN} -Dleader=${leader} -Dto=${to}
-Dfrom=${from} -Dlen=${len} -P ${CMAKE_CURRENT_SOURCE_DIR}/cmp-test.cmake)
add_vector (${from})
add_vector (${to})
endmacro ()
unset (test_bits)
if (WITH_SINGLE_PRECISION)
set (test_bits 20)
endif ()
if (WITH_DOUBLE_PRECISION)
set (test_bits ${test_bits} 24)
endif ()
foreach (b ${test_bits})
foreach (r 96000 65537)
add_cmp_test (${base_rate} ${r} ${b})
add_cmp_test (${r} ${base_rate} ${b})
endforeach ()
endforeach ()
add_custom_target (test-vectors ALL DEPENDS ${vectors})

View File

@@ -1 +1 @@
A few tests on the pass-band performance; not a comprehensive test suite.
A few tests on the pass-band performance; not a comprehensive test suite.

View File

@@ -1,28 +1,30 @@
# SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
# Licence for this file: LGPL v2.1 See LICENCE for details.
if (${bits} STREQUAL 24)
set (quality 45)
else ()
set (quality 44)
endif ()
execute_process(COMMAND ${EXAMPLES_BIN}3-options-input-fn ${from} ${to} 1 2 2 ${quality} a
INPUT_FILE ref-${from}.s32
OUTPUT_FILE ${from}-${to}.s32
ERROR_VARIABLE test_error
RESULT_VARIABLE test_result)
if (test_result)
message (FATAL_ERROR "Resampling failure: ${test_error}")
endif ()
execute_process(COMMAND ${BIN}vector-cmp ref-${to}.s32 ${from}-${to}.s32 ${to} ${leader} ${len} ${bits} 98
OUTPUT_VARIABLE test_output
RESULT_VARIABLE test_result)
if (test_result)
message (FATAL_ERROR ${test_output})
else ()
message (STATUS ${test_output})
endif ()
# SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
# Licence for this file: LGPL v2.1 See LICENCE for details.
if (${bits} STREQUAL 24)
set (quality 45)
else ()
set (quality 44)
endif ()
set (output ${from}-${to}-${quality}.s32)
execute_process(COMMAND ${EXAMPLES_BIN}3-options-input-fn ${from} ${to} 1 2 2 ${quality} a
INPUT_FILE ref-${from}.s32
OUTPUT_FILE ${output}
ERROR_VARIABLE test_error
RESULT_VARIABLE test_result)
if (test_result)
message (FATAL_ERROR "Resampling failure: ${test_error}")
endif ()
execute_process(COMMAND ${BIN}vector-cmp ref-${to}.s32 ${output} ${to} ${leader} ${len} ${bits} 98
OUTPUT_VARIABLE test_output
RESULT_VARIABLE test_result)
if (test_result)
message (FATAL_ERROR ${test_output})
else ()
message (STATUS ${test_output})
endif ()

View File

@@ -1,29 +1,29 @@
#!/bin/bash
# SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
# Licence for this file: LGPL v2.1 See LICENCE for details.
len=8
#vg="valgrind --leak-check=full --show-reachable=yes"
$vg ./1-single-block
ir=96000
or=44100
for i in 1 2; do
prev=""
sox -r $ir -n 0.f32 synth $len sin 0+`expr $ir / 2`
for f in `find . -type f -executable -name "[2-4]*"`; do
$vg $f $ir $or < 0.f32 > $f.f32
test x$prev != x && cmp $f.f32 $prev
prev=$f.f32
done
or=96000
ir=44100
done
rm *.f32
rm ?.png
for n in 0 1 2 3; do
$vg ./5-variable-rate $n | sox -tf32 -r44100 -c1 - -n spectrogram -hwk -o $n.png -X 50
vg=""
done
#!/bin/bash
# SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
# Licence for this file: LGPL v2.1 See LICENCE for details.
len=8
#vg="valgrind --leak-check=full --show-reachable=yes"
$vg ./1-single-block
ir=96000
or=44100
for i in 1 2; do
prev=""
sox -r $ir -n 0.f32 synth $len sin 0+`expr $ir / 2`
for f in `find . -type f -executable -name "[2-4]*"`; do
$vg $f $ir $or < 0.f32 > $f.f32
test x$prev != x && cmp $f.f32 $prev
prev=$f.f32
done
or=96000
ir=44100
done
rm *.f32
rm ?.png
for n in 0 1 2 3; do
$vg ./5-variable-rate $n | sox -tf32 -r44100 -c1 - -n spectrogram -hwk -o $n.png -X 50
vg=""
done

View File

@@ -1,40 +1,40 @@
#!/bin/bash
# SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
# Licence for this file: LGPL v2.1 See LICENCE for details.
ir=96000
or=44100
len=16
f=0+48k
g=48k+0
ex=./3-options-input-fn
types=(f32 f64 s32 s16)
do_one() {
$ex $ir $or $c $1 $2 $3 < $c.${types[$1]} |
sox -t ${types[$2]} -r $or -c $c - -n spectrogram -X50 -hwk -z180 -o io$n$c.png
n=`expr $n + 1`
}
rm io??.png
j=2; test z$1 != z && j=$1
for c in `seq 1 $j`; do
for n in `seq 0 3`; do
sox -r $ir -n $c.${types[$n]} synth $len sin $f gain -.1
done
n=0
for m in `seq 0 3`; do do_one $m $m 4; done
do_one 1 2 5
do_one 2 0 5
do_one 3 2 4
do_one 0 3 4
f="$f sin $g"
g=48k:0
done
rm ?.[sf][0-9][0-9]
#!/bin/bash
# SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
# Licence for this file: LGPL v2.1 See LICENCE for details.
ir=96000
or=44100
len=16
f=0+48k
g=48k+0
ex=./3-options-input-fn
types=(f32 f64 s32 s16)
do_one() {
$ex $ir $or $c $1 $2 $3 < $c.${types[$1]} |
sox -t ${types[$2]} -r $or -c $c - -n spectrogram -X50 -hwk -z180 -o io$n$c.png
n=`expr $n + 1`
}
rm io??.png
j=2; test z$1 != z && j=$1
for c in `seq 1 $j`; do
for n in `seq 0 3`; do
sox -r $ir -n $c.${types[$n]} synth $len sin $f gain -.1
done
n=0
for m in `seq 0 3`; do do_one $m $m 4; done
do_one 1 2 5
do_one 2 0 5
do_one 3 2 4
do_one 0 3 4
f="$f sin $g"
g=48k:0
done
rm ?.[sf][0-9][0-9]

View File

@@ -1,21 +1,22 @@
#!/bin/sh
# SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
# Licence for this file: LGPL v2.1 See LICENCE for details.
# Warning: the intermediate signal (piped) is 3.2 Gbytes so may slug the
# system somewhat.
ex=./3-options-input-fn
q=6
rm lr.png
./vector-gen 1000 0 8 500 .9375 1.s32
$ex 1 1e5 1 2 1 $q < 1.s32 | $ex 1e5 1 1 1 2 $q > 2.s32
/usr/bin/sox -M -r 1k 1.s32 -r 1k 2.s32 -n spectrogram -hwk -z180 -o lr.png
display lr.png &
rm [12].s32
#!/bin/sh
# SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
# Licence for this file: LGPL v2.1 See LICENCE for details.
# Warning: the intermediate signal (piped) is 3.2 Gbytes so may slug the
# system somewhat.
ex=../examples/3-options-input-fn
q=6
r=1e5
rm lr.png
../tests/vector-gen 1000 0 8 500 .9375 1.s32
$ex 1 $r 1 2 1 $q < 1.s32 | $ex $r 1 1 1 2 $q > 2.s32
sox -M -r 1k 1.s32 -r 1k 2.s32 -n spectrogram -hwk -z180 -o lr.png
display lr.png &
rm [12].s32

View File

@@ -1,53 +1,53 @@
/* SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
* Licence for this file: LGPL v2.1 See LICENCE for details. */
/* Utility used to help test the library; not for general consumption.
*
* Compare two swept-sine files. */
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "../src/rint.h"
int main(int bit, char const * arg[])
{
FILE * f1 = fopen(arg[1], "rb"),
* f2 = fopen(arg[2], "rb");
double rate = atof (arg[3]), /* Rate for this vector */
leader_len = atof (arg[4]), /* Leader length in seconds */
len = atof (arg[5]), /* Sweep length (excl. leader_len) */
expect_bits= atof (arg[6]),
expect_bw = atof (arg[7]);
int32_t s1, s2;
long count = 0;
static long thresh[32];
double bw, prev = 0;
for (; fread(&s1, sizeof(s1), 1, f1) == 1 &&
fread(&s2, sizeof(s2), 1, f2) == 1; ++count) {
long diff = abs((int)(s1 - s2));
for (bit = 0; diff && bit < 32; bit++, diff >>= 1)
if ((diff & 1) && !thresh[bit])
thresh[bit] = count + 1;
}
if (count != (long)((leader_len + len) * rate + .5)) {
printf("incorrect file length\n");
exit(1);
}
for (bit = 0; bit < 32; ++bit) {
bw = ((double)thresh[bit] - 1) / rate - leader_len;
if (bit && bw >= 0 && (bw - prev) * 100 / len < .08) {
--bit;
break;
}
prev = bw;
}
bit = 32 - bit;
bw = bw * 100 / len;
printf("Bit perfect to %i bits, from DC to %.2f%% nyquist.\n", bit, bw);
return !(bit >= expect_bits && bw >= expect_bw);
}
/* SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
* Licence for this file: LGPL v2.1 See LICENCE for details. */
/* Utility used to help test the library; not for general consumption.
*
* Compare two swept-sine files. */
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "../src/rint.h"
int main(int bit, char const * arg[])
{
FILE * f1 = fopen(arg[1], "rb"),
* f2 = fopen(arg[2], "rb");
double rate = atof (arg[3]), /* Rate for this vector */
leader_len = atof (arg[4]), /* Leader length in seconds */
len = atof (arg[5]), /* Sweep length (excl. leader_len) */
expect_bits= atof (arg[6]),
expect_bw = atof (arg[7]);
int32_t s1, s2;
long count = 0;
static long thresh[32];
double bw, prev = 0;
for (; fread(&s1, sizeof(s1), 1, f1) == 1 &&
fread(&s2, sizeof(s2), 1, f2) == 1; ++count) {
long diff = abs((int)(s1 - s2));
for (bit = 0; diff && bit < 32; bit++, diff >>= 1)
if ((diff & 1) && !thresh[bit])
thresh[bit] = count + 1;
}
if (count != (long)((leader_len + len) * rate + .5)) {
printf("incorrect file length\n");
exit(1);
}
for (bit = 0; bit < 32; ++bit) {
bw = ((double)thresh[bit] - 1) / rate - leader_len;
if (bit && bw >= 0 && (bw - prev) * 100 / len < .08) {
--bit;
break;
}
prev = bw;
}
bit = 32 - bit;
bw = bw * 100 / len;
printf("Bit perfect to %i bits, from DC to %.2f%% nyquist.\n", bit, bw);
return !(bit >= expect_bits && bw >= expect_bw);
}

View File

@@ -1,56 +1,56 @@
/* SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
* Licence for this file: LGPL v2.1 See LICENCE for details. */
/* Utility used to help test the library; not for general consumption.
*
* Generate a swept sine to a file, with faded `lead-in' section. */
#define QUAD 0
#if QUAD
#include <quadmath.h>
#endif
#include "../examples/examples-common.h"
#if QUAD
#define modf modfq
#define cos cosq
#define sin sinq
#undef M_PI
#define M_PI M_PIq
#define real __float128
#define atof(x) strtoflt128(x, 0)
#else
#define real double
#include "rint.h"
#endif
int main(int i, char const * argv[])
{
real rate = atof(argv[1]), /* Rate for this vector */
lead_in_len = atof(argv[2]), /* Lead-in length in seconds */
len = atof(argv[3]), /* Sweep length (excl. lead_in_len) */
sweep_to_freq = atof(argv[4]), /* Sweep from DC to this freq. */
multiplier = atof(argv[5]), /* For headroom */
f1 = -sweep_to_freq / len * lead_in_len, f2 = sweep_to_freq,
n1 = rate * -lead_in_len, n2 = rate * len,
m = (f2 - f1) / (n2 - n1) / 2, dummy;
FILE * file = fopen(argv[6], "wb");
i = (int)n1;
if (!file || i != n1)
exit(1);
for (; i < (int)(n2 + .5); ++i) {
double d1 = multiplier * sin(2 * M_PI * modf(i * m * i / rate, &dummy));
double d = i < 0? d1 * (1 - cos(M_PI * (i + n1) / n1)) * .5 : d1;
#if QUAD
size_t actual = fwrite(&d, sizeof(d), 1, file);
#else
int32_t out = rint32(d * (32768. * 65536 - 1));
size_t actual = fwrite(&out, sizeof(out), 1, file);
#endif
if (actual != 1)
return 1;
}
return 0;
}
/* SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
* Licence for this file: LGPL v2.1 See LICENCE for details. */
/* Utility used to help test the library; not for general consumption.
*
* Generate a swept sine to a file, with faded `lead-in' section. */
#define QUAD 0
#if QUAD
#include <quadmath.h>
#endif
#include "../examples/examples-common.h"
#if QUAD
#define modf modfq
#define cos cosq
#define sin sinq
#undef M_PI
#define M_PI M_PIq
#define real __float128
#define atof(x) strtoflt128(x, 0)
#else
#define real double
#include "rint.h"
#endif
int main(int i, char const * argv[])
{
real rate = atof(argv[1]), /* Rate for this vector */
lead_in_len = atof(argv[2]), /* Lead-in length in seconds */
len = atof(argv[3]), /* Sweep length (excl. lead_in_len) */
sweep_to_freq = atof(argv[4]), /* Sweep from DC to this freq. */
multiplier = atof(argv[5]), /* For headroom */
f1 = -sweep_to_freq / len * lead_in_len, f2 = sweep_to_freq,
n1 = rate * -lead_in_len, n2 = rate * len,
m = (f2 - f1) / (n2 - n1) / 2, dummy;
FILE * file = fopen(argv[6], "wb");
i = (int)n1;
if (!file || i != n1)
exit(1);
for (; i < (int)(n2 + .5); ++i) {
double d1 = multiplier * sin(2 * M_PI * modf(i * m * i / rate, &dummy));
double d = i < 0? d1 * (1 - cos(M_PI * (i + n1) / n1)) * .5 : d1;
#if QUAD
size_t actual = fwrite(&d, sizeof(d), 1, file);
#else
int32_t out = rint32(d * (32768. * 65536 - 1));
size_t actual = fwrite(&out, sizeof(out), 1, file);
#endif
if (actual != 1)
return 1;
}
return 0;
}