1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-10-11 00:53:46 +02:00

Convert default resampler from libresample to libsoxr.

This commit is contained in:
v.audacity
2012-10-09 02:57:19 +00:00
parent de3bf9610a
commit 79faef4192
104 changed files with 13914 additions and 8 deletions

View File

@@ -0,0 +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_DEFS})
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} ${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} -Dobin=${obin} -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

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

View File

@@ -0,0 +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 A0045)
else ()
set (quality A0044)
endif ()
execute_process(COMMAND ${obin}3b-options-with-input-fn ${from} ${to} 1 2 2 ${quality}
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}")
#else ()
#message (STATUS ${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 ()

View File

@@ -0,0 +1,45 @@
#!/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=8
f=3k
f=0+48k
g=48k+0
ex=../examples/4-split-channels
#vg="valgrind --leak-check=full --show-reachable=yes "
ex="$vg../examples/3b-options-with-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 -X85 -hwk -z180 -o $n$c.png
n=`expr $n + 1`
}
rm *.png
j=1; 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]
#kv . 2> /dev/null

View File

@@ -0,0 +1,52 @@
/* SoX Resampler Library Copyright (c) 2012 robs@users.sourceforge.net
*
* 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

@@ -0,0 +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.
*
* Generate a swept sine to a file, with faded `lead-in' section. */
#define QUAD 0
#if QUAD
#include <quadmath.h>
#endif
#include "../examples/util.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]),
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[5], "wb");
i = (int)n1;
if (!file || i != n1)
exit(1);
for (; i < (int)(n2 + .5); ++i) {
double d1 = 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
fwrite(&d, sizeof(d), 1, file);
#else
int32_t out = rint32(d * (32768. * 65536 - 1));
fwrite(&out, sizeof(out), 1, file);
#endif
}
return 0;
}