Update libsoxr to 0.1.1
This commit is contained in:
parent
0413de548b
commit
f510d21218
|
@ -117,12 +117,10 @@ libsoxr
|
|||
The SoX Resampler library performs one-dimensional sample-rate conversion,
|
||||
by Rob Sykes.
|
||||
http://sourceforge.net/p/soxr/wiki/Home/
|
||||
Version in Audacity SVN: 0.0.5
|
||||
Version in Audacity SVN: 0.1.1
|
||||
Patches:
|
||||
* "libsoxr/configure" file: modified cmake params
|
||||
* modified .vcproj file in win\Projects\libsoxr
|
||||
|
||||
Upstream Version: 0.0.5 (although no file downloads are available yet)
|
||||
Upstream Version: 0.1.1
|
||||
|
||||
libvamp
|
||||
-------
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
# SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
# SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
|
||||
# Licence for this file: LGPL v2.1 See LICENCE for details.
|
||||
|
||||
cmake_minimum_required (VERSION 2.8 FATAL_ERROR)
|
||||
|
||||
project (soxr C)
|
||||
set (DESCRIPTION_SUMMARY "One-dimensional sample-rate conversion library")
|
||||
set (DESCRIPTION_SUMMARY "High quality, one-dimensional sample-rate conversion library")
|
||||
|
||||
|
||||
|
||||
# Release versioning:
|
||||
|
||||
set (PROJECT_VERSION_MAJOR 0)
|
||||
set (PROJECT_VERSION_MINOR 0)
|
||||
set (PROJECT_VERSION_PATCH 5)
|
||||
set (PROJECT_VERSION_MINOR 1)
|
||||
set (PROJECT_VERSION_PATCH 1)
|
||||
|
||||
# For shared-object; if, since the last public release:
|
||||
# * library code changed at all: ++revision
|
||||
|
@ -20,9 +20,9 @@ set (PROJECT_VERSION_PATCH 5)
|
|||
# * interfaces added: ++age
|
||||
# * interfaces removed: age = 0
|
||||
|
||||
set (SO_VERSION_CURRENT 0)
|
||||
set (SO_VERSION_CURRENT 1)
|
||||
set (SO_VERSION_REVISION 0)
|
||||
set (SO_VERSION_AGE 0)
|
||||
set (SO_VERSION_AGE 1)
|
||||
|
||||
|
||||
|
||||
|
@ -34,7 +34,7 @@ if (NOT CMAKE_BUILD_TYPE)
|
|||
set (CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." FORCE)
|
||||
endif ()
|
||||
|
||||
option (BUILD_TESTS "Build sanity-tests." OFF)
|
||||
option (BUILD_TESTS "Build sanity-tests." ON)
|
||||
option (BUILD_SHARED_LIBS "Build shared libraries." ON)
|
||||
option (BUILD_EXAMPLES "Build examples." OFF)
|
||||
option (WITH_OPENMP "Include OpenMP threading." ON)
|
||||
|
@ -50,8 +50,10 @@ cmake_dependent_option (WITH_AVFFT "Use libavcodec (LGPL) for SIMD DFT." OFF
|
|||
cmake_dependent_option (WITH_PFFFT "Use PFFFT (BSD-like licence) for SIMD DFT." ON
|
||||
"WITH_SIMD;NOT WITH_AVFFT" OFF)
|
||||
if (UNIX)
|
||||
cmake_dependent_option (BUILD_LSR_TESTS "Build LSR tests." OFF
|
||||
"WITH_LSR_BINDINGS" OFF)
|
||||
if (EXISTS ${PROJECT_SOURCE_DIR}/lsr-tests)
|
||||
cmake_dependent_option (BUILD_LSR_TESTS "Build LSR tests." OFF
|
||||
"WITH_LSR_BINDINGS" OFF)
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
|
||||
|
@ -103,10 +105,6 @@ if (WITH_AVFFT)
|
|||
endif ()
|
||||
endif ()
|
||||
|
||||
if (EXISTS ${PROJECT_SOURCE_DIR}/src/vr32.c)
|
||||
set (HAVE_VR 1)
|
||||
endif ()
|
||||
|
||||
check_function_exists (lrint HAVE_LRINT)
|
||||
check_include_files (fenv.h HAVE_FENV_H)
|
||||
test_big_endian (WORDS_BIGENDIAN)
|
||||
|
@ -119,7 +117,7 @@ macro (make_exist)
|
|||
endforeach ()
|
||||
endmacro ()
|
||||
|
||||
make_exist (HAVE_LRINT HAVE_FENV_H WORDS_BIGENDIAN HAVE_SIMD HAVE_VR)
|
||||
make_exist (HAVE_LRINT HAVE_FENV_H WORDS_BIGENDIAN HAVE_SIMD)
|
||||
make_exist (HAVE_SINGLE_PRECISION HAVE_DOUBLE_PRECISION HAVE_AVFFT)
|
||||
|
||||
|
||||
|
@ -130,11 +128,12 @@ if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
|
|||
set (PROJECT_CXX_FLAGS "-Wconversion -Wall -W -pedantic -Wundef -Wcast-align -Wpointer-arith -Wno-long-long")
|
||||
set (PROJECT_C_FLAGS "${PROJECT_CXX_FLAGS} -Wnested-externs -Wmissing-prototypes -Wstrict-prototypes")
|
||||
if (CMAKE_BUILD_TYPE STREQUAL "Release")
|
||||
set (CMAKE_SHARED_LINKER_FLAGS "-s") # strip
|
||||
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -s") # strip
|
||||
endif ()
|
||||
#option (VISIBILITY_HIDDEN "Build with -fvisibility=hidden." ON)
|
||||
cmake_dependent_option (VISIBILITY_HIDDEN "Build with -fvisibility=hidden." ON
|
||||
"BUILD_SHARED_LIBS" OFF)
|
||||
if (VISIBILITY_HIDDEN)
|
||||
add_definitions (-fvisibility=hidden)
|
||||
add_definitions (-fvisibility=hidden -DSOXR_VISIBILITY)
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
|
@ -178,10 +177,22 @@ endif ()
|
|||
|
||||
# Installation configuration:
|
||||
|
||||
set (LIB_SUFFIX "" CACHE STRING "Define suffix of libraries directory name (32 or 64).")
|
||||
set (BIN_INSTALL_DIR "bin" CACHE PATH "The subdirectory to the binaries." FORCE)
|
||||
set (LIB_INSTALL_DIR "lib${LIB_SUFFIX}" CACHE PATH "The subdirectory to the libraries." FORCE)
|
||||
set (INCLUDE_INSTALL_DIR "include" CACHE PATH "The subdirectory to the headers." FORCE)
|
||||
if (NOT DEFINED BIN_INSTALL_DIR)
|
||||
set (BIN_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/bin")
|
||||
endif ()
|
||||
if (NOT DEFINED LIB_INSTALL_DIR)
|
||||
set (LIB_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}")
|
||||
endif ()
|
||||
if (NOT DEFINED INCLUDE_INSTALL_DIR)
|
||||
set (INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/include")
|
||||
endif ()
|
||||
if (NOT DEFINED DOC_INSTALL_DIR)
|
||||
if (UNIX)
|
||||
set (DOC_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/share/doc/lib${PROJECT_NAME}")
|
||||
else ()
|
||||
set (DOC_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/doc")
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
if (APPLE)
|
||||
option (BUILD_FRAMEWORK "Build an OS X framework." OFF)
|
||||
|
@ -207,6 +218,12 @@ if (BUILD_TESTS OR BUILD_LSR_TESTS)
|
|||
enable_testing ()
|
||||
endif ()
|
||||
|
||||
install (FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/README
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/LICENCE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/NEWS
|
||||
DESTINATION ${DOC_INSTALL_DIR})
|
||||
|
||||
|
||||
|
||||
# Subdirectories:
|
||||
|
@ -269,8 +286,8 @@ if (UNIX)
|
|||
set (CPACK_PACKAGE_VERSION_MINOR "${PROJECT_VERSION_MINOR}")
|
||||
set (CPACK_PACKAGE_VERSION_PATCH "${PROJECT_VERSION_PATCH}")
|
||||
|
||||
set (CPACK_SOURCE_GENERATOR "TBZ2")
|
||||
set (CPACK_SOURCE_IGNORE_FILES "/Debug/;/Release/;/cpack/;\\\\.swp$;\\\\.gitignore")
|
||||
set (CPACK_SOURCE_GENERATOR "TGZ")
|
||||
set (CPACK_SOURCE_IGNORE_FILES "dist;/lsr-tests/;/Debug/;/Release/;/cpack/;\\\\.swp$;\\\\.gitignore;/\\\\.git/")
|
||||
|
||||
include (CPack)
|
||||
|
||||
|
|
|
@ -1,208 +0,0 @@
|
|||
# Doxyfile 1.3.4
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# Project related configuration options
|
||||
#---------------------------------------------------------------------------
|
||||
PROJECT_NAME = lib${PROJECT_NAME}
|
||||
PROJECT_NUMBER = ${PROJECT_VERSION}
|
||||
OUTPUT_DIRECTORY = doc
|
||||
OUTPUT_LANGUAGE = English
|
||||
USE_WINDOWS_ENCODING = NO
|
||||
BRIEF_MEMBER_DESC = YES
|
||||
REPEAT_BRIEF = YES
|
||||
ALWAYS_DETAILED_SEC = NO
|
||||
INLINE_INHERITED_MEMB = NO
|
||||
FULL_PATH_NAMES = NO
|
||||
STRIP_FROM_PATH =
|
||||
SHORT_NAMES = NO
|
||||
JAVADOC_AUTOBRIEF = NO
|
||||
MULTILINE_CPP_IS_BRIEF = NO
|
||||
DETAILS_AT_TOP = NO
|
||||
INHERIT_DOCS = YES
|
||||
DISTRIBUTE_GROUP_DOC = NO
|
||||
TAB_SIZE = 2
|
||||
ALIASES =
|
||||
OPTIMIZE_OUTPUT_FOR_C = YES
|
||||
OPTIMIZE_OUTPUT_JAVA = NO
|
||||
SUBGROUPING = YES
|
||||
#---------------------------------------------------------------------------
|
||||
# Build related configuration options
|
||||
#---------------------------------------------------------------------------
|
||||
EXTRACT_ALL = YES
|
||||
EXTRACT_PRIVATE = NO
|
||||
EXTRACT_STATIC = NO
|
||||
EXTRACT_LOCAL_CLASSES = NO
|
||||
HIDE_UNDOC_MEMBERS = NO
|
||||
HIDE_UNDOC_CLASSES = NO
|
||||
HIDE_FRIEND_COMPOUNDS = NO
|
||||
HIDE_IN_BODY_DOCS = NO
|
||||
INTERNAL_DOCS = YES
|
||||
CASE_SENSE_NAMES = YES
|
||||
HIDE_SCOPE_NAMES = NO
|
||||
SHOW_INCLUDE_FILES = YES
|
||||
INLINE_INFO = YES
|
||||
SORT_MEMBER_DOCS = YES
|
||||
GENERATE_TODOLIST = NO
|
||||
GENERATE_TESTLIST = NO
|
||||
GENERATE_BUGLIST = NO
|
||||
GENERATE_DEPRECATEDLIST= NO
|
||||
ENABLED_SECTIONS =
|
||||
MAX_INITIALIZER_LINES = 30
|
||||
SHOW_USED_FILES = YES
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options related to warning and progress messages
|
||||
#---------------------------------------------------------------------------
|
||||
QUIET = NO
|
||||
WARNINGS = YES
|
||||
WARN_IF_UNDOCUMENTED = NO
|
||||
WARN_IF_DOC_ERROR = YES
|
||||
WARN_FORMAT = "$file:$line: $text"
|
||||
WARN_LOGFILE =
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options related to the input files
|
||||
#---------------------------------------------------------------------------
|
||||
INPUT = @CMAKE_SOURCE_DIR@/src
|
||||
FILE_PATTERNS = @PROJECT_NAME@.h
|
||||
RECURSIVE = YES
|
||||
EXCLUDE =
|
||||
EXCLUDE_SYMLINKS = NO
|
||||
EXCLUDE_PATTERNS =
|
||||
EXAMPLE_PATH =
|
||||
EXAMPLE_PATTERNS =
|
||||
EXAMPLE_RECURSIVE = NO
|
||||
IMAGE_PATH =
|
||||
INPUT_FILTER =
|
||||
FILTER_SOURCE_FILES = NO
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options related to source browsing
|
||||
#---------------------------------------------------------------------------
|
||||
SOURCE_BROWSER = NO
|
||||
INLINE_SOURCES = NO
|
||||
STRIP_CODE_COMMENTS = YES
|
||||
REFERENCED_BY_RELATION = YES
|
||||
REFERENCES_RELATION = YES
|
||||
VERBATIM_HEADERS = YES
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options related to the alphabetical class index
|
||||
#---------------------------------------------------------------------------
|
||||
ALPHABETICAL_INDEX = YES
|
||||
COLS_IN_ALPHA_INDEX = 5
|
||||
IGNORE_PREFIX =
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options related to the HTML output
|
||||
#---------------------------------------------------------------------------
|
||||
GENERATE_HTML = YES
|
||||
HTML_OUTPUT = html
|
||||
HTML_FILE_EXTENSION = .html
|
||||
HTML_HEADER = @CMAKE_SOURCE_DIR@/doc/header.html
|
||||
HTML_FOOTER = @CMAKE_SOURCE_DIR@/doc/footer.html
|
||||
HTML_STYLESHEET = @CMAKE_SOURCE_DIR@/doc/stylesheet.css
|
||||
HTML_ALIGN_MEMBERS = YES
|
||||
GENERATE_HTMLHELP = NO
|
||||
CHM_FILE =
|
||||
HHC_LOCATION =
|
||||
GENERATE_CHI = NO
|
||||
BINARY_TOC = NO
|
||||
TOC_EXPAND = NO
|
||||
DISABLE_INDEX = YES
|
||||
ENUM_VALUES_PER_LINE = 4
|
||||
GENERATE_TREEVIEW = NO
|
||||
TREEVIEW_WIDTH = 250
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options related to the LaTeX output
|
||||
#---------------------------------------------------------------------------
|
||||
GENERATE_LATEX = NO
|
||||
LATEX_OUTPUT = latex
|
||||
LATEX_CMD_NAME = latex
|
||||
MAKEINDEX_CMD_NAME = makeindex
|
||||
COMPACT_LATEX = NO
|
||||
PAPER_TYPE = letter
|
||||
EXTRA_PACKAGES =
|
||||
LATEX_HEADER =
|
||||
PDF_HYPERLINKS = YES
|
||||
USE_PDFLATEX = YES
|
||||
LATEX_BATCHMODE = NO
|
||||
LATEX_HIDE_INDICES = NO
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options related to the RTF output
|
||||
#---------------------------------------------------------------------------
|
||||
GENERATE_RTF = NO
|
||||
RTF_OUTPUT = rtf
|
||||
COMPACT_RTF = NO
|
||||
RTF_HYPERLINKS = NO
|
||||
RTF_STYLESHEET_FILE =
|
||||
RTF_EXTENSIONS_FILE =
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options related to the man page output
|
||||
#---------------------------------------------------------------------------
|
||||
GENERATE_MAN = NO
|
||||
MAN_OUTPUT = man
|
||||
MAN_EXTENSION = .3
|
||||
MAN_LINKS = NO
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options related to the XML output
|
||||
#---------------------------------------------------------------------------
|
||||
GENERATE_XML = NO
|
||||
XML_OUTPUT = xml
|
||||
XML_SCHEMA =
|
||||
XML_DTD =
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options for the AutoGen Definitions output
|
||||
#---------------------------------------------------------------------------
|
||||
GENERATE_AUTOGEN_DEF = NO
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options related to the Perl module output
|
||||
#---------------------------------------------------------------------------
|
||||
GENERATE_PERLMOD = NO
|
||||
PERLMOD_LATEX = NO
|
||||
PERLMOD_PRETTY = YES
|
||||
PERLMOD_MAKEVAR_PREFIX =
|
||||
#---------------------------------------------------------------------------
|
||||
# Configuration options related to the preprocessor
|
||||
#---------------------------------------------------------------------------
|
||||
ENABLE_PREPROCESSING = YES
|
||||
MACRO_EXPANSION = NO
|
||||
EXPAND_ONLY_PREDEF = NO
|
||||
SEARCH_INCLUDES = YES
|
||||
INCLUDE_PATH =
|
||||
INCLUDE_FILE_PATTERNS =
|
||||
PREDEFINED = DO_NOT_DOCUMENT \
|
||||
DOXYGEN \
|
||||
WITH_MP4 \
|
||||
WITH_ASF
|
||||
EXPAND_AS_DEFINED =
|
||||
SKIP_FUNCTION_MACROS = YES
|
||||
#---------------------------------------------------------------------------
|
||||
# Configuration::addtions related to external references
|
||||
#---------------------------------------------------------------------------
|
||||
TAGFILES =
|
||||
GENERATE_TAGFILE =
|
||||
ALLEXTERNALS = NO
|
||||
EXTERNAL_GROUPS = YES
|
||||
PERL_PATH = /usr/bin/perl
|
||||
#---------------------------------------------------------------------------
|
||||
# Configuration options related to the dot tool
|
||||
#---------------------------------------------------------------------------
|
||||
CLASS_DIAGRAMS = YES
|
||||
HIDE_UNDOC_RELATIONS = YES
|
||||
HAVE_DOT = YES
|
||||
CLASS_GRAPH = YES
|
||||
COLLABORATION_GRAPH = YES
|
||||
UML_LOOK = NO
|
||||
TEMPLATE_RELATIONS = YES
|
||||
INCLUDE_GRAPH = YES
|
||||
INCLUDED_BY_GRAPH = YES
|
||||
CALL_GRAPH = NO
|
||||
GRAPHICAL_HIERARCHY = YES
|
||||
DOT_IMAGE_FORMAT = png
|
||||
DOT_PATH =
|
||||
DOTFILE_DIRS =
|
||||
MAX_DOT_GRAPH_WIDTH = 1024
|
||||
MAX_DOT_GRAPH_HEIGHT = 1024
|
||||
MAX_DOT_GRAPH_DEPTH = 0
|
||||
GENERATE_LEGEND = YES
|
||||
DOT_CLEANUP = YES
|
||||
#---------------------------------------------------------------------------
|
||||
# Configuration::addtions related to the search engine
|
||||
#---------------------------------------------------------------------------
|
||||
SEARCHENGINE = NO
|
|
@ -1,4 +1,15 @@
|
|||
SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
|
||||
|
||||
INSTALLATION GUIDE CONTENTS
|
||||
|
||||
* Standard build
|
||||
* Build customisation
|
||||
* Cross-compiling with mingw (linux host)
|
||||
* Integration with other build systems
|
||||
|
||||
|
||||
|
||||
STANDARD BUILD
|
||||
|
||||
1. Prerequisites:
|
||||
|
||||
|
@ -42,10 +53,13 @@ SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
|||
|
||||
5. Installation test
|
||||
|
||||
To test the installation, build and run the first example programme (see
|
||||
examples/README).
|
||||
To test the installation, build and run some of the example programmes
|
||||
(see examples/README).
|
||||
|
||||
|
||||
|
||||
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:
|
||||
|
@ -64,3 +78,46 @@ To list help on the available options, enter:
|
|||
Options, if given, should be preceded with '-D', e.g.
|
||||
|
||||
cmake -DWITH_SIMD:BOOL=OFF ..
|
||||
|
||||
|
||||
|
||||
CROSS-COMPILING WITH MINGW (LINUX HOST)
|
||||
|
||||
For example:
|
||||
|
||||
mkdir build
|
||||
cd build
|
||||
cmake -DCMAKE_TOOLCHAIN_FILE=~/Toolchain-x86_64-mingw-w64-mingw32.cmake \
|
||||
-DCMAKE_INSTALL_PREFIX=install \
|
||||
-DHAVE_WORDS_BIGENDIAN_EXITCODE=1 \
|
||||
-DBUILD_TESTS=0 \
|
||||
-DBUILD_EXAMPLES=1 \
|
||||
..
|
||||
make
|
||||
|
||||
where ~/Toolchain-x86_64-mingw-w64-mingw32.cmake might contain:
|
||||
|
||||
SET(CMAKE_SYSTEM_NAME Windows)
|
||||
SET(CMAKE_C_COMPILER /usr/bin/x86_64-w64-mingw32-gcc)
|
||||
SET(CMAKE_CXX_COMPILER /usr/bin/x86_64-w64-mingw32-g++)
|
||||
SET(CMAKE_RC_COMPILER /usr/bin/x86_64-w64-mingw32-windres)
|
||||
SET(CMAKE_Fortran_COMPILER /usr/bin/x86_64-w64-mingw32-gfortran)
|
||||
SET(CMAKE_AR:FILEPATH /usr/bin/x86_64-w64-mingw32-ar)
|
||||
SET(CMAKE_RANLIB:FILEPATH /usr/bin/x86_64-w64-mingw32-ranlib)
|
||||
SET(CMAKE_FIND_ROOT_PATH /usr/x86_64-w64-mingw32)
|
||||
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||
SET(QT_BINARY_DIR /usr/x86_64-w64-mingw32/bin /usr/bin)
|
||||
SET(Boost_COMPILER -gcc47)
|
||||
|
||||
|
||||
|
||||
INTEGRATION WITH OTHER BUILD SYSTEMS
|
||||
|
||||
Autotools-based systems might find it useful to create a file called
|
||||
`configure' in the directory containing this file, consisting of the line:
|
||||
cmake -DBUILD_SHARED_LIBS=OFF .
|
||||
(or with other build options as required).
|
||||
|
||||
For MS visual studio, see msvc/README
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
|
||||
|
||||
This library is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU Lesser General Public License as published by
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
Version 0.1.1 (2013-03-03)
|
||||
* Minor fixes/improvements to build/tests.
|
||||
* Fix crash (e.g. with k3b) when null error pointer passed to src_create (lsr
|
||||
bindings only).
|
||||
* Fix broken resampling in many cases with SIMD and anti_aliasing_pc < 100.
|
||||
* For clarity, renamed and slightly changed usage of three parameters in
|
||||
soxr_quality_spec_t (ABI compatible, API incompatible). An application not
|
||||
setting these parameters directly need make no change; otherwise, changes
|
||||
should be made per the following example (as shown, compatibility with both
|
||||
old/new APIs is maintained). See also the comments on these parameters in
|
||||
soxr.h. N.B. ABI compatibility with the 0.1.0 API may be removed in a
|
||||
future release.
|
||||
#if !defined SOXR_VERSION /* Deprecated, 0.1.0 API */
|
||||
q_spec.phase = minimum_phase? 0 : 50;
|
||||
q_spec.bw_pc = cutoff * 100;
|
||||
q_spec.anti_aliasing_pc = anti_aliasing * 100;
|
||||
#else /* 0.1.1 API */ Explanation:
|
||||
q_spec.phase_response = minimum_phase? 0 : 50; Renamed.
|
||||
q_spec.passband_end = cutoff; Renamed, no longer %.
|
||||
q_spec.stopband_begin = 2 - anti_aliasing; Renamed, no longer %, no
|
||||
#endif longer mirrored in Fs.
|
||||
|
||||
Version 0.1.0 (2013-01-19)
|
||||
* First public release.
|
|
@ -1,4 +1,4 @@
|
|||
SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
|
||||
|
||||
The SoX Resampler library `libsoxr' performs one-dimensional sample-rate
|
||||
conversion -- it may be used, for example, to resample PCM-encoded audio.
|
||||
|
@ -40,10 +40,13 @@ based over-sampling.
|
|||
Note that for real-time resampling, libsoxr may have a higher latency
|
||||
than non-FFT based resamplers. For example, when using the `High Quality'
|
||||
configuration to resample between 44100Hz and 48000Hz, the latency is
|
||||
around 1000 output samples, i.e. roughly 20ms.
|
||||
around 1000 output samples, i.e. roughly 20ms (though passband and FFT-
|
||||
size configuration parameters may be used to reduce this figure).
|
||||
|
||||
For build and installation instructions, see the file `INSTALL'; for
|
||||
copyright and licensing information, see the file `LICENCE'.
|
||||
|
||||
For support and new versions, see http://soxr.sourceforge.net
|
||||
________
|
||||
¹ For example, multi-channel resampling can utilise multiple CPU-cores.
|
||||
² Bit-perfect within practical occupied-bandwidth limits.
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
# SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
|
||||
# Licence for this file: LGPL v2.1 See LICENCE for details.
|
||||
|
||||
# - Find AVCODEC
|
||||
|
|
|
@ -8,22 +8,39 @@
|
|||
# OPENMP_FOUND - true if openmp is detected
|
||||
#
|
||||
# Supported compilers can be found at http://openmp.org/wp/openmp-compilers/
|
||||
|
||||
#
|
||||
# Modified for libsoxr not to rely on presence of C++ compiler.
|
||||
#
|
||||
#=============================================================================
|
||||
# Copyright 2009 Kitware, Inc.
|
||||
# Copyright 2008-2009 André Rigland Brodtkorb <Andre.Brodtkorb@ifi.uio.no>
|
||||
#
|
||||
# Distributed under the OSI-approved BSD License (the "License");
|
||||
# see accompanying file Copyright.txt for details.
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
# met:
|
||||
#
|
||||
# This software is distributed WITHOUT ANY WARRANTY; without even the
|
||||
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See the License for more information.
|
||||
# * Redistributions of source code must retain the above copyright notice,
|
||||
# this list of conditions and the following disclaimer.
|
||||
#
|
||||
# Modified for libsoxr not to rely on presence of C++ compiler.
|
||||
#=============================================================================
|
||||
# (To distribute this file outside of CMake, substitute the full
|
||||
# License text for the above reference.)
|
||||
# * Redistributions in binary form must reproduce the above copyright notice,
|
||||
# this list of conditions and the following disclaimer in the documentation
|
||||
# and/or other materials provided with the distribution.
|
||||
#
|
||||
# * The names of Kitware, Inc., the Insight Consortium, or the names of
|
||||
# any consortium members, or of any contributors, may not be used to
|
||||
# endorse or promote products derived from this software without
|
||||
# specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS''
|
||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
|
||||
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
include (CheckCSourceCompiles)
|
||||
include (FindPackageHandleStandardArgs)
|
||||
|
|
|
@ -3,14 +3,49 @@
|
|||
# The following variables are set:
|
||||
# SIMD_C_FLAGS - flags to add to the C compiler for this package.
|
||||
# SIMD_FOUND - true if support for this package is found.
|
||||
#
|
||||
#=============================================================================
|
||||
# Based on FindOpenMP.cmake, which is:
|
||||
#
|
||||
# Copyright 2009 Kitware, Inc.
|
||||
# Copyright 2008-2009 André Rigland Brodtkorb <Andre.Brodtkorb@ifi.uio.no>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
# met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright notice,
|
||||
# this list of conditions and the following disclaimer.
|
||||
#
|
||||
# * Redistributions in binary form must reproduce the above copyright notice,
|
||||
# this list of conditions and the following disclaimer in the documentation
|
||||
# and/or other materials provided with the distribution.
|
||||
#
|
||||
# * The names of Kitware, Inc., the Insight Consortium, or the names of
|
||||
# any consortium members, or of any contributors, may not be used to
|
||||
# endorse or promote products derived from this software without
|
||||
# specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS''
|
||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
|
||||
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
include (CheckCSourceCompiles)
|
||||
include (FindPackageHandleStandardArgs)
|
||||
|
||||
set (SIMD_C_FLAG_CANDIDATES
|
||||
#Microsoft Visual Studio
|
||||
# Microsoft Visual Studio x64
|
||||
" "
|
||||
# Microsoft Visual Studio x86
|
||||
"/arch:SSE /fp:fast -D__SSE__"
|
||||
#Gnu
|
||||
# Gnu
|
||||
"-msse -mfpmath=sse"
|
||||
)
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
# SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
|
||||
# Licence for this file: LGPL v2.1 See LICENCE for details.
|
||||
|
||||
# - Macro to determine endian type
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
# SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
# Licence for this file: LGPL v2.1 See LICENCE for details.
|
||||
|
||||
# Wrapper to allow easier integration with projects using autotools.
|
||||
|
||||
# Such projects will probably be using static libs so should pass
|
||||
# -DBUILD_SHARED_LIBS=OFF amongst any other options needed.
|
||||
|
||||
# Autotools options should not be passed to this script.
|
||||
|
||||
cmake -DBUILD_SHARED_LIBS=OFF -DWITH_OPENMP=OFF .
|
|
@ -1,4 +1,4 @@
|
|||
# SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
# SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
|
||||
# Licence for this file: LGPL v2.1 See LICENCE for details.
|
||||
|
||||
if (NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
|
||||
|
@ -12,7 +12,7 @@ foreach (file ${files})
|
|||
message (STATUS "Deinstalling \"${dest}\"")
|
||||
if (EXISTS "${dest}" OR IS_SYMLINK "${dest}")
|
||||
execute_process (
|
||||
COMMAND @CMAKE_COMMAND@ -E remove "${dest}"
|
||||
COMMAND "@CMAKE_COMMAND@" -E remove "${dest}"
|
||||
OUTPUT_VARIABLE rm_out
|
||||
RESULT_VARIABLE rm_retval
|
||||
)
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
Not convinced that this is going anywhere useful.
|
||||
|
||||
Run "make docs" in the parent directory to generate the API documentation.
|
|
@ -1,4 +0,0 @@
|
|||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -1,31 +0,0 @@
|
|||
<head>
|
||||
<title>$title ($projectname)</title>
|
||||
<link href="stylesheet.css" rel="stylesheet" type="text/css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="container">
|
||||
<table border="0" width="100%">
|
||||
<tr>
|
||||
<td width="1">
|
||||
<img src="../logo.png">
|
||||
</td>
|
||||
<td>
|
||||
<div id="intro">
|
||||
<table border="0" height="119" cellpadding="0" cellspacing="0" width="100%">
|
||||
<tr><td valign="top"><h1>The SoX Resampler $projectnumber ($title)</h1></td></tr>
|
||||
<tr>
|
||||
<td valign="bottom">
|
||||
<div id="links">
|
||||
<a href="index.html">Home</a>
|
||||
<a href="files.html">Headers</a>
|
||||
<a href="functions.html">Class Members</a>
|
||||
<a href="globals.html">File Members</a>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<div id="text">
|
Binary file not shown.
Before Width: | Height: | Size: 3.9 KiB |
|
@ -1,395 +0,0 @@
|
|||
body {
|
||||
font-family: sans-serif;
|
||||
background: white;
|
||||
color: black;
|
||||
margin: 0px;
|
||||
padding: 15px;
|
||||
}
|
||||
|
||||
a:link {
|
||||
font-weight: bold;
|
||||
text-decoration: none;
|
||||
color: gray;
|
||||
}
|
||||
|
||||
a:visited {
|
||||
font-weight: bold;
|
||||
text-decoration: none;
|
||||
color: gray;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
color: #cccccc;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
a:active {
|
||||
color: #cccccc;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
img {
|
||||
border-style: none;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-family: sans-serif;
|
||||
}
|
||||
|
||||
h2 {
|
||||
font-family: sans-serif;
|
||||
}
|
||||
|
||||
h3 {
|
||||
font-family: sans-serif;
|
||||
}
|
||||
|
||||
/* container */
|
||||
|
||||
#container {
|
||||
position: absolute;
|
||||
border-width: thin;
|
||||
border-style: solid;
|
||||
width: 95%;
|
||||
}
|
||||
|
||||
/* intro */
|
||||
|
||||
#intro {
|
||||
padding: 5px;
|
||||
margin: 0px;
|
||||
background: #cccccc;
|
||||
border-width: medium;
|
||||
border-style: solid;
|
||||
}
|
||||
|
||||
#intro h1 {
|
||||
margin: 5px;
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
/* links */
|
||||
|
||||
#links {
|
||||
font-size: x-small;
|
||||
vertical-align: bottom;
|
||||
}
|
||||
|
||||
#links a {
|
||||
border-width: thin;
|
||||
border-style: dotted;
|
||||
border-color: white;
|
||||
/* margin: 0px 10px 0px 0px; */
|
||||
margin: 1px;
|
||||
padding: 3px;
|
||||
line-height: 230%
|
||||
}
|
||||
|
||||
#links a:hover {
|
||||
color: black;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
#links h3 {
|
||||
outline-width: thin;
|
||||
border-style: solid;
|
||||
padding: 2px;
|
||||
margin: 3px 0px 3px 0px;
|
||||
}
|
||||
|
||||
/* menu */
|
||||
|
||||
#menu h3 {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
/* text */
|
||||
|
||||
#text {
|
||||
margin: 0px;
|
||||
padding: 5px 5px 0px 5px;
|
||||
float: left;
|
||||
}
|
||||
|
||||
#text h3 {
|
||||
border-width: thin;
|
||||
border-style: solid;
|
||||
padding: 2px;
|
||||
margin: 3px 0px 3px 0px;
|
||||
}
|
||||
|
||||
#text li {
|
||||
margin: 0px 0px 10px 0px;
|
||||
}
|
||||
|
||||
#text ul {
|
||||
margin: 5px;
|
||||
padding: 0px 0px 0px 20px;
|
||||
}
|
||||
|
||||
#leftcolumn {
|
||||
float: left;
|
||||
width: 300px;
|
||||
margin: 0px 10px 0px 0px;
|
||||
padding: 0px;
|
||||
}
|
||||
|
||||
#rightcolumn {
|
||||
float: right;
|
||||
width: 210px;
|
||||
margin: 0px;
|
||||
padding: 0px;
|
||||
}
|
||||
|
||||
/* vspacer */
|
||||
|
||||
.vspacer {
|
||||
height: 10px;
|
||||
}
|
||||
|
||||
.silver {
|
||||
border-width: thin;
|
||||
border-color: black;
|
||||
border-style: solid;
|
||||
background: #cccccc;
|
||||
}
|
||||
|
||||
a.code {
|
||||
text-decoration: none;
|
||||
font-weight: normal;
|
||||
color: #4444ee
|
||||
}
|
||||
|
||||
a.codeRef {
|
||||
font-weight: normal;
|
||||
color: #4444ee
|
||||
}
|
||||
|
||||
div.fragment {
|
||||
width: 98%;
|
||||
border: 1px solid #CCCCCC;
|
||||
background-color: #f5f5f5;
|
||||
padding-left: 4px;
|
||||
margin: 4px;
|
||||
}
|
||||
|
||||
div.ah {
|
||||
background-color: black;
|
||||
font-weight: bold; color: #ffffff;
|
||||
margin-bottom: 3px;
|
||||
margin-top: 3px
|
||||
}
|
||||
|
||||
#text td {
|
||||
width: auto;
|
||||
}
|
||||
|
||||
div.memdoc {
|
||||
margin-top: 0px;
|
||||
margin-bottom: 20px;
|
||||
padding: 10px 10px 10px 40px;
|
||||
}
|
||||
|
||||
div.memproto {
|
||||
border: thin solid black;
|
||||
background-color: #f2f2ff;
|
||||
width: 100%;
|
||||
margin-top: 20px;
|
||||
padding-top: 10px;
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
|
||||
td.paramtype {
|
||||
color: #602020;
|
||||
}
|
||||
|
||||
table.memname {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
div.groupHeader {
|
||||
margin-left: 16px;
|
||||
margin-top: 12px;
|
||||
margin-bottom: 6px;
|
||||
font-weight: bold
|
||||
}
|
||||
|
||||
div.groupText {
|
||||
margin-left: 16px;
|
||||
font-style: italic;
|
||||
font-size: smaller
|
||||
}
|
||||
|
||||
body {
|
||||
background: white;
|
||||
color: black;
|
||||
margin-right: 20px;
|
||||
margin-left: 20px;
|
||||
}
|
||||
|
||||
td.indexkey {
|
||||
background-color: #eeeeff;
|
||||
font-weight: bold;
|
||||
padding-right : 10px;
|
||||
padding-top : 2px;
|
||||
padding-left : 10px;
|
||||
padding-bottom : 2px;
|
||||
margin-left : 0px;
|
||||
margin-right : 0px;
|
||||
margin-top : 2px;
|
||||
margin-bottom : 2px
|
||||
}
|
||||
|
||||
td.indexvalue {
|
||||
background-color: #eeeeff;
|
||||
font-style: italic;
|
||||
padding-right : 10px;
|
||||
padding-top : 2px;
|
||||
padding-left : 10px;
|
||||
padding-bottom : 2px;
|
||||
margin-left : 0px;
|
||||
margin-right : 0px;
|
||||
margin-top : 2px;
|
||||
margin-bottom : 2px
|
||||
}
|
||||
|
||||
tr.memlist {
|
||||
background-color: #f0f0f0;
|
||||
}
|
||||
|
||||
p.formulaDsp {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
img.formulaDsp {
|
||||
|
||||
}
|
||||
|
||||
img.formulaInl {
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
span.keyword {
|
||||
color: #008000
|
||||
}
|
||||
|
||||
span.keywordtype {
|
||||
color: #604020
|
||||
}
|
||||
|
||||
span.keywordflow {
|
||||
color: #e08000
|
||||
}
|
||||
|
||||
span.comment {
|
||||
color: #800000
|
||||
}
|
||||
|
||||
span.preprocessor {
|
||||
color: #806020
|
||||
}
|
||||
|
||||
span.stringliteral {
|
||||
color: #002080
|
||||
}
|
||||
|
||||
span.charliteral {
|
||||
color: #008080
|
||||
}
|
||||
|
||||
.mdTable {
|
||||
border: 1px solid #868686;
|
||||
background-color: #f2f2ff;
|
||||
}
|
||||
|
||||
.mdRow {
|
||||
padding: 8px 20px;
|
||||
}
|
||||
|
||||
.mdescLeft {
|
||||
font-size: smaller;
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
background-color: #FAFAFA;
|
||||
padding-left: 8px;
|
||||
border-top: 1px none #E0E0E0;
|
||||
border-right: 1px none #E0E0E0;
|
||||
border-bottom: 1px none #E0E0E0;
|
||||
border-left: 1px none #E0E0E0;
|
||||
margin: 0px;
|
||||
}
|
||||
|
||||
.mdescRight {
|
||||
font-size: smaller;
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
font-style: italic;
|
||||
background-color: #FAFAFA;
|
||||
padding-left: 4px;
|
||||
border-top: 1px none #E0E0E0;
|
||||
border-right: 1px none #E0E0E0;
|
||||
border-bottom: 1px none #E0E0E0;
|
||||
border-left: 1px none #E0E0E0;
|
||||
margin: 0px;
|
||||
padding-bottom: 0px;
|
||||
padding-right: 8px;
|
||||
}
|
||||
|
||||
.memItemLeft {
|
||||
padding: 1px 0px 0px 8px;
|
||||
margin: 4px;
|
||||
border-top-width: 1px;
|
||||
border-right-width: 1px;
|
||||
border-bottom-width: 1px;
|
||||
border-left-width: 1px;
|
||||
border-top-style: solid;
|
||||
border-top-color: #E0E0E0;
|
||||
border-right-color: #E0E0E0;
|
||||
border-bottom-color: #E0E0E0;
|
||||
border-left-color: #E0E0E0;
|
||||
border-right-style: none;
|
||||
border-bottom-style: none;
|
||||
border-left-style: none;
|
||||
background-color: #FAFAFA;
|
||||
font-family: Geneva, Arial, Helvetica, sans-serif;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.memItemRight {
|
||||
padding: 1px 0px 0px 8px;
|
||||
margin: 4px;
|
||||
border-top-width: 1px;
|
||||
border-right-width: 1px;
|
||||
border-bottom-width: 1px;
|
||||
border-left-width: 1px;
|
||||
border-top-style: solid;
|
||||
border-top-color: #E0E0E0;
|
||||
border-right-color: #E0E0E0;
|
||||
border-bottom-color: #E0E0E0;
|
||||
border-left-color: #E0E0E0;
|
||||
border-right-style: none;
|
||||
border-bottom-style: none;
|
||||
border-left-style: none;
|
||||
background-color: #FAFAFA;
|
||||
font-family: Geneva, Arial, Helvetica, sans-serif;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.search {
|
||||
color: #0000ee;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
form.search {
|
||||
margin-bottom: 0px;
|
||||
margin-top: 0px;
|
||||
}
|
||||
|
||||
input.search {
|
||||
font-size: 75%;
|
||||
color: #000080;
|
||||
font-weight: normal;
|
||||
background-color: #eeeeff;
|
||||
}
|
||||
|
||||
td.tiny {
|
||||
font-size: 75%;
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
/* SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
/* SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
|
||||
* Licence for this file: LGPL v2.1 See LICENCE for details. */
|
||||
|
||||
/* Example 1: `One-shot' resample a single block of data in memory.
|
||||
|
@ -37,12 +37,14 @@ int main(int argc, char const * arg[])
|
|||
out, olen, &odone, /* Output. */
|
||||
NULL, NULL, NULL); /* Default configuration.*/
|
||||
|
||||
unsigned i = 0; /* Print out the resampled data... */
|
||||
unsigned i = 0; /* Print out the resampled data, */
|
||||
while (i++ < odone)
|
||||
printf("%5.2f%c", out[i-1], " \n"[!(i&7) || i == odone]);
|
||||
puts(soxr_strerror(error)); /* ...and the reported result. */
|
||||
printf("%-26s %s\n", arg[0], soxr_strerror(error)); /* and reported result. */
|
||||
|
||||
if (argc > 3) /* Library version check: */
|
||||
printf("runtime=%s API="SOXR_THIS_VERSION_STR"\n", soxr_version());
|
||||
|
||||
free(out); /* Tidy up. */
|
||||
return !!error;
|
||||
(void)argc, (void)arg; /* Not used in this example. */
|
||||
}
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
/* SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
|
||||
* Licence for this file: LGPL v2.1 See LICENCE for details. */
|
||||
|
||||
/* Example 1a: Variant of example 1 using libsamplerate-like bindings. */
|
||||
|
||||
#include <soxr-lsr.h>
|
||||
#include "examples-common.h"
|
||||
|
||||
float in[] = { /* Input: 12 cycles of a sine wave with freq. = irate/4 */
|
||||
0,1,0,-1, 0,1,0,-1, 0,1,0,-1, 0,1,0,-1, 0,1,0,-1, 0,1,0,-1,
|
||||
0,1,0,-1, 0,1,0,-1, 0,1,0,-1, 0,1,0,-1, 0,1,0,-1, 0,1,0,-1};
|
||||
|
||||
int main(int argc, char const * arg[])
|
||||
{
|
||||
double irate = argc > 1? atof(arg[1]) : 1; /* Default to upsampling */
|
||||
double orate = argc > 2? atof(arg[2]) : 2; /* by a factor of 2. */
|
||||
|
||||
size_t olen = (size_t)(AL(in) * orate / irate + .5); /* Assay output len. */
|
||||
float * out = (float *)malloc(sizeof(*out) * olen); /* Allocate output buf. */
|
||||
|
||||
int error, i = 0;
|
||||
SRC_DATA data;
|
||||
|
||||
data.data_in = in;
|
||||
data.data_out = out;
|
||||
data.input_frames = AL(in);
|
||||
data.output_frames = (int)olen;
|
||||
data.src_ratio = orate / irate;
|
||||
error = src_simple(&data, SRC_SINC_FASTEST, 1);
|
||||
|
||||
while (i++ < data.output_frames_gen) /* Print out the resampled data, */
|
||||
printf("%5.2f%c", out[i-1], " \n"[!(i&7) || i == data.output_frames_gen]);
|
||||
printf("%-26s %s\n", arg[0], src_strerror(error)); /* and reported result. */
|
||||
|
||||
if (argc > 3) /* Library version check: */
|
||||
printf("runtime=%s\n", src_get_version());
|
||||
|
||||
free(out); /* Tidy up. */
|
||||
return !!error;
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
/* SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
/* SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
|
||||
* Licence for this file: LGPL v2.1 See LICENCE for details. */
|
||||
|
||||
/* Example 2: resample a raw, single-channel, floating-point data stream from
|
|
@ -1,64 +0,0 @@
|
|||
/* SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
* Licence for this file: LGPL v2.1 See LICENCE for details. */
|
||||
|
||||
/* Example 2a: resample a raw, single-channel, floating-point data stream from
|
||||
* stdin to stdout. The application uses the single function `soxr_process'
|
||||
* for both input and output to/from the resampler.
|
||||
*
|
||||
* Arguments are: INPUT-RATE OUTPUT-RATE
|
||||
*/
|
||||
|
||||
#include <soxr.h>
|
||||
#include "examples-common.h"
|
||||
|
||||
int main(int argc, char const * arg[])
|
||||
{
|
||||
double irate = argc > 1? atof(arg[1]) : 44100.;
|
||||
double orate = argc > 2? atof(arg[2]) : 96000.;
|
||||
|
||||
soxr_error_t error;
|
||||
|
||||
soxr_t resampler = soxr_create(
|
||||
irate, orate, 1, /* Input rate, output rate, # of channels. */
|
||||
&error, /* To report any error during creation. */
|
||||
NULL, NULL, NULL); /* Use configuration defaults.*/
|
||||
|
||||
if (!error) {
|
||||
#define buf_total_len 12000 /* In samples. */
|
||||
|
||||
/* Allocate resampling input and output buffers in proportion to the input
|
||||
* and output rates: */
|
||||
size_t ibuflen = (size_t)(irate * buf_total_len / (irate + orate) + .5);
|
||||
size_t obuflen = buf_total_len - ibuflen;
|
||||
char * ibuf = malloc(sizeof(float) * ibuflen), * iptr = 0;
|
||||
void * obuf = malloc(sizeof(float) * obuflen);
|
||||
|
||||
size_t iavailable = 0;
|
||||
size_t idone, odone, written;
|
||||
|
||||
USE_STD_STDIO;
|
||||
do { /* Resample in blocks: */
|
||||
if (!iavailable && ibuf) { /* If ibuf is empty, try to fill it: */
|
||||
iavailable = fread(ibuf, sizeof(float), ibuflen, stdin);
|
||||
if (!iavailable) /* If none available, don't retry. Pass NULL */
|
||||
free(ibuf), ibuf = 0;/* ibuf to resampler to indicate end-of-input. */
|
||||
iptr = ibuf; /* Reset input to the start of the buffer. */
|
||||
}
|
||||
|
||||
error = soxr_process(resampler,
|
||||
iptr, iavailable, &idone, obuf, obuflen, &odone);
|
||||
|
||||
iptr += idone * sizeof(float); /* Update input buffer according to how */
|
||||
iavailable -= idone; /* much the resampler has consumed. */
|
||||
|
||||
written = fwrite(obuf, sizeof(float), odone, stdout); /* Consume output.*/
|
||||
} while (!error && (ibuf || written));
|
||||
/* Tidy up: */
|
||||
free(obuf), free(ibuf);
|
||||
soxr_delete(resampler);
|
||||
}
|
||||
/* Diagnostics: */
|
||||
fprintf(stderr, "%-26s %s; I/O: %s\n", arg[0],
|
||||
soxr_strerror(error), errno? strerror(errno) : "no error");
|
||||
return error || errno;
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
/* SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
* Licence for this file: LGPL v2.1 See LICENCE for details. */
|
||||
|
||||
/* Example 2b: resample a raw, single-channel, floating-point data stream from
|
||||
* stdin to stdout. The application provides an input function, called on
|
||||
* demand by libsoxr, in response to calls to soxr_output().
|
||||
*
|
||||
* Arguments are: INPUT-RATE OUTPUT-RATE
|
||||
*/
|
||||
|
||||
#include <soxr.h>
|
||||
#include "examples-common.h"
|
||||
|
||||
#define iolen 10000
|
||||
|
||||
static size_t input_fn(
|
||||
void * p, /* Generic pointer to any state variables neded here. */
|
||||
soxr_cbuf_t * buf, /* To tell the resampler where the data is. */
|
||||
size_t requested_len) /* In samples per channel. */
|
||||
{
|
||||
static float * ibuf; /* Static context; this could be changed using `p'. */
|
||||
size_t actual;
|
||||
size_t len = min(requested_len, iolen);
|
||||
|
||||
/* Allocate the input buffer memory; check for errors: */
|
||||
*buf = ibuf = (float *)realloc(ibuf, sizeof(float) * len);
|
||||
if (!ibuf)
|
||||
return 0; /* Indicate failure (*buf is also 0). */
|
||||
|
||||
/* Read samples from the input stream; check for errors: */
|
||||
actual = fread(ibuf, sizeof(float), len, stdin);
|
||||
if (!actual) {
|
||||
if (ferror(stdin))
|
||||
*buf = 0; /* Indicate failure (actual is also 0). */
|
||||
free(ibuf), ibuf = 0;
|
||||
}
|
||||
|
||||
return actual;
|
||||
(void)p; /* Not used in this example. */
|
||||
}
|
||||
|
||||
int main(int argc, char const * arg[])
|
||||
{
|
||||
double irate = argc > 1? atof(arg[1]) : 44100.;
|
||||
double orate = argc > 2? atof(arg[2]) : 96000.;
|
||||
|
||||
soxr_error_t error;
|
||||
soxr_t resampler = soxr_create(irate, orate, 1, &error, 0, 0, 0);
|
||||
if (!error) /* Register input_fn with the resampler: */
|
||||
error = soxr_set_input_fn(resampler, input_fn, 0);
|
||||
|
||||
if (!error) { /* If all is good, run the resampler: */
|
||||
float resampled[iolen];
|
||||
size_t actual;
|
||||
/* Resample in blocks: */
|
||||
USE_STD_STDIO;
|
||||
do actual = soxr_output(resampler, resampled, iolen);
|
||||
while (fwrite(resampled, sizeof(float), actual, stdout));
|
||||
|
||||
error = soxr_error(resampler); /* Note: before deleting the resampler! */
|
||||
soxr_delete(resampler);
|
||||
}
|
||||
/* Diagnostics: */
|
||||
fprintf(stderr, "%-26s %s; I/O: %s\n", arg[0],
|
||||
soxr_strerror(error), errno? strerror(errno) : "no error");
|
||||
return error || errno;
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
/* SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
/* SoX Resampler Library Copyright (c) 2007-13 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,
|
||||
|
@ -9,7 +9,7 @@
|
|||
* (illustrated in example 2) this requires that the application implements
|
||||
* less logic, but one more function.
|
||||
*
|
||||
* The eight arguments (which are optional, from last to first) are:
|
||||
* The 11 arguments (which are optional, from last to first) are:
|
||||
* INPUT-RATE As example 2
|
||||
* OUTPUT-RATE Ditto
|
||||
* NUM-CHANNELS Number of interleaved channels
|
||||
|
@ -17,6 +17,9 @@
|
|||
* OUT-DATATYPE# Ditto
|
||||
* Q-RECIPE Quality recipe (in hex) See soxr.h
|
||||
* Q-FLAGS Quality flags (in hex) See soxr.h
|
||||
* PASSBAND-END %
|
||||
* STOPBAND-BEGIN %
|
||||
* PHASE-RESPONSE [0,100]
|
||||
* USE-THREADS 1 to use multi-threading (where available)
|
||||
*/
|
||||
|
||||
|
@ -47,9 +50,12 @@ int main(int n, char const * arg[])
|
|||
soxr_datatype_t const otype = 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_quality_spec_t const q_spec = soxr_quality_spec(q_recipe, q_flags);
|
||||
soxr_quality_spec_t q_spec = soxr_quality_spec(q_recipe, q_flags);
|
||||
soxr_io_spec_t const io_spec = soxr_io_spec(itype, otype);
|
||||
soxr_runtime_spec_t const runtime_spec = soxr_runtime_spec(!use_threads);
|
||||
|
||||
|
@ -58,7 +64,8 @@ int main(int n, char const * arg[])
|
|||
#define buf_total_len 15000 /* In samples per channel. */
|
||||
size_t const osize = soxr_datatype_size(otype) * chans;
|
||||
size_t const isize = soxr_datatype_size(itype) * chans;
|
||||
size_t const olen = (size_t)(orate * buf_total_len / (irate + orate) + .5);
|
||||
size_t const olen0= (size_t)(orate * buf_total_len / (irate + orate) + .5);
|
||||
size_t const olen = min(max(olen0, 1), buf_total_len - 1);
|
||||
size_t const ilen = buf_total_len - olen;
|
||||
void * const obuf = malloc(osize * olen);
|
||||
void * const ibuf = malloc(isize * ilen);
|
||||
|
@ -66,9 +73,15 @@ int main(int n, char const * arg[])
|
|||
input_context_t icontext;
|
||||
size_t odone, clips = 0;
|
||||
soxr_error_t error;
|
||||
soxr_t soxr;
|
||||
|
||||
/* 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;
|
||||
|
||||
/* Create a stream resampler: */
|
||||
soxr_t soxr = soxr_create(
|
||||
soxr = soxr_create(
|
||||
irate, orate, chans, /* Input rate, output rate, # of channels. */
|
||||
&error, /* To report any error during creation. */
|
||||
&io_spec, &q_spec, &runtime_spec);
|
||||
|
|
|
@ -1,83 +0,0 @@
|
|||
/* 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,
|
||||
* and other options.
|
||||
*
|
||||
* The eight arguments are:
|
||||
* INPUT-RATE As example 2a
|
||||
* OUTPUT-RATE Ditto
|
||||
* NUM-CHANNELS Number of interleaved channels
|
||||
* IN-DATATYPE# 0:float32 1:float64 2:int32 3:int16
|
||||
* OUT-DATATYPE# Ditto
|
||||
* 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 <soxr.h>
|
||||
#include "examples-common.h"
|
||||
|
||||
int main(int n, char const * arg[])
|
||||
{
|
||||
char const * arg0 = n? --n, *arg++ : "";
|
||||
double irate = n? --n, atof(*arg++) : 96000.;
|
||||
double orate = n? --n, atof(*arg++) : 44100.;
|
||||
unsigned chans = n? --n, (unsigned)atoi(*arg++) : 1;
|
||||
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;
|
||||
size_t osize = soxr_datatype_size(otype) * chans;
|
||||
size_t clips = 0;
|
||||
soxr_error_t error;
|
||||
|
||||
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);
|
||||
|
||||
soxr_t resampler = soxr_create(
|
||||
irate, orate, chans, &error, &io_spec, &q_spec, &runtime_spec);
|
||||
|
||||
if (!error) {
|
||||
#define buf_total_len 15000 /* In samples. */
|
||||
|
||||
/* Allocate resampling input and output buffers in proportion to the input
|
||||
* and output rates: */
|
||||
size_t ibuflen = (size_t)(irate * buf_total_len / (irate + orate) + .5);
|
||||
size_t obuflen = buf_total_len - ibuflen;
|
||||
char * ibuf = malloc(isize * ibuflen), * iptr = 0;
|
||||
void * obuf = malloc(osize * obuflen);
|
||||
|
||||
size_t iavailable = 0;
|
||||
size_t idone, odone, written;
|
||||
|
||||
USE_STD_STDIO;
|
||||
do { /* Resample in blocks: */
|
||||
if (!iavailable && ibuf) { /* If ibuf is empty, try to fill it: */
|
||||
iavailable = fread(ibuf, isize, ibuflen, stdin);
|
||||
if (!iavailable) /* If none available, don't retry. Pass NULL */
|
||||
free(ibuf), ibuf = 0;/* ibuf to resampler to indicate end-of-input. */
|
||||
iptr = ibuf; /* Reset input to the start of the buffer. */
|
||||
}
|
||||
|
||||
error = soxr_process(resampler,
|
||||
iptr, iavailable, &idone, obuf, obuflen, &odone);
|
||||
|
||||
iptr += idone * isize; /* Update input buffer according to how */
|
||||
iavailable -= idone; /* much the resampler has consumed. */
|
||||
|
||||
written = fwrite(obuf, osize, odone, stdout); /* Consume output. */
|
||||
} while (!error && (ibuf || written));
|
||||
|
||||
free(obuf), free(ibuf);
|
||||
clips = *soxr_num_clips(resampler); /* Can occur only with integer output.*/
|
||||
soxr_delete(resampler);
|
||||
}
|
||||
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;
|
||||
}
|
|
@ -1,85 +0,0 @@
|
|||
/* SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
* Licence for this file: LGPL v2.1 See LICENCE for details. */
|
||||
|
||||
/* Example 3b: extends example 2b with multiple channels, multiple datatypes,
|
||||
* and other options.
|
||||
*
|
||||
* 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-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 <soxr.h>
|
||||
#include "examples-common.h"
|
||||
|
||||
#define iolen 8000
|
||||
|
||||
|
||||
|
||||
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;
|
||||
len = fread(ibuf, isize, len, stdin);
|
||||
if (!len) {
|
||||
if (ferror(stdin))
|
||||
*buf = 0;
|
||||
free(ibuf), ibuf = 0;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(int n, char const * arg[])
|
||||
{
|
||||
char const * arg0 = n? --n, *arg++ : "";
|
||||
double irate = n? --n, atof(*arg++) : 96000.;
|
||||
double orate = n? --n, atof(*arg++) : 44100.;
|
||||
unsigned chans = n? --n, (unsigned)atoi(*arg++) : 1;
|
||||
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;
|
||||
size_t osize = soxr_datatype_size(otype) * chans;
|
||||
size_t clips = 0;
|
||||
soxr_error_t error;
|
||||
|
||||
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);
|
||||
|
||||
soxr_t resampler = soxr_create(
|
||||
irate, orate, chans, &error, &io_spec, &q_spec, &runtime_spec);
|
||||
if (!error) error = soxr_set_input_fn(resampler, input_fn, &isize);
|
||||
|
||||
USE_STD_STDIO;
|
||||
if (!error) {
|
||||
void * resampled = malloc(osize * iolen);
|
||||
size_t actual;
|
||||
|
||||
do actual = soxr_output(resampler, resampled, iolen);
|
||||
while (fwrite(resampled, osize, actual, stdout));
|
||||
|
||||
free(resampled);
|
||||
error = soxr_error(resampler);
|
||||
clips = *soxr_num_clips(resampler); /* Can occur only with integer output.*/
|
||||
soxr_delete(resampler);
|
||||
}
|
||||
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;
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
/* SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
/* SoX Resampler Library Copyright (c) 2007-13 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.
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
/* SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
|
||||
* Licence for this file: LGPL v2.1 See LICENCE for details. */
|
||||
|
||||
/* Example 5: Variable-rate resampling (N.B. experimental). A test signal
|
||||
|
|
|
@ -1,21 +1,37 @@
|
|||
# SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
# SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
|
||||
# Licence for this file: LGPL v2.1 See LICENCE for details.
|
||||
|
||||
if (${BUILD_EXAMPLES})
|
||||
project (soxr)
|
||||
file (GLOB SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.[cC])
|
||||
if (NOT BUILD_SHARED_LIBS AND OPENMP_FOUND)
|
||||
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_C_FLAGS}")
|
||||
endif ()
|
||||
else ()
|
||||
project (soxr) # Adds c++ compiler
|
||||
file (GLOB SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/[1-9]-*.[cC])
|
||||
elseif (${BUILD_TESTS})
|
||||
file (GLOB SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/3*.c)
|
||||
endif ()
|
||||
|
||||
if (${BUILD_EXAMPLES} OR ${BUILD_TESTS})
|
||||
if (${WITH_LSR_BINDINGS})
|
||||
set (LSR_SOURCES 1a-lsr.c)
|
||||
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})
|
||||
|
||||
foreach (fe ${SOURCES})
|
||||
foreach (fe ${SOURCES} ${LSR_SOURCES})
|
||||
get_filename_component (f ${fe} NAME_WE)
|
||||
add_executable (${f} ${fe})
|
||||
if (${f} STREQUAL "1a-lsr")
|
||||
target_link_libraries (${f} soxr-lsr)
|
||||
endif ()
|
||||
endforeach ()
|
||||
|
||||
if (${BUILD_TESTS} AND ${WITH_LSR_BINDINGS})
|
||||
add_test (lsr-bindings ${BIN}1a-lsr)
|
||||
endif ()
|
||||
|
||||
file (GLOB INSTALL_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.[cCh])
|
||||
install (FILES ${INSTALL_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/README DESTINATION ${DOC_INSTALL_DIR}/examples)
|
||||
|
|
|
@ -1,18 +1,20 @@
|
|||
SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
|
||||
|
||||
These simple examples show the different ways that an application may
|
||||
interface with libsoxr. Note that real-world applications may also have to
|
||||
interface with soxr. Note that real-world applications may also have to
|
||||
deal with file-formats, codecs, (more sophisticated) dithering, etc., which
|
||||
are not covered here.
|
||||
|
||||
With libsoxr installed, the examples may be built using commands similar to
|
||||
the following. On unix-like systems:
|
||||
With the library installed, the examples may be built using commands similar
|
||||
to the following. On unix-like systems:
|
||||
|
||||
cc 1-single-block.c -lsoxr
|
||||
cc 1a-lsr.c -lsoxr-lsr
|
||||
|
||||
or, on MS-Windows:
|
||||
or, with MSVC on MS-Windows:
|
||||
|
||||
cl 1-single-block.c -I"C:/Program Files/soxr/include" "C:/Program Files/soxr/lib/soxr.lib"
|
||||
cl 1a-lsr.c -I"C:/Program Files/soxr/include" "C:/Program Files/soxr/lib/soxr-lsr.lib"
|
||||
|
||||
IDEs may hide such commands behind configuration screens and build menus --
|
||||
where applicable, consult your IDE's user-manual.
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
/* SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
|
||||
* Licence for this file: LGPL v2.1 See LICENCE for details. */
|
||||
|
||||
/* Common includes etc. for the examples. */
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
#!/bin/sh
|
||||
# SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
# SoX Resampler Library Copyright (c) 2007-13 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
|
||||
|
||||
build=$1
|
||||
test x$build = x && build=Release
|
||||
|
||||
|
@ -10,6 +12,6 @@ rm -f CMakeCache.txt # Prevent interference from any in-tree build
|
|||
mkdir -p $build
|
||||
cd $build
|
||||
|
||||
cmake -DCMAKE_BUILD_TYPE=$build -DBUILD_TESTS=ON .. &&
|
||||
make &&
|
||||
(make test || echo "FAILURE details in $build/Testing/Temporary/LastTest.log")
|
||||
cmake -DCMAKE_BUILD_TYPE=$build .. &&
|
||||
make $j &&
|
||||
(ctest $j || echo "FAILURE details in $build/Testing/Temporary/LastTest.log")
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
@echo off
|
||||
rem SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
rem SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
|
||||
rem Licence for this file: LGPL v2.1 See LICENCE for details.
|
||||
|
||||
set build=%1
|
||||
|
@ -11,7 +11,7 @@ del/f CMakeCache.txt
|
|||
mkdir %build%
|
||||
cd %build%
|
||||
|
||||
cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=%build% -DBUILD_TESTS=ON ..
|
||||
cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=%build% ..
|
||||
if errorlevel 1 goto end
|
||||
|
||||
nmake
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
#!/bin/sh
|
||||
set -e
|
||||
# SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
|
||||
# Licence for this file: LGPL v2.1 See LICENCE for details.
|
||||
|
||||
# Sanity-check of library installed on unix-like system
|
||||
|
||||
# This script checks the installation of the entire library (including lsr).
|
||||
#
|
||||
# Distros using three separate packages can do the following (in order):
|
||||
#
|
||||
# * Install soxr pkg (i.e. basically, just the shared object)
|
||||
# * ./inst-check-soxr
|
||||
# * Install soxr-lsr pkg (i.e. basically, just the shared object)
|
||||
# * ./inst-check-soxr-lsr
|
||||
# * Install the -dev pkg (i.e. examples, headers, & pkg-config)
|
||||
# * ./inst-check PATH-OF-INSTALLED-EXAMPLES-DIR (e.g. /usr/share/doc/libsoxr/examples)
|
||||
|
||||
# Where are the example source files:
|
||||
src=$1
|
||||
test x$src = x && src=/usr/local/share/doc/libsoxr/examples
|
||||
|
||||
dir="$(dirname $(readlink -f $0))"
|
||||
$dir/inst-check-soxr $src
|
||||
$dir/inst-check-soxr-lsr $src
|
|
@ -0,0 +1,52 @@
|
|||
#!/bin/sh
|
||||
set -e
|
||||
# SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
|
||||
# Licence for this file: LGPL v2.1 See LICENCE for details.
|
||||
|
||||
# Sanity-check of sub-library installed on unix-like system
|
||||
|
||||
arg="$1" # path to installed examples (if dev pkg installed); otherwise omitted
|
||||
dir="$(dirname $(readlink -f $0))"
|
||||
|
||||
# Find the examples:
|
||||
src="$arg"
|
||||
test x"$src" = x && src="$dir/examples"
|
||||
cd $src
|
||||
|
||||
# Somewhere to put the binaries:
|
||||
tmp=`mktemp -d`
|
||||
|
||||
build_examples() {
|
||||
if [ x"$arg" = x ]; then
|
||||
echo "Examples in `pwd`; using local headers:" # for when dev pkg not installed
|
||||
libs=-l$1
|
||||
cflags=-I$dir/src
|
||||
else
|
||||
echo "Examples in `pwd`; using pkg-config:"
|
||||
libs=$(pkg-config --libs $1)
|
||||
cflags=$(pkg-config --cflags $1)
|
||||
fi
|
||||
for f in ?$2-*.[cC]; do
|
||||
cc=cc; echo $f | grep -q C$ && cc=c++
|
||||
out=$tmp/`echo $f | sed "s/.[cC]$//"`
|
||||
cmd="$cc $cflags -o $out $f $libs"
|
||||
echo $cmd; $cmd
|
||||
done
|
||||
}
|
||||
|
||||
# Determine library:
|
||||
if [ `basename $0` = inst-check-soxr ]; then
|
||||
build_examples soxr
|
||||
gen="dd if=/dev/urandom count=1000"
|
||||
$tmp/1-single-block 1 2 .
|
||||
$gen 2> /dev/null | $tmp/2-stream 2>&1 >$tmp/stdout
|
||||
$gen 2> /dev/null | $tmp/3-options-input-fn 6 7 2 2 0 2>&1 >$tmp/stdout
|
||||
$gen 2> /dev/null | $tmp/4-split-channels 7 6 2 2 3 2>&1 >$tmp/stdout # Clipping expected here
|
||||
$gen 2> /dev/null | $tmp/5-variable-rate 2>&1 >$tmp/stdout
|
||||
else
|
||||
build_examples soxr-lsr a # lsr has 'a' suffix on example number.
|
||||
$tmp/1a-lsr 1 2 .
|
||||
fi
|
||||
|
||||
# Tidy up:
|
||||
rm -rf $tmp
|
|
@ -1,49 +0,0 @@
|
|||
# SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
# Licence for this file: LGPL v2.1 See LICENCE for details.
|
||||
|
||||
list (APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules)
|
||||
|
||||
find_package (FFTW)
|
||||
if (FFTW_FOUND)
|
||||
include_directories (${FFTW_INCLUDE_DIRS})
|
||||
link_libraries (${FFTW_LIBRARIES})
|
||||
set (HAVE_FFTW3 1)
|
||||
endif ()
|
||||
|
||||
find_package (sndfile)
|
||||
if (SNDFILE_FOUND)
|
||||
include_directories (${SNDFILE_INCLUDE_DIRS})
|
||||
link_libraries (${SNDFILE_LIBRARIES})
|
||||
set (HAVE_SNDFILE 1)
|
||||
endif ()
|
||||
|
||||
check_function_exists (lrintf HAVE_LRINTF)
|
||||
check_function_exists (alarm HAVE_ALARM)
|
||||
check_function_exists (signal HAVE_SIGNAL)
|
||||
check_include_files (sys/times.h HAVE_SYS_TIMES_H)
|
||||
make_exist (HAVE_LRINTF HAVE_ALARM HAVE_SIGNAL HAVE_SYS_TIMES_H)
|
||||
make_exist (HAVE_FFTW HAVE_SNDFILE)
|
||||
|
||||
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
|
||||
include_directories (${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
add_library (tests_lib SHARED util calc_snr)
|
||||
|
||||
link_libraries (tests_lib ${PROJECT_NAME}-lsr)
|
||||
|
||||
enable_testing ()
|
||||
|
||||
set (tests
|
||||
callback_hang_test callback_test downsample_test
|
||||
float_short_test misc_test multi_channel_test
|
||||
reset_test simple_test snr_bw_test termination_test varispeed_test)
|
||||
|
||||
foreach (test ${tests})
|
||||
add_executable (${test} ${test})
|
||||
add_test (lsr-${test} ${BIN}${test})
|
||||
set_property (TEST lsr-${test} PROPERTY ENVIRONMENT "SOXR_LSR_STRICT=1")
|
||||
endforeach ()
|
||||
|
||||
add_executable (multichan_throughput_test multichan_throughput_test)
|
||||
add_executable (throughput_test throughput_test )
|
||||
add_executable (sndfile-resample sndfile-resample)
|
|
@ -1,340 +0,0 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
||||
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Library General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Library General
|
||||
Public License instead of this License.
|
|
@ -1,8 +0,0 @@
|
|||
The C source and header files in this directory have been copied from
|
||||
the `libsamplerate' project and are copyrighted by its authors -- see
|
||||
the notices within the files and the file `COPYING' for details.
|
||||
|
||||
They are used here to test libsoxr's optional libsamplerate-like
|
||||
wrapper. The only modifications made are to the file `snr_bw_test.c' to
|
||||
remove reliance on certain frequency response troughs that are specific
|
||||
to libsamplerate.
|
|
@ -1,242 +0,0 @@
|
|||
/*
|
||||
** Copyright (C) 2002-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
|
||||
**
|
||||
** This program is free software; you can redistribute it and/or modify
|
||||
** it under the terms of the GNU General Public License as published by
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "util.h"
|
||||
|
||||
#if (HAVE_FFTW3 == 1)
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <fftw3.h>
|
||||
|
||||
#define MAX_SPEC_LEN (1<<18)
|
||||
#define MAX_PEAKS 10
|
||||
|
||||
static void log_mag_spectrum (double *input, int len, double *magnitude) ;
|
||||
static void smooth_mag_spectrum (double *magnitude, int len) ;
|
||||
static double find_snr (const double *magnitude, int len, int expected_peaks) ;
|
||||
|
||||
typedef struct
|
||||
{ double peak ;
|
||||
int index ;
|
||||
} PEAK_DATA ;
|
||||
|
||||
double
|
||||
calculate_snr (float *data, int len, int expected_peaks)
|
||||
{ static double magnitude [MAX_SPEC_LEN] ;
|
||||
static double datacopy [MAX_SPEC_LEN] ;
|
||||
|
||||
double snr = 200.0 ;
|
||||
int k ;
|
||||
|
||||
if (len > MAX_SPEC_LEN)
|
||||
{ printf ("%s : line %d : data length too large.\n", __FILE__, __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
for (k = 0 ; k < len ; k++)
|
||||
datacopy [k] = data [k] ;
|
||||
|
||||
/* Pad the data just a little to speed up the FFT. */
|
||||
while ((len & 0x1F) && len < MAX_SPEC_LEN)
|
||||
{ datacopy [len] = 0.0 ;
|
||||
len ++ ;
|
||||
} ;
|
||||
|
||||
log_mag_spectrum (datacopy, len, magnitude) ;
|
||||
smooth_mag_spectrum (magnitude, len / 2) ;
|
||||
|
||||
snr = find_snr (magnitude, len, expected_peaks) ;
|
||||
|
||||
return snr ;
|
||||
} /* calculate_snr */
|
||||
|
||||
/*==============================================================================
|
||||
** There is a slight problem with trying to measure SNR with the method used
|
||||
** here; the side lobes of the windowed FFT can look like a noise/aliasing peak.
|
||||
** The solution is to smooth the magnitude spectrum by wiping out troughs
|
||||
** between adjacent peaks as done here.
|
||||
** This removes side lobe peaks without affecting noise/aliasing peaks.
|
||||
*/
|
||||
|
||||
static void linear_smooth (double *mag, PEAK_DATA *larger, PEAK_DATA *smaller) ;
|
||||
|
||||
static void
|
||||
smooth_mag_spectrum (double *mag, int len)
|
||||
{ PEAK_DATA peaks [2] ;
|
||||
|
||||
int k ;
|
||||
|
||||
memset (peaks, 0, sizeof (peaks)) ;
|
||||
|
||||
/* Find first peak. */
|
||||
for (k = 1 ; k < len - 1 ; k++)
|
||||
{ if (mag [k - 1] < mag [k] && mag [k] >= mag [k + 1])
|
||||
{ peaks [0].peak = mag [k] ;
|
||||
peaks [0].index = k ;
|
||||
break ;
|
||||
} ;
|
||||
} ;
|
||||
|
||||
/* Find subsequent peaks ans smooth between peaks. */
|
||||
for (k = peaks [0].index + 1 ; k < len - 1 ; k++)
|
||||
{ if (mag [k - 1] < mag [k] && mag [k] >= mag [k + 1])
|
||||
{ peaks [1].peak = mag [k] ;
|
||||
peaks [1].index = k ;
|
||||
|
||||
if (peaks [1].peak > peaks [0].peak)
|
||||
linear_smooth (mag, &peaks [1], &peaks [0]) ;
|
||||
else
|
||||
linear_smooth (mag, &peaks [0], &peaks [1]) ;
|
||||
peaks [0] = peaks [1] ;
|
||||
} ;
|
||||
} ;
|
||||
|
||||
} /* smooth_mag_spectrum */
|
||||
|
||||
static void
|
||||
linear_smooth (double *mag, PEAK_DATA *larger, PEAK_DATA *smaller)
|
||||
{ int k ;
|
||||
|
||||
if (smaller->index < larger->index)
|
||||
{ for (k = smaller->index + 1 ; k < larger->index ; k++)
|
||||
mag [k] = (mag [k] < mag [k - 1]) ? 0.999 * mag [k - 1] : mag [k] ;
|
||||
}
|
||||
else
|
||||
{ for (k = smaller->index - 1 ; k >= larger->index ; k--)
|
||||
mag [k] = (mag [k] < mag [k + 1]) ? 0.999 * mag [k + 1] : mag [k] ;
|
||||
} ;
|
||||
|
||||
} /* linear_smooth */
|
||||
|
||||
/*==============================================================================
|
||||
*/
|
||||
|
||||
static int
|
||||
peak_compare (const void *vp1, const void *vp2)
|
||||
{ const PEAK_DATA *peak1, *peak2 ;
|
||||
|
||||
peak1 = (const PEAK_DATA*) vp1 ;
|
||||
peak2 = (const PEAK_DATA*) vp2 ;
|
||||
|
||||
return (peak1->peak < peak2->peak) ? 1 : -1 ;
|
||||
} /* peak_compare */
|
||||
|
||||
static double
|
||||
find_snr (const double *magnitude, int len, int expected_peaks)
|
||||
{ PEAK_DATA peaks [MAX_PEAKS] ;
|
||||
|
||||
int k, peak_count = 0 ;
|
||||
double snr ;
|
||||
|
||||
memset (peaks, 0, sizeof (peaks)) ;
|
||||
|
||||
/* Find the MAX_PEAKS largest peaks. */
|
||||
for (k = 1 ; k < len - 1 ; k++)
|
||||
{ if (magnitude [k - 1] < magnitude [k] && magnitude [k] >= magnitude [k + 1])
|
||||
{ if (peak_count < MAX_PEAKS)
|
||||
{ peaks [peak_count].peak = magnitude [k] ;
|
||||
peaks [peak_count].index = k ;
|
||||
peak_count ++ ;
|
||||
qsort (peaks, peak_count, sizeof (PEAK_DATA), peak_compare) ;
|
||||
}
|
||||
else if (magnitude [k] > peaks [MAX_PEAKS - 1].peak)
|
||||
{ peaks [MAX_PEAKS - 1].peak = magnitude [k] ;
|
||||
peaks [MAX_PEAKS - 1].index = k ;
|
||||
qsort (peaks, MAX_PEAKS, sizeof (PEAK_DATA), peak_compare) ;
|
||||
} ;
|
||||
} ;
|
||||
} ;
|
||||
|
||||
if (peak_count < expected_peaks)
|
||||
{ printf ("\n%s : line %d : bad peak_count (%d), expected %d.\n\n", __FILE__, __LINE__, peak_count, expected_peaks) ;
|
||||
return -1.0 ;
|
||||
} ;
|
||||
|
||||
/* Sort the peaks. */
|
||||
qsort (peaks, peak_count, sizeof (PEAK_DATA), peak_compare) ;
|
||||
|
||||
snr = peaks [0].peak ;
|
||||
for (k = 1 ; k < peak_count ; k++)
|
||||
if (fabs (snr - peaks [k].peak) > 10.0)
|
||||
return fabs (peaks [k].peak) ;
|
||||
|
||||
return snr ;
|
||||
} /* find_snr */
|
||||
|
||||
static void
|
||||
log_mag_spectrum (double *input, int len, double *magnitude)
|
||||
{ fftw_plan plan = NULL ;
|
||||
|
||||
double maxval ;
|
||||
int k ;
|
||||
|
||||
if (input == NULL || magnitude == NULL)
|
||||
return ;
|
||||
|
||||
plan = fftw_plan_r2r_1d (len, input, magnitude, FFTW_R2HC, FFTW_ESTIMATE | FFTW_PRESERVE_INPUT) ;
|
||||
if (plan == NULL)
|
||||
{ printf ("%s : line %d : create plan failed.\n", __FILE__, __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
fftw_execute (plan) ;
|
||||
|
||||
fftw_destroy_plan (plan) ;
|
||||
|
||||
/* (k < N/2 rounded up) */
|
||||
maxval = 0.0 ;
|
||||
for (k = 1 ; k < len / 2 ; k++)
|
||||
{ magnitude [k] = sqrt (magnitude [k] * magnitude [k] + magnitude [len - k - 1] * magnitude [len - k - 1]) ;
|
||||
maxval = (maxval < magnitude [k]) ? magnitude [k] : maxval ;
|
||||
} ;
|
||||
|
||||
memset (magnitude + len / 2, 0, len / 2 * sizeof (magnitude [0])) ;
|
||||
|
||||
/* Don't care about DC component. Make it zero. */
|
||||
magnitude [0] = 0.0 ;
|
||||
|
||||
/* log magnitude. */
|
||||
for (k = 0 ; k < len ; k++)
|
||||
{ magnitude [k] = magnitude [k] / maxval ;
|
||||
magnitude [k] = (magnitude [k] < 1e-15) ? -200.0 : 20.0 * log10 (magnitude [k]) ;
|
||||
} ;
|
||||
|
||||
return ;
|
||||
} /* log_mag_spectrum */
|
||||
|
||||
#else /* ! (HAVE_LIBFFTW && HAVE_LIBRFFTW) */
|
||||
|
||||
double
|
||||
calculate_snr (float *data, int len, int expected_peaks)
|
||||
{ double snr = 200.0 ;
|
||||
|
||||
data = data ;
|
||||
len = len ;
|
||||
expected_peaks = expected_peaks ;
|
||||
|
||||
return snr ;
|
||||
} /* calculate_snr */
|
||||
|
||||
#endif
|
||||
|
|
@ -1,131 +0,0 @@
|
|||
/*
|
||||
** Copyright (C) 2002-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
|
||||
**
|
||||
** This program is free software; you can redistribute it and/or modify
|
||||
** it under the terms of the GNU General Public License as published by
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <math.h>
|
||||
|
||||
#if HAVE_ALARM && HAVE_SIGNAL && HAVE_SIGALRM
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
#include <samplerate.h>
|
||||
|
||||
#include "util.h"
|
||||
|
||||
#define SHORT_BUFFER_LEN 512
|
||||
#define LONG_BUFFER_LEN (1 << 14)
|
||||
|
||||
typedef struct
|
||||
{ double ratio ;
|
||||
int count ;
|
||||
} SRC_PAIR ;
|
||||
|
||||
static void callback_hang_test (int converter) ;
|
||||
|
||||
static void alarm_handler (int number) ;
|
||||
static long input_callback (void *cb_data, float **data) ;
|
||||
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
/* Set up SIGALRM handler. */
|
||||
signal (SIGALRM, alarm_handler) ;
|
||||
|
||||
puts ("") ;
|
||||
callback_hang_test (SRC_ZERO_ORDER_HOLD) ;
|
||||
callback_hang_test (SRC_LINEAR) ;
|
||||
callback_hang_test (SRC_SINC_FASTEST) ;
|
||||
puts ("") ;
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
|
||||
static void
|
||||
callback_hang_test (int converter)
|
||||
{ static float output [LONG_BUFFER_LEN] ;
|
||||
static SRC_PAIR pairs [] =
|
||||
{
|
||||
{ 1.2, 5 }, { 1.1, 1 }, { 1.0, 1 }, { 3.0, 1 }, { 2.0, 1 }, { 0.3, 1 },
|
||||
{ 1.2, 0 }, { 1.1, 10 }, { 1.0, 1 }
|
||||
} ;
|
||||
|
||||
|
||||
SRC_STATE *src_state ;
|
||||
|
||||
double src_ratio = 1.0 ;
|
||||
int k, error ;
|
||||
|
||||
printf ("\tcallback_hang_test (%-28s) ....... ", src_get_name (converter)) ;
|
||||
fflush (stdout) ;
|
||||
|
||||
/* Perform sample rate conversion. */
|
||||
src_state = src_callback_new (input_callback, converter, 1, &error, NULL) ;
|
||||
if (src_state == NULL)
|
||||
{ printf ("\n\nLine %d : src_callback_new () failed : %s\n\n", __LINE__, src_strerror (error)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
for (k = 0 ; k < ARRAY_LEN (pairs) ; k++)
|
||||
{ alarm (1) ;
|
||||
src_ratio = pairs [k].ratio ;
|
||||
src_callback_read (src_state, src_ratio, pairs [k].count, output) ;
|
||||
} ;
|
||||
|
||||
src_state = src_delete (src_state) ;
|
||||
|
||||
alarm (0) ;
|
||||
puts ("ok") ;
|
||||
|
||||
return ;
|
||||
} /* callback_hang_test */
|
||||
|
||||
static void
|
||||
alarm_handler (int number)
|
||||
{
|
||||
(void) number ;
|
||||
printf ("\n\n Error : Hang inside src_callback_read() detected. Exiting!\n\n") ;
|
||||
exit (1) ;
|
||||
} /* alarm_handler */
|
||||
|
||||
static long
|
||||
input_callback (void *cb_data, float **data)
|
||||
{
|
||||
static float buffer [20] ;
|
||||
|
||||
(void) cb_data ;
|
||||
*data = buffer ;
|
||||
|
||||
return ARRAY_LEN (buffer) ;
|
||||
} /* input_callback */
|
||||
|
||||
#else
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
puts ("\tCan't run this test on this platform.") ;
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
#endif
|
|
@ -1,243 +0,0 @@
|
|||
/*
|
||||
** Copyright (C) 2003-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
|
||||
**
|
||||
** This program is free software; you can redistribute it and/or modify
|
||||
** it under the terms of the GNU General Public License as published by
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <samplerate.h>
|
||||
|
||||
#include "util.h"
|
||||
|
||||
#define BUFFER_LEN 10000
|
||||
#define CB_READ_LEN 256
|
||||
|
||||
static void callback_test (int converter, double ratio) ;
|
||||
static void end_of_stream_test (int converter) ;
|
||||
|
||||
int
|
||||
main (void)
|
||||
{ static double src_ratios [] =
|
||||
{ 1.0, 0.099, 0.1, 0.33333333, 0.789, 1.0001, 1.9, 3.1, 9.9
|
||||
} ;
|
||||
|
||||
int k ;
|
||||
|
||||
puts ("") ;
|
||||
|
||||
puts (" Zero Order Hold interpolator :") ;
|
||||
for (k = 0 ; k < ARRAY_LEN (src_ratios) ; k++)
|
||||
callback_test (SRC_ZERO_ORDER_HOLD, src_ratios [k]) ;
|
||||
|
||||
puts (" Linear interpolator :") ;
|
||||
for (k = 0 ; k < ARRAY_LEN (src_ratios) ; k++)
|
||||
callback_test (SRC_LINEAR, src_ratios [k]) ;
|
||||
|
||||
puts (" Sinc interpolator :") ;
|
||||
for (k = 0 ; k < ARRAY_LEN (src_ratios) ; k++)
|
||||
callback_test (SRC_SINC_FASTEST, src_ratios [k]) ;
|
||||
|
||||
puts ("") ;
|
||||
|
||||
puts (" End of stream test :") ;
|
||||
end_of_stream_test (SRC_ZERO_ORDER_HOLD) ;
|
||||
end_of_stream_test (SRC_LINEAR) ;
|
||||
end_of_stream_test (SRC_SINC_FASTEST) ;
|
||||
|
||||
puts ("") ;
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
/*=====================================================================================
|
||||
*/
|
||||
|
||||
typedef struct
|
||||
{ int channels ;
|
||||
long count, total ;
|
||||
int end_of_data ;
|
||||
float data [BUFFER_LEN] ;
|
||||
} TEST_CB_DATA ;
|
||||
|
||||
static long
|
||||
test_callback_func (void *cb_data, float **data)
|
||||
{ TEST_CB_DATA *pcb_data ;
|
||||
|
||||
long frames ;
|
||||
|
||||
if ((pcb_data = cb_data) == NULL)
|
||||
return 0 ;
|
||||
|
||||
if (data == NULL)
|
||||
return 0 ;
|
||||
|
||||
if (pcb_data->total - pcb_data->count > CB_READ_LEN)
|
||||
frames = CB_READ_LEN / pcb_data->channels ;
|
||||
else
|
||||
frames = (pcb_data->total - pcb_data->count) / pcb_data->channels ;
|
||||
|
||||
*data = pcb_data->data + pcb_data->count ;
|
||||
pcb_data->count += frames ;
|
||||
|
||||
return frames ;
|
||||
} /* test_callback_func */
|
||||
|
||||
|
||||
static void
|
||||
callback_test (int converter, double src_ratio)
|
||||
{ static TEST_CB_DATA test_callback_data ;
|
||||
static float output [BUFFER_LEN] ;
|
||||
|
||||
SRC_STATE *src_state ;
|
||||
|
||||
long read_count, read_total ;
|
||||
int error ;
|
||||
|
||||
printf ("\tcallback_test (SRC ratio = %6.4f) ........... ", src_ratio) ;
|
||||
fflush (stdout) ;
|
||||
|
||||
test_callback_data.channels = 2 ;
|
||||
test_callback_data.count = 0 ;
|
||||
test_callback_data.end_of_data = 0 ;
|
||||
test_callback_data.total = ARRAY_LEN (test_callback_data.data) ;
|
||||
|
||||
if ((src_state = src_callback_new (test_callback_func, converter, test_callback_data.channels, &error, &test_callback_data)) == NULL)
|
||||
{ printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
read_total = 0 ;
|
||||
do
|
||||
{ /* We will be throwing away output data, so just grab as much as possible. */
|
||||
read_count = ARRAY_LEN (output) / test_callback_data.channels ;
|
||||
read_count = src_callback_read (src_state, src_ratio, read_count, output) ;
|
||||
read_total += read_count ;
|
||||
}
|
||||
while (read_count > 0) ;
|
||||
|
||||
if ((error = src_error (src_state)) != 0)
|
||||
{ printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
src_state = src_delete (src_state) ;
|
||||
|
||||
if (fabs (read_total / src_ratio - ARRAY_LEN (test_callback_data.data)) > 2.0)
|
||||
{ printf ("\n\nLine %d : input / output length mismatch.\n\n", __LINE__) ;
|
||||
printf (" input len : %d\n", ARRAY_LEN (test_callback_data.data)) ;
|
||||
printf (" output len : %ld (should be %g +/- 2)\n\n", read_total,
|
||||
floor (0.5 + src_ratio * ARRAY_LEN (test_callback_data.data))) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
puts ("ok") ;
|
||||
|
||||
return ;
|
||||
} /* callback_test */
|
||||
|
||||
/*=====================================================================================
|
||||
*/
|
||||
|
||||
static long
|
||||
eos_callback_func (void *cb_data, float **data)
|
||||
{
|
||||
TEST_CB_DATA *pcb_data ;
|
||||
long frames ;
|
||||
|
||||
if (data == NULL)
|
||||
return 0 ;
|
||||
|
||||
if ((pcb_data = cb_data) == NULL)
|
||||
return 0 ;
|
||||
|
||||
/*
|
||||
** Return immediately if there is no more data.
|
||||
** In this case, the output pointer 'data' will not be set and
|
||||
** valgrind should not warn about it.
|
||||
*/
|
||||
if (pcb_data->end_of_data)
|
||||
return 0 ;
|
||||
|
||||
if (pcb_data->total - pcb_data->count > CB_READ_LEN)
|
||||
frames = CB_READ_LEN / pcb_data->channels ;
|
||||
else
|
||||
frames = (pcb_data->total - pcb_data->count) / pcb_data->channels ;
|
||||
|
||||
*data = pcb_data->data + pcb_data->count ;
|
||||
pcb_data->count += frames ;
|
||||
|
||||
/*
|
||||
** Set end_of_data so that the next call to the callback function will
|
||||
** return zero ocunt without setting the 'data' pointer.
|
||||
*/
|
||||
if (pcb_data->total < 2 * pcb_data->count)
|
||||
pcb_data->end_of_data = 1 ;
|
||||
|
||||
return frames ;
|
||||
} /* eos_callback_data */
|
||||
|
||||
|
||||
static void
|
||||
end_of_stream_test (int converter)
|
||||
{ static TEST_CB_DATA test_callback_data ;
|
||||
static float output [BUFFER_LEN] ;
|
||||
|
||||
SRC_STATE *src_state ;
|
||||
|
||||
double src_ratio = 0.3 ;
|
||||
long read_count, read_total ;
|
||||
int error ;
|
||||
|
||||
printf ("\t%-30s ........... ", src_get_name (converter)) ;
|
||||
fflush (stdout) ;
|
||||
|
||||
test_callback_data.channels = 2 ;
|
||||
test_callback_data.count = 0 ;
|
||||
test_callback_data.end_of_data = 0 ;
|
||||
test_callback_data.total = ARRAY_LEN (test_callback_data.data) ;
|
||||
|
||||
if ((src_state = src_callback_new (eos_callback_func, converter, test_callback_data.channels, &error, &test_callback_data)) == NULL)
|
||||
{ printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
read_total = 0 ;
|
||||
do
|
||||
{ /* We will be throwing away output data, so just grab as much as possible. */
|
||||
read_count = ARRAY_LEN (output) / test_callback_data.channels ;
|
||||
read_count = src_callback_read (src_state, src_ratio, read_count, output) ;
|
||||
read_total += read_count ;
|
||||
}
|
||||
while (read_count > 0) ;
|
||||
|
||||
if ((error = src_error (src_state)) != 0)
|
||||
{ printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
src_state = src_delete (src_state) ;
|
||||
|
||||
if (test_callback_data.end_of_data == 0)
|
||||
{ printf ("\n\nLine %d : test_callback_data.end_of_data should not be 0."
|
||||
" This is a bug in the test.\n\n", __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
puts ("ok") ;
|
||||
return ;
|
||||
} /* end_of_stream_test */
|
|
@ -1,23 +0,0 @@
|
|||
# SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
# Licence for this file: LGPL v2.1 See LICENCE for details.
|
||||
|
||||
# - Find FFTW
|
||||
# Find the native installation of this package: includes and libraries.
|
||||
#
|
||||
# FFTW_INCLUDES - where to find headers for this package.
|
||||
# FFTW_LIBRARIES - List of libraries when using this package.
|
||||
# FFTW_FOUND - True if this package can be found.
|
||||
|
||||
if (FFTW_INCLUDES)
|
||||
set (FFTW_FIND_QUIETLY TRUE)
|
||||
endif (FFTW_INCLUDES)
|
||||
|
||||
find_path (FFTW_INCLUDES fftw3.h)
|
||||
|
||||
find_library (FFTW_LIBRARIES NAMES fftw3)
|
||||
|
||||
include (FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args (
|
||||
FFTW DEFAULT_MSG FFTW_LIBRARIES FFTW_INCLUDES)
|
||||
|
||||
mark_as_advanced (FFTW_LIBRARIES FFTW_INCLUDES)
|
|
@ -1,23 +0,0 @@
|
|||
# SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
# Licence for this file: LGPL v2.1 See LICENCE for details.
|
||||
|
||||
# - Find SNDFILE
|
||||
# Find the native installation of this package: includes and libraries.
|
||||
#
|
||||
# SNDFILE_INCLUDES - where to find headers for this package.
|
||||
# SNDFILE_LIBRARIES - List of libraries when using this package.
|
||||
# SNDFILE_FOUND - True if this package can be found.
|
||||
|
||||
if (SNDFILE_INCLUDES)
|
||||
set (SNDFILE_FIND_QUIETLY TRUE)
|
||||
endif (SNDFILE_INCLUDES)
|
||||
|
||||
find_path (SNDFILE_INCLUDES sndfile.h)
|
||||
|
||||
find_library (SNDFILE_LIBRARIES NAMES sndfile)
|
||||
|
||||
include (FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args (
|
||||
SNDFILE DEFAULT_MSG SNDFILE_LIBRARIES SNDFILE_INCLUDES)
|
||||
|
||||
mark_as_advanced (SNDFILE_LIBRARIES SNDFILE_INCLUDES)
|
|
@ -1,24 +0,0 @@
|
|||
/* SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
* Licence for this file: LGPL v2.1 See LICENCE for details. */
|
||||
|
||||
#if !defined soxsrc_lsr_tests_config_included
|
||||
#define soxsrc_lsr_tests_config_included
|
||||
|
||||
#define HAVE_ALARM @HAVE_ALARM@
|
||||
#define HAVE_FFTW3 @HAVE_FFTW3@
|
||||
#define HAVE_LRINTF @HAVE_LRINTF@
|
||||
#define HAVE_LRINT @HAVE_LRINT@
|
||||
#define HAVE_SIGNAL @HAVE_SIGNAL@
|
||||
#define HAVE_SNDFILE @HAVE_SNDFILE@
|
||||
#define HAVE_SYS_TIMES_H @HAVE_SYS_TIMES_H@
|
||||
|
||||
#if HAVE_SIGNAL
|
||||
#include <signal.h>
|
||||
#if defined SIGALRM
|
||||
#define HAVE_SIGALRM 1
|
||||
#else
|
||||
#define HAVE_SIGALRM 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,61 +0,0 @@
|
|||
/*
|
||||
** Copyright (C) 2008-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
|
||||
**
|
||||
** This program is free software; you can redistribute it and/or modify
|
||||
** it under the terms of the GNU General Public License as published by
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <samplerate.h>
|
||||
|
||||
#include "util.h"
|
||||
|
||||
static void
|
||||
downsample_test (int converter)
|
||||
{ static float in [1000], out [10] ;
|
||||
SRC_DATA data ;
|
||||
|
||||
printf (" downsample_test (%-28s) ....... ", src_get_name (converter)) ;
|
||||
fflush (stdout) ;
|
||||
|
||||
data.src_ratio = 1.0 / 255.0 ;
|
||||
data.input_frames = ARRAY_LEN (in) ;
|
||||
data.output_frames = ARRAY_LEN (out) ;
|
||||
data.data_in = in ;
|
||||
data.data_out = out ;
|
||||
|
||||
if (src_simple (&data, converter, 1))
|
||||
{ puts ("src_simple failed.") ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
puts ("ok") ;
|
||||
} /* downsample_test */
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
puts ("") ;
|
||||
|
||||
downsample_test (SRC_ZERO_ORDER_HOLD) ;
|
||||
downsample_test (SRC_LINEAR) ;
|
||||
downsample_test (SRC_SINC_FASTEST) ;
|
||||
downsample_test (SRC_SINC_MEDIUM_QUALITY) ;
|
||||
downsample_test (SRC_SINC_BEST_QUALITY) ;
|
||||
|
||||
puts ("") ;
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
|
@ -1,281 +0,0 @@
|
|||
/*
|
||||
** Copyright (C) 2001-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
|
||||
**
|
||||
** This program is free software; you can redistribute it and/or modify
|
||||
** it under the terms of the GNU Lesser General Public License as published by
|
||||
** the Free Software Foundation; either version 2.1 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU Lesser General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU Lesser General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/* Version 1.5 */
|
||||
|
||||
#ifndef FLOAT_CAST_HEADER
|
||||
#define FLOAT_CAST_HEADER
|
||||
|
||||
/*============================================================================
|
||||
** On Intel Pentium processors (especially PIII and probably P4), converting
|
||||
** from float to int is very slow. To meet the C specs, the code produced by
|
||||
** most C compilers targeting Pentium needs to change the FPU rounding mode
|
||||
** before the float to int conversion is performed.
|
||||
**
|
||||
** Changing the FPU rounding mode causes the FPU pipeline to be flushed. It
|
||||
** is this flushing of the pipeline which is so slow.
|
||||
**
|
||||
** Fortunately the ISO C99 specifications define the functions lrint, lrintf,
|
||||
** llrint and llrintf which fix this problem as a side effect.
|
||||
**
|
||||
** On Unix-like systems, the configure process should have detected the
|
||||
** presence of these functions. If they weren't found we have to replace them
|
||||
** here with a standard C cast.
|
||||
*/
|
||||
|
||||
/*
|
||||
** The C99 prototypes for lrint and lrintf are as follows:
|
||||
**
|
||||
** long int lrintf (float x) ;
|
||||
** long int lrint (double x) ;
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
/*
|
||||
** The presence of the required functions are detected during the configure
|
||||
** process and the values HAVE_LRINT and HAVE_LRINTF are set accordingly in
|
||||
** the config.h file.
|
||||
*/
|
||||
|
||||
#define HAVE_LRINT_REPLACEMENT 0
|
||||
|
||||
#if (HAVE_LRINT && HAVE_LRINTF)
|
||||
|
||||
/*
|
||||
** These defines enable functionality introduced with the 1999 ISO C
|
||||
** standard. They must be defined before the inclusion of math.h to
|
||||
** engage them. If optimisation is enabled, these functions will be
|
||||
** inlined. With optimisation switched off, you have to link in the
|
||||
** maths library using -lm.
|
||||
*/
|
||||
|
||||
#define _ISOC9X_SOURCE 1
|
||||
#define _ISOC99_SOURCE 1
|
||||
|
||||
#define __USE_ISOC9X 1
|
||||
#define __USE_ISOC99 1
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#elif (defined (__CYGWIN__))
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#undef HAVE_LRINT_REPLACEMENT
|
||||
#define HAVE_LRINT_REPLACEMENT 1
|
||||
|
||||
#undef lrint
|
||||
#undef lrintf
|
||||
|
||||
#define lrint double2int
|
||||
#define lrintf float2int
|
||||
|
||||
/*
|
||||
** The native CYGWIN lrint and lrintf functions are buggy:
|
||||
** http://sourceware.org/ml/cygwin/2005-06/msg00153.html
|
||||
** http://sourceware.org/ml/cygwin/2005-09/msg00047.html
|
||||
** and slow.
|
||||
** These functions (pulled from the Public Domain MinGW math.h header)
|
||||
** replace the native versions.
|
||||
*/
|
||||
|
||||
static inline long double2int (double in)
|
||||
{ long retval ;
|
||||
|
||||
__asm__ __volatile__
|
||||
( "fistpl %0"
|
||||
: "=m" (retval)
|
||||
: "t" (in)
|
||||
: "st"
|
||||
) ;
|
||||
|
||||
return retval ;
|
||||
} /* double2int */
|
||||
|
||||
static inline long float2int (float in)
|
||||
{ long retval ;
|
||||
|
||||
__asm__ __volatile__
|
||||
( "fistpl %0"
|
||||
: "=m" (retval)
|
||||
: "t" (in)
|
||||
: "st"
|
||||
) ;
|
||||
|
||||
return retval ;
|
||||
} /* float2int */
|
||||
|
||||
#elif (defined (WIN64) || defined(_WIN64))
|
||||
|
||||
/* Win64 section should be places before Win32 one, because
|
||||
** most likely both WIN32 and WIN64 will be defined in 64-bit case.
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
|
||||
/* Win64 doesn't seem to have these functions, nor inline assembly.
|
||||
** Therefore implement inline versions of these functions here.
|
||||
*/
|
||||
#include <emmintrin.h>
|
||||
#include <mmintrin.h>
|
||||
|
||||
__inline long int
|
||||
lrint(double flt)
|
||||
{
|
||||
return _mm_cvtsd_si32(_mm_load_sd(&flt));
|
||||
}
|
||||
|
||||
__inline long int
|
||||
lrintf(float flt)
|
||||
{
|
||||
return _mm_cvtss_si32(_mm_load_ss(&flt));
|
||||
}
|
||||
|
||||
#elif (defined (WIN32) || defined (_WIN32))
|
||||
|
||||
#undef HAVE_LRINT_REPLACEMENT
|
||||
#define HAVE_LRINT_REPLACEMENT 1
|
||||
|
||||
#include <math.h>
|
||||
|
||||
/*
|
||||
** Win32 doesn't seem to have these functions.
|
||||
** Therefore implement inline versions of these functions here.
|
||||
*/
|
||||
|
||||
__inline long int
|
||||
lrint (double flt)
|
||||
{ int intgr ;
|
||||
|
||||
_asm
|
||||
{ fld flt
|
||||
fistp intgr
|
||||
} ;
|
||||
|
||||
return intgr ;
|
||||
}
|
||||
|
||||
__inline long int
|
||||
lrintf (float flt)
|
||||
{ int intgr ;
|
||||
|
||||
_asm
|
||||
{ fld flt
|
||||
fistp intgr
|
||||
} ;
|
||||
|
||||
return intgr ;
|
||||
}
|
||||
|
||||
#elif (defined (__MWERKS__) && defined (macintosh))
|
||||
|
||||
/* This MacOS 9 solution was provided by Stephane Letz */
|
||||
|
||||
#undef HAVE_LRINT_REPLACEMENT
|
||||
#define HAVE_LRINT_REPLACEMENT 1
|
||||
#include <math.h>
|
||||
|
||||
#undef lrint
|
||||
#undef lrintf
|
||||
|
||||
#define lrint double2int
|
||||
#define lrintf float2int
|
||||
|
||||
inline int
|
||||
float2int (register float in)
|
||||
{ long res [2] ;
|
||||
|
||||
asm
|
||||
{ fctiw in, in
|
||||
stfd in, res
|
||||
}
|
||||
return res [1] ;
|
||||
} /* float2int */
|
||||
|
||||
inline int
|
||||
double2int (register double in)
|
||||
{ long res [2] ;
|
||||
|
||||
asm
|
||||
{ fctiw in, in
|
||||
stfd in, res
|
||||
}
|
||||
return res [1] ;
|
||||
} /* double2int */
|
||||
|
||||
#elif (defined (__MACH__) && defined (__APPLE__))
|
||||
|
||||
/* For Apple MacOSX. */
|
||||
|
||||
#undef HAVE_LRINT_REPLACEMENT
|
||||
#define HAVE_LRINT_REPLACEMENT 1
|
||||
#include <math.h>
|
||||
|
||||
#undef lrint
|
||||
#undef lrintf
|
||||
|
||||
#define lrint double2int
|
||||
#define lrintf float2int
|
||||
|
||||
inline static long
|
||||
float2int (register float in)
|
||||
{ int res [2] ;
|
||||
|
||||
__asm__ __volatile__
|
||||
( "fctiw %1, %1\n\t"
|
||||
"stfd %1, %0"
|
||||
: "=m" (res) /* Output */
|
||||
: "f" (in) /* Input */
|
||||
: "memory"
|
||||
) ;
|
||||
|
||||
return res [1] ;
|
||||
} /* lrintf */
|
||||
|
||||
inline static long
|
||||
double2int (register double in)
|
||||
{ int res [2] ;
|
||||
|
||||
__asm__ __volatile__
|
||||
( "fctiw %1, %1\n\t"
|
||||
"stfd %1, %0"
|
||||
: "=m" (res) /* Output */
|
||||
: "f" (in) /* Input */
|
||||
: "memory"
|
||||
) ;
|
||||
|
||||
return res [1] ;
|
||||
} /* lrint */
|
||||
|
||||
#else
|
||||
#ifndef __sgi
|
||||
#warning "Don't have the functions lrint() and lrintf()."
|
||||
#warning "Replacing these functions with a standard C cast."
|
||||
#endif
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#define lrint(dbl) ((long) (dbl))
|
||||
#define lrintf(flt) ((long) (flt))
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* FLOAT_CAST_HEADER */
|
||||
|
|
@ -1,192 +0,0 @@
|
|||
/*
|
||||
** Copyright (C) 2003-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
|
||||
**
|
||||
** This program is free software; you can redistribute it and/or modify
|
||||
** it under the terms of the GNU General Public License as published by
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <samplerate.h>
|
||||
|
||||
#include "util.h"
|
||||
|
||||
#define BUFFER_LEN 10000
|
||||
|
||||
static void float_to_short_test (void) ;
|
||||
static void short_to_float_test (void) ;
|
||||
|
||||
static void float_to_int_test (void) ;
|
||||
static void int_to_float_test (void) ;
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
puts ("") ;
|
||||
|
||||
float_to_short_test () ;
|
||||
short_to_float_test () ;
|
||||
|
||||
float_to_int_test () ;
|
||||
int_to_float_test () ;
|
||||
|
||||
puts ("") ;
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
/*=====================================================================================
|
||||
*/
|
||||
|
||||
static void
|
||||
float_to_short_test (void)
|
||||
{
|
||||
static float fpos [] =
|
||||
{ 0.95, 0.99, 1.0, 1.01, 1.1, 2.0, 11.1, 111.1, 2222.2, 33333.3
|
||||
} ;
|
||||
static float fneg [] =
|
||||
{ -0.95, -0.99, -1.0, -1.01, -1.1, -2.0, -11.1, -111.1, -2222.2, -33333.3
|
||||
} ;
|
||||
|
||||
static short out [MAX (ARRAY_LEN (fpos), ARRAY_LEN (fneg))] ;
|
||||
|
||||
int k ;
|
||||
|
||||
printf ("\tfloat_to_short_test ............................. ") ;
|
||||
|
||||
src_float_to_short_array (fpos, out, ARRAY_LEN (fpos)) ;
|
||||
|
||||
for (k = 0 ; k < ARRAY_LEN (fpos) ; k++)
|
||||
if (out [k] < 30000)
|
||||
{ printf ("\n\n\tLine %d : out [%d] == %d\n", __LINE__, k, out [k]) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
src_float_to_short_array (fneg, out, ARRAY_LEN (fneg)) ;
|
||||
|
||||
for (k = 0 ; k < ARRAY_LEN (fneg) ; k++)
|
||||
if (out [k] > -30000)
|
||||
{ printf ("\n\n\tLine %d : out [%d] == %d\n", __LINE__, k, out [k]) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
puts ("ok") ;
|
||||
|
||||
return ;
|
||||
} /* float_to_short_test */
|
||||
|
||||
/*-------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
static void
|
||||
short_to_float_test (void)
|
||||
{
|
||||
static short input [BUFFER_LEN] ;
|
||||
static short output [BUFFER_LEN] ;
|
||||
static float temp [BUFFER_LEN] ;
|
||||
|
||||
int k ;
|
||||
|
||||
printf ("\tshort_to_float_test ............................. ") ;
|
||||
|
||||
for (k = 0 ; k < ARRAY_LEN (input) ; k++)
|
||||
input [k] = (k * 0x8000) / ARRAY_LEN (input) ;
|
||||
|
||||
src_short_to_float_array (input, temp, ARRAY_LEN (temp)) ;
|
||||
src_float_to_short_array (temp, output, ARRAY_LEN (output)) ;
|
||||
|
||||
for (k = 0 ; k < ARRAY_LEN (input) ; k++)
|
||||
if (ABS (input [k] - output [k]) > 0)
|
||||
{ printf ("\n\n\tLine %d : index %d %d -> %d\n", __LINE__, k, input [k], output [k]) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
puts ("ok") ;
|
||||
|
||||
return ;
|
||||
} /* short_to_float_test */
|
||||
|
||||
/*=====================================================================================
|
||||
*/
|
||||
|
||||
static void
|
||||
float_to_int_test (void)
|
||||
{
|
||||
static float fpos [] =
|
||||
{ 0.95, 0.99, 1.0, 1.01, 1.1, 2.0, 11.1, 111.1, 2222.2, 33333.3
|
||||
} ;
|
||||
static float fneg [] =
|
||||
{ -0.95, -0.99, -1.0, -1.01, -1.1, -2.0, -11.1, -111.1, -2222.2, -33333.3
|
||||
} ;
|
||||
|
||||
static int out [MAX (ARRAY_LEN (fpos), ARRAY_LEN (fneg))] ;
|
||||
|
||||
int k ;
|
||||
|
||||
printf ("\tfloat_to_int_test ............................... ") ;
|
||||
|
||||
src_float_to_int_array (fpos, out, ARRAY_LEN (fpos)) ;
|
||||
|
||||
for (k = 0 ; k < ARRAY_LEN (fpos) ; k++)
|
||||
if (out [k] < 30000 * 0x10000)
|
||||
{ printf ("\n\n\tLine %d : out [%d] == %d\n", __LINE__, k, out [k]) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
src_float_to_int_array (fneg, out, ARRAY_LEN (fneg)) ;
|
||||
|
||||
for (k = 0 ; k < ARRAY_LEN (fneg) ; k++)
|
||||
if (out [k] > -30000 * 0x1000)
|
||||
{ printf ("\n\n\tLine %d : out [%d] == %d\n", __LINE__, k, out [k]) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
puts ("ok") ;
|
||||
|
||||
return ;
|
||||
} /* float_to_int_test */
|
||||
|
||||
/*-------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
static void
|
||||
int_to_float_test (void)
|
||||
{
|
||||
static int input [BUFFER_LEN] ;
|
||||
static int output [BUFFER_LEN] ;
|
||||
static float temp [BUFFER_LEN] ;
|
||||
|
||||
int k ;
|
||||
|
||||
printf ("\tint_to_float_test ............................... ") ;
|
||||
|
||||
for (k = 0 ; k < ARRAY_LEN (input) ; k++)
|
||||
input [k] = (k * 0x80000000) / ARRAY_LEN (input) ;
|
||||
|
||||
src_int_to_float_array (input, temp, ARRAY_LEN (temp)) ;
|
||||
src_float_to_int_array (temp, output, ARRAY_LEN (output)) ;
|
||||
|
||||
for (k = 0 ; k < ARRAY_LEN (input) ; k++)
|
||||
if (ABS (input [k] - output [k]) > 0)
|
||||
{ printf ("\n\n\tLine %d : index %d %d -> %d\n", __LINE__, k, input [k], output [k]) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
puts ("ok") ;
|
||||
|
||||
return ;
|
||||
} /* int_to_float_test */
|
||||
|
|
@ -1,175 +0,0 @@
|
|||
/*
|
||||
** Copyright (C) 2002-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
|
||||
**
|
||||
** This program is free software; you can redistribute it and/or modify
|
||||
** it under the terms of the GNU General Public License as published by
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <samplerate.h>
|
||||
|
||||
#include "util.h"
|
||||
|
||||
static void name_test (void) ;
|
||||
static void error_test (void) ;
|
||||
static void src_ratio_test (void) ;
|
||||
static void zero_input_test (int converter) ;
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
puts ("") ;
|
||||
|
||||
printf (" version : %s\n\n", src_get_version ()) ;
|
||||
|
||||
/* Current max converter is SRC_LINEAR. */
|
||||
name_test () ;
|
||||
|
||||
error_test () ;
|
||||
|
||||
src_ratio_test () ;
|
||||
|
||||
zero_input_test (SRC_ZERO_ORDER_HOLD) ;
|
||||
zero_input_test (SRC_LINEAR) ;
|
||||
zero_input_test (SRC_SINC_FASTEST) ;
|
||||
|
||||
puts ("") ;
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
static void
|
||||
name_test (void)
|
||||
{ const char *name ;
|
||||
int k = 0 ;
|
||||
|
||||
puts (" name_test :") ;
|
||||
|
||||
while (1)
|
||||
{ name = src_get_name (k) ;
|
||||
if (name == NULL)
|
||||
break ;
|
||||
printf ("\tName %d : %s\n", k, name) ;
|
||||
printf ("\tDesc %d : %s\n", k, src_get_description (k)) ;
|
||||
k ++ ;
|
||||
} ;
|
||||
|
||||
puts ("") ;
|
||||
|
||||
return ;
|
||||
} /* name_test */
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
typedef struct
|
||||
{ double ratio ;
|
||||
int should_pass ;
|
||||
} RATIO_TEST ;
|
||||
|
||||
static RATIO_TEST ratio_test [] =
|
||||
{ { 1.0 / 256.1, 0 },
|
||||
{ 1.0 / 256.0, 1 },
|
||||
{ 1.0, 1 },
|
||||
{ 256.0, 1 },
|
||||
{ 256.1, 0 },
|
||||
{ -1.0, 0 }
|
||||
} ;
|
||||
|
||||
static void
|
||||
src_ratio_test (void)
|
||||
{ int k ;
|
||||
|
||||
puts (" src_ratio_test (SRC ratio must be in range [1/256, 256]):" ) ;
|
||||
|
||||
|
||||
for (k = 0 ; k < ARRAY_LEN (ratio_test) ; k++)
|
||||
{ if (ratio_test [k].should_pass && src_is_valid_ratio (ratio_test [k].ratio) == 0)
|
||||
{ printf ("\n\nLine %d : SRC ratio %f should have passed.\n\n", __LINE__, ratio_test [k].ratio) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
if (! ratio_test [k].should_pass && src_is_valid_ratio (ratio_test [k].ratio) != 0)
|
||||
{ printf ("\n\nLine %d : SRC ratio %f should not have passed.\n\n", __LINE__, ratio_test [k].ratio) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
printf ("\t SRC ratio (%9.5f) : %s ................... ok\n", ratio_test [k].ratio,
|
||||
(ratio_test [k].should_pass ? "pass" : "fail")) ;
|
||||
} ;
|
||||
|
||||
puts ("") ;
|
||||
|
||||
return ;
|
||||
} /* src_ratio_test */
|
||||
|
||||
static void
|
||||
error_test (void)
|
||||
{ const char *errorstr ;
|
||||
int k, errors = 0 ;
|
||||
|
||||
puts (" error_test :") ;
|
||||
|
||||
for (k = 0 ; 1 ; k++)
|
||||
{ errorstr = src_strerror (k) ;
|
||||
printf ("\t%-2d : %s\n", k, errorstr) ;
|
||||
if (errorstr == NULL)
|
||||
{ errors ++ ;
|
||||
continue ;
|
||||
} ;
|
||||
if (strstr (errorstr, "Placeholder.") == errorstr)
|
||||
break ;
|
||||
} ;
|
||||
|
||||
if (errors != 0)
|
||||
{ printf ("\n\nLine %d : Missing error numbers above.\n\n", __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
puts ("") ;
|
||||
|
||||
return ;
|
||||
} /* error_test */
|
||||
|
||||
static void
|
||||
zero_input_test (int converter)
|
||||
{ SRC_DATA data ;
|
||||
SRC_STATE *state ;
|
||||
float out [100] ;
|
||||
int error ;
|
||||
|
||||
printf (" %s (%-26s) ........ ", __func__, src_get_name (converter)) ;
|
||||
fflush (stdout) ;
|
||||
|
||||
if ((state = src_new (converter, 1, &error)) == NULL)
|
||||
{ printf ("\n\nLine %d : src_new failed : %s.\n\n", __LINE__, src_strerror (error)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
data.data_in = (float *) 0xdeadbeef ;
|
||||
data.input_frames = 0 ;
|
||||
data.data_out = out ;
|
||||
data.output_frames = ARRAY_LEN (out) ;
|
||||
data.end_of_input = 0 ;
|
||||
data.src_ratio = 1.0 ;
|
||||
|
||||
if ((error = src_process (state, &data)))
|
||||
{ printf ("\n\nLine %d : src_new failed : %s.\n\n", __LINE__, src_strerror (error)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
state = src_delete (state) ;
|
||||
|
||||
puts ("ok") ;
|
||||
} /* zero_input_test */
|
|
@ -1,364 +0,0 @@
|
|||
/*
|
||||
** Copyright (C) 2002-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
|
||||
**
|
||||
** This program is free software; you can redistribute it and/or modify
|
||||
** it under the terms of the GNU General Public License as published by
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <samplerate.h>
|
||||
|
||||
#include "util.h"
|
||||
#define BUFFER_LEN 50000
|
||||
#define BLOCK_LEN (12)
|
||||
|
||||
#define MAX_CHANNELS 10
|
||||
|
||||
static void simple_test (int converter, int channel_count, double target_snr) ;
|
||||
static void process_test (int converter, int channel_count, double target_snr) ;
|
||||
static void callback_test (int converter, int channel_count, double target_snr) ;
|
||||
|
||||
int
|
||||
main (void)
|
||||
{ double target ;
|
||||
int k ;
|
||||
|
||||
puts ("\n Zero Order Hold interpolator :") ;
|
||||
target = 38.0 ;
|
||||
for (k = 1 ; k <= 3 ; k++)
|
||||
{ simple_test (SRC_ZERO_ORDER_HOLD, k, target) ;
|
||||
process_test (SRC_ZERO_ORDER_HOLD, k, target) ;
|
||||
callback_test (SRC_ZERO_ORDER_HOLD, k, target) ;
|
||||
} ;
|
||||
|
||||
puts ("\n Linear interpolator :") ;
|
||||
target = 79.0 ;
|
||||
for (k = 1 ; k <= 3 ; k++)
|
||||
{ simple_test (SRC_LINEAR, k, target) ;
|
||||
process_test (SRC_LINEAR, k, target) ;
|
||||
callback_test (SRC_LINEAR, k, target) ;
|
||||
} ;
|
||||
|
||||
puts ("\n Sinc interpolator :") ;
|
||||
target = 100.0 ;
|
||||
for (k = 1 ; k <= MAX_CHANNELS ; k++)
|
||||
{ simple_test (SRC_SINC_FASTEST, k, target) ;
|
||||
process_test (SRC_SINC_FASTEST, k, target) ;
|
||||
callback_test (SRC_SINC_FASTEST, k, target) ;
|
||||
} ;
|
||||
|
||||
puts ("") ;
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
/*==============================================================================
|
||||
*/
|
||||
|
||||
static float input_serial [BUFFER_LEN * MAX_CHANNELS] ;
|
||||
static float input_interleaved [BUFFER_LEN * MAX_CHANNELS] ;
|
||||
static float output_interleaved [BUFFER_LEN * MAX_CHANNELS] ;
|
||||
static float output_serial [BUFFER_LEN * MAX_CHANNELS] ;
|
||||
|
||||
static void
|
||||
simple_test (int converter, int channel_count, double target_snr)
|
||||
{ SRC_DATA src_data ;
|
||||
|
||||
double freq, snr ;
|
||||
int ch, error, frames ;
|
||||
|
||||
printf ("\t%-22s (%2d channel%c) ............ ", "simple_test", channel_count, channel_count > 1 ? 's' : ' ') ;
|
||||
fflush (stdout) ;
|
||||
|
||||
assert (channel_count <= MAX_CHANNELS) ;
|
||||
|
||||
memset (input_serial, 0, sizeof (input_serial)) ;
|
||||
memset (input_interleaved, 0, sizeof (input_interleaved)) ;
|
||||
memset (output_interleaved, 0, sizeof (output_interleaved)) ;
|
||||
memset (output_serial, 0, sizeof (output_serial)) ;
|
||||
|
||||
frames = BUFFER_LEN ;
|
||||
|
||||
/* Calculate channel_count separate windowed sine waves. */
|
||||
for (ch = 0 ; ch < channel_count ; ch++)
|
||||
{ freq = (200.0 + 33.333333333 * ch) / 44100.0 ;
|
||||
gen_windowed_sines (1, &freq, 1.0, input_serial + ch * frames, frames) ;
|
||||
} ;
|
||||
|
||||
/* Interleave the data in preparation for SRC. */
|
||||
interleave_data (input_serial, input_interleaved, frames, channel_count) ;
|
||||
|
||||
/* Choose a converstion ratio <= 1.0. */
|
||||
src_data.src_ratio = 0.95 ;
|
||||
|
||||
src_data.data_in = input_interleaved ;
|
||||
src_data.input_frames = frames ;
|
||||
|
||||
src_data.data_out = output_interleaved ;
|
||||
src_data.output_frames = frames ;
|
||||
|
||||
if ((error = src_simple (&src_data, converter, channel_count)))
|
||||
{ printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (fabs (src_data.output_frames_gen - src_data.src_ratio * src_data.input_frames) > 2)
|
||||
{ printf ("\n\nLine %d : bad output data length %ld should be %d.\n", __LINE__,
|
||||
src_data.output_frames_gen, (int) floor (src_data.src_ratio * src_data.input_frames)) ;
|
||||
printf ("\tsrc_ratio : %.4f\n", src_data.src_ratio) ;
|
||||
printf ("\tinput_len : %ld\n", src_data.input_frames) ;
|
||||
printf ("\toutput_len : %ld\n\n", src_data.output_frames_gen) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
/* De-interleave data so SNR can be calculated for each channel. */
|
||||
deinterleave_data (output_interleaved, output_serial, frames, channel_count) ;
|
||||
|
||||
for (ch = 0 ; ch < channel_count ; ch++)
|
||||
{ snr = calculate_snr (output_serial + ch * frames, frames, 1) ;
|
||||
if (snr < target_snr)
|
||||
{ printf ("\n\nLine %d: channel %d snr %f should be %f\n", __LINE__, ch, snr, target_snr) ;
|
||||
save_oct_float ("output.dat", input_serial, channel_count * frames, output_serial, channel_count * frames) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
} ;
|
||||
|
||||
puts ("ok") ;
|
||||
|
||||
return ;
|
||||
} /* simple_test */
|
||||
|
||||
/*==============================================================================
|
||||
*/
|
||||
|
||||
static void
|
||||
process_test (int converter, int channel_count, double target_snr)
|
||||
{ SRC_STATE *src_state ;
|
||||
SRC_DATA src_data ;
|
||||
|
||||
double freq, snr ;
|
||||
int ch, error, frames, current_in, current_out ;
|
||||
|
||||
printf ("\t%-22s (%2d channel%c) ............ ", "process_test", channel_count, channel_count > 1 ? 's' : ' ') ;
|
||||
fflush (stdout) ;
|
||||
|
||||
assert (channel_count <= MAX_CHANNELS) ;
|
||||
|
||||
memset (input_serial, 0, sizeof (input_serial)) ;
|
||||
memset (input_interleaved, 0, sizeof (input_interleaved)) ;
|
||||
memset (output_interleaved, 0, sizeof (output_interleaved)) ;
|
||||
memset (output_serial, 0, sizeof (output_serial)) ;
|
||||
|
||||
frames = BUFFER_LEN ;
|
||||
|
||||
/* Calculate channel_count separate windowed sine waves. */
|
||||
for (ch = 0 ; ch < channel_count ; ch++)
|
||||
{ freq = (400.0 + 11.333333333 * ch) / 44100.0 ;
|
||||
gen_windowed_sines (1, &freq, 1.0, input_serial + ch * frames, frames) ;
|
||||
} ;
|
||||
|
||||
/* Interleave the data in preparation for SRC. */
|
||||
interleave_data (input_serial, input_interleaved, frames, channel_count) ;
|
||||
|
||||
/* Perform sample rate conversion. */
|
||||
if ((src_state = src_new (converter, channel_count, &error)) == NULL)
|
||||
{ printf ("\n\nLine %d : src_new() failed : %s\n\n", __LINE__, src_strerror (error)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
src_data.end_of_input = 0 ; /* Set this later. */
|
||||
|
||||
/* Choose a converstion ratio < 1.0. */
|
||||
src_data.src_ratio = 0.95 ;
|
||||
|
||||
src_data.data_in = input_interleaved ;
|
||||
src_data.data_out = output_interleaved ;
|
||||
|
||||
current_in = current_out = 0 ;
|
||||
|
||||
while (1)
|
||||
{ src_data.input_frames = MAX (MIN (BLOCK_LEN, frames - current_in), 0) ;
|
||||
src_data.output_frames = MAX (MIN (BLOCK_LEN, frames - current_out), 0) ;
|
||||
|
||||
if ((error = src_process (src_state, &src_data)))
|
||||
{ printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (src_data.end_of_input && src_data.output_frames_gen == 0)
|
||||
break ;
|
||||
|
||||
current_in += src_data.input_frames_used ;
|
||||
current_out += src_data.output_frames_gen ;
|
||||
|
||||
src_data.data_in += src_data.input_frames_used * channel_count ;
|
||||
src_data.data_out += src_data.output_frames_gen * channel_count ;
|
||||
|
||||
src_data.end_of_input = (current_in >= frames) ? 1 : 0 ;
|
||||
} ;
|
||||
|
||||
src_state = src_delete (src_state) ;
|
||||
|
||||
if (fabs (current_out - src_data.src_ratio * current_in) > 2)
|
||||
{ printf ("\n\nLine %d : bad output data length %d should be %d.\n", __LINE__,
|
||||
current_out, (int) floor (src_data.src_ratio * current_in)) ;
|
||||
printf ("\tsrc_ratio : %.4f\n", src_data.src_ratio) ;
|
||||
printf ("\tinput_len : %d\n", frames) ;
|
||||
printf ("\toutput_len : %d\n\n", current_out) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
/* De-interleave data so SNR can be calculated for each channel. */
|
||||
deinterleave_data (output_interleaved, output_serial, frames, channel_count) ;
|
||||
|
||||
for (ch = 0 ; ch < channel_count ; ch++)
|
||||
{ snr = calculate_snr (output_serial + ch * frames, frames, 1) ;
|
||||
if (snr < target_snr)
|
||||
{ printf ("\n\nLine %d: channel %d snr %f should be %f\n", __LINE__, ch, snr, target_snr) ;
|
||||
save_oct_float ("output.dat", input_serial, channel_count * frames, output_serial, channel_count * frames) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
} ;
|
||||
|
||||
puts ("ok") ;
|
||||
|
||||
return ;
|
||||
} /* process_test */
|
||||
|
||||
/*==============================================================================
|
||||
*/
|
||||
|
||||
typedef struct
|
||||
{ int channels ;
|
||||
long total_frames ;
|
||||
long current_frame ;
|
||||
float *data ;
|
||||
} TEST_CB_DATA ;
|
||||
|
||||
static long
|
||||
test_callback_func (void *cb_data, float **data)
|
||||
{ TEST_CB_DATA *pcb_data ;
|
||||
|
||||
long frames ;
|
||||
|
||||
if ((pcb_data = cb_data) == NULL)
|
||||
return 0 ;
|
||||
|
||||
if (data == NULL)
|
||||
return 0 ;
|
||||
|
||||
*data = pcb_data->data + (pcb_data->current_frame * pcb_data->channels) ;
|
||||
|
||||
if (pcb_data->total_frames - pcb_data->current_frame < BLOCK_LEN)
|
||||
frames = pcb_data->total_frames - pcb_data->current_frame ;
|
||||
else
|
||||
frames = BLOCK_LEN ;
|
||||
|
||||
pcb_data->current_frame += frames ;
|
||||
|
||||
return frames ;
|
||||
} /* test_callback_func */
|
||||
|
||||
static void
|
||||
callback_test (int converter, int channel_count, double target_snr)
|
||||
{ TEST_CB_DATA test_callback_data ;
|
||||
SRC_STATE *src_state = NULL ;
|
||||
|
||||
double freq, snr, src_ratio ;
|
||||
int ch, error, frames, read_total, read_count ;
|
||||
|
||||
printf ("\t%-22s (%2d channel%c) ............ ", "callback_test", channel_count, channel_count > 1 ? 's' : ' ') ;
|
||||
fflush (stdout) ;
|
||||
|
||||
assert (channel_count <= MAX_CHANNELS) ;
|
||||
|
||||
memset (input_serial, 0, sizeof (input_serial)) ;
|
||||
memset (input_interleaved, 0, sizeof (input_interleaved)) ;
|
||||
memset (output_interleaved, 0, sizeof (output_interleaved)) ;
|
||||
memset (output_serial, 0, sizeof (output_serial)) ;
|
||||
memset (&test_callback_data, 0, sizeof (test_callback_data)) ;
|
||||
|
||||
frames = BUFFER_LEN ;
|
||||
|
||||
/* Calculate channel_count separate windowed sine waves. */
|
||||
for (ch = 0 ; ch < channel_count ; ch++)
|
||||
{ freq = (200.0 + 33.333333333 * ch) / 44100.0 ;
|
||||
gen_windowed_sines (1, &freq, 1.0, input_serial + ch * frames, frames) ;
|
||||
} ;
|
||||
|
||||
/* Interleave the data in preparation for SRC. */
|
||||
interleave_data (input_serial, input_interleaved, frames, channel_count) ;
|
||||
|
||||
/* Perform sample rate conversion. */
|
||||
src_ratio = 0.95 ;
|
||||
test_callback_data.channels = channel_count ;
|
||||
test_callback_data.total_frames = frames ;
|
||||
test_callback_data.current_frame = 0 ;
|
||||
test_callback_data.data = input_interleaved ;
|
||||
|
||||
if ((src_state = src_callback_new (test_callback_func, converter, channel_count, &error, &test_callback_data)) == NULL)
|
||||
{ printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
read_total = 0 ;
|
||||
while (read_total < frames)
|
||||
{ read_count = src_callback_read (src_state, src_ratio, frames - read_total, output_interleaved + read_total * channel_count) ;
|
||||
|
||||
if (read_count <= 0)
|
||||
break ;
|
||||
|
||||
read_total += read_count ;
|
||||
} ;
|
||||
|
||||
if ((error = src_error (src_state)) != 0)
|
||||
{ printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
src_state = src_delete (src_state) ;
|
||||
|
||||
if (fabs (read_total - src_ratio * frames) > 2)
|
||||
{ printf ("\n\nLine %d : bad output data length %d should be %d.\n", __LINE__,
|
||||
read_total, (int) floor (src_ratio * frames)) ;
|
||||
printf ("\tsrc_ratio : %.4f\n", src_ratio) ;
|
||||
printf ("\tinput_len : %d\n", frames) ;
|
||||
printf ("\toutput_len : %d\n\n", read_total) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
/* De-interleave data so SNR can be calculated for each channel. */
|
||||
deinterleave_data (output_interleaved, output_serial, frames, channel_count) ;
|
||||
|
||||
for (ch = 0 ; ch < channel_count ; ch++)
|
||||
{ snr = calculate_snr (output_serial + ch * frames, frames, 1) ;
|
||||
if (snr < target_snr)
|
||||
{ printf ("\n\nLine %d: channel %d snr %f should be %f\n", __LINE__, ch, snr, target_snr) ;
|
||||
save_oct_float ("output.dat", input_serial, channel_count * frames, output_serial, channel_count * frames) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
} ;
|
||||
|
||||
puts ("ok") ;
|
||||
|
||||
return ;
|
||||
} /* callback_test */
|
||||
|
|
@ -1,216 +0,0 @@
|
|||
/*
|
||||
** Copyright (C) 2008-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
|
||||
**
|
||||
** This program is free software; you can redistribute it and/or modify
|
||||
** it under the terms of the GNU General Public License as published by
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <samplerate.h>
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "util.h"
|
||||
#include "float_cast.h"
|
||||
|
||||
#define BUFFER_LEN (1<<17)
|
||||
|
||||
static float input [BUFFER_LEN] ;
|
||||
static float output [BUFFER_LEN] ;
|
||||
|
||||
static long
|
||||
throughput_test (int converter, int channels, long best_throughput)
|
||||
{ SRC_DATA src_data ;
|
||||
clock_t start_time, clock_time ;
|
||||
double duration ;
|
||||
long total_frames = 0, throughput ;
|
||||
int error ;
|
||||
|
||||
printf (" %-30s %2d ", src_get_name (converter), channels) ;
|
||||
fflush (stdout) ;
|
||||
|
||||
src_data.data_in = input ;
|
||||
src_data.input_frames = ARRAY_LEN (input) / channels ;
|
||||
|
||||
src_data.data_out = output ;
|
||||
src_data.output_frames = ARRAY_LEN (output) / channels ;
|
||||
|
||||
src_data.src_ratio = 0.99 ;
|
||||
|
||||
sleep (2) ;
|
||||
|
||||
start_time = clock () ;
|
||||
|
||||
do
|
||||
{
|
||||
if ((error = src_simple (&src_data, converter, channels)) != 0)
|
||||
{ puts (src_strerror (error)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
total_frames += src_data.output_frames_gen ;
|
||||
|
||||
clock_time = clock () - start_time ;
|
||||
duration = (1.0 * clock_time) / CLOCKS_PER_SEC ;
|
||||
}
|
||||
while (duration < 5.0) ;
|
||||
|
||||
if (src_data.input_frames_used != src_data.input_frames)
|
||||
{ printf ("\n\nLine %d : input frames used %ld should be %ld\n", __LINE__, src_data.input_frames_used, src_data.input_frames) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (fabs (src_data.src_ratio * src_data.input_frames_used - src_data.output_frames_gen) > 2)
|
||||
{ printf ("\n\nLine %d : input / output length mismatch.\n\n", __LINE__) ;
|
||||
printf (" input len : %d\n", ARRAY_LEN (input) / channels) ;
|
||||
printf (" output len : %ld (should be %g +/- 2)\n\n", src_data.output_frames_gen,
|
||||
floor (0.5 + src_data.src_ratio * src_data.input_frames_used)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
throughput = lrint (floor (total_frames / duration)) ;
|
||||
|
||||
if (best_throughput == 0)
|
||||
{ best_throughput = MAX (throughput, best_throughput) ;
|
||||
printf ("%5.2f %10ld\n", duration, throughput) ;
|
||||
}
|
||||
else
|
||||
{ best_throughput = MAX (throughput, best_throughput) ;
|
||||
printf ("%5.2f %10ld %10ld\n", duration, throughput, best_throughput) ;
|
||||
}
|
||||
|
||||
return best_throughput ;
|
||||
} /* throughput_test */
|
||||
|
||||
static void
|
||||
single_run (void)
|
||||
{ const int max_channels = 10 ;
|
||||
int k ;
|
||||
|
||||
printf ("\n CPU name : %s\n", get_cpu_name ()) ;
|
||||
|
||||
puts (
|
||||
"\n"
|
||||
" Converter Channels Duration Throughput\n"
|
||||
" ---------------------------------------------------------------------"
|
||||
) ;
|
||||
|
||||
for (k = 1 ; k <= max_channels / 2 ; k++)
|
||||
throughput_test (SRC_SINC_FASTEST, k, 0) ;
|
||||
|
||||
puts ("") ;
|
||||
for (k = 1 ; k <= max_channels / 2 ; k++)
|
||||
throughput_test (SRC_SINC_MEDIUM_QUALITY, k, 0) ;
|
||||
|
||||
puts ("") ;
|
||||
for (k = 1 ; k <= max_channels ; k++)
|
||||
throughput_test (SRC_SINC_BEST_QUALITY, k, 0) ;
|
||||
|
||||
puts ("") ;
|
||||
return ;
|
||||
} /* single_run */
|
||||
|
||||
static void
|
||||
multi_run (int run_count)
|
||||
{ int k, ch ;
|
||||
|
||||
printf ("\n CPU name : %s\n", get_cpu_name ()) ;
|
||||
|
||||
puts (
|
||||
"\n"
|
||||
" Converter Channels Duration Throughput Best Throughput\n"
|
||||
" ----------------------------------------------------------------------------------------"
|
||||
) ;
|
||||
|
||||
for (ch = 1 ; ch <= 5 ; ch++)
|
||||
{ long sinc_fastest = 0, sinc_medium = 0, sinc_best = 0 ;
|
||||
|
||||
for (k = 0 ; k < run_count ; k++)
|
||||
{ sinc_fastest = throughput_test (SRC_SINC_FASTEST, ch, sinc_fastest) ;
|
||||
sinc_medium = throughput_test (SRC_SINC_MEDIUM_QUALITY, ch, sinc_medium) ;
|
||||
sinc_best = throughput_test (SRC_SINC_BEST_QUALITY, ch, sinc_best) ;
|
||||
|
||||
puts ("") ;
|
||||
|
||||
/* Let the CPU cool down. We might be running on a laptop. */
|
||||
sleep (10) ;
|
||||
} ;
|
||||
|
||||
puts (
|
||||
"\n"
|
||||
" Converter Best Throughput\n"
|
||||
" ------------------------------------------------"
|
||||
) ;
|
||||
|
||||
printf (" %-30s %10ld\n", src_get_name (SRC_SINC_FASTEST), sinc_fastest) ;
|
||||
printf (" %-30s %10ld\n", src_get_name (SRC_SINC_MEDIUM_QUALITY), sinc_medium) ;
|
||||
printf (" %-30s %10ld\n", src_get_name (SRC_SINC_BEST_QUALITY), sinc_best) ;
|
||||
} ;
|
||||
|
||||
puts ("") ;
|
||||
} /* multi_run */
|
||||
|
||||
static void
|
||||
usage_exit (const char * argv0)
|
||||
{ const char * cptr ;
|
||||
|
||||
if ((cptr = strrchr (argv0, '/')) != NULL)
|
||||
argv0 = cptr ;
|
||||
|
||||
printf (
|
||||
"Usage :\n"
|
||||
" %s - Single run of the throughput test.\n"
|
||||
" %s --best-of N - Do N runs of test a print bext result.\n"
|
||||
"\n",
|
||||
argv0, argv0) ;
|
||||
|
||||
exit (0) ;
|
||||
} /* usage_exit */
|
||||
|
||||
int
|
||||
main (int argc, char ** argv)
|
||||
{ double freq ;
|
||||
|
||||
memset (input, 0, sizeof (input)) ;
|
||||
freq = 0.01 ;
|
||||
gen_windowed_sines (1, &freq, 1.0, input, BUFFER_LEN) ;
|
||||
|
||||
if (argc == 1)
|
||||
single_run () ;
|
||||
else if (argc == 3 && strcmp (argv [1], "--best-of") == 0)
|
||||
{ int run_count = atoi (argv [2]) ;
|
||||
|
||||
if (run_count < 1 || run_count > 20)
|
||||
{ printf ("Please be sensible. Run count should be in range (1, 10].\n") ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
multi_run (run_count) ;
|
||||
}
|
||||
else
|
||||
usage_exit (argv [0]) ;
|
||||
|
||||
puts (
|
||||
" Duration is in seconds.\n"
|
||||
" Throughput is in frames/sec (more is better).\n"
|
||||
) ;
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
|
@ -1,238 +0,0 @@
|
|||
/*
|
||||
** Copyright (C) 2002-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
|
||||
**
|
||||
** This program is free software; you can redistribute it and/or modify
|
||||
** it under the terms of the GNU General Public License as published by
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <samplerate.h>
|
||||
|
||||
#include "util.h"
|
||||
|
||||
#define BUFFER_LEN 2048
|
||||
#define CB_READ_LEN 256
|
||||
|
||||
static void process_reset_test (int converter) ;
|
||||
static void callback_reset_test (int converter) ;
|
||||
|
||||
static float data_one [BUFFER_LEN] ;
|
||||
static float data_zero [BUFFER_LEN] ;
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
puts ("") ;
|
||||
|
||||
process_reset_test (SRC_ZERO_ORDER_HOLD) ;
|
||||
process_reset_test (SRC_LINEAR) ;
|
||||
process_reset_test (SRC_SINC_FASTEST) ;
|
||||
|
||||
callback_reset_test (SRC_ZERO_ORDER_HOLD) ;
|
||||
callback_reset_test (SRC_LINEAR) ;
|
||||
callback_reset_test (SRC_SINC_FASTEST) ;
|
||||
|
||||
puts ("") ;
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
static void
|
||||
process_reset_test (int converter)
|
||||
{ static float output [BUFFER_LEN] ;
|
||||
|
||||
SRC_STATE *src_state ;
|
||||
SRC_DATA src_data ;
|
||||
int k, error ;
|
||||
|
||||
printf ("\tprocess_reset_test (%-28s) ....... ", src_get_name (converter)) ;
|
||||
fflush (stdout) ;
|
||||
|
||||
for (k = 0 ; k < BUFFER_LEN ; k++)
|
||||
{ data_one [k] = 1.0 ;
|
||||
data_zero [k] = 0.0 ;
|
||||
} ;
|
||||
|
||||
/* Get a converter. */
|
||||
if ((src_state = src_new (converter, 1, &error)) == NULL)
|
||||
{ printf ("\n\nLine %d : src_new() failed : %s.\n\n", __LINE__, src_strerror (error)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
/* Process a bunch of 1.0 valued samples. */
|
||||
src_data.data_in = data_one ;
|
||||
src_data.data_out = output ;
|
||||
src_data.input_frames = BUFFER_LEN ;
|
||||
src_data.output_frames = BUFFER_LEN ;
|
||||
src_data.src_ratio = 0.9 ;
|
||||
src_data.end_of_input = 1 ;
|
||||
|
||||
if ((error = src_process (src_state, &src_data)) != 0)
|
||||
{ printf ("\n\nLine %d : src_simple () returned error : %s\n\n", __LINE__, src_strerror (error)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
/* Reset the state of the converter.*/
|
||||
src_reset (src_state) ;
|
||||
|
||||
/* Now process some zero data. */
|
||||
src_data.data_in = data_zero ;
|
||||
src_data.data_out = output ;
|
||||
src_data.input_frames = BUFFER_LEN ;
|
||||
src_data.output_frames = BUFFER_LEN ;
|
||||
src_data.src_ratio = 0.9 ;
|
||||
src_data.end_of_input = 1 ;
|
||||
|
||||
if ((error = src_process (src_state, &src_data)) != 0)
|
||||
{ printf ("\n\nLine %d : src_simple () returned error : %s\n\n", __LINE__, src_strerror (error)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
/* Finally make sure that the output data is zero ie reset was sucessful. */
|
||||
for (k = 0 ; k < BUFFER_LEN / 2 ; k++)
|
||||
if (output [k] != 0.0)
|
||||
{ printf ("\n\nLine %d : output [%d] should be 0.0, is %f.\n", __LINE__, k, output [k]) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
/* Make sure that this function has been exported. */
|
||||
src_set_ratio (src_state, 1.0) ;
|
||||
|
||||
/* Delete converter. */
|
||||
src_state = src_delete (src_state) ;
|
||||
|
||||
puts ("ok") ;
|
||||
} /* process_reset_test */
|
||||
|
||||
/*==============================================================================
|
||||
*/
|
||||
|
||||
typedef struct
|
||||
{ int channels ;
|
||||
long count, total ;
|
||||
float *data ;
|
||||
} TEST_CB_DATA ;
|
||||
|
||||
static long
|
||||
test_callback_func (void *cb_data, float **data)
|
||||
{ TEST_CB_DATA *pcb_data ;
|
||||
|
||||
long frames ;
|
||||
|
||||
if ((pcb_data = cb_data) == NULL)
|
||||
return 0 ;
|
||||
|
||||
if (data == NULL)
|
||||
return 0 ;
|
||||
|
||||
if (pcb_data->total - pcb_data->count > 0)
|
||||
frames = pcb_data->total - pcb_data->count ;
|
||||
else
|
||||
frames = 0 ;
|
||||
|
||||
*data = pcb_data->data + pcb_data->count ;
|
||||
pcb_data->count += frames ;
|
||||
|
||||
return frames ;
|
||||
} /* test_callback_func */
|
||||
|
||||
static void
|
||||
callback_reset_test (int converter)
|
||||
{ static TEST_CB_DATA test_callback_data ;
|
||||
|
||||
static float output [BUFFER_LEN] ;
|
||||
|
||||
SRC_STATE *src_state ;
|
||||
|
||||
double src_ratio = 1.1 ;
|
||||
long read_count, read_total ;
|
||||
int k, error ;
|
||||
|
||||
printf ("\tcallback_reset_test (%-28s) ....... ", src_get_name (converter)) ;
|
||||
fflush (stdout) ;
|
||||
|
||||
for (k = 0 ; k < ARRAY_LEN (data_one) ; k++)
|
||||
{ data_one [k] = 1.0 ;
|
||||
data_zero [k] = 0.0 ;
|
||||
} ;
|
||||
|
||||
if ((src_state = src_callback_new (test_callback_func, converter, 1, &error, &test_callback_data)) == NULL)
|
||||
{ printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
/* Process a bunch of 1.0 valued samples. */
|
||||
test_callback_data.channels = 1 ;
|
||||
test_callback_data.count = 0 ;
|
||||
test_callback_data.total = ARRAY_LEN (data_one) ;
|
||||
test_callback_data.data = data_one ;
|
||||
|
||||
read_total = 0 ;
|
||||
do
|
||||
{ read_count = (ARRAY_LEN (output) - read_total > CB_READ_LEN) ? CB_READ_LEN : ARRAY_LEN (output) - read_total ;
|
||||
read_count = src_callback_read (src_state, src_ratio, read_count, output + read_total) ;
|
||||
read_total += read_count ;
|
||||
}
|
||||
while (read_count > 0) ;
|
||||
|
||||
/* Check for errors. */
|
||||
if ((error = src_error (src_state)) != 0)
|
||||
{ printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
/* Reset the state of the converter.*/
|
||||
src_reset (src_state) ;
|
||||
|
||||
/* Process a bunch of 0.0 valued samples. */
|
||||
test_callback_data.channels = 1 ;
|
||||
test_callback_data.count = 0 ;
|
||||
test_callback_data.total = ARRAY_LEN (data_zero) ;
|
||||
test_callback_data.data = data_zero ;
|
||||
|
||||
/* Now process some zero data. */
|
||||
read_total = 0 ;
|
||||
do
|
||||
{ read_count = (ARRAY_LEN (output) - read_total > CB_READ_LEN) ? CB_READ_LEN : ARRAY_LEN (output) - read_total ;
|
||||
read_count = src_callback_read (src_state, src_ratio, read_count, output + read_total) ;
|
||||
read_total += read_count ;
|
||||
}
|
||||
while (read_count > 0) ;
|
||||
|
||||
/* Check for errors. */
|
||||
if ((error = src_error (src_state)) != 0)
|
||||
{ printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
/* Finally make sure that the output data is zero ie reset was sucessful. */
|
||||
for (k = 0 ; k < BUFFER_LEN / 2 ; k++)
|
||||
if (output [k] != 0.0)
|
||||
{ printf ("\n\nLine %d : output [%d] should be 0.0, is %f.\n\n", __LINE__, k, output [k]) ;
|
||||
save_oct_float ("output.dat", data_one, ARRAY_LEN (data_one), output, ARRAY_LEN (output)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
/* Make sure that this function has been exported. */
|
||||
src_set_ratio (src_state, 1.0) ;
|
||||
|
||||
/* Delete converter. */
|
||||
src_state = src_delete (src_state) ;
|
||||
|
||||
puts ("ok") ;
|
||||
} /* callback_reset_test */
|
||||
|
||||
|
|
@ -1,117 +0,0 @@
|
|||
/*
|
||||
** Copyright (C) 2002-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
|
||||
**
|
||||
** This program is free software; you can redistribute it and/or modify
|
||||
** it under the terms of the GNU General Public License as published by
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <samplerate.h>
|
||||
|
||||
#include "util.h"
|
||||
|
||||
#define BUFFER_LEN 2048
|
||||
|
||||
static void simple_test (int converter, double ratio) ;
|
||||
|
||||
int
|
||||
main (void)
|
||||
{ static double src_ratios [] =
|
||||
{ 1.0001, 0.099, 0.1, 0.33333333, 0.789, 1.9, 3.1, 9.9
|
||||
} ;
|
||||
|
||||
int k ;
|
||||
|
||||
puts ("") ;
|
||||
|
||||
puts (" Zero Order Hold interpolator :") ;
|
||||
for (k = 0 ; k < ARRAY_LEN (src_ratios) ; k++)
|
||||
simple_test (SRC_ZERO_ORDER_HOLD, src_ratios [k]) ;
|
||||
|
||||
puts (" Linear interpolator :") ;
|
||||
for (k = 0 ; k < ARRAY_LEN (src_ratios) ; k++)
|
||||
simple_test (SRC_LINEAR, src_ratios [k]) ;
|
||||
|
||||
puts (" Sinc interpolator :") ;
|
||||
for (k = 0 ; k < ARRAY_LEN (src_ratios) ; k++)
|
||||
simple_test (SRC_SINC_FASTEST, src_ratios [k]) ;
|
||||
|
||||
puts ("") ;
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
static void
|
||||
simple_test (int converter, double src_ratio)
|
||||
{ static float input [BUFFER_LEN], output [BUFFER_LEN] ;
|
||||
|
||||
SRC_DATA src_data ;
|
||||
|
||||
int input_len, output_len, error, terminate ;
|
||||
|
||||
printf ("\tsimple_test (SRC ratio = %6.4f) ........... ", src_ratio) ;
|
||||
fflush (stdout) ;
|
||||
|
||||
/* Calculate maximun input and output lengths. */
|
||||
if (src_ratio >= 1.0)
|
||||
{ output_len = BUFFER_LEN ;
|
||||
input_len = (int) floor (BUFFER_LEN / src_ratio) ;
|
||||
}
|
||||
else
|
||||
{ input_len = BUFFER_LEN ;
|
||||
output_len = (int) floor (BUFFER_LEN * src_ratio) ;
|
||||
} ;
|
||||
|
||||
/* Reduce input_len by 10 so output is longer than necessary. */
|
||||
input_len -= 10 ;
|
||||
|
||||
if (output_len > BUFFER_LEN)
|
||||
{ printf ("\n\nLine %d : output_len > BUFFER_LEN\n\n", __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
memset (&src_data, 0, sizeof (src_data)) ;
|
||||
|
||||
src_data.data_in = input ;
|
||||
src_data.input_frames = input_len ;
|
||||
|
||||
src_data.src_ratio = src_ratio ;
|
||||
|
||||
src_data.data_out = output ;
|
||||
src_data.output_frames = BUFFER_LEN ;
|
||||
|
||||
if ((error = src_simple (&src_data, converter, 1)))
|
||||
{ printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
terminate = (int) ceil ((src_ratio >= 1.0) ? src_ratio : 1.0 / src_ratio) ;
|
||||
|
||||
if (fabs (src_data.output_frames_gen - src_ratio * input_len) > 2 * terminate)
|
||||
{ printf ("\n\nLine %d : bad output data length %ld should be %d.\n", __LINE__,
|
||||
src_data.output_frames_gen, (int) floor (src_ratio * input_len)) ;
|
||||
printf ("\tsrc_ratio : %.4f\n", src_ratio) ;
|
||||
printf ("\tinput_len : %d\n\toutput_len : %d\n\n", input_len, output_len) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
puts ("ok") ;
|
||||
|
||||
return ;
|
||||
} /* simple_test */
|
||||
|
|
@ -1,332 +0,0 @@
|
|||
/*
|
||||
** Copyright (C) 2002-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
|
||||
**
|
||||
** This program is free software; you can redistribute it and/or modify
|
||||
** it under the terms of the GNU General Public License as published by
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#if (HAVE_SNDFILE)
|
||||
|
||||
#include <samplerate.h>
|
||||
#include <sndfile.h>
|
||||
|
||||
#define DEFAULT_CONVERTER SRC_SINC_MEDIUM_QUALITY
|
||||
|
||||
#define BUFFER_LEN 4096 /*-(1<<16)-*/
|
||||
|
||||
static void usage_exit (const char *progname) ;
|
||||
static sf_count_t sample_rate_convert (SNDFILE *infile, SNDFILE *outfile, int converter, double src_ratio, int channels, double * gain) ;
|
||||
static double apply_gain (float * data, long frames, int channels, double max, double gain) ;
|
||||
|
||||
int
|
||||
main (int argc, char *argv [])
|
||||
{ SNDFILE *infile, *outfile = NULL ;
|
||||
SF_INFO sfinfo ;
|
||||
|
||||
sf_count_t count ;
|
||||
double src_ratio = -1.0, gain = 1.0 ;
|
||||
int new_sample_rate = -1, k, converter, max_speed = SF_FALSE ;
|
||||
|
||||
if (argc == 2 && strcmp (argv [1], "--version") == 0)
|
||||
{ char buffer [64], *cptr ;
|
||||
|
||||
if ((cptr = strrchr (argv [0], '/')) != NULL)
|
||||
argv [0] = cptr + 1 ;
|
||||
if ((cptr = strrchr (argv [0], '\\')) != NULL)
|
||||
argv [0] = cptr + 1 ;
|
||||
|
||||
sf_command (NULL, SFC_GET_LIB_VERSION, buffer, sizeof (buffer)) ;
|
||||
|
||||
printf ("%s (%s,%s)\n", argv [0], src_get_version (), buffer) ;
|
||||
exit (0) ;
|
||||
} ;
|
||||
|
||||
if (argc != 5 && argc != 7 && argc != 8)
|
||||
usage_exit (argv [0]) ;
|
||||
|
||||
/* Set default converter. */
|
||||
converter = DEFAULT_CONVERTER ;
|
||||
|
||||
for (k = 1 ; k < argc - 2 ; k++)
|
||||
{ if (strcmp (argv [k], "--max-speed") == 0)
|
||||
max_speed = SF_TRUE ;
|
||||
else if (strcmp (argv [k], "-to") == 0)
|
||||
{ k ++ ;
|
||||
new_sample_rate = atoi (argv [k]) ;
|
||||
}
|
||||
else if (strcmp (argv [k], "-by") == 0)
|
||||
{ k ++ ;
|
||||
src_ratio = atof (argv [k]) ;
|
||||
}
|
||||
else if (strcmp (argv [k], "-c") == 0)
|
||||
{ k ++ ;
|
||||
converter = atoi (argv [k]) ;
|
||||
}
|
||||
else
|
||||
usage_exit (argv [0]) ;
|
||||
} ;
|
||||
|
||||
if (new_sample_rate <= 0 && src_ratio <= 0.0)
|
||||
usage_exit (argv [0]) ;
|
||||
|
||||
if (src_get_name (converter) == NULL)
|
||||
{ printf ("Error : bad converter number.\n") ;
|
||||
usage_exit (argv [0]) ;
|
||||
} ;
|
||||
|
||||
if (strcmp (argv [argc - 2], argv [argc - 1]) == 0)
|
||||
{ printf ("Error : input and output file names are the same.\n") ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if ((infile = sf_open (argv [argc - 2], SFM_READ, &sfinfo)) == NULL)
|
||||
{ printf ("Error : Not able to open input file '%s'\n", argv [argc - 2]) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
printf ("Input File : %s\n", argv [argc - 2]) ;
|
||||
printf ("Sample Rate : %d\n", sfinfo.samplerate) ;
|
||||
printf ("Input Frames : %ld\n\n", (long) sfinfo.frames) ;
|
||||
|
||||
if (new_sample_rate > 0)
|
||||
{ src_ratio = (1.0 * new_sample_rate) / sfinfo.samplerate ;
|
||||
sfinfo.samplerate = new_sample_rate ;
|
||||
}
|
||||
else if (src_is_valid_ratio (src_ratio))
|
||||
sfinfo.samplerate = (int) floor (sfinfo.samplerate * src_ratio) ;
|
||||
else
|
||||
{ printf ("Not able to determine new sample rate. Exiting.\n") ;
|
||||
sf_close (infile) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (fabs (src_ratio - 1.0) < 1e-20)
|
||||
{ printf ("Target samplerate and input samplerate are the same. Exiting.\n") ;
|
||||
sf_close (infile) ;
|
||||
exit (0) ;
|
||||
} ;
|
||||
|
||||
printf ("SRC Ratio : %f\n", src_ratio) ;
|
||||
printf ("Converter : %s\n\n", src_get_name (converter)) ;
|
||||
|
||||
if (src_is_valid_ratio (src_ratio) == 0)
|
||||
{ printf ("Error : Sample rate change out of valid range.\n") ;
|
||||
sf_close (infile) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
/* Delete the output file length to zero if already exists. */
|
||||
remove (argv [argc - 1]) ;
|
||||
|
||||
printf ("Output file : %s\n", argv [argc - 1]) ;
|
||||
printf ("Sample Rate : %d\n", sfinfo.samplerate) ;
|
||||
|
||||
do
|
||||
{ sf_close (outfile) ;
|
||||
|
||||
if ((outfile = sf_open (argv [argc - 1], SFM_WRITE, &sfinfo)) == NULL)
|
||||
{ printf ("Error : Not able to open output file '%s'\n", argv [argc - 1]) ;
|
||||
sf_close (infile) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (max_speed)
|
||||
{ /* This is mainly for the comparison program tests/src-evaluate.c */
|
||||
sf_command (outfile, SFC_SET_ADD_PEAK_CHUNK, NULL, SF_FALSE) ;
|
||||
}
|
||||
else
|
||||
{ /* Update the file header after every write. */
|
||||
sf_command (outfile, SFC_SET_UPDATE_HEADER_AUTO, NULL, SF_TRUE) ;
|
||||
} ;
|
||||
|
||||
sf_command (outfile, SFC_SET_CLIPPING, NULL, SF_TRUE) ;
|
||||
|
||||
count = sample_rate_convert (infile, outfile, converter, src_ratio, sfinfo.channels, &gain) ;
|
||||
}
|
||||
while (count < 0) ;
|
||||
|
||||
printf ("Output Frames : %ld\n\n", (long) count) ;
|
||||
|
||||
sf_close (infile) ;
|
||||
sf_close (outfile) ;
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
/*==============================================================================
|
||||
*/
|
||||
|
||||
static sf_count_t
|
||||
sample_rate_convert (SNDFILE *infile, SNDFILE *outfile, int converter, double src_ratio, int channels, double * gain)
|
||||
{ static float input [BUFFER_LEN] ;
|
||||
static float output [BUFFER_LEN] ;
|
||||
|
||||
SRC_STATE *src_state ;
|
||||
SRC_DATA src_data ;
|
||||
int error ;
|
||||
double max = 0.0 ;
|
||||
sf_count_t output_count = 0 ;
|
||||
|
||||
sf_seek (infile, 0, SEEK_SET) ;
|
||||
sf_seek (outfile, 0, SEEK_SET) ;
|
||||
|
||||
/* Initialize the sample rate converter. */
|
||||
if ((src_state = src_new (converter, channels, &error)) == NULL)
|
||||
{ printf ("\n\nError : src_new() failed : %s.\n\n", src_strerror (error)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
src_data.end_of_input = 0 ; /* Set this later. */
|
||||
|
||||
/* Start with zero to force load in while loop. */
|
||||
src_data.input_frames = 0 ;
|
||||
src_data.data_in = input ;
|
||||
|
||||
src_data.src_ratio = src_ratio ;
|
||||
|
||||
src_data.data_out = output ;
|
||||
src_data.output_frames = BUFFER_LEN /channels ;
|
||||
|
||||
while (1)
|
||||
{
|
||||
/* If the input buffer is empty, refill it. */
|
||||
if (src_data.input_frames == 0)
|
||||
{ src_data.input_frames = sf_readf_float (infile, input, BUFFER_LEN / channels) ;
|
||||
src_data.data_in = input ;
|
||||
|
||||
/* The last read will not be a full buffer, so snd_of_input. */
|
||||
if (src_data.input_frames < BUFFER_LEN / channels)
|
||||
src_data.end_of_input = SF_TRUE ;
|
||||
} ;
|
||||
|
||||
if ((error = src_process (src_state, &src_data)))
|
||||
{ printf ("\nError : %s\n", src_strerror (error)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
/* Terminate if done. */
|
||||
if (src_data.end_of_input && src_data.output_frames_gen == 0)
|
||||
break ;
|
||||
|
||||
max = apply_gain (src_data.data_out, src_data.output_frames_gen, channels, max, *gain) ;
|
||||
|
||||
/* Write output. */
|
||||
sf_writef_float (outfile, output, src_data.output_frames_gen) ;
|
||||
output_count += src_data.output_frames_gen ;
|
||||
|
||||
src_data.data_in += src_data.input_frames_used * channels ;
|
||||
src_data.input_frames -= src_data.input_frames_used ;
|
||||
} ;
|
||||
|
||||
src_state = src_delete (src_state) ;
|
||||
|
||||
if (max > 1.0)
|
||||
{ *gain = 1.0 / max ;
|
||||
printf ("\nOutput has clipped. Restarting conversion to prevent clipping.\n\n") ;
|
||||
return -1 ;
|
||||
} ;
|
||||
|
||||
return output_count ;
|
||||
} /* sample_rate_convert */
|
||||
|
||||
static double
|
||||
apply_gain (float * data, long frames, int channels, double max, double gain)
|
||||
{
|
||||
long k ;
|
||||
|
||||
for (k = 0 ; k < frames * channels ; k++)
|
||||
{ data [k] *= gain ;
|
||||
|
||||
if (fabs (data [k]) > max)
|
||||
max = fabs (data [k]) ;
|
||||
} ;
|
||||
|
||||
return max ;
|
||||
} /* apply_gain */
|
||||
|
||||
static void
|
||||
usage_exit (const char *progname)
|
||||
{ char lsf_ver [128] ;
|
||||
const char *cptr ;
|
||||
int k ;
|
||||
|
||||
if ((cptr = strrchr (progname, '/')) != NULL)
|
||||
progname = cptr + 1 ;
|
||||
|
||||
if ((cptr = strrchr (progname, '\\')) != NULL)
|
||||
progname = cptr + 1 ;
|
||||
|
||||
|
||||
sf_command (NULL, SFC_GET_LIB_VERSION, lsf_ver, sizeof (lsf_ver)) ;
|
||||
|
||||
printf ("\n"
|
||||
" A Sample Rate Converter using libsndfile for file I/O and Secret \n"
|
||||
" Rabbit Code (aka libsamplerate) for performing the conversion.\n"
|
||||
" It works on any file format supported by libsndfile with any \n"
|
||||
" number of channels (limited only by host memory).\n"
|
||||
"\n"
|
||||
" %s\n"
|
||||
" %s\n"
|
||||
"\n"
|
||||
" Usage : \n"
|
||||
" %s -to <new sample rate> [-c <number>] <input file> <output file>\n"
|
||||
" %s -by <amount> [-c <number>] <input file> <output file>\n"
|
||||
"\n", src_get_version (), lsf_ver, progname, progname) ;
|
||||
|
||||
puts (
|
||||
" The optional -c argument allows the converter type to be chosen from\n"
|
||||
" the following list :"
|
||||
"\n"
|
||||
) ;
|
||||
|
||||
for (k = 0 ; (cptr = src_get_name (k)) != NULL ; k++)
|
||||
printf (" %d : %s%s\n", k, cptr, k == DEFAULT_CONVERTER ? " (default)" : "") ;
|
||||
|
||||
puts ("") ;
|
||||
|
||||
exit (1) ;
|
||||
} /* usage_exit */
|
||||
|
||||
/*==============================================================================
|
||||
*/
|
||||
|
||||
#else /* (HAVE_SNFILE == 0) */
|
||||
|
||||
/* Alternative main function when libsndfile is not available. */
|
||||
|
||||
int
|
||||
main (void)
|
||||
{ puts (
|
||||
"\n"
|
||||
"****************************************************************\n"
|
||||
" This example program was compiled without libsndfile \n"
|
||||
" (http://www.mega-nerd.com/libsndfile/).\n"
|
||||
" It is therefore completely broken and non-functional.\n"
|
||||
"****************************************************************\n"
|
||||
"\n"
|
||||
) ;
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
#endif
|
||||
|
|
@ -1,401 +0,0 @@
|
|||
/*
|
||||
** Copyright (C) 2002-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
|
||||
**
|
||||
** This program is free software; you can redistribute it and/or modify
|
||||
** it under the terms of the GNU General Public License as published by
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <time.h>
|
||||
|
||||
#if (HAVE_FFTW3)
|
||||
|
||||
#include <samplerate.h>
|
||||
|
||||
#include "util.h"
|
||||
|
||||
#define BUFFER_LEN 50000
|
||||
#define MAX_FREQS 4
|
||||
#define MAX_RATIOS 6
|
||||
#define MAX_SPEC_LEN (1<<15)
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846264338
|
||||
#endif
|
||||
|
||||
enum
|
||||
{ BOOLEAN_FALSE = 0,
|
||||
BOOLEAN_TRUE = 1
|
||||
} ;
|
||||
|
||||
typedef struct
|
||||
{ int freq_count ;
|
||||
double freqs [MAX_FREQS] ;
|
||||
|
||||
double src_ratio ;
|
||||
int pass_band_peaks ;
|
||||
|
||||
double snr ;
|
||||
double peak_value ;
|
||||
} SINGLE_TEST ;
|
||||
|
||||
typedef struct
|
||||
{ int converter ;
|
||||
int tests ;
|
||||
int do_bandwidth_test ;
|
||||
SINGLE_TEST test_data [10] ;
|
||||
} CONVERTER_TEST ;
|
||||
|
||||
static double snr_test (SINGLE_TEST *snr_test_data, int number, int converter, int verbose) ;
|
||||
static double find_peak (float *output, int output_len) ;
|
||||
static double bandwidth_test (int converter, int verbose) ;
|
||||
|
||||
int
|
||||
main (int argc, char *argv [])
|
||||
{ CONVERTER_TEST snr_test_data [] =
|
||||
{
|
||||
{ SRC_ZERO_ORDER_HOLD,
|
||||
8,
|
||||
BOOLEAN_FALSE,
|
||||
{ { 1, { 0.01111111111 }, 3.0, 1, 28.0, 1.0 },
|
||||
{ 1, { 0.01111111111 }, 0.6, 1, 36.0, 1.0 },
|
||||
{ 1, { 0.01111111111 }, 0.3, 1, 36.0, 1.0 },
|
||||
{ 1, { 0.01111111111 }, 1.0, 1, 150.0, 1.0 },
|
||||
{ 1, { 0.01111111111 }, 1.001, 1, 38.0, 1.0 },
|
||||
{ 2, { 0.011111, 0.324 }, 1.9999, 2, 14.0, .96 },
|
||||
{ 2, { 0.012345, 0.457 }, 0.456789, 1, 12.0, .96 },
|
||||
{ 1, { 0.3511111111 }, 1.33, 1, 10.0, 1.0 }
|
||||
}
|
||||
},
|
||||
|
||||
{ SRC_LINEAR,
|
||||
8,
|
||||
BOOLEAN_FALSE,
|
||||
{ { 1, { 0.01111111111 }, 3.0, 1, 73.0, 1.0 },
|
||||
{ 1, { 0.01111111111 }, 0.6, 1, 73.0, 1.0 },
|
||||
{ 1, { 0.01111111111 }, 0.3, 1, 73.0, 1.0 },
|
||||
{ 1, { 0.01111111111 }, 1.0, 1, 150.0, 1.0 },
|
||||
{ 1, { 0.01111111111 }, 1.001, 1, 77.0, 1.0 },
|
||||
{ 2, { 0.011111, 0.324 }, 1.9999, 2, 16.0, 0.96 },
|
||||
{ 2, { 0.012345, 0.457 }, 0.456789, 1, 26.0, 0.96 },
|
||||
{ 1, { 0.3511111111 }, 1.33, 1, 14.4, 0.99 }
|
||||
}
|
||||
},
|
||||
|
||||
{ SRC_SINC_FASTEST,
|
||||
9,
|
||||
BOOLEAN_TRUE,
|
||||
{ { 1, { 0.01111111111 }, 3.0, 1, 100.0, 1.0 },
|
||||
{ 1, { 0.01111111111 }, 0.6, 1, 99.0, 1.0 },
|
||||
{ 1, { 0.01111111111 }, 0.3, 1, 100.0, 1.0 },
|
||||
{ 1, { 0.01111111111 }, 1.0, 1, 150.0, 1.0 },
|
||||
{ 1, { 0.01111111111 }, 1.001, 1, 100.0, 1.0 },
|
||||
{ 2, { 0.011111, 0.324 }, 1.9999, 2, 97.0, 1.0 },
|
||||
{ 2, { 0.012345, 0.457 }, 0.456789, 1, 100.0, 0.5 },
|
||||
{ 2, { 0.011111, 0.45 }, 0.6, 1, 97.0, 0.5 },
|
||||
{ 1, { 0.3511111111 }, 1.33, 1, 97.0, 1.0 }
|
||||
}
|
||||
},
|
||||
|
||||
{ SRC_SINC_MEDIUM_QUALITY,
|
||||
9,
|
||||
BOOLEAN_TRUE,
|
||||
{ { 1, { 0.01111111111 }, 3.0, 1, 130.0, 1.0 },
|
||||
{ 1, { 0.01111111111 }, 0.6, 1, 132.0, 1.0 },
|
||||
{ 1, { 0.01111111111 }, 0.3, 1, 138.0, 1.0 },
|
||||
{ 1, { 0.01111111111 }, 1.0, 1, 155.0, 1.0 },
|
||||
{ 1, { 0.01111111111 }, 1.001, 1, 134.0, 1.0 },
|
||||
{ 2, { 0.011111, 0.324 }, 1.9999, 2, 127.0, 1.0 },
|
||||
{ 2, { 0.012345, 0.457 }, 0.456789, 1, 124.0, 0.5 },
|
||||
{ 2, { 0.011111, 0.45 }, 0.6, 1, 126.0, 0.5 },
|
||||
{ 1, { 0.43111111111 }, 1.33, 1, 121.0, 1.0 }
|
||||
}
|
||||
},
|
||||
|
||||
{ SRC_SINC_BEST_QUALITY,
|
||||
9,
|
||||
BOOLEAN_TRUE,
|
||||
{ { 1, { 0.01111111111 }, 3.0, 1, 147.0, 1.0 },
|
||||
{ 1, { 0.01111111111 }, 0.6, 1, 147.0, 1.0 },
|
||||
{ 1, { 0.01111111111 }, 0.3, 1, 147.0, 1.0 },
|
||||
{ 1, { 0.01111111111 }, 1.0, 1, 155.0, 1.0 },
|
||||
{ 1, { 0.01111111111 }, 1.001, 1, 147.0, 1.0 },
|
||||
{ 2, { 0.011111, 0.324 }, 1.9999, 2, 147.0, 1.0 },
|
||||
{ 2, { 0.012345, 0.457 }, 0.456789, 1, 148.0, 0.5 },
|
||||
{ 2, { 0.011111, 0.45 }, 0.6, 1, 149.0, 0.5 },
|
||||
{ 1, { 0.43111111111 }, 1.33, 1, 145.0, 1.0 }
|
||||
}
|
||||
},
|
||||
} ; /* snr_test_data */
|
||||
|
||||
double best_snr, snr, freq3dB ;
|
||||
int j, k, converter, verbose = 0 ;
|
||||
|
||||
if (argc == 2 && strcmp (argv [1], "--verbose") == 0)
|
||||
verbose = 1 ;
|
||||
|
||||
puts ("") ;
|
||||
|
||||
for (j = 0 ; j < ARRAY_LEN (snr_test_data) ; j++)
|
||||
{ best_snr = 5000.0 ;
|
||||
|
||||
converter = snr_test_data [j].converter ;
|
||||
|
||||
printf (" Converter %d : %s\n", converter, src_get_name (converter)) ;
|
||||
printf (" %s\n", src_get_description (converter)) ;
|
||||
|
||||
for (k = 0 ; k < snr_test_data [j].tests ; k++)
|
||||
{ snr = snr_test (&(snr_test_data [j].test_data [k]), k, converter, verbose) ;
|
||||
if (best_snr > snr)
|
||||
best_snr = snr ;
|
||||
} ;
|
||||
|
||||
printf (" Worst case Signal-to-Noise Ratio : %.2f dB.\n", best_snr) ;
|
||||
|
||||
if (snr_test_data [j].do_bandwidth_test == BOOLEAN_FALSE)
|
||||
{ puts (" Bandwith test not performed on this converter.\n") ;
|
||||
continue ;
|
||||
}
|
||||
|
||||
freq3dB = bandwidth_test (converter, verbose) ;
|
||||
|
||||
printf (" Measured -3dB rolloff point : %5.2f %%.\n\n", freq3dB) ;
|
||||
} ;
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
/*==============================================================================
|
||||
*/
|
||||
|
||||
static double
|
||||
snr_test (SINGLE_TEST *test_data, int number, int converter, int verbose)
|
||||
{ static float data [BUFFER_LEN + 1] ;
|
||||
static float output [MAX_SPEC_LEN] ;
|
||||
|
||||
SRC_STATE *src_state ;
|
||||
SRC_DATA src_data ;
|
||||
|
||||
double output_peak, snr ;
|
||||
int k, output_len, input_len, error ;
|
||||
|
||||
if (verbose != 0)
|
||||
{ printf ("\tSignal-to-Noise Ratio Test %d.\n"
|
||||
"\t=====================================\n", number) ;
|
||||
printf ("\tFrequencies : [ ") ;
|
||||
for (k = 0 ; k < test_data->freq_count ; k++)
|
||||
printf ("%6.4f ", test_data->freqs [k]) ;
|
||||
|
||||
printf ("]\n\tSRC Ratio : %8.4f\n", test_data->src_ratio) ;
|
||||
}
|
||||
else
|
||||
{ printf ("\tSignal-to-Noise Ratio Test %d : ", number) ;
|
||||
fflush (stdout) ;
|
||||
} ;
|
||||
|
||||
/* Set up the output array. */
|
||||
if (test_data->src_ratio >= 1.0)
|
||||
{ output_len = MAX_SPEC_LEN ;
|
||||
input_len = (int) ceil (MAX_SPEC_LEN / test_data->src_ratio) ;
|
||||
if (input_len > BUFFER_LEN)
|
||||
input_len = BUFFER_LEN ;
|
||||
}
|
||||
else
|
||||
{ input_len = BUFFER_LEN ;
|
||||
output_len = (int) ceil (BUFFER_LEN * test_data->src_ratio) ;
|
||||
output_len &= ((-1) << 4) ;
|
||||
if (output_len > MAX_SPEC_LEN)
|
||||
output_len = MAX_SPEC_LEN ;
|
||||
input_len = (int) ceil (output_len / test_data->src_ratio) ;
|
||||
} ;
|
||||
|
||||
memset (output, 0, sizeof (output)) ;
|
||||
|
||||
/* Generate input data array. */
|
||||
gen_windowed_sines (test_data->freq_count, test_data->freqs, 1.0, data, input_len) ;
|
||||
|
||||
/* Perform sample rate conversion. */
|
||||
if ((src_state = src_new (converter, 1, &error)) == NULL)
|
||||
{ printf ("\n\nLine %d : src_new() failed : %s.\n\n", __LINE__, src_strerror (error)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
src_data.end_of_input = 1 ; /* Only one buffer worth of input. */
|
||||
|
||||
src_data.data_in = data ;
|
||||
src_data.input_frames = input_len ;
|
||||
|
||||
src_data.src_ratio = test_data->src_ratio ;
|
||||
|
||||
src_data.data_out = output ;
|
||||
src_data.output_frames = output_len ;
|
||||
|
||||
if ((error = src_process (src_state, &src_data)))
|
||||
{ printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
src_state = src_delete (src_state) ;
|
||||
|
||||
if (verbose != 0)
|
||||
printf ("\tOutput Len : %ld\n", src_data.output_frames_gen) ;
|
||||
|
||||
if (abs (src_data.output_frames_gen - output_len) > 4)
|
||||
{ printf ("\n\nLine %d : output data length should be %d.\n\n", __LINE__, output_len) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
/* Check output peak. */
|
||||
output_peak = find_peak (output, src_data.output_frames_gen) ;
|
||||
|
||||
if (verbose != 0)
|
||||
printf ("\tOutput Peak : %6.4f\n", output_peak) ;
|
||||
|
||||
if (fabs (output_peak - test_data->peak_value) > 0.01)
|
||||
{ printf ("\n\nLine %d : output peak (%6.4f) should be %6.4f\n\n", __LINE__, output_peak, test_data->peak_value) ;
|
||||
save_oct_float ("snr_test.dat", data, BUFFER_LEN, output, output_len) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
/* Calculate signal-to-noise ratio. */
|
||||
snr = calculate_snr (output, src_data.output_frames_gen, test_data->pass_band_peaks) ;
|
||||
|
||||
if (snr < 0.0)
|
||||
{ /* An error occurred. */
|
||||
save_oct_float ("snr_test.dat", data, BUFFER_LEN, output, src_data.output_frames_gen) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (verbose != 0)
|
||||
printf ("\tSNR Ratio : %.2f dB\n", snr) ;
|
||||
|
||||
if (snr < test_data->snr)
|
||||
{ printf ("\n\nLine %d : SNR (%5.2f) should be > %6.2f dB\n\n", __LINE__, snr, test_data->snr) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (verbose != 0)
|
||||
puts ("\t-------------------------------------\n\tPass\n") ;
|
||||
else
|
||||
puts ("Pass") ;
|
||||
|
||||
return snr ;
|
||||
} /* snr_test */
|
||||
|
||||
static double
|
||||
find_peak (float *data, int len)
|
||||
{ double peak = 0.0 ;
|
||||
int k = 0 ;
|
||||
|
||||
for (k = 0 ; k < len ; k++)
|
||||
if (fabs (data [k]) > peak)
|
||||
peak = fabs (data [k]) ;
|
||||
|
||||
return peak ;
|
||||
} /* find_peak */
|
||||
|
||||
|
||||
static double
|
||||
find_attenuation (double freq, int converter, int verbose)
|
||||
{ static float input [BUFFER_LEN] ;
|
||||
static float output [2 * BUFFER_LEN] ;
|
||||
|
||||
SRC_DATA src_data ;
|
||||
double output_peak ;
|
||||
int error ;
|
||||
|
||||
gen_windowed_sines (1, &freq, 1.0, input, BUFFER_LEN) ;
|
||||
|
||||
src_data.end_of_input = 1 ; /* Only one buffer worth of input. */
|
||||
|
||||
src_data.data_in = input ;
|
||||
src_data.input_frames = BUFFER_LEN ;
|
||||
|
||||
src_data.src_ratio = 1.999 ;
|
||||
|
||||
src_data.data_out = output ;
|
||||
src_data.output_frames = ARRAY_LEN (output) ;
|
||||
|
||||
if ((error = src_simple (&src_data, converter, 1)))
|
||||
{ printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
output_peak = find_peak (output, ARRAY_LEN (output)) ;
|
||||
|
||||
if (verbose)
|
||||
printf ("\tFreq : %6f InPeak : %6f OutPeak : %6f Atten : %6.2f dB\n",
|
||||
freq, 1.0, output_peak, 20.0 * log10 (1.0 / output_peak)) ;
|
||||
|
||||
return 20.0 * log10 (1.0 / output_peak) ;
|
||||
} /* find_attenuation */
|
||||
|
||||
static double
|
||||
bandwidth_test (int converter, int verbose)
|
||||
{ double f1, f2, a1, a2 ;
|
||||
double freq, atten ;
|
||||
|
||||
f1 = 0.35 ;
|
||||
a1 = find_attenuation (f1, converter, verbose) ;
|
||||
|
||||
f2 = 0.495 ;
|
||||
a2 = find_attenuation (f2, converter, verbose) ;
|
||||
|
||||
if (a1 > 3.0 || a2 < 3.0)
|
||||
{ printf ("\n\nLine %d : cannot bracket 3dB point.\n\n", __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
while (a2 - a1 > 1.0)
|
||||
{ freq = f1 + 0.5 * (f2 - f1) ;
|
||||
atten = find_attenuation (freq, converter, verbose) ;
|
||||
|
||||
if (atten < 3.0)
|
||||
{ f1 = freq ;
|
||||
a1 = atten ;
|
||||
}
|
||||
else
|
||||
{ f2 = freq ;
|
||||
a2 = atten ;
|
||||
} ;
|
||||
} ;
|
||||
|
||||
freq = f1 + (3.0 - a1) * (f2 - f1) / (a2 - a1) ;
|
||||
|
||||
return 200.0 * freq ;
|
||||
} /* bandwidth_test */
|
||||
|
||||
#else /* (HAVE_FFTW3) == 0 */
|
||||
|
||||
/* Alternative main function when librfftw is not available. */
|
||||
|
||||
int
|
||||
main (void)
|
||||
{ puts ("\n"
|
||||
"****************************************************************\n"
|
||||
" This test cannot be run without FFTW (http://www.fftw.org/).\n"
|
||||
" Both the real and the complex versions of the library are\n"
|
||||
" required.") ;
|
||||
puts ("****************************************************************\n") ;
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
#endif
|
||||
|
|
@ -1,339 +0,0 @@
|
|||
/*
|
||||
** Copyright (C) 2002-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
|
||||
**
|
||||
** This program is free software; you can redistribute it and/or modify
|
||||
** it under the terms of the GNU General Public License as published by
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <samplerate.h>
|
||||
|
||||
#include "util.h"
|
||||
|
||||
#define SHORT_BUFFER_LEN 2048
|
||||
#define LONG_BUFFER_LEN ((1 << 16) - 20)
|
||||
|
||||
static void simple_test (int converter) ;
|
||||
static void stream_test (int converter, double ratio) ;
|
||||
static void init_term_test (int converter, double ratio) ;
|
||||
|
||||
static int next_block_length (int reset) ;
|
||||
|
||||
int
|
||||
main (void)
|
||||
{ static double src_ratios [] =
|
||||
{ 0.999900, 1.000100, 0.789012, 1.200000, 0.333333, 3.100000,
|
||||
0.125000, 8.000000, 0.099900, 9.990000, 0.100000, 10.00000
|
||||
} ;
|
||||
|
||||
int k ;
|
||||
|
||||
puts ("\n Zero Order Hold interpolator:") ;
|
||||
|
||||
for (k = 0 ; k < ARRAY_LEN (src_ratios) ; k++)
|
||||
init_term_test (SRC_ZERO_ORDER_HOLD, src_ratios [k]) ;
|
||||
puts ("") ;
|
||||
for (k = 0 ; k < ARRAY_LEN (src_ratios) ; k++)
|
||||
stream_test (SRC_ZERO_ORDER_HOLD, src_ratios [k]) ;
|
||||
|
||||
|
||||
puts ("\n Linear interpolator:") ;
|
||||
for (k = 0 ; k < ARRAY_LEN (src_ratios) ; k++)
|
||||
init_term_test (SRC_LINEAR, src_ratios [k]) ;
|
||||
puts ("") ;
|
||||
for (k = 0 ; k < ARRAY_LEN (src_ratios) ; k++)
|
||||
stream_test (SRC_LINEAR, src_ratios [k]) ;
|
||||
|
||||
|
||||
puts ("\n Sinc interpolator:") ;
|
||||
for (k = 0 ; k < ARRAY_LEN (src_ratios) ; k++)
|
||||
init_term_test (SRC_SINC_FASTEST, src_ratios [k]) ;
|
||||
puts ("") ;
|
||||
for (k = 0 ; k < ARRAY_LEN (src_ratios) ; k++)
|
||||
stream_test (SRC_SINC_FASTEST, src_ratios [k]) ;
|
||||
|
||||
puts ("") ;
|
||||
|
||||
simple_test (SRC_SINC_FASTEST) ;
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
static void
|
||||
simple_test (int converter)
|
||||
{
|
||||
int ilen = 199030, olen = 1000, error ;
|
||||
|
||||
{
|
||||
float in [ilen] ;
|
||||
float out [olen] ;
|
||||
double ratio = (1.0 * olen) / ilen ;
|
||||
SRC_DATA src_data =
|
||||
{ in, out,
|
||||
ilen, olen,
|
||||
0, 0, 0,
|
||||
ratio
|
||||
} ;
|
||||
|
||||
error = src_simple (&src_data, converter, 1) ;
|
||||
if (error)
|
||||
{ printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
} ;
|
||||
|
||||
return ;
|
||||
} /* simple_test */
|
||||
|
||||
static void
|
||||
init_term_test (int converter, double src_ratio)
|
||||
{ static float input [SHORT_BUFFER_LEN], output [SHORT_BUFFER_LEN] ;
|
||||
|
||||
SRC_DATA src_data ;
|
||||
|
||||
int k, input_len, output_len, error, terminate ;
|
||||
|
||||
printf ("\tinit_term_test (SRC ratio = %7.4f) .......... ", src_ratio) ;
|
||||
fflush (stdout) ;
|
||||
|
||||
/* Calculate maximun input and output lengths. */
|
||||
if (src_ratio >= 1.0)
|
||||
{ output_len = SHORT_BUFFER_LEN ;
|
||||
input_len = (int) floor (SHORT_BUFFER_LEN / src_ratio) ;
|
||||
}
|
||||
else
|
||||
{ input_len = SHORT_BUFFER_LEN ;
|
||||
output_len = (int) floor (SHORT_BUFFER_LEN * src_ratio) ;
|
||||
} ;
|
||||
|
||||
/* Reduce input_len by 10 so output is longer than necessary. */
|
||||
input_len -= 10 ;
|
||||
|
||||
for (k = 0 ; k < ARRAY_LEN (input) ; k++)
|
||||
input [k] = 1.0 ;
|
||||
|
||||
if (output_len > SHORT_BUFFER_LEN)
|
||||
{ printf ("\n\nLine %d : output_len > SHORT_BUFFER_LEN\n\n", __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
src_data.data_in = input ;
|
||||
src_data.input_frames = input_len ;
|
||||
|
||||
src_data.src_ratio = src_ratio ;
|
||||
|
||||
src_data.data_out = output ;
|
||||
src_data.output_frames = SHORT_BUFFER_LEN ;
|
||||
|
||||
if ((error = src_simple (&src_data, converter, 1)))
|
||||
{ printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
terminate = (int) ceil ((src_ratio >= 1.0) ? 1 : 1.0 / src_ratio) ;
|
||||
|
||||
if (fabs (src_ratio * input_len - src_data.output_frames_gen) > terminate)
|
||||
{ printf ("\n\nLine %d : Bad output frame count.\n\n", __LINE__) ;
|
||||
printf ("\tterminate : %d\n", terminate) ;
|
||||
printf ("\tsrc_ratio : %.4f\n", src_ratio) ;
|
||||
printf ("\tinput_len : %d\n"
|
||||
"\tinput_len * src_ratio : %f\n", input_len, input_len * src_ratio) ;
|
||||
printf ("\toutput_frames_gen : %ld\n\n", src_data.output_frames_gen) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (abs (src_data.input_frames_used - input_len) > 1)
|
||||
{ printf ("\n\nLine %d : input_frames_used should be %d, is %ld.\n\n",
|
||||
__LINE__, input_len, src_data.input_frames_used) ;
|
||||
printf ("\tsrc_ratio : %.4f\n", src_ratio) ;
|
||||
printf ("\tinput_len : %d\n\tinput_used : %ld\n\n", input_len, src_data.input_frames_used) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (fabs (output [0]) < 0.1)
|
||||
{ printf ("\n\nLine %d : First output sample is bad.\n\n", __LINE__) ;
|
||||
printf ("\toutput [0] == %f\n\n", output [0]) ;
|
||||
exit (1) ;
|
||||
}
|
||||
|
||||
puts ("ok") ;
|
||||
|
||||
return ;
|
||||
} /* init_term_test */
|
||||
|
||||
static void
|
||||
stream_test (int converter, double src_ratio)
|
||||
{ static float input [LONG_BUFFER_LEN], output [LONG_BUFFER_LEN] ;
|
||||
|
||||
SRC_STATE *src_state ;
|
||||
SRC_DATA src_data ;
|
||||
|
||||
int input_len, output_len, current_in, current_out ;
|
||||
int k, error, terminate ;
|
||||
|
||||
printf ("\tstream_test (SRC ratio = %7.4f) .......... ", src_ratio) ;
|
||||
fflush (stdout) ;
|
||||
|
||||
/* Erik */
|
||||
for (k = 0 ; k < LONG_BUFFER_LEN ; k++) input [k] = k * 1.0 ;
|
||||
|
||||
/* Calculate maximun input and output lengths. */
|
||||
if (src_ratio >= 1.0)
|
||||
{ output_len = LONG_BUFFER_LEN ;
|
||||
input_len = (int) floor (LONG_BUFFER_LEN / src_ratio) ;
|
||||
}
|
||||
else
|
||||
{ input_len = LONG_BUFFER_LEN ;
|
||||
output_len = (int) floor (LONG_BUFFER_LEN * src_ratio) ;
|
||||
} ;
|
||||
|
||||
/* Reduce input_len by 10 so output is longer than necessary. */
|
||||
input_len -= 20 ;
|
||||
|
||||
if (output_len > LONG_BUFFER_LEN)
|
||||
{ printf ("\n\nLine %d : output_len > LONG_BUFFER_LEN\n\n", __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
current_in = current_out = 0 ;
|
||||
|
||||
/* Perform sample rate conversion. */
|
||||
if ((src_state = src_new (converter, 1, &error)) == NULL)
|
||||
{ printf ("\n\nLine %d : src_new() failed : %s\n\n", __LINE__, src_strerror (error)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
src_data.end_of_input = 0 ; /* Set this later. */
|
||||
|
||||
src_data.data_in = input ;
|
||||
|
||||
src_data.src_ratio = src_ratio ;
|
||||
|
||||
src_data.data_out = output ;
|
||||
src_data.output_frames = ARRAY_LEN (output) / 10 ;
|
||||
|
||||
terminate = 1 + (int) ceil ((src_ratio >= 1.0) ? src_ratio : 1.0 / src_ratio) ;
|
||||
|
||||
while (1)
|
||||
{
|
||||
src_data.input_frames = next_block_length (0) ;
|
||||
src_data.input_frames = MIN (src_data.input_frames, input_len - current_in) ;
|
||||
|
||||
src_data.output_frames = ARRAY_LEN (output) - current_out ;
|
||||
/*-Erik MIN (src_data.output_frames, output_len - current_out) ;-*/
|
||||
|
||||
src_data.end_of_input = (current_in >= input_len) ? 1 : 0 ;
|
||||
|
||||
if ((error = src_process (src_state, &src_data)))
|
||||
{ printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ;
|
||||
printf (" src_data.input_frames : %ld\n", src_data.input_frames) ;
|
||||
printf (" src_data.output_frames : %ld\n\n", src_data.output_frames) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (src_data.end_of_input && src_data.output_frames_gen == 0)
|
||||
break ;
|
||||
|
||||
if (src_data.input_frames_used > src_data.input_frames)
|
||||
{ printf ("\n\nLine %d : input_frames_used > input_frames\n\n", __LINE__) ;
|
||||
printf (" src_data.input_frames : %ld\n", src_data.input_frames) ;
|
||||
printf (" src_data.input_frames_used : %ld\n", src_data.input_frames_used) ;
|
||||
printf (" src_data.output_frames : %ld\n", src_data.output_frames) ;
|
||||
printf (" src_data.output_frames_gen : %ld\n\n", src_data.output_frames_gen) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (src_data.input_frames_used < 0)
|
||||
{ printf ("\n\nLine %d : input_frames_used (%ld) < 0\n\n", __LINE__, src_data.input_frames_used) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (src_data.output_frames_gen < 0)
|
||||
{ printf ("\n\nLine %d : output_frames_gen (%ld) < 0\n\n", __LINE__, src_data.output_frames_gen) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
current_in += src_data.input_frames_used ;
|
||||
current_out += src_data.output_frames_gen ;
|
||||
|
||||
if (current_in > input_len + terminate)
|
||||
{ printf ("\n\nLine %d : current_in (%d) > input_len (%d + %d)\n\n", __LINE__, current_in, input_len, terminate) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (current_out > output_len)
|
||||
{ printf ("\n\nLine %d : current_out (%d) > output_len (%d)\n\n", __LINE__, current_out, output_len) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (src_data.input_frames_used > input_len)
|
||||
{ printf ("\n\nLine %d : input_frames_used (%ld) > %d\n\n", __LINE__, src_data.input_frames_used, input_len) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (src_data.output_frames_gen > output_len)
|
||||
{ printf ("\n\nLine %d : output_frames_gen (%ld) > %d\n\n", __LINE__, src_data.output_frames_gen, output_len) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (src_data.data_in == NULL && src_data.output_frames_gen == 0)
|
||||
break ;
|
||||
|
||||
|
||||
src_data.data_in += src_data.input_frames_used ;
|
||||
src_data.data_out += src_data.output_frames_gen ;
|
||||
} ;
|
||||
|
||||
src_state = src_delete (src_state) ;
|
||||
|
||||
if (fabs (current_out - src_ratio * input_len) > terminate)
|
||||
{ printf ("\n\nLine %d : bad output data length %d should be %2.1f +/- %d.\n", __LINE__,
|
||||
current_out, src_ratio * input_len, terminate) ;
|
||||
printf ("\tsrc_ratio : %.4f\n", src_ratio) ;
|
||||
printf ("\tinput_len : %d\n\tinput_used : %d\n", input_len, current_in) ;
|
||||
printf ("\toutput_len : %d\n\toutput_gen : %d\n\n", output_len, current_out) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (current_in != input_len)
|
||||
{ printf ("\n\nLine %d : unused input.\n", __LINE__) ;
|
||||
printf ("\tinput_len : %d\n", input_len) ;
|
||||
printf ("\tinput_frames_used : %d\n\n", current_in) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
puts ("ok") ;
|
||||
|
||||
return ;
|
||||
} /* stream_test */
|
||||
|
||||
static int
|
||||
next_block_length (int reset)
|
||||
{ static int block_lengths [] = /* Should be an odd length. */
|
||||
{ /*-2, 500, 5, 400, 10, 300, 20, 200, 50, 100, 70 -*/
|
||||
5, 400, 10, 300, 20, 200, 50, 100, 70
|
||||
} ;
|
||||
static int block_len_index = 0 ;
|
||||
|
||||
if (reset)
|
||||
block_len_index = 0 ;
|
||||
else
|
||||
block_len_index = (block_len_index + 1) % ARRAY_LEN (block_lengths) ;
|
||||
|
||||
return block_lengths [block_len_index] ;
|
||||
} /* next_block_length */
|
||||
|
|
@ -1,212 +0,0 @@
|
|||
/*
|
||||
** Copyright (C) 2004-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
|
||||
**
|
||||
** This program is free software; you can redistribute it and/or modify
|
||||
** it under the terms of the GNU General Public License as published by
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <samplerate.h>
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "util.h"
|
||||
#include "float_cast.h"
|
||||
|
||||
#define BUFFER_LEN (1<<16)
|
||||
|
||||
static float input [BUFFER_LEN] ;
|
||||
static float output [BUFFER_LEN] ;
|
||||
|
||||
static long
|
||||
throughput_test (int converter, long best_throughput)
|
||||
{ SRC_DATA src_data ;
|
||||
clock_t start_time, clock_time ;
|
||||
double duration ;
|
||||
long total_frames = 0, throughput ;
|
||||
int error ;
|
||||
|
||||
printf (" %-30s ", src_get_name (converter)) ;
|
||||
fflush (stdout) ;
|
||||
|
||||
src_data.data_in = input ;
|
||||
src_data.input_frames = ARRAY_LEN (input) ;
|
||||
|
||||
src_data.data_out = output ;
|
||||
src_data.output_frames = ARRAY_LEN (output) ;
|
||||
|
||||
src_data.src_ratio = 0.99 ;
|
||||
|
||||
sleep (2) ;
|
||||
|
||||
start_time = clock () ;
|
||||
|
||||
do
|
||||
{
|
||||
if ((error = src_simple (&src_data, converter, 1)) != 0)
|
||||
{ puts (src_strerror (error)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
total_frames += src_data.output_frames_gen ;
|
||||
|
||||
clock_time = clock () - start_time ;
|
||||
duration = (1.0 * clock_time) / CLOCKS_PER_SEC ;
|
||||
}
|
||||
while (duration < 3.0) ;
|
||||
|
||||
if (src_data.input_frames_used != ARRAY_LEN (input))
|
||||
{ printf ("\n\nLine %d : input frames used %ld should be %d\n", __LINE__, src_data.input_frames_used, ARRAY_LEN (input)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (fabs (src_data.src_ratio * src_data.input_frames_used - src_data.output_frames_gen) > 2)
|
||||
{ printf ("\n\nLine %d : input / output length mismatch.\n\n", __LINE__) ;
|
||||
printf (" input len : %d\n", ARRAY_LEN (input)) ;
|
||||
printf (" output len : %ld (should be %g +/- 2)\n\n", src_data.output_frames_gen,
|
||||
floor (0.5 + src_data.src_ratio * src_data.input_frames_used)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
throughput = lrint (floor (total_frames / duration)) ;
|
||||
|
||||
if (best_throughput == 0)
|
||||
{ best_throughput = MAX (throughput, best_throughput) ;
|
||||
printf ("%5.2f %10ld\n", duration, throughput) ;
|
||||
}
|
||||
else
|
||||
{ best_throughput = MAX (throughput, best_throughput) ;
|
||||
printf ("%5.2f %10ld %10ld\n", duration, throughput, best_throughput) ;
|
||||
}
|
||||
|
||||
|
||||
return best_throughput ;
|
||||
} /* throughput_test */
|
||||
|
||||
static void
|
||||
single_run (void)
|
||||
{
|
||||
|
||||
printf ("\n CPU name : %s\n", get_cpu_name ()) ;
|
||||
|
||||
puts (
|
||||
"\n"
|
||||
" Converter Duration Throughput\n"
|
||||
" -----------------------------------------------------------"
|
||||
) ;
|
||||
|
||||
throughput_test (SRC_ZERO_ORDER_HOLD, 0) ;
|
||||
throughput_test (SRC_LINEAR, 0) ;
|
||||
throughput_test (SRC_SINC_FASTEST, 0) ;
|
||||
throughput_test (SRC_SINC_MEDIUM_QUALITY, 0) ;
|
||||
throughput_test (SRC_SINC_BEST_QUALITY, 0) ;
|
||||
|
||||
puts ("") ;
|
||||
return ;
|
||||
} /* single_run */
|
||||
|
||||
static void
|
||||
multi_run (int run_count)
|
||||
{ long zero_order_hold = 0, linear = 0 ;
|
||||
long sinc_fastest = 0, sinc_medium = 0, sinc_best = 0 ;
|
||||
int k ;
|
||||
|
||||
puts (
|
||||
"\n"
|
||||
" Converter Duration Throughput Best Throughput\n"
|
||||
" --------------------------------------------------------------------------------"
|
||||
) ;
|
||||
|
||||
for (k = 0 ; k < run_count ; k++)
|
||||
{ zero_order_hold = throughput_test (SRC_ZERO_ORDER_HOLD, zero_order_hold) ;
|
||||
linear = throughput_test (SRC_LINEAR, linear) ;
|
||||
sinc_fastest = throughput_test (SRC_SINC_FASTEST, sinc_fastest) ;
|
||||
sinc_medium = throughput_test (SRC_SINC_MEDIUM_QUALITY, sinc_medium) ;
|
||||
sinc_best = throughput_test (SRC_SINC_BEST_QUALITY, sinc_best) ;
|
||||
|
||||
puts ("") ;
|
||||
|
||||
/* Let the CPU cool down. We might be running on a laptop. */
|
||||
sleep (10) ;
|
||||
} ;
|
||||
|
||||
printf ("\n CPU name : %s\n", get_cpu_name ()) ;
|
||||
|
||||
puts (
|
||||
"\n"
|
||||
" Converter Best Throughput\n"
|
||||
" ------------------------------------------------"
|
||||
) ;
|
||||
printf (" %-30s %10ld\n", src_get_name (SRC_ZERO_ORDER_HOLD), zero_order_hold) ;
|
||||
printf (" %-30s %10ld\n", src_get_name (SRC_LINEAR), linear) ;
|
||||
printf (" %-30s %10ld\n", src_get_name (SRC_SINC_FASTEST), sinc_fastest) ;
|
||||
printf (" %-30s %10ld\n", src_get_name (SRC_SINC_MEDIUM_QUALITY), sinc_medium) ;
|
||||
printf (" %-30s %10ld\n", src_get_name (SRC_SINC_BEST_QUALITY), sinc_best) ;
|
||||
|
||||
puts ("") ;
|
||||
} /* multi_run */
|
||||
|
||||
static void
|
||||
usage_exit (const char * argv0)
|
||||
{ const char * cptr ;
|
||||
|
||||
if ((cptr = strrchr (argv0, '/')) != NULL)
|
||||
argv0 = cptr ;
|
||||
|
||||
printf (
|
||||
"Usage :\n"
|
||||
" %s - Single run of the throughput test.\n"
|
||||
" %s --best-of N - Do N runs of test a print bext result.\n"
|
||||
"\n",
|
||||
argv0, argv0) ;
|
||||
|
||||
exit (0) ;
|
||||
} /* usage_exit */
|
||||
|
||||
int
|
||||
main (int argc, char ** argv)
|
||||
{ double freq ;
|
||||
|
||||
memset (input, 0, sizeof (input)) ;
|
||||
freq = 0.01 ;
|
||||
gen_windowed_sines (1, &freq, 1.0, input, BUFFER_LEN) ;
|
||||
|
||||
if (argc == 1)
|
||||
single_run () ;
|
||||
else if (argc == 3 && strcmp (argv [1], "--best-of") == 0)
|
||||
{ int run_count = atoi (argv [2]) ;
|
||||
|
||||
if (run_count < 1 || run_count > 20)
|
||||
{ printf ("Please be sensible. Run count should be in range (1, 10].\n") ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
multi_run (run_count) ;
|
||||
}
|
||||
else
|
||||
usage_exit (argv [0]) ;
|
||||
|
||||
puts (
|
||||
" Duration is in seconds.\n"
|
||||
" Throughput is in samples/sec (more is better).\n"
|
||||
) ;
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
|
@ -1,230 +0,0 @@
|
|||
/*
|
||||
** Copyright (C) 2002-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
|
||||
**
|
||||
** This program is free software; you can redistribute it and/or modify
|
||||
** it under the terms of the GNU General Public License as published by
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "util.h"
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846264338
|
||||
#endif
|
||||
|
||||
void
|
||||
gen_windowed_sines (int freq_count, const double *freqs, double max, float *output, int output_len)
|
||||
{ int k, freq ;
|
||||
double amplitude, phase ;
|
||||
|
||||
amplitude = max / freq_count ;
|
||||
|
||||
for (k = 0 ; k < output_len ; k++)
|
||||
output [k] = 0.0 ;
|
||||
|
||||
for (freq = 0 ; freq < freq_count ; freq++)
|
||||
{ phase = 0.9 * M_PI / freq_count ;
|
||||
|
||||
if (freqs [freq] <= 0.0 || freqs [freq] >= 0.5)
|
||||
{ printf ("\n%s : Error : freq [%d] == %g is out of range. Should be < 0.5.\n", __FILE__, freq, freqs [freq]) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
for (k = 0 ; k < output_len ; k++)
|
||||
output [k] += amplitude * sin (freqs [freq] * (2 * k) * M_PI + phase) ;
|
||||
} ;
|
||||
|
||||
/* Apply Hanning Window. */
|
||||
for (k = 0 ; k < output_len ; k++)
|
||||
output [k] *= 0.5 - 0.5 * cos ((2 * k) * M_PI / (output_len - 1)) ;
|
||||
|
||||
/* data [k] *= 0.3635819 - 0.4891775 * cos ((2 * k) * M_PI / (output_len - 1))
|
||||
+ 0.1365995 * cos ((4 * k) * M_PI / (output_len - 1))
|
||||
- 0.0106411 * cos ((6 * k) * M_PI / (output_len - 1)) ;
|
||||
*/
|
||||
|
||||
return ;
|
||||
} /* gen_windowed_sines */
|
||||
|
||||
void
|
||||
save_oct_float (char *filename, float *input, int in_len, float *output, int out_len)
|
||||
{ FILE *file ;
|
||||
int k ;
|
||||
|
||||
printf ("Dumping input and output data to file : %s.\n\n", filename) ;
|
||||
|
||||
if (! (file = fopen (filename, "w")))
|
||||
return ;
|
||||
|
||||
fprintf (file, "# Not created by Octave\n") ;
|
||||
|
||||
fprintf (file, "# name: input\n") ;
|
||||
fprintf (file, "# type: matrix\n") ;
|
||||
fprintf (file, "# rows: %d\n", in_len) ;
|
||||
fprintf (file, "# columns: 1\n") ;
|
||||
|
||||
for (k = 0 ; k < in_len ; k++)
|
||||
fprintf (file, "% g\n", input [k]) ;
|
||||
|
||||
fprintf (file, "# name: output\n") ;
|
||||
fprintf (file, "# type: matrix\n") ;
|
||||
fprintf (file, "# rows: %d\n", out_len) ;
|
||||
fprintf (file, "# columns: 1\n") ;
|
||||
|
||||
for (k = 0 ; k < out_len ; k++)
|
||||
fprintf (file, "% g\n", output [k]) ;
|
||||
|
||||
fclose (file) ;
|
||||
return ;
|
||||
} /* save_oct_float */
|
||||
|
||||
void
|
||||
save_oct_double (char *filename, double *input, int in_len, double *output, int out_len)
|
||||
{ FILE *file ;
|
||||
int k ;
|
||||
|
||||
printf ("Dumping input and output data to file : %s.\n\n", filename) ;
|
||||
|
||||
if (! (file = fopen (filename, "w")))
|
||||
return ;
|
||||
|
||||
fprintf (file, "# Not created by Octave\n") ;
|
||||
|
||||
fprintf (file, "# name: input\n") ;
|
||||
fprintf (file, "# type: matrix\n") ;
|
||||
fprintf (file, "# rows: %d\n", in_len) ;
|
||||
fprintf (file, "# columns: 1\n") ;
|
||||
|
||||
for (k = 0 ; k < in_len ; k++)
|
||||
fprintf (file, "% g\n", input [k]) ;
|
||||
|
||||
fprintf (file, "# name: output\n") ;
|
||||
fprintf (file, "# type: matrix\n") ;
|
||||
fprintf (file, "# rows: %d\n", out_len) ;
|
||||
fprintf (file, "# columns: 1\n") ;
|
||||
|
||||
for (k = 0 ; k < out_len ; k++)
|
||||
fprintf (file, "% g\n", output [k]) ;
|
||||
|
||||
fclose (file) ;
|
||||
return ;
|
||||
} /* save_oct_double */
|
||||
|
||||
void
|
||||
interleave_data (const float *in, float *out, int frames, int channels)
|
||||
{ int fr, ch ;
|
||||
|
||||
for (fr = 0 ; fr < frames ; fr++)
|
||||
for (ch = 0 ; ch < channels ; ch++)
|
||||
out [ch + channels * fr] = in [fr + frames * ch] ;
|
||||
|
||||
return ;
|
||||
} /* interleave_data */
|
||||
|
||||
void
|
||||
deinterleave_data (const float *in, float *out, int frames, int channels)
|
||||
{ int fr, ch ;
|
||||
|
||||
for (ch = 0 ; ch < channels ; ch++)
|
||||
for (fr = 0 ; fr < frames ; fr++)
|
||||
out [fr + frames * ch] = in [ch + channels * fr] ;
|
||||
|
||||
return ;
|
||||
} /* deinterleave_data */
|
||||
|
||||
void
|
||||
reverse_data (float *data, int datalen)
|
||||
{ int left, right ;
|
||||
float temp ;
|
||||
|
||||
left = 0 ;
|
||||
right = datalen - 1 ;
|
||||
|
||||
while (left < right)
|
||||
{ temp = data [left] ;
|
||||
data [left] = data [right] ;
|
||||
data [right] = temp ;
|
||||
left ++ ;
|
||||
right -- ;
|
||||
} ;
|
||||
|
||||
} /* reverse_data */
|
||||
|
||||
const char *
|
||||
get_cpu_name (void)
|
||||
{
|
||||
const char *name = "Unknown", *search = NULL ;
|
||||
static char buffer [512] ;
|
||||
FILE * file = NULL ;
|
||||
int is_pipe = 0 ;
|
||||
|
||||
#if defined (__linux__)
|
||||
file = fopen ("/proc/cpuinfo", "r") ;
|
||||
search = "model name" ;
|
||||
#elif defined (__APPLE__)
|
||||
file = popen ("/usr/sbin/system_profiler -detailLevel full SPHardwareDataType", "r") ;
|
||||
search = "Processor Name" ;
|
||||
is_pipe = 1 ;
|
||||
#elif defined (__FreeBSD__)
|
||||
file = popen ("sysctl -a", "r") ;
|
||||
search = "hw.model" ;
|
||||
is_pipe = 1 ;
|
||||
#else
|
||||
file = NULL ;
|
||||
#endif
|
||||
|
||||
if (file == NULL)
|
||||
return name ;
|
||||
|
||||
if (search == NULL)
|
||||
{ printf ("Error : search is NULL in function %s.\n", __func__) ;
|
||||
return name ;
|
||||
} ;
|
||||
|
||||
while (fgets (buffer, sizeof (buffer), file) != NULL)
|
||||
if (strstr (buffer, search))
|
||||
{ char *src, *dest ;
|
||||
|
||||
if ((src = strchr (buffer, ':')) != NULL)
|
||||
{ src ++ ;
|
||||
while (isspace (src [0]))
|
||||
src ++ ;
|
||||
name = src ;
|
||||
|
||||
/* Remove consecutive spaces. */
|
||||
src ++ ;
|
||||
for (dest = src ; src [0] ; src ++)
|
||||
{ if (isspace (src [0]) && isspace (dest [-1]))
|
||||
continue ;
|
||||
dest [0] = src [0] ;
|
||||
dest ++ ;
|
||||
} ;
|
||||
dest [0] = 0 ;
|
||||
break ;
|
||||
} ;
|
||||
} ;
|
||||
|
||||
if (is_pipe)
|
||||
pclose (file) ;
|
||||
else
|
||||
fclose (file) ;
|
||||
|
||||
return name ;
|
||||
} /* get_cpu_name */
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
/*
|
||||
** Copyright (C) 2002-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
|
||||
**
|
||||
** This program is free software; you can redistribute it and/or modify
|
||||
** it under the terms of the GNU General Public License as published by
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#define ABS(a) (((a) < 0) ? - (a) : (a))
|
||||
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
|
||||
#define MAX(a,b) (((a) >= (b)) ? (a) : (b))
|
||||
|
||||
#define ARRAY_LEN(x) ((int) (sizeof (x) / sizeof ((x) [0])))
|
||||
|
||||
void gen_windowed_sines (int freq_count, const double *freqs, double max, float *output, int output_len) ;
|
||||
|
||||
void save_oct_float (char *filename, float *input, int in_len, float *output, int out_len) ;
|
||||
void save_oct_double (char *filename, double *input, int in_len, double *output, int out_len) ;
|
||||
|
||||
void interleave_data (const float *in, float *out, int frames, int channels) ;
|
||||
|
||||
void deinterleave_data (const float *in, float *out, int frames, int channels) ;
|
||||
|
||||
void reverse_data (float *data, int datalen) ;
|
||||
|
||||
double calculate_snr (float *data, int len, int expected_peaks) ;
|
||||
|
||||
const char * get_cpu_name (void) ;
|
||||
|
||||
#if OS_IS_WIN32
|
||||
/*
|
||||
** Extra Win32 hacks.
|
||||
**
|
||||
** Despite Microsoft claim of windows being POSIX compatibile it has '_sleep'
|
||||
** instead of 'sleep'.
|
||||
*/
|
||||
|
||||
#define sleep _sleep
|
||||
#endif
|
||||
|
|
@ -1,152 +0,0 @@
|
|||
/*
|
||||
** Copyright (C) 2006-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
|
||||
**
|
||||
** This program is free software; you can redistribute it and/or modify
|
||||
** it under the terms of the GNU General Public License as published by
|
||||
** the Free Software Foundation; either version 2 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <samplerate.h>
|
||||
|
||||
#include "util.h"
|
||||
|
||||
#define BUFFER_LEN (1 << 16)
|
||||
|
||||
static void varispeed_test (int converter, double target_snr) ;
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
puts ("") ;
|
||||
printf (" Zero Order Hold interpolator : ") ;
|
||||
varispeed_test (SRC_ZERO_ORDER_HOLD, 10.0) ;
|
||||
|
||||
printf (" Linear interpolator : ") ;
|
||||
varispeed_test (SRC_LINEAR, 10.0) ;
|
||||
|
||||
printf (" Sinc interpolator : ") ;
|
||||
varispeed_test (SRC_SINC_FASTEST, 115.0) ;
|
||||
|
||||
puts ("") ;
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
static void
|
||||
varispeed_test (int converter, double target_snr)
|
||||
{ static float input [BUFFER_LEN], output [BUFFER_LEN] ;
|
||||
double sine_freq, snr ;
|
||||
|
||||
SRC_STATE *src_state ;
|
||||
SRC_DATA src_data ;
|
||||
|
||||
int input_len, error ;
|
||||
|
||||
memset (input, 0, sizeof (input)) ;
|
||||
|
||||
input_len = ARRAY_LEN (input) / 2 ;
|
||||
|
||||
sine_freq = 0.0111 ;
|
||||
gen_windowed_sines (1, &sine_freq, 1.0, input, input_len) ;
|
||||
|
||||
/* Perform sample rate conversion. */
|
||||
if ((src_state = src_new (converter, 1, &error)) == NULL)
|
||||
{ printf ("\n\nLine %d : src_new() failed : %s\n\n", __LINE__, src_strerror (error)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
src_data.end_of_input = 1 ;
|
||||
|
||||
src_data.data_in = input ;
|
||||
src_data.input_frames = input_len ;
|
||||
|
||||
src_data.src_ratio = 3.0 ;
|
||||
|
||||
src_data.data_out = output ;
|
||||
src_data.output_frames = ARRAY_LEN (output) ;
|
||||
|
||||
if ((error = src_set_ratio (src_state, 1.0 / src_data.src_ratio)))
|
||||
{ printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if ((error = src_process (src_state, &src_data)))
|
||||
{ printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ;
|
||||
printf (" src_data.input_frames : %ld\n", src_data.input_frames) ;
|
||||
printf (" src_data.output_frames : %ld\n\n", src_data.output_frames) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (src_data.input_frames_used != input_len)
|
||||
{ printf ("\n\nLine %d : unused input.\n", __LINE__) ;
|
||||
printf ("\tinput_len : %d\n", input_len) ;
|
||||
printf ("\tinput_frames_used : %ld\n\n", src_data.input_frames_used) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
/* Copy the last output to the input. */
|
||||
memcpy (input, output, sizeof (input)) ;
|
||||
reverse_data (input, src_data.output_frames_gen) ;
|
||||
|
||||
if ((error = src_reset (src_state)))
|
||||
{ printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
src_data.end_of_input = 1 ;
|
||||
|
||||
src_data.data_in = input ;
|
||||
input_len = src_data.input_frames = src_data.output_frames_gen ;
|
||||
|
||||
src_data.data_out = output ;
|
||||
src_data.output_frames = ARRAY_LEN (output) ;
|
||||
|
||||
if ((error = src_set_ratio (src_state, 1.0 / src_data.src_ratio)))
|
||||
{ printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if ((error = src_process (src_state, &src_data)))
|
||||
{ printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ;
|
||||
printf (" src_data.input_frames : %ld\n", src_data.input_frames) ;
|
||||
printf (" src_data.output_frames : %ld\n\n", src_data.output_frames) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (src_data.input_frames_used != input_len)
|
||||
{ printf ("\n\nLine %d : unused input.\n", __LINE__) ;
|
||||
printf ("\tinput_len : %d\n", input_len) ;
|
||||
printf ("\tinput_frames_used : %ld\n\n", src_data.input_frames_used) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
src_state = src_delete (src_state) ;
|
||||
|
||||
snr = calculate_snr (output, src_data.output_frames_gen, 1) ;
|
||||
|
||||
if (target_snr > snr)
|
||||
{ printf ("\n\nLine %d : snr (%3.1f) does not meet target (%3.1f)\n\n", __LINE__, snr, target_snr) ;
|
||||
save_oct_float ("varispeed.mat", input, src_data.input_frames, output, src_data.output_frames_gen) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
puts ("ok") ;
|
||||
|
||||
return ;
|
||||
} /* varispeed_test */
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
SoX Resampler Library Copyright (c) 2007-13 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.
|
||||
|
|
|
@ -1,25 +1,19 @@
|
|||
/* SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
/* SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
|
||||
* Licence for this file: LGPL v2.1 See LICENCE for details. */
|
||||
|
||||
/* N.B. Pre-configured for typical Win32 systems. Normal procedure is to use
|
||||
* the cmake configuration and build system. See INSTALL. */
|
||||
/* N.B. Pre-configured for typical 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 SOXR_VERSION_MAJOR 0
|
||||
#define SOXR_VERSION_MINOR 0
|
||||
#define SOXR_VERSION_PATCH 1
|
||||
#define SOXR_VERSION "0.0.5"
|
||||
|
||||
#define HAVE_SINGLE_PRECISION 1
|
||||
#define HAVE_DOUBLE_PRECISION 1
|
||||
#define HAVE_VR 1
|
||||
#define HAVE_AVFFT 0
|
||||
#define HAVE_SIMD 1
|
||||
#define HAVE_FENV_H 0
|
||||
#define HAVE_LRINT 0
|
||||
#define WORDS_BIGENDIAN 0
|
||||
#define HAVE_AVFFT 0
|
||||
#define HAVE_SIMD 1
|
||||
#define HAVE_FENV_H 0
|
||||
#define HAVE_LRINT 0
|
||||
#define WORDS_BIGENDIAN 0
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
|
@ -39,17 +33,15 @@
|
|||
#if LONG_MAX > 2147483647L
|
||||
#define int32_t int
|
||||
#define int64_t long
|
||||
#define DBL (double)
|
||||
#elif LONG_MAX < 2147483647L
|
||||
#error this library requires that 'long int' has at least 32-bits
|
||||
#else
|
||||
#define int32_t long
|
||||
#if defined(_MSC_VER)
|
||||
#if defined _MSC_VER
|
||||
#define int64_t __int64
|
||||
#else
|
||||
#define int64_t long long
|
||||
#endif
|
||||
#define DBL
|
||||
#endif
|
||||
#define uint32_t unsigned int32_t
|
||||
#define uint64_t unsigned int64_t
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
/* SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
/* SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
|
||||
* Licence for this file: LGPL v2.1 See LICENCE for details. */
|
||||
|
||||
#if !defined soxr_config_included
|
||||
#define soxr_config_included
|
||||
|
||||
#define SOXR_VERSION "@PROJECT_VERSION@"
|
||||
#define HAVE_SINGLE_PRECISION @HAVE_SINGLE_PRECISION@
|
||||
#define HAVE_DOUBLE_PRECISION @HAVE_DOUBLE_PRECISION@
|
||||
#define HAVE_VR @HAVE_VR@
|
||||
#define HAVE_AVFFT @HAVE_AVFFT@
|
||||
#define HAVE_SIMD @HAVE_SIMD@
|
||||
#define HAVE_FENV_H @HAVE_FENV_H@
|
||||
|
@ -32,7 +30,6 @@
|
|||
#if LONG_MAX > 2147483647L
|
||||
#define int32_t int
|
||||
#define int64_t long
|
||||
#define DBL (double)
|
||||
#elif LONG_MAX < 2147483647L
|
||||
#error this library requires that 'long int' has at least 32-bits
|
||||
#else
|
||||
|
@ -42,7 +39,6 @@
|
|||
#else
|
||||
#define int64_t long long
|
||||
#endif
|
||||
#define DBL
|
||||
#endif
|
||||
#define uint32_t unsigned int32_t
|
||||
#define uint64_t unsigned int64_t
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
# 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} -DSOXR_LIB)
|
||||
|
@ -9,8 +9,10 @@ add_definitions (${PROJECT_C_FLAGS} -DSOXR_LIB)
|
|||
|
||||
set (RDFT32 fft4g32)
|
||||
if (WITH_AVFFT AND AVCODEC_FOUND)
|
||||
set (RDFT32 avfft32)
|
||||
set (RDFT32S avfft32s)
|
||||
elseif (WITH_PFFFT)
|
||||
#set (RDFT32 pffft32)
|
||||
set (RDFT32S pffft32s)
|
||||
elseif (WITH_SIMD)
|
||||
set (RDFT32S fft4g32s)
|
||||
|
@ -24,10 +26,6 @@ if (WITH_SINGLE_PRECISION)
|
|||
set (SP_SOURCES rate32 ${RDFT32})
|
||||
endif ()
|
||||
|
||||
if (HAVE_VR)
|
||||
set (VR_SOURCES vr32)
|
||||
endif ()
|
||||
|
||||
if (HAVE_SIMD)
|
||||
set (SIMD_SOURCES rate32s ${RDFT32S} simd)
|
||||
foreach (source ${SIMD_SOURCES})
|
||||
|
@ -40,7 +38,7 @@ endif ()
|
|||
# Libsoxr:
|
||||
|
||||
add_library (${PROJECT_NAME} ${LIB_TYPE} ${PROJECT_NAME}.c data-io dbesi0 filter fft4g64
|
||||
${SP_SOURCES} ${VR_SOURCES} ${DP_SOURCES} ${SIMD_SOURCES})
|
||||
${SP_SOURCES} vr32 ${DP_SOURCES} ${SIMD_SOURCES})
|
||||
set_target_properties (${PROJECT_NAME} PROPERTIES
|
||||
VERSION "${SO_VERSION}"
|
||||
SOVERSION ${SO_VERSION_MAJOR}
|
||||
|
@ -50,9 +48,9 @@ set_target_properties (${PROJECT_NAME} PROPERTIES
|
|||
if (BUILD_FRAMEWORK)
|
||||
set_target_properties (${PROJECT_NAME} PROPERTIES FRAMEWORK TRUE)
|
||||
elseif (NOT WIN32)
|
||||
set (TARGET_PCS ${CMAKE_CURRENT_BINARY_DIR}/lib${PROJECT_NAME}.pc)
|
||||
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/lib${PROJECT_NAME}.pc.in ${TARGET_PCS})
|
||||
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/lib${PROJECT_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
|
||||
set (TARGET_PCS ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc)
|
||||
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc.in ${TARGET_PCS})
|
||||
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
|
||||
endif ()
|
||||
|
||||
|
||||
|
@ -61,7 +59,7 @@ endif ()
|
|||
|
||||
if (WITH_LSR_BINDINGS)
|
||||
set (LSR ${PROJECT_NAME}-lsr)
|
||||
set (LSR_SO_VERSION 0.1.8)
|
||||
set (LSR_SO_VERSION 0.1.9)
|
||||
set (LSR_SO_VERSION_MAJOR 0)
|
||||
add_library (${LSR} ${LIB_TYPE} lsr)
|
||||
target_link_libraries (${LSR} ${PROJECT_NAME})
|
||||
|
@ -74,9 +72,9 @@ if (WITH_LSR_BINDINGS)
|
|||
if (BUILD_FRAMEWORK)
|
||||
set_target_properties (${LSR} PROPERTIES FRAMEWORK TRUE)
|
||||
elseif (NOT WIN32)
|
||||
set (TARGET_PCS "${TARGET_PCS} ${CMAKE_CURRENT_BINARY_DIR}/lib${LSR}.pc")
|
||||
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/lib${LSR}.pc.in ${CMAKE_CURRENT_BINARY_DIR}/lib${LSR}.pc)
|
||||
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/lib${LSR}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
|
||||
set (TARGET_PCS "${TARGET_PCS} ${CMAKE_CURRENT_BINARY_DIR}/${LSR}.pc")
|
||||
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/${LSR}.pc.in ${CMAKE_CURRENT_BINARY_DIR}/${LSR}.pc)
|
||||
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/${LSR}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
/* SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
|
||||
* Licence for this file: LGPL v2.1 See LICENCE for details. */
|
||||
|
||||
#if defined SOXR_LIB
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
/* SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
|
||||
* Licence for this file: LGPL v2.1 See LICENCE for details. */
|
||||
|
||||
#include <math.h>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
/* SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
|
||||
* Licence for this file: LGPL v2.1 See LICENCE for details. */
|
||||
|
||||
#include <math.h>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
/* SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
|
||||
* Licence for this file: LGPL v2.1 See LICENCE for details. */
|
||||
|
||||
/* Concurrent Control with "Readers" and "Writers", P.J. Courtois et al, 1971 */
|
||||
|
@ -6,7 +6,9 @@
|
|||
#if !defined ccrw2_included
|
||||
#define ccrw2_included
|
||||
|
||||
#if defined SOXR_LIB
|
||||
#include "internal.h"
|
||||
#endif
|
||||
|
||||
#if defined _OPENMP
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
/* SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
|
||||
* Licence for this file: LGPL v2.1 See LICENCE for details. */
|
||||
|
||||
#include <limits.h>
|
||||
|
@ -62,28 +62,31 @@ void _soxr_deinterleave_f(float * * dest, /* Round/clipping not needed here */
|
|||
|
||||
#if HAVE_FENV_H
|
||||
#include <fenv.h>
|
||||
#define fe_test_invalid() fetestexcept(FE_INVALID)
|
||||
#define fe_clear_invalid() feclearexcept(FE_INVALID)
|
||||
#elif defined _MSC_VER
|
||||
#define FE_INVALID 1
|
||||
#define FE_DIVBYZERO 4
|
||||
#define FE_OVERFLOW 8
|
||||
#define FE_UNDERFLOW 16
|
||||
#define FE_INEXACT 32
|
||||
#define FE_ALL_EXCEPT (FE_INEXACT|FE_DIVBYZERO|FE_UNDERFLOW|FE_OVERFLOW|FE_INVALID)
|
||||
static __inline int fetestexcept(int excepts)
|
||||
#define FE_INVALID 1
|
||||
#if defined _WIN64
|
||||
#include <float.h>
|
||||
#define fe_test_invalid() (_statusfp() & _SW_INVALID)
|
||||
#define fe_clear_invalid _clearfp /* FIXME clears all */
|
||||
#else
|
||||
static __inline int fe_test_invalid()
|
||||
{
|
||||
short status_word;
|
||||
__asm fnstsw status_word
|
||||
return status_word & excepts & FE_ALL_EXCEPT;
|
||||
return status_word & FE_INVALID;
|
||||
}
|
||||
|
||||
static __inline int feclearexcept(int excepts)
|
||||
static __inline int fe_clear_invalid()
|
||||
{
|
||||
int16_t status[14];
|
||||
__asm fnstenv status
|
||||
status[2] &= ~(excepts & FE_ALL_EXCEPT);
|
||||
status[2] &= ~FE_INVALID;
|
||||
__asm fldenv status
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
/* SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
|
||||
* Licence for this file: LGPL v2.1 See LICENCE for details. */
|
||||
|
||||
#if !defined soxr_data_io_included
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
/* SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
|
||||
* Licence for this file: LGPL v2.1 See LICENCE for details. */
|
||||
|
||||
void lsx_cdft(int, int, double *, int *, double *);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
/* SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
|
||||
* Licence for this file: LGPL v2.1 See LICENCE for details. */
|
||||
|
||||
#include "filter.h"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
/* SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
|
||||
* Licence for this file: LGPL v2.1 See LICENCE for details. */
|
||||
|
||||
#include "filter.h"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
/* SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
|
||||
* Licence for this file: LGPL v2.1 See LICENCE for details. */
|
||||
|
||||
#include "filter.h"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
/* SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
|
||||
* Licence for this file: LGPL v2.1 See LICENCE for details. */
|
||||
|
||||
static int * LSX_FFT_BR;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
/* 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
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
/* SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
|
||||
* Licence for this file: LGPL v2.1 See LICENCE for details. */
|
||||
|
||||
#include "filter.h"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
/* SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
|
||||
* Licence for this file: LGPL v2.1 See LICENCE for details. */
|
||||
|
||||
#if !defined soxr_filter_included
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
/* SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
|
||||
* Licence for this file: LGPL v2.1 See LICENCE for details. */
|
||||
|
||||
#include "half_coefs.h"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
/* SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
|
||||
* Licence for this file: LGPL v2.1 See LICENCE for details. */
|
||||
|
||||
/* Down-sample by a factor of 2 using a FIR with odd length (LEN).*/
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
/* SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
|
||||
* Licence for this file: LGPL v2.1 See LICENCE for details. */
|
||||
|
||||
#if defined __GNUC__
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
/* SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
|
||||
* Licence for this file: LGPL v2.1 See LICENCE for details. */
|
||||
|
||||
#if !defined soxr_internal_included
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
prefix=${CMAKE_INSTALL_PREFIX}
|
||||
exec_prefix=${CMAKE_INSTALL_PREFIX}
|
||||
libdir=${LIB_INSTALL_DIR}
|
||||
includedir=${INCLUDE_INSTALL_DIR}
|
||||
|
||||
Name: lib${LSR}
|
||||
Description: ${DESCRIPTION_SUMMARY} (with libsamplerate-like bindings)
|
||||
Requires: libsoxr
|
||||
Version: ${PROJECT_VERSION}
|
||||
Libs: -L${LIB_INSTALL_DIR} -l${LSR}
|
||||
Cflags: -I${INCLUDE_INSTALL_DIR}
|
|
@ -1,11 +0,0 @@
|
|||
prefix=${CMAKE_INSTALL_PREFIX}
|
||||
exec_prefix=${CMAKE_INSTALL_PREFIX}
|
||||
libdir=${LIB_INSTALL_DIR}
|
||||
includedir=${INCLUDE_INSTALL_DIR}
|
||||
|
||||
Name: lib${PROJECT_NAME}
|
||||
Description: ${DESCRIPTION_SUMMARY}
|
||||
Requires:
|
||||
Version: ${PROJECT_VERSION}
|
||||
Libs: -L${LIB_INSTALL_DIR} -l${PROJECT_NAME}
|
||||
Cflags: -I${INCLUDE_INSTALL_DIR}
|
|
@ -1,4 +1,4 @@
|
|||
/* SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
/* SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
|
||||
* Licence for this file: LGPL v2.1 See LICENCE for details. */
|
||||
|
||||
/* Wrapper mostly compatible with `libsamplerate'. */
|
||||
|
@ -19,7 +19,6 @@ typedef struct soxr SRC_STATE;
|
|||
#include "soxr-lsr.h"
|
||||
#include "rint.h"
|
||||
|
||||
|
||||
soxr_error_t src_simple(io_t * p, unsigned id, int channels)
|
||||
{
|
||||
size_t idone, odone;
|
||||
|
@ -52,7 +51,8 @@ soxr_t src_callback_new(soxr_input_fn_t fn, unsigned id, int channels, SRC_ERROR
|
|||
soxr = soxr_create(0, 0, (unsigned)channels, &error, 0, &q_spec, &r_spec);
|
||||
if (soxr)
|
||||
error = soxr_set_input_fn(soxr, fn, p, 0);
|
||||
*(int *)error0 = (int)(long)error;
|
||||
if (error0)
|
||||
*(int *)error0 = (int)(ptrdiff_t)error;
|
||||
return soxr;
|
||||
}
|
||||
|
||||
|
@ -105,7 +105,7 @@ static char const * const names[] = {"LSR best sinc", "LSR medium sinc", "LSR fa
|
|||
char const * src_get_name(unsigned n) {return n < 5u + !getenv("SOXR_LSR_STRICT")? names[n] : 0;}
|
||||
char const * src_get_description(unsigned id) {return src_get_name(id);}
|
||||
char const * src_get_version(void) {return soxr_version();}
|
||||
char const * src_strerror(soxr_error_t error) {return error == (soxr_error_t)1? "Placeholder." : soxr_strerror(error);}
|
||||
char const * src_strerror(soxr_error_t error) {return error == (soxr_error_t)1? "Placeholder." : sizeof(int) >= sizeof(char *) || !error ? soxr_strerror(error) : "soxr error";}
|
||||
int src_is_valid_ratio(double oi_ratio) {return getenv("SOXR_LSR_STRICT")? oi_ratio >= 1./256 && oi_ratio <= 256 : oi_ratio > 0;}
|
||||
soxr_error_t src_error(soxr_t p) {return soxr_error(p);}
|
||||
soxr_error_t src_reset(soxr_t p) {return soxr_clear(p);}
|
||||
|
|
|
@ -88,7 +88,7 @@
|
|||
#endif
|
||||
|
||||
#if defined(COMPILER_GCC)
|
||||
# define ALWAYS_INLINE(return_type) return_type __attribute__ ((always_inline))
|
||||
# define ALWAYS_INLINE(return_type) inline return_type __attribute__ ((always_inline))
|
||||
# define NEVER_INLINE(return_type) return_type __attribute__ ((noinline))
|
||||
# define RESTRICT __restrict
|
||||
/*# define VLA_ARRAY_ON_STACK(type__, varname__, size__) type__ varname__[size__]; */
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
/* SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
/* SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
|
||||
* Licence for this file: LGPL v2.1 See LICENCE for details. */
|
||||
|
||||
#define _soxr_simd_aligned_free free
|
||||
#define _soxr_simd_aligned_malloc malloc
|
||||
#define PFFFT_SIMD_DISABLE
|
||||
#include "pffft.c"
|
||||
#include "filter.h"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
/* SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
|
||||
* Licence for this file: LGPL v2.1 See LICENCE for details. */
|
||||
|
||||
#include "pffft.c"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
/* SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
|
||||
* Licence for this file: LGPL v2.1 See LICENCE for details. */
|
||||
|
||||
/* Resample using an interpolated poly-phase FIR with length LEN.*/
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
/* SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
|
||||
* Licence for this file: LGPL v2.1 See LICENCE for details. */
|
||||
|
||||
/* Resample using a non-interpolated poly-phase FIR with length LEN.*/
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
/* SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
|
||||
* Licence for this file: LGPL v2.1 See LICENCE for details. */
|
||||
|
||||
#include <math.h>
|
||||
|
@ -7,35 +7,24 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
#include "filter.h"
|
||||
#include "internal.h"
|
||||
|
||||
#if defined SOXR_LIB
|
||||
#include "internal.h"
|
||||
|
||||
extern struct {
|
||||
void * (* forward_setup)(int);
|
||||
void * (* backward_setup)(int);
|
||||
void (* delete_setup)(void *);
|
||||
void (* forward)(int, void *, sample_t *, sample_t *);
|
||||
void (* oforward)(int, void *, sample_t *, sample_t *);
|
||||
void (* backward)(int, void *, sample_t *, sample_t *);
|
||||
void (* obackward)(int, void *, sample_t *, sample_t *);
|
||||
void (* convolve)(int, void *, sample_t *, sample_t const *);
|
||||
void (* convolve_portion)(int, sample_t *, sample_t const *);
|
||||
int (* multiplier)(void);
|
||||
void (* reorder_back)(int, void *, sample_t *, sample_t *);
|
||||
} RDFT_CB;
|
||||
typedef void (* fn_t)(void);
|
||||
extern fn_t RDFT_CB[11];
|
||||
|
||||
#define rdft_forward_setup (*RDFT_CB.forward_setup)
|
||||
#define rdft_backward_setup (*RDFT_CB.backward_setup)
|
||||
#define rdft_delete_setup (*RDFT_CB.delete_setup)
|
||||
#define rdft_forward (*RDFT_CB.forward)
|
||||
#define rdft_oforward (*RDFT_CB.oforward)
|
||||
#define rdft_backward (*RDFT_CB.backward)
|
||||
#define rdft_obackward (*RDFT_CB.obackward)
|
||||
#define rdft_convolve (*RDFT_CB.convolve)
|
||||
#define rdft_convolve_portion (*RDFT_CB.convolve_portion)
|
||||
#define rdft_multiplier (*RDFT_CB.multiplier)
|
||||
#define rdft_reorder_back (*RDFT_CB.reorder_back)
|
||||
#define rdft_forward_setup (*(void * (*)(int))RDFT_CB[0])
|
||||
#define rdft_backward_setup (*(void * (*)(int))RDFT_CB[1])
|
||||
#define rdft_delete_setup (*(void (*)(void *))RDFT_CB[2])
|
||||
#define rdft_forward (*(void (*)(int, void *, sample_t *, sample_t *))RDFT_CB[3])
|
||||
#define rdft_oforward (*(void (*)(int, void *, sample_t *, sample_t *))RDFT_CB[4])
|
||||
#define rdft_backward (*(void (*)(int, void *, sample_t *, sample_t *))RDFT_CB[5])
|
||||
#define rdft_obackward (*(void (*)(int, void *, sample_t *, sample_t *))RDFT_CB[6])
|
||||
#define rdft_convolve (*(void (*)(int, void *, sample_t *, sample_t const *))RDFT_CB[7])
|
||||
#define rdft_convolve_portion (*(void (*)(int, sample_t *, sample_t const *))RDFT_CB[8])
|
||||
#define rdft_multiplier (*(int (*)(void))RDFT_CB[9])
|
||||
#define rdft_reorder_back (*(void (*)(int, void *, sample_t *, sample_t *))RDFT_CB[10])
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -309,6 +298,7 @@ static void dft_stage_init(
|
|||
{
|
||||
dft_filter_t * f = &p->shared->dft_filter[instance];
|
||||
int num_taps = 0, dft_length = f->dft_length, i;
|
||||
bool f_domain_m = abs(3-M) == 1 && Fs <= 1;
|
||||
|
||||
if (!dft_length) {
|
||||
int k = phase == 50 && lsx_is_power_of_2(L) && Fn == L? L << 1 : 4;
|
||||
|
@ -336,7 +326,7 @@ static void dft_stage_init(
|
|||
if (!f->dft_length) {
|
||||
void * coef_setup = rdft_forward_setup(dft_length);
|
||||
int Lp = lsx_is_power_of_2(L)? L : 1;
|
||||
int Mp = lsx_is_power_of_2(M)? M : 1;
|
||||
int Mp = f_domain_m? M : 1;
|
||||
f->dft_forward_setup = rdft_forward_setup(dft_length / Lp);
|
||||
f->dft_backward_setup = rdft_backward_setup(dft_length / Mp);
|
||||
if (Mp == 1)
|
||||
|
@ -354,9 +344,9 @@ static void dft_stage_init(
|
|||
p->type = dft_stage;
|
||||
p->fn = dft_stage_fn;
|
||||
p->preload = f->post_peak / L;
|
||||
p->at.integer = f->post_peak % L;
|
||||
p->at.integer = f->post_peak % L;
|
||||
p->L = L;
|
||||
p->step.integer = abs(3-M) == 1 && Fs == 1 && 1? -M/2 : M;
|
||||
p->step.integer = f_domain_m? -M/2 : M;
|
||||
p->dft_filter_num = instance;
|
||||
p->block_len = f->dft_length - (f->num_taps - 1);
|
||||
p->phase0 = p->at.integer / p->L;
|
||||
|
@ -379,7 +369,7 @@ typedef struct {
|
|||
#define have_post_stage (postM * postL != 1)
|
||||
|
||||
#define TO_3dB(a) ((1.6e-6*a-7.5e-4)*a+.646)
|
||||
#define LOW_Q_BW0_PC (67 + 5 / 8.)
|
||||
#define LOW_Q_BW0 (1385 / 2048.) /* 0.67625 rounded to be a FP exact. */
|
||||
|
||||
typedef enum {
|
||||
rolloff_none, rolloff_small /* <= 0.01 dB */, rolloff_medium /* <= 0.35 dB */
|
||||
|
@ -395,9 +385,9 @@ static char const * rate_init(
|
|||
double factor, /* Input rate divided by output rate. */
|
||||
double bits, /* Required bit-accuracy (pass + stop) 16|20|28 */
|
||||
double phase, /* Linear/minimum etc. filter phase. 50 */
|
||||
double bw_pc, /* Pass-band % (0dB pt.) to preserve. 91.3|98.4*/
|
||||
double anti_aliasing_pc, /* % bandwidth without aliasing 100 */
|
||||
rolloff_t rolloff, /* Pass-band roll-off small */
|
||||
double passband_end, /* 0dB pt. bandwidth to preserve; nyquist=1 0.913*/
|
||||
double stopband_begin, /* Aliasing/imaging control; > passband_end 1 */
|
||||
rolloff_t rolloff, /* Pass-band roll-off small */
|
||||
bool maintain_3dB_pt, /* true */
|
||||
double multiplier, /* Linear gain to apply during conversion. 1 */
|
||||
|
||||
|
@ -410,24 +400,25 @@ static char const * rate_init(
|
|||
int log2_large_dft_size)
|
||||
{
|
||||
double att = (bits + 1) * linear_to_dB(2.), attArb = att; /* pass + stop */
|
||||
double tbw0 = 1 - bw_pc / 100, Fs_a = 2 - anti_aliasing_pc / 100;
|
||||
double tbw0 = 1 - passband_end, Fs_a = stopband_begin;
|
||||
double arbM = factor, tbw_tighten = 1;
|
||||
int n = 0, i, preL = 1, preM = 1, shift = 0, arbL = 1, postL = 1, postM = 1;
|
||||
bool upsample = false, rational = false, iOpt = !noSmallIntOpt;
|
||||
int mode = rolloff > rolloff_small? factor > 1 || bw_pc > LOW_Q_BW0_PC:
|
||||
int mode = rolloff > rolloff_small? factor > 1 || passband_end > LOW_Q_BW0:
|
||||
(int)ceil(2 + (bits - 17) / 4);
|
||||
stage_t * s;
|
||||
|
||||
assert(factor > 0);
|
||||
assert(!bits || (15 <= bits && bits <= 33));
|
||||
assert(0 <= phase && phase <= 100);
|
||||
assert(53 <= bw_pc && bw_pc <= 100);
|
||||
assert(85 <= anti_aliasing_pc && anti_aliasing_pc <= 100);
|
||||
assert(.53 <= passband_end);
|
||||
assert(stopband_begin <= 1.2);
|
||||
assert(passband_end + .005 < stopband_begin);
|
||||
|
||||
p->factor = factor;
|
||||
if (bits) while (!n++) { /* Determine stages: */
|
||||
int try, L, M, x, maxL = interpolator > 0? 1 : mode? 2048 :
|
||||
(int)ceil(DBL max_coefs_size * 1000. / (U100_l * sizeof(sample_t)));
|
||||
(int)ceil((double)max_coefs_size * 1000. / (U100_l * sizeof(sample_t)));
|
||||
double d, epsilon = 0, frac;
|
||||
upsample = arbM < 1;
|
||||
for (i = (int)(arbM * .5), shift = 0; i >>= 1; arbM *= .5, ++shift);
|
||||
|
@ -545,7 +536,7 @@ static char const * rate_init(
|
|||
arb_stage.shared->poly_fir_coefs = prepare_coefs(
|
||||
coefs, num_coefs, phases, order, multiplier);
|
||||
lsx_debug("fir_len=%i phases=%i coef_interp=%i size=%.3gk",
|
||||
num_coefs, phases, order, DBL coefs_size / 1000.);
|
||||
num_coefs, phases, order, (double)coefs_size / 1000.);
|
||||
free(coefs);
|
||||
}
|
||||
multiplier = 1;
|
||||
|
@ -698,10 +689,10 @@ static char const * rate_create(
|
|||
return rate_init(
|
||||
channel, shared,
|
||||
io_ratio,
|
||||
q_spec->bits,
|
||||
q_spec->phase,
|
||||
q_spec->bw_pc,
|
||||
q_spec->anti_aliasing_pc,
|
||||
q_spec->precision,
|
||||
q_spec->phase_response,
|
||||
q_spec->passband_end,
|
||||
q_spec->stopband_begin,
|
||||
"\1\2\0"[q_spec->flags & 3],
|
||||
!!(q_spec->flags & SOXR_MAINTAIN_3DB_PT),
|
||||
scale,
|
||||
|
@ -718,7 +709,6 @@ static char const * id(void)
|
|||
return RATE_ID;
|
||||
}
|
||||
|
||||
typedef void (* fn_t)(void);
|
||||
fn_t RATE_CB[] = {
|
||||
(fn_t)rate_input,
|
||||
(fn_t)rate_process,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
/* SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
|
||||
* Licence for this file: LGPL v2.1 See LICENCE for details. */
|
||||
|
||||
#define sample_t float
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
/* SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
|
||||
* Licence for this file: LGPL v2.1 See LICENCE for details. */
|
||||
|
||||
#define sample_t float
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
/* SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
|
||||
* Licence for this file: LGPL v2.1 See LICENCE for details. */
|
||||
|
||||
#define sample_t double
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
/* SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
|
||||
* Licence for this file: LGPL v2.1 See LICENCE for details. */
|
||||
|
||||
void ORDERED_CONVOLVE(int n, void * not_used, DFT_FLOAT * a, const DFT_FLOAT * b)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
/* SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
|
||||
* Licence for this file: LGPL v2.1 See LICENCE for details. */
|
||||
|
||||
#if defined DITHER
|
||||
|
@ -11,7 +11,7 @@
|
|||
#define COPY_SEED unsigned long seed = *seed0;
|
||||
#define COPY_SEED1 unsigned long seed1 = seed
|
||||
#define PASS_SEED1 , &seed1
|
||||
#define PASS_SEED0 , seed0
|
||||
#define PASS_SEED , &seed
|
||||
|
||||
#else
|
||||
|
||||
|
@ -22,7 +22,7 @@
|
|||
#define COPY_SEED
|
||||
#define COPY_SEED1
|
||||
#define PASS_SEED1
|
||||
#define PASS_SEED0
|
||||
#define PASS_SEED
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -37,8 +37,8 @@ static void RINT_CLIP(RINT_T * const dest, FLOATX const * const src,
|
|||
for (; i < n; ++i) {
|
||||
double d = src[i] + DITHERING;
|
||||
dest[stride * i] = RINT(d);
|
||||
if (fetestexcept(FE_INVALID)) {
|
||||
feclearexcept(FE_INVALID);
|
||||
if (fe_test_invalid()) {
|
||||
fe_clear_invalid();
|
||||
dest[stride * i] = d > 0? RINT_MAX : -RINT_MAX - 1;
|
||||
++*clips;
|
||||
}
|
||||
|
@ -57,19 +57,19 @@ static size_t LSX_RINT_CLIP(void * * const dest0, FLOATX const * const src,
|
|||
COPY_SEED
|
||||
#if defined FE_INVALID && defined FPU_RINT
|
||||
#define _ dest[i] = RINT(src[i] + DITHERING), ++i,
|
||||
feclearexcept(FE_INVALID);
|
||||
fe_clear_invalid();
|
||||
for (i = 0; i < (n & ~7u);) {
|
||||
COPY_SEED1;
|
||||
DITHER_VARS;
|
||||
_ _ _ _ _ _ _ _ 0;
|
||||
if (fetestexcept(FE_INVALID)) {
|
||||
feclearexcept(FE_INVALID);
|
||||
if (fe_test_invalid()) {
|
||||
fe_clear_invalid();
|
||||
RINT_CLIP(dest, src, 1, i - 8, i, &clips PASS_SEED1);
|
||||
}
|
||||
}
|
||||
RINT_CLIP(dest, src, 1, i, n, &clips PASS_SEED0);
|
||||
RINT_CLIP(dest, src, 1, i, n, &clips PASS_SEED);
|
||||
#else
|
||||
#define _ d = src[i] + DITHERING, dest[i++] = (RINT_T)(d > N - 1? ++clips, (RINT_T)(N - 1) : d < -N? ++clips, (RINT_T)(-N) : RINT(d)),
|
||||
#define _ d = src[i] + DITHERING, dest[i++] = (RINT_T)(d > 0? d+.5 >= N? ++clips, N-1 : d+.5 : d-.5 <= -N-1? ++clips, -N:d-.5),
|
||||
const double N = 1. + RINT_MAX;
|
||||
double d;
|
||||
for (i = 0; i < (n & ~7u);) {
|
||||
|
@ -98,22 +98,22 @@ static size_t LSX_RINT_CLIP_2(void * * dest0, FLOATX const * const * srcs,
|
|||
COPY_SEED
|
||||
#if defined FE_INVALID && defined FPU_RINT
|
||||
#define _ dest[stride * i] = RINT(src[i] + DITHERING), ++i,
|
||||
feclearexcept(FE_INVALID);
|
||||
fe_clear_invalid();
|
||||
for (j = 0; j < stride; ++j, ++dest) {
|
||||
FLOATX const * const src = srcs[j];
|
||||
for (i = 0; i < (n & ~7u);) {
|
||||
COPY_SEED1;
|
||||
DITHER_VARS;
|
||||
_ _ _ _ _ _ _ _ 0;
|
||||
if (fetestexcept(FE_INVALID)) {
|
||||
feclearexcept(FE_INVALID);
|
||||
if (fe_test_invalid()) {
|
||||
fe_clear_invalid();
|
||||
RINT_CLIP(dest, src, stride, i - 8, i, &clips PASS_SEED1);
|
||||
}
|
||||
}
|
||||
RINT_CLIP(dest, src, stride, i, n, &clips PASS_SEED0);
|
||||
RINT_CLIP(dest, src, stride, i, n, &clips PASS_SEED);
|
||||
}
|
||||
#else
|
||||
#define _ d = src[i] + DITHERING, dest[stride * i++] = (RINT_T)(d > N - 1? ++clips, (RINT_T)(N - 1) : d < -N? ++clips, (RINT_T)(-N) : RINT(d)),
|
||||
#define _ d = src[i] + DITHERING, dest[stride * i++] = (RINT_T)(d > 0? d+.5 >= N? ++clips, N-1 : d+.5 : d-.5 <= -N-1? ++clips, -N:d-.5),
|
||||
const double N = 1. + RINT_MAX;
|
||||
double d;
|
||||
for (j = 0; j < stride; ++j, ++dest) {
|
||||
|
@ -134,7 +134,7 @@ static size_t LSX_RINT_CLIP_2(void * * dest0, FLOATX const * const * srcs,
|
|||
}
|
||||
#undef _
|
||||
|
||||
#undef PASS_SEED0
|
||||
#undef PASS_SEED
|
||||
#undef PASS_SEED1
|
||||
#undef COPY_SEED1
|
||||
#undef COPY_SEED
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
/* SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
|
||||
* Licence for this file: LGPL v2.1 See LICENCE for details. */
|
||||
|
||||
#if !defined soxr_rint_included
|
||||
|
@ -26,7 +26,7 @@
|
|||
__asm__ __volatile__ ("ftosid %0, %P1": "=w"(result): "w"(input));
|
||||
return result;
|
||||
}
|
||||
#elif defined _MSC_VER && defined _M_IX86
|
||||
#elif defined _MSC_VER && defined _M_IX86 /* FIXME need solution for MSVC x64 */
|
||||
#define FPU_RINT32
|
||||
static __inline int32_t rint32(double input) {
|
||||
int32_t result;
|
||||
|
@ -49,7 +49,7 @@
|
|||
__asm__ __volatile__("fistps %0": "=m"(result): "t"(input): "st");
|
||||
return result;
|
||||
}
|
||||
#elif defined _MSC_VER && defined _M_IX86
|
||||
#elif defined _MSC_VER && defined _M_IX86 /* FIXME need solution for MSVC x64 */
|
||||
#define FPU_RINT16
|
||||
static __inline int16_t rint16(double input) {
|
||||
int16_t result;
|
||||
|
@ -60,7 +60,7 @@
|
|||
return result;
|
||||
}
|
||||
#else
|
||||
#define rint16(x) (int16_t)floor((x)+.5) /* Is this faster than in rint32? */
|
||||
#define rint16(x) (int16_t)((x) < 0? x - .5 : x + .5)
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
/* SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
|
||||
* Licence for this file: LGPL v2.1 See LICENCE for details. */
|
||||
|
||||
#define PFFT_MACROS_ONLY
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
/* SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
|
||||
* Licence for this file: LGPL v2.1 See LICENCE for details. */
|
||||
|
||||
#include <assert.h>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
/* SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
|
||||
* Licence for this file: LGPL v2.1 See LICENCE for details. */
|
||||
|
||||
#if !defined simd_included
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* SoX Resampler Library Copyright (c) 2007-12 robs@users.sourceforge.net
|
||||
/* SoX Resampler Library Copyright (c) 2007-13 robs@users.sourceforge.net
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
|
@ -15,7 +15,7 @@
|
|||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/* Wrapper mostly compatible with `libsamplerate'.
|
||||
/* Wrapper compatible with `libsamplerate' (constant-rate).
|
||||
* (Libsoxr's native API can be found in soxr.h). */
|
||||
|
||||
#if !defined SAMPLERATE_H
|
||||
|
@ -30,6 +30,8 @@
|
|||
#else
|
||||
#define SOXR __declspec(dllimport)
|
||||
#endif
|
||||
#elif defined SOXR_VISIBILITY && defined __GNUC__ && (__GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ >= 1)
|
||||
#define SOXR __attribute__ ((visibility("default")))
|
||||
#else
|
||||
#define SOXR
|
||||
#endif
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue