From e47d6560af7be02a0a97f59338b3e176090a3709 Mon Sep 17 00:00:00 2001 From: Rob Sykes Date: Sun, 29 May 2016 20:47:44 +0100 Subject: [PATCH] clean-up --- CMakeLists.txt | 79 ++++++++++++------------ INSTALL | 37 +++++------ NEWS | 6 +- cmake/Modules/FindOpenMP.cmake | 38 ------------ cmake/Modules/FindSIMD32.cmake | 12 ++-- cmake/Modules/SetSystemProcessor.cmake | 58 +++++++++--------- examples/CMakeLists.txt | 12 ++-- go | 13 ++-- msvc/README | 27 +++++--- msvc/example1.vcproj | 82 +++++++++++++++++++++++++ msvc/libsoxr.sln | 29 +++++++++ msvc/libsoxr.vcproj | 80 +++++++++++++----------- msvc/soxr-config.h | 21 ++++--- soxr-config.h.in | 13 ++-- src/CMakeLists.txt | 8 +-- src/aliases.h | 2 +- src/avfft32s.c | 2 +- src/ccrw2.h | 4 +- src/constructors.c | 85 -------------------------- src/cr-core.c | 8 +-- src/cr.h | 4 +- src/{simd32-dev.h => dev32s.h} | 4 +- src/{simd64-dev.h => dev64s.h} | 4 +- src/fft4g32s.c | 2 +- src/fifo.h | 4 +- src/{avx.h => pffft-avx.h} | 0 src/pffft-wrap.c | 4 +- src/pffft.c | 2 +- src/{lsr.c => soxr-lsr.c} | 0 src/soxr-lsr.h | 2 +- src/soxr.c | 81 ++++++++++++++++++++++++ src/{simd.c => util-simd.c} | 0 src/{simd32.c => util32s.c} | 4 +- src/{simd32.h => util32s.h} | 4 +- src/{simd64.c => util64s.c} | 4 +- src/{simd64.h => util64s.h} | 4 +- src/vr-coefs.c | 3 + src/vr-coefs.h | 3 + tests/CMakeLists.txt | 2 +- tests/throughput-test.bat | 3 +- tests/throughput.c | 60 ++++++++++++------ 41 files changed, 469 insertions(+), 341 deletions(-) delete mode 100644 cmake/Modules/FindOpenMP.cmake create mode 100644 msvc/example1.vcproj create mode 100644 msvc/libsoxr.sln delete mode 100644 src/constructors.c rename src/{simd32-dev.h => dev32s.h} (95%) rename src/{simd64-dev.h => dev64s.h} (94%) rename src/{avx.h => pffft-avx.h} (100%) rename src/{lsr.c => soxr-lsr.c} (100%) rename src/{simd.c => util-simd.c} (100%) rename src/{simd32.c => util32s.c} (80%) rename src/{simd32.h => util32s.h} (92%) rename src/{simd64.c => util64s.c} (80%) rename src/{simd64.h => util64s.h} (92%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 60a5c33..4fbe632 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,11 +16,10 @@ set (PROJECT_VERSION_MINOR 1) set (PROJECT_VERSION_PATCH 2) # For shared-object; if, since the last public release: -# -# 1) library code changed at all: ++revision -# 2) interfaces changed at all: ++current, revision = 0 -# 3) interfaces added: ++age -# 4) interfaces removed: age = 0 +# 1) library code changed at all: ++revision +# 2) interfaces changed at all: ++current, revision = 0 +# 3) interfaces added: ++age +# 4) interfaces removed: age = 0 set (SO_VERSION_CURRENT 1) set (SO_VERSION_REVISION 1) @@ -97,15 +96,20 @@ if (NEED_LIBM) set (LIBM_LIBRARIES m) endif () +if (${BUILD_EXAMPLES}) + project (${PROJECT_NAME}) # Adds c++ compiler +endif () + if (WITH_OPENMP) find_package (OpenMP) - if (OpenMP_FOUND) + if (OPENMP_FOUND) set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") - set (CMAKE_EXE_LINKER_FLAGS - "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}") - set (CMAKE_SHARED_LINKER_FLAGS - "${CMAKE_SHARED_LINKER_FLAGS} ${OpenMP_SHARED_LINKER_FLAGS}") - endif () + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") + if (MINGW) # Is this still needed? + set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_C_FLAGS}") + set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${OpenMP_C_FLAGS}") + endif () + endif() endif () if (WITH_CR32S) @@ -145,15 +149,14 @@ test_big_endian (HAVE_BIGENDIAN) # Compiler configuration: if (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "Clang") - set (PROJECT_CXX_FLAGS "${PROJECT_CXX_FLAGS} -Wconversion -Wall -Wextra") - set (PROJECT_CXX_FLAGS "${PROJECT_CXX_FLAGS} -pedantic -Wundef -Wpointer-arith") - set (PROJECT_CXX_FLAGS "${PROJECT_CXX_FLAGS} -Wno-long-long -Wno-keyword-macro") + set (PROJECT_CXX_FLAGS "${PROJECT_CXX_FLAGS} -Wconversion -Wall -Wextra \ + -pedantic -Wundef -Wpointer-arith -Wno-long-long -Wno-keyword-macro") if (WITH_DEV_GPROF) set (PROJECT_CXX_FLAGS "${PROJECT_CXX_FLAGS} -pg") endif () # Can use std=c89, but gnu89 should give faster sinf, cosf, etc.: - set (PROJECT_C_FLAGS "${PROJECT_CXX_FLAGS} -std=gnu89 -Wnested-externs") - set (PROJECT_C_FLAGS "${PROJECT_C_FLAGS} -Wmissing-prototypes -Wstrict-prototypes") + set (PROJECT_C_FLAGS "${PROJECT_CXX_FLAGS} \ + -std=gnu89 -Wnested-externs -Wmissing-prototypes -Wstrict-prototypes") if (CMAKE_BUILD_TYPE STREQUAL "Release") set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -s") # strip endif () @@ -208,6 +211,10 @@ if (BUILD_SHARED_LIBS) endif () endif () +if (CMAKE_BUILD_TYPE STREQUAL "None") # As used by some distros. + add_definitions (-DNDEBUG) +endif () + # Installation configuration: @@ -277,24 +284,21 @@ endif () -# Rough-and-ready distclean for anyone still doing in-tree builds: +# GNU Autotools compatibility; 'make check': + +add_custom_target (check COMMAND ${CMAKE_CTEST_COMMAND}) + + + +# GNU Autotools compatibility; 'make distclean': if (UNIX) - add_custom_target (distclean - COMMAND make clean && rm -rf - CMakeCache.txt - CMakeFiles - cmake_install.cmake - CPackConfig.cmake - CPackSourceConfig.cmake - deinstall.cmake - Makefile - soxr-config.h - src/CMakeFiles - src/cmake_install.cmake - src/libsoxr-lsr.pc - src/libsoxr.pc - src/Makefile) + add_custom_target (distclean COMMAND make clean && find . + \\! -path \\*/Modules/\\* \\! -name cmp-test.cmake -a -name \\*.cmake + -o -name CMakeFiles -o -name Makefile -o -name CMakeCache.txt -o -name + Testing -o -name cmake_install.cmake -o -name install_manifest.txt -o + -path ./soxr-config.h -o -name config.h -o -name \\*.pc -o -name \\*.s32 + | xargs rm -rf) endif () @@ -317,13 +321,8 @@ if (UNIX) set (CPACK_PACKAGE_VERSION_MAJOR "${PROJECT_VERSION_MAJOR}") set (CPACK_PACKAGE_VERSION_MINOR "${PROJECT_VERSION_MINOR}") set (CPACK_PACKAGE_VERSION_PATCH "${PROJECT_VERSION_PATCH}") - - set (CPACK_SOURCE_GENERATOR "TGZ") - set (CPACK_SOURCE_IGNORE_FILES "dist;/lsr-tests/;/Debug/;/Release/;/cpack/;\\\\.swp$;\\\\.gitignore;/\\\\.git/") - + set (CPACK_SOURCE_GENERATOR "TGZ") # Use TXZ (cmake 3.1) after 17-12-16 + set (CPACK_SOURCE_IGNORE_FILES + "dist;/lsr-tests/;/Debug.*/;/Release.*/;\\\\.swp$;\\\\.git.*;/\\\\.git/") include (CPack) - - if (IS_DIRECTORY ${PROJECT_SOURCE_DIR}/cpack) - add_subdirectory (cpack) - endif () endif () diff --git a/INSTALL b/INSTALL index c429e61..5599870 100644 --- a/INSTALL +++ b/INSTALL @@ -21,7 +21,7 @@ STANDARD BUILD * A 'make' utility (most compiler installations already have one of these). - * CMake: https://cmake.org/download/ + * CMake v3.0 or newer: https://cmake.org/download/ 2. Build: @@ -61,30 +61,32 @@ STANDARD BUILD BUILD CUSTOMISATION -If it is necessary to customise the build, then steps 2 and 3 above may be -substituted as follows. Change directory to the one containing this file, -then enter commands along the lines of: +If it is necessary to customise the build, then steps 2 and 3 above should be +substituted as follows: change directory to the one containing this file, then +enter commands along the lines: mkdir build cd build - cmake [OPTIONS] .. + cmake -Wno-dev -DCMAKE_BUILD_TYPE=Release [OPTIONS] .. make make test sudo make install +N.B. The CMAKE_BUILD_TYPE to use for library deployment is Release. + To list help on the available options, enter: cmake -LH .. Options, if given, should be preceded with '-D', e.g. - cmake -DBUILD_SHARED_LIBS:BOOL=OFF .. + -DBUILD_SHARED_LIBS:BOOL=OFF Resampling engines -As available on a given system, options for including up to five resampling +As available on a given system, options for including up-to five resampling ‘engines’ are available (per above) as follows: WITH_CR32: for constant-rate HQ resampling, @@ -98,7 +100,9 @@ By default, these options are all set to ON. When both SIMD and non-SIMD engine variants are included, run-time selection is automatic (based on CPU capability) for x86 CPUs, and can be automatic for ARM CPUs if the 3rd-party library `libavutil' is available at libsoxr -build-time. +build-time. Which engine has been selected for a specific configuration and +invocation of the library can be checked using example #3, which reports it. +See also Run-time Configuration, below. @@ -153,7 +157,7 @@ Autotools-based systems might find it useful to create a file called cmake -DBUILD_SHARED_LIBS=OFF . (or with other build options as required). -For MS Visual C++, see msvc/README. +For MS Visual Studio, see msvc/README. @@ -161,11 +165,11 @@ RUN-TIME CONFIGURATION The libsoxr API structure ‘soxr_runtime_spec_t’ allows application developers to optimise some aspects of libsoxr’s operation for a particular application. -However, since optimal performance might depend on an individual end-user’s -run-time system and the end-user’s preferences, environment variables are +Optimal performance however, might depend on an individual end-user’s run- +time system and the end-user’s preferences. Hence environment variables are available to set (override) run-time parameters as follows: - Env. variable Equivalent soxr_runtime_spec_t item + Env. variable Equivalent soxr_runtime_spec_t item (see soxr.h) ------------------ ----------------------------------- SOXR_COEFS_SIZE coef_size_kbytes SOXR_COEF_INTERP SOXR_COEF_INTERP_xxx @@ -173,8 +177,7 @@ available to set (override) run-time parameters as follows: SOXR_MIN_DFT_SIZE log2_min_dft_size SOXR_NUM_THREADS num_threads -Additionally, the SOXR_USE_SIMD32 and SOXR_USE_SIMD64 environment variables -may be used to override automatic selection (or to provide manual selection -where automatic selection is not available) between SIMD and non-SIMD engine -variants. (Which engine is selected for a specific configuration of libsoxr -can be checked using example #3, which reports it.) +Additionally, the SOXR_USE_SIMD32 and SOXR_USE_SIMD64 boolean environment +variables can be used to override automatic selection (or to provide manual +selection where automatic selection is not available) between SIMD and +non-SIMD engine variants. diff --git a/NEWS b/NEWS index d368fa2..4252447 100644 --- a/NEWS +++ b/NEWS @@ -1,8 +1,8 @@ Version 0.1.3 (2016-mm-dd) * SIMD enhancements: SSE, AVX, Neon. - * Improved support for clang, ARM, and cross-compilation. - * Other minor fixes/improvements to build/tests/documentation. - * N.B. some cmake configuration variable name changes. + * Improve support for clang, ARM, and cross-compilation. + * Provide env. var. override of runtime parameters. + * N.B. some build configuration name changes; see INSTALL. Version 0.1.2 (2015-09-05) * Fix conversion failure when I/O types differ but I/O rates don't. diff --git a/cmake/Modules/FindOpenMP.cmake b/cmake/Modules/FindOpenMP.cmake deleted file mode 100644 index 3664eed..0000000 --- a/cmake/Modules/FindOpenMP.cmake +++ /dev/null @@ -1,38 +0,0 @@ -# SoX Resampler Library Copyright (c) 2007-16 robs@users.sourceforge.net -# Licence for this file: LGPL v2.1 See LICENCE for details. - -# - Finds OpenMP support -# -# The following variables are set: -# OpenMP_C_FLAGS - flags to add to the C compiler for this package. -# OpenMP_FOUND - true if support for this package is found. - -if (DEFINED OpenMP_C_FLAGS) - set (TRIAL_C_FLAGS) -else () - set (TRIAL_C_FLAGS - "-fopenmp" # Gnu - "-fopenmp=libiomp5" # Clang - "/openmp" # MSVC - " " - ) - - set (TEST_C_SOURCE " - #ifndef _OPENMP - #error - #endif - #include - int main() {return 0;} - ") -endif () - -include (FindCFlags) - -FindCFlags ("OpenMP" "OpenMP threading" - "${TRIAL_C_FLAGS}" "${TEST_C_SOURCE}") - -if (MINGW) - set (OpenMP_SHARED_LINKER_FLAGS "${OpenMP_SHARED_LINKER_FLAGS} ${OpenMP_C_FLAGS}") - set (OpenMP_EXE_LINKER_FLAGS "${OpenMP_EXE_LINKER_FLAGS} ${OpenMP_C_FLAGS}") - mark_as_advanced (OpenMP_SHARED_LINKER_FLAGS OpenMP_EXE_LINKER_FLAGS) -endif () diff --git a/cmake/Modules/FindSIMD32.cmake b/cmake/Modules/FindSIMD32.cmake index fdb9074..9e42373 100644 --- a/cmake/Modules/FindSIMD32.cmake +++ b/cmake/Modules/FindSIMD32.cmake @@ -19,9 +19,9 @@ elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "^arm") ) set (TEST_C_SOURCE " #include - int main() { - float32x4_t a = vdupq_n_f32(0), b = a, c = vaddq_f32(a,b); - return 0; + int main(int c, char * * v) { + float32x4_t a = vdupq_n_f32((float)c), b = vdupq_n_f32((float)!!v); + return !vgetq_lane_u32(vceqq_f32(a,b),0); } ") else () @@ -41,9 +41,9 @@ else () ) set (TEST_C_SOURCE " #include - int main() { - __m128 a = _mm_setzero_ps(), b = a, c = _mm_add_ps(a,b); - return 0; + int main(int c, char * * v) { + __m128 a = _mm_set_ss((float)c), b = _mm_set_ss((float)!!v); + return _mm_comineq_ss(a,b); } ") endif () diff --git a/cmake/Modules/SetSystemProcessor.cmake b/cmake/Modules/SetSystemProcessor.cmake index 30cae54..8e2c292 100644 --- a/cmake/Modules/SetSystemProcessor.cmake +++ b/cmake/Modules/SetSystemProcessor.cmake @@ -1,35 +1,37 @@ # SoX Resampler Library Copyright (c) 2007-16 robs@users.sourceforge.net # Licence for this file: LGPL v2.1 See LICENCE for details. -# Sets CMAKE_SYSTEM_PROCESSOR (for cross-compiling). +# Sets CMAKE_SYSTEM_PROCESSOR for cross-compiling. macro (set_system_processor) - if ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "" OR "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "unknown") - unset(CMAKE_SYSTEM_PROCESSOR) - endif () - if (NOT DEFINED CMAKE_SYSTEM_PROCESSOR) - include (CheckCSourceCompiles) - set (CPU_LINES - "#if defined __x86_64__ || defined _M_X64 /*\;x86_64\;*/" - "#if defined __i386__ || defined _M_IX86 /*\;x86_32\;*/" - "#if defined __arm__ || defined _M_ARM /*\;arm\;*/" - ) - foreach (CPU_LINE ${CPU_LINES}) - string (CONCAT CPU_SOURCE "${CPU_LINE}" " - int main() {return 0;} - #endif - ") - unset (SYSTEM_PROCESSOR_DETECTED CACHE) - check_c_source_compiles ("${CPU_SOURCE}" SYSTEM_PROCESSOR_DETECTED) - if (SYSTEM_PROCESSOR_DETECTED) - list (GET CPU_LINE 1 CMAKE_SYSTEM_PROCESSOR) - message (STATUS "CMAKE_SYSTEM_PROCESSOR is ${CMAKE_SYSTEM_PROCESSOR}") - break () - endif () - endforeach () - endif () + if (CMAKE_CROSSCOMPILING) + if ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "" OR "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "unknown") + unset(CMAKE_SYSTEM_PROCESSOR) + endif () + if (NOT DEFINED CMAKE_SYSTEM_PROCESSOR) + include (CheckCSourceCompiles) + set (CPU_LINES + "#if defined __x86_64__ || defined _M_X64 /*\;x86_64\;*/" + "#if defined __i386__ || defined _M_IX86 /*\;x86_32\;*/" + "#if defined __arm__ || defined _M_ARM /*\;arm\;*/" + ) + foreach (CPU_LINE ${CPU_LINES}) + string (CONCAT CPU_SOURCE "${CPU_LINE}" " + int main() {return 0;} + #endif + ") + unset (SYSTEM_PROCESSOR_DETECTED CACHE) + check_c_source_compiles ("${CPU_SOURCE}" SYSTEM_PROCESSOR_DETECTED) + if (SYSTEM_PROCESSOR_DETECTED) + list (GET CPU_LINE 1 CMAKE_SYSTEM_PROCESSOR) + message (STATUS "CMAKE_SYSTEM_PROCESSOR is ${CMAKE_SYSTEM_PROCESSOR}") + break () + endif () + endforeach () + endif () - # N.B. Will not overwrite existing cache variable: - set (CMAKE_SYSTEM_PROCESSOR "${CMAKE_SYSTEM_PROCESSOR}" - CACHE STRING "Target system processor") + # N.B. Will not overwrite existing cache variable: + set (CMAKE_SYSTEM_PROCESSOR "${CMAKE_SYSTEM_PROCESSOR}" + CACHE STRING "Target system processor") + endif () endmacro () diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 7a95823..c8c17c9 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,6 +1,10 @@ # SoX Resampler Library Copyright (c) 2007-16 robs@users.sourceforge.net # Licence for this file: LGPL v2.1 See LICENCE for details. +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}) @@ -9,20 +13,12 @@ if (${BUILD_EXAMPLES} OR ${BUILD_TESTS}) endif () if (${BUILD_EXAMPLES}) - project (soxr) # Adds c++ compiler list (APPEND SOURCES 1-single-block 2-stream 4-split-channels) if (${WITH_VR32}) list (APPEND SOURCES 5-variable-rate) endif () endif () -if (NOT BUILD_SHARED_LIBS AND OPENMP_FOUND) - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_C_FLAGS}") -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}) - foreach (fe ${SOURCES} ${LSR_SOURCES}) get_filename_component (f ${fe} NAME_WE) add_executable (${f} ${fe}) diff --git a/go b/go index 5e9a04f..7fba810 100755 --- a/go +++ b/go @@ -1,19 +1,18 @@ #!/bin/sh set -e -# 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. -case $1 in -j*) j=$1; shift;; esac # Support -jX for parallel build/test +case "$1" in -j*) j="$1"; shift;; esac # Support -jX for parallel build/test -build=$1 -test x$build = x && build=Release +test x"$1" = x && build=Release || build="$1" rm -f CMakeCache.txt # Prevent interference from any in-tree build -mkdir -p $build -cd $build +mkdir -p "$build" +cd "$build" -cmake -DCMAKE_BUILD_TYPE=$build -Wno-dev .. +cmake -Wno-dev -DCMAKE_BUILD_TYPE="$build" .. make $j ctest $j || echo "FAILURE details in $build/Testing/Temporary/LastTest.log" diff --git a/msvc/README b/msvc/README index 5a34eba..5b7f60a 100644 --- a/msvc/README +++ b/msvc/README @@ -1,9 +1,22 @@ -SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net +SoX Resampler Library Copyright (c) 2007-16 robs@users.sourceforge.net -Cmake is able to configure, build (as either a DLL or a static library), -and install libsoxr for general use on MS-Windows as on other OSs. -However, for projects that prefer to maintain a more monolithic build -structure using the MSVC compiler, the accompanying files may be useful. +Cmake is the recommended way to configure, build (as either a DLL or a static +library), and install libsoxr for general use on MS-Windows, as on other OSs. - * libsoxr.vcproj Builds a static lib for MSVC ver >= 9 (2008). - * soxr-config.h Pre-configured for a typical Win32 system. +However, building within MS Visual Studio is also possible, as exemplified by +the accompanying files: + + * soxr-config.h Pre-configured for a modern Win32 system. + + * libsoxr.vcproj Builds the library as a DLL, per above. + + * libsoxr.sln, Build an example exe using the above. + example1.vcproj + +The following notes apply to adaptation of these files: + + * For a system without AVX support, set WITH_CR64S to 0 in + soxr-config.h and exclude the three files ...64s.c from the build. + + * If changing libsoxr.vcproj to build a static library, then also + remove the preprocessor definition: SOXR_DLL. diff --git a/msvc/example1.vcproj b/msvc/example1.vcproj new file mode 100644 index 0000000..1523855 --- /dev/null +++ b/msvc/example1.vcproj @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/msvc/libsoxr.sln b/msvc/libsoxr.sln new file mode 100644 index 0000000..bb3e9c7 --- /dev/null +++ b/msvc/libsoxr.sln @@ -0,0 +1,29 @@ + +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual C++ Express 2008 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example1", "example1.vcproj", "{CA28595B-B14F-45FD-BA56-FBDFFB70FFC4}" + ProjectSection(ProjectDependencies) = postProject + {4916B0C1-2F99-433A-B88A-A99CB4E1E0AB} = {4916B0C1-2F99-433A-B88A-A99CB4E1E0AB} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libsoxr", "libsoxr.vcproj", "{4916B0C1-2F99-433A-B88A-A99CB4E1E0AB}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Release|Win32 = Release|Win32 + Debug|Win32 = Debug|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {CA28595B-B14F-45FD-BA56-FBDFFB70FFC4}.Release|Win32.ActiveCfg = Release|Win32 + {CA28595B-B14F-45FD-BA56-FBDFFB70FFC4}.Release|Win32.Build.0 = Release|Win32 + {CA28595B-B14F-45FD-BA56-FBDFFB70FFC4}.Debug|Win32.ActiveCfg = Debug|Win32 + {CA28595B-B14F-45FD-BA56-FBDFFB70FFC4}.Debug|Win32.Build.0 = Debug|Win32 + {4916B0C1-2F99-433A-B88A-A99CB4E1E0AB}.Release|Win32.ActiveCfg = Release|Win32 + {4916B0C1-2F99-433A-B88A-A99CB4E1E0AB}.Release|Win32.Build.0 = Release|Win32 + {4916B0C1-2F99-433A-B88A-A99CB4E1E0AB}.Debug|Win32.ActiveCfg = Debug|Win32 + {4916B0C1-2F99-433A-B88A-A99CB4E1E0AB}.Debug|Win32.Build.0 = Debug|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/msvc/libsoxr.vcproj b/msvc/libsoxr.vcproj index 2dd7be0..65ee42d 100644 --- a/msvc/libsoxr.vcproj +++ b/msvc/libsoxr.vcproj @@ -3,9 +3,10 @@ ProjectType="Visual C++" Version="9.00" Name="libsoxr" - ProjectGUID="{af9ad75c-4785-4432-bac3-adab1e7f1192}" + ProjectGUID="{4916B0C1-2F99-433A-B88A-A99CB4E1E0AB}" RootNamespace="libsoxr" - TargetFrameworkVersion="131072" + Keyword="Win32Proj" + TargetFrameworkVersion="196613" > @@ -17,68 +18,79 @@ Name="Debug|Win32" OutputDirectory="$(SolutionDir)$(ConfigurationName)" IntermediateDirectory="$(ConfigurationName)" - ConfigurationType="4" - CharacterSet="2" - WholeProgramOptimization="0" + ConfigurationType="2" + CharacterSet="1" > + + - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + diff --git a/msvc/soxr-config.h b/msvc/soxr-config.h index a1fcfb4..d17ae6b 100644 --- a/msvc/soxr-config.h +++ b/msvc/soxr-config.h @@ -1,26 +1,27 @@ /* SoX Resampler Library Copyright (c) 2007-16 robs@users.sourceforge.net * Licence for this file: LGPL v2.1 See LICENCE for details. */ -/* N.B. Pre-configured for typical MS-Windows systems. However, the normal +/* N.B. Pre-configured for modern MS-Windows systems. However, the normal * procedure is to use the cmake configuration and build system. See INSTALL. */ #if !defined soxr_config_included #define soxr_config_included +#define AVCODEC_FOUND 0 +#define AVUTIL_FOUND 0 + +#define HAVE_FENV_H 1 +#define HAVE_STDBOOL_H 1 +#define HAVE_STDINT_H 1 +#define HAVE_LRINT 1 +#define HAVE_BIGENDIAN 0 + #define WITH_CR32 1 #define WITH_CR32S 1 #define WITH_CR64 1 #define WITH_CR64S 1 #define WITH_VR32 1 -#define AVCODEC_FOUND 0 -#define AVUTIL_FOUND 0 - -#define HAVE_FENV_H 0 -#define HAVE_STDBOOL_H 0 -#define HAVE_STDINT_H 0 -#define HAVE_LRINT 0 -#define HAVE_BIGENDIAN 0 -#define WITH_DEV_TRACE 0 +#define WITH_DEV_TRACE 1 #endif diff --git a/soxr-config.h.in b/soxr-config.h.in index 37ccdb2..8d654d8 100644 --- a/soxr-config.h.in +++ b/soxr-config.h.in @@ -4,12 +4,6 @@ #if !defined soxr_config_included #define soxr_config_included -#cmakedefine01 WITH_CR32 -#cmakedefine01 WITH_CR32S -#cmakedefine01 WITH_CR64 -#cmakedefine01 WITH_CR64S -#cmakedefine01 WITH_VR32 - #cmakedefine01 AVCODEC_FOUND #cmakedefine01 AVUTIL_FOUND @@ -18,6 +12,13 @@ #cmakedefine01 HAVE_STDINT_H #cmakedefine01 HAVE_LRINT #cmakedefine01 HAVE_BIGENDIAN + +#cmakedefine01 WITH_CR32 +#cmakedefine01 WITH_CR32S +#cmakedefine01 WITH_CR64 +#cmakedefine01 WITH_CR64S +#cmakedefine01 WITH_VR32 + #cmakedefine01 WITH_DEV_TRACE #endif diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 67d34d7..3c45b13 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -35,7 +35,7 @@ elseif (WITH_CR32S) set (RDFT32S fft4g32s fft4g32) endif () -set (SOURCES ${PROJECT_NAME}.c constructors data-io) +set (SOURCES ${PROJECT_NAME}.c data-io) if (WITH_CR32 OR WITH_CR32S OR WITH_CR64 OR WITH_CR64S) list (APPEND SOURCES dbesi0 filter fft4g64 cr.c) @@ -54,7 +54,7 @@ if (WITH_VR32) endif () if (WITH_CR32S) - foreach (source cr32s ${RDFT32S} simd32) + foreach (source cr32s ${RDFT32S} util32s) list (APPEND SOURCES ${source}) set_property (SOURCE ${source} APPEND_STRING PROPERTY COMPILE_FLAGS ${SIMD32_C_FLAGS}) @@ -62,7 +62,7 @@ if (WITH_CR32S) endif () if (WITH_CR64S) - foreach (source cr64s pffft64s simd64) + foreach (source cr64s pffft64s util64s) list (APPEND SOURCES ${source}) set_property (SOURCE ${source} APPEND_STRING PROPERTY COMPILE_FLAGS ${SIMD64_C_FLAGS}) @@ -97,7 +97,7 @@ if (WITH_LSR_BINDINGS) set (LSR ${PROJECT_NAME}-lsr) set (LSR_SO_VERSION 0.1.9) set (LSR_SO_VERSION_MAJOR 0) - add_library (${LSR} ${LIB_TYPE} lsr) + add_library (${LSR} ${LIB_TYPE} ${LSR}) target_link_libraries (${LSR} ${PROJECT_NAME}) set_target_properties (${LSR} PROPERTIES VERSION "${LSR_SO_VERSION}" diff --git a/src/aliases.h b/src/aliases.h index ebcce41..d1a392f 100644 --- a/src/aliases.h +++ b/src/aliases.h @@ -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. */ #if defined SOXR_LIB diff --git a/src/avfft32s.c b/src/avfft32s.c index 8b1da80..5a7e62d 100644 --- a/src/avfft32s.c +++ b/src/avfft32s.c @@ -3,7 +3,7 @@ #include #include -#include "simd32.h" +#include "util32s.h" #include "rdft_t.h" static void * forward_setup(int len) {return av_rdft_init((int)(log(len)/log(2)+.5),DFT_R2C);} diff --git a/src/ccrw2.h b/src/ccrw2.h index b42185b..09331a4 100644 --- a/src/ccrw2.h +++ b/src/ccrw2.h @@ -3,8 +3,8 @@ /* Concurrent Control with "Readers" and "Writers", P.J. Courtois et al, 1971 */ -#if !defined ccrw2_included -#define ccrw2_included +#if !defined soxr_ccrw2_included +#define soxr_ccrw2_included #if defined SOXR_LIB #include "internal.h" diff --git a/src/constructors.c b/src/constructors.c deleted file mode 100644 index 0128990..0000000 --- a/src/constructors.c +++ /dev/null @@ -1,85 +0,0 @@ -/* SoX Resampler Library Copyright (c) 2007-16 robs@users.sourceforge.net - * Licence for this file: LGPL v2.1 See LICENCE for details. */ - -#include "soxr.h" -#include "filter.h" -#include "internal.h" -#include -#include -#include - -#if !WITH_CR32 && !WITH_CR32S && !WITH_CR64 && !WITH_CR64S -#undef lsx_to_3dB -#define lsx_to_3dB(x) ((x)/(x)) -#endif - - - -soxr_quality_spec_t soxr_quality_spec(unsigned long recipe, unsigned long flags) -{ - soxr_quality_spec_t spec, * p = &spec; - unsigned quality = recipe & 0xf; - double rej; - memset(p, 0, sizeof(*p)); - if (quality > SOXR_PRECISIONQ) { - p->e = "invalid quality type"; - return spec; - } - flags |= quality < SOXR_LSR0Q ? RESET_ON_CLEAR : 0; - p->phase_response = "\62\31\144"[(recipe & 0x30)>>4]; - p->stopband_begin = 1; - p->precision = - quality == SOXR_QQ ? 0 : - quality <= SOXR_16_BITQ ? 16 : - quality <= SOXR_32_BITQ ? 4 + quality * 4 : - quality <= SOXR_LSR2Q ? 55 - quality * 4 : /* TODO: move to lsr.c */ - 0; - rej = p->precision * linear_to_dB(2.); - p->flags = flags; - if (quality <= SOXR_32_BITQ || quality == SOXR_PRECISIONQ) { - #define LOW_Q_BW0 (1385 / 2048.) /* 0.67625 rounded to be a FP exact. */ - p->passband_end = quality == 1? LOW_Q_BW0 : 1 - .05 / lsx_to_3dB(rej); - if (quality <= 2) - p->flags &= ~SOXR_ROLLOFF_NONE, p->flags |= SOXR_ROLLOFF_MEDIUM; - } - else { /* TODO: move to lsr.c */ - static float const bw[] = {.931f, .832f, .663f}; - p->passband_end = bw[quality - SOXR_LSR0Q]; - if (quality == SOXR_LSR2Q) - p->flags &= ~SOXR_ROLLOFF_NONE, p->flags |= SOXR_ROLLOFF_LSR2Q | SOXR_PROMOTE_TO_LQ; - } - if (recipe & SOXR_STEEP_FILTER) - p->passband_end = 1 - .01 / lsx_to_3dB(rej); - return spec; -} - - - -soxr_runtime_spec_t soxr_runtime_spec(unsigned num_threads) -{ - soxr_runtime_spec_t spec, * p = &spec; - memset(p, 0, sizeof(*p)); - p->log2_min_dft_size = 10; - p->log2_large_dft_size = 17; - p->coef_size_kbytes = 400; - p->num_threads = num_threads; - return spec; -} - - - -soxr_io_spec_t soxr_io_spec( - soxr_datatype_t itype, - soxr_datatype_t otype) -{ - soxr_io_spec_t spec, * p = &spec; - memset(p, 0, sizeof(*p)); - if ((itype | otype) >= SOXR_SPLIT * 2) - p->e = "invalid io datatype(s)"; - else { - p->itype = itype; - p->otype = otype; - p->scale = 1; - } - return spec; -} diff --git a/src/cr-core.c b/src/cr-core.c index bc6282c..3f35ff0 100644 --- a/src/cr-core.c +++ b/src/cr-core.c @@ -31,11 +31,11 @@ #if CORE_TYPE & (CORE_SIMD_POLY|CORE_SIMD_HALF|CORE_SIMD_DFT) #if CORE_TYPE & CORE_DBL - #include "simd64.h" - #include "simd64-dev.h" + #include "util64s.h" + #include "dev64s.h" #else - #include "simd32.h" - #include "simd32-dev.h" + #include "util32s.h" + #include "dev32s.h" #endif #endif diff --git a/src/cr.h b/src/cr.h index 7e20327..1b707e6 100644 --- a/src/cr.h +++ b/src/cr.h @@ -1,8 +1,8 @@ /* SoX Resampler Library Copyright (c) 2007-16 robs@users.sourceforge.net * Licence for this file: LGPL v2.1 See LICENCE for details. */ -#if !defined soxr_rate1_included -#define soxr_rate1_included +#if !defined soxr_cr_included +#define soxr_cr_included #define FIFO_SIZE_T int #include "fifo.h" diff --git a/src/simd32-dev.h b/src/dev32s.h similarity index 95% rename from src/simd32-dev.h rename to src/dev32s.h index 0408758..7edae86 100644 --- a/src/simd32-dev.h +++ b/src/dev32s.h @@ -1,8 +1,8 @@ /* SoX Resampler Library Copyright (c) 2007-16 robs@users.sourceforge.net * Licence for this file: LGPL v2.1 See LICENCE for details. */ -#if !defined soxr_simd_dev_included -#define soxr_simd_dev_included +#if !defined soxr_dev32s_included +#define soxr_dev32s_included #if defined __GNUC__ #define SIMD_INLINE(T) static __inline T __attribute__((always_inline)) diff --git a/src/simd64-dev.h b/src/dev64s.h similarity index 94% rename from src/simd64-dev.h rename to src/dev64s.h index 37484e4..4672210 100644 --- a/src/simd64-dev.h +++ b/src/dev64s.h @@ -1,8 +1,8 @@ /* SoX Resampler Library Copyright (c) 2007-16 robs@users.sourceforge.net * Licence for this file: LGPL v2.1 See LICENCE for details. */ -#if !defined soxr_simd64_dev_included -#define soxr_simd64_dev_included +#if !defined soxr_dev64s_included +#define soxr_dev64s_included #if defined __GNUC__ #define SIMD_INLINE(T) static __inline T __attribute__((always_inline)) diff --git a/src/fft4g32s.c b/src/fft4g32s.c index 34dae4b..8ce9726 100644 --- a/src/fft4g32s.c +++ b/src/fft4g32s.c @@ -2,7 +2,7 @@ * Licence for this file: LGPL v2.1 See LICENCE for details. */ #include "filter.h" -#include "simd.h" +#include "util32s.h" #include "rdft_t.h" static void * null(void) {return 0;} diff --git a/src/fifo.h b/src/fifo.h index 19f6c1d..33af9fe 100644 --- a/src/fifo.h +++ b/src/fifo.h @@ -1,8 +1,8 @@ /* SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net * Licence for this file: LGPL v2.1 See LICENCE for details. */ -#ifndef fifo_included -#define fifo_included +#ifndef soxr_fifo_included +#define soxr_fifo_included #if !defined FIFO_SIZE_T #define FIFO_SIZE_T size_t diff --git a/src/avx.h b/src/pffft-avx.h similarity index 100% rename from src/avx.h rename to src/pffft-avx.h diff --git a/src/pffft-wrap.c b/src/pffft-wrap.c index 806547c..c920f06 100644 --- a/src/pffft-wrap.c +++ b/src/pffft-wrap.c @@ -6,9 +6,9 @@ #include "math-wrap.h" #if PFFFT_DOUBLE - #include "simd64.h" + #include "util64s.h" #else - #include "simd32.h" + #include "util32s.h" #define sin(x) sinf(x) #define cos(x) cosf(x) #endif diff --git a/src/pffft.c b/src/pffft.c index 5729274..46c841e 100644 --- a/src/pffft.c +++ b/src/pffft.c @@ -151,7 +151,7 @@ typedef __m128 v4sf; # define VALIGNED(ptr) ((((long)(ptr)) & 0xF) == 0) #else -#include "avx.h" +#include "pffft-avx.h" #endif /* diff --git a/src/lsr.c b/src/soxr-lsr.c similarity index 100% rename from src/lsr.c rename to src/soxr-lsr.c diff --git a/src/soxr-lsr.h b/src/soxr-lsr.h index 2acd138..c0923aa 100644 --- a/src/soxr-lsr.h +++ b/src/soxr-lsr.h @@ -37,9 +37,9 @@ #endif typedef float SRC_SAMPLE; +#if !defined SOXR_LIB enum SRC_SRCTYPE_e {SRC_SINC_BEST_QUALITY, SRC_SINC_MEDIUM_QUALITY, SRC_SINC_FASTEST, SRC_ZERO_ORDER_HOLD, SRC_LINEAR}; -#if !defined SOXR_LIB typedef int SRC_SRCTYPE; typedef int SRC_ERROR; typedef long (* src_callback_t)(void *, SRC_SAMPLE * *); diff --git a/src/soxr.c b/src/soxr.c index d963bec..3d36ae9 100644 --- a/src/soxr.c +++ b/src/soxr.c @@ -43,6 +43,7 @@ char const * soxr_version(void) + typedef void sample_t; /* float or double */ typedef void (* fn_t)(void); typedef fn_t control_block_t[10]; @@ -91,6 +92,55 @@ struct soxr { +#if !WITH_CR32 && !WITH_CR32S && !WITH_CR64 && !WITH_CR64S + #define lsx_to_3dB(x) ((x)/(x)) +#else + #include "filter.h" +#endif + + + +soxr_quality_spec_t soxr_quality_spec(unsigned long recipe, unsigned long flags) +{ + soxr_quality_spec_t spec, * p = &spec; + unsigned q = recipe & 0xf; /* TODO: move to soxr-lsr.c: */ + unsigned quality = q > SOXR_LSR2Q+2? SOXR_VHQ : q > SOXR_LSR2Q? SOXR_QQ : q; + double rej; + memset(p, 0, sizeof(*p)); + if (quality > SOXR_PRECISIONQ) { + p->e = "invalid quality type"; + return spec; + } + flags |= quality < SOXR_LSR0Q ? RESET_ON_CLEAR : 0; + p->phase_response = "\62\31\144"[(recipe & 0x30)>>4]; + p->stopband_begin = 1; + p->precision = + quality == SOXR_QQ ? 0 : + quality <= SOXR_16_BITQ ? 16 : + quality <= SOXR_32_BITQ ? 4 + quality * 4 : + quality <= SOXR_LSR2Q ? 55 - quality * 4 : /* TODO: move to soxr-lsr.c */ + 0; + rej = p->precision * linear_to_dB(2.); + p->flags = flags; + if (quality <= SOXR_32_BITQ || quality == SOXR_PRECISIONQ) { + #define LOW_Q_BW0 (1385 / 2048.) /* 0.67625 rounded to be a FP exact. */ + p->passband_end = quality == 1? LOW_Q_BW0 : 1 - .05 / lsx_to_3dB(rej); + if (quality <= 2) + p->flags &= ~SOXR_ROLLOFF_NONE, p->flags |= SOXR_ROLLOFF_MEDIUM; + } + else { /* TODO: move to soxr-lsr.c */ + static float const bw[] = {.931f, .832f, .663f}; + p->passband_end = bw[quality - SOXR_LSR0Q]; + if (quality == SOXR_LSR2Q) + p->flags &= ~SOXR_ROLLOFF_NONE, p->flags |= SOXR_ROLLOFF_LSR2Q | SOXR_PROMOTE_TO_LQ; + } + if (recipe & SOXR_STEEP_FILTER) + p->passband_end = 1 - .01 / lsx_to_3dB(rej); + return spec; +} + + + char const * soxr_engine(soxr_t p) { return resampler_id(); @@ -112,6 +162,37 @@ soxr_error_t soxr_error(soxr_t p) +soxr_runtime_spec_t soxr_runtime_spec(unsigned num_threads) +{ + soxr_runtime_spec_t spec, * p = &spec; + memset(p, 0, sizeof(*p)); + p->log2_min_dft_size = 10; + p->log2_large_dft_size = 17; + p->coef_size_kbytes = 400; + p->num_threads = num_threads; + return spec; +} + + + +soxr_io_spec_t soxr_io_spec( + soxr_datatype_t itype, + soxr_datatype_t otype) +{ + soxr_io_spec_t spec, * p = &spec; + memset(p, 0, sizeof(*p)); + if ((itype | otype) >= SOXR_SPLIT * 2) + p->e = "invalid io datatype(s)"; + else { + p->itype = itype; + p->otype = otype; + p->scale = 1; + } + return spec; +} + + + #if WITH_CR32S || WITH_CR64S #if defined __GNUC__ && defined __x86_64__ #define CPUID(type, eax_, ebx_, ecx_, edx_) \ diff --git a/src/simd.c b/src/util-simd.c similarity index 100% rename from src/simd.c rename to src/util-simd.c diff --git a/src/simd32.c b/src/util32s.c similarity index 80% rename from src/simd32.c rename to src/util32s.c index 3f6cb81..b9c9e08 100644 --- a/src/simd32.c +++ b/src/util32s.c @@ -3,6 +3,6 @@ #define PFFFT_DOUBLE 0 -#include "simd32.h" +#include "util32s.h" -#include "simd.c" +#include "util-simd.c" diff --git a/src/simd32.h b/src/util32s.h similarity index 92% rename from src/simd32.h rename to src/util32s.h index bc185da..12226e5 100644 --- a/src/simd32.h +++ b/src/util32s.h @@ -1,8 +1,8 @@ /* SoX Resampler Library Copyright (c) 2007-16 robs@users.sourceforge.net * Licence for this file: LGPL v2.1 See LICENCE for details. */ -#if !defined simd32_included -#define simd32_included +#if !defined soxr_util32s_included +#define soxr_util32s_included #include diff --git a/src/simd64.c b/src/util64s.c similarity index 80% rename from src/simd64.c rename to src/util64s.c index b601750..0faa9e9 100644 --- a/src/simd64.c +++ b/src/util64s.c @@ -3,6 +3,6 @@ #define PFFFT_DOUBLE 1 -#include "simd64.h" +#include "util64s.h" -#include "simd.c" +#include "util-simd.c" diff --git a/src/simd64.h b/src/util64s.h similarity index 92% rename from src/simd64.h rename to src/util64s.h index 0ebc439..7beeb89 100644 --- a/src/simd64.h +++ b/src/util64s.h @@ -1,8 +1,8 @@ /* SoX Resampler Library Copyright (c) 2007-16 robs@users.sourceforge.net * Licence for this file: LGPL v2.1 See LICENCE for details. */ -#if !defined simd64_included -#define simd64_included +#if !defined soxr_util64s_included +#define soxr_util64s_included #include diff --git a/src/vr-coefs.c b/src/vr-coefs.c index 14886df..a57bec8 100644 --- a/src/vr-coefs.c +++ b/src/vr-coefs.c @@ -103,6 +103,9 @@ static void iir(int N, double Fp, char const * name) int main(int argc, char **argv) { + puts("/* SoX Resampler Library Copyright (c) 2007-16 robs@users.sourceforge.net"); + puts(" * Licence for this file: LGPL v2.1 See LICENCE for details. */\n"); + fir(241, 1, .45, .5, 160, 32, "half_fir_coefs"); fir( 24, .5, .25, .5, 1, 31, "fast_half_fir_coefs"); fir( 20, 12, .9 , 1.5, 160, 58, "coefs0_d"); diff --git a/src/vr-coefs.h b/src/vr-coefs.h index 9790ec0..e44138e 100644 --- a/src/vr-coefs.h +++ b/src/vr-coefs.h @@ -1,3 +1,6 @@ +/* SoX Resampler Library Copyright (c) 2007-16 robs@users.sourceforge.net + * Licence for this file: LGPL v2.1 See LICENCE for details. */ + static float const half_fir_coefs[] = { 0.471112154f, 0.316907549f, 0.0286963396f, -0.101927032f, -0.0281272982f, 0.0568029535f, 0.027196876f, -0.0360795942f, diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 3c28f9c..55cb55d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,7 +1,7 @@ # 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}) +set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${PROJECT_C_FLAGS}") link_libraries (${PROJECT_NAME} ${LIBM_LIBRARIES}) file (GLOB SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.c) diff --git a/tests/throughput-test.bat b/tests/throughput-test.bat index a183881..482c93b 100644 --- a/tests/throughput-test.bat +++ b/tests/throughput-test.bat @@ -1 +1,2 @@ -for /L %%i in (0,1,3) DO throughput 44.1 48 1 0 %%i +@echo off +for /L %%i in (0,1,3) DO throughput 44.1 48 1 0 %%i diff --git a/tests/throughput.c b/tests/throughput.c index 21a4c32..1ca37a1 100644 --- a/tests/throughput.c +++ b/tests/throughput.c @@ -6,24 +6,49 @@ #include "../examples/examples-common.h" #define k 1000 + #if defined _WIN32 #define WIN32_LEAN_AND_MEAN #include - #define timerDecl LARGE_INTEGER start, stop, tmp - #define timerStart(msecs) QueryPerformanceCounter(&start), \ - QueryPerformanceFrequency(&tmp), \ + #define timerStart(msecs) LARGE_INTEGER start, stop, tmp; \ + QueryPerformanceCounter(&start), QueryPerformanceFrequency(&tmp), \ stop.QuadPart = (msecs * tmp.QuadPart + k/2) / k #define timerRunning() (QueryPerformanceCounter(&tmp), \ (tmp.QuadPart-start.QuadPart < stop.QuadPart)) #else #include - #define timerDecl struct timespec stop, tmp - #define timerStart(msecs) clock_gettime(CLOCK_MONOTONIC, &stop), \ - stop.tv_nsec += (msecs%k)*(k*k), \ - stop.tv_sec += msecs/k + stop.tv_nsec/(k*k*k), \ - stop.tv_nsec %= k*k*k - #define timerRunning() (clock_gettime(CLOCK_MONOTONIC, &tmp), \ - (tmp.tv_sec < stop.tv_sec || tmp.tv_nsec < stop.tv_nsec)) + #include + #if defined _POSIX_TIMERS && _POSIX_TIMERS > 0 + #define K (k*k) + #define tv_frac tv_nsec + #if defined _POSIX_MONOTONIC_CLOCK + #define get_time(x) clock_gettime(CLOCK_MONOTONIC, x) + #else + #define get_time(x) clock_gettime(CLOCK_REALTIME, x) + #endif + #else + #include + #if defined timeradd + #define K k + #define tv_frac tv_usec + #define timespec timeval + #define get_time(x) gettimeofday(x, NULL) + #else + #include + #define K 1 + #define tv_frac millitm + #define tv_sec time + #define timespec timeb + #define get_time(x) ftime(x) + #endif + #endif + + #define timerStart(msecs) struct timespec stop, tmp; get_time(&stop), \ + stop.tv_frac += (msecs%k)*K, \ + stop.tv_sec += msecs/k + stop.tv_frac/(K*k), \ + stop.tv_frac %= K*k + #define timerRunning() (get_time(&tmp), \ + (tmp.tv_sec < stop.tv_sec || tmp.tv_frac < stop.tv_frac)) #endif int main(int n, char const * arg[]) @@ -74,9 +99,12 @@ int main(int n, char const * arg[]) &error, /* To report any error during creation. */ &io_spec, &q_spec, &runtime_spec); +#define RAND ((rand()*(1./RAND_MAX)-.5)*1) +#define DURATION_MSECS 125 +#define NUM_ATTEMPTS 8 + if (!error) { /* If all is well, run the resampler: */ engine = soxr_engine(soxr); -#define RAND ((rand()*(1./RAND_MAX)-.5)*1) switch (itype & 3) { case 0: for (i=0;i