Since I (erikd), do almost zero Android development, I am happy accept patches
for this documentation and script to improve its utility for real Android
developers.
+
+---
+
+## Using CMake
+
+(Tested on Linux)
+
+For convenience, export the following variables:
+
+```
+export ANDROID_ABI=arm64-v8a
+export ANDROID_PLATFORM_API_LEVEL=29
+export NDK_ROOT=/path/to/android/ndk
+```
+
+Set `ANDROID_ABI`, `ANDROID_PLATFORM_API_LEVEL` according to your target system. Now cd into the libsndfile root directory, and run
+
+```
+cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=$NDK_ROOT/build/cmake/android.toolchain.cmake -DANDROID_ABI=$ANDROID_ABI -DANDROID_PLATFORM=$ANDROID_PLATFORM_API_LEVEL
+```
+
+cd into `build` and run make
+
+```
+cd build
+make [-j <number of parallel jobs>]
+```
+
+This will build libsndfile for android.
--- /dev/null
+# Changelog
+
+All notable changes to this project will be documented in this file.
+
+The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
+and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
+
+## [Unreleased]
+
+## [1.1.0] - 2022-03-27
+
+### Added
+
+* MPEG Encode/Decode Support.
+
+ Uses libmpg123 for decode, liblame for encode. Encoding and decoding support
+ is independent of each other and is split into separate files. MPEG support
+ is generalized as subformats, `SF_FORMAT_MPEG_LAYER`(I,II,III) so that it
+ might be used by other containers (`MPEG1WAVEFORMAT` for example), but also
+ contains a major format `SF_FORMAT_MPEG` for 'mp3 files.'
+
+ Encoding Status:
+ * Layer III encoding
+ * ID3v1 writing
+ * ID3v2 writing
+ * Lame/Xing Tag writing
+ * Bitrate selection command
+ * VBR or CBR
+
+ Decoding Status:
+ * Layers I/II/III decoding
+ * ID3v1 reading
+ * ID3v2 reading
+ * Seeking
+* New fuzzer for OSS-Fuzz, thanks @DavidKorczynski.
+* This `CHANGELOG.md`. All notable changes to this project will be documented in
+ this file. The old `NEWS` file has been renamed to `NEWS.OLD` and is no longer
+ updated.
+* Add support for decoding MPEG III Audio in WAV files.
+* `SECURITY.md` file to give people instructions for reporting security
+ vulnerabilities, thanks @zidingz.
+* Support for [Vcpkg manifest mode](https://vcpkg.readthedocs.io/en/latest/users/manifests/).
+
+ If you have problems with manifest mode, disable it with `VCPKG_MANIFEST_MODE`
+ switch.
+* [Export CMake targets from the build tree (PR #802)](https://cmake.org/cmake/help/latest/guide/importing-exporting/index.html#exporting-targets-from-the-build-tree)
+* CIFuzz fuzzer, thanks to @AdamKorcz (PR #796)
+
+### Changed
+
+* `SFC_SET_DITHER_ON_READ` and `SFC_SET_DITHER_ON_WRITE` enums comments in
+ public header, thanks @SmiVan (issue #677).
+* `ENABLE_SNDFILE_WINDOWS_PROTOTYPES` define is deprecated and not needed
+ anymore.
+
+ Previously, in order for the [`sf_wchar_open`()](http://libsndfile.github.io/libsndfile/api.html#open)
+ function to become available on the Windows platform, it was required to
+ perform certain actions:
+
+ ```c
+ #include <windows.h>
+ #define ENABLE_SNDFILE_WINDOWS_PROTOTYPES 1
+ #including <sndfile.h>
+ ```
+
+ These steps are no longer required and the `sf_wchar_open`() function is
+ always available on the Windows platform.
+* Use UTF-8 as internal path encoding on Windows platform.
+
+ This is an internal change to unify and simplify the handling of file paths.
+
+ On the Windows platform, the file path is always converted to UTF-8 and
+ converted to UTF-16 only for calls to WinAPI functions.
+
+ The behavior of the functions for opening files on other platforms does not
+ change.
+* Switch to .xz over .bz2 for release tarballs.
+* Disable static builds using Autotools by default. If you want static
+ libraries, pass --enable-static to ./configure
+
+### Fixed
+
+* Typo in `docs/index.md`.
+* Typo in `programs/sndfile-convert.c`, thanks @fjl.
+* Memory leak in `caf_read_header`(), credit to OSS-Fuzz ([issue 30375](https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=30375)).
+* Stack overflow in `guess_file_type`(), thanks @bobsayshilol, credit to
+ OSS-Fuzz ([issue 29339](https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=29339)).
+* Abort in fuzzer, thanks @bobsayshilol, credit to OSS-Fuzz
+ ([issue 26257](https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=26257)).
+* Infinite loop in `svx_read_header`(), thanks @bobsayshilol, credit to OSS-Fuzz
+ ([issue 25442](https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=25442)).
+* GCC and Clang pedantic warnings, thanks @bobsayshilol.
+* Normalisation issue when scaling floating point data to `int` in
+ `replace_read_f2i`(), thanks @bobsayshilol, (issue #702).
+* Missing samples when doing a partial read of Ogg file from index till the end
+ of file, thanks @arthurt (issue #643).
+* sndfile-salvage: Handle files > 4 GB on Windows OS
+* Undefined shift in `dyn_get_32bit`(), credit to OSS-Fuzz
+ ([issue 27366](https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=27366)).
+* Integer overflow in `nms_adpcm_update`(), credit to OSS-Fuzz
+ ([issue 25522](https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=25522)).
+* Integer overflow in `psf_log_printf`(), credit to OSS-Fuzz
+ ([issue 28441](https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=28441)),
+ ([issue 25624](https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=25624)).
+* ABI version incompatibility between Autotools and CMake build on Apple
+ platforms.
+
+ Now ABI must be compatible with Autotools builds. Note that this change
+ requires CMake >= 3.17 for building dylib on Apple platforms.
+
+* Fix build with Autotools + MinGW toolchain on Windows platform.
+
+ See https://github.com/msys2/MINGW-packages/issues/5803 for details.
+
+### Security
+
+* Heap buffer overflow in `wavlike_ima_decode_block`(), thanks @bobsayshilol,
+ credit to OSS-Fuzz ([issue 25530](https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=25530)).
+* Heap buffer overflow in `msadpcm_decode_block`(), thanks @bobsayshilol,
+ credit to OSS-Fuzz ([issue 26803](https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=26803)).
+* Heap buffer overflow in `psf_binheader_readf`(), thanks @bobsayshilol,
+ credit to OSS-Fuzz ([issue 26026](https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=26026)).
+* Index out of bounds in `psf_nms_adpcm_decode_block`(), credit to OSS-Fuzz
+ ([issue 25561](https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=25561)).
+* Heap buffer overflow in `flac_buffer_copy`(), thanks @yuawn, @bobsayshilol.
+* Heap buffer overflow in `copyPredictorTo24`(), thanks @bobsayshilol,
+ credit to OSS-Fuzz ([issue 27503](https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=27503)).
+* Uninitialized variable in `psf_binheader_readf`(), thanks @shao-hua-li,
+ credit to OSS-Fuzz ([issue 25364](https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=25364)).
+
+[Unreleased]: https://github.com/libsndfile/libsndfile/compare/1.1.0...HEAD
+[1.1.0]: https://github.com/libsndfile/libsndfile/compare/1.0.31...1.1.0
endif ()
endif ()
-project(libsndfile VERSION 1.0.31)
+option (ENABLE_EXTERNAL_LIBS "Enable FLAC, Vorbis, and Opus codecs" ON)
+if (ENABLE_EXTERNAL_LIBS)
+ list (APPEND VCPKG_MANIFEST_FEATURES "external-libs")
+endif ()
+
+option (ENABLE_MPEG "Enable MPEG codecs" ON)
+if (ENABLE_MPEG)
+ list (APPEND VCPKG_MANIFEST_FEATURES "mpeg")
+endif ()
+
+option (ENABLE_EXPERIMENTAL "Enable experimental code" OFF)
+if (ENABLE_EXPERIMENTAL)
+ list (APPEND VCPKG_MANIFEST_FEATURES "speex")
+endif ()
+
+option (BUILD_REGTEST "Build regtest" OFF)
+if (BUILD_REGTEST)
+ list (APPEND VCPKG_MANIFEST_FEATURES "regtest")
+endif ()
+
+project(libsndfile VERSION 1.1.0)
#
# Variables
option (BUILD_PROGRAMS "Build programs" ON)
option (BUILD_EXAMPLES "Build examples" ON)
option (ENABLE_CPACK "Enable CPack support" ON)
-option (ENABLE_EXPERIMENTAL "Enable experimental code" OFF)
option (ENABLE_BOW_DOCS "Enable black-on-white html docs" OFF)
if (MSVC AND (DEFINED ENABLE_STATIC_RUNTIME))
option (ENABLE_STATIC_RUNTIME "Enable static runtime" ${ENABLE_STATIC_RUNTIME})
include(SndFileChecks)
+if (ENABLE_EXTERNAL_LIBS AND NOT (Vorbis_FOUND OR FLAC_FOUND OR OPUS_FOUND))
+ set (ENABLE_EXTERNAL_LIBS OFF)
+endif()
+if(ENABLE_MPEG AND (NOT HAVE_MPEG_LIBS))
+ set (ENABLE_MPEG OFF)
+endif()
+if (BUILD_REGTEST AND (NOT SQLITE3_FOUND))
+ set (BUILD_REGTEST OFF)
+endif()
-cmake_dependent_option (BUILD_REGTEST "Build regtest" ON "SQLITE3_FOUND" OFF)
-cmake_dependent_option (ENABLE_EXTERNAL_LIBS "Enable FLAC, Vorbis, and Opus codecs" ON "Vorbis_FOUND;FLAC_FOUND;OPUS_FOUND" OFF)
cmake_dependent_option (ENABLE_CPU_CLIP "Enable tricky cpu specific clipper" ON "CPU_CLIPS_POSITIVE;CPU_CLIPS_NEGATIVE" OFF)
if (NOT ENABLE_CPU_CLIP)
set (CPU_CLIPS_POSITIVE FALSE)
set (HAVE_SNDIO_H ${SNDIO_FOUND})
set (ENABLE_EXPERIMENTAL_CODE ${ENABLE_EXPERIMENTAL})
+set (HAVE_MPEG ${ENABLE_MPEG})
set (HAVE_SPEEX ${ENABLE_EXPERIMENTAL})
-set (HAVE_OPUS ${ENABLE_EXPERIMENTAL})
add_feature_info (BUILD_SHARED_LIBS BUILD_SHARED_LIBS "build shared libraries")
add_feature_info (ENABLE_EXTERNAL_LIBS ENABLE_EXTERNAL_LIBS "enable FLAC, Vorbis, and Opus codecs")
+add_feature_info (ENABLE_MPEG ENABLE_MPEG "enable MPEG audio (including mp3) codecs")
add_feature_info (ENABLE_EXPERIMENTAL ENABLE_EXPERIMENTAL "enable experimental code")
add_feature_info (BUILD_TESTING BUILD_TESTING "build tests")
add_feature_info (BUILD_REGTEST BUILD_REGTEST "build regtest")
DESCRIPTION "Free Lossless Audio Codec Library"
PURPOSE "Enables FLAC support"
)
+set_package_properties (Lame PROPERTIES
+ TYPE RECOMMENDED
+ URL "https://lame.sourceforge.io/"
+ DESCRIPTION "High quality MPEG Audio Layer III (MP3) encoder"
+ PURPOSE "Enables MPEG layer III (MP3) writing support"
+ )
+set_package_properties (MPG123 PROPERTIES
+ TYPE RECOMMENDED
+ URL "https://www.mpg123.de/"
+ DESCRIPTION "MPEG Audio Layer I/II/III decoder"
+ PURPOSE "Enables MPEG Audio reading support"
+ )
set_package_properties(Opus PROPERTIES
TYPE RECOMMENDED
URL "www.opus-codec.org/"
set (EXTERNAL_XIPH_REQUIRE "${EXTERNAL_XIPH_REQUIRE} speex")
endif ()
endif ()
+ if (ENABLE_MPEG)
+ set (EXTERNAL_MPEG_REQUIRE "libmpg123")
+ get_filename_component(LAME_WE ${LAME_LIBRARY} NAME_WE)
+ if (LAME_HIP_LIBRARY)
+ get_filename_component(LAME_HIP_WE ${LAME_HIP_LIBRARY} NAME_WE)
+ endif ()
+ if (CMAKE_IMPORT_LIBRARY_PREFIX)
+ string (REGEX REPLACE "^${CMAKE_IMPORT_LIBRARY_PREFIX}" "" LAME_WE_NO_PREFIX ${LAME_WE})
+ if (LAME_HIP_LIBRARY)
+ string (REGEX REPLACE "^${CMAKE_IMPORT_LIBRARY_PREFIX}" "" LAME_HIP_WE_NO_PREFIX ${LAME_HIP_WE})
+ endif ()
+ endif ()
+ set (EXTERNAL_MPEG_LIBS "-l${LAME_WE_NO_PREFIX}")
+ if (LAME_HIP_LIBRARY)
+ set (EXTERNAL_MPEG_LIBS "${MPEG_LIBS} -l${LAME_HIP_WE}")
+ endif ()
+ endif ()
configure_file (sndfile.pc.in sndfile.pc @ONLY)
src/ogg.c
src/chanmap.h
src/chanmap.c
+ src/id3.h
src/id3.c
$<$<BOOL:${WIN32}>:src/windows.c>
src/sndfile.c
src/ogg_speex.c
src/ogg_pcm.c
src/ogg_opus.c
+ src/ogg_vcomment.h
src/ogg_vcomment.c
src/nms_adpcm.c
+ src/mpeg.c
+ src/mpeg_decode.c
+ src/mpeg_l3_encode.c
src/GSM610/config.h
src/GSM610/gsm.h
src/GSM610/gsm610_priv.h
$<$<BOOL:${HAVE_EXTERNAL_XIPH_LIBS}>:FLAC::FLAC>
$<$<AND:$<BOOL:${ENABLE_EXPERIMENTAL}>,$<BOOL:${HAVE_EXTERNAL_XIPH_LIBS}>,$<BOOL:${HAVE_SPEEX}>>:Speex::Speex>
$<$<BOOL:${HAVE_EXTERNAL_XIPH_LIBS}>:Opus::opus>
+ $<$<BOOL:${HAVE_MPEG}>:MPG123::libmpg123>
+ $<$<BOOL:${HAVE_MPEG}>:Lame::Lame>
)
set_target_properties (sndfile PROPERTIES
PUBLIC_HEADER "${sndfile_HDRS}"
if (BUILD_SHARED_LIBS)
+ #
+ # ABI version of library.
+ #
+
+ #
+ # Read libtool version from `configure.ac` and set libsndfile ABI version:
+ #
+ # SNDFILE_ABI_VERSION_MAJOR
+ # SNDFILE_ABI_VERSION_MINOR
+ # SNDFILE_ABI_VERSION_PATCH
+ # SNDFILE_ABI_VERSION
+ #
+ # and Mach-O current and compatibility versions:
+ #
+ # SNDFILE_MACHO_CURRENT_VERSION
+ # SNDFILE_MACHO_COMPATIBILITY_VERSION
+ #
+
+ include (SetupABIVersions)
+
+ setup_abi_versions()
+
if (WIN32)
set (VERSION_MAJOR ${CPACK_PACKAGE_VERSION_MAJOR})
set (GEN_TOOL cmake)
target_sources (sndfile PRIVATE ${PROJECT_BINARY_DIR}/src/version-metadata.rc)
endif ()
+
set_target_properties (sndfile PROPERTIES
- SOVERSION ${PROJECT_VERSION_MAJOR}
- VERSION ${PROJECT_VERSION}
+ SOVERSION ${SNDFILE_ABI_VERSION_MAJOR}
+ VERSION ${SNDFILE_ABI_VERSION}
)
+ if (APPLE)
+ if (NOT (CMAKE_VERSION VERSION_LESS 3.17))
+ set_target_properties (sndfile PROPERTIES
+ MACHO_CURRENT_VERSION ${SNDFILE_MACHO_CURRENT_VERSION}
+ MACHO_COMPATIBILITY_VERSION ${SNDFILE_MACHO_COMPATIBILITY_VERSION}
+ )
+ else ()
+ message (FATAL_ERROR "Apple platform requires cmake >= 3.17 to build dylib.")
+ endif ()
+ endif ()
+
# Symbol files generation
if (WIN32)
if (DEFINED SYMBOL_OS)
add_custom_command (
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/src/${SYMBOL_FILENAME}
- COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/src/create_symbols_file.py ${SYMBOL_OS} ${PROJECT_VERSION} > ${CMAKE_CURRENT_BINARY_DIR}/src/${SYMBOL_FILENAME}
+ COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/src/create_symbols_file.py ${SYMBOL_OS} ${SNDFILE_ABI_VERSION} > ${CMAKE_CURRENT_BINARY_DIR}/src/${SYMBOL_FILENAME}
COMMENT "Generating ${SYMBOL_FILENAME}..."
)
$<$<BOOL:${LIBM_REQUIRED}>:m>
)
+# generate
+
+ add_executable (generate examples/generate.c)
+ target_link_libraries (generate PRIVATE sndfile)
+
# sndfilehandle
add_executable (sndfilehandle examples/sndfilehandle.cc)
make_sine
sfprocess
list_formats
+ generate
sndfilehandle
)
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
+ export (EXPORT SndFileTargets NAMESPACE SndFile:: FILE ${PROJECT_BINARY_DIR}/SndFileTargets.cmake)
+
include (CMakePackageConfigHelpers)
if (ENABLE_EXTERNAL_LIBS)
set (SndFile_WITH_EXTERNAL_LIBS 0)
endif ()
+ if(ENABLE_MPEG)
+ set (SndFile_WITH_MPEG 1)
+ else ()
+ set (SndFile_WITH_MPEG 0)
+ endif ()
+
set (INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR})
configure_package_config_file(cmake/SndFileConfig.cmake.in SndFileConfig.cmake
+ INSTALL_DESTINATION ${PROJECT_BINARY_DIR}
+ INSTALL_PREFIX ${PROJECT_BINARY_DIR}
+ PATH_VARS INCLUDE_INSTALL_DIR
+ )
+ configure_package_config_file(cmake/SndFileConfig.cmake.in SndFileConfig2.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_PACKAGEDIR}
PATH_VARS INCLUDE_INSTALL_DIR
)
DESTINATION ${CMAKE_INSTALL_PACKAGEDIR}
)
install(
+ FILES ${CMAKE_CURRENT_BINARY_DIR}/SndFileConfig2.cmake
+ RENAME SndFileConfig.cmake
+ DESTINATION ${CMAKE_INSTALL_PACKAGEDIR}
+ )
+ install(
FILES
- ${CMAKE_CURRENT_BINARY_DIR}/SndFileConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/SndFileConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_PACKAGEDIR}
)
$<$<BOOL:${LIBM_REQUIRED}>:m>
)
+ add_executable (mpeg_test tests/mpeg_test.c)
+ target_link_libraries (mpeg_test
+ PRIVATE
+ sndfile
+ test_utils
+ $<$<BOOL:${LIBM_REQUIRED}>:m>
+ )
+
add_executable (stdin_test tests/stdin_test.c)
target_link_libraries (stdin_test
PRIVATE
add_test (lossy_comp_test_ogg_opus lossy_comp_test ogg_opus)
add_test (string_test_opus string_test opus)
+ ### mpeg-tests ###
+ add_test (mpeg_test mpeg_test)
+ add_test (compression_size_test_mpeg compression_size_test mpeg)
+
### io-tests
add_test (stdio_test stdio_test)
add_test (pipe_test pipe_test)
endif ()
if (ENABLE_CPACK)
+ if ((NOT CPACK_PACKAGE_VERSION) AND CPACK_PACKAGE_VERSION_STAGE)
+ set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_FULL}")
+ endif ()
include (CPack)
endif ()
* Patches should always be submitted via a either Github "pull request" or a
via emailed patches created using "git format-patch".
* Patches for new features should include tests and documentation.
+* Commit messages should follow the ["How to Write a Git Commit Message"](https://chris.beams.io/posts/git-commit/) guide:
+ 1. Separate subject from body with a blank line
+ 2. Limit the subject line to 50 characters
+ 3. Capitalize the subject line
+ 4. Do not end the subject line with a period
+ 5. Use the imperative mood in the subject line
+ 6. Wrap the body at 72 characters
+ 7. Use the body to explain what and why vs. how
+
+ Additional rule: the commit message may contain a prefix. The prefix must
+ contain the name of the feature or source file related to the commit and must
+ end with a colon followed by the message body.
+
+ Examples of good commit messages:
+ 1. Fix typo
+ 2. Update CHANGELOG.md
+ 3. Add ACT file format support
+ 4. ogg_vorbis: Fix granule position when seeking Vorbis streams
+
+ Examples of bad commit messages:
+ 1. Fixed bug (rule 5)
+ 2. update docs (rule 3)
+ 3. Add very cool feature. (rule 4)
+
* Patches to fix bugs should either pass all tests, or modify the tests in some
sane way.
* When a new feature is added for a particular file format and that feature
endif
EXTRA_DIST = libsndfile.spec.in sndfile.pc.in Scripts/android-configure.sh \
- Scripts/linux-to-win-cross-configure.sh \
- CMakeLists.txt $(cmake_files) Win32
+ NEWS.OLD CHANGELOG.md Scripts/linux-to-win-cross-configure.sh \
+ CMakeLists.txt $(cmake_files) Win32 SECURITY.md
cmake_files = cmake/ClipMode.cmake cmake/FindFLAC.cmake \
cmake/CMakeAutoGen.cmake cmake/CMakeAutoGenScript.cmake \
cmake/SndFileChecks.cmake cmake/TestInline.cmake \
cmake/TestLargeFiles.cmake cmake/TestInline.c.in \
cmake/FindOpus.cmake cmake/SndFileConfig.cmake.in \
- cmake/CheckCPUArch.cmake cmake/CheckCPUArch.c.in
+ cmake/CheckCPUArch.cmake cmake/CheckCPUArch.c.in \
+ cmake/SetupABIVersions.cmake
pkgconfig_DATA = sndfile.pc
lib_LTLIBRARIES = src/libsndfile.la
include_HEADERS = include/sndfile.hh
nodist_include_HEADERS = include/sndfile.h
-src_libsndfile_la_CFLAGS = $(EXTERNAL_XIPH_CFLAGS)
+src_libsndfile_la_CFLAGS = $(EXTERNAL_XIPH_CFLAGS) $(MPEG_CFLAGS)
# MinGW requires -no-undefined if a DLL is to be built.
src_libsndfile_la_LDFLAGS = -no-undefined -version-info $(SHARED_VERSION_INFO) $(SHLIB_VERSION_ARG)
src_libsndfile_la_SOURCES = src/sndfile.c src/aiff.c src/au.c src/avr.c src/caf.c src/dwd.c src/flac.c src/g72x.c src/htk.c src/ircam.c \
src/macos.c src/mat4.c src/mat5.c src/nist.c src/paf.c src/pvf.c src/raw.c src/rx2.c src/sd2.c \
src/sds.c src/svx.c src/txw.c src/voc.c src/wve.c src/w64.c src/wavlike.c src/wav.c src/xi.c src/mpc2k.c src/rf64.c \
- src/ogg_vorbis.c src/ogg_speex.c src/ogg_pcm.c src/ogg_opus.c src/ogg_vcomment.c \
- src/common.h src/sfconfig.h src/sfendian.h src/wavlike.h src/sf_unistd.h src/ogg.h src/chanmap.h src/ogg_vcomment.h
+ src/ogg.c src/ogg.h src/ogg_vorbis.c src/ogg_speex.c src/ogg_pcm.c src/ogg_opus.c src/ogg_vcomment.c src/ogg_vcomment.h \
+ src/common.h src/sfconfig.h src/sfendian.h src/wavlike.h src/sf_unistd.h src/chanmap.h src/mpeg.c
nodist_src_libsndfile_la_SOURCES = $(nodist_include_HEADERS)
src_libsndfile_la_LIBADD = src/GSM610/libgsm.la src/G72x/libg72x.la src/ALAC/libalac.la \
- src/libcommon.la $(EXTERNAL_XIPH_LIBS) -lm
+ src/libcommon.la $(EXTERNAL_XIPH_LIBS) -lm $(MPEG_LIBS)
EXTRA_src_libsndfile_la_DEPENDENCIES = $(SYMBOL_FILES)
noinst_LTLIBRARIES = src/libcommon.la
-src_libcommon_la_CFLAGS = $(EXTERNAL_XIPH_CFLAGS)
+src_libcommon_la_CFLAGS = $(EXTERNAL_XIPH_CFLAGS) $(MPEG_CFLAGS)
src_libcommon_la_SOURCES = src/common.c src/file_io.c src/command.c src/pcm.c src/ulaw.c src/alaw.c \
src/float32.c src/double64.c src/ima_adpcm.c src/ms_adpcm.c src/gsm610.c src/dwvw.c src/vox_adpcm.c \
src/interleave.c src/strings.c src/dither.c src/cart.c src/broadcast.c src/audio_detect.c \
- src/ima_oki_adpcm.c src/ima_oki_adpcm.h src/alac.c src/chunk.c src/ogg.c src/chanmap.c \
- src/windows.c src/id3.c src/nms_adpcm.c $(WIN_VERSION_FILE)
+ src/ima_oki_adpcm.c src/ima_oki_adpcm.h src/alac.c src/chunk.c src/chanmap.c \
+ src/windows.c src/id3.c src/id3.h src/nms_adpcm.c src/mpeg_decode.c src/mpeg_l3_encode.c src/mpeg.h $(WIN_VERSION_FILE)
check_PROGRAMS = src/test_main
src_test_main_SOURCES = src/test_main.c src/test_main.h src/test_conversions.c src/test_float.c src/test_endswap.c \
SYMBOL_SCRIPT = $(top_srcdir)/src/create_symbols_file.py
src/Symbols.gnu-binutils: $(SYMBOL_SCRIPT)
- $(PYTHON) $(SYMBOL_SCRIPT) linux $(VERSION) > $(top_srcdir)/$@
+ $(PYTHON) $(SYMBOL_SCRIPT) linux $(ABI_VERSION) > $(top_srcdir)/$@
src/Symbols.darwin: $(SYMBOL_SCRIPT)
- $(PYTHON) $(SYMBOL_SCRIPT) darwin $(VERSION) > $(top_srcdir)/$@
+ $(PYTHON) $(SYMBOL_SCRIPT) darwin $(ABI_VERSION) > $(top_srcdir)/$@
src/libsndfile-1.def: $(SYMBOL_SCRIPT)
- $(PYTHON) $(SYMBOL_SCRIPT) win32 $(VERSION) > $(top_srcdir)/$@
+ $(PYTHON) $(SYMBOL_SCRIPT) win32 $(ABI_VERSION) > $(top_srcdir)/$@
src/Symbols.os2: $(SYMBOL_SCRIPT)
- $(PYTHON) $(SYMBOL_SCRIPT) os2 $(VERSION) > $(top_srcdir)/$@
+ $(PYTHON) $(SYMBOL_SCRIPT) os2 $(ABI_VERSION) > $(top_srcdir)/$@
src/Symbols.static: $(SYMBOL_SCRIPT)
- $(PYTHON) $(SYMBOL_SCRIPT) static $(VERSION) > $(top_srcdir)/$@
+ $(PYTHON) $(SYMBOL_SCRIPT) static $(ABI_VERSION) > $(top_srcdir)/$@
#===============================================================================
# Building windows resource files (if needed).
tests/locale_test tests/win32_ordinal_test tests/ogg_test tests/compression_size_test \
tests/checksum_test tests/external_libs_test tests/rdwr_test tests/format_check_test $(CPP_TEST) \
tests/channel_test tests/long_read_write_test tests/stdin_test tests/stdout_test \
- tests/dither_test tests/fix_this tests/largefile_test tests/benchmark tests/ogg_opus_test
+ tests/dither_test tests/fix_this tests/largefile_test tests/benchmark tests/ogg_opus_test \
+ tests/mpeg_test
BUILT_SOURCES += \
tests/write_read_test.c \
tests_checksum_test_SOURCES = tests/checksum_test.c tests/utils.c tests/utils.h
tests_checksum_test_LDADD = src/libsndfile.la
+tests_mpeg_test_SOURCES = tests/mpeg_test.c tests/utils.c tests/utils.h
+tests_mpeg_test_LDADD = src/libsndfile.la
+
# Lite remove start
tests_dwvw_test_SOURCES = tests/dwvw_test.c tests/utils.c tests/utils.h
tests_dwvw_test_LDADD = src/libsndfile.la
if USE_OSSFUZZERS
noinst_PROGRAMS += \
- ossfuzz/sndfile_fuzzer
+ ossfuzz/sndfile_fuzzer \
+ ossfuzz/sndfile_alt_fuzzer
noinst_LTLIBRARIES += \
ossfuzz/libstandaloneengine.la
ossfuzz_sndfile_fuzzer_LDFLAGS = $(AM_LDFLAGS) -static
ossfuzz_sndfile_fuzzer_LDADD = src/libsndfile.la $(FUZZ_LDADD)
+ossfuzz_sndfile_alt_fuzzer_SOURCES = ossfuzz/sndfile_alt_fuzzer.cc
+ossfuzz_sndfile_alt_fuzzer_CXXFLAGS = $(AM_CXXFLAGS) $(FUZZ_FLAG)
+ossfuzz_sndfile_alt_fuzzer_LDFLAGS = $(AM_LDFLAGS) -static
+ossfuzz_sndfile_alt_fuzzer_LDADD = src/libsndfile.la $(FUZZ_LDADD)
+
ossfuzz_libstandaloneengine_la_SOURCES = ossfuzz/standaloneengine.cc ossfuzz/testinput.h
ossfuzz_libstandaloneengine_la_CXXFLAGS = $(AM_CXXFLAGS)
-This is libsndfile, 1.0.29
+This is libsndfile, 1.1.0
libsndfile is a library of C routines for reading and writing
files containing sampled audio data.
## Hacking
The canonical source code repository for libsndfile is at
-[http://libsndfile.github.io/libsndfile/][github].
+<https://github.com/libsndfile/libsndfile>.
You can grab the source code using:
Setting up a build environment for libsndfile on Debian or Ubuntu is as simple as:
sudo apt install autoconf autogen automake build-essential libasound2-dev \
- libflac-dev libogg-dev libtool libvorbis-dev libopus-dev pkg-config python
+ libflac-dev libogg-dev libtool libvorbis-dev libopus-dev libmp3lame-dev \
+ libmpg123-dev pkg-config python
For other Linux distributions or any of the *BSDs, the setup should be similar
although the package install tools and package names may be slightly different.
Similarly on Mac OS X, assuming [brew] is already installed:
- brew install autoconf autogen automake flac libogg libtool libvorbis opus pkg-config
+ brew install autoconf autogen automake flac libogg libtool libvorbis opus mpg123 pkg-config
Once the build environment has been set up, building and testing libsndfile is
as simple as:
`ON` by default. Setting `BUILD_SHARED_LIBS` to `ON` disables this option.
* `ENABLE_EXTERNAL_LIBS` - enable Ogg, Vorbis, FLAC and Opus support. This
option is available and set to `ON` if all dependency libraries were found.
+* `ENABLE_MPEG` - MP3 support. This option is available and set to `ON` if all
+ dependency libraries were found.
* `ENABLE_CPU_CLIP` - enable tricky cpu specific clipper. Enabled and set to
`ON` when CPU clips negative\positive. Don't touch it if you are not sure
* `ENABLE_BOW_DOCS` - enable black-on-white documentation theme, `OFF` by
C/C++ -> Code Generation -> Runtime Library
-Dynamic version of system CRT library is defaut and it means that end user needs
+Dynamic version of system CRT library is default and it means that end user needs
to have the same runtime library installed on his system. Most likely it is so,
but if it is not, the user will see this error message using libsndfile DLL:
Second advice is about Ogg, Vorbis FLAC and Opus support. Searching external
libraries under Windows is a little bit tricky. The best way is to use
-[Vcpkg](https://github.com/Microsoft/vcpkg). You need to install static libogg,
-libvorbis, libflac and libopus libraries:
+[Vcpkg](https://github.com/Microsoft/vcpkg).
- vcpkg install libogg:x64-windows-static libvorbis:x64-windows-static
- libflac:x64-windows-static opus:x64-windows-static libogg:x86-windows-static
- libvorbis:x86-windows-static libflac:x86-windows-static opus:x86-windows-static
-
-Then and add this parameter to cmake command line:
+Install Vcpkg and then add this parameter to cmake command line:
-DCMAKE_TOOLCHAIN_FILE=<path-to-vcpkg>/scripts/buildsystems/vcpkg.cmake
-You also need to set `VCPKG_TARGET_TRIPLET` because you use static libraries:
+You also need to set `VCPKG_TARGET_TRIPLET` if you want to use static libraries:
-DVCPKG_TARGET_TRIPLET=x64-windows-static
+Then you need to install static libogg, libvorbis, libflac, libopus, mpg123 and
+mp3lame Vcpkg packages.
+
+After 1.1.0beta2 you don't need to install dependencies manually. Libsndfile
+now supports [Vcpkg manifest mode](https://vcpkg.readthedocs.io/en/latest/users/manifests/)
+and all dependencies are installed automatically.
+
+However, you can turn off the manifest mode and return to the classic mode using
+the `VCPKG_MANIFEST_MODE` parameter from the command line:
+
+ -DVCPKG_MANIFEST_MODE=OFF
+
+In classic mode, you need to install the required libraries manually:
+
+ vcpkg install libvorbis:x64-windows-static libflac:x64-windows-static
+ opus:x64-windows-static mp3lame:x86-windows-static mpg123:x86-windows-static
+ libvorbis:x86-windows-static libflac:x86-windows-static
+ opus:x86-windows-static mp3lame:x86-windows-static mpg123:x86-windows-static
+
**Note**: Use must use the same CRT library for external libraries and the
libsndfile library itself. For `*-static` triplets Vcpkg uses
[static CRT](https://vcpkg.readthedocs.io/en/latest/users/triplets/).
--- /dev/null
+# Security Policy
+
+## Supported Versions
+
+| Version | Supported |
+| ------- | ------------------ |
+| 1.1.x | :white_check_mark: |
+
+## Reporting a Vulnerability
+
+Please send report privately to evpobry@gmail.com, and include how would you like to be credited.
--- /dev/null
+# - Find lame
+# Find the native lame includes and libraries
+#
+# LAME_INCLUDE_DIRS - where to find lame.h, etc.
+# LAME_LIBRARIES - List of libraries when using lame.
+# LAME_FOUND - True if Lame found.
+
+if (LAME_INCLUDE_DIR)
+ # Already in cache, be silent
+ set(LAME_FIND_QUIETLY TRUE)
+endif ()
+
+find_path (LAME_INCLUDE_DIR lame/lame.h
+ HINTS
+ ${LAME_ROOT}
+ )
+
+# MSVC built lame may be named mp3lame_static.
+# The provided project files name the library with the lib prefix.
+
+find_library (LAME_LIBRARY
+ NAMES
+ mp3lame
+ mp3lame_static
+ libmp3lame
+ libmp3lame_static
+ libmp3lame-static
+ HINTS
+ ${LAME_ROOT}
+ )
+
+find_library (LAME_HIP_LIBRARY
+ NAMES
+ mpghip-static
+ libmpghip-static
+ HINTS
+ ${LAME_ROOT}
+ )
+
+# Handle the QUIETLY and REQUIRED arguments and set LAME_FOUND
+# to TRUE if all listed variables are TRUE.
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args (Lame
+ REQUIRED_VARS
+ LAME_LIBRARY
+ LAME_INCLUDE_DIR
+ )
+
+if (LAME_FOUND)
+ set (LAME_LIBRARIES ${LAME_LIBRARY} ${LAME_HIP_LIBRARY})
+ set (LAME_INCLUDE_DIRS ${LAME_INCLUDE_DIR})
+
+ if (NOT TARGET Lame::Lame)
+ add_library (Lame::Lame UNKNOWN IMPORTED)
+ set_target_properties (Lame::Lame PROPERTIES
+ INTERFACE_INCLUDE_DIRECTORIES "${LAME_INCLUDE_DIRS}"
+ IMPORTED_LOCATION "${LAME_LIBRARY}"
+ )
+ if (LAME_HIP_LIBRARY)
+ set_property (TARGET Lame::Lame APPEND PROPERTY
+ INTERFACE_LINK_LIBRARIES "${LAME_HIP_LIBRARY}")
+ endif ()
+ endif ()
+endif ()
+
+mark_as_advanced(LAME_INCLUDE_DIR LAME_LIBRARY LAME_HIP_LIBRARY)
--- /dev/null
+# - Find mpg123
+# Find the native mpg123 includes and libraries
+#
+# MPG123_INCLUDE_DIRS - where to find mpg123.h, etc.
+# MPG123_LIBRARIES - List of libraries when using mpg123.
+# MPG123_FOUND - True if Mpg123 found.
+
+if (MPG123_INCLUDE_DIR)
+ # Already in cache, be silent
+ set(MPG123_FIND_QUIETLY TRUE)
+endif ()
+
+find_package (PkgConfig QUIET)
+pkg_check_modules(PC_MPG123 QUIET libmpg123>=1.25.10)
+
+set (MPG123_VERSION ${PC_MPG123_VERSION})
+
+find_path (MPG123_INCLUDE_DIR mpg123.h
+ HINTS
+ ${PC_MPG123_INCLUDEDIR}
+ ${PC_MPG123_INCLUDE_DIRS}
+ ${MPG123_ROOT}
+ )
+
+# MSVC built mpg123 may be named mpg123_static.
+# The provided project files name the library with the lib prefix.
+
+find_library (MPG123_LIBRARY
+ NAMES
+ mpg123
+ mpg123_static
+ libmpg123
+ libmpg123_static
+ HINTS
+ ${PC_MPG123_LIBDIR}
+ ${PC_MPG123_LIBRARY_DIRS}
+ ${MPG123_ROOT}
+ )
+
+# Handle the QUIETLY and REQUIRED arguments and set MPG123_FOUND
+# to TRUE if all listed variables are TRUE.
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args (Mpg123
+ REQUIRED_VARS
+ MPG123_LIBRARY
+ MPG123_INCLUDE_DIR
+ VERSION_VAR
+ MPG123_VERSION
+ )
+
+if (MPG123_FOUND)
+ set (MPG123_LIBRARIES ${MPG123_LIBRARY})
+ set (MPG123_INCLUDE_DIRS ${MPG123_INCLUDE_DIR})
+
+ if (NOT TARGET MPG123::libmpg123)
+ add_library (MPG123::libmpg123 UNKNOWN IMPORTED)
+ set_target_properties (MPG123::libmpg123 PROPERTIES
+ INTERFACE_INCLUDE_DIRECTORIES "${MPG123_INCLUDE_DIRS}"
+ IMPORTED_LOCATION "${MPG123_LIBRARIES}"
+ )
+ endif ()
+endif ()
+
+mark_as_advanced(MPG123_INCLUDE_DIR MPG123_LIBRARY)
--- /dev/null
+# Inspiration: https://github.com/ros2-dotnet/Fast-RTPS
+
+macro (SETUP_ABI_VERSIONS)
+
+ file (STRINGS ${PROJECT_SOURCE_DIR}/configure.ac CONFIGURE_AC_CONTENT)
+ file (STRINGS
+ configure.ac
+ SNDFILE_LT_CURRENT_TMP
+ REGEX "^m4_define\\(\\[?lt_current\\]?, *\\[?[0-9]+\\]?\\)"
+ )
+ string (REGEX REPLACE "m4_define\\(\\[?lt_current\\]?, *\\[?([0-9]+)\\]?\\)"
+ "\\1"
+ SNDFILE_LT_CURRENT
+ ${SNDFILE_LT_CURRENT_TMP}
+ )
+
+ file (STRINGS
+ configure.ac
+ SNDFILE_LT_REVISION_TMP
+ REGEX "^m4_define\\(\\[?lt_revision\\]?, *\\[?[0-9]+\\]?\\)"
+ )
+ string (REGEX REPLACE "m4_define\\(\\[?lt_revision\\]?, *\\[?([0-9]+)\\]?\\)"
+ "\\1"
+ SNDFILE_LT_REVISION
+ ${SNDFILE_LT_REVISION_TMP}
+ )
+
+ file (STRINGS
+ configure.ac
+ SNDFILE_LT_AGE_TMP
+ REGEX "^m4_define\\(\\[?lt_age\\]?, *\\[?[0-9]+\\]?\\)"
+ )
+ string (REGEX REPLACE "m4_define\\(\\[?lt_age\\]?, *\\[?([0-9]+)\\]?\\)"
+ "\\1"
+ SNDFILE_LT_AGE
+ ${SNDFILE_LT_AGE_TMP}
+ )
+
+ #
+ # Calculate CMake compatible ABI version from libtool version.
+ #
+
+ math (EXPR SNDFILE_ABI_VERSION_MAJOR "${SNDFILE_LT_CURRENT} - ${SNDFILE_LT_AGE}")
+ set (SNDFILE_ABI_VERSION_MINOR ${SNDFILE_LT_AGE})
+ set (SNDFILE_ABI_VERSION_PATCH ${SNDFILE_LT_REVISION})
+ set (SNDFILE_ABI_VERSION "${SNDFILE_ABI_VERSION_MAJOR}.${SNDFILE_ABI_VERSION_MINOR}.${SNDFILE_ABI_VERSION_PATCH}")
+
+ #
+ # Apple platform current and compatibility versions.
+ #
+
+ math (EXPR SNDFILE_MACHO_CURRENT_VERSION_MAJOR "${SNDFILE_ABI_VERSION_MAJOR} + ${SNDFILE_ABI_VERSION_MINOR} + 1")
+ set (SNDFILE_MACHO_CURRENT_VERSION "${SNDFILE_MACHO_CURRENT_VERSION_MAJOR}.${SNDFILE_ABI_VERSION_PATCH}.0")
+ set (SNDFILE_MACHO_COMPATIBILITY_VERSION "${SNDFILE_MACHO_CURRENT_VERSION_MAJOR}.0.0")
+
+endmacro (SETUP_ABI_VERSIONS)
set (HAVE_EXTERNAL_XIPH_LIBS 0)
endif ()
+find_package (Lame)
+find_package (Mpg123 1.25.10)
+if (LAME_FOUND AND (TARGET MPG123::libmpg123))
+ set (HAVE_MPEG_LIBS 1)
+else ()
+ set (HAVE_MPEG_LIBS 0)
+endif()
+
find_package (Speex)
find_package (SQLite3)
check_include_file (sys/types.h HAVE_SYS_TYPES_H)
check_include_file (unistd.h HAVE_UNISTD_H)
check_include_file (immintrin.h HAVE_IMMINTRIN_H)
+check_include_file (stdbool.h HAVE_STDBOOL_H)
check_cpu_arch_x86 (CPU_IS_X86)
check_cpu_arch_x64 (CPU_IS_X64)
set(SndFile_VERSION_PATCH @PROJECT_VERSION_PATCH@)
set (SndFile_WITH_EXTERNAL_LIBS @SndFile_WITH_EXTERNAL_LIBS@)
+set (SndFile_WITH_MPEG @SndFile_WITH_MPEG@)
@PACKAGE_INIT@
find_dependency (Opus)
endif ()
+if (SndFile_WITH_MPEG AND NOT @BUILD_SHARED_LIBS@)
+ find_dependency (Lame)
+ find_dependency (MPG123)
+endif ()
+
include (${CMAKE_CURRENT_LIST_DIR}/SndFileTargets.cmake)
set_and_check (SndFile_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@")
-dnl Copyright (C) 1999-2021 Erik de Castro Lopo <erikd@mega-nerd.com>.
+dnl Copyright (C) 1999-2022 Erik de Castro Lopo <erikd@mega-nerd.com>.
dnl Require autoconf version >= 2.69
AC_PREREQ([2.69])
-AC_INIT([libsndfile],[1.0.31],[sndfile@mega-nerd.com],
+AC_INIT([libsndfile],[1.1.0],[sndfile@mega-nerd.com],
[libsndfile],[http://libsndfile.github.io/libsndfile/])
dnl Check whether we want to set defaults for CFLAGS, CXXFLAGS, CPPFLAGS and LDFLAGS
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_HEADERS([src/config.h])
-AM_INIT_AUTOMAKE([1.14 foreign dist-bzip2 no-dist-gzip serial-tests subdir-objects])
+AM_INIT_AUTOMAKE([1.14 foreign dist-xz no-dist-gzip serial-tests subdir-objects])
AM_SILENT_RULES([yes])
dnl ====================================================================================
AC_PROG_SED
AM_PROG_AR
-LT_INIT([win32-dll])
+LT_INIT([disable-static win32-dll])
LT_PROG_RC
AC_PROG_INSTALL
dnl age.
dnl 6. If any interfaces have been removed since the last public release, then set age
dnl to 0.
-SHARED_VERSION_INFO="1:31:0"
-dnl ------------------------------------------------------------------------------------
+dnl This is libtool version of library, we add it to `--version-info` property.
+
+m4_define([lt_current], [1])
+m4_define([lt_revision], [34])
+m4_define([lt_age], [0])
+
+dnl This is ABI version for linker scripts, CMake uses the same format for
+dnl VERSION property of shared library.
+dnl The formula is: c:r:a -> c-a:a:r
+
+m4_define([abi_version_major], [m4_eval(lt_current - lt_age)])
+m4_define([abi_version_minor], [lt_age])
+m4_define([abi_version_patch], [lt_revision])
-AC_HEADER_STDC
+dnl ------------------------------------------------------------------------------------
AC_CHECK_HEADERS([endian.h])
AC_CHECK_HEADERS([byteswap.h])
AC_CHECK_HEADERS([locale.h])
AC_CHECK_HEADERS([sys/time.h])
AC_CHECK_HEADERS([immintrin.h])
+AC_CHECK_HEADERS([stdbool.h])
AC_HEADER_SYS_WAIT
AC_ARG_ENABLE([werror],
[AS_HELP_STRING([--enable-werror], [enable -Werror in all Makefiles])])
-AC_ARG_ENABLE([stack-smash-protection],
- [AS_HELP_STRING([--enable-stack-smash-protection], [Enable GNU GCC stack smash protection])])
-
AC_ARG_ENABLE([cpu-clip],
[AS_HELP_STRING([--disable-cpu-clip], [disable tricky cpu specific clipper])])
AC_ARG_ENABLE([external-libs],
[AS_HELP_STRING([--disable-external-libs], [disable use of FLAC, Ogg and Vorbis [[default=no]]])])
+AC_ARG_ENABLE([mpeg],
+ [AS_HELP_STRING([--disable-mpeg], [disable use of LAME/MPG123 for MPEG (MP3) [[defaults=no]]])])
+
AC_ARG_ENABLE(octave,
[AS_HELP_STRING([--enable-octave], [enable building of GNU Octave module])])
fi
], [
AS_ECHO([""])
- AC_MSG_WARN([[*** One or more of the external libraries (ie libflac, libogg and]])
- AC_MSG_WARN([[*** libvorbis) is either missing (possibly only the development]])
+ AC_MSG_WARN([[*** One or more of the external libraries (ie libflac, libogg,]])
+ AC_MSG_WARN([[*** libvorbis and libopus) is either missing (possibly only the development]])
AC_MSG_WARN([[*** headers) or is of an unsupported version.]])
AC_MSG_WARN([[***]])
AC_MSG_WARN([[*** Unfortunately, for ease of maintenance, the external libs]])
AC_DEFINE_UNQUOTED([HAVE_EXTERNAL_XIPH_LIBS], [$HAVE_EXTERNAL_XIPH_LIBS], [Will be set to 1 if flac, ogg, vorbis, and opus are available.])
dnl ====================================================================================
+dnl Check for MPEG libraris liblame
+
+ac_cv_lame="no"
+ac_cv_mpg123="no"
+HAVE_MPEG=0
+EXTERNAL_MPEG_REQUIRE=""
+EXTERNAL_MPEG_LIBS=""
+
+AS_IF([test -n "$PKG_CONFIG"], [
+ AS_IF([test "x$enable_mpeg" = "xno"], [
+ AC_MSG_WARN([[*** MPEG (Lame/MPG123) disabled. ***]])
+ ], [
+ AC_CHECK_HEADER(lame/lame.h,
+ lame_header_found="yes",
+ lame_header_found="no")
+ AC_SEARCH_LIBS(lame_set_VBR_q, [lame mp3lame], [lame_lib_found="yes"], [lame_lib_found="no"])
+ AS_IF([test "x$lame_lib_found$lame_header_found" = "xyesyes"], [
+ ac_cv_lame="yes"
+ ], [
+ AC_MSG_WARN([["MPEG support selected but external Lame library cannot be found.]])
+ ])
+
+ PKG_CHECK_MOD_VERSION([MPG123], [libmpg123 >= 1.25.10], [
+ ac_cv_mpg123="yes"
+ ], [
+ AC_MSG_WARN([["MPEG support selected but external MPG123 library cannot be found.]])
+ ])
+
+ AS_IF([test "x$ac_cv_lame$ac_cv_mpg123" = "xyesyes"], [
+ enable_mpeg="yes"
+ HAVE_MPEG=1
+ EXTERNAL_MPEG_REQUIRE="libmpg123"
+ EXTERNAL_MPEG_LIBS="-lmp3lame"
+ MPEG_CFLAGS="$MPG123_CFLAGS"
+ MPEG_LIBS="$MPG123_LIBS"
+ ], [
+ enable_mpeg="no"
+ AS_ECHO([""])
+ AC_MSG_WARN([[*** MPEG support disabled.]])
+ AS_ECHO([""])
+ ])
+ ])
+ ])
+
+AC_DEFINE_UNQUOTED([HAVE_MPEG], [$HAVE_MPEG], [Will be set to 1 if lame, mpg123 mpeg support is available.])
+
+dnl ====================================================================================
dnl Check for libsqlite3 (only used in regtest).
ac_cv_sqlite3=0
AC_LANG_POP([C++])
])
-common_flags="-Wall -Wextra -Wpointer-arith -Wcast-align -Wcast-qual -Wshadow -Wwrite-strings -Wundef -Wuninitialized -Winit-self -Wno-format-truncation"
-AX_APPEND_COMPILE_FLAGS([${common_flags} -Wvla -Wbad-function-cast -Wnested-externs -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Waggregate-return], [CFLAGS])
+common_flags="-Wall -Wextra -Wpointer-arith -Wcast-align -Wcast-qual -Wshadow -Wwrite-strings -Wundef -Wuninitialized -Winit-self"
+common_cflags="${common_flags}"
+dnl Clang doesn't know about -Wno-format-truncation
+dnl and would spew tons of warnings otherwise.
+AS_IF([test "x$ax_cv_c_compiler_vendor" = "xgnu"], [
+ common_cflags+=" -Wno-format-truncation"
+ ])
+common_cxxflags="${common_flags}"
+AS_IF([test "x$ax_cv_cxx_compiler_vendor" = "xgnu"], [
+ common_cxxflags+=" -Wno-format-truncation"
+ ])
+
+AX_APPEND_COMPILE_FLAGS([${common_cflags} -Wvla -Wbad-function-cast -Wnested-externs -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Waggregate-return], [CFLAGS])
AC_LANG_PUSH([C++])
-AX_APPEND_COMPILE_FLAGS([${common_flags} -Wctor-dtor-privacy -Wnon-virtual-dtor -Woverloaded-virtual -Wreorder -Wsign-promo], [CXXFLAGS])
+AX_APPEND_COMPILE_FLAGS([${common_cxxflags} -Wctor-dtor-privacy -Wnon-virtual-dtor -Woverloaded-virtual -Wreorder -Wsign-promo], [CXXFLAGS])
AC_LANG_POP([C++])
-AS_IF([test "x$enable_stack_smash_protection" = "xyes"], [
- XIPH_GCC_STACK_PROTECTOR
- XIPH_GXX_STACK_PROTECTOR
- ])
-
AS_IF([test "x$enable_test_coverage" = "xyes"], [
AX_APPEND_COMPILE_FLAGS([-coverage], [CFLAGS])
])
OS_SPECIFIC_LINKS=" -static-libgcc $OS_SPECIFIC_LINKS"
])
-WIN_RC_VERSION=`echo $PACKAGE_VERSION | $SED -e "s/p.*//" -e "s/\./,/g"`
+WIN_RC_VERSION=`echo $PACKAGE_VERSION | $SED -e "s/pre.*//" -e "s/beta.*//" -e "s/\./,/g"`
AS_IF([test "x$enable_static" = "xno"], [
AC_SUBST(HTML_FGCOLOUR)
AC_SUBST(SHLIB_VERSION_ARG)
-AC_SUBST(SHARED_VERSION_INFO)
+AC_SUBST([SHARED_VERSION_INFO], [lt_current:lt_revision:lt_age])
+AC_SUBST([ABI_VERSION], [abi_version_major.abi_version_minor.abi_version_patch])
AC_SUBST(CLEAN_VERSION)
AC_SUBST(VERSION_MAJOR)
AC_SUBST(GEN_TOOL)
AC_SUBST(WIN_RC_VERSION)
AC_SUBST(HAVE_EXTERNAL_XIPH_LIBS)
+AC_SUBST(HAVE_MPEG)
AC_SUBST(OS_SPECIFIC_CFLAGS)
AC_SUBST(OS_SPECIFIC_LINKS)
AC_SUBST(SNDIO_LIBS)
AC_SUBST(EXTERNAL_XIPH_CFLAGS)
AC_SUBST(EXTERNAL_XIPH_LIBS)
AC_SUBST(EXTERNAL_XIPH_REQUIRE)
+AC_SUBST(EXTERNAL_MPEG_REQUIRE)
+AC_SUBST(MPG123_CFLAGS)
+AC_SUBST(MPG123_LIBS)
+AC_SUBST(MPEG_CFLAGS)
+AC_SUBST(MPEG_LIBS)
AC_SUBST(SRC_BINDIR)
AC_SUBST(TEST_BINDIR)
Experimental code : ................... ${enable_experimental:-no}
Using ALSA in example programs : ...... ${enable_alsa:-no}
External FLAC/Ogg/Vorbis/Opus : ....... ${enable_external_libs:-no}
+ External MPEG Lame/MPG123 : ........... ${enable_mpeg:-no}
Building Octave interface : ........... ${OCTAVE_BUILD}
Tools :
CXX Compiler Vendor is : .............. ${ax_cv_cxx_compiler_vendor} (${ax_cv_cxx_compiler_version})
Sanitizer enabled : ................... ${enable_sanitizer:-no}
- Stack smash protection : .............. ${enable_stack_smash_protection:-no}
Installation directories :
## Q20 : Why doesn't libsndfile support MP3? {#Q020}
-In the past, MP3 was not supported because the technology behind MP3 was
+~~In the past, MP3 was not supported because the technology behind MP3 was
patented. Those patents have now expired and there is an
[open ticket](https://github.com/libsndfile/libsndfile/issues/258) to implement
-MP3 support.
+MP3 support.~~
+
+**Update :** Starting from version 1.1.0 libsndfile supports MP3 format.
## Q21 : How do I use libsndfile in a closed source or commercial program and comply with the license? {#Q021}
---
author: "The libsndfile team"
-version: "1.0.31"
+version: "1.1.0"
markdown: kramdown
plugins:
<a href="#history">History</a> -+-
<a href="#features">Features</a> -+-
<a href="#similar-or-related-projects">Similar or related projects</a> -+-
- <a href="https://github.com/libsndfile/libsndfile/blob/master/NEWS">News</a>
+ <a href="https://github.com/libsndfile/libsndfile/blob/master/CHANGELOG.md">News</a>
<br>
<a href="development.html">Development</a> -+-
<a href="api.html">Programming interface</a> -+-
the caller has to set the **samplerate**, **channels** and **format** fields to
valid values. All other fields of the structure are filled in by the library.
+**Note:** The libsndfile library will reject values ​​for **samplerate** field
+that are greater than `655350` and values ​​for field **channels** that are
+greater than `1024`. These values ​​represent the maximum theoretical limit and
+may be less for specific formats.
+
When opening a file for write, the caller must fill in structure members
**samplerate**, **channels**, and **format**.
also include bitmasks for separating major and minor file types. Not all
combinations of endian-ness and major and minor file types are valid.
-| Name | Value | Description |
-|:-----------------------|:-----------|:-------------------------------------------|
-| **Major formats.** |
-| SF_FORMAT_WAV | 0x010000 | Microsoft WAV format (little endian). |
-| SF_FORMAT_AIFF | 0x020000 | Apple/SGI AIFF format (big endian). |
-| SF_FORMAT_AU | 0x030000 | Sun/NeXT AU format (big endian). |
-| SF_FORMAT_RAW | 0x040000 | RAW PCM data. |
-| SF_FORMAT_PAF | 0x050000 | Ensoniq PARIS file format. |
-| SF_FORMAT_SVX | 0x060000 | Amiga IFF / SVX8 / SV16 format. |
-| SF_FORMAT_NIST | 0x070000 | Sphere NIST format. |
-| SF_FORMAT_VOC | 0x080000 | VOC files. |
-| SF_FORMAT_IRCAM | 0x0A0000 | Berkeley/IRCAM/CARL |
-| SF_FORMAT_W64 | 0x0B0000 | Sonic Foundry's 64 bit RIFF/WAV |
-| SF_FORMAT_MAT4 | 0x0C0000 | Matlab (tm) V4.2 / GNU Octave 2.0 |
-| SF_FORMAT_MAT5 | 0x0D0000 | Matlab (tm) V5.0 / GNU Octave 2.1 |
-| SF_FORMAT_PVF | 0x0E0000 | Portable Voice Format |
-| SF_FORMAT_XI | 0x0F0000 | Fasttracker 2 Extended Instrument |
-| SF_FORMAT_HTK | 0x100000 | HMM Tool Kit format |
-| SF_FORMAT_SDS | 0x110000 | Midi Sample Dump Standard |
-| SF_FORMAT_AVR | 0x120000 | Audio Visual Research |
-| SF_FORMAT_WAVEX | 0x130000 | MS WAVE with WAVEFORMATEX |
-| SF_FORMAT_SD2 | 0x160000 | Sound Designer 2 |
-| SF_FORMAT_FLAC | 0x170000 | FLAC lossless file format |
-| SF_FORMAT_CAF | 0x180000 | Core Audio File format |
-| SF_FORMAT_WVE | 0x190000 | Psion WVE format |
-| SF_FORMAT_OGG | 0x200000 | Xiph OGG container |
-| SF_FORMAT_MPC2K | 0x210000 | Akai MPC 2000 sampler |
-| SF_FORMAT_RF64 | 0x220000 | RF64 WAV file |
-| **Subtypes.** |
-| SF_FORMAT_PCM_S8 | 0x0001 | Signed 8 bit data |
-| SF_FORMAT_PCM_16 | 0x0002 | Signed 16 bit data |
-| SF_FORMAT_PCM_24 | 0x0003 | Signed 24 bit data |
-| SF_FORMAT_PCM_32 | 0x0004 | Signed 32 bit data |
-| SF_FORMAT_PCM_U8 | 0x0005 | Unsigned 8 bit data (WAV and RAW only) |
-| SF_FORMAT_FLOAT | 0x0006 | 32 bit float data |
-| SF_FORMAT_DOUBLE | 0x0007 | 64 bit float data |
-| SF_FORMAT_ULAW | 0x0010 | U-Law encoded. |
-| SF_FORMAT_ALAW | 0x0011 | A-Law encoded. |
-| SF_FORMAT_IMA_ADPCM | 0x0012 | IMA ADPCM. |
-| SF_FORMAT_MS_ADPCM | 0x0013 | Microsoft ADPCM. |
-| SF_FORMAT_GSM610 | 0x0020 | GSM 6.10 encoding. |
-| SF_FORMAT_VOX_ADPCM | 0x0021 | OKI / Dialogix ADPCM |
-| SF_FORMAT_NMS_ADPCM_16 | 0x0022 | 16kbs NMS G721-variant encoding. |
-| SF_FORMAT_NMS_ADPCM_24 | 0x0023 | 24kbs NMS G721-variant encoding. |
-| SF_FORMAT_NMS_ADPCM_32 | 0x0024 | 32kbs NMS G721-variant encoding. |
-| SF_FORMAT_G721_32 | 0x0030 | 32kbs G721 ADPCM encoding. |
-| SF_FORMAT_G723_24 | 0x0031 | 24kbs G723 ADPCM encoding. |
-| SF_FORMAT_G723_40 | 0x0032 | 40kbs G723 ADPCM encoding. |
-| SF_FORMAT_DWVW_12 | 0x0040 | 12 bit Delta Width Variable Word encoding. |
-| SF_FORMAT_DWVW_16 | 0x0041 | 16 bit Delta Width Variable Word encoding. |
-| SF_FORMAT_DWVW_24 | 0x0042 | 24 bit Delta Width Variable Word encoding. |
-| SF_FORMAT_DWVW_N | 0x0043 | N bit Delta Width Variable Word encoding. |
-| SF_FORMAT_DPCM_8 | 0x0050 | 8 bit differential PCM (XI only) |
-| SF_FORMAT_DPCM_16 | 0x0051 | 16 bit differential PCM (XI only) |
-| SF_FORMAT_VORBIS | 0x0060 | Xiph Vorbis encoding. |
-| SF_FORMAT_OPUS | 0x0064 | Xiph/Skype Opus encoding. |
-| SF_FORMAT_ALAC_16 | 0x0070 | Apple Lossless Audio Codec (16 bit). |
-| SF_FORMAT_ALAC_20 | 0x0071 | Apple Lossless Audio Codec (20 bit). |
-| SF_FORMAT_ALAC_24 | 0x0072 | Apple Lossless Audio Codec (24 bit). |
-| SF_FORMAT_ALAC_32 | 0x0073 | Apple Lossless Audio Codec (32 bit). |
-| **Endian-ness options.** |
-| SF_ENDIAN_FILE | 0x00000000 | Default file endian-ness. |
-| SF_ENDIAN_LITTLE | 0x10000000 | Force little endian-ness. |
-| SF_ENDIAN_BIG | 0x20000000 | Force big endian-ness. |
-| SF_ENDIAN_CPU | 0x30000000 | Force CPU endian-ness. |
-| SF_FORMAT_SUBMASK | 0x0000FFFF | |
-| SF_FORMAT_TYPEMASK | 0x0FFF0000 | |
-| SF_FORMAT_ENDMASK | 0x30000000 | |
+| Name | Value | Description |
+|:-------------------------|:-----------|:-------------------------------------------|
+| **Major formats.** |
+| SF_FORMAT_WAV | 0x010000 | Microsoft WAV format (little endian). |
+| SF_FORMAT_AIFF | 0x020000 | Apple/SGI AIFF format (big endian). |
+| SF_FORMAT_AU | 0x030000 | Sun/NeXT AU format (big endian). |
+| SF_FORMAT_RAW | 0x040000 | RAW PCM data. |
+| SF_FORMAT_PAF | 0x050000 | Ensoniq PARIS file format. |
+| SF_FORMAT_SVX | 0x060000 | Amiga IFF / SVX8 / SV16 format. |
+| SF_FORMAT_NIST | 0x070000 | Sphere NIST format. |
+| SF_FORMAT_VOC | 0x080000 | VOC files. |
+| SF_FORMAT_IRCAM | 0x0A0000 | Berkeley/IRCAM/CARL |
+| SF_FORMAT_W64 | 0x0B0000 | Sonic Foundry's 64 bit RIFF/WAV |
+| SF_FORMAT_MAT4 | 0x0C0000 | Matlab (tm) V4.2 / GNU Octave 2.0 |
+| SF_FORMAT_MAT5 | 0x0D0000 | Matlab (tm) V5.0 / GNU Octave 2.1 |
+| SF_FORMAT_PVF | 0x0E0000 | Portable Voice Format |
+| SF_FORMAT_XI | 0x0F0000 | Fasttracker 2 Extended Instrument |
+| SF_FORMAT_HTK | 0x100000 | HMM Tool Kit format |
+| SF_FORMAT_SDS | 0x110000 | Midi Sample Dump Standard |
+| SF_FORMAT_AVR | 0x120000 | Audio Visual Research |
+| SF_FORMAT_WAVEX | 0x130000 | MS WAVE with WAVEFORMATEX |
+| SF_FORMAT_SD2 | 0x160000 | Sound Designer 2 |
+| SF_FORMAT_FLAC | 0x170000 | FLAC lossless file format |
+| SF_FORMAT_CAF | 0x180000 | Core Audio File format |
+| SF_FORMAT_WVE | 0x190000 | Psion WVE format |
+| SF_FORMAT_OGG | 0x200000 | Xiph OGG container |
+| SF_FORMAT_MPC2K | 0x210000 | Akai MPC 2000 sampler |
+| SF_FORMAT_RF64 | 0x220000 | RF64 WAV file |
+| SF_FORMAT_MPEG | 0x230000 | MPEG-1/2 audio stream |
+| **Subtypes.** |
+| SF_FORMAT_PCM_S8 | 0x0001 | Signed 8 bit data |
+| SF_FORMAT_PCM_16 | 0x0002 | Signed 16 bit data |
+| SF_FORMAT_PCM_24 | 0x0003 | Signed 24 bit data |
+| SF_FORMAT_PCM_32 | 0x0004 | Signed 32 bit data |
+| SF_FORMAT_PCM_U8 | 0x0005 | Unsigned 8 bit data (WAV and RAW only) |
+| SF_FORMAT_FLOAT | 0x0006 | 32 bit float data |
+| SF_FORMAT_DOUBLE | 0x0007 | 64 bit float data |
+| SF_FORMAT_ULAW | 0x0010 | U-Law encoded. |
+| SF_FORMAT_ALAW | 0x0011 | A-Law encoded. |
+| SF_FORMAT_IMA_ADPCM | 0x0012 | IMA ADPCM. |
+| SF_FORMAT_MS_ADPCM | 0x0013 | Microsoft ADPCM. |
+| SF_FORMAT_GSM610 | 0x0020 | GSM 6.10 encoding. |
+| SF_FORMAT_VOX_ADPCM | 0x0021 | OKI / Dialogix ADPCM |
+| SF_FORMAT_NMS_ADPCM_16 | 0x0022 | 16kbs NMS G721-variant encoding. |
+| SF_FORMAT_NMS_ADPCM_24 | 0x0023 | 24kbs NMS G721-variant encoding. |
+| SF_FORMAT_NMS_ADPCM_32 | 0x0024 | 32kbs NMS G721-variant encoding. |
+| SF_FORMAT_G721_32 | 0x0030 | 32kbs G721 ADPCM encoding. |
+| SF_FORMAT_G723_24 | 0x0031 | 24kbs G723 ADPCM encoding. |
+| SF_FORMAT_G723_40 | 0x0032 | 40kbs G723 ADPCM encoding. |
+| SF_FORMAT_DWVW_12 | 0x0040 | 12 bit Delta Width Variable Word encoding. |
+| SF_FORMAT_DWVW_16 | 0x0041 | 16 bit Delta Width Variable Word encoding. |
+| SF_FORMAT_DWVW_24 | 0x0042 | 24 bit Delta Width Variable Word encoding. |
+| SF_FORMAT_DWVW_N | 0x0043 | N bit Delta Width Variable Word encoding. |
+| SF_FORMAT_DPCM_8 | 0x0050 | 8 bit differential PCM (XI only) |
+| SF_FORMAT_DPCM_16 | 0x0051 | 16 bit differential PCM (XI only) |
+| SF_FORMAT_VORBIS | 0x0060 | Xiph Vorbis encoding. |
+| SF_FORMAT_OPUS | 0x0064 | Xiph/Skype Opus encoding. |
+| SF_FORMAT_ALAC_16 | 0x0070 | Apple Lossless Audio Codec (16 bit). |
+| SF_FORMAT_ALAC_20 | 0x0071 | Apple Lossless Audio Codec (20 bit). |
+| SF_FORMAT_ALAC_24 | 0x0072 | Apple Lossless Audio Codec (24 bit). |
+| SF_FORMAT_ALAC_32 | 0x0073 | Apple Lossless Audio Codec (32 bit). |
+| SF_FORMAT_MPEG_LAYER_I | 0x0080 | MPEG-1 Audio Layer I. |
+| SF_FORMAT_MPEG_LAYER_II | 0x0081 | MPEG-1 Audio Layer II. |
+| SF_FORMAT_MPEG_LAYER_III | 0x0082 | MPEG-2 Audio Layer III. |
+| **Endian-ness options.** |
+| SF_ENDIAN_FILE | 0x00000000 | Default file endian-ness. |
+| SF_ENDIAN_LITTLE | 0x10000000 | Force little endian-ness. |
+| SF_ENDIAN_BIG | 0x20000000 | Force big endian-ness. |
+| SF_ENDIAN_CPU | 0x30000000 | Force CPU endian-ness. |
+| SF_FORMAT_SUBMASK | 0x0000FFFF | |
+| SF_FORMAT_TYPEMASK | 0x0FFF0000 | |
+| SF_FORMAT_ENDMASK | 0x30000000 | |
Every call to **sf_open**() should be matched with a call to
[**sf_close**()](#close) to free up memory allocated during the call to **sf_open**().
| [SFC_RF64_AUTO_DOWNGRADE](#sfc_rf64_auto_downgrade) | Set auto downgrade from RF64 to WAV. |
| [SFC_GET_ORIGINAL_SAMPLERATE](#sfc_get_original_samplerate) | Get original samplerate metadata. |
| [SFC_SET_ORIGINAL_SAMPLERATE](#sfc_set_original_samplerate) | Set original samplerate metadata. |
+| [SFC_GET_BITRATE_MODE](#sfc_get_bitrate_mode) | Get bitrate mode.
+| [SFC_SET_BITRATE_MODE](#sfc_set_bitrate_mode) | Set bitrate mode.
---
On write, can only succeed if no data has been written. On read, if successful,
[SFC_GET_CURRENT_SF_INFO](#sfc_get_current_sf_info) should be called to
determine the new frames count and samplerate
+
+## SFC_GET_BITRATE_MODE
+
+Get bitrate mode.
+
+The bitrate mode is one of:
+
+| Name | Value | Description |
+|:-------------------------|:------|:------------------|
+| SF_BITRATE_MODE_CONSTANT | 800 | Constant bitrate. |
+| SF_BITRATE_MODE_AVERAGE | 801 | Average bitrate. |
+| SF_BITRATE_MODE_VARIABLE | 802 | Variable bitrate. |
+
+### Parameters
+
+sndfile
+: A valid SNDFILE* pointer
+
+cmd
+: SFC_GET_BITRATE_MODE
+
+data
+: NULL
+
+datasize
+: anything
+
+### Return value
+
+Returns one of `SF_BITRATE_MODE_XXX` on success, `-1` otherwise.
+
+## SFC_SET_BITRATE_MODE
+
+Set bitrate mode.
+
+The bitrate mode is one of:
+
+| Name | Value | Description |
+|:-------------------------|:------|:------------------|
+| SF_BITRATE_MODE_CONSTANT | 800 | Constant bitrate. |
+| SF_BITRATE_MODE_AVERAGE | 801 | Average bitrate. |
+| SF_BITRATE_MODE_VARIABLE | 802 | Variable bitrate. |
+
+### Parameters
+
+sndfile
+: A valid SNDFILE* pointer
+
+cmd
+: SFC_SET_BITRATE_MODE
+
+data
+: pointer to an integer
+
+datasize
+: sizeof (int)
+
+### Return value
+
+Returns `SF_TRUE` on success, `SF_FALSE` otherwise.
The main repository can be found on Github:
-<http://libsndfile.github.io/libsndfile/">
+<https://github.com/libsndfile/libsndfile/>
and includes [instuctions](https://github.com/libsndfile/libsndfile/blob/master/README.md)
on how to build libsndfile from the Git repo.
From version 1.0.29, libsndfile can read and write
[Ogg/Opus](https://opus-codec.org/).
+From version 1.1.0, libsndfile can read and write MP3.
+
Some of the file formats I am also interested in adding are:
- Kurzweil K2000 sampler files.
- Ogg Speex.
-- MPEG Layer 3 (commonly known as MP3)
Other file formats may also be added on request.
problems, delete old generated sndfile.h from $(top_builddir)/src.
* Version 1.0.31 (January 24 2021) Bugfix release. Fix multiple memory leaks
reported by OSS-Fuzz. More SSE2-optimized functions for x86 and amd64.
+* Version 1.1.0 (March 27 2022) Minor release, backward compatible with previous
+ releases. Added long-awaited MP3 support. Numerous improvements and bugfixes.
## Similar or Related Projects
Check latest version on
[GitHub Releases page](https://github.com/libsndfile/libsndfile/releases/).
-Binatries and source packages are signed by current releaser David Seifert aka
+Binaries and source packages are signed by current releaser David Seifert aka
@SoapGentoo. You can verify signatures with his public GPG key:
```
exit (1) ;
} ;
- while ((readcount = sf_read_float (infile, buffer, BUFFER_LEN)) > 0)
+ while ((readcount = (int) sf_read_float (infile, buffer, BUFFER_LEN)) > 0)
sf_write_float (outfile, buffer, readcount) ;
sf_close (infile) ;
if (sfinfo.channels == 1)
{ for (k = 0 ; k < SAMPLE_COUNT ; k++)
- buffer [k] = AMPLITUDE * sin (LEFT_FREQ * 2 * k * M_PI) ;
+ buffer [k] = (int) (AMPLITUDE * sin (LEFT_FREQ * 2 * k * M_PI)) ;
}
else if (sfinfo.channels == 2)
{ for (k = 0 ; k < SAMPLE_COUNT ; k++)
- { buffer [2 * k] = AMPLITUDE * sin (LEFT_FREQ * 2 * k * M_PI) ;
- buffer [2 * k + 1] = AMPLITUDE * sin (RIGHT_FREQ * 2 * k * M_PI) ;
+ { buffer [2 * k] = (int) (AMPLITUDE * sin (LEFT_FREQ * 2 * k * M_PI)) ;
+ buffer [2 * k + 1] = (int) (AMPLITUDE * sin (RIGHT_FREQ * 2 * k * M_PI)) ;
} ;
}
else
if (sfinfo.channels > MAX_CHANNELS)
{ printf ("Not able to process more than %d channels\n", MAX_CHANNELS) ;
+ sf_close (infile) ;
return 1 ;
} ;
/* Open the output file. */
if (! (outfile = sf_open (outfilename, SFM_WRITE, &sfinfo)))
{ printf ("Not able to open output file %s.\n", outfilename) ;
puts (sf_strerror (NULL)) ;
+ sf_close (infile) ;
return 1 ;
} ;
/* While there are.frames in the input file, read them, process
** them and write them to the output file.
*/
- while ((readcount = sf_read_double (infile, data, BUFFER_LEN)))
+ while ((readcount = (int) sf_read_double (infile, data, BUFFER_LEN)))
{ process_data (data, readcount, sfinfo.channels) ;
sf_write_double (outfile, data, readcount) ;
} ;
#define BUFFER_LEN (1 << 14)
-
-typedef struct
-{ char *infilename, *outfilename ;
- SF_INFO infileinfo, outfileinfo ;
-} OptionData ;
-
const char * program_name (const char * argv0) ;
static void sfe_copy_data_int (SNDFILE *outfile, SNDFILE *infile, int channels) ;
static void add_instrument_data (SNDFILE *outfile, const SF_INFO * in_info) ;
/* Open the output file. */
if ((outfile = sf_open (outfilename, SFM_WRITE, &out_sfinfo)) == NULL)
{ printf ("Not able to open output file %s : %s\n", outfilename, sf_strerror (NULL)) ;
+ sf_close (infile) ;
return 1 ;
} ;
readcount = frames ;
while (readcount > 0)
- { readcount = sf_readf_int (infile, data, frames) ;
+ { readcount = (int) sf_readf_int (infile, data, frames) ;
sf_writef_int (outfile, data, readcount) ;
} ;
} /* print_usage */
-static void
+static int
convert_to_text (SNDFILE * infile, FILE * outfile, int channels, int full_precision)
-{ float buf [BLOCK_SIZE] ;
+{ float *buf ;
sf_count_t frames ;
int k, m, readcount ;
+ buf = malloc (BLOCK_SIZE * sizeof (float)) ;
+ if (buf == NULL)
+ { printf ("Error : Out of memory.\n\n") ;
+ return 1 ;
+ } ;
+
frames = BLOCK_SIZE / channels ;
- while ((readcount = sf_readf_float (infile, buf, frames)) > 0)
+ while ((readcount = (int) sf_readf_float (infile, buf, frames)) > 0)
{ for (k = 0 ; k < readcount ; k++)
{ for (m = 0 ; m < channels ; m++)
if (full_precision)
} ;
} ;
- return ;
+ free (buf) ;
+
+ return 0 ;
} /* convert_to_text */
int
FILE *outfile = NULL ;
SF_INFO sfinfo ;
int full_precision = 0 ;
+ int ret = 1 ;
progname = strrchr (argv [0], '/') ;
progname = progname ? progname + 1 : argv [0] ;
{ case 4 :
if (!strcmp ("--full-precision", argv [3]))
{ print_usage (progname) ;
- return 1 ;
+ goto cleanup ;
} ;
full_precision = 1 ;
argv++ ;
break ;
default:
print_usage (progname) ;
- return 1 ;
+ goto cleanup ;
} ;
infilename = argv [1] ;
if (strcmp (infilename, outfilename) == 0)
{ printf ("Error : Input and output filenames are the same.\n\n") ;
print_usage (progname) ;
- return 1 ;
+ goto cleanup ;
} ;
if (infilename [0] == '-')
{ printf ("Error : Input filename (%s) looks like an option.\n\n", infilename) ;
print_usage (progname) ;
- return 1 ;
+ goto cleanup ;
} ;
if (outfilename [0] == '-')
{ printf ("Error : Output filename (%s) looks like an option.\n\n", outfilename) ;
print_usage (progname) ;
- return 1 ;
+ goto cleanup ;
} ;
memset (&sfinfo, 0, sizeof (sfinfo)) ;
if ((infile = sf_open (infilename, SFM_READ, &sfinfo)) == NULL)
{ printf ("Not able to open input file %s.\n", infilename) ;
puts (sf_strerror (NULL)) ;
- return 1 ;
+ goto cleanup ;
} ;
/* Open the output file. */
if ((outfile = fopen (outfilename, "w")) == NULL)
{ printf ("Not able to open output file %s : %s\n", outfilename, sf_strerror (NULL)) ;
- return 1 ;
+ goto cleanup ;
} ;
fprintf (outfile, "# Converted from file %s.\n", infilename) ;
fprintf (outfile, "# Channels %d, Sample rate %d\n", sfinfo.channels, sfinfo.samplerate) ;
- convert_to_text (infile, outfile, sfinfo.channels, full_precision) ;
+ ret = convert_to_text (infile, outfile, sfinfo.channels, full_precision) ;
+
+cleanup :
sf_close (infile) ;
- fclose (outfile) ;
+ if (outfile != NULL)
+ fclose (outfile) ;
- return 0 ;
+ return ret ;
} /* main */
SF_FORMAT_OGG = 0x200000, /* Xiph OGG container */
SF_FORMAT_MPC2K = 0x210000, /* Akai MPC 2000 sampler */
SF_FORMAT_RF64 = 0x220000, /* RF64 WAV file */
+ SF_FORMAT_MPEG = 0x230000, /* MPEG-1/2 audio stream */
/* Subtypes from here on. */
SF_FORMAT_ALAC_24 = 0x0072, /* Apple Lossless Audio Codec (24 bit). */
SF_FORMAT_ALAC_32 = 0x0073, /* Apple Lossless Audio Codec (32 bit). */
+ SF_FORMAT_MPEG_LAYER_I = 0x0080, /* MPEG-1 Audio Layer I */
+ SF_FORMAT_MPEG_LAYER_II = 0x0081, /* MPEG-1 Audio Layer II */
+ SF_FORMAT_MPEG_LAYER_III = 0x0082, /* MPEG-2 Audio Layer III */
+
/* Endian-ness options. */
SF_ENDIAN_FILE = 0x00000000, /* Default file endian-ness. */
SFC_SET_RAW_START_OFFSET = 0x1090,
+ /* Commands reserved for dithering, which is not implemented. */
SFC_SET_DITHER_ON_WRITE = 0x10A0,
SFC_SET_DITHER_ON_READ = 0x10A1,
SFC_SET_OGG_PAGE_LATENCY_MS = 0x1302,
SFC_SET_OGG_PAGE_LATENCY = 0x1303,
+ SFC_GET_BITRATE_MODE = 0x1304,
+ SFC_SET_BITRATE_MODE = 0x1305,
+
/* Cart Chunk support */
SFC_SET_CART_INFO = 0x1400,
SFC_GET_CART_INFO = 0x1401,
SF_CHANNEL_MAP_MAX
} ;
+/* Bitrate mode values (for use with SFC_GET/SET_BITRATE_MODE)
+*/
+enum
+{ SF_BITRATE_MODE_CONSTANT = 0,
+ SF_BITRATE_MODE_AVERAGE,
+ SF_BITRATE_MODE_VARIABLE
+} ;
+
/* A SNDFILE* pointer can be passed around much like stdio.h's FILE* pointer. */
-typedef struct SNDFILE_tag SNDFILE ;
+typedef struct sf_private_tag SNDFILE ;
/* The following typedef is system specific and is defined when libsndfile is
** compiled. sf_count_t will be a 64 bit value when the underlying OS allows
/*
** Enums and typedefs for adding dither on read and write.
-** See the html documentation for sf_command(), SFC_SET_DITHER_ON_WRITE
-** and SFC_SET_DITHER_ON_READ.
+** Reserved for future implementation.
*/
enum
/* The function sf_wchar_open() is Windows Only!
** Open a file passing in a Windows Unicode filename. Otherwise, this is
** the same as sf_open().
-**
-** In order for this to work, you need to do the following:
-**
-** #include <windows.h>
-** #define ENABLE_SNDFILE_WINDOWS_PROTOTYPES 1
-** #including <sndfile.h>
*/
-#if (defined (ENABLE_SNDFILE_WINDOWS_PROTOTYPES) && ENABLE_SNDFILE_WINDOWS_PROTOTYPES)
-SNDFILE* sf_wchar_open (LPCWSTR wpath, int mode, SF_INFO *sfinfo) ;
+#ifdef _WIN32
+SNDFILE* sf_wchar_open (const wchar_t *wpath, int mode, SF_INFO *sfinfo) ;
#endif
**
** API documentation is in the doc/ directory of the source code tarball
** and at http://libsndfile.github.io/libsndfile/api.html.
+**
+** This file is intended to compile with C++98 and newer.
*/
#ifndef SNDFILE_HH
#include <string>
#include <new> // for std::nothrow
-#if __cplusplus < 201100
-#ifndef nullptr
-#define nullptr NULL
-#endif
+#if ((defined (_MSC_VER) && (_MSC_VER >= 1600)) || (__cplusplus >= 201100L))
+#define SF_NULL nullptr
+#else
+#define SF_NULL NULL
#endif
class SndfileHandle
public :
/* Default constructor */
- SndfileHandle (void) : p (nullptr) {} ;
+ SndfileHandle (void) : p (SF_NULL) {} ;
SndfileHandle (const char *path, int mode = SFM_READ,
int format = 0, int channels = 0, int samplerate = 0) ;
SndfileHandle (std::string const & path, int mode = SFM_READ,
SndfileHandle (SF_VIRTUAL_IO &sfvirtual, void *user_data, int mode = SFM_READ,
int format = 0, int channels = 0, int samplerate = 0) ;
-#ifdef ENABLE_SNDFILE_WINDOWS_PROTOTYPES
- SndfileHandle (LPCWSTR wpath, int mode = SFM_READ,
+#ifdef _WIN32
+ SndfileHandle (const wchar_t *wpath, int mode = SFM_READ,
int format = 0, int channels = 0, int samplerate = 0) ;
#endif
SndfileHandle & operator = (const SndfileHandle &rhs) ;
/* Mainly for debugging/testing. */
- int refCount (void) const { return (p == nullptr) ? 0 : p->ref ; }
+ int refCount (void) const { return (p == SF_NULL) ? 0 : p->ref ; }
- operator bool () const { return (p != nullptr) ; }
+ operator bool () const { return (p != SF_NULL) ; }
bool operator == (const SndfileHandle &rhs) const { return (p == rhs.p) ; }
inline
SndfileHandle::SNDFILE_ref::SNDFILE_ref (void)
-: sf (nullptr), sfinfo (), ref (1)
+: sf (SF_NULL), sfinfo (), ref (1)
{}
inline
SndfileHandle::SNDFILE_ref::~SNDFILE_ref (void)
-{ if (sf != nullptr) sf_close (sf) ; }
+{ if (sf != SF_NULL) sf_close (sf) ; }
inline
SndfileHandle::SndfileHandle (const char *path, int mode, int fmt, int chans, int srate)
-: p (nullptr)
+: p (SF_NULL)
{
p = new (std::nothrow) SNDFILE_ref () ;
- if (p != nullptr)
+ if (p != SF_NULL)
{ p->ref = 1 ;
p->sfinfo.frames = 0 ;
inline
SndfileHandle::SndfileHandle (std::string const & path, int mode, int fmt, int chans, int srate)
-: p (nullptr)
+: p (SF_NULL)
{
p = new (std::nothrow) SNDFILE_ref () ;
- if (p != nullptr)
+ if (p != SF_NULL)
{ p->ref = 1 ;
p->sfinfo.frames = 0 ;
inline
SndfileHandle::SndfileHandle (int fd, bool close_desc, int mode, int fmt, int chans, int srate)
-: p (nullptr)
+: p (SF_NULL)
{
if (fd < 0)
return ;
p = new (std::nothrow) SNDFILE_ref () ;
- if (p != nullptr)
+ if (p != SF_NULL)
{ p->ref = 1 ;
p->sfinfo.frames = 0 ;
inline
SndfileHandle::SndfileHandle (SF_VIRTUAL_IO &sfvirtual, void *user_data, int mode, int fmt, int chans, int srate)
-: p (nullptr)
+: p (SF_NULL)
{
p = new (std::nothrow) SNDFILE_ref () ;
- if (p != nullptr)
+ if (p != SF_NULL)
{ p->ref = 1 ;
p->sfinfo.frames = 0 ;
inline
SndfileHandle::~SndfileHandle (void)
-{ if (p != nullptr && -- p->ref == 0)
+{ if (p != SF_NULL && -- p->ref == 0)
delete p ;
} /* SndfileHandle destructor */
inline
SndfileHandle::SndfileHandle (const SndfileHandle &orig)
: p (orig.p)
-{ if (p != nullptr)
+{ if (p != SF_NULL)
++ p->ref ;
} /* SndfileHandle copy constructor */
{
if (&rhs == this)
return *this ;
- if (p != nullptr && -- p->ref == 0)
+ if (p != SF_NULL && -- p->ref == 0)
delete p ;
p = rhs.p ;
- if (p != nullptr)
+ if (p != SF_NULL)
++ p->ref ;
return *this ;
inline SNDFILE *
SndfileHandle::rawHandle (void)
-{ return (p ? p->sf : nullptr) ; }
+{ return (p ? p->sf : SF_NULL) ; }
inline SNDFILE *
SndfileHandle::takeOwnership (void)
{
- if (p == nullptr || (p->ref != 1))
- return nullptr ;
+ if (p == SF_NULL || (p->ref != 1))
+ return SF_NULL ;
SNDFILE * sf = p->sf ;
- p->sf = nullptr ;
+ p->sf = SF_NULL ;
delete p ;
- p = nullptr ;
+ p = SF_NULL ;
return sf ;
}
-#ifdef ENABLE_SNDFILE_WINDOWS_PROTOTYPES
+#ifdef _WIN32
inline
-SndfileHandle::SndfileHandle (LPCWSTR wpath, int mode, int fmt, int chans, int srate)
-: p (nullptr)
+SndfileHandle::SndfileHandle (const wchar_t *wpath, int mode, int fmt, int chans, int srate)
+: p (SF_NULL)
{
p = new (std::nothrow) SNDFILE_ref () ;
- if (p != nullptr)
+ if (p != SF_NULL)
{ p->ref = 1 ;
p->sfinfo.frames = 0 ;
# ===========================================================================
-# http://www.gnu.org/software/autoconf-archive/ax_add_fortify_source.html
+# https://www.gnu.org/software/autoconf-archive/ax_add_fortify_source.html
# ===========================================================================
#
# SYNOPSIS
# DESCRIPTION
#
# Check whether -D_FORTIFY_SOURCE=2 can be added to CPPFLAGS without macro
-# redefinition warnings. Some distributions (such as Gentoo Linux) enable
-# _FORTIFY_SOURCE globally in their compilers, leading to unnecessary
-# warnings in the form of
+# redefinition warnings, other cpp warnings or linker. Some distributions
+# (such as Gentoo Linux) enable _FORTIFY_SOURCE globally in their
+# compilers, leading to unnecessary warnings in the form of
#
# <command-line>:0:0: error: "_FORTIFY_SOURCE" redefined [-Werror]
# <built-in>: note: this is the location of the previous definition
# _FORTIFY_SOURCE is already defined, and if not, adds -D_FORTIFY_SOURCE=2
# to CPPFLAGS.
#
+# Newer mingw-w64 msys2 package comes with a bug in
+# headers-git-7.0.0.5546.d200317d-1. It broke -D_FORTIFY_SOURCE support,
+# and would need -lssp or -fstack-protector. See
+# https://github.com/msys2/MINGW-packages/issues/5803. Try to actually
+# link it.
+#
# LICENSE
#
# Copyright (c) 2017 David Seifert <soap@gentoo.org>
+# Copyright (c) 2019 Reini Urban <rurban@cpan.org>
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice
# and this notice are preserved. This file is offered as-is, without any
# warranty.
-#serial 1
+#serial 4
AC_DEFUN([AX_ADD_FORTIFY_SOURCE],[
+ ac_save_cflags=$CFLAGS
+ ac_cwerror_flag=yes
+ AX_CHECK_COMPILE_FLAG([-Werror],[CFLAGS="$CFLAGS -Werror"])
AC_MSG_CHECKING([whether to add -D_FORTIFY_SOURCE=2 to CPPFLAGS])
AC_LINK_IFELSE([
- AC_LANG_SOURCE(
+ AC_LANG_PROGRAM([],
[[
- int main() {
#ifndef _FORTIFY_SOURCE
return 0;
#else
this_is_an_error;
#endif
- }
]]
- )], [
- AC_MSG_RESULT([yes])
- CPPFLAGS="$CPPFLAGS -D_FORTIFY_SOURCE=2"
- ], [
- AC_MSG_RESULT([no])
- ])
+ )],
+ AC_LINK_IFELSE([
+ AC_LANG_SOURCE([[
+ #define _FORTIFY_SOURCE 2
+ #include <string.h>
+ int main() {
+ char *s = " ";
+ strcpy(s, "x");
+ return strlen(s)-1;
+ }
+ ]]
+ )],
+ [
+ AC_MSG_RESULT([yes])
+ CFLAGS=$ac_save_cflags
+ CPPFLAGS="$CPPFLAGS -D_FORTIFY_SOURCE=2"
+ ], [
+ AC_MSG_RESULT([no])
+ CFLAGS=$ac_save_cflags
+ ],
+ ),
+ [
+ AC_MSG_RESULT([no])
+ CFLAGS=$ac_save_cflags
+ ])
])
CFLAGS=$pkg_link_saved_CFLAGS
LIBS=$pkg_link_saved_LIBS
-if test $pkg_link = no ; then
- $as_echo_n "link failed ... "
+AS_IF([test x$pkg_link = xno], [
+ AS_ECHO_N(["link failed ... "])
pkg_failed=yes
- fi
+])
m4_define([_PKG_TEXT], [Alternatively, you may set the environment variables $1[]_CFLAGS
and $1[]_LIBS to avoid the need to call pkg-config.
AC_ARG_WITH(mkoctfile,
- AC_HELP_STRING([--with-mkoctfile], [choose the mkoctfile version]),
+ AS_HELP_STRING([--with-mkoctfile], [choose the mkoctfile version]),
[ with_mkoctfile=$withval ])
test -z "$with_mkoctfile" && with_mkoctfile=mkoctfile
[
AC_ARG_WITH(octave,
- AC_HELP_STRING([--with-octave], [choose the octave version]),
+ AS_HELP_STRING([--with-octave], [choose the octave version]),
[ with_octave=$withval ])
test -z "$with_octave" && with_octave=octave
[
AC_ARG_WITH(octave-config,
- AC_HELP_STRING([--with-octave-config], [choose the octave-config version]),
+ AS_HELP_STRING([--with-octave-config], [choose the octave-config version]),
[ with_octave_config=$withval ])
test -z "$with_octave_config" && with_octave_config=octave-config
+++ /dev/null
-dnl Copyright (C) 2013 Xiph.org Foundation
-dnl
-dnl Redistribution and use in source and binary forms, with or without
-dnl modification, are permitted provided that the following conditions
-dnl are met:
-dnl
-dnl - Redistributions of source code must retain the above copyright
-dnl notice, this list of conditions and the following disclaimer.
-dnl
-dnl - Redistributions in binary form must reproduce the above copyright
-dnl notice, this list of conditions and the following disclaimer in the
-dnl documentation and/or other materials provided with the distribution.
-dnl
-dnl - Neither the name of the Xiph.org Foundation nor the names of its
-dnl contributors may be used to endorse or promote products derived from
-dnl this software without specific prior written permission.
-dnl
-dnl THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-dnl ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-dnl LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-dnl A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
-dnl CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-dnl EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-dnl PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-dnl PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-dnl LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-dnl NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-dnl SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-dnl Want to know of GCC stack protector works, botfor the C and for the C++
-dnl compiler.
-dnl
-dnl Just checking if the compiler accepts the required CFLAGSs is not enough
-dnl because we have seen at least one instance where this check was
-dnl in-sufficient.
-dnl
-dnl Instead, try to compile and link a test program with the stack protector
-dnl flags. If that works, we use it.
-
-AC_DEFUN([XIPH_GCC_STACK_PROTECTOR],
-[AC_LANG_ASSERT(C)
- AC_MSG_CHECKING([if $CC supports stack smash protection])
- xiph_stack_check_old_cflags="$CFLAGS"
- SSP_FLAGS="-fstack-protector --param ssp-buffer-size=4"
- CFLAGS=$SSP_FLAGS
- AC_TRY_LINK([
- #include <stdio.h>
- ],
- [puts("Hello, World!"); return 0;],
- AC_MSG_RESULT([yes])
- CFLAGS="$xiph_stack_check_old_cflags $SSP_FLAGS",
- AC_MSG_RESULT([no])
- CFLAGS="$xiph_stack_check_old_cflags"
- )
-])# XIPH_GCC_STACK_PROTECTOR
-
-AC_DEFUN([XIPH_GXX_STACK_PROTECTOR],
-[AC_LANG_PUSH([C++])
- AC_MSG_CHECKING([if $CXX supports stack smash protection])
- xiph_stack_check_old_cflags="$CFLAGS"
- SSP_FLAGS="-fstack-protector --param ssp-buffer-size=4"
- CFLAGS=$SSP_FLAGS
- AC_TRY_LINK([
- #include <cstdio>
- ],
- [puts("Hello, World!"); return 0;],
- AC_MSG_RESULT([yes])
- CFLAGS="$xiph_stack_check_old_cflags $SSP_FLAGS",
- AC_MSG_RESULT([no])
- CFLAGS="$xiph_stack_check_old_cflags"
- )
- AC_LANG_POP([C++])
-])# XIPH_GXX_STACK_PROTECTOR
-.Dd November 2, 2014
+.Dd September 10, 2021
.Dt SNDFILE-PLAY 1
.Os
.Sh NAME
sndio
.It FreeBSD
/dev/dsp (OSS)
+.It NetBSD
+/dev/audio
.It Solaris
/dev/audio
.It MacOSX 10.6
# Copy the fuzzer to the output directory.
cp -v ossfuzz/sndfile_fuzzer $OUT/
+cp -v ossfuzz/sndfile_alt_fuzzer $OUT/
--- /dev/null
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sndfile.h>
+#include <inttypes.h>
+
+#include "sndfile_fuzz_header.h"
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
+{ // One byte is needed for deciding which function to target.
+ if (size == 0)
+ return 0 ;
+
+ const uint8_t decider = *data ;
+ data += 1 ;
+ size -= 1 ;
+
+ SF_INFO sndfile_info ;
+ VIO_DATA vio_data ;
+ SF_VIRTUAL_IO vio ;
+ SNDFILE *sndfile = NULL ;
+ int err = sf_init_file(data, size, &sndfile, &vio_data, &vio, &sndfile_info) ;
+ if (err)
+ goto EXIT_LABEL ;
+
+ // Just the right number of channels. Create some buffer space for reading.
+ switch (decider % 3)
+ { case 0 :
+ {
+ short* read_buffer = NULL ;
+ read_buffer = (short*)malloc(sizeof(short) * size);
+ if (read_buffer == NULL)
+ abort() ;
+
+ while (sf_read_short(sndfile, read_buffer, size))
+ {
+ // Do nothing with the data.
+ }
+ free(read_buffer) ;
+ }
+ break ;
+ case 1 :
+ {
+ int* read_buffer = NULL ;
+ read_buffer = (int*)malloc(sizeof(int) * size) ;
+ if (read_buffer == NULL)
+ abort() ;
+
+ while (sf_read_int(sndfile, read_buffer, size))
+ {
+ // Do nothing with the data.
+ }
+ free(read_buffer) ;
+ }
+ break ;
+ case 2 :
+ {
+ double* read_buffer = NULL ;
+ read_buffer = (double*)malloc(sizeof(double) * size) ;
+ if (read_buffer == NULL)
+ abort() ;
+
+ while (sf_read_double(sndfile, read_buffer, size))
+ {
+ // Do nothing with the data.
+ }
+ free(read_buffer) ;
+ }
+ break ;
+ default :
+ break ;
+ } ;
+
+ EXIT_LABEL:
+ if (sndfile != NULL)
+ sf_close(sndfile);
+
+ return 0 ;
+}
--- /dev/null
+#ifndef SNDFILE_FUZZ_HEADER_H
+#define SNDFILE_FUZZ_HEADER_H
+
+typedef struct
+{
+ sf_count_t offset ;
+ sf_count_t length ;
+ const unsigned char *data ;
+} VIO_DATA ;
+
+static sf_count_t vfget_filelen (void *user_data)
+{ VIO_DATA *vf = (VIO_DATA *)user_data ;
+ return vf->length ;
+}
+
+static sf_count_t vfseek (sf_count_t offset, int whence, void *user_data)
+{
+ VIO_DATA *vf = (VIO_DATA *)user_data ;
+ sf_count_t new_offset ;
+
+ switch (whence)
+ { case SEEK_SET :
+ new_offset = offset ;
+ break ;
+
+ case SEEK_CUR :
+ new_offset = vf->offset + offset ;
+ break ;
+
+ case SEEK_END :
+ new_offset = vf->length + offset ;
+ break ;
+
+ default :
+ break ;
+ }
+
+ /* Ensure you can't seek outside the data */
+ if (new_offset > vf->length)
+ { /* Trying to seek past the end of the data */
+ printf("vf overseek: new_offset(%" PRId64 ") > vf->length(%" PRId64 ");"
+ " whence(%d), vf->offset(%" PRId64 "), offset(%" PRId64 ")\n",
+ new_offset, vf->length, whence, vf->offset, offset) ;
+ new_offset = vf->length ;
+ }
+ else if (new_offset < 0)
+ { /* Trying to seek before the start of the data */
+ printf("vf underseek: new_offset(%" PRId64 ") < 0; whence(%d), vf->offset"
+ "(%" PRId64 "), vf->length(%" PRId64 "), offset(%" PRId64 ")\n",
+ new_offset, whence, vf->offset, vf->length, offset) ;
+ new_offset = 0 ;
+ }
+ vf->offset = new_offset ;
+
+ return vf->offset ;
+}
+
+static sf_count_t vfread (void *ptr, sf_count_t count, void *user_data)
+{ VIO_DATA *vf = (VIO_DATA *)user_data ;
+
+ if (vf->offset + count > vf->length)
+ count = vf->length - vf->offset ;
+
+ memcpy(ptr, vf->data + vf->offset, count) ;
+ vf->offset += count ;
+
+ return count ;
+}
+
+static sf_count_t vfwrite (const void *ptr, sf_count_t count, void *user_data)
+{
+ (void)ptr ;
+ (void)count ;
+ (void)user_data ;
+
+ // Cannot write to this virtual file.
+ return 0;
+}
+
+static sf_count_t vftell (void *user_data)
+{ VIO_DATA *vf = (VIO_DATA *)user_data ;
+
+ return vf->offset ;
+}
+
+int sf_init_file(const uint8_t *data,
+ size_t size,
+ SNDFILE **sndfile,
+ VIO_DATA *vio_data,
+ SF_VIRTUAL_IO *vio, SF_INFO *sndfile_info)
+{ float* read_buffer = NULL ;
+
+ // Initialize the virtual IO structure.
+ vio->get_filelen = vfget_filelen ;
+ vio->seek = vfseek ;
+ vio->read = vfread ;
+ vio->write = vfwrite ;
+ vio->tell = vftell ;
+
+ // Initialize the VIO user data.
+ vio_data->data = data ;
+ vio_data->length = size ;
+ vio_data->offset = 0 ;
+
+ memset(sndfile_info, 0, sizeof(SF_INFO)) ;
+
+ // Try and open the virtual file.
+ *sndfile = sf_open_virtual(vio, SFM_READ, sndfile_info, vio_data) ;
+
+ if (sndfile_info->channels == 0)
+ return -1 ;
+
+ if (sndfile_info->channels > 1024 * 1024)
+ return -1 ;
+
+ return 0;
+}
+
+#endif
#include <sndfile.h>
#include <inttypes.h>
-typedef struct
-{
- sf_count_t offset;
- sf_count_t length;
- const unsigned char *data;
-} VIO_DATA;
-
-static sf_count_t vfget_filelen (void *user_data)
-{
- VIO_DATA *vf = (VIO_DATA *)user_data;
- return vf->length;
-}
-
-static sf_count_t vfseek (sf_count_t offset, int whence, void *user_data)
-{
- VIO_DATA *vf = (VIO_DATA *)user_data;
- sf_count_t new_offset;
-
- switch (whence)
- {
- case SEEK_SET:
- new_offset = offset;
- break ;
-
- case SEEK_CUR:
- new_offset = vf->offset + offset;
- break ;
-
- case SEEK_END:
- new_offset = vf->length + offset;
- break;
-
- default:
- break;
- }
-
- /* Ensure you can't seek outside the data */
- if (new_offset > vf->length)
- {
- /* Trying to seek past the end of the data */
- printf("vf overseek: new_offset(%" PRId64 ") > vf->length(%" PRId64 ");"
- " whence(%d), vf->offset(%" PRId64 "), offset(%" PRId64 ")\n",
- new_offset, vf->length, whence, vf->offset, offset);
- new_offset = vf->length;
- }
- else if (new_offset < 0)
- {
- /* Trying to seek before the start of the data */
- printf("vf underseek: new_offset(%" PRId64 ") < 0; whence(%d), vf->offset"
- "(%" PRId64 "), vf->length(%" PRId64 "), offset(%" PRId64 ")\n",
- new_offset, whence, vf->offset, vf->length, offset);
- new_offset = 0;
- }
- vf->offset = new_offset;
-
- return vf->offset;
-}
-
-static sf_count_t vfread (void *ptr, sf_count_t count, void *user_data)
-{
- VIO_DATA *vf = (VIO_DATA *)user_data;
-
- if (vf->offset + count > vf->length)
- {
- count = vf->length - vf->offset;
- }
-
- memcpy(ptr, vf->data + vf->offset, count);
- vf->offset += count;
-
- return count;
-}
-
-static sf_count_t vfwrite (const void *ptr, sf_count_t count, void *user_data)
-{
- (void)ptr;
- (void)count;
- (void)user_data;
-
- // Cannot write to this virtual file.
- return 0;
-}
-
-static sf_count_t vftell (void *user_data)
-{ VIO_DATA *vf = (VIO_DATA *)user_data;
-
- return vf->offset;
-}
+#include "sndfile_fuzz_header.h"
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
-{
- VIO_DATA vio_data;
- SF_VIRTUAL_IO vio;
- SF_INFO sndfile_info;
- SNDFILE *sndfile = NULL;
- float* read_buffer = NULL;
-
- // Initialize the virtual IO structure.
- vio.get_filelen = vfget_filelen;
- vio.seek = vfseek;
- vio.read = vfread;
- vio.write = vfwrite;
- vio.tell = vftell;
-
- // Initialize the VIO user data.
- vio_data.data = data;
- vio_data.length = size;
- vio_data.offset = 0;
-
- memset(&sndfile_info, 0, sizeof(SF_INFO));
-
- // Try and open the virtual file.
- sndfile = sf_open_virtual(&vio, SFM_READ, &sndfile_info, &vio_data);
-
- if (sndfile_info.channels == 0)
- {
- // No sound channels in file.
- goto EXIT_LABEL;
- }
- else if (sndfile_info.channels > 1024 * 1024)
- {
- // Too many channels to handle.
- goto EXIT_LABEL;
- }
-
- // Just the right number of channels. Create some buffer space for reading.
- read_buffer = (float*)malloc(sizeof(float) * sndfile_info.channels);
- if (read_buffer == NULL)
- {
- abort();
- }
-
- while (sf_readf_float(sndfile, read_buffer, 1))
- {
- // Do nothing with the data.
- }
+{ VIO_DATA vio_data ;
+ SF_VIRTUAL_IO vio ;
+ SF_INFO sndfile_info ;
+ SNDFILE *sndfile = NULL ;
+ float* read_buffer = NULL ;
+
+ int err = sf_init_file(data, size, &sndfile, &vio_data, &vio, &sndfile_info) ;
+ if (err)
+ goto EXIT_LABEL ;
+
+ // Just the right number of channels. Create some buffer space for reading.
+ read_buffer = (float*)malloc(sizeof(float) * sndfile_info.channels);
+ if (read_buffer == NULL)
+ abort() ;
+
+ while (sf_readf_float(sndfile, read_buffer, 1))
+ {
+ // Do nothing with the data.
+ }
EXIT_LABEL:
- if (sndfile != NULL)
- {
- sf_close(sndfile);
- }
+ if (sndfile != NULL)
+ sf_close(sndfile) ;
- free(read_buffer);
+ free(read_buffer) ;
- return 0;
+ return 0 ;
}
{ data [k] /= max ;
if (!isfinite (data [k])) /* infinite or NaN */
- return 1;
+ return 1 ;
}
sf_writef_double (outfile, data, readcount) ;
} ;
readcount = frames ;
while (readcount > 0)
- { readcount = sf_readf_int (infile, data, frames) ;
+ { readcount = (int) sf_readf_int (infile, data, frames) ;
sf_writef_int (outfile, data, readcount) ;
} ;
{ case SF_FORMAT_PCM_16 :
case SF_FORMAT_PCM_24 :
case SF_FORMAT_PCM_32 :
+ case SF_FORMAT_MPEG_LAYER_III :
break ;
default :
/* Special case for coding_history because we may want to append. */
if (info->coding_history != NULL)
{ if (info->coding_hist_append)
- { int slen = strlen (binfo.coding_history) ;
+ { int slen = (int) strlen (binfo.coding_history) ;
while (slen > 1 && isspace (binfo.coding_history [slen - 1]))
slen -- ;
memset (binfo.coding_history, 0, sizeof (binfo.coding_history)) ;
memcpy (binfo.coding_history, info->coding_history, slen) ;
- binfo.coding_history_size = slen ;
+ binfo.coding_history_size = (uint32_t) slen ;
} ;
} ;
{ "caf", 0, SF_FORMAT_CAF },
{ "wve", 0, SF_FORMAT_WVE },
{ "prc", 0, SF_FORMAT_WVE },
- { "ogg", 0, SF_FORMAT_OGG },
{ "oga", 0, SF_FORMAT_OGG },
+ { "ogg", 0, SF_FORMAT_OGG | SF_FORMAT_VORBIS },
{ "opus", 0, SF_FORMAT_OGG | SF_FORMAT_OPUS },
{ "mpc", 0, SF_FORMAT_MPC2K },
{ "rf64", 0, SF_FORMAT_RF64 },
+ { "mp3", 0, SF_FORMAT_MPEG | SF_FORMAT_MPEG_LAYER_III },
} ; /* format_map */
int
case SF_FORMAT_OGG : return "OGG" ;
case SF_FORMAT_MPC2K : return "MPC2K" ;
case SF_FORMAT_RF64 : return "RF64" ;
+ case SF_FORMAT_MPEG : return "MPEG" ;
default : break ;
} ;
case SF_FORMAT_ALAC_24 : return "24 bit ALAC" ;
case SF_FORMAT_ALAC_32 : return "32 bit ALAC" ;
case SF_FORMAT_OPUS : return "Opus" ;
+ case SF_FORMAT_MPEG_LAYER_I : return "MPEG layer 1" ;
+ case SF_FORMAT_MPEG_LAYER_II : return "MPEG layer 2" ;
+ case SF_FORMAT_MPEG_LAYER_III : return "MPEG layer 3" ;
default : break ;
} ;
return "unknown" ;
sf_seek (wfile, 0, SEEK_END) ;
while (readcount > 0)
- { readcount = sf_readf_double (rofile, data, frames) ;
+ { readcount = (int) sf_readf_double (rofile, data, frames) ;
sf_writef_double (wfile, data, readcount) ;
} ;
sf_seek (wfile, 0, SEEK_END) ;
while (readcount > 0)
- { readcount = sf_readf_int (rofile, data, frames) ;
+ { readcount = (int) sf_readf_int (rofile, data, frames) ;
sf_writef_int (wfile, data, readcount) ;
} ;
continue ;
} ;
- printf ("Error : Not able to decode argunment '%s'.\n", argv [k]) ;
+ printf ("Error : Not able to decode argument '%s'.\n", argv [k]) ;
exit (1) ;
} ;
|| (outfileminor == SF_FORMAT_DOUBLE) || (outfileminor == SF_FORMAT_FLOAT)
|| (infileminor == SF_FORMAT_DOUBLE) || (infileminor == SF_FORMAT_FLOAT)
|| (infileminor == SF_FORMAT_OPUS) || (outfileminor == SF_FORMAT_OPUS)
- || (infileminor == SF_FORMAT_VORBIS) || (outfileminor == SF_FORMAT_VORBIS))
+ || (infileminor == SF_FORMAT_VORBIS) || (outfileminor == SF_FORMAT_VORBIS)
+ || (infileminor == SF_FORMAT_MPEG_LAYER_I)
+ || (infileminor == SF_FORMAT_MPEG_LAYER_II)
+ || (infileminor == SF_FORMAT_MPEG_LAYER_III) || (outfileminor == SF_FORMAT_MPEG_LAYER_III))
{ if (sfe_copy_data_fp (outfile, infile, sfinfo.channels, normalize) != 0)
{ printf ("Error : Not able to decode input file %s.\n", infilename) ;
return 1 ;
memset (&binfo, 0, sizeof (binfo)) ;
if (channels < ARRAY_LEN (chanmap))
- { size_t size = channels * sizeof (chanmap [0]) ;
+ { int size = channels * sizeof (chanmap [0]) ;
if (sf_command (infile, SFC_GET_CHANNEL_MAP_INFO, chanmap, size) == SF_TRUE)
sf_command (outfile, SFC_SET_CHANNEL_MAP_INFO, chanmap, size) ;
int
main (int argc, char **argv)
-{ STATE state ;
+{ STATE *state = NULL ;
SF_INFO sfinfo ;
char pathname [512], ext [32], *cptr ;
- int ch, double_split ;
+ int ch, double_split, ret = 1 ;
if (argc != 2)
{ if (argc != 1)
puts ("\nError : need a single input file.\n") ;
usage_exit () ;
+ goto cleanup ;
} ;
- memset (&state, 0, sizeof (state)) ;
+ state = calloc (1, sizeof (*state)) ;
+ if (!state)
+ { printf ("\nError : Out of memory.\n") ;
+ goto cleanup ;
+ } ;
memset (&sfinfo, 0, sizeof (sfinfo)) ;
- if ((state.infile = sf_open (argv [1], SFM_READ, &sfinfo)) == NULL)
+ if ((state->infile = sf_open (argv [1], SFM_READ, &sfinfo)) == NULL)
{ printf ("\nError : Not able to open input file '%s'\n%s\n", argv [1], sf_strerror (NULL)) ;
- exit (1) ;
+ goto cleanup ;
} ;
if (sfinfo.channels < 2)
{ printf ("\nError : Input file '%s' only has one channel.\n", argv [1]) ;
- exit (1) ;
+ goto cleanup ;
} ;
if (sfinfo.channels > MAX_CHANNELS)
{ printf ("\nError : Input file '%s' has too many (%d) channels. Limit is %d.\n",
argv [1], sfinfo.channels, MAX_CHANNELS) ;
- exit (1) ;
+ goto cleanup ;
} ;
- state.channels = sfinfo.channels ;
+ state->channels = sfinfo.channels ;
sfinfo.channels = 1 ;
if (snprintf (pathname, sizeof (pathname), "%s", argv [1]) > (int) sizeof (pathname))
{ printf ("\nError : Length of provided filename '%s' exceeds MAX_PATH (%d).\n", argv [1], (int) sizeof (pathname)) ;
- exit (1) ;
+ goto cleanup ;
} ;
if ((cptr = strrchr (pathname, '.')) == NULL)
printf ("Input file : %s\n", pathname) ;
puts ("Output files :") ;
- for (ch = 0 ; ch < state.channels ; ch++)
+ for (ch = 0 ; ch < state->channels ; ch++)
{ char filename [520] ;
size_t count ;
{ printf ("File name truncated to %s\n", filename) ;
} ;
- if ((state.outfile [ch] = sf_open (filename, SFM_WRITE, &sfinfo)) == NULL)
+ if ((state->outfile [ch] = sf_open (filename, SFM_WRITE, &sfinfo)) == NULL)
{ printf ("Not able to open output file '%s'\n%s\n", filename, sf_strerror (NULL)) ;
- exit (1) ;
+ goto cleanup ;
} ;
printf (" %s\n", filename) ;
} ;
if (double_split)
- deinterleave_double (&state) ;
+ deinterleave_double (state) ;
else
- deinterleave_int (&state) ;
+ deinterleave_int (state) ;
+
+ ret = 0 ;
+
+cleanup :
+
+ if (state != NULL)
+ { sf_close (state->infile) ;
+ for (ch = 0 ; ch < MAX_CHANNELS ; ch++)
+ if (state->outfile [ch] != NULL)
+ sf_close (state->outfile [ch]) ;
+ } ;
- sf_close (state.infile) ;
- for (ch = 0 ; ch < MAX_CHANNELS ; ch++)
- if (state.outfile [ch] != NULL)
- sf_close (state.outfile [ch]) ;
+ free (state) ;
- return 0 ;
+ return ret ;
} /* main */
/*------------------------------------------------------------------------------
"a_00.wav, a_01.wav and so on.\n"
) ;
printf ("Using %s.\n\n", sf_version_string ()) ;
- exit (1) ;
} /* usage_exit */
static void
int ch, k ;
do
- { read_len = sf_readf_int (state->infile, state->din.i, BUFFER_LEN) ;
+ { read_len = (int) sf_readf_int (state->infile, state->din.i, BUFFER_LEN) ;
for (ch = 0 ; ch < state->channels ; ch ++)
{ for (k = 0 ; k < read_len ; k++)
int ch, k ;
do
- { read_len = sf_readf_double (state->infile, state->din.d, BUFFER_LEN) ;
+ { read_len = (int) sf_readf_double (state->infile, state->din.d, BUFFER_LEN) ;
for (ch = 0 ; ch < state->channels ; ch ++)
{ for (k = 0 ; k < read_len ; k++)
** Print version and usage.
*/
-static double data [BUFFER_LEN] ;
-
static void
usage_exit (const char *progname)
{ printf ("Usage :\n %s <file> ...\n", progname) ;
case SF_FORMAT_FLOAT :
case SF_FORMAT_DOUBLE :
+ case SF_FORMAT_VORBIS :
+ case SF_FORMAT_OPUS :
decibels = max / 1.0 ;
break ;
printf (" Loop points : %d\n", inst.loop_count) ;
for (k = 0 ; k < inst.loop_count ; k++)
- printf (" %-2d Mode : %s Start : %6d End : %6d Count : %6d\n", k, str_of_type (inst.loops [k].mode), inst.loops [k].start, inst.loops [k].end, inst.loops [k].count) ;
+ printf (" %-2d Mode : %s Start : %6" PRIu32 " End : %6" PRIu32
+ " Count : %6" PRIu32 "\n", k, str_of_type (inst.loops [k].mode),
+ inst.loops [k].start, inst.loops [k].end, inst.loops [k].count) ;
putchar ('\n') ;
return 0 ;
} STATE ;
-static void usage_exit (void) ;
+static void print_usage (void) ;
static void interleave_int (STATE * state) ;
static void interleave_double (STATE * state) ;
int
main (int argc, char **argv)
-{ STATE state ;
+{ STATE *state = NULL ;
SF_INFO sfinfo ;
int k, double_merge = 0 ;
+ int ret = 1 ;
if (argc < 5)
{ if (argc > 1)
puts ("\nError : need at least 2 input files.") ;
- usage_exit () ;
+ print_usage () ;
+ goto cleanup ;
} ;
if (strcmp (argv [argc - 2], "-o") != 0)
{ puts ("\nError : second last command line parameter should be '-o'.\n") ;
- usage_exit () ;
+ print_usage () ;
+ goto cleanup ;
} ;
if (argc - 3 > MAX_INPUTS)
{ printf ("\nError : Cannot handle more than %d input channels.\n\n", MAX_INPUTS) ;
- exit (1) ;
+ goto cleanup ;
+ } ;
+
+ state = calloc (1, sizeof (STATE)) ;
+ if (state == NULL)
+ { puts ("\nError : out of memory.\n") ;
+ goto cleanup ;
} ;
- memset (&state, 0, sizeof (state)) ;
memset (&sfinfo, 0, sizeof (sfinfo)) ;
for (k = 1 ; k < argc - 2 ; k++)
{
- if ((state.infile [k - 1] = sf_open (argv [k], SFM_READ, &sfinfo)) == NULL)
+ if ((state->infile [k - 1] = sf_open (argv [k], SFM_READ, &sfinfo)) == NULL)
{ printf ("\nError : Not able to open input file '%s'\n%s\n", argv [k], sf_strerror (NULL)) ;
- exit (1) ;
+ goto cleanup ;
} ;
if (sfinfo.channels != 1)
{ printf ("\bError : Input file '%s' should be mono (has %d channels).\n", argv [k], sfinfo.channels) ;
- exit (1) ;
+ goto cleanup ;
} ;
switch (sfinfo.format & SF_FORMAT_SUBMASK)
break ;
} ;
- state.channels ++ ;
+ state->channels ++ ;
} ;
- sfinfo.channels = state.channels ;
+ sfinfo.channels = state->channels ;
sfinfo.format = sfe_file_type_of_ext (argv [argc - 1], sfinfo.format) ;
- if ((state.outfile = sf_open (argv [argc - 1], SFM_WRITE, &sfinfo)) == NULL)
+ if ((state->outfile = sf_open (argv [argc - 1], SFM_WRITE, &sfinfo)) == NULL)
{ printf ("Not able to open output file '%s'\n%s\n", argv [argc - 1], sf_strerror (NULL)) ;
- exit (1) ;
+ goto cleanup ;
} ;
if (double_merge)
- interleave_double (&state) ;
+ interleave_double (state) ;
else
- interleave_int (&state) ;
+ interleave_int (state) ;
+
+ ret = 0 ;
+
+cleanup :
+
+ if (state != NULL)
+ { for (k = 0 ; k < MAX_INPUTS ; k++)
+ if (state->infile [k] != NULL)
+ sf_close (state->infile [k]) ;
+ sf_close (state->outfile) ;
+ }
- for (k = 0 ; k < MAX_INPUTS ; k++)
- if (state.infile [k] != NULL)
- sf_close (state.infile [k]) ;
- sf_close (state.outfile) ;
+ free (state) ;
- return 0 ;
+ return ret ;
} /* main */
/*------------------------------------------------------------------------------
static void
-usage_exit (void)
+print_usage (void)
{ puts ("\nUsage : sndfile-interleave <input 1> <input 2> ... -o <output file>\n") ;
puts ("Merge two or more mono files into a single multi-channel file.\n") ;
printf ("Using %s.\n\n", sf_version_string ()) ;
- exit (1) ;
-} /* usage_exit */
+} /* print_usage */
static void
{ max_read_len = 0 ;
for (ch = 0 ; ch < state->channels ; ch ++)
- { read_len = sf_read_int (state->infile [ch], state->din.i, BUFFER_LEN) ;
+ { read_len = (int) sf_read_int (state->infile [ch], state->din.i, BUFFER_LEN) ;
if (read_len < BUFFER_LEN)
memset (state->din.i + read_len, 0, sizeof (state->din.i [0]) * (BUFFER_LEN - read_len)) ;
{ max_read_len = 0 ;
for (ch = 0 ; ch < state->channels ; ch ++)
- { read_len = sf_read_double (state->infile [ch], state->din.d, BUFFER_LEN) ;
+ { read_len = (int) sf_read_double (state->infile [ch], state->din.d, BUFFER_LEN) ;
if (read_len < BUFFER_LEN)
memset (state->din.d + read_len, 0, sizeof (state->din.d [0]) * (BUFFER_LEN - read_len)) ;
#elif HAVE_SNDIO_H
#include <sndio.h>
-#elif (defined (sun) && defined (unix))
+#elif (defined (sun) && defined (unix)) || defined(__NetBSD__)
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/audioio.h>
return 0 ;
break ;
+#if defined ESTRPIPE && ESTRPIPE != EPIPE
case -ESTRPIPE :
fprintf (stderr, "alsa_write_float: Suspend event.n") ;
return 0 ;
break ;
+#endif
case -EIO :
puts ("alsa_write_float: EIO") ;
** Solaris.
*/
-#if (defined (sun) && defined (unix)) /* ie Solaris */
+#if (defined (sun) && defined (unix)) || defined(__NetBSD__)
static void
solaris_play (int argc, char *argv [])
audio_info.play.channels = sfinfo.channels ;
audio_info.play.precision = 16 ;
audio_info.play.encoding = AUDIO_ENCODING_LINEAR ;
- audio_info.play.gain = AUDIO_MAX_GAIN ;
- audio_info.play.balance = AUDIO_MID_BALANCE ;
if ((error = ioctl (audio_fd, AUDIO_SETINFO, &audio_info)))
{ perror ("ioctl (AUDIO_SETINFO) failed") ;
return ;
} /* solaris_play */
-#endif /* Solaris */
+#endif /* Solaris or NetBSD */
/*==============================================================================
** Main function.
opensoundsys_play (argc, argv) ;
#elif HAVE_SNDIO_H
sndio_play (argc, argv) ;
-#elif (defined (sun) && defined (unix))
+#elif (defined (sun) && defined (unix)) || defined(__NetBSD__)
solaris_play (argc, argv) ;
#elif (OS_IS_WIN32 == 1)
win32_play (argc, argv) ;
#define NOT(x) (! (x))
+#ifndef _WIN32
+typedef off_t sf_off_t ;
+#else
+typedef long long sf_off_t ;
+#endif
+
static void usage_exit (const char *progname) ;
static void salvage_file (const char * broken_wav, const char * fixed_w64) ;
/*==============================================================================
*/
-static void lseek_or_die (int fd, off_t offset, int whence) ;
-static sf_count_t get_file_length (int fd, const char * name) ;
+static void lseek_or_die (int fd, sf_off_t offset, int whence) ;
+static sf_off_t get_file_length (int fd, const char * name) ;
static sf_count_t find_data_offset (int fd, int format) ;
static void copy_data (int fd, SNDFILE * sndfile, int readsize) ;
*/
static void
-lseek_or_die (int fd, off_t offset, int whence)
+lseek_or_die (int fd, sf_off_t offset, int whence)
{
+#ifndef _WIN32
if (lseek (fd, offset, whence) < 0)
+#else
+ if (_lseeki64 (fd, offset, whence) < 0)
+#endif
{ printf ("lseek failed : %s\n", strerror (errno)) ;
exit (1) ;
} ;
} /* lseek_or_die */
-static sf_count_t
+static sf_off_t
get_file_length (int fd, const char * name)
-{ struct stat sbuf ;
+{
+#ifndef _WIN32
+ struct stat sbuf ;
+#else
+ struct _stat64 sbuf ;
+#endif
if (sizeof (sbuf.st_size) != 8)
{ puts ("Error : sizeof (sbuf.st_size) != 8. Was program compiled with\n"
exit (1) ;
} ;
+#ifndef _WIN32
if (fstat (fd, &sbuf) != 0)
+#else
+ if (_fstat64 (fd, &sbuf) != 0)
+#endif
{ printf ("Error : fstat ('%s') failed : %s\n", name, strerror (errno)) ;
exit (1) ;
} ;
exit (1) ;
} ;
- slen = strlen (target) ;
+ slen = (int) strlen (target) ;
lseek_or_die (fd, 0, SEEK_SET) ;
int
db_list_all (REG_DB * db_handle)
{
- printf ("%s : %p\n", __func__, db_handle) ;
+ printf ("%s : %p\n", __func__, (void *) db_handle) ;
return 0 ;
} /* db_list_all */
int
db_del_entry (REG_DB * db_handle, const char * entry)
{
- printf ("%s : %p %s\n", __func__, db_handle, entry) ;
+ printf ("%s : %p %s\n", __func__, (void *) db_handle, entry) ;
return 0 ;
} /* db_del_entry */
get_filename_pathname (REGTEST_DB * db, const char *filepath)
{
const char * basename = db_basename (filepath) ;
- int slen ;
+ size_t slen ;
/* Test for a relative path
*/
Name: sndfile
Description: A library for reading and writing audio files
Requires:
-Requires.private: @EXTERNAL_XIPH_REQUIRE@
+Requires.private: @EXTERNAL_XIPH_REQUIRE@ @EXTERNAL_MPEG_REQUIRE@
Version: @VERSION@
Libs: -L${libdir} -lsndfile
+Libs.private: @EXTERNAL_MPEG_LIBS@
Cflags: -I${includedir}
#if __GNUC__
#define ALWAYS_INLINE __attribute__ ((always_inline))
+#elif defined _MSC_VER
+#define ALWAYS_INLINE __forceinline
#else
#define ALWAYS_INLINE
#endif
#if __GNUC__
#define ALWAYS_INLINE __attribute__ ((always_inline))
+#elif defined _MSC_VER
+#define ALWAYS_INLINE __forceinline
#else
#define ALWAYS_INLINE
#endif
{
int32_t mPredictor [ALAC_FRAME_LENGTH] ;
uint16_t mShiftBuffer [ALAC_FRAME_LENGTH] ;
- } ;
+ } u ;
uint32_t mNumChannels ;
} ALAC_DECODER ;
RequireAction (p->mConfig.compatibleVersion <= kALACVersion, return kALAC_IncompatibleVersion ;) ;
RequireAction ((p->mConfig.bitDepth >= 8 && p->mConfig.bitDepth <= 32), return kALAC_BadBitWidth ;) ;
- RequireAction ((p->mMixBufferU != NULL) && (p->mMixBufferV != NULL) && (p->mPredictor != NULL),
+ RequireAction ((p->mMixBufferU != NULL) && (p->mMixBufferV != NULL) && (p->u.mPredictor != NULL),
status = kALAC_MemFullError ; goto Exit ;) ;
}
else
// decompress
set_ag_params (&agParams, p->mConfig.mb, (pb * pbFactorU) / 4, p->mConfig.kb, numSamples, numSamples, p->mConfig.maxRun) ;
- status = dyn_decomp (&agParams, bits, p->mPredictor, numSamples, chanBits, &bits1) ;
+ status = dyn_decomp (&agParams, bits, p->u.mPredictor, numSamples, chanBits, &bits1) ;
RequireNoErr (status, goto Exit ;) ;
if (modeU == 0)
{
- unpc_block (p->mPredictor, p->mMixBufferU, numSamples, &coefsU [0], numU, chanBits, denShiftU) ;
+ unpc_block (p->u.mPredictor, p->mMixBufferU, numSamples, &coefsU [0], numU, chanBits, denShiftU) ;
}
else
{
// the special "numActive == 31" mode can be done in-place
- unpc_block (p->mPredictor, p->mPredictor, numSamples, NULL, 31, chanBits, 0) ;
- unpc_block (p->mPredictor, p->mMixBufferU, numSamples, &coefsU [0], numU, chanBits, denShiftU) ;
+ unpc_block (p->u.mPredictor, p->u.mPredictor, numSamples, NULL, 31, chanBits, 0) ;
+ unpc_block (p->u.mPredictor, p->mMixBufferU, numSamples, &coefsU [0], numU, chanBits, denShiftU) ;
}
}
else
//Assert (shift <= 16) ;
for (i = 0 ; i < numSamples ; i++)
- p->mShiftBuffer [i] = (uint16_t) BitBufferRead (&shiftBits, (uint8_t) shift) ;
+ p->u.mShiftBuffer [i] = (uint16_t) BitBufferRead (&shiftBits, (uint8_t) shift) ;
}
// convert 32-bit integers into output buffer
case 24:
out32 = sampleBuffer + channelIndex ;
if (bytesShifted != 0)
- copyPredictorTo24Shift (p->mMixBufferU, p->mShiftBuffer, out32, numChannels, numSamples, bytesShifted) ;
+ copyPredictorTo24Shift (p->mMixBufferU, p->u.mShiftBuffer, out32, numChannels, numSamples, bytesShifted) ;
else
copyPredictorTo24 (p->mMixBufferU, out32, numChannels, numSamples) ;
break ;
case 32:
out32 = sampleBuffer + channelIndex ;
if (bytesShifted != 0)
- copyPredictorTo32Shift (p->mMixBufferU, p->mShiftBuffer, out32, numChannels, numSamples, bytesShifted) ;
+ copyPredictorTo32Shift (p->mMixBufferU, p->u.mShiftBuffer, out32, numChannels, numSamples, bytesShifted) ;
else
copyPredictorTo32 (p->mMixBufferU, out32, numChannels, numSamples) ;
break ;
// decompress and run predictor for "left" channel
set_ag_params (&agParams, p->mConfig.mb, (pb * pbFactorU) / 4, p->mConfig.kb, numSamples, numSamples, p->mConfig.maxRun) ;
- status = dyn_decomp (&agParams, bits, p->mPredictor, numSamples, chanBits, &bits1) ;
+ status = dyn_decomp (&agParams, bits, p->u.mPredictor, numSamples, chanBits, &bits1) ;
RequireNoErr (status, goto Exit ;) ;
if (modeU == 0)
{
- unpc_block (p->mPredictor, p->mMixBufferU, numSamples, &coefsU [0], numU, chanBits, denShiftU) ;
+ unpc_block (p->u.mPredictor, p->mMixBufferU, numSamples, &coefsU [0], numU, chanBits, denShiftU) ;
}
else
{
// the special "numActive == 31" mode can be done in-place
- unpc_block (p->mPredictor, p->mPredictor, numSamples, NULL, 31, chanBits, 0) ;
- unpc_block (p->mPredictor, p->mMixBufferU, numSamples, &coefsU [0], numU, chanBits, denShiftU) ;
+ unpc_block (p->u.mPredictor, p->u.mPredictor, numSamples, NULL, 31, chanBits, 0) ;
+ unpc_block (p->u.mPredictor, p->mMixBufferU, numSamples, &coefsU [0], numU, chanBits, denShiftU) ;
}
// decompress and run predictor for "right" channel
set_ag_params (&agParams, p->mConfig.mb, (pb * pbFactorV) / 4, p->mConfig.kb, numSamples, numSamples, p->mConfig.maxRun) ;
- status = dyn_decomp (&agParams, bits, p->mPredictor, numSamples, chanBits, &bits2) ;
+ status = dyn_decomp (&agParams, bits, p->u.mPredictor, numSamples, chanBits, &bits2) ;
RequireNoErr (status, goto Exit ;) ;
if (modeV == 0)
{
- unpc_block (p->mPredictor, p->mMixBufferV, numSamples, &coefsV [0], numV, chanBits, denShiftV) ;
+ unpc_block (p->u.mPredictor, p->mMixBufferV, numSamples, &coefsV [0], numV, chanBits, denShiftV) ;
}
else
{
// the special "numActive == 31" mode can be done in-place
- unpc_block (p->mPredictor, p->mPredictor, numSamples, NULL, 31, chanBits, 0) ;
- unpc_block (p->mPredictor, p->mMixBufferV, numSamples, &coefsV [0], numV, chanBits, denShiftV) ;
+ unpc_block (p->u.mPredictor, p->u.mPredictor, numSamples, NULL, 31, chanBits, 0) ;
+ unpc_block (p->u.mPredictor, p->mMixBufferV, numSamples, &coefsV [0], numV, chanBits, denShiftV) ;
}
}
else
for (i = 0 ; i < (numSamples * 2) ; i += 2)
{
- p->mShiftBuffer [i + 0] = (uint16_t) BitBufferRead (&shiftBits, (uint8_t) shift) ;
- p->mShiftBuffer [i + 1] = (uint16_t) BitBufferRead (&shiftBits, (uint8_t) shift) ;
+ p->u.mShiftBuffer [i + 0] = (uint16_t) BitBufferRead (&shiftBits, (uint8_t) shift) ;
+ p->u.mShiftBuffer [i + 1] = (uint16_t) BitBufferRead (&shiftBits, (uint8_t) shift) ;
}
}
case 24:
out32 = sampleBuffer + channelIndex ;
unmix24 (p->mMixBufferU, p->mMixBufferV, out32, numChannels, numSamples,
- mixBits, mixRes, p->mShiftBuffer, bytesShifted) ;
+ mixBits, mixRes, p->u.mShiftBuffer, bytesShifted) ;
break ;
case 32:
out32 = sampleBuffer + channelIndex ;
unmix32 (p->mMixBufferU, p->mMixBufferV, out32, numChannels, numSamples,
- mixBits, mixRes, p->mShiftBuffer, bytesShifted) ;
+ mixBits, mixRes, p->u.mShiftBuffer, bytesShifted) ;
break ;
}
}
}
-#if 0 // ! DEBUG
+#if 1 // ! DEBUG
// if we've decoded all of our channels, bail (but not in debug b/c we want to know if we're seeing bad bits)
// - this also protects us if the config does not match the bitstream or crap data bits follow the audio bits
if (channelIndex >= numChannels)
#if __GNUC__
#define ALWAYS_INLINE __attribute__ ((always_inline))
+#elif defined _MSC_VER
+#define ALWAYS_INLINE __forceinline
#else
#define ALWAYS_INLINE
#endif
#if __GNUC__
#define ALWAYS_INLINE __attribute__ ((always_inline))
+#elif defined _MSC_VER
+#define ALWAYS_INLINE __forceinline
#else
#define ALWAYS_INLINE
#endif
#if __GNUC__
#define ALWAYS_INLINE __attribute__ ((always_inline))
+#elif defined _MSC_VER
+#define ALWAYS_INLINE __forceinline
#else
#define ALWAYS_INLINE
#endif
#if __GNUC__
#define ALWAYS_INLINE __attribute__ ((always_inline))
+#elif defined _MSC_VER
+#define ALWAYS_INLINE __forceinline
#else
#define ALWAYS_INLINE
#endif
#if __GNUC__
#define ALWAYS_INLINE __attribute__ ((always_inline))
+#elif defined _MSC_VER
+#define ALWAYS_INLINE __forceinline
#else
#define ALWAYS_INLINE
#endif
int
aiff_open (SF_PRIVATE *psf)
{ COMM_CHUNK comm_fmt ;
- int error, subformat ;
+ int error = 0, subformat ;
memset (&comm_fmt, 0, sizeof (comm_fmt)) ;
if ((psf->peak_info = peak_info_calloc (psf->sf.channels)) == NULL)
return SFE_MALLOC_FAILED ;
- /* read in rest of PEAK chunk. */
+ /* Read in rest of PEAK chunk. */
psf_binheader_readf (psf, "E44", &(psf->peak_info->version), &(psf->peak_info->timestamp)) ;
if (psf->peak_info->version != 1)
ubuf.scbuf [0] = 0 ;
/* The COMM chunk has an int aligned to an odd word boundary. Some
- ** procesors are not able to deal with this (ie bus fault) so we have
+ ** processors are not able to deal with this (ie bus fault) so we have
** to take special care.
*/
/* Can't have a decoder and an encoder at the same time so stick
- ** them in an un-named union.
+ ** them in a union.
*/
union
{ ALAC_DECODER decoder ;
ALAC_ENCODER encoder ;
- } ;
+ } u ;
char enctmpname [512] ;
FILE *enctmp ;
plac = psf->codec_data ;
if (psf->file.mode == SFM_WRITE)
- { ALAC_ENCODER *penc = &plac->encoder ;
+ { ALAC_ENCODER *penc = &plac->u.encoder ;
SF_CHUNK_INFO chunk_info ;
sf_count_t readcount ;
uint8_t kuki_data [1024] ;
/* Read in the ALAC cookie data and pass it to the init function. */
kuki_size = alac_kuki_read (psf, info->kuki_offset, u.kuki, sizeof (u.kuki)) ;
- if ((error = alac_decoder_init (&plac->decoder, u.kuki, kuki_size)) != ALAC_noErr)
+ if ((error = alac_decoder_init (&plac->u.decoder, u.kuki, kuki_size)) != ALAC_noErr)
{ psf_log_printf (psf, "*** alac_decoder_init() returned %s. ***\n", alac_error_string (error)) ;
return SFE_INTERNAL ;
} ;
- if (plac->decoder.mNumChannels != (unsigned) psf->sf.channels)
- { psf_log_printf (psf, "*** Initialized decoder has %u channels, but it should be %d. ***\n", plac->decoder.mNumChannels, psf->sf.channels) ;
+ if (plac->u.decoder.mNumChannels != (unsigned) psf->sf.channels)
+ { psf_log_printf (psf, "*** Initialized decoder has %u channels, but it should be %d. ***\n", plac->u.decoder.mNumChannels, psf->sf.channels) ;
return SFE_INTERNAL ;
} ;
return SFE_ALAC_FAIL_TMPFILE ;
} ;
- alac_encoder_init (&plac->encoder, psf->sf.samplerate, psf->sf.channels, alac_format_flags, ALAC_FRAME_LENGTH) ;
+ alac_encoder_init (&plac->u.encoder, psf->sf.samplerate, psf->sf.channels, alac_format_flags, ALAC_FRAME_LENGTH) ;
return 0 ;
} /* alac_writer_init */
static int
alac_decode_block (SF_PRIVATE *psf, ALAC_PRIVATE *plac)
-{ ALAC_DECODER *pdec = &plac->decoder ;
+{ ALAC_DECODER *pdec = &plac->u.decoder ;
uint32_t packet_size ;
BitBuffer bit_buffer ;
static int
alac_encode_block (ALAC_PRIVATE *plac)
-{ ALAC_ENCODER *penc = &plac->encoder ;
+{ ALAC_ENCODER *penc = &plac->u.encoder ;
uint32_t num_bytes = 0 ;
alac_encode (penc, plac->partial_block_frames, plac->buffer, plac->byte_buffer, &num_bytes) ;
break ;
readcount = (plac->frames_this_block - plac->partial_block_frames) * plac->channels ;
- readcount = readcount > len ? len : readcount ;
+ readcount = readcount > len ? (int) len : readcount ;
iptr = plac->buffer + plac->partial_block_frames * plac->channels ;
break ;
readcount = (plac->frames_this_block - plac->partial_block_frames) * plac->channels ;
- readcount = readcount > len ? len : readcount ;
+ readcount = readcount > len ? (int) len : readcount ;
iptr = plac->buffer + plac->partial_block_frames * plac->channels ;
break ;
readcount = (plac->frames_this_block - plac->partial_block_frames) * plac->channels ;
- readcount = readcount > len ? len : readcount ;
+ readcount = readcount > len ? (int) len : readcount ;
iptr = plac->buffer + plac->partial_block_frames * plac->channels ;
break ;
readcount = (plac->frames_this_block - plac->partial_block_frames) * plac->channels ;
- readcount = readcount > len ? len : readcount ;
+ readcount = readcount > len ? (int) len : readcount ;
iptr = plac->buffer + plac->partial_block_frames * plac->channels ;
while (len > 0)
{ writecount = (plac->frames_per_block - plac->partial_block_frames) * plac->channels ;
- writecount = (writecount == 0 || writecount > len) ? len : writecount ;
+ writecount = (writecount == 0 || writecount > len) ? (int) len : writecount ;
iptr = plac->buffer + plac->partial_block_frames * plac->channels ;
while (len > 0)
{ writecount = (plac->frames_per_block - plac->partial_block_frames) * plac->channels ;
- writecount = (writecount == 0 || writecount > len) ? len : writecount ;
+ writecount = (writecount == 0 || writecount > len) ? (int) len : writecount ;
iptr = plac->buffer + plac->partial_block_frames * plac->channels ;
while (len > 0)
{ writecount = (plac->frames_per_block - plac->partial_block_frames) * plac->channels ;
- writecount = (writecount == 0 || writecount > len) ? len : writecount ;
+ writecount = (writecount == 0 || writecount > len) ? (int) len : writecount ;
iptr = plac->buffer + plac->partial_block_frames * plac->channels ;
while (len > 0)
{ writecount = (plac->frames_per_block - plac->partial_block_frames) * plac->channels ;
- writecount = (writecount == 0 || writecount > len) ? len : writecount ;
+ writecount = (writecount == 0 || writecount > len) ? (int) len : writecount ;
iptr = plac->buffer + plac->partial_block_frames * plac->channels ;
pakt_size = chunk_info.datalen ;
chunk_info.data = pakt_data = malloc (pakt_size + 5) ;
+ if (!chunk_info.data)
+ return NULL ;
if ((bcount = psf->get_chunk_data (psf, chunk_iterator, &chunk_info)) != SF_ERR_NO_ERROR)
{ while (chunk_iterator)
count ++ ;
if (count > 5 || bcount + count > pakt_size)
- { printf ("%s %d : Ooops! count %d bcount %d\n", __func__, __LINE__, count, bcount) ;
+ { printf ("%s %d : Ooops! count %" PRIi32 " bcount %" PRIu32 "\n", __func__, __LINE__, count, bcount) ;
value = 0 ;
break ;
} ;
static inline void
alaw2s_array (unsigned char *buffer, int count, short *ptr)
-{ while (--count >= 0)
- ptr [count] = alaw_decode [(int) buffer [count]] ;
+{ for (int i = 0 ; i < count ; i++)
+ ptr [i] = alaw_decode [(int) buffer [i]] ;
} /* alaw2s_array */
static inline void
alaw2i_array (unsigned char *buffer, int count, int *ptr)
-{ while (--count >= 0)
- ptr [count] = ((uint32_t) alaw_decode [(int) buffer [count]]) << 16 ;
+{ for (int i = 0 ; i < count ; i++)
+ ptr [i] = ((uint32_t) alaw_decode [(int) buffer [i]]) << 16 ;
} /* alaw2i_array */
static inline void
alaw2f_array (unsigned char *buffer, int count, float *ptr, float normfact)
-{ while (--count >= 0)
- ptr [count] = normfact * alaw_decode [(int) buffer [count]] ;
+{ for (int i = 0 ; i < count ; i++)
+ ptr [i] = normfact * alaw_decode [(int) buffer [i]] ;
} /* alaw2f_array */
static inline void
alaw2d_array (unsigned char *buffer, int count, double *ptr, double normfact)
-{ while (--count >= 0)
- ptr [count] = normfact * alaw_decode [(int) buffer [count]] ;
+{ for (int i = 0 ; i < count ; i++)
+ ptr [i] = normfact * alaw_decode [(int) buffer [i]] ;
} /* alaw2d_array */
static inline void
s2alaw_array (const short *ptr, int count, unsigned char *buffer)
-{ while (--count >= 0)
- { if (ptr [count] >= 0)
- buffer [count] = alaw_encode [ptr [count] / 16] ;
+{ for (int i = 0 ; i < count ; i++)
+ { if (ptr [i] >= 0)
+ buffer [i] = alaw_encode [ptr [i] / 16] ;
else
- buffer [count] = 0x7F & alaw_encode [ptr [count] / -16] ;
+ buffer [i] = 0x7F & alaw_encode [ptr [i] / -16] ;
} ;
} /* s2alaw_array */
static inline void
i2alaw_array (const int *ptr, int count, unsigned char *buffer)
-{ while (--count >= 0)
- { if (ptr [count] == INT_MIN)
- buffer [count] = alaw_encode [INT_MAX >> (16 + 4)] ;
- else if (ptr [count] >= 0)
- buffer [count] = alaw_encode [ptr [count] >> (16 + 4)] ;
+{ for (int i = 0 ; i < count ; i++)
+ { if (ptr [i] == INT_MIN)
+ buffer [i] = alaw_encode [INT_MAX >> (16 + 4)] ;
+ else if (ptr [i] >= 0)
+ buffer [i] = alaw_encode [ptr [i] >> (16 + 4)] ;
else
- buffer [count] = 0x7F & alaw_encode [- ptr [count] >> (16 + 4)] ;
+ buffer [i] = 0x7F & alaw_encode [- ptr [i] >> (16 + 4)] ;
} ;
} /* i2alaw_array */
static inline void
f2alaw_array (const float *ptr, int count, unsigned char *buffer, float normfact)
-{ while (--count >= 0)
- { if (ptr [count] >= 0)
- buffer [count] = alaw_encode [psf_lrintf (normfact * ptr [count])] ;
+{ for (int i = 0 ; i < count ; i++)
+ { if (ptr [i] >= 0)
+ buffer [i] = alaw_encode [psf_lrintf (normfact * ptr [i])] ;
else
- buffer [count] = 0x7F & alaw_encode [- psf_lrintf (normfact * ptr [count])] ;
+ buffer [i] = 0x7F & alaw_encode [- psf_lrintf (normfact * ptr [i])] ;
} ;
} /* f2alaw_array */
static inline void
d2alaw_array (const double *ptr, int count, unsigned char *buffer, double normfact)
-{ while (--count >= 0)
- { if (!isfinite (ptr [count]))
- buffer [count] = 0 ;
- else if (ptr [count] >= 0)
- buffer [count] = alaw_encode [psf_lrint (normfact * ptr [count])] ;
+{ for (int i = 0 ; i < count ; i++)
+ { if (!isfinite (ptr [i]))
+ buffer [i] = 0 ;
+ else if (ptr [i] >= 0)
+ buffer [i] = alaw_encode [psf_lrint (normfact * ptr [i])] ;
else
- buffer [count] = 0x7F & alaw_encode [- psf_lrint (normfact * ptr [count])] ;
+ buffer [i] = 0x7F & alaw_encode [- psf_lrint (normfact * ptr [i])] ;
} ;
} /* d2alaw_array */
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.ucbuf, 1, bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.ucbuf, 1, bufferlen, psf) ;
alaw2s_array (ubuf.ucbuf, readcount, ptr + total) ;
total += readcount ;
if (readcount < bufferlen)
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.ucbuf, 1, bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.ucbuf, 1, bufferlen, psf) ;
alaw2i_array (ubuf.ucbuf, readcount, ptr + total) ;
total += readcount ;
if (readcount < bufferlen)
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.ucbuf, 1, bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.ucbuf, 1, bufferlen, psf) ;
alaw2f_array (ubuf.ucbuf, readcount, ptr + total, normfact) ;
total += readcount ;
if (readcount < bufferlen)
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.ucbuf, 1, bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.ucbuf, 1, bufferlen, psf) ;
alaw2d_array (ubuf.ucbuf, readcount, ptr + total, normfact) ;
total += readcount ;
if (readcount < bufferlen)
{ if (len < bufferlen)
bufferlen = (int) len ;
s2alaw_array (ptr + total, bufferlen, ubuf.ucbuf) ;
- writecount = psf_fwrite (ubuf.ucbuf, 1, bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.ucbuf, 1, bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
{ if (len < bufferlen)
bufferlen = (int) len ;
i2alaw_array (ptr + total, bufferlen, ubuf.ucbuf) ;
- writecount = psf_fwrite (ubuf.ucbuf, 1, bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.ucbuf, 1, bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
{ if (len < bufferlen)
bufferlen = (int) len ;
f2alaw_array (ptr + total, bufferlen, ubuf.ucbuf, normfact) ;
- writecount = psf_fwrite (ubuf.ucbuf, 1, bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.ucbuf, 1, bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
{ if (len < bufferlen)
bufferlen = (int) len ;
d2alaw_array (ptr + total, bufferlen, ubuf.ucbuf, normfact) ;
- writecount = psf_fwrite (ubuf.ucbuf, 1, bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.ucbuf, 1, bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
#define TWOBIT_MARKER (MAKE_MARKER ('2', 'B', 'I', 'T'))
#define AVR_HDR_SIZE 128
-#define SFE_AVR_X 666
-
/*
** From: hyc@hanauma.Jpl.Nasa.Gov (Howard Chu)
**
psf_log_printf (psf, "%M\n", hdr.marker) ;
if (hdr.marker != TWOBIT_MARKER)
- return SFE_AVR_X ;
+ return SFE_AVR_NOT_AVR ;
psf_log_printf (psf, " Name : %s\n", hdr.name) ;
default :
psf_log_printf (psf, "Error : bad rez/sign combination.\n") ;
- return SFE_AVR_X ;
+ return SFE_AVR_BAD_REZ_SIGN ;
} ;
psf_binheader_readf (psf, "E4444", &hdr.srate, &hdr.frames, &hdr.lbeg, &hdr.lend) ;
/* Force coding_history_size to be even. */
len = strlen (psf->broadcast_16k->coding_history) ;
len += (len & 1) ? 1 : 0 ;
- psf->broadcast_16k->coding_history_size = len ;
+ psf->broadcast_16k->coding_history_size = (uint32_t) len ;
/* Currently writing this version. */
psf->broadcast_16k->version = 2 ;
break ;
default :
- snprintf (chnstr, sizeof (chnstr), "%uchn", psfinfo->channels) ;
+ snprintf (chnstr, sizeof (chnstr), "%dchn", psfinfo->channels) ;
break ;
} ;
} ;
count = snprintf (added_history, added_history_max,
- "A=PCM,F=%u,W=%d,M=%s,T=%s-%s\r\n",
+ "A=PCM,F=%d,W=%d,M=%s,T=%s-%s\r\n",
psfinfo->samplerate, width, chnstr, PACKAGE_NAME, PACKAGE_VERSION) ;
if (count >= added_history_max)
#define CAF_PEAK_CHUNK_SIZE(ch) ((int) (sizeof (int) + ch * (sizeof (float) + 8)))
-#define SFE_CAF_NOT_CAF 666
-#define SFE_CAF_NO_DESC 667
-#define SFE_CAF_BAD_PEAK 668
-
/*------------------------------------------------------------------------------
** Typedefs.
*/
{ case peak_MARKER :
psf_log_printf (psf, "%M : %D\n", marker, chunk_size) ;
if (chunk_size != CAF_PEAK_CHUNK_SIZE (psf->sf.channels))
- { psf_binheader_readf (psf, "j", make_size_t (chunk_size)) ;
+ { psf_binheader_readf (psf, "j", (size_t) chunk_size) ;
psf_log_printf (psf, "*** File PEAK chunk %D should be %d.\n", chunk_size, CAF_PEAK_CHUNK_SIZE (psf->sf.channels)) ;
return SFE_CAF_BAD_PEAK ;
} ;
+ if (psf->peak_info)
+ { psf_log_printf (psf, "*** Found existing peak info, using last one.\n") ;
+ free (psf->peak_info) ;
+ psf->peak_info = NULL ;
+ } ;
if ((psf->peak_info = peak_info_calloc (psf->sf.channels)) == NULL)
return SFE_MALLOC_FAILED ;
case chan_MARKER :
if (chunk_size < 12)
{ psf_log_printf (psf, "%M : %D (should be >= 12)\n", marker, chunk_size) ;
- psf_binheader_readf (psf, "j", make_size_t (chunk_size)) ;
+ psf_binheader_readf (psf, "j", (size_t) chunk_size) ;
break ;
}
case free_MARKER :
psf_log_printf (psf, "%M : %D\n", marker, chunk_size) ;
- psf_binheader_readf (psf, "j", make_size_t (chunk_size)) ;
+ psf_binheader_readf (psf, "j", (size_t) chunk_size) ;
break ;
case data_MARKER :
if (psf->datalength + psf->dataoffset < psf->filelength)
psf->dataend = psf->datalength + psf->dataoffset ;
- psf_binheader_readf (psf, "j", make_size_t (psf->datalength)) ;
+ psf_binheader_readf (psf, "j", (size_t) psf->datalength) ;
have_data = 1 ;
break ;
case kuki_MARKER :
psf_log_printf (psf, "%M : %D\n", marker, chunk_size) ;
pcaf->alac.kuki_offset = psf_ftell (psf) - 12 ;
- psf_binheader_readf (psf, "j", make_size_t (chunk_size)) ;
+ psf_binheader_readf (psf, "j", (size_t) chunk_size) ;
break ;
case pakt_MARKER :
psf_log_printf (psf, "*** 'pakt' chunk header is all zero.\n") ;
pcaf->alac.pakt_offset = psf_ftell (psf) - 12 ;
- psf_binheader_readf (psf, "j", make_size_t (chunk_size) - 24) ;
+ psf_binheader_readf (psf, "j", (size_t) chunk_size - 24) ;
break ;
case info_MARKER :
default :
psf_log_printf (psf, "%M : %D (skipped)\n", marker, chunk_size) ;
- psf_binheader_readf (psf, "j", make_size_t (chunk_size)) ;
+ psf_binheader_readf (psf, "j", (size_t) chunk_size) ;
break ;
} ;
if ((buf = malloc (chunk_size + 1)) == NULL)
return (psf->error = SFE_MALLOC_FAILED) ;
- psf_binheader_readf (psf, "E4b", &count, buf, make_size_t (chunk_size)) ;
+ psf_binheader_readf (psf, "E4b", &count, buf, (size_t) chunk_size) ;
psf_log_printf (psf, " count: %u\n", count) ;
/* Force terminate `buf` to make sure. */
len = strlen (psf->cart_16k->tag_text) ;
len += (len & 1) ? 1 : 2 ;
- psf->cart_16k->tag_text_size = len ;
+ psf->cart_16k->tag_text_size = (uint32_t) len ;
return SF_TRUE ;
} /* cart_var_set */
hash = marker_len > 4 ? hash_of_str (marker_str) : u.marker ;
memcpy (psf->iterator->id, marker_str, marker_len) ;
- psf->iterator->id_size = marker_len ;
+ psf->iterator->id_size = (unsigned) marker_len ;
psf->iterator->hash = hash ;
}
{ pchk->used = 0 ;
pchk->count = 20 ;
pchk->chunks = calloc (pchk->count, sizeof (READ_CHUNK)) ;
+ if (!pchk->chunks)
+ { return SFE_MALLOC_FAILED ;
+ } ;
}
else if (pchk->used > pchk->count)
return SFE_INTERNAL ;
rchunk.offset = offset ;
rchunk.len = len ;
- rchunk.id_size = marker_len > 64 ? 64 : marker_len ;
+ rchunk.id_size = marker_len > 64 ? 64 : (unsigned) marker_len ;
memcpy (rchunk.id, marker_str, rchunk.id_size) ;
return psf_store_read_chunk (pchk, &rchunk) ;
{ pchk->used = 0 ;
pchk->count = 20 ;
pchk->chunks = calloc (pchk->count, sizeof (WRITE_CHUNK)) ;
+ if (!pchk->chunks)
+ { return SFE_MALLOC_FAILED ;
+ } ;
}
else if (pchk->used >= pchk->count)
{ WRITE_CHUNK * old_ptr = pchk->chunks ;
},
#endif
+#if HAVE_MPEG
+ { SF_FORMAT_MPEG | SF_FORMAT_MPEG_LAYER_III,
+ "MPEG Layer 3", "mp3"
+ },
+#endif
+
{ SF_FORMAT_RAW | SF_FORMAT_VOX_ADPCM,
"OKI Dialogic VOX ADPCM", "vox"
},
{ SF_FORMAT_MAT4, "MAT4 (GNU Octave 2.0 / Matlab 4.2)", "mat" },
{ SF_FORMAT_MAT5, "MAT5 (GNU Octave 2.1 / Matlab 5.0)", "mat" },
{ SF_FORMAT_MPC2K, "MPC (Akai MPC 2k)", "mpc" },
+#if HAVE_MPEG
+ { SF_FORMAT_MPEG, "MPEG-1/2 Audio", "m1a" },
+#endif
#if HAVE_EXTERNAL_XIPH_LIBS
{ SF_FORMAT_OGG, "OGG (OGG Container format)", "oga" },
#endif
{ SF_FORMAT_OPUS, "Opus", NULL },
#endif
+#if HAVE_MPEG
+ { SF_FORMAT_MPEG_LAYER_I, "MPEG Layer I", "mp1" },
+ { SF_FORMAT_MPEG_LAYER_II, "MPEG Layer II", "mp2" },
+ { SF_FORMAT_MPEG_LAYER_III, "MPEG Layer III", "mp3" },
+#endif
+
{ SF_FORMAT_ALAC_16, "16 bit ALAC", NULL },
{ SF_FORMAT_ALAC_20, "20 bit ALAC", NULL },
{ SF_FORMAT_ALAC_24, "24 bit ALAC", NULL },
len = ARRAY_LEN (ubuf.dbuf) - (ARRAY_LEN (ubuf.dbuf) % psf->sf.channels) ;
for (readcount = 1, max_val = 0.0 ; readcount > 0 ; /* nothing */)
- { readcount = sf_read_double ((SNDFILE*) psf, data, len) ;
+ { readcount = (int) sf_read_double ((SNDFILE*) psf, data, len) ;
for (k = 0 ; k < readcount ; k++)
{ temp = fabs (data [k]) ;
max_val = temp > max_val ? temp : max_val ;
chan = 0 ;
readcount = len ;
while (readcount > 0)
- { readcount = sf_read_double ((SNDFILE*) psf, data, len) ;
+ { readcount = (int) sf_read_double ((SNDFILE*) psf, data, len) ;
for (k = 0 ; k < readcount ; k++)
{ temp = fabs (data [k]) ;
peaks [chan] = temp > peaks [chan] ? temp : peaks [chan] ;
void
psf_log_printf (SF_PRIVATE *psf, const char *format, ...)
{ va_list ap ;
- uint32_t u ;
- int d, tens, shift, width, width_specifier, left_align, slen ;
+ uint32_t u, tens ;
+ int d, shift, width, width_specifier, left_align, slen, precision ;
char c, *strptr, istr [5], lead_char, sign_char ;
va_start (ap, format) ;
while ((c = *format++) && isdigit (c))
width_specifier = width_specifier * 10 + (c - '0') ;
+ precision = 0 ;
+ if (c == '.')
+ { while ((c = *format++) && isdigit (c))
+ precision = precision * 10 + (c - '0') ;
+ } ;
+
switch (c)
{ case 0 : /* NULL character. */
va_end (ap) ;
strptr = va_arg (ap, char *) ;
if (strptr == NULL)
break ;
- slen = strlen (strptr) ;
+ if (precision > 0)
+ slen = strnlen (strptr, precision) ;
+ else
+ slen = strlen (strptr) ;
width_specifier = width_specifier >= slen ? width_specifier - slen : 0 ;
if (left_align == SF_FALSE)
while (width_specifier -- > 0)
log_putchar (psf, ' ') ;
- while (*strptr)
+ while (slen--)
log_putchar (psf, *strptr++) ;
while (width_specifier -- > 0)
log_putchar (psf, ' ') ;
d = va_arg (ap, int) ;
if (d < 0)
- { d = -d ;
- sign_char = '-' ;
+ { sign_char = '-' ;
if (lead_char != '0' && left_align == SF_FALSE)
width_specifier -- ;
- } ;
+
+ u = - ((unsigned) d) ;
+ }
+ else
+ { u = (unsigned) d ;
+ }
tens = 1 ;
width = 1 ;
- while (d / tens >= 10)
+ while (u / tens >= 10)
{ tens *= 10 ;
width ++ ;
} ;
log_putchar (psf, lead_char) ;
while (tens > 0)
- { log_putchar (psf, '0' + d / tens) ;
- d %= tens ;
+ { log_putchar (psf, '0' + u / tens) ;
+ u %= tens ;
tens /= 10 ;
} ;
break ;
case 'D': /* sf_count_t */
- { sf_count_t D, Tens ;
+ { sf_count_t D ;
+ uint64_t U, Tens ;
D = va_arg (ap, sf_count_t) ;
log_putchar (psf, '0') ;
break ;
}
- if (D < 0)
- { log_putchar (psf, '-') ;
- D = -D ;
- } ;
+ else
+ { if (D < 0)
+ { log_putchar (psf, '-') ;
+ U = -((uint64_t) D) ;
+ }
+ else
+ { U = (uint64_t) D;
+ }
+ }
+
Tens = 1 ;
width = 1 ;
- while (D / Tens >= 10)
+ while (U / Tens >= 10)
{ Tens *= 10 ;
width ++ ;
} ;
} ;
while (Tens > 0)
- { log_putchar (psf, '0' + D / Tens) ;
- D %= Tens ;
+ { log_putchar (psf, '0' + U / Tens) ;
+ U %= Tens ;
Tens /= 10 ;
} ;
} ;
static inline void
header_put_be_8byte (SF_PRIVATE *psf, sf_count_t x)
{ psf->header.ptr [psf->header.indx++] = (x >> 56) ;
- psf->header.ptr [psf->header.indx++] = (x >> 48) ;
- psf->header.ptr [psf->header.indx++] = (x >> 40) ;
- psf->header.ptr [psf->header.indx++] = (x >> 32) ;
- psf->header.ptr [psf->header.indx++] = (x >> 24) ;
- psf->header.ptr [psf->header.indx++] = (x >> 16) ;
- psf->header.ptr [psf->header.indx++] = (x >> 8) ;
- psf->header.ptr [psf->header.indx++] = x ;
+ psf->header.ptr [psf->header.indx++] = (unsigned char) (x >> 48) ;
+ psf->header.ptr [psf->header.indx++] = (unsigned char) (x >> 40) ;
+ psf->header.ptr [psf->header.indx++] = (unsigned char) (x >> 32) ;
+ psf->header.ptr [psf->header.indx++] = (unsigned char) (x >> 24) ;
+ psf->header.ptr [psf->header.indx++] = (unsigned char) (x >> 16) ;
+ psf->header.ptr [psf->header.indx++] = (unsigned char) (x >> 8) ;
+ psf->header.ptr [psf->header.indx++] = (unsigned char) x ;
} /* header_put_be_8byte */
static inline void
header_put_le_8byte (SF_PRIVATE *psf, sf_count_t x)
-{ psf->header.ptr [psf->header.indx++] = x ;
- psf->header.ptr [psf->header.indx++] = (x >> 8) ;
- psf->header.ptr [psf->header.indx++] = (x >> 16) ;
- psf->header.ptr [psf->header.indx++] = (x >> 24) ;
- psf->header.ptr [psf->header.indx++] = (x >> 32) ;
- psf->header.ptr [psf->header.indx++] = (x >> 40) ;
- psf->header.ptr [psf->header.indx++] = (x >> 48) ;
+{ psf->header.ptr [psf->header.indx++] = (unsigned char) x ;
+ psf->header.ptr [psf->header.indx++] = (unsigned char) (x >> 8) ;
+ psf->header.ptr [psf->header.indx++] = (unsigned char) (x >> 16) ;
+ psf->header.ptr [psf->header.indx++] = (unsigned char) (x >> 24) ;
+ psf->header.ptr [psf->header.indx++] = (unsigned char) (x >> 32) ;
+ psf->header.ptr [psf->header.indx++] = (unsigned char) (x >> 40) ;
+ psf->header.ptr [psf->header.indx++] = (unsigned char) (x >> 48) ;
psf->header.ptr [psf->header.indx++] = (x >> 56) ;
} /* header_put_le_8byte */
while ((c = *format++))
{
if (psf->header.indx + 16 >= psf->header.len && psf_bump_header_allocation (psf, 16))
- return count ;
+ break ;
switch (c)
{ case ' ' : /* Do nothing. Just used to space out format string. */
size = strlen (strptr) + 1 ;
if (psf->header.indx + 4 + (sf_count_t) size + (sf_count_t) (size & 1) > psf->header.len && psf_bump_header_allocation (psf, 4 + size + (size & 1)))
- return count ;
+ break ;
if (psf->rwf_endian == SF_ENDIAN_BIG)
header_put_be_int (psf, size + (size & 1)) ;
strptr = va_arg (argptr, char *) ;
size = strlen (strptr) ;
if (psf->header.indx + 4 + (sf_count_t) size + (sf_count_t) (size & 1) > psf->header.len && psf_bump_header_allocation (psf, 4 + size + (size & 1)))
- return count ;
+ break ;
if (psf->rwf_endian == SF_ENDIAN_BIG)
header_put_be_int (psf, size) ;
else
size = (size > 254) ? 254 : size ;
if (psf->header.indx + 1 + (sf_count_t) size > psf->header.len && psf_bump_header_allocation (psf, 1 + size))
- return count ;
+ break ;
header_put_byte (psf, size) ;
memcpy (&(psf->header.ptr [psf->header.indx]), strptr, size) ;
size = va_arg (argptr, size_t) ;
if (psf->header.indx + (sf_count_t) size > psf->header.len && psf_bump_header_allocation (psf, size))
- return count ;
+ break ;
memcpy (&(psf->header.ptr [psf->header.indx]), bindata, size) ;
psf->header.indx += size ;
size = va_arg (argptr, size_t) ;
if (psf->header.indx + (sf_count_t) size > psf->header.len && psf_bump_header_allocation (psf, size))
- return count ;
+ break ;
count += size ;
while (size)
size = va_arg (argptr, size_t) ;
if (psf->header.indx + (sf_count_t) size > psf->header.len && psf_bump_header_allocation (psf, size))
- return count ;
+ break ;
psf->header.indx += size ;
count += size ;
size = va_arg (argptr, size_t) ;
if ((sf_count_t) size >= psf->header.len && psf_bump_header_allocation (psf, size))
- return count ;
+ break ;
psf->header.indx = size ;
break ;
psf_bump_header_allocation (psf, position) ;
if (position > psf->header.len)
{ /* Too much header to cache so just seek instead. */
- psf->header.indx = psf->header.end ;
+ psf->header.indx = psf->header.end = 0 ;
psf_fseek (psf, position, whence) ;
return ;
} ;
psf_binheader_readf (SF_PRIVATE *psf, char const *format, ...)
{ va_list argptr ;
sf_count_t *countptr, countdata ;
- unsigned char *ucptr, sixteen_bytes [16] ;
+ unsigned char *ucptr, sixteen_bytes [16] = { 0 } ;
unsigned int *intptr, intdata ;
unsigned short *shortptr ;
char *charptr ;
while ((c = *format++))
{
if (psf->header.indx + 16 >= psf->header.len && psf_bump_header_allocation (psf, 16))
- return count ;
+ break ;
switch (c)
{ case 'e' : /* All conversions are now from LE to host. */
memset (charptr, 0, count) ;
if (psf->header.indx + count >= psf->header.len && psf_bump_header_allocation (psf, count))
- return 0 ;
+ break ;
byte_count += header_gets (psf, charptr, count) ;
break ;
byte_count += count ;
break ;
+ case '!' : /* Clear buffer, forcing re-read. */
+ psf->header.end = psf->header.indx = 0 ;
+ break ;
+
default :
psf_log_printf (psf, "*** Invalid format specifier `%c'\n", c) ;
psf->error = SFE_INTERNAL ;
/*========================================================================================
*/
+int
+psf_isprint (int ch)
+{ return (ch >= ' ' && ch <= '~') ;
+} /* psf_isprint */
+
+void
+psf_strlcat (char *dest, size_t n, const char *src)
+{ strncat (dest, src, n - strlen (dest) - 1) ;
+ dest [n - 1] = 0 ;
+} /* psf_strlcat */
+
+void
+psf_strlcpy (char *dest, size_t n, const char *src)
+{ strncpy (dest, src, n - 1) ;
+ dest [n - 1] = 0 ;
+} /* psf_strlcpy */
+
+/*========================================================================================
+*/
+
+void *
+psf_memdup (const void *src, size_t n)
+{ if (src == NULL)
+ return NULL ;
+
+ void * mem = calloc (1, n & 3 ? n + 4 - (n & 3) : n) ;
+ if (mem != NULL)
+ memcpy (mem, src, n) ;
+ return mem ;
+} /* psf_memdup */
+
void*
psf_memset (void *s, int c, sf_count_t len)
{ char *ptr ;
** bodgy something up instead.
*/
+#ifdef _MSC_VER
typedef SF_CUES_VAR (0) SF_CUES_0 ;
+#else
+typedef SF_CUES_VAR () SF_CUES_0 ;
+#endif
/* calculate size of SF_CUES struct given number of cues */
#define SF_CUES_VAR_SIZE(count) (sizeof (SF_CUES_0) + count * sizeof (SF_CUE_POINT))
SF_CUES *
psf_cues_alloc (uint32_t cue_count)
{ SF_CUES *pcues = calloc (1, SF_CUES_VAR_SIZE (cue_count)) ;
-
- pcues->cue_count = cue_count ;
+ if (pcues)
+ { pcues->cue_count = cue_count ;
+ } ;
return pcues ;
} /* psf_cues_alloc */
CASE_NAME (SF_FORMAT_CAF) ;
CASE_NAME (SF_FORMAT_WVE) ;
CASE_NAME (SF_FORMAT_OGG) ;
+ CASE_NAME (SF_FORMAT_MPEG) ;
default :
break ;
} ;
CASE_NAME (SF_FORMAT_DPCM_8) ;
CASE_NAME (SF_FORMAT_DPCM_16) ;
CASE_NAME (SF_FORMAT_VORBIS) ;
+ CASE_NAME (SF_FORMAT_MPEG_LAYER_I) ;
+ CASE_NAME (SF_FORMAT_MPEG_LAYER_II) ;
+ CASE_NAME (SF_FORMAT_MPEG_LAYER_III) ;
default :
break ;
} ;
{ float normfact ;
normfact = normalize ? (1.0 * 0x7FFF) : 1.0 ;
- while (--count >= 0)
- dest [count] = psf_lrintf (src [count] * normfact) ;
+ for (int i = 0 ; i < count ; i++)
+ dest [i] = psf_lrintf (src [i] * normfact) ;
return ;
} /* psf_f2s_array */
normfact = normalize ? (1.0 * 0x8000) : 1.0 ;
- while (--count >= 0)
- { scaled_value = src [count] * normfact ;
- if (CPU_CLIPS_POSITIVE == 0 && scaled_value >= (1.0 * 0x7FFF))
- { dest [count] = 0x7FFF ;
+ for (int i = 0 ; i < count ; i++)
+ { scaled_value = src [i] * normfact ;
+#if CPU_CLIPS_POSITIVE == 0
+ if (scaled_value >= (1.0 * 0x7FFF))
+ { dest [i] = 0x7FFF ;
continue ;
} ;
- if (CPU_CLIPS_NEGATIVE == 0 && scaled_value <= (-8.0 * 0x1000))
- { dest [count] = 0x8000 ;
+#endif
+#if CPU_CLIPS_NEGATIVE == 0
+ if (scaled_value <= (-8.0 * 0x1000))
+ { dest [i] = -0x7FFF - 1 ;
continue ;
} ;
+#endif
- dest [count] = psf_lrintf (scaled_value) ;
+ dest [i] = psf_lrintf (scaled_value) ;
} ;
return ;
{ double normfact ;
normfact = normalize ? (1.0 * 0x7FFF) : 1.0 ;
- while (--count >= 0)
- dest [count] = psf_lrint (src [count] * normfact) ;
+ for (int i = 0 ; i < count ; i++)
+ dest [i] = psf_lrint (src [i] * normfact) ;
return ;
} /* psf_f2s_array */
normfact = normalize ? (1.0 * 0x8000) : 1.0 ;
- while (--count >= 0)
- { scaled_value = src [count] * normfact ;
- if (CPU_CLIPS_POSITIVE == 0 && scaled_value >= (1.0 * 0x7FFF))
- { dest [count] = 0x7FFF ;
+ for (int i = 0 ; i < count ; i++)
+ { scaled_value = src [i] * normfact ;
+#if CPU_CLIPS_POSITIVE == 0
+ if (scaled_value >= (1.0 * 0x7FFF))
+ { dest [i] = 0x7FFF ;
continue ;
} ;
- if (CPU_CLIPS_NEGATIVE == 0 && scaled_value <= (-8.0 * 0x1000))
- { dest [count] = 0x8000 ;
+#endif
+#if CPU_CLIPS_NEGATIVE == 0
+ if (scaled_value <= (-8.0 * 0x1000))
+ { dest [i] = -0x7FFF - 1 ;
continue ;
} ;
+#endif
- dest [count] = psf_lrint (scaled_value) ;
+ dest [i] = psf_lrint (scaled_value) ;
} ;
return ;
{ float normfact ;
normfact = normalize ? (1.0 * 0x7FFFFFFF) : 1.0 ;
- while (--count >= 0)
- dest [count] = psf_lrintf (src [count] * normfact) ;
+ for (int i = 0 ; i < count ; i++)
+ dest [i] = psf_lrintf (src [i] * normfact) ;
return ;
} /* psf_f2i_array */
normfact = normalize ? (8.0 * 0x10000000) : 1.0 ;
- while (--count >= 0)
- { scaled_value = src [count] * normfact ;
- if (CPU_CLIPS_POSITIVE == 0 && scaled_value >= (1.0 * 0x7FFFFFFF))
- { dest [count] = 0x7FFFFFFF ;
+ for (int i = 0 ; i < count ; i++)
+ { scaled_value = src [i] * normfact ;
+#if CPU_CLIPS_POSITIVE == 0
+ if (scaled_value >= (1.0 * 0x7FFFFFFF))
+ { dest [i] = 0x7FFFFFFF ;
continue ;
} ;
- if (CPU_CLIPS_NEGATIVE == 0 && scaled_value <= (-8.0 * 0x10000000))
- { dest [count] = 0x80000000 ;
+#endif
+#if CPU_CLIPS_NEGATIVE == 0
+ if (scaled_value <= (-8.0 * 0x10000000))
+ { dest [i] = 0x80000000 ;
continue ;
} ;
+#endif
- dest [count] = psf_lrintf (scaled_value) ;
+ dest [i] = psf_lrintf (scaled_value) ;
} ;
return ;
{ double normfact ;
normfact = normalize ? (1.0 * 0x7FFFFFFF) : 1.0 ;
- while (--count >= 0)
- dest [count] = psf_lrint (src [count] * normfact) ;
+ for (int i = 0 ; i < count ; i++)
+ dest [i] = psf_lrint (src [i] * normfact) ;
return ;
} /* psf_f2i_array */
normfact = normalize ? (8.0 * 0x10000000) : 1.0 ;
- while (--count >= 0)
- { scaled_value = src [count] * normfact ;
- if (CPU_CLIPS_POSITIVE == 0 && scaled_value >= (1.0 * 0x7FFFFFFF))
- { dest [count] = 0x7FFFFFFF ;
+ for (int i = 0 ; i < count ; i++)
+ { scaled_value = src [i] * normfact ;
+#if CPU_CLIPS_POSITIVE == 0
+ if (scaled_value >= (1.0 * 0x7FFFFFFF))
+ { dest [i] = 0x7FFFFFFF ;
continue ;
} ;
- if (CPU_CLIPS_NEGATIVE == 0 && scaled_value <= (-8.0 * 0x10000000))
- { dest [count] = 0x80000000 ;
+#endif
+#if CPU_CLIPS_NEGATIVE == 0
+ if (scaled_value <= (-8.0 * 0x10000000))
+ { dest [i] = 0x80000000 ;
continue ;
} ;
+#endif
- dest [count] = psf_lrint (scaled_value) ;
+ dest [i] = psf_lrint (scaled_value) ;
} ;
return ;
#include <stdlib.h>
#include <string.h>
+#if HAVE_STDBOOL_H
+#include <stdbool.h>
+#endif
#if HAVE_INTTYPES_H
#include <inttypes.h>
#define ARRAY_LEN(x) ((int) (sizeof (x) / sizeof ((x) [0])))
-#define NOT(x) (! (x))
-
-#if COMPILER_IS_GCC
-#define SF_MAX(x, y) ({ \
- typeof (x) sf_max_x1 = (x) ; \
- typeof (y) sf_max_y1 = (y) ; \
- (void) (&sf_max_x1 == &sf_max_y1) ; \
- sf_max_x1 > sf_max_y1 ? sf_max_x1 : sf_max_y1 ; })
-
-#define SF_MIN(x, y) ({ \
- typeof (x) sf_min_x2 = (x) ; \
- typeof (y) sf_min_y2 = (y) ; \
- (void) (&sf_min_x2 == &sf_min_y2) ; \
- sf_min_x2 < sf_min_y2 ? sf_min_x2 : sf_min_y2 ; })
-#else
#define SF_MAX(a, b) ((a) > (b) ? (a) : (b))
#define SF_MIN(a, b) ((a) < (b) ? (a) : (b))
-#endif
#define COMPILE_TIME_ASSERT(e) (sizeof (struct { int : - !! (e) ; }))
#define SF_MAX_CHANNELS 1024
+/* Max FLAC sample rate : https://xiph.org/flac/format.html */
+#define SF_MAX_SAMPLERATE 655350
/*
typedef SF_CART_INFO_VAR (16 * 1024) SF_CART_INFO_16K ;
+typedef struct
+{ sf_count_t offset ;
+ sf_count_t len ;
+ unsigned minor_version ;
+} ID3V2_HEADER_INFO ;
+
#if SIZEOF_WCHAR_T == 2
typedef wchar_t sfwchar_t ;
#else
#endif
-static inline void *
-psf_memdup (const void *src, size_t n)
-{ void * mem = calloc (1, n & 3 ? n + 4 - (n & 3) : n) ;
- return memcpy (mem, src, n) ;
-} /* psf_memdup */
+void *psf_memdup (const void *src, size_t n) ;
/*
** This version of isprint specifically ignores any locale info. Its used for
** determining which characters can be printed in things like hexdumps.
*/
-static inline int
-psf_isprint (int ch)
-{ return (ch >= ' ' && ch <= '~') ;
-} /* psf_isprint */
+int psf_isprint (int ch) ;
/*=======================================================================================
** SF_PRIVATE stuct - a pointer to this struct is passed back to the caller of the
typedef struct
{
- union
- { char c [SF_FILENAME_LEN] ;
- sfwchar_t wc [SF_FILENAME_LEN] ;
- } path ;
-
- union
- { char c [SF_FILENAME_LEN] ;
- sfwchar_t wc [SF_FILENAME_LEN] ;
- } dir ;
-
- union
- { char c [SF_FILENAME_LEN / 4] ;
- sfwchar_t wc [SF_FILENAME_LEN / 4] ;
- } name ;
+ char path [SF_FILENAME_LEN] ;
+ char dir [SF_FILENAME_LEN] ;
+ char name [SF_FILENAME_LEN / 4] ;
#if USE_WINDOWS_API
/*
** These fields can only be used in src/file_io.c.
** They are basically the same as a windows file HANDLE.
*/
- void *handle, *hsaved ;
-
- int use_wchar ;
+ void *handle, *hsaved ;
#else
/* These fields can only be used in src/file_io.c. */
- int filedes, savedes ;
+ int filedes, savedes ;
#endif
- int do_not_close_descriptor ;
- int mode ; /* Open mode : SFM_READ, SFM_WRITE or SFM_RDWR. */
+ int do_not_close_descriptor ;
+ int mode ; /* Open mode : SFM_READ, SFM_WRITE or SFM_RDWR. */
} PSF_FILE ;
typedef struct sf_private_tag
{
- /* Canary in a coal mine. */
- union
- { /* Place a double here to encourage double alignment. */
- double d [2] ;
- char c [16] ;
- } canary ;
-
PSF_FILE file, rsrc ;
char syserr [SF_SYSERR_LEN] ;
int (*get_chunk_data) (struct sf_private_tag*, const SF_CHUNK_ITERATOR * iterator, SF_CHUNK_INFO * chunk_info) ;
int cpu_flags ;
+
+ ID3V2_HEADER_INFO id3_header ;
} SF_PRIVATE ;
SFE_OPUS_BAD_SAMPLERATE,
+ SFE_CAF_NOT_CAF,
+ SFE_CAF_NO_DESC,
+ SFE_CAF_BAD_PEAK,
+
+ SFE_AVR_NOT_AVR,
+ SFE_AVR_BAD_REZ_SIGN,
+
+ SFE_MPC_NO_MARKER,
+
+ SFE_MPEG_BAD_SAMPLERATE,
+
SFE_MAX_ERROR /* This must be last in list. */
} ;
int psf_open_rsrc (SF_PRIVATE *psf) ;
int psf_close_rsrc (SF_PRIVATE *psf) ;
+int psf_copy_filename (SF_PRIVATE *psf, const char *path) ;
+
/*
void psf_fclearerr (SF_PRIVATE *psf) ;
int psf_ferror (SF_PRIVATE *psf) ;
int ogg_opus_open (SF_PRIVATE *psf) ;
int ogg_open (SF_PRIVATE *psf) ;
+int mpeg_open (SF_PRIVATE *psf) ;
/* In progress. Do not currently work. */
-int mpeg_open (SF_PRIVATE *psf) ;
int rx2_open (SF_PRIVATE *psf) ;
int txw_open (SF_PRIVATE *psf) ;
int wve_open (SF_PRIVATE *psf) ;
int flac_init (SF_PRIVATE *psf) ;
int g72x_init (SF_PRIVATE * psf) ;
int alac_init (SF_PRIVATE *psf, const ALAC_DECODER_INFO * info) ;
+int mpeg_init (SF_PRIVATE *psf, int bitrate_mode, int write_metadata) ;
int dither_init (SF_PRIVATE *psf, int mode) ;
int psf_find_write_chunk (WRITE_CHUNKS * pchk, const char * marker) ;
-static inline int
-fourcc_to_marker (const SF_CHUNK_INFO * chunk_info)
-{ const unsigned char * cptr ;
-
- if (chunk_info->id_size != 4)
- return 0 ;
-
- cptr = (const unsigned char *) chunk_info->id ;
- return (cptr [3] << 24) + (cptr [2] << 16) + (cptr [1] << 8) + cptr [0] ;
-} /* fourcc_to_marker */
-
/*------------------------------------------------------------------------------------
** Functions that work like OpenBSD's strlcpy/strlcat to replace strncpy/strncat.
**
** compiler errors if code is carelessly converted from one to the other.
*/
-static inline void
-psf_strlcat (char *dest, size_t n, const char *src)
-{ strncat (dest, src, n - strlen (dest) - 1) ;
- dest [n - 1] = 0 ;
-} /* psf_strlcat */
-
-static inline void
-psf_strlcpy (char *dest, size_t n, const char *src)
-{ strncpy (dest, src, n - 1) ;
- dest [n - 1] = 0 ;
-} /* psf_strlcpy */
+void psf_strlcat (char *dest, size_t n, const char *src) ;
+void psf_strlcpy (char *dest, size_t n, const char *src) ;
/*------------------------------------------------------------------------------------
** SIMD optimized math functions.
int audio_detect (SF_PRIVATE * psf, AUDIO_DETECT *ad, const unsigned char * data, int datalen) ;
int id3_skip (SF_PRIVATE * psf) ;
+const char *id3_lookup_v1_genre (int number) ;
void alac_get_desc_chunk_items (int subformat, uint32_t *fmt_flags, uint32_t *frames_per_packet) ;
/* Will be set to 1 if flac, ogg and vorbis are available. */
#cmakedefine01 HAVE_EXTERNAL_XIPH_LIBS
+/* Will be set to 1 if lame and mpg123 are available. */
+#cmakedefine01 HAVE_MPEG
+
/* Define to 1 if you have the `floor' function. */
#cmakedefine01 HAVE_FLOOR
/* Define to 1 if you have the <immintrin.h> header file. */
#cmakedefine01 HAVE_IMMINTRIN_H
+/* Define to 1 if you have the <stdbool.h> header file. */
+#cmakedefine01 HAVE_STDBOOL_H
+
/* Define to 1 if you have the `vsnprintf' function. */
#cmakedefine01 HAVE_VSNPRINTF
dither_short (ptr, (short*) pdither->buffer, writecount / psf->sf.channels, psf->sf.channels) ;
- thiswrite = pdither->write_short (psf, (short*) pdither->buffer, writecount) ;
+ thiswrite = (int) pdither->write_short (psf, (short*) pdither->buffer, writecount) ;
total += thiswrite ;
len -= thiswrite ;
if (thiswrite < writecount)
dither_int (ptr, (int*) pdither->buffer, writecount / psf->sf.channels, psf->sf.channels) ;
- thiswrite = pdither->write_int (psf, (int*) pdither->buffer, writecount) ;
+ thiswrite = (int) pdither->write_int (psf, (int*) pdither->buffer, writecount) ;
total += thiswrite ;
len -= thiswrite ;
if (thiswrite < writecount)
bufferlen = sizeof (pdither->buffer) / (sizeof (float)) ;
while (len > 0)
- { writecount = (len >= bufferlen) ? bufferlen : (float) len ;
+ { writecount = (len >= bufferlen) ? bufferlen : (int) len ;
writecount /= psf->sf.channels ;
writecount *= psf->sf.channels ;
dither_float (ptr, (float*) pdither->buffer, writecount / psf->sf.channels, psf->sf.channels) ;
- thiswrite = pdither->write_float (psf, (float*) pdither->buffer, writecount) ;
+ thiswrite = (int) pdither->write_float (psf, (float*) pdither->buffer, writecount) ;
total += thiswrite ;
len -= thiswrite ;
if (thiswrite < writecount)
bufferlen = sizeof (pdither->buffer) / sizeof (double) ;
while (len > 0)
- { writecount = (len >= bufferlen) ? bufferlen : (double) len ;
+ { writecount = (len >= bufferlen) ? bufferlen : (int) len ;
writecount /= psf->sf.channels ;
writecount *= psf->sf.channels ;
dither_double (ptr, (double*) pdither->buffer, writecount / psf->sf.channels, psf->sf.channels) ;
- thiswrite = pdither->write_double (psf, (double*) pdither->buffer, writecount) ;
+ thiswrite = (int) pdither->write_double (psf, (double*) pdither->buffer, writecount) ;
total += thiswrite ;
len -= thiswrite ;
if (thiswrite < writecount)
static void
d2s_array (const double *src, int count, short *dest, double scale)
-{ while (--count >= 0)
- { dest [count] = psf_lrint (scale * src [count]) ;
+{ for (int i = 0 ; i < count ; i++)
+ { dest [i] = psf_lrint (scale * src [i]) ;
} ;
} /* d2s_array */
static void
d2s_clip_array (const double *src, int count, short *dest, double scale)
-{ while (--count >= 0)
- { double tmp = scale * src [count] ;
+{ for (int i = 0 ; i < count ; i++)
+ { double tmp = scale * src [i] ;
if (CPU_CLIPS_POSITIVE == 0 && tmp > 32767.0)
- dest [count] = SHRT_MAX ;
+ dest [i] = SHRT_MAX ;
else if (CPU_CLIPS_NEGATIVE == 0 && tmp < -32768.0)
- dest [count] = SHRT_MIN ;
+ dest [i] = SHRT_MIN ;
else
- dest [count] = psf_lrint (tmp) ;
+ dest [i] = psf_lrint (tmp) ;
} ;
} /* d2s_clip_array */
static void
d2i_array (const double *src, int count, int *dest, double scale)
-{ while (--count >= 0)
- { dest [count] = psf_lrint (scale * src [count]) ;
+{ for (int i = 0 ; i < count ; i++)
+ { dest [i] = psf_lrint (scale * src [i]) ;
} ;
} /* d2i_array */
static void
d2i_clip_array (const double *src, int count, int *dest, double scale)
-{ while (--count >= 0)
- { float tmp = scale * src [count] ;
+{ for (int i = 0 ; i < count ; i++)
+ { float tmp = scale * src [i] ;
if (CPU_CLIPS_POSITIVE == 0 && tmp > (1.0 * INT_MAX))
- dest [count] = INT_MAX ;
+ dest [i] = INT_MAX ;
else if (CPU_CLIPS_NEGATIVE == 0 && tmp < (-1.0 * INT_MAX))
- dest [count] = INT_MIN ;
+ dest [i] = INT_MIN ;
else
- dest [count] = psf_lrint (tmp) ;
+ dest [i] = psf_lrint (tmp) ;
} ;
} /* d2i_clip_array */
static inline void
d2f_array (const double *src, int count, float *dest)
-{ while (--count >= 0)
- { dest [count] = src [count] ;
+{ for (int i = 0 ; i < count ; i++)
+ { dest [i] = src [i] ;
} ;
} /* d2f_array */
static inline void
s2d_array (const short *src, double *dest, int count, double scale)
-{ while (--count >= 0)
- { dest [count] = scale * src [count] ;
+{ for (int i = 0 ; i < count ; i++)
+ { dest [i] = scale * src [i] ;
} ;
} /* s2d_array */
static inline void
i2d_array (const int *src, double *dest, int count, double scale)
-{ while (--count >= 0)
- { dest [count] = scale * src [count] ;
+{ for (int i = 0 ; i < count ; i++)
+ { dest [i] = scale * src [i] ;
} ;
} /* i2d_array */
static inline void
f2d_array (const float *src, double *dest, int count)
-{ while (--count >= 0)
- { dest [count] = src [count] ;
+{ for (int i = 0 ; i < count ; i++)
+ { dest [i] = src [i] ;
} ;
} /* f2d_array */
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.dbuf, sizeof (double), bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.dbuf, sizeof (double), bufferlen, psf) ;
if (psf->data_endswap == SF_TRUE)
endswap_double_array (ubuf.dbuf, readcount) ;
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.dbuf, sizeof (double), bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.dbuf, sizeof (double), bufferlen, psf) ;
if (psf->data_endswap == SF_TRUE)
endswap_double_array (ubuf.dbuf, bufferlen) ;
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.dbuf, sizeof (double), bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.dbuf, sizeof (double), bufferlen, psf) ;
if (psf->data_endswap == SF_TRUE)
endswap_double_array (ubuf.dbuf, readcount) ;
if (psf->data_endswap == SF_TRUE)
endswap_double_array (ubuf.dbuf, bufferlen) ;
- writecount = psf_fwrite (ubuf.dbuf, sizeof (double), bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.dbuf, sizeof (double), bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
if (psf->data_endswap == SF_TRUE)
endswap_double_array (ubuf.dbuf, bufferlen) ;
- writecount = psf_fwrite (ubuf.dbuf, sizeof (double), bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.dbuf, sizeof (double), bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
if (psf->data_endswap == SF_TRUE)
endswap_double_array (ubuf.dbuf, bufferlen) ;
- writecount = psf_fwrite (ubuf.dbuf, sizeof (double), bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.dbuf, sizeof (double), bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
endswap_double_copy (ubuf.dbuf, ptr + total, bufferlen) ;
- writecount = psf_fwrite (ubuf.dbuf, sizeof (double), bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.dbuf, sizeof (double), bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.dbuf, sizeof (double), bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.dbuf, sizeof (double), bufferlen, psf) ;
if (psf->data_endswap == SF_TRUE)
endswap_double_array (ubuf.dbuf, bufferlen) ;
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.dbuf, sizeof (double), bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.dbuf, sizeof (double), bufferlen, psf) ;
if (psf->data_endswap == SF_TRUE)
endswap_double_array (ubuf.dbuf, bufferlen) ;
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.dbuf, sizeof (double), bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.dbuf, sizeof (double), bufferlen, psf) ;
if (psf->data_endswap == SF_TRUE)
endswap_double_array (ubuf.dbuf, bufferlen) ;
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.dbuf, sizeof (double), bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.dbuf, sizeof (double), bufferlen, psf) ;
if (psf->data_endswap == SF_TRUE)
endswap_double_array (ubuf.dbuf, readcount) ;
if (psf->data_endswap == SF_TRUE)
endswap_double_array (ubuf.dbuf, bufferlen) ;
- writecount = psf_fwrite (ubuf.dbuf, sizeof (double), bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.dbuf, sizeof (double), bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
if (psf->data_endswap == SF_TRUE)
endswap_double_array (ubuf.dbuf, bufferlen) ;
- writecount = psf_fwrite (ubuf.dbuf, sizeof (double), bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.dbuf, sizeof (double), bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
if (psf->data_endswap == SF_TRUE)
endswap_double_array (ubuf.dbuf, bufferlen) ;
- writecount = psf_fwrite (ubuf.dbuf, sizeof (double), bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.dbuf, sizeof (double), bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
if (psf->data_endswap == SF_TRUE)
endswap_double_array (ubuf.dbuf, bufferlen) ;
- writecount = psf_fwrite (ubuf.dbuf, sizeof (double), bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.dbuf, sizeof (double), bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
static void
d2bd_read (double *buffer, int count)
-{ while (--count >= 0)
- { buffer [count] = DOUBLE64_READ ((unsigned char *) (buffer + count)) ;
+{ for (int i = 0 ; i < count ; i++)
+ { buffer [i] = DOUBLE64_READ ((unsigned char *) &buffer [i]) ;
} ;
} /* d2bd_read */
static void
bd2d_write (double *buffer, int count)
-{ while (--count >= 0)
- { DOUBLE64_WRITE (buffer [count], (unsigned char*) (buffer + count)) ;
+{ for (int i = 0 ; i < count ; i++)
+ { DOUBLE64_WRITE (buffer [i], (unsigned char*) &buffer [i]) ;
} ;
} /* bd2d_write */
** No assumptions are made about the packing of this struct.
*/
typedef struct
-{ unsigned char major, minor, compression, channels, bitwidth ;
- unsigned short srate, maxval ;
- unsigned int id, datalen, frames, offset ;
+{ uint8_t major, minor, compression, channels, bitwidth ;
+ uint16_t srate, maxval ;
+ uint32_t id, datalen, frames, offset ;
} DWD_HEADER ;
static int
if (psf->filelength != dwdh.offset + dwdh.datalen)
{ psf_log_printf (psf, " Data Length : %d (should be %D)\n", dwdh.datalen, psf->filelength - dwdh.offset) ;
- dwdh.datalen = (unsigned int) (psf->filelength - dwdh.offset) ;
+ dwdh.datalen = (uint32_t) (psf->filelength - dwdh.offset) ;
}
else
psf_log_printf (psf, " Data Length : %d\n", dwdh.datalen) ;
iptr = ubuf.ibuf ;
bufferlen = ARRAY_LEN (ubuf.ibuf) ;
while (len > 0)
- { readcount = (len >= bufferlen) ? bufferlen : len ;
+ { readcount = (len >= bufferlen) ? bufferlen : (int) len ;
count = dwvw_decode_data (psf, pdwvw, iptr, readcount) ;
for (k = 0 ; k < readcount ; k++)
ptr [total + k] = iptr [k] >> 16 ;
iptr = ubuf.ibuf ;
bufferlen = ARRAY_LEN (ubuf.ibuf) ;
while (len > 0)
- { readcount = (len >= bufferlen) ? bufferlen : len ;
+ { readcount = (len >= bufferlen) ? bufferlen : (int) len ;
count = dwvw_decode_data (psf, pdwvw, iptr, readcount) ;
for (k = 0 ; k < readcount ; k++)
ptr [total + k] = normfact * (float) (iptr [k]) ;
iptr = ubuf.ibuf ;
bufferlen = ARRAY_LEN (ubuf.ibuf) ;
while (len > 0)
- { readcount = (len >= bufferlen) ? bufferlen : len ;
+ { readcount = (len >= bufferlen) ? bufferlen : (int) len ;
count = dwvw_decode_data (psf, pdwvw, iptr, readcount) ;
for (k = 0 ; k < readcount ; k++)
ptr [total + k] = normfact * (double) (iptr [k]) ;
/* Load bits in bit reseviour. */
while (pdwvw->bit_count < bit_count)
{ if (pdwvw->b.index >= pdwvw->b.end)
- { pdwvw->b.end = psf_fread (pdwvw->b.buffer, 1, sizeof (pdwvw->b.buffer), psf) ;
+ { pdwvw->b.end = (int) psf_fread (pdwvw->b.buffer, 1, sizeof (pdwvw->b.buffer), psf) ;
pdwvw->b.index = 0 ;
} ;
iptr = ubuf.ibuf ;
bufferlen = ARRAY_LEN (ubuf.ibuf) ;
while (len > 0)
- { writecount = (len >= bufferlen) ? bufferlen : len ;
+ { writecount = (len >= bufferlen) ? bufferlen : (int) len ;
for (k = 0 ; k < writecount ; k++)
iptr [k] = arith_shift_left (ptr [total + k], 16) ;
count = dwvw_encode_data (psf, pdwvw, iptr, writecount) ;
iptr = ubuf.ibuf ;
bufferlen = ARRAY_LEN (ubuf.ibuf) ;
while (len > 0)
- { writecount = (len >= bufferlen) ? bufferlen : len ;
+ { writecount = (len >= bufferlen) ? bufferlen : (int) len ;
for (k = 0 ; k < writecount ; k++)
iptr [k] = psf_lrintf (normfact * ptr [total + k]) ;
count = dwvw_encode_data (psf, pdwvw, iptr, writecount) ;
iptr = ubuf.ibuf ;
bufferlen = ARRAY_LEN (ubuf.ibuf) ;
while (len > 0)
- { writecount = (len >= bufferlen) ? bufferlen : len ;
+ { writecount = (len >= bufferlen) ? bufferlen : (int) len ;
for (k = 0 ; k < writecount ; k++)
iptr [k] = psf_lrint (normfact * ptr [total + k]) ;
count = dwvw_encode_data (psf, pdwvw, iptr, writecount) ;
static void psf_log_syserr (SF_PRIVATE *psf, int error) ;
+int
+psf_copy_filename (SF_PRIVATE *psf, const char *path)
+{ const char *ccptr ;
+ char *cptr ;
+
+ if (strlen (path) > 1 && strlen (path) - 1 >= sizeof (psf->file.path))
+ { psf->error = SFE_FILENAME_TOO_LONG ;
+ return psf->error ;
+ } ;
+
+ snprintf (psf->file.path, sizeof (psf->file.path), "%s", path) ;
+ if ((ccptr = strrchr (path, '/')) || (ccptr = strrchr (path, '\\')))
+ ccptr ++ ;
+ else
+ ccptr = path ;
+
+ snprintf (psf->file.name, sizeof (psf->file.name), "%s", ccptr) ;
+
+ /* Now grab the directory. */
+ snprintf (psf->file.dir, sizeof (psf->file.dir), "%s", path) ;
+ if ((cptr = strrchr (psf->file.dir, '/')) || (cptr = strrchr (psf->file.dir, '\\')))
+ cptr [1] = 0 ;
+ else
+ psf->file.dir [0] = 0 ;
+
+ return 0 ;
+} /* psf_copy_filename */
+
#if (USE_WINDOWS_API == 0)
/*------------------------------------------------------------------------------
return 0 ;
/* Test for MacOSX style resource fork on HPFS or HPFS+ filesystems. */
- count = snprintf (psf->rsrc.path.c, sizeof (psf->rsrc.path.c), "%s/..namedfork/rsrc", psf->file.path.c) ;
+ count = snprintf (psf->rsrc.path, sizeof (psf->rsrc.path), "%s/..namedfork/rsrc", psf->file.path) ;
psf->error = SFE_NO_ERROR ;
- if (count < sizeof (psf->rsrc.path.c))
+ if (count < sizeof (psf->rsrc.path))
{ if ((psf->rsrc.filedes = psf_open_fd (&psf->rsrc)) >= 0)
{ psf->rsrclength = psf_get_filelen_fd (psf->rsrc.filedes) ;
if (psf->rsrclength > 0 || (psf->rsrc.mode & SFM_WRITE))
** Now try for a resource fork stored as a separate file in the same
** directory, but preceded with a dot underscore.
*/
- count = snprintf (psf->rsrc.path.c, sizeof (psf->rsrc.path.c), "%s._%s", psf->file.dir.c, psf->file.name.c) ;
+ count = snprintf (psf->rsrc.path, sizeof (psf->rsrc.path), "%s._%s", psf->file.dir, psf->file.name) ;
psf->error = SFE_NO_ERROR ;
- if (count < sizeof (psf->rsrc.path.c) && (psf->rsrc.filedes = psf_open_fd (&psf->rsrc)) >= 0)
+ if (count < sizeof (psf->rsrc.path) && (psf->rsrc.filedes = psf_open_fd (&psf->rsrc)) >= 0)
{ psf->rsrclength = psf_get_filelen_fd (psf->rsrc.filedes) ;
return SFE_NO_ERROR ;
} ;
** Now try for a resource fork stored in a separate file in the
** .AppleDouble/ directory.
*/
- count = snprintf (psf->rsrc.path.c, sizeof (psf->rsrc.path.c), "%s.AppleDouble/%s", psf->file.dir.c, psf->file.name.c) ;
+ count = snprintf (psf->rsrc.path, sizeof (psf->rsrc.path), "%s.AppleDouble/%s", psf->file.dir, psf->file.name) ;
psf->error = SFE_NO_ERROR ;
- if (count < sizeof (psf->rsrc.path.c))
+ if (count < sizeof (psf->rsrc.path))
{ if ((psf->rsrc.filedes = psf_open_fd (&psf->rsrc)) >= 0)
{ psf->rsrclength = psf_get_filelen_fd (psf->rsrc.filedes) ;
return SFE_NO_ERROR ;
} ;
if (mode == 0)
- fd = open (pfile->path.c, oflag) ;
+ fd = open (pfile->path, oflag) ;
else
- fd = open (pfile->path.c, oflag, mode) ;
+ fd = open (pfile->path, oflag, mode) ;
return fd ;
} /* psf_open_fd */
#endif
} /* psf_fsync */
-#elif USE_WINDOWS_API
+#else
/* Win32 file i/o functions implemented using native Win32 API */
psf->error = 0 ;
psf->file.handle = psf_open_handle (&psf->file) ;
- if (psf->file.handle == NULL)
+ if (psf->file.handle == INVALID_HANDLE_VALUE)
psf_log_syserr (psf, GetLastError ()) ;
return psf->error ;
return 0 ;
if (psf->file.do_not_close_descriptor)
- { psf->file.handle = NULL ;
+ { psf->file.handle = INVALID_HANDLE_VALUE ;
return 0 ;
} ;
if ((retval = psf_close_handle (psf->file.handle)) == -1)
psf_log_syserr (psf, GetLastError ()) ;
- psf->file.handle = NULL ;
+ psf->file.handle = INVALID_HANDLE_VALUE ;
return retval ;
} /* psf_fclose */
/* USE_WINDOWS_API */ int
psf_open_rsrc (SF_PRIVATE *psf)
{
- if (psf->rsrc.handle != NULL)
+ if (psf->rsrc.handle != INVALID_HANDLE_VALUE)
return 0 ;
/* Test for MacOSX style resource fork on HPFS or HPFS+ filesystems. */
- snprintf (psf->rsrc.path.c, sizeof (psf->rsrc.path.c), "%s/rsrc", psf->file.path.c) ;
+ snprintf (psf->rsrc.path, sizeof (psf->rsrc.path), "%s/rsrc", psf->file.path) ;
psf->error = SFE_NO_ERROR ;
- if ((psf->rsrc.handle = psf_open_handle (&psf->rsrc)) != NULL)
+ if ((psf->rsrc.handle = psf_open_handle (&psf->rsrc)) != INVALID_HANDLE_VALUE)
{ psf->rsrclength = psf_get_filelen_handle (psf->rsrc.handle) ;
return SFE_NO_ERROR ;
} ;
** Now try for a resource fork stored as a separate file in the same
** directory, but preceded with a dot underscore.
*/
- snprintf (psf->rsrc.path.c, sizeof (psf->rsrc.path.c), "%s._%s", psf->file.dir.c, psf->file.name.c) ;
+ snprintf (psf->rsrc.path, sizeof (psf->rsrc.path), "%s._%s", psf->file.dir, psf->file.name) ;
psf->error = SFE_NO_ERROR ;
- if ((psf->rsrc.handle = psf_open_handle (&psf->rsrc)) != NULL)
+ if ((psf->rsrc.handle = psf_open_handle (&psf->rsrc)) != INVALID_HANDLE_VALUE)
{ psf->rsrclength = psf_get_filelen_handle (psf->rsrc.handle) ;
return SFE_NO_ERROR ;
} ;
** Now try for a resource fork stored in a separate file in the
** .AppleDouble/ directory.
*/
- snprintf (psf->rsrc.path.c, sizeof (psf->rsrc.path.c), "%s.AppleDouble/%s", psf->file.dir.c, psf->file.name.c) ;
+ snprintf (psf->rsrc.path, sizeof (psf->rsrc.path), "%s.AppleDouble/%s", psf->file.dir, psf->file.name) ;
psf->error = SFE_NO_ERROR ;
- if ((psf->rsrc.handle = psf_open_handle (&psf->rsrc)) != NULL)
+ if ((psf->rsrc.handle = psf_open_handle (&psf->rsrc)) != INVALID_HANDLE_VALUE)
{ psf->rsrclength = psf_get_filelen_handle (psf->rsrc.handle) ;
return SFE_NO_ERROR ;
} ;
/* No resource file found. */
- if (psf->rsrc.handle == NULL)
+ if (psf->rsrc.handle == INVALID_HANDLE_VALUE)
psf_log_syserr (psf, GetLastError ()) ;
- psf->rsrc.handle = NULL ;
-
return psf->error ;
} /* psf_open_rsrc */
/* USE_WINDOWS_API */ void
psf_init_files (SF_PRIVATE *psf)
-{ psf->file.handle = NULL ;
- psf->rsrc.handle = NULL ;
- psf->file.hsaved = NULL ;
+{ psf->file.handle = INVALID_HANDLE_VALUE ;
+ psf->rsrc.handle = INVALID_HANDLE_VALUE ;
+ psf->file.hsaved = INVALID_HANDLE_VALUE ;
} /* psf_init_files */
/* USE_WINDOWS_API */ void
DWORD dwShareMode ;
DWORD dwCreationDistribution ;
HANDLE handle ;
+ LPWSTR pwszPath = NULL ;
switch (pfile->mode)
{ case SFM_READ :
break ;
default :
- return NULL ;
+ return INVALID_HANDLE_VALUE ;
+ } ;
+
+ int nResult = MultiByteToWideChar (CP_UTF8, 0, pfile->path, -1, NULL, 0) ;
+ pwszPath = malloc (nResult * sizeof (WCHAR)) ;
+ if (!pwszPath)
+ return INVALID_HANDLE_VALUE ;
+
+ int nResult2 = MultiByteToWideChar (CP_UTF8, 0, pfile->path, -1, pwszPath, nResult) ;
+ if (nResult != nResult2)
+ { free (pwszPath) ;
+ return INVALID_HANDLE_VALUE ;
} ;
#if defined (WINAPI_FAMILY_PARTITION) && !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_SYSTEM)
if (!pfile->use_wchar)
- return NULL ;
+ return INVALID_HANDLE_VALUE ;
CREATEFILE2_EXTENDED_PARAMETERS cfParams = { 0 } ;
cfParams.dwSize = sizeof (CREATEFILE2_EXTENDED_PARAMETERS) ;
cfParams.dwFileAttributes = FILE_ATTRIBUTE_NORMAL ;
- handle = CreateFile2 (pfile->path.wc, dwDesiredAccess, dwShareMode, dwCreationDistribution, &cfParams) ;
-
- if (handle == INVALID_HANDLE_VALUE)
- return NULL ;
-
- return handle ;
+ handle = CreateFile2 (pwszPath, dwDesiredAccess, dwShareMode, dwCreationDistribution, &cfParams) ;
#else
- if (pfile->use_wchar)
- handle = CreateFileW (
- pfile->path.wc, /* pointer to name of the file */
- dwDesiredAccess, /* access (read-write) mode */
- dwShareMode, /* share mode */
- 0, /* pointer to security attributes */
- dwCreationDistribution, /* how to create */
- FILE_ATTRIBUTE_NORMAL, /* file attributes (could use FILE_FLAG_SEQUENTIAL_SCAN) */
- NULL /* handle to file with attributes to copy */
- ) ;
- else
- handle = CreateFileA (
- pfile->path.c, /* pointer to name of the file */
- dwDesiredAccess, /* access (read-write) mode */
- dwShareMode, /* share mode */
- 0, /* pointer to security attributes */
- dwCreationDistribution, /* how to create */
- FILE_ATTRIBUTE_NORMAL, /* file attributes (could use FILE_FLAG_SEQUENTIAL_SCAN) */
- NULL /* handle to file with attributes to copy */
- ) ;
-
- if (handle == INVALID_HANDLE_VALUE)
- return NULL ;
+ handle = CreateFileW (
+ pwszPath, /* pointer to name of the file */
+ dwDesiredAccess, /* access (read-write) mode */
+ dwShareMode, /* share mode */
+ 0, /* pointer to security attributes */
+ dwCreationDistribution, /* how to create */
+ FILE_ATTRIBUTE_NORMAL, /* file attributes (could use FILE_FLAG_SEQUENTIAL_SCAN) */
+ NULL /* handle to file with attributes to copy */
+ ) ;
+#endif
+ free (pwszPath) ;
return handle ;
-#endif
} /* psf_open_handle */
/* USE_WINDOWS_API */ static void
/* USE_WINDOWS_API */ int
psf_close_rsrc (SF_PRIVATE *psf)
{ psf_close_handle (psf->rsrc.handle) ;
- psf->rsrc.handle = NULL ;
+ psf->rsrc.handle = INVALID_HANDLE_VALUE ;
return 0 ;
} /* psf_close_rsrc */
/* USE_WINDOWS_API */ int
psf_set_stdio (SF_PRIVATE *psf)
-{ HANDLE handle = NULL ;
+{ HANDLE handle = INVALID_HANDLE_VALUE ;
int error = 0 ;
switch (psf->file.mode)
/* USE_WINDOWS_API */ int
psf_file_valid (SF_PRIVATE *psf)
-{ if (psf->file.handle == NULL)
- return SF_FALSE ;
- if (psf->file.handle == INVALID_HANDLE_VALUE)
+{ if (psf->file.handle == INVALID_HANDLE_VALUE)
return SF_FALSE ;
return SF_TRUE ;
} /* psf_set_file */
/* USE_WINDOWS_API */ static int
psf_close_handle (HANDLE handle)
-{ if (handle == NULL)
+{ if (handle == INVALID_HANDLE_VALUE)
return 0 ;
if (CloseHandle (handle) == 0)
return retval ;
} /* psf_ftruncate */
-
-#else
-/* Win32 file i/o functions implemented using Unix-style file i/o API */
-
-/* Win32 has a 64 file offset seek function:
-**
-** __int64 _lseeki64 (int handle, __int64 offset, int origin) ;
-**
-** It also has a 64 bit fstat function:
-**
-** int fstati64 (int, struct _stati64) ;
-**
-** but the fscking thing doesn't work!!!!! The file size parameter returned
-** by this function is only valid up until more data is written at the end of
-** the file. That makes this function completely 100% useless.
-*/
-
-#include <io.h>
-#include <direct.h>
-
-/* Win32 */ int
-psf_fopen (SF_PRIVATE *psf, const char *pathname, int open_mode)
-{ int oflag, mode ;
-
- switch (open_mode)
- { case SFM_READ :
- oflag = O_RDONLY | O_BINARY ;
- mode = 0 ;
- break ;
-
- case SFM_WRITE :
- oflag = O_WRONLY | O_CREAT | O_TRUNC | O_BINARY ;
- mode = S_IRUSR | S_IWUSR | S_IRGRP ;
- break ;
-
- case SFM_RDWR :
- oflag = O_RDWR | O_CREAT | O_BINARY ;
- mode = S_IRUSR | S_IWUSR | S_IRGRP ;
- break ;
-
- default :
- psf->error = SFE_BAD_OPEN_MODE ;
- return -1 ;
- break ;
- } ;
-
- if (mode == 0)
- psf->file.filedes = open (pathname, oflag) ;
- else
- psf->file.filedes = open (pathname, oflag, mode) ;
-
- if (psf->file.filedes == -1)
- psf_log_syserr (psf, errno) ;
-
- return psf->file.filedes ;
-} /* psf_fopen */
-
-/* Win32 */ sf_count_t
-psf_fseek (SF_PRIVATE *psf, sf_count_t offset, int whence)
-{ sf_count_t new_position ;
-
- if (psf->virtual_io)
- return psf->vio.seek (offset, whence, psf->vio_user_data) ;
-
- switch (whence)
- { case SEEK_SET :
- offset += psf->fileoffset ;
- break ;
-
- case SEEK_END :
- if (psf->file.mode == SFM_WRITE)
- { new_position = _lseeki64 (psf->file.filedes, offset, whence) ;
-
- if (new_position < 0)
- psf_log_syserr (psf, errno) ;
-
- return new_position - psf->fileoffset ;
- } ;
-
- /* Transform SEEK_END into a SEEK_SET, ie find the file
- ** length add the requested offset (should be <= 0) to
- ** get the offset wrt the start of file.
- */
- whence = SEEK_SET ;
- offset = _lseeki64 (psf->file.filedes, 0, SEEK_END) + offset ;
- break ;
-
- default :
- /* No need to do anything about SEEK_CUR. */
- break ;
- } ;
-
- /*
- ** Bypass weird Win32-ism if necessary.
- ** _lseeki64() returns an "invalid parameter" error if called with the
- ** offset == 0 and whence == SEEK_CUR.
- *** Use the _telli64() function instead.
- */
- if (offset == 0 && whence == SEEK_CUR)
- new_position = _telli64 (psf->file.filedes) ;
- else
- new_position = _lseeki64 (psf->file.filedes, offset, whence) ;
-
- if (new_position < 0)
- psf_log_syserr (psf, errno) ;
-
- new_position -= psf->fileoffset ;
-
- return new_position ;
-} /* psf_fseek */
-
-/* Win32 */ sf_count_t
-psf_fread (void *ptr, sf_count_t bytes, sf_count_t items, SF_PRIVATE *psf)
-{ sf_count_t total = 0 ;
- ssize_t count ;
-
- if (psf->virtual_io)
- return psf->vio.read (ptr, bytes*items, psf->vio_user_data) / bytes ;
-
- items *= bytes ;
-
- /* Do this check after the multiplication above. */
- if (items <= 0)
- return 0 ;
-
- while (items > 0)
- { /* Break the writes down to a sensible size. */
- count = (items > SENSIBLE_SIZE) ? SENSIBLE_SIZE : (ssize_t) items ;
-
- count = read (psf->file.filedes, ((char*) ptr) + total, (size_t) count) ;
-
- if (count == -1)
- { if (errno == EINTR)
- continue ;
-
- psf_log_syserr (psf, errno) ;
- break ;
- } ;
-
- if (count == 0)
- break ;
-
- total += count ;
- items -= count ;
- } ;
-
- return total / bytes ;
-} /* psf_fread */
-
-/* Win32 */ sf_count_t
-psf_fwrite (const void *ptr, sf_count_t bytes, sf_count_t items, SF_PRIVATE *psf)
-{ sf_count_t total = 0 ;
- ssize_t count ;
-
- if (psf->virtual_io)
- return psf->vio.write (ptr, bytes*items, psf->vio_user_data) / bytes ;
-
- items *= bytes ;
-
- /* Do this check after the multiplication above. */
- if (items <= 0)
- return 0 ;
-
- while (items > 0)
- { /* Break the writes down to a sensible size. */
- count = (items > SENSIBLE_SIZE) ? SENSIBLE_SIZE : items ;
-
- count = write (psf->file.filedes, ((const char*) ptr) + total, count) ;
-
- if (count == -1)
- { if (errno == EINTR)
- continue ;
-
- psf_log_syserr (psf, errno) ;
- break ;
- } ;
-
- if (count == 0)
- break ;
-
- total += count ;
- items -= count ;
- } ;
-
- return total / bytes ;
-} /* psf_fwrite */
-
-/* Win32 */ sf_count_t
-psf_ftell (SF_PRIVATE *psf)
-{ sf_count_t pos ;
-
- if (psf->virtual_io)
- return psf->vio.tell (psf->vio_user_data) ;
-
- pos = _telli64 (psf->file.filedes) ;
-
- if (pos == ((sf_count_t) -1))
- { psf_log_syserr (psf, errno) ;
- return -1 ;
- } ;
-
- return pos - psf->fileoffset ;
-} /* psf_ftell */
-
-/* Win32 */ int
-psf_fclose (SF_PRIVATE *psf)
-{ int retval ;
-
- while ((retval = close (psf->file.filedes)) == -1 && errno == EINTR)
- /* Do nothing. */ ;
-
- if (retval == -1)
- psf_log_syserr (psf, errno) ;
-
- psf->file.filedes = -1 ;
-
- return retval ;
-} /* psf_fclose */
-
-/* Win32 */ sf_count_t
-psf_fgets (char *buffer, sf_count_t bufsize, SF_PRIVATE *psf)
-{ sf_count_t k = 0 ;
- sf_count_t count ;
-
- while (k < bufsize - 1)
- { count = read (psf->file.filedes, &(buffer [k]), 1) ;
-
- if (count == -1)
- { if (errno == EINTR)
- continue ;
-
- psf_log_syserr (psf, errno) ;
- break ;
- } ;
-
- if (count == 0 || buffer [k++] == '\n')
- break ;
- } ;
-
- buffer [k] = 0 ;
-
- return k ;
-} /* psf_fgets */
-
-/* Win32 */ int
-psf_is_pipe (SF_PRIVATE *psf)
-{ struct stat statbuf ;
-
- if (psf->virtual_io)
- return SF_FALSE ;
-
- /* Not sure if this works. */
- if (fstat (psf->file.filedes, &statbuf) == -1)
- { psf_log_syserr (psf, errno) ;
- /* Default to maximum safety. */
- return SF_TRUE ;
- } ;
-
- /* These macros are defined in Win32/unistd.h. */
- if (S_ISFIFO (statbuf.st_mode) || S_ISSOCK (statbuf.st_mode))
- return SF_TRUE ;
-
- return SF_FALSE ;
-} /* psf_checkpipe */
-
-/* Win32 */ sf_count_t
-psf_get_filelen (SF_PRIVATE *psf)
-{
-#if 0
- /*
- ** Windoze is SOOOOO FUCKED!!!!!!!
- ** This code should work but doesn't. Why?
- ** Code below does work.
- */
- struct _stati64 statbuf ;
-
- if (_fstati64 (psf->file.filedes, &statbuf))
- { psf_log_syserr (psf, errno) ;
- return (sf_count_t) -1 ;
- } ;
-
- return statbuf.st_size ;
-#else
- sf_count_t current, filelen ;
-
- if (psf->virtual_io)
- return psf->vio.get_filelen (psf->vio_user_data) ;
-
- if ((current = _telli64 (psf->file.filedes)) < 0)
- { psf_log_syserr (psf, errno) ;
- return (sf_count_t) -1 ;
- } ;
-
- /*
- ** Lets face it, windoze if FUBAR!!!
- **
- ** For some reason, I have to call _lseeki64() TWICE to get to the
- ** end of the file.
- **
- ** This might have been avoided if windows had implemented the POSIX
- ** standard function fsync() but NO, that would have been too easy.
- **
- ** I am VERY close to saying that windoze will no longer be supported
- ** by libsndfile and changing the license to GPL at the same time.
- */
-
- _lseeki64 (psf->file.filedes, 0, SEEK_END) ;
-
- if ((filelen = _lseeki64 (psf->file.filedes, 0, SEEK_END)) < 0)
- { psf_log_syserr (psf, errno) ;
- return (sf_count_t) -1 ;
- } ;
-
- if (filelen > current)
- _lseeki64 (psf->file.filedes, current, SEEK_SET) ;
-
- switch (psf->file.mode)
- { case SFM_WRITE :
- filelen = filelen - psf->fileoffset ;
- break ;
-
- case SFM_READ :
- if (psf->fileoffset > 0 && psf->filelength > 0)
- filelen = psf->filelength ;
- break ;
-
- case SFM_RDWR :
- /*
- ** Cannot open embedded files SFM_RDWR so we don't need to
- ** subtract psf->fileoffset. We already have the answer we
- ** need.
- */
- break ;
-
- default :
- filelen = 0 ;
- } ;
-
- return filelen ;
-#endif
-} /* psf_get_filelen */
-
-/* Win32 */ int
-psf_ftruncate (SF_PRIVATE *psf, sf_count_t len)
-{ int retval ;
-
- /* Returns 0 on success, non-zero on failure. */
- if (len < 0)
- return 1 ;
-
- /* The global village idiots at micorsoft decided to implement
- ** nearly all the required 64 bit file offset functions except
- ** for one, truncate. The fscking morons!
- **
- ** This is not 64 bit file offset clean. Somone needs to clean
- ** this up.
- */
- if (len > 0x7FFFFFFF)
- return -1 ;
-
- retval = chsize (psf->file.filedes, len) ;
-
- if (retval == -1)
- psf_log_syserr (psf, errno) ;
-
- return retval ;
-} /* psf_ftruncate */
-
-
-static void
-psf_log_syserr (SF_PRIVATE *psf, int error)
-{
- /* Only log an error if no error has been set yet. */
- if (psf->error == 0)
- { psf->error = SFE_SYSTEM ;
- snprintf (psf->syserr, sizeof (psf->syserr), "System error : %s", strerror (error)) ;
- } ;
-
- return ;
-} /* psf_log_syserr */
-
#endif
static void
s2flac8_array (const short *src, int32_t *dest, int count)
-{ while (--count >= 0)
- dest [count] = src [count] >> 8 ;
+{ for (int i = 0 ; i < count ; i++)
+ dest [i] = src [i] >> 8 ;
} /* s2flac8_array */
static void
s2flac16_array (const short *src, int32_t *dest, int count)
-{ while (--count >= 0)
- dest [count] = src [count] ;
+{ for (int i = 0 ; i < count ; i++)
+ dest [i] = src [i] ;
} /* s2flac16_array */
static void
s2flac24_array (const short *src, int32_t *dest, int count)
-{ while (--count >= 0)
- dest [count] = src [count] << 8 ;
+{ for (int i = 0 ; i < count ; i++)
+ dest [i] = src [i] << 8 ;
} /* s2flac24_array */
static void
i2flac8_array (const int *src, int32_t *dest, int count)
-{ while (--count >= 0)
- dest [count] = src [count] >> 24 ;
+{ for (int i = 0 ; i < count ; i++)
+ dest [i] = src [i] >> 24 ;
} /* i2flac8_array */
static void
i2flac16_array (const int *src, int32_t *dest, int count)
{
- while (--count >= 0)
- dest [count] = src [count] >> 16 ;
+ for (int i = 0 ; i < count ; i++)
+ dest [i] = src [i] >> 16 ;
} /* i2flac16_array */
static void
i2flac24_array (const int *src, int32_t *dest, int count)
-{ while (--count >= 0)
- dest [count] = src [count] >> 8 ;
+{ for (int i = 0 ; i < count ; i++)
+ dest [i] = src [i] >> 8 ;
} /* i2flac24_array */
static sf_count_t
/* Decode some more. */
while (pflac->pos < pflac->len)
{ if (FLAC__stream_decoder_process_single (pflac->fsd) == 0)
+ { psf_log_printf (psf, "FLAC__stream_decoder_process_single returned false\n") ;
+ /* Current frame is busted, so NULL the pointer. */
+ pflac->frame = NULL ;
break ;
+ } ;
state = FLAC__stream_decoder_get_state (pflac->fsd) ;
if (state >= FLAC__STREAM_DECODER_END_OF_STREAM)
{ psf_log_printf (psf, "FLAC__stream_decoder_get_state returned %s\n", FLAC__StreamDecoderStateString [state]) ;
normfact = normalize ? (8.0 * 0x10) : 1.0 ;
- while (--count >= 0)
- { scaled_value = src [count] * normfact ;
+ for (int i = 0 ; i < count ; i++)
+ { scaled_value = src [i] * normfact ;
if (CPU_CLIPS_POSITIVE == 0 && scaled_value >= (1.0 * 0x7F))
- { dest [count] = 0x7F ;
+ { dest [i] = 0x7F ;
continue ;
} ;
if (CPU_CLIPS_NEGATIVE == 0 && scaled_value <= (-8.0 * 0x10))
- { dest [count] = -0x80 ;
+ { dest [i] = -0x80 ;
continue ;
} ;
- dest [count] = psf_lrintf (scaled_value) ;
+ dest [i] = psf_lrintf (scaled_value) ;
} ;
return ;
normfact = normalize ? (8.0 * 0x1000) : 1.0 ;
- while (--count >= 0)
- { scaled_value = src [count] * normfact ;
+ for (int i = 0 ; i < count ; i++)
+ { scaled_value = src [i] * normfact ;
if (CPU_CLIPS_POSITIVE == 0 && scaled_value >= (1.0 * 0x7FFF))
- { dest [count] = 0x7FFF ;
+ { dest [i] = 0x7FFF ;
continue ;
} ;
if (CPU_CLIPS_NEGATIVE == 0 && scaled_value <= (-8.0 * 0x1000))
- { dest [count] = -0x8000 ;
+ { dest [i] = -0x8000 ;
continue ;
} ;
- dest [count] = psf_lrintf (scaled_value) ;
+ dest [i] = psf_lrintf (scaled_value) ;
} ;
} /* f2flac16_clip_array */
normfact = normalize ? (8.0 * 0x100000) : 1.0 ;
- while (--count >= 0)
- { scaled_value = src [count] * normfact ;
+ for (int i = 0 ; i < count ; i++)
+ { scaled_value = src [i] * normfact ;
if (CPU_CLIPS_POSITIVE == 0 && scaled_value >= (1.0 * 0x7FFFFF))
- { dest [count] = 0x7FFFFF ;
+ { dest [i] = 0x7FFFFF ;
continue ;
} ;
if (CPU_CLIPS_NEGATIVE == 0 && scaled_value <= (-8.0 * 0x100000))
- { dest [count] = -0x800000 ;
+ { dest [i] = -0x800000 ;
continue ;
}
- dest [count] = psf_lrintf (scaled_value) ;
+ dest [i] = psf_lrintf (scaled_value) ;
} ;
return ;
f2flac8_array (const float *src, int32_t *dest, int count, int normalize)
{ float normfact = normalize ? (1.0 * 0x7F) : 1.0 ;
- while (--count >= 0)
- dest [count] = psf_lrintf (src [count] * normfact) ;
+ for (int i = 0 ; i < count ; i++)
+ dest [i] = psf_lrintf (src [i] * normfact) ;
} /* f2flac8_array */
static void
f2flac16_array (const float *src, int32_t *dest, int count, int normalize)
{ float normfact = normalize ? (1.0 * 0x7FFF) : 1.0 ;
- while (--count >= 0)
- dest [count] = psf_lrintf (src [count] * normfact) ;
+ for (int i = 0 ; i < count ; i++)
+ dest [i] = psf_lrintf (src [i] * normfact) ;
} /* f2flac16_array */
static void
f2flac24_array (const float *src, int32_t *dest, int count, int normalize)
{ float normfact = normalize ? (1.0 * 0x7FFFFF) : 1.0 ;
- while (--count >= 0)
- dest [count] = psf_lrintf (src [count] * normfact) ;
+ for (int i = 0 ; i < count ; i++)
+ dest [i] = psf_lrintf (src [i] * normfact) ;
} /* f2flac24_array */
static sf_count_t
normfact = normalize ? (8.0 * 0x10) : 1.0 ;
- while (--count >= 0)
- { scaled_value = src [count] * normfact ;
+ for (int i = 0 ; i < count ; i++)
+ { scaled_value = src [i] * normfact ;
if (CPU_CLIPS_POSITIVE == 0 && scaled_value >= (1.0 * 0x7F))
- { dest [count] = 0x7F ;
+ { dest [i] = 0x7F ;
continue ;
} ;
if (CPU_CLIPS_NEGATIVE == 0 && scaled_value <= (-8.0 * 0x10))
- { dest [count] = -0x80 ;
+ { dest [i] = -0x80 ;
continue ;
} ;
- dest [count] = psf_lrint (scaled_value) ;
+ dest [i] = psf_lrint (scaled_value) ;
} ;
return ;
normfact = normalize ? (8.0 * 0x1000) : 1.0 ;
- while (--count >= 0)
- { scaled_value = src [count] * normfact ;
+ for (int i = 0 ; i < count ; i++)
+ { scaled_value = src [i] * normfact ;
if (CPU_CLIPS_POSITIVE == 0 && scaled_value >= (1.0 * 0x7FFF))
- { dest [count] = 0x7FFF ;
+ { dest [i] = 0x7FFF ;
continue ;
} ;
if (CPU_CLIPS_NEGATIVE == 0 && scaled_value <= (-8.0 * 0x1000))
- { dest [count] = -0x8000 ;
+ { dest [i] = -0x8000 ;
continue ;
} ;
- dest [count] = psf_lrint (scaled_value) ;
+ dest [i] = psf_lrint (scaled_value) ;
} ;
return ;
normfact = normalize ? (8.0 * 0x100000) : 1.0 ;
- while (--count >= 0)
- { scaled_value = src [count] * normfact ;
+ for (int i = 0 ; i < count ; i++)
+ { scaled_value = src [i] * normfact ;
if (CPU_CLIPS_POSITIVE == 0 && scaled_value >= (1.0 * 0x7FFFFF))
- { dest [count] = 0x7FFFFF ;
+ { dest [i] = 0x7FFFFF ;
continue ;
} ;
if (CPU_CLIPS_NEGATIVE == 0 && scaled_value <= (-8.0 * 0x100000))
- { dest [count] = -0x800000 ;
+ { dest [i] = -0x800000 ;
continue ;
} ;
- dest [count] = psf_lrint (scaled_value) ;
+ dest [i] = psf_lrint (scaled_value) ;
} ;
return ;
d2flac8_array (const double *src, int32_t *dest, int count, int normalize)
{ double normfact = normalize ? (1.0 * 0x7F) : 1.0 ;
- while (--count >= 0)
- dest [count] = psf_lrint (src [count] * normfact) ;
+ for (int i = 0 ; i < count ; i++)
+ dest [i] = psf_lrint (src [i] * normfact) ;
} /* d2flac8_array */
static void
d2flac16_array (const double *src, int32_t *dest, int count, int normalize)
{ double normfact = normalize ? (1.0 * 0x7FFF) : 1.0 ;
- while (--count >= 0)
- dest [count] = psf_lrint (src [count] * normfact) ;
+ for (int i = 0 ; i < count ; i++)
+ dest [i] = psf_lrint (src [i] * normfact) ;
} /* d2flac16_array */
static void
d2flac24_array (const double *src, int32_t *dest, int count, int normalize)
{ double normfact = normalize ? (1.0 * 0x7FFFFF) : 1.0 ;
- while (--count >= 0)
- dest [count] = psf_lrint (src [count] * normfact) ;
+ for (int i = 0 ; i < count ; i++)
+ dest [i] = psf_lrint (src [i] * normfact) ;
} /* d2flac24_array */
static sf_count_t
static void
f2s_array (const float *src, int count, short *dest, float scale)
{
- while (--count >= 0)
- { dest [count] = psf_lrintf (scale * src [count]) ;
+ for (int i = 0 ; i < count ; i++)
+ { dest [i] = psf_lrintf (scale * src [i]) ;
} ;
} /* f2s_array */
static void
f2s_clip_array (const float *src, int count, short *dest, float scale)
-{ while (--count >= 0)
- { float tmp = scale * src [count] ;
+{ for (int i = 0 ; i < count ; i++)
+ { float tmp = scale * src [i] ;
if (CPU_CLIPS_POSITIVE == 0 && tmp > 32767.0)
- dest [count] = SHRT_MAX ;
+ dest [i] = SHRT_MAX ;
else if (CPU_CLIPS_NEGATIVE == 0 && tmp < -32768.0)
- dest [count] = SHRT_MIN ;
+ dest [i] = SHRT_MIN ;
else
- dest [count] = psf_lrintf (tmp) ;
+ dest [i] = psf_lrintf (tmp) ;
} ;
} /* f2s_clip_array */
static inline void
f2i_array (const float *src, int count, int *dest, float scale)
-{ while (--count >= 0)
- { dest [count] = psf_lrintf (scale * src [count]) ;
+{ for (int i = 0 ; i < count ; i++)
+ { dest [i] = psf_lrintf (scale * src [i]) ;
} ;
} /* f2i_array */
static inline void
f2i_clip_array (const float *src, int count, int *dest, float scale)
-{ while (--count >= 0)
- { float tmp = scale * src [count] ;
+{ for (int i = 0 ; i < count ; i++)
+ { float tmp = scale * src [i] ;
if (CPU_CLIPS_POSITIVE == 0 && tmp > (1.0 * INT_MAX))
- dest [count] = INT_MAX ;
+ dest [i] = INT_MAX ;
else if (CPU_CLIPS_NEGATIVE == 0 && tmp < (-1.0 * INT_MAX))
- dest [count] = INT_MIN ;
+ dest [i] = INT_MIN ;
else
- dest [count] = psf_lrintf (tmp) ;
+ dest [i] = psf_lrintf (tmp) ;
} ;
} /* f2i_clip_array */
static inline void
f2d_array (const float *src, int count, double *dest)
-{ while (--count >= 0)
- { dest [count] = src [count] ;
+{ for (int i = 0 ; i < count ; i++)
+ { dest [i] = src [i] ;
} ;
} /* f2d_array */
static inline void
s2f_array (const short *src, float *dest, int count, float scale)
-{ while (--count >= 0)
- { dest [count] = scale * src [count] ;
+{ for (int i = 0 ; i < count ; i++)
+ { dest [i] = scale * src [i] ;
} ;
} /* s2f_array */
static inline void
i2f_array (const int *src, float *dest, int count, float scale)
-{ while (--count >= 0)
- { dest [count] = scale * src [count] ;
+{ for (int i = 0 ; i < count ; i++)
+ { dest [i] = scale * src [i] ;
} ;
} /* i2f_array */
static inline void
d2f_array (const double *src, float *dest, int count)
-{ while (--count >= 0)
- { dest [count] = src [count] ;
+{ for (int i = 0 ; i < count ; i++)
+ { dest [i] = src [i] ;
} ;
} /* d2f_array */
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.fbuf, sizeof (float), bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.fbuf, sizeof (float), bufferlen, psf) ;
/* Fix me : Need lef2s_array */
if (psf->data_endswap == SF_TRUE)
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.fbuf, sizeof (float), bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.fbuf, sizeof (float), bufferlen, psf) ;
if (psf->data_endswap == SF_TRUE)
endswap_int_array (ubuf.ibuf, bufferlen) ;
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.fbuf, sizeof (float), bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.fbuf, sizeof (float), bufferlen, psf) ;
endswap_int_copy ((int*) (ptr + total), ubuf.ibuf, readcount) ;
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.fbuf, sizeof (float), bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.fbuf, sizeof (float), bufferlen, psf) ;
if (psf->data_endswap == SF_TRUE)
endswap_int_array (ubuf.ibuf, bufferlen) ;
if (psf->data_endswap == SF_TRUE)
endswap_int_array (ubuf.ibuf, bufferlen) ;
- writecount = psf_fwrite (ubuf.fbuf, sizeof (float), bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.fbuf, sizeof (float), bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
if (psf->data_endswap == SF_TRUE)
endswap_int_array (ubuf.ibuf, bufferlen) ;
- writecount = psf_fwrite (ubuf.fbuf, sizeof (float) , bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.fbuf, sizeof (float) , bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
endswap_int_copy (ubuf.ibuf, (const int*) (ptr + total), bufferlen) ;
- writecount = psf_fwrite (ubuf.fbuf, sizeof (float), bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.fbuf, sizeof (float), bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
if (psf->data_endswap == SF_TRUE)
endswap_int_array (ubuf.ibuf, bufferlen) ;
- writecount = psf_fwrite (ubuf.fbuf, sizeof (float), bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.fbuf, sizeof (float), bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.fbuf, sizeof (float), bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.fbuf, sizeof (float), bufferlen, psf) ;
if (psf->data_endswap == SF_TRUE)
endswap_int_array (ubuf.ibuf, bufferlen) ;
float scale ;
bufferlen = ARRAY_LEN (ubuf.fbuf) ;
- scale = (psf->float_int_mult == 0) ? 1.0 : 0x7FFF / psf->float_max ;
+ scale = (psf->float_int_mult == 0) ? 1.0 : 2147483648.0f / psf->float_max ;
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.fbuf, sizeof (float), bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.fbuf, sizeof (float), bufferlen, psf) ;
if (psf->data_endswap == SF_TRUE)
endswap_int_array (ubuf.ibuf, bufferlen) ;
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.fbuf, sizeof (float), bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.fbuf, sizeof (float), bufferlen, psf) ;
if (psf->data_endswap == SF_TRUE)
endswap_int_array (ubuf.ibuf, bufferlen) ;
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.fbuf, sizeof (float), bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.fbuf, sizeof (float), bufferlen, psf) ;
if (psf->data_endswap == SF_TRUE)
endswap_int_array (ubuf.ibuf, bufferlen) ;
if (psf->data_endswap == SF_TRUE)
endswap_int_array (ubuf.ibuf, bufferlen) ;
- writecount = psf_fwrite (ubuf.fbuf, sizeof (float), bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.fbuf, sizeof (float), bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
if (psf->data_endswap == SF_TRUE)
endswap_int_array (ubuf.ibuf, bufferlen) ;
- writecount = psf_fwrite (ubuf.fbuf, sizeof (float), bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.fbuf, sizeof (float), bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
if (psf->data_endswap == SF_TRUE)
endswap_int_array (ubuf.ibuf, bufferlen) ;
- writecount = psf_fwrite (ubuf.fbuf, sizeof (float) , bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.fbuf, sizeof (float) , bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
if (psf->data_endswap == SF_TRUE)
endswap_int_array (ubuf.ibuf, bufferlen) ;
- writecount = psf_fwrite (ubuf.fbuf, sizeof (float), bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.fbuf, sizeof (float), bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
static void
bf2f_array (float *buffer, int count)
-{ while (--count >= 0)
- { buffer [count] = FLOAT32_READ ((unsigned char *) (buffer + count)) ;
+{ for (int i = 0 ; i < count ; i++)
+ { buffer [i] = FLOAT32_READ ((unsigned char *) &buffer [i]) ;
} ;
} /* bf2f_array */
static void
f2bf_array (float *buffer, int count)
-{ while (--count >= 0)
- { FLOAT32_WRITE (buffer [count], (unsigned char*) (buffer + count)) ;
+{ for (int i = 0 ; i < count ; i++)
+ { FLOAT32_WRITE (buffer [i], (unsigned char*) &buffer [i]) ;
} ;
} /* f2bf_array */
sptr = ubuf.sbuf ;
bufferlen = SF_BUFFER_LEN / sizeof (short) ;
while (len > 0)
- { readcount = (len >= bufferlen) ? bufferlen : len ;
+ { readcount = (len >= bufferlen) ? bufferlen : (int) len ;
count = g72x_read_block (psf, pg72x, sptr, readcount) ;
for (k = 0 ; k < readcount ; k++)
sptr = ubuf.sbuf ;
bufferlen = SF_BUFFER_LEN / sizeof (short) ;
while (len > 0)
- { readcount = (len >= bufferlen) ? bufferlen : len ;
+ { readcount = (len >= bufferlen) ? bufferlen : (int) len ;
count = g72x_read_block (psf, pg72x, sptr, readcount) ;
for (k = 0 ; k < readcount ; k++)
ptr [total + k] = normfact * sptr [k] ;
sptr = ubuf.sbuf ;
bufferlen = SF_BUFFER_LEN / sizeof (short) ;
while (len > 0)
- { readcount = (len >= bufferlen) ? bufferlen : len ;
+ { readcount = (len >= bufferlen) ? bufferlen : (int) len ;
count = g72x_read_block (psf, pg72x, sptr, readcount) ;
for (k = 0 ; k < readcount ; k++)
ptr [total + k] = normfact * (double) (sptr [k]) ;
sptr = ubuf.sbuf ;
bufferlen = SF_BUFFER_LEN / sizeof (short) ;
while (len > 0)
- { writecount = (len >= bufferlen) ? bufferlen : len ;
+ { writecount = (len >= bufferlen) ? bufferlen : (int) len ;
for (k = 0 ; k < writecount ; k++)
sptr [k] = ptr [total + k] >> 16 ;
count = g72x_write_block (psf, pg72x, sptr, writecount) ;
sptr = ubuf.sbuf ;
bufferlen = SF_BUFFER_LEN / sizeof (short) ;
while (len > 0)
- { writecount = (len >= bufferlen) ? bufferlen : len ;
+ { writecount = (len >= bufferlen) ? bufferlen : (int) len ;
for (k = 0 ; k < writecount ; k++)
sptr [k] = psf_lrintf (normfact * ptr [total + k]) ;
count = g72x_write_block (psf, pg72x, sptr, writecount) ;
sptr = ubuf.sbuf ;
bufferlen = SF_BUFFER_LEN / sizeof (short) ;
while (len > 0)
- { writecount = (len >= bufferlen) ? bufferlen : len ;
+ { writecount = (len >= bufferlen) ? bufferlen : (int) len ;
for (k = 0 ; k < writecount ; k++)
sptr [k] = psf_lrint (normfact * ptr [total + k]) ;
count = g72x_write_block (psf, pg72x, sptr, writecount) ;
return 1 ;
} ;
- if ((k = psf_fread (pgsm610->block, 1, WAVLIKE_GSM610_BLOCKSIZE, psf)) != WAVLIKE_GSM610_BLOCKSIZE)
+ if ((k = (int) psf_fread (pgsm610->block, 1, WAVLIKE_GSM610_BLOCKSIZE, psf)) != WAVLIKE_GSM610_BLOCKSIZE)
psf_log_printf (psf, "*** Warning : short read (%d != %d).\n", k, WAVLIKE_GSM610_BLOCKSIZE) ;
if (gsm_decode (pgsm610->gsm_data, pgsm610->block, pgsm610->samples) < 0)
return 1 ;
} ;
- if ((k = psf_fread (pgsm610->block, 1, GSM610_BLOCKSIZE, psf)) != GSM610_BLOCKSIZE)
+ if ((k = (int) psf_fread (pgsm610->block, 1, GSM610_BLOCKSIZE, psf)) != GSM610_BLOCKSIZE)
psf_log_printf (psf, "*** Warning : short read (%d != %d).\n", k, GSM610_BLOCKSIZE) ;
if (gsm_decode (pgsm610->gsm_data, pgsm610->block, pgsm610->samples) < 0)
sptr = ubuf.sbuf ;
bufferlen = ARRAY_LEN (ubuf.sbuf) ;
while (len > 0)
- { readcount = (len >= bufferlen) ? bufferlen : len ;
+ { readcount = (len >= bufferlen) ? bufferlen : (int) len ;
count = gsm610_read_block (psf, pgsm610, sptr, readcount) ;
for (k = 0 ; k < readcount ; k++)
ptr [total + k] = arith_shift_left (sptr [k], 16) ;
sptr = ubuf.sbuf ;
bufferlen = ARRAY_LEN (ubuf.sbuf) ;
while (len > 0)
- { readcount = (len >= bufferlen) ? bufferlen : len ;
+ { readcount = (len >= bufferlen) ? bufferlen : (int) len ;
count = gsm610_read_block (psf, pgsm610, sptr, readcount) ;
for (k = 0 ; k < readcount ; k++)
ptr [total + k] = normfact * sptr [k] ;
sptr = ubuf.sbuf ;
bufferlen = ARRAY_LEN (ubuf.sbuf) ;
while (len > 0)
- { readcount = (len >= bufferlen) ? bufferlen : len ;
+ { readcount = (len >= bufferlen) ? bufferlen : (int) len ;
count = gsm610_read_block (psf, pgsm610, sptr, readcount) ;
for (k = 0 ; k < readcount ; k++)
ptr [total + k] = normfact * sptr [k] ;
gsm_encode (pgsm610->gsm_data, pgsm610->samples, pgsm610->block) ;
/* Write the block to disk. */
- if ((k = psf_fwrite (pgsm610->block, 1, GSM610_BLOCKSIZE, psf)) != GSM610_BLOCKSIZE)
+ if ((k = (int) psf_fwrite (pgsm610->block, 1, GSM610_BLOCKSIZE, psf)) != GSM610_BLOCKSIZE)
psf_log_printf (psf, "*** Warning : short write (%d != %d).\n", k, GSM610_BLOCKSIZE) ;
pgsm610->samplecount = 0 ;
gsm_encode (pgsm610->gsm_data, pgsm610->samples+WAVLIKE_GSM610_SAMPLES / 2, pgsm610->block+WAVLIKE_GSM610_BLOCKSIZE / 2) ;
/* Write the block to disk. */
- if ((k = psf_fwrite (pgsm610->block, 1, WAVLIKE_GSM610_BLOCKSIZE, psf)) != WAVLIKE_GSM610_BLOCKSIZE)
+ if ((k = (int) psf_fwrite (pgsm610->block, 1, WAVLIKE_GSM610_BLOCKSIZE, psf)) != WAVLIKE_GSM610_BLOCKSIZE)
psf_log_printf (psf, "*** Warning : short write (%d != %d).\n", k, WAVLIKE_GSM610_BLOCKSIZE) ;
pgsm610->samplecount = 0 ;
sptr = ubuf.sbuf ;
bufferlen = ARRAY_LEN (ubuf.sbuf) ;
while (len > 0)
- { writecount = (len >= bufferlen) ? bufferlen : len ;
+ { writecount = (len >= bufferlen) ? bufferlen : (int) len ;
for (k = 0 ; k < writecount ; k++)
sptr [k] = ptr [total + k] >> 16 ;
count = gsm610_write_block (psf, pgsm610, sptr, writecount) ;
sptr = ubuf.sbuf ;
bufferlen = ARRAY_LEN (ubuf.sbuf) ;
while (len > 0)
- { writecount = (len >= bufferlen) ? bufferlen : len ;
+ { writecount = (len >= bufferlen) ? bufferlen : (int) len ;
for (k = 0 ; k < writecount ; k++)
sptr [k] = psf_lrintf (normfact * ptr [total + k]) ;
count = gsm610_write_block (psf, pgsm610, sptr, writecount) ;
sptr = ubuf.sbuf ;
bufferlen = ARRAY_LEN (ubuf.sbuf) ;
while (len > 0)
- { writecount = (len >= bufferlen) ? bufferlen : len ;
+ { writecount = (len >= bufferlen) ? bufferlen : (int) len ;
for (k = 0 ; k < writecount ; k++)
sptr [k] = psf_lrint (normfact * ptr [total + k]) ;
count = gsm610_write_block (psf, pgsm610, sptr, writecount) ;
#include "sndfile.h"
#include "sfendian.h"
#include "common.h"
+#include "id3.h"
+
+#if HAVE_MPEG
+#include <lame/lame.h>
+
+struct id3v1_genre_handler_userdata
+{ int number ;
+ const char *ret ;
+} ;
+
+static void
+id3v1_genre_handler (int number, const char *description, void *userdata)
+{ struct id3v1_genre_handler_userdata *data = (struct id3v1_genre_handler_userdata *) userdata ;
+ if (data->number == number)
+ data->ret = description ;
+}
+
+const char *
+id3_lookup_v1_genre (int number)
+{ struct id3v1_genre_handler_userdata data ;
+
+ data.number = number ;
+ data.ret = NULL ;
+ id3tag_genre_list (id3v1_genre_handler, &data) ;
+
+ return data.ret ;
+}
+
+#else /* HAVE_MPEG */
+
+const char *
+id3_lookup_v1_genre (int UNUSED (number))
+{ return NULL ;
+ }
+
+#endif
int
id3_skip (SF_PRIVATE * psf)
{ unsigned char buf [10] ;
+ int offset ;
memset (buf, 0, sizeof (buf)) ;
psf_binheader_readf (psf, "pb", 0, buf, 10) ;
if (buf [0] == 'I' && buf [1] == 'D' && buf [2] == '3')
- { int offset = buf [6] & 0x7f ;
+ { psf->id3_header.minor_version = buf [3] ;
+ offset = buf [6] & 0x7f ;
offset = (offset << 7) | (buf [7] & 0x7f) ;
offset = (offset << 7) | (buf [8] & 0x7f) ;
offset = (offset << 7) | (buf [9] & 0x7f) ;
- psf_log_printf (psf, "ID3 length : %d\n--------------------\n", offset) ;
+ /*
+ ** ID3 count field is how many bytes of ID3v2 header FOLLOW the ten
+ ** bytes of header magic and offset, NOT the total ID3v2 header len.
+ */
+ psf->id3_header.len = offset + 10 ;
+ psf->id3_header.offset = psf->fileoffset ;
+
+ psf_log_printf (psf, " ID3v2.%d header length : %d\n----------------------------------------\n",
+ psf->id3_header.minor_version, psf->id3_header.len) ;
/* Never want to jump backwards in a file. */
if (offset < 0)
return 0 ;
- /* Calculate new file offset and position ourselves there. */
- offset += 10 ;
- if (psf->fileoffset + offset < psf->filelength)
- { psf_binheader_readf (psf, "p", offset) ;
- psf->fileoffset += offset ;
+ /* Position ourselves at the new file offset. */
+ if (psf->fileoffset + psf->id3_header.len < psf->filelength)
+ { psf_binheader_readf (psf, "p!", psf->id3_header.len) ;
+ psf->fileoffset += psf->id3_header.len ;
return 1 ;
} ;
} ;
return 0 ;
} /* id3_skip */
+
+const char *
+id3_process_v2_genre (const char *genre)
+{ int num = 0 ;
+ char c ;
+ const char *ptr ;
+
+ if (!genre)
+ return NULL ;
+
+ /*
+ ** Genre may require more processing.
+ **
+ ** It is allowed to have numeric references to the genre table from ID3v1.
+ ** We'll just convert the simple case here, strings of the format "(nnn)".
+ */
+ ptr = genre ;
+ if (ptr [0] == '(' && (c = *++ ptr) && isdigit (c))
+ { num = c - '0' ;
+ while ((c == *++ ptr) && isdigit (c))
+ num = num * 10 + (c - '0') ;
+ if (c == ')' && (c = *++ ptr) == '\0' && num < 256)
+ if ((ptr = id3_lookup_v1_genre (num)))
+ return ptr ;
+ } ;
+
+ return genre ;
+} /* id3_process_v2_genre */
--- /dev/null
+/*
+** Copyright (C) 2008-2019 Erik de Castro Lopo <erikd@mega-nerd.com>
+** Copyright (C) 2019 Arthur Taylor <art@ified.ca>
+**
+** 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.
+*/
+
+#ifndef SF_SRC_ID3_H
+#define SF_SRC_ID3_H
+
+int id3_skip (SF_PRIVATE * psf) ;
+
+const char *id3_lookup_v1_genre (int number) ;
+
+const char *id3_process_v2_genre (const char *genre) ;
+
+#endif /* SF_SRC_ID3_H */
if (psf->file.mode != SFM_READ)
return SFE_BAD_MODE_RW ;
- pimasize = sizeof (IMA_ADPCM_PRIVATE) + blockalign * psf->sf.channels + 3 * psf->sf.channels * samplesperblock ;
+ /*
+ ** Allocate enough space for 1 more than a multiple of 8 samples
+ ** to avoid having to branch when pulling apart the nibbles.
+ */
+ count = ((samplesperblock - 2) | 7) + 2 ;
+ pimasize = sizeof (IMA_ADPCM_PRIVATE) + psf->sf.channels * (blockalign + samplesperblock + sizeof(short) * count) ;
if (! (pima = calloc (1, pimasize)))
return SFE_MALLOC_FAILED ;
return 1 ;
} ;
- if ((k = psf_fread (pima->block, 1, pima->blocksize * pima->channels, psf)) != pima->blocksize * pima->channels)
+ if ((k = (int) psf_fread (pima->block, 1, pima->blocksize * pima->channels, psf)) != pima->blocksize * pima->channels)
psf_log_printf (psf, "*** Warning : short read (%d != %d).\n", k, pima->blocksize) ;
/* Read and check the block header. */
} ;
/* Write the block to disk. */
- if ((k = psf_fwrite (pima->block, 1, pima->channels * pima->blocksize, psf)) != pima->channels * pima->blocksize)
+ if ((k = (int) psf_fwrite (pima->block, 1, pima->channels * pima->blocksize, psf)) != pima->channels * pima->blocksize)
psf_log_printf (psf, "*** Warning : short write (%d != %d).\n", k, pima->channels * pima->blocksize) ;
memset (pima->block, 0, pima->channels * pima->blocksize) ;
static int
wavlike_ima_decode_block (SF_PRIVATE *psf, IMA_ADPCM_PRIVATE *pima)
{ int chan, k, predictor, blockindx, indx, indxstart, diff ;
- short step, bytecode, stepindx [2] ;
+ short step, bytecode, stepindx [2] = { 0 };
pima->blockcount ++ ;
pima->samplecount = 0 ;
return 1 ;
} ;
- if ((k = psf_fread (pima->block, 1, pima->blocksize, psf)) != pima->blocksize)
+ if ((k = (int) psf_fread (pima->block, 1, pima->blocksize, psf)) != pima->blocksize)
psf_log_printf (psf, "*** Warning : short read (%d != %d).\n", k, pima->blocksize) ;
/* Read and check the block header. */
/* Write the block to disk. */
- if ((k = psf_fwrite (pima->block, 1, pima->blocksize, psf)) != pima->blocksize)
+ if ((k = (int) psf_fwrite (pima->block, 1, pima->blocksize, psf)) != pima->blocksize)
psf_log_printf (psf, "*** Warning : short write (%d != %d).\n", k, pima->blocksize) ;
memset (pima->samples, 0, pima->samplesperblock * sizeof (short)) ;
#define HEADER_LENGTH 42 /* Sum of above data fields. */
#define HEADER_NAME_LEN 17 /* Length of name string. */
-#define SFE_MPC_NO_MARKER 666
-
/*------------------------------------------------------------------------------
** Private static functions.
*/
if (psf->is_pipe == SF_FALSE)
psf_fseek (psf, 0, SEEK_SET) ;
- snprintf (sample_name, sizeof (sample_name), "%-*.*s", HEADER_NAME_LEN, HEADER_NAME_LEN, psf->file.name.c) ;
+ snprintf (sample_name, sizeof (sample_name), "%-*.*s", HEADER_NAME_LEN, HEADER_NAME_LEN, psf->file.name) ;
psf_binheader_writef (psf, "e11b", BHW1 (1), BHW1 (4), BHWv (sample_name), BHWz (HEADER_NAME_LEN)) ;
psf_binheader_writef (psf, "e111", BHW1 (100), BHW1 (0), BHW1 ((psf->sf.channels - 1) & 1)) ;
--- /dev/null
+/*
+** Copyright (C) 2019 Erik de Castro Lopo <erikd@mega-nerd.com>
+** Copyright (C) 2021 Arthur Taylor <art@ified.ca>
+**
+** 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.
+*/
+
+#include "sfconfig.h"
+
+#include "sndfile.h"
+#include "common.h"
+
+#if HAVE_MPEG
+
+#include "mpeg.h"
+
+static int mpeg_write_header (SF_PRIVATE *psf, int calc_length) ;
+static int mpeg_command (SF_PRIVATE *psf, int command, void *data, int datasize) ;
+
+/*------------------------------------------------------------------------------
+ * Private functions
+ */
+
+static int
+mpeg_write_header (SF_PRIVATE *psf, int UNUSED (calc_length))
+{
+ if (psf->have_written)
+ return 0 ;
+
+ return mpeg_l3_encoder_write_id3tag (psf) ;
+}
+
+static int
+mpeg_command (SF_PRIVATE *psf, int command, void *data, int datasize)
+{ int bitrate_mode ;
+
+ switch (command)
+ { case SFC_SET_COMPRESSION_LEVEL :
+ if (data == NULL || datasize != sizeof (double))
+ { psf->error = SFE_BAD_COMMAND_PARAM ;
+ return SF_FALSE ;
+ } ;
+ if (psf->file.mode != SFM_WRITE)
+ { psf->error = SFE_NOT_WRITEMODE ;
+ return SF_FALSE ;
+ } ;
+ return mpeg_l3_encoder_set_quality (psf, *(double *) data) ;
+
+ case SFC_SET_BITRATE_MODE :
+ if (psf->file.mode != SFM_WRITE)
+ { psf->error = SFE_NOT_WRITEMODE ;
+ return SF_FALSE ;
+ } ;
+ if (data == NULL || datasize != sizeof (int))
+ { psf->error = SFE_BAD_COMMAND_PARAM ;
+ return SF_FALSE ;
+ } ;
+ bitrate_mode = *(int *) data ;
+ return mpeg_l3_encoder_set_bitrate_mode (psf, bitrate_mode) ;
+
+ case SFC_GET_BITRATE_MODE :
+ if (psf->file.mode == SFM_READ)
+ return mpeg_decoder_get_bitrate_mode (psf) ;
+ else
+ return mpeg_l3_encoder_get_bitrate_mode (psf) ;
+
+ default :
+ return SF_FALSE ;
+ } ;
+
+ return SF_FALSE ;
+} /* mpeg_command */
+
+/*------------------------------------------------------------------------------
+ * Public functions
+ */
+
+int
+mpeg_init (SF_PRIVATE *psf, int bitrate_mode, int write_metadata)
+{ int error ;
+
+ if (psf->file.mode == SFM_RDWR)
+ return SFE_BAD_MODE_RW ;
+
+ if (psf->file.mode == SFM_WRITE)
+ { switch (SF_CODEC (psf->sf.format))
+ { case SF_FORMAT_MPEG_LAYER_III :
+ if ((error = mpeg_l3_encoder_init (psf, write_metadata)))
+ return error ;
+ mpeg_l3_encoder_set_bitrate_mode (psf, bitrate_mode) ;
+ if (write_metadata)
+ { /* ID3 support */
+ psf->strings.flags = SF_STR_ALLOW_START ;
+ psf->write_header = mpeg_write_header ;
+ } ;
+ break ;
+
+ case SF_FORMAT_MPEG_LAYER_I :
+ case SF_FORMAT_MPEG_LAYER_II :
+ psf_log_printf (psf, "MPEG Layer I and II encoding is not yet supported.\n") ;
+ return SFE_UNIMPLEMENTED ;
+
+ default:
+ psf_log_printf (psf, "%s: bad psf->sf.format 0x%x.\n", __func__, psf->sf.format) ;
+ return SFE_INTERNAL ;
+ } ;
+ } ;
+
+ if (psf->file.mode == SFM_READ)
+ { if ((error = mpeg_decoder_init (psf)))
+ return error ;
+ } ;
+
+ return 0 ;
+} /* mpeg_init */
+
+int
+mpeg_open (SF_PRIVATE *psf)
+{ int error ;
+
+ /* Choose variable bitrate mode by default for standalone files.*/
+ if ((error = mpeg_init (psf, SF_BITRATE_MODE_VARIABLE, SF_TRUE)))
+ return error ;
+
+ psf->dataoffset = 0 ;
+ psf->command = mpeg_command ;
+
+ if (psf->filelength != SF_COUNT_MAX)
+ psf->datalength = psf->filelength - psf->dataoffset ;
+ else
+ psf->datalength = SF_COUNT_MAX ;
+
+
+ return 0 ;
+} /* mpeg_open */
+
+#else /* HAVE_MPEG */
+
+int
+mpeg_init (SF_PRIVATE *psf, int UNUSED (bitrate_mode) , int UNUSED (write_metadata))
+{
+ psf_log_printf (psf, "This version of libsndfile was compiled without MPEG support.\n") ;
+ return SFE_UNIMPLEMENTED ;
+} /* mpeg_init */
+
+int
+mpeg_open (SF_PRIVATE *psf)
+{
+ psf_log_printf (psf, "This version of libsndfile was compiled without MP3 support.\n") ;
+ return SFE_UNIMPLEMENTED ;
+} /* mpeg_open */
+
+#endif
--- /dev/null
+/*
+** Copyright (C) 2019 Erik de Castro Lopo <erikd@mega-nerd.com>
+** Copyright (C) 2019 Arthur Taylor <art@ified.ca>
+**
+** 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.
+*/
+
+#ifndef SNDFILE_MPEG_H
+#define SNDFILE_MPEG_H
+
+#include "common.h"
+
+int mpeg_decoder_init (SF_PRIVATE *psf) ;
+
+/*
+** Get the file bitrate mode, returning one of the SF_BITRATE_MODE_ enum
+** values. Purely informative, 'Frankenstein' files and VBR files without an
+** Xing/LAME/Info header may not be detected properly.
+*/
+int mpeg_decoder_get_bitrate_mode (SF_PRIVATE *psf) ;
+
+
+/*
+** Initialize an encoder instance for writing. If parameter info_tag is
+** SF_TRUE, a Xing/LAME/Info header is written at the beginning of the file,
+** (unless the file cannot seek.)
+*/
+int mpeg_l3_encoder_init (SF_PRIVATE *psf, int info_tag) ;
+
+
+/*
+** Write an ID3v2 header from the sndfile string metadata. Must be called
+** before any audio data is written. Writing an ID3v2 header will also cause
+** a ID3v1 trailer to be written on close automatically.
+*/
+int mpeg_l3_encoder_write_id3tag (SF_PRIVATE *psf) ;
+
+/*
+** Set the encoder quality setting. Argument to compression should be identical
+** to that for SFC_SET_COMPRESSION_LEVEL; It should be in the range [0-1],
+** with 0 being highest quality, least compression, and 1 being the opposite.
+** Returns SF_TRUE on success, SF_FALSE otherwise.
+*/
+int mpeg_l3_encoder_set_quality (SF_PRIVATE *psf, double compression) ;
+
+/*
+** Set the encoder bitrate mode. Can only be called before any data has been
+** written. Argument mode should be one of the SF_BITRATE_MODE_ enum values.
+** Returns SF_TRUE on success, SF_FALSE otherwise. The SF_BITRATE_MODE_FILE
+** enum value should not be passed here but rather intercepted at the container
+** level and translated according to the container.
+*/
+int mpeg_l3_encoder_set_bitrate_mode (SF_PRIVATE *psf, int mode) ;
+
+/*
+** Get the encoder bitrate mode in use. Returns a SF_BITRATE_MODE_ enum value.
+** Will not return SF_BITRATE_MODE_FILE.
+*/
+int mpeg_l3_encoder_get_bitrate_mode (SF_PRIVATE *psf) ;
+
+
+#endif /* SNDFILE_MPEG_H */
--- /dev/null
+/*
+** Copyright (C) 2019 - 2021 Arthur Taylor <art@ified.ca>
+** Copyright (C) 2019 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.
+*/
+
+#include "sfconfig.h"
+
+#include <math.h>
+
+#include "sndfile.h"
+#include "common.h"
+#include "mpeg.h"
+
+#if HAVE_MPEG
+
+#include "sfendian.h"
+#include "id3.h"
+
+#include <mpg123.h>
+
+typedef struct
+{ mpg123_handle *pmh ;
+ size_t header_remaining ;
+} MPEG_DEC_PRIVATE ;
+
+static int mpeg_dec_close (SF_PRIVATE *psf) ;
+static sf_count_t mpeg_dec_seek (SF_PRIVATE *psf, int whence, sf_count_t count) ;
+
+static ssize_t mpeg_dec_io_read (void *priv, void *buffer, size_t nbytes) ;
+static off_t mpeg_dec_io_lseek (void *priv, off_t offset, int whence) ;
+
+static ssize_t
+mpeg_dec_io_read (void *priv, void *buffer, size_t nbytes)
+{ SF_PRIVATE *psf = (SF_PRIVATE *) priv ;
+ MPEG_DEC_PRIVATE *pmp3d = (MPEG_DEC_PRIVATE *) psf->codec_data ;
+
+ if (pmp3d->header_remaining)
+ { if (pmp3d->header_remaining < nbytes)
+ nbytes = pmp3d->header_remaining ;
+ psf_binheader_readf (psf, "b", buffer, nbytes) ;
+ pmp3d->header_remaining -= nbytes ;
+ return nbytes ;
+ } ;
+
+ return psf_fread (buffer, 1, nbytes, psf) ;
+} /* mpeg_dec_io_read */
+
+static off_t
+mpeg_dec_io_lseek (void *priv, off_t offset, int whence)
+{ SF_PRIVATE *psf = (SF_PRIVATE *) priv ;
+
+ return psf_fseek (psf, offset, whence) ;
+} /* mpeg_dec_io_lseek */
+
+static int
+mpeg_dec_close (SF_PRIVATE *psf)
+{ MPEG_DEC_PRIVATE *pmp3d = (MPEG_DEC_PRIVATE *) psf->codec_data ;
+
+ if (pmp3d)
+ { if (pmp3d->pmh)
+ { mpg123_close (pmp3d->pmh) ;
+ mpg123_delete (pmp3d->pmh) ;
+ pmp3d->pmh = NULL ;
+ }
+ free (psf->codec_data) ;
+ psf->codec_data = NULL ;
+ } ;
+
+ return 0 ;
+} /* mpeg_dec_close */
+
+static sf_count_t
+mpeg_dec_decode (SF_PRIVATE *psf, float *ptr, sf_count_t len)
+{ MPEG_DEC_PRIVATE *pmp3d = (MPEG_DEC_PRIVATE *) psf->codec_data ;
+ size_t done ;
+ int error ;
+
+ error = mpg123_read (pmp3d->pmh, (unsigned char *) ptr, len * sizeof (float), &done) ;
+
+ if (error == MPG123_OK)
+ return done / sizeof (float) ;
+
+ if (error == MPG123_DONE)
+ return 0 ;
+
+ if (error == MPG123_NEW_FORMAT)
+ { psf->error = SFE_MALFORMED_FILE ;
+ return -1 ;
+ } ;
+
+ psf->error = SFE_INTERNAL ;
+ return -1 ;
+} /* mpeg_dec_decode */
+
+static sf_count_t
+mpeg_dec_read_s (SF_PRIVATE *psf, short *ptr, sf_count_t len)
+{ BUF_UNION ubuf ;
+ sf_count_t total, readlen ;
+ void (*convert) (const float *, short *, int, int) ;
+ const sf_count_t buflen = ARRAY_LEN (ubuf.fbuf) ;
+
+ convert = (psf->add_clipping) ? psf_f2s_clip_array : psf_f2s_array ;
+ for (total = 0 ; total < len ; total += readlen)
+ { readlen = mpeg_dec_decode (psf, ubuf.fbuf, SF_MIN (buflen, len - total)) ;
+ if (readlen <= 0)
+ break ;
+
+ convert (ubuf.fbuf, ptr + total, readlen, SF_TRUE) ;
+ } ;
+
+ return total ;
+} /*mpeg_dec_read_s */
+
+static sf_count_t
+mpeg_dec_read_i (SF_PRIVATE *psf, int *ptr, sf_count_t len)
+{ BUF_UNION ubuf ;
+ sf_count_t total, readlen ;
+ void (*convert) (const float *, int *, int, int) ;
+ const sf_count_t buflen = ARRAY_LEN (ubuf.fbuf) ;
+
+ convert = (psf->add_clipping) ? psf_f2i_clip_array : psf_f2i_array ;
+ for (total = 0 ; total < len ; total += readlen)
+ { readlen = mpeg_dec_decode (psf, ubuf.fbuf, SF_MIN (buflen, len - total)) ;
+ if (readlen <= 0)
+ break ;
+
+ convert (ubuf.fbuf, ptr + total, readlen, SF_TRUE) ;
+ } ;
+
+ return total ;
+} /* mpeg_dec_read_i */
+
+static sf_count_t
+mpeg_dec_read_f (SF_PRIVATE *psf, float *ptr, sf_count_t len)
+{ sf_count_t readlen ;
+
+ readlen = mpeg_dec_decode (psf, ptr, len) ;
+ if (readlen <= 0)
+ return 0 ;
+
+ if (psf->norm_float == SF_FALSE)
+ for (int i = 0 ; i < readlen ; i++)
+ { ptr [i] *= (1.0f * 0x8000) ;
+ } ;
+
+ return readlen ;
+} /* mpeg_dec_read_f */
+
+static inline void
+f2d_array (const float *src, int count, double *dest, double normfact)
+{ for (int i = 0 ; i < count ; i++)
+ { dest [i] = src [i] * normfact ;
+ }
+} /* f2d_array */
+
+static sf_count_t
+mpeg_dec_read_d (SF_PRIVATE *psf, double *ptr, sf_count_t len)
+{ BUF_UNION ubuf ;
+ sf_count_t total, readlen ;
+ double normfact ;
+ const sf_count_t buflen = ARRAY_LEN (ubuf.fbuf) ;
+
+ normfact = (psf->norm_double == SF_TRUE) ? 1.0 : (1.0 * 0x8000) ;
+
+ for (total = 0 ; total < len ; total += readlen)
+ { readlen = mpeg_dec_decode (psf, ubuf.fbuf, SF_MIN (buflen, len - total)) ;
+ if (readlen <= 0)
+ break ;
+
+ f2d_array (ubuf.fbuf, readlen, ptr + total, normfact) ;
+ } ;
+
+ return total ;
+} /* mpeg_dec_read_d */
+
+static sf_count_t
+mpeg_dec_seek (SF_PRIVATE *psf, int mode, sf_count_t count)
+{ MPEG_DEC_PRIVATE *pmp3d = (MPEG_DEC_PRIVATE *) psf->codec_data ;
+ off_t ret ;
+
+ if (mode != SFM_READ || psf->file.mode != SFM_READ)
+ { psf->error = SFE_BAD_SEEK ;
+ return PSF_SEEK_ERROR ;
+ } ;
+
+ ret = mpg123_seek (pmp3d->pmh, count, SEEK_SET) ;
+
+ if (ret < 0)
+ return PSF_SEEK_ERROR ;
+
+ return (sf_count_t) ret ;
+} /* mpeg_dec_seek */
+
+static int
+mpeg_dec_fill_sfinfo (mpg123_handle *mh, SF_INFO *info)
+{ int error ;
+ int channels ;
+ int encoding ;
+ long rate ;
+ off_t length ;
+
+ error = mpg123_getformat (mh, &rate, &channels, &encoding) ;
+ if (error != MPG123_OK)
+ return error ;
+
+ info->samplerate = rate ;
+ info->channels = channels ;
+
+ length = mpg123_length (mh) ;
+ if (length >= 0)
+ { info->frames = length ;
+ info->seekable = SF_TRUE ;
+ }
+ else
+ { info->frames = SF_COUNT_MAX ;
+ info->seekable = SF_FALSE ;
+ }
+
+ /* Force 32-bit float samples. */
+ if (encoding != MPG123_ENC_FLOAT_32)
+ { error = mpg123_format (mh, rate, channels, MPG123_ENC_FLOAT_32) ;
+ } ;
+
+ return error ;
+} /* mpeg_dec_fill_sfinfo */
+
+static void
+mpeg_dec_print_frameinfo (SF_PRIVATE *psf, const struct mpg123_frameinfo *fi)
+{ psf_log_printf (psf, "MPEG-1/2 Audio\n----------------------------------------\n") ;
+ psf_log_printf (psf, " MPEG version : %s\n",
+ fi->version == MPG123_1_0 ? "MPEG 1.0" :
+ fi->version == MPG123_2_0 ? "MPEG 2.0" :
+ fi->version == MPG123_2_5 ? "MPEG 2.5" : "???") ;
+ psf_log_printf (psf, " layer : %d\n", fi->layer) ;
+ psf_log_printf (psf, " rate : %d\n", fi->rate) ;
+ psf_log_printf (psf, " mode : %s\n",
+ fi->mode == MPG123_M_STEREO ? "stereo" :
+ fi->mode == MPG123_M_JOINT ? "joint stereo" :
+ fi->mode == MPG123_M_DUAL ? "dual channel" :
+ fi->mode == MPG123_M_MONO ? "mono" : "???") ;
+ psf_log_printf (psf, " mode ext : %d\n", fi->mode_ext) ;
+ psf_log_printf (psf, " framesize : %d\n", fi->framesize) ;
+ psf_log_printf (psf, " crc : %d\n", !! (fi->flags & MPG123_CRC)) ;
+ psf_log_printf (psf, " copyright flag : %d\n", !! (fi->flags & MPG123_COPYRIGHT)) ;
+ psf_log_printf (psf, " private flag : %d\n", !! (fi->flags & MPG123_PRIVATE)) ;
+ psf_log_printf (psf, " original flag : %d\n", !! (fi->flags & MPG123_ORIGINAL)) ;
+ psf_log_printf (psf, " emphasis : %d\n", fi->emphasis) ;
+ psf_log_printf (psf, " bitrate mode : ") ;
+ switch (fi->vbr)
+ { case MPG123_CBR :
+ psf_log_printf (psf, "constant\n") ;
+ psf_log_printf (psf, " bitrate : %d kbps\n", fi->bitrate) ;
+ break ;
+ case MPG123_VBR :
+ psf_log_printf (psf, "variable\n") ;
+ break ;
+
+ case MPG123_ABR :
+ psf_log_printf (psf, "average\n") ;
+ psf_log_printf (psf, " ABR target : %d\n", fi->abr_rate) ;
+ break ;
+
+ default :
+ psf_log_printf (psf, "(%d) ???\n", fi->vbr) ;
+ break ;
+ } ;
+} /* mpeg_dec_print_frameinfo */
+
+/*
+ * Like strlcpy, except the size argument is the maximum size of the input,
+ * always null terminates the output string. Thus, up to size + 1 bytes may be
+ * written.
+ *
+ * Returns the length of the copied string.
+ */
+static int
+strcpy_inbounded (char *dest, size_t size, const char *src)
+{ char *c = memccpy (dest, src, '\0', size) ;
+ if (!c)
+ c = dest + size ;
+ *c = '\0' ;
+ return c - dest ;
+} /* strcpy_inbounded */
+
+static void
+mpeg_decoder_read_strings_id3v1 (SF_PRIVATE *psf, mpg123_id3v1 *tags)
+{ const char *genre ;
+ char buf [31] ;
+
+ psf_log_printf (psf, "ID3v1 Tags\n") ;
+
+ if (strcpy_inbounded (buf, ARRAY_LEN (tags->title), tags->title))
+ { psf_log_printf (psf, " Title : %s\n", buf) ;
+ psf_store_string (psf, SF_STR_TITLE, buf) ;
+ } ;
+
+ if (strcpy_inbounded (buf, ARRAY_LEN (tags->artist), tags->artist))
+ { psf_log_printf (psf, " Artist : %s\n", buf) ;
+ psf_store_string (psf, SF_STR_ARTIST, buf) ;
+ } ;
+
+ if (strcpy_inbounded (buf, ARRAY_LEN (tags->album), tags->album))
+ { psf_log_printf (psf, " Album : %s\n", buf) ;
+ psf_store_string (psf, SF_STR_ALBUM, buf) ;
+ } ;
+
+ if (strcpy_inbounded (buf, ARRAY_LEN (tags->year), tags->year))
+ { psf_log_printf (psf, " Year : %s\n", buf) ;
+ psf_store_string (psf, SF_STR_DATE, buf) ;
+ } ;
+
+ if (strcpy_inbounded (buf, ARRAY_LEN (tags->comment), tags->comment))
+ { psf_log_printf (psf, " Comment : %s\n", buf) ;
+ psf_store_string (psf, SF_STR_COMMENT, buf) ;
+ } ;
+
+ /* ID3v1.1 Tracknumber */
+ if (tags->comment [28] == '\0' && tags->comment [29] != '\0')
+ { snprintf (buf, ARRAY_LEN (buf), "%hhu", (unsigned char) tags->comment [29]) ;
+ psf_log_printf (psf, " Tracknumber : %s\n", buf) ;
+ psf_store_string (psf, SF_STR_TRACKNUMBER, buf) ;
+ } ;
+
+ if ((genre = id3_lookup_v1_genre (tags->genre)) != NULL)
+ { psf_log_printf (psf, " Genre : %s\n", genre) ;
+ psf_store_string (psf, SF_STR_GENRE, genre) ;
+ } ;
+} /* mpeg_decoder_read_strings_id3v1 */
+
+static void
+mpeg_decoder_read_strings_id3v2 (SF_PRIVATE *psf, mpg123_id3v2 *tags)
+{ mpg123_text *text_frame ;
+ size_t i ;
+ uint32_t marker ;
+ const char *title = NULL ;
+ const char *copyright = NULL ;
+ const char *software = NULL ;
+ const char *artist = NULL ;
+ const char *comment = NULL ;
+ const char *date = NULL ;
+ const char *album = NULL ;
+ const char *license = NULL ;
+ const char *tracknumber = NULL ;
+ const char *genre = NULL ;
+ const char *tlen = NULL ;
+
+ psf_log_printf (psf, "ID3v2 Tags\n") ;
+
+ // Read the parsed text tags
+ for (i = 0 ; i < tags->texts ; i++)
+ { text_frame = &tags->text [i] ;
+ psf_log_printf (psf, " %.4s : %s\n", text_frame->id, text_frame->text.p) ;
+
+ // Thankfully mpg123 translates v2.2 3-byte frames to v2.3 4-byte for us.
+ marker = MAKE_MARKER (text_frame->id [0], text_frame->id [1],
+ text_frame->id [2], text_frame->id [3]) ;
+
+ /* Use our own map of frame types to metadata for text frames */
+ switch (marker)
+ { case MAKE_MARKER ('T', 'I', 'T', '2') :
+ title = text_frame->text.p ;
+ break ;
+
+ case MAKE_MARKER ('T', 'C', 'O', 'P') :
+ copyright = text_frame->text.p ;
+ break ;
+
+ case MAKE_MARKER ('T', 'E', 'N', 'C') :
+ case MAKE_MARKER ('T', 'S', 'S', 'E') :
+ software = text_frame->text.p ;
+ break ;
+
+ case MAKE_MARKER ('T', 'P', 'E', '1') :
+ artist = text_frame->text.p ;
+ break ;
+
+ case MAKE_MARKER ('T', 'A', 'L', 'B') :
+ album = text_frame->text.p ;
+ break ;
+
+ case MAKE_MARKER ('T', 'R', 'C', 'K') :
+ tracknumber = text_frame->text.p ;
+ break ;
+
+ case MAKE_MARKER ('T', 'Y', 'E', 'R') :
+ case MAKE_MARKER ('T', 'D', 'R', 'C') :
+ /* TODO (maybe)
+ case MAKE_MARKER ('T', 'D', 'A', 'T') :
+ case MAKE_MARKER ('T', 'I', 'M', 'E') :
+ case MAKE_MARKER ('T', 'D', 'R', 'A') :
+ */
+ date = text_frame->text.p ;
+ break ;
+
+ case MAKE_MARKER ('T', 'O', 'W', 'N') :
+ tracknumber = text_frame->text.p ;
+ break ;
+
+ case MAKE_MARKER ('T', 'C', 'O', 'N') :
+ genre = text_frame->text.p ;
+ break ;
+
+ case MAKE_MARKER ('T', 'L', 'E', 'N') :
+ tlen = text_frame->text.p ;
+ break ;
+ } ;
+ } ;
+
+ /* Use mpg123's handling of comment headers, but print all the comment headers anyways. */
+ if (tags->comment)
+ comment = tags->comment->p ;
+ for (i = 0 ; i < tags->comments ; i++)
+ { text_frame = &tags->comment_list [i] ;
+ psf_log_printf (psf, " %.4s : (%s)[%s] %s\n", text_frame->id,
+ text_frame->description. p, text_frame->lang, text_frame->text.p) ;
+ } ;
+
+ /* Print extra headers */
+ for (i = 0 ; i < tags->extras ; i++)
+ { text_frame = &tags->extra [i] ;
+ psf_log_printf (psf, " %.4s : (%s) %s\n", text_frame->id,
+ text_frame->description.p, text_frame->text.p) ;
+ } ;
+
+ if (title != NULL)
+ psf_store_string (psf, SF_STR_TITLE, title) ;
+ if (copyright != NULL)
+ psf_store_string (psf, SF_STR_COPYRIGHT, copyright) ;
+ if (software != NULL)
+ psf_store_string (psf, SF_STR_SOFTWARE, software) ;
+ if (artist != NULL)
+ psf_store_string (psf, SF_STR_ARTIST, artist) ;
+ if (comment != NULL)
+ psf_store_string (psf, SF_STR_COMMENT, comment) ;
+ if (date != NULL)
+ psf_store_string (psf, SF_STR_DATE, date) ;
+ if (album != NULL)
+ psf_store_string (psf, SF_STR_ALBUM, album) ;
+ if (license != NULL)
+ psf_store_string (psf, SF_STR_LICENSE, license) ;
+ if (tracknumber != NULL)
+ psf_store_string (psf, SF_STR_TRACKNUMBER, tracknumber) ;
+ if (genre != NULL)
+ psf_store_string (psf, SF_STR_GENRE, id3_process_v2_genre (genre)) ;
+ if (tlen != NULL)
+ { /* If non-seekable, set framecount? Can we trust it? */
+ } ;
+} /* mpeg_decoder_read_strings_id3v2 */
+
+static void
+mpeg_decoder_read_strings (SF_PRIVATE *psf)
+{ MPEG_DEC_PRIVATE *pmp3d = (MPEG_DEC_PRIVATE *) psf->codec_data ;
+ mpg123_id3v1 *v1_tags ;
+ mpg123_id3v2 *v2_tags ;
+
+ if (mpg123_id3 (pmp3d->pmh, &v1_tags, &v2_tags) != MPG123_OK)
+ return ;
+
+ if (v1_tags != NULL)
+ mpeg_decoder_read_strings_id3v1 (psf, v1_tags) ;
+
+ if (v2_tags != NULL)
+ mpeg_decoder_read_strings_id3v2 (psf, v2_tags) ;
+} /* mpeg_decoder_read_strings */
+
+static int
+mpeg_dec_byterate (SF_PRIVATE *psf)
+{ MPEG_DEC_PRIVATE *pmp3d = (MPEG_DEC_PRIVATE *) psf->codec_data ;
+ struct mpg123_frameinfo fi ;
+
+ if (mpg123_info (pmp3d->pmh, &fi) == MPG123_OK)
+ return (fi.bitrate + 7) / 8 ;
+
+ return -1 ;
+
+} /* mpeg_dec_byterate */
+
+/*==============================================================================
+** exported functions
+*/
+
+int
+mpeg_decoder_init (SF_PRIVATE *psf)
+{ MPEG_DEC_PRIVATE *pmp3d ;
+ struct mpg123_frameinfo fi ;
+ int error ;
+
+ if (! (psf->file.mode & SFM_READ))
+ return SFE_INTERNAL ;
+
+ /*
+ ** *** FIXME - Threading issues ***
+ **
+ ** mpg123_init() is a global call that should only be called once, and
+ ** should be paried with mpg123_exit() when done. libsndfile does not
+ ** provide for these requirements.
+ **
+ ** Currently this is a moot issue as mpg123_init() non-conditionally writes
+ ** static areas with calculated data, and mpg123_exit() is a NOP, but this
+ ** could change in a future version of it!
+ **
+ ** From mpg123.h:
+ ** > This should be called once in a non-parallel context. It is not explicitly
+ ** > thread-safe, but repeated/concurrent calls still _should_ be safe as static
+ ** > tables are filled with the same values anyway.
+ **
+ ** Note that calling mpg123_init() after it has already completed is a NOP.
+ **
+ ** Update 2021-07-04
+ ** mpg123 upstream has confirmed that mpg132_init() will become a NOP in future,
+ ** so this is moot.
+ */
+ if (mpg123_init () != MPG123_OK)
+ return SFE_INTERNAL ;
+
+ psf->codec_data = pmp3d = calloc (1, sizeof (MPEG_DEC_PRIVATE)) ;
+ if (!psf->codec_data)
+ return SFE_MALLOC_FAILED ;
+
+ pmp3d->pmh = mpg123_new (NULL, &error) ;
+ if (!pmp3d->pmh)
+ { psf_log_printf (psf, "Could not obtain a mpg123 handle: %s\n", mpg123_plain_strerror (error)) ;
+ return SFE_INTERNAL ;
+ } ;
+
+ psf->codec_close = mpeg_dec_close ;
+
+ mpg123_replace_reader_handle (pmp3d->pmh,
+ mpeg_dec_io_read, mpeg_dec_io_lseek, NULL) ;
+
+ mpg123_param (pmp3d->pmh, MPG123_REMOVE_FLAGS, MPG123_AUTO_RESAMPLE, 1.0) ;
+ mpg123_param (pmp3d->pmh, MPG123_ADD_FLAGS, MPG123_FORCE_FLOAT | MPG123_GAPLESS, 1.0) ;
+#if MPG123_API_VERSION >= 45
+ mpg123_param (pmp3d->pmh, MPG123_ADD_FLAGS, MPG123_NO_FRANKENSTEIN, 1.0) ;
+#endif
+
+ /*
+ ** Need to pass the first MPEG frame to libmpg123, but that frame was read
+ ** into psf->binheader in order that we could identify the stream.
+ */
+ if (psf->is_pipe)
+ { /*
+ ** Can't seek, so setup our libmpg123 io callbacks to read the binheader
+ ** buffer first.
+ */
+ psf_binheader_readf (psf, "p", psf->dataoffset) ;
+ pmp3d->header_remaining = psf_binheader_readf (psf, NULL) - psf->dataoffset ;
+
+ /* Tell libmpg123 we can't seek the file. */
+ mpg123_param (pmp3d->pmh, MPG123_ADD_FLAGS, MPG123_NO_PEEK_END, 1.0) ;
+ }
+ else
+ { /*
+ ** libmpg123 can parse the ID3v2 header. Undo the embedded file offset if the
+ ** enclosing file data is the ID3v2 header.
+ */
+ if (psf->id3_header.len > 0 && psf->id3_header.len + psf->id3_header.offset == psf->fileoffset)
+ psf->fileoffset = psf->id3_header.offset ;
+
+ psf_fseek (psf, 0, SEEK_SET) ;
+ } ;
+
+ error = mpg123_open_handle (pmp3d->pmh, psf) ;
+ if (error != MPG123_OK)
+ { psf_log_printf (psf, "mpg123 could not open the file: %s\n", mpg123_plain_strerror (error)) ;
+ return SFE_BAD_FILE ;
+ } ;
+
+ if (mpeg_dec_fill_sfinfo (pmp3d->pmh, &psf->sf) != MPG123_OK)
+ { psf_log_printf (psf, "Cannot get MPEG decoder configuration: %s\n", mpg123_plain_strerror (error)) ;
+ return SFE_BAD_FILE ;
+ } ;
+
+ error = mpg123_info (pmp3d->pmh, &fi) ;
+ if (error != MPG123_OK)
+ { psf_log_printf (psf, "Cannot get MPEG frame info: %s\n", mpg123_plain_strerror (error)) ;
+ return SFE_INTERNAL ;
+ }
+
+ switch (fi.layer)
+ { case 1 : psf->sf.format |= SF_FORMAT_MPEG_LAYER_I ; break ;
+ case 2 : psf->sf.format |= SF_FORMAT_MPEG_LAYER_II ; break ;
+ case 3 : psf->sf.format |= SF_FORMAT_MPEG_LAYER_III ; break ;
+ default :
+ return SFE_BAD_FILE ;
+ } ;
+ mpeg_dec_print_frameinfo (psf, &fi) ;
+
+ psf->read_short = mpeg_dec_read_s ;
+ psf->read_int = mpeg_dec_read_i ;
+ psf->read_float = mpeg_dec_read_f ;
+ psf->read_double = mpeg_dec_read_d ;
+ psf->seek = mpeg_dec_seek ;
+ psf->byterate = mpeg_dec_byterate ;
+
+ mpeg_decoder_read_strings (psf) ;
+
+ return 0 ;
+} /* mpeg_decoder_init */
+
+int
+mpeg_decoder_get_bitrate_mode (SF_PRIVATE *psf)
+{ MPEG_DEC_PRIVATE *pmp3d = (MPEG_DEC_PRIVATE *) psf->codec_data ;
+ struct mpg123_frameinfo fi ;
+
+ if (mpg123_info (pmp3d->pmh, &fi) == MPG123_OK)
+ {
+ switch (fi.vbr)
+ { case MPG123_CBR : return SF_BITRATE_MODE_CONSTANT ;
+ case MPG123_ABR : return SF_BITRATE_MODE_AVERAGE ;
+ case MPG123_VBR : return SF_BITRATE_MODE_VARIABLE ;
+ default : break ;
+ } ;
+ } ;
+
+ psf_log_printf (psf, "Cannot determine MPEG bitrate mode.\n") ;
+ return -1 ;
+} /* mpeg_decoder_get_bitrate_mode */
+
+#else /* HAVE_MPEG */
+
+int mpeg_decoder_init (SF_PRIVATE *psf)
+{ psf_log_printf (psf, "This version of libsndfile was compiled without MPEG decode support.\n") ;
+ return SFE_UNIMPLEMENTED ;
+} /* mpeg_decoder_init */
+
+#endif /* HAVE_MPEG */
--- /dev/null
+/*
+** Copyright (C) 2020 Arthur Taylor <art@ified.ca>
+** Copyright (C) 2019 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.
+*/
+
+#include "sfconfig.h"
+#include "sndfile.h"
+#include "common.h"
+#include "mpeg.h"
+
+
+#if HAVE_MPEG
+
+#include <lame/lame.h>
+
+/*
+ * RANT RANT RANT
+ *
+ * Lame has 11 functions for inputing sample data of various types and
+ * configurations, but due to bad definitions, or missing combinations, they
+ * aren't really of much help to us.
+ *
+ */
+
+typedef struct
+{ lame_t lamef ;
+ unsigned char *block ;
+ size_t block_len ;
+ int frame_samples ;
+ double compression ;
+ int initialized ;
+} MPEG_L3_ENC_PRIVATE ;
+
+
+/*-----------------------------------------------------------------------------------------------
+** Private function prototypes.
+*/
+
+static int mpeg_l3_encoder_close (SF_PRIVATE *psf) ;
+static int mpeg_l3_encoder_construct (SF_PRIVATE *psf) ;
+static int mpeg_l3_encoder_byterate (SF_PRIVATE *psf) ;
+
+static sf_count_t mpeg_l3_encode_write_short_stereo (SF_PRIVATE *psf, const short *ptr, sf_count_t len) ;
+static sf_count_t mpeg_l3_encode_write_int_stereo (SF_PRIVATE *psf, const int *ptr, sf_count_t len) ;
+static sf_count_t mpeg_l3_encode_write_float_stereo (SF_PRIVATE *psf, const float *ptr, sf_count_t len) ;
+static sf_count_t mpeg_l3_encode_write_double_stereo (SF_PRIVATE *psf, const double *ptr, sf_count_t len) ;
+static sf_count_t mpeg_l3_encode_write_short_mono (SF_PRIVATE *psf, const short *ptr, sf_count_t len) ;
+static sf_count_t mpeg_l3_encode_write_int_mono (SF_PRIVATE *psf, const int *ptr, sf_count_t len) ;
+static sf_count_t mpeg_l3_encode_write_float_mono (SF_PRIVATE *psf, const float *ptr, sf_count_t len) ;
+static sf_count_t mpeg_l3_encode_write_double_mono (SF_PRIVATE *psf, const double *ptr, sf_count_t len) ;
+
+/*-----------------------------------------------------------------------------------------------
+** Exported functions.
+*/
+
+int
+mpeg_l3_encoder_init (SF_PRIVATE *psf, int info_tag)
+{ MPEG_L3_ENC_PRIVATE* pmpeg = NULL ;
+
+ if (psf->file.mode == SFM_RDWR)
+ return SFE_BAD_MODE_RW ;
+
+ if (psf->file.mode != SFM_WRITE)
+ return SFE_INTERNAL ;
+
+ psf->codec_data = pmpeg = calloc (1, sizeof (MPEG_L3_ENC_PRIVATE)) ;
+ if (!pmpeg)
+ return SFE_MALLOC_FAILED ;
+
+ if (psf->sf.channels < 1 || psf->sf.channels > 2)
+ return SFE_BAD_OPEN_FORMAT ;
+
+ if (! (pmpeg->lamef = lame_init ()))
+ return SFE_MALLOC_FAILED ;
+
+ pmpeg->compression = -1.0 ; /* Unset */
+
+ lame_set_in_samplerate (pmpeg->lamef, psf->sf.samplerate) ;
+ lame_set_num_channels (pmpeg->lamef, psf->sf.channels) ;
+ if (lame_set_out_samplerate (pmpeg->lamef, psf->sf.samplerate) < 0)
+ return SFE_MPEG_BAD_SAMPLERATE ;
+
+ lame_set_write_id3tag_automatic (pmpeg->lamef, 0) ;
+
+ if (!info_tag || psf->is_pipe)
+ { /* Can't seek back, so force disable Xing/Lame/Info header. */
+ lame_set_bWriteVbrTag (pmpeg->lamef, 0) ;
+ } ;
+
+ if (psf->sf.channels == 2)
+ { psf->write_short = mpeg_l3_encode_write_short_stereo ;
+ psf->write_int = mpeg_l3_encode_write_int_stereo ;
+ psf->write_float = mpeg_l3_encode_write_float_stereo ;
+ psf->write_double = mpeg_l3_encode_write_double_stereo ;
+ }
+ else
+ { psf->write_short = mpeg_l3_encode_write_short_mono ;
+ psf->write_int = mpeg_l3_encode_write_int_mono ;
+ psf->write_float = mpeg_l3_encode_write_float_mono ;
+ psf->write_double = mpeg_l3_encode_write_double_mono ;
+ }
+
+ psf->sf.seekable = 0 ;
+ psf->codec_close = mpeg_l3_encoder_close ;
+ psf->byterate = mpeg_l3_encoder_byterate ;
+ psf->datalength = 0 ;
+
+ return 0 ;
+} /* mpeg_l3_encoder_init */
+
+int
+mpeg_l3_encoder_write_id3tag (SF_PRIVATE *psf)
+{ MPEG_L3_ENC_PRIVATE *pmpeg = (MPEG_L3_ENC_PRIVATE *) psf->codec_data ;
+ unsigned char *id3v2_buffer ;
+ int i, id3v2_size ;
+
+ if (psf->have_written)
+ return 0 ;
+
+ if ((i = mpeg_l3_encoder_construct (psf)))
+ return i ;
+
+ if (psf_fseek (psf, 0, SEEK_SET) != 0)
+ return SFE_NOT_SEEKABLE ;
+
+ /* Safe to call multiple times. */
+ id3tag_init (pmpeg->lamef) ;
+
+ for (i = 0 ; i < SF_MAX_STRINGS ; i++)
+ { switch (psf->strings.data [i].type)
+ { case SF_STR_TITLE :
+ id3tag_set_title (pmpeg->lamef, psf->strings.storage + psf->strings.data [i].offset) ;
+ break ;
+
+ case SF_STR_ARTIST :
+ id3tag_set_artist (pmpeg->lamef, psf->strings.storage + psf->strings.data [i].offset) ;
+ break ;
+
+ case SF_STR_ALBUM :
+ id3tag_set_album (pmpeg->lamef, psf->strings.storage + psf->strings.data [i].offset) ;
+ break ;
+
+ case SF_STR_DATE :
+ id3tag_set_year (pmpeg->lamef, psf->strings.storage + psf->strings.data [i].offset) ;
+ break ;
+
+ case SF_STR_COMMENT :
+ id3tag_set_comment (pmpeg->lamef, psf->strings.storage + psf->strings.data [i].offset) ;
+ break ;
+
+ case SF_STR_GENRE :
+ id3tag_set_genre (pmpeg->lamef, psf->strings.storage + psf->strings.data [i].offset) ;
+ break ;
+
+ case SF_STR_TRACKNUMBER :
+ id3tag_set_track (pmpeg->lamef, psf->strings.storage + psf->strings.data [i].offset) ;
+ break ;
+
+ default:
+ break ;
+ } ;
+ } ;
+
+ /* The header in this case is the ID3v2 tag header. */
+ id3v2_size = lame_get_id3v2_tag (pmpeg->lamef, 0, 0) ;
+ if (id3v2_size > 0)
+ { psf_log_printf (psf, "Writing ID3v2 header.\n") ;
+ if (! (id3v2_buffer = malloc (id3v2_size)))
+ return SFE_MALLOC_FAILED ;
+ lame_get_id3v2_tag (pmpeg->lamef, id3v2_buffer, id3v2_size) ;
+ psf_fwrite (id3v2_buffer, 1, id3v2_size, psf) ;
+ psf->dataoffset = id3v2_size ;
+ free (id3v2_buffer) ;
+ } ;
+
+ return 0 ;
+}
+
+int
+mpeg_l3_encoder_set_quality (SF_PRIVATE *psf, double compression)
+{ MPEG_L3_ENC_PRIVATE *pmpeg = (MPEG_L3_ENC_PRIVATE *) psf->codec_data ;
+ int bitrate_mode ;
+ int bitrate ;
+ int ret ;
+
+ if (compression < 0.0 || compression > 1.0)
+ return SF_FALSE ;
+
+ /*
+ ** Save the compression setting, as we may have to re-interpret it if
+ ** the bitrate mode changes.
+ */
+ pmpeg->compression = compression ;
+
+ bitrate_mode = mpeg_l3_encoder_get_bitrate_mode (psf) ;
+ if (bitrate_mode == SF_BITRATE_MODE_VARIABLE)
+ { ret = lame_set_VBR_quality (pmpeg->lamef, compression * 10.0) ;
+ }
+ else
+ { /* Choose a bitrate. */
+ if (psf->sf.samplerate >= 32000)
+ { /* MPEG-1.0, bitrates are [32,320] kbps */
+ bitrate = (320.0 - (compression * (320.0 - 32.0))) ;
+ }
+ else if (psf->sf.samplerate >= 16000)
+ { /* MPEG-2.0, bitrates are [8,160] */
+ bitrate = (160.0 - (compression * (160.0 - 8.0))) ;
+ }
+ else
+ { /* MPEG-2.5, bitrates are [8,64] */
+ bitrate = (64.0 - (compression * (64.0 - 8.0))) ;
+ }
+
+ if (bitrate_mode == SF_BITRATE_MODE_AVERAGE)
+ ret = lame_set_VBR_mean_bitrate_kbps (pmpeg->lamef, bitrate) ;
+ else
+ ret = lame_set_brate (pmpeg->lamef, bitrate) ;
+ } ;
+
+ if (ret == LAME_OKAY)
+ return SF_TRUE ;
+
+ psf_log_printf (psf, "Failed to set lame encoder quality.\n") ;
+ return SF_FALSE ;
+} /* mpeg_l3_encoder_set_quality */
+
+int
+mpeg_l3_encoder_set_bitrate_mode (SF_PRIVATE *psf, int mode)
+{ MPEG_L3_ENC_PRIVATE *pmpeg = (MPEG_L3_ENC_PRIVATE *) psf->codec_data ;
+ enum vbr_mode_e vbr_mode ;
+
+ if (pmpeg->initialized)
+ { psf->error = SFE_CMD_HAS_DATA ;
+ return SF_FALSE ;
+ } ;
+
+ switch (mode)
+ { case SF_BITRATE_MODE_CONSTANT : vbr_mode = vbr_off ; break ;
+ case SF_BITRATE_MODE_AVERAGE : vbr_mode = vbr_abr ; break ;
+ case SF_BITRATE_MODE_VARIABLE : vbr_mode = vbr_default ; break ;
+ default :
+ psf->error = SFE_BAD_COMMAND_PARAM ;
+ return SF_FALSE ;
+ } ;
+
+ if (lame_set_VBR (pmpeg->lamef, vbr_mode) == LAME_OKAY)
+ { /* Re-evaluate the compression setting. */
+ return mpeg_l3_encoder_set_quality (psf, pmpeg->compression) ;
+ } ;
+
+ psf_log_printf (psf, "Failed to set LAME vbr mode to %d.\n", vbr_mode) ;
+ return SF_FALSE ;
+} /* mpeg_l3_encoder_set_bitrate_mode */
+
+int
+mpeg_l3_encoder_get_bitrate_mode (SF_PRIVATE *psf)
+{ MPEG_L3_ENC_PRIVATE *pmpeg = (MPEG_L3_ENC_PRIVATE *) psf->codec_data ;
+ enum vbr_mode_e vbr_mode ;
+
+ vbr_mode = lame_get_VBR (pmpeg->lamef) ;
+
+ if (vbr_mode == vbr_off)
+ return SF_BITRATE_MODE_CONSTANT ;
+ if (vbr_mode == vbr_abr)
+ return SF_BITRATE_MODE_AVERAGE ;
+ if (vbr_mode == vbr_default || vbr_mode < vbr_max_indicator)
+ return SF_BITRATE_MODE_VARIABLE ;
+
+ /* Something is wrong. */
+ psf->error = SFE_INTERNAL ;
+ return -1 ;
+} /* mpeg_l3_encoder_get_bitrate_mode */
+
+
+/*-----------------------------------------------------------------------------------------------
+** Private functions.
+*/
+
+static int
+mpeg_l3_encoder_close (SF_PRIVATE *psf)
+{ MPEG_L3_ENC_PRIVATE* pmpeg = (MPEG_L3_ENC_PRIVATE *) psf->codec_data ;
+ int ret, len ;
+ sf_count_t pos ;
+ unsigned char *buffer ;
+
+ /* Magic number 7200 comes from a comment in lame.h */
+ len = 7200 ;
+ if (! (buffer = malloc (len)))
+ return SFE_MALLOC_FAILED ;
+ ret = lame_encode_flush (pmpeg->lamef, buffer, len) ;
+ if (ret > 0)
+ psf_fwrite (buffer, 1, ret, psf) ;
+
+ /*
+ ** Write an IDv1 trailer. The whole tag structure is always 128 bytes, so is
+ ** guaranteed to fit in the buffer allocated above.
+ */
+ ret = lame_get_id3v1_tag (pmpeg->lamef, buffer, len) ;
+ if (ret > 0)
+ { psf_log_printf (psf, " Writing ID3v1 trailer.\n") ;
+ psf_fwrite (buffer, 1, ret, psf) ;
+ } ;
+
+ /*
+ ** If possible, seek back and write the LAME/XING/Info headers. This
+ ** contains information about the whole file and a seek table, and can
+ ** only be written after encoding.
+ **
+ ** If enabled, Lame wrote an empty header at the beginning of the data
+ ** that we now fill in.
+ */
+ ret = lame_get_lametag_frame (pmpeg->lamef, 0, 0) ;
+ if (ret > 0)
+ { if (ret > len)
+ { len = ret ;
+ free (buffer) ;
+ if (! (buffer = malloc (len)))
+ return SFE_MALLOC_FAILED ;
+ } ;
+ psf_log_printf (psf, " Writing LAME info header at offset %d, %d bytes.\n",
+ psf->dataoffset, len) ;
+ lame_get_lametag_frame (pmpeg->lamef, buffer, len) ;
+ pos = psf_ftell (psf) ;
+ if (psf_fseek (psf, psf->dataoffset, SEEK_SET) == psf->dataoffset)
+ { psf_fwrite (buffer, 1, ret, psf) ;
+ psf_fseek (psf, pos, SEEK_SET) ;
+ } ;
+ } ;
+ free (buffer) ;
+
+ free (pmpeg->block) ;
+ pmpeg->block = NULL ;
+
+ if (pmpeg->lamef)
+ { lame_close (pmpeg->lamef) ;
+ pmpeg->lamef = NULL ;
+ } ;
+
+ return 0 ;
+} /* mpeg_l3_encoder_close */
+
+static void
+mpeg_l3_encoder_log_config (SF_PRIVATE *psf, lame_t lamef)
+{ const char *version ;
+ const char *chn_mode ;
+
+ switch (lame_get_version (lamef))
+ { case 0 : version = "2" ; break ;
+ case 1 : version = "1" ; break ;
+ case 2 : version = "2.5" ; break ;
+ default : version = "unknown!?" ; break ;
+ } ;
+ switch (lame_get_mode (lamef))
+ { case STEREO : chn_mode = "stereo" ; break ;
+ case JOINT_STEREO : chn_mode = "joint-stereo" ; break ;
+ case MONO : chn_mode = "mono" ; break ;
+ default : chn_mode = "unknown!?" ; break ;
+ } ;
+ psf_log_printf (psf, " MPEG Version : %s\n", version) ;
+ psf_log_printf (psf, " Block samples : %d\n", lame_get_framesize (lamef)) ;
+ psf_log_printf (psf, " Channel mode : %s\n", chn_mode) ;
+ psf_log_printf (psf, " Samplerate : %d\n", lame_get_out_samplerate (lamef)) ;
+ psf_log_printf (psf, " Encoder mode : ") ;
+ switch (lame_get_VBR (lamef))
+ { case vbr_off :
+ psf_log_printf (psf, "CBR\n") ;
+ psf_log_printf (psf, " Bitrate : %d kbps\n", lame_get_brate (lamef)) ;
+ break ;
+ case vbr_abr :
+ psf_log_printf (psf, "ABR\n") ;
+ psf_log_printf (psf, " Mean Bitrate : %d kbps\n", lame_get_VBR_mean_bitrate_kbps (lamef)) ;
+ break ;
+
+ case vbr_mt :
+ case vbr_default :
+ psf_log_printf (psf, "VBR\n") ;
+ psf_log_printf (psf, " Quality : %d\n", lame_get_VBR_q (lamef)) ;
+ break ;
+
+ default:
+ psf_log_printf (psf, "Unknown!? (%d)\n", lame_get_VBR (lamef)) ;
+ break ;
+ } ;
+
+ psf_log_printf (psf, " Encoder delay : %d\n", lame_get_encoder_delay (lamef)) ;
+ psf_log_printf (psf, " Write INFO header : %d\n", lame_get_bWriteVbrTag (lamef)) ;
+} /* mpeg_l3_encoder_log_config */
+
+static int
+mpeg_l3_encoder_construct (SF_PRIVATE *psf)
+{ MPEG_L3_ENC_PRIVATE *pmpeg = (MPEG_L3_ENC_PRIVATE *) psf->codec_data ;
+ int frame_samples_per_channel ;
+
+ if (pmpeg->initialized == SF_FALSE)
+ { if (lame_init_params (pmpeg->lamef) < 0)
+ { psf_log_printf (psf, "Failed to initialize lame encoder!\n") ;
+ return SFE_INTERNAL ;
+ } ;
+
+ psf_log_printf (psf, "Initialized LAME encoder.\n") ;
+ mpeg_l3_encoder_log_config (psf, pmpeg->lamef) ;
+
+ frame_samples_per_channel = lame_get_framesize (pmpeg->lamef) ;
+
+ /*
+ * Suggested output buffer size in bytes from lame.h comment is
+ * 1.25 * samples + 7200
+ */
+ pmpeg->block_len = (frame_samples_per_channel * 4) / 3 + 7200 ;
+ pmpeg->frame_samples = frame_samples_per_channel * psf->sf.channels ;
+
+ pmpeg->block = malloc (pmpeg->block_len) ;
+ if (!pmpeg->block)
+ return SFE_MALLOC_FAILED ;
+
+ pmpeg->initialized = SF_TRUE ;
+ } ;
+
+ return 0 ;
+} /* mpeg_l3_encoder_construct */
+
+static int
+mpeg_l3_encoder_byterate (SF_PRIVATE *psf)
+{ MPEG_L3_ENC_PRIVATE *pmpeg = (MPEG_L3_ENC_PRIVATE *) psf->codec_data ;
+ int bitrate_mode ;
+ int byterate ;
+ float calculated_byterate ;
+
+ bitrate_mode = mpeg_l3_encoder_get_bitrate_mode (psf) ;
+ byterate = (lame_get_brate (pmpeg->lamef) + 7) / 8 ;
+
+ if (bitrate_mode == SF_BITRATE_MODE_VARIABLE)
+ { /*
+ ** For VBR, lame_get_brate returns the minimum bitrate, so calculate the
+ ** average byterate so far.
+ */
+ calculated_byterate = psf_ftell (psf) - psf->dataoffset ;
+ calculated_byterate /= (float) psf->write_current ;
+ calculated_byterate *= (float) psf->sf.samplerate ;
+
+ return SF_MIN (byterate, (int) calculated_byterate) ;
+ }
+
+ return byterate ;
+} /* mpeg_l3_encoder_byterate */
+
+static sf_count_t
+mpeg_l3_encode_write_short_mono (SF_PRIVATE *psf, const short *ptr, sf_count_t len)
+{ MPEG_L3_ENC_PRIVATE *pmpeg = (MPEG_L3_ENC_PRIVATE*) psf->codec_data ;
+ sf_count_t total = 0 ;
+ int nbytes, writecount, writen ;
+
+ if ((psf->error = mpeg_l3_encoder_construct (psf)))
+ return 0 ;
+
+ while (len)
+ { writecount = SF_MIN (len, (sf_count_t) pmpeg->frame_samples) ;
+
+ nbytes = lame_encode_buffer (pmpeg->lamef, ptr + total, NULL, writecount, pmpeg->block, pmpeg->block_len) ;
+ if (nbytes < 0)
+ { psf_log_printf (psf, "lame_encode_buffer returned %d\n", nbytes) ;
+ break ;
+ } ;
+
+ if (nbytes)
+ { writen = psf_fwrite (pmpeg->block, 1, nbytes, psf) ;
+ if (writen != nbytes)
+ { psf_log_printf (psf, "*** Warning : short write (%d != %d).\n", writen, nbytes) ;
+ } ;
+ } ;
+
+ total += writecount ;
+ len -= writecount ;
+ } ;
+
+ return total ;
+}
+
+
+static sf_count_t
+mpeg_l3_encode_write_short_stereo (SF_PRIVATE *psf, const short *ptr, sf_count_t len)
+{ BUF_UNION ubuf ;
+ MPEG_L3_ENC_PRIVATE *pmpeg = (MPEG_L3_ENC_PRIVATE*) psf->codec_data ;
+ sf_count_t total = 0 ;
+ int nbytes, writecount, writen ;
+
+ if ((psf->error = mpeg_l3_encoder_construct (psf)))
+ return 0 ;
+
+ const sf_count_t max_samples = SF_MIN (ARRAY_LEN (ubuf.sbuf), pmpeg->frame_samples) ;
+ while (len)
+ { writecount = SF_MIN (len, max_samples) ;
+ /*
+ * An oversight, but lame_encode_buffer_interleaved() lacks a const.
+ * As such, need another memcpy to not cause a warning.
+ */
+ memcpy (ubuf.sbuf, ptr + total, writecount) ;
+ nbytes = lame_encode_buffer_interleaved (pmpeg->lamef, ubuf.sbuf, writecount / 2, pmpeg->block, pmpeg->block_len) ;
+ if (nbytes < 0)
+ { psf_log_printf (psf, "lame_encode_buffer returned %d\n", nbytes) ;
+ break ;
+ } ;
+
+ if (nbytes)
+ { writen = psf_fwrite (pmpeg->block, 1, nbytes, psf) ;
+ if (writen != nbytes)
+ { psf_log_printf (psf, "*** Warning : short write (%d != %d).\n", writen, nbytes) ;
+ } ;
+ } ;
+
+ total += writecount ;
+ len -= writecount ;
+ } ;
+
+ return total ;
+}
+
+
+static sf_count_t
+mpeg_l3_encode_write_int_mono (SF_PRIVATE *psf, const int *ptr, sf_count_t len)
+{ MPEG_L3_ENC_PRIVATE *pmpeg = (MPEG_L3_ENC_PRIVATE*) psf->codec_data ;
+ sf_count_t total = 0 ;
+ int nbytes, writecount, writen ;
+
+ if ((psf->error = mpeg_l3_encoder_construct (psf)))
+ return 0 ;
+
+ while (len)
+ { writecount = SF_MIN (len, (sf_count_t) pmpeg->frame_samples) ;
+
+ nbytes = lame_encode_buffer_int (pmpeg->lamef, ptr + total, NULL, writecount, pmpeg->block, pmpeg->block_len) ;
+ if (nbytes < 0)
+ { psf_log_printf (psf, "lame_encode_buffer returned %d\n", nbytes) ;
+ break ;
+ } ;
+
+ if (nbytes)
+ { writen = psf_fwrite (pmpeg->block, 1, nbytes, psf) ;
+ if (writen != nbytes)
+ { psf_log_printf (psf, "*** Warning : short write (%d != %d).\n", writen, nbytes) ;
+ } ;
+ } ;
+
+ total += writecount ;
+ len -= writecount ;
+ } ;
+
+ return total ;
+}
+
+
+static sf_count_t
+mpeg_l3_encode_write_int_stereo (SF_PRIVATE *psf, const int *ptr, sf_count_t len)
+{ MPEG_L3_ENC_PRIVATE *pmpeg = (MPEG_L3_ENC_PRIVATE*) psf->codec_data ;
+ sf_count_t total = 0 ;
+ int nbytes, writecount, writen ;
+
+ if ((psf->error = mpeg_l3_encoder_construct (psf)))
+ return 0 ;
+
+ while (len)
+ { writecount = SF_MIN (len, (sf_count_t) pmpeg->frame_samples) ;
+
+ nbytes = lame_encode_buffer_interleaved_int (pmpeg->lamef, ptr + total, writecount / 2, pmpeg->block, pmpeg->block_len) ;
+ if (nbytes < 0)
+ { psf_log_printf (psf, "lame_encode_buffer returned %d\n", nbytes) ;
+ break ;
+ } ;
+
+ if (nbytes)
+ { writen = psf_fwrite (pmpeg->block, 1, nbytes, psf) ;
+ if (writen != nbytes)
+ { psf_log_printf (psf, "*** Warning : short write (%d != %d).\n", writen, nbytes) ;
+ } ;
+ } ;
+
+ total += writecount ;
+ len -= writecount ;
+ } ;
+
+ return total ;
+}
+
+
+static sf_count_t
+mpeg_l3_encode_write_float_mono (SF_PRIVATE *psf, const float *ptr, sf_count_t len)
+{ MPEG_L3_ENC_PRIVATE *pmpeg = (MPEG_L3_ENC_PRIVATE*) psf->codec_data ;
+ sf_count_t total = 0 ;
+ int nbytes, writecount, writen ;
+
+ if ((psf->error = mpeg_l3_encoder_construct (psf)))
+ return 0 ;
+
+ while (len)
+ { writecount = SF_MIN (len, (sf_count_t) pmpeg->frame_samples) ;
+
+ if (psf->norm_float)
+ nbytes = lame_encode_buffer_ieee_float (pmpeg->lamef, ptr + total, NULL, writecount, pmpeg->block, pmpeg->block_len) ;
+ else
+ nbytes = lame_encode_buffer_float (pmpeg->lamef, ptr + total, NULL, writecount, pmpeg->block, pmpeg->block_len) ;
+ if (nbytes < 0)
+ { psf_log_printf (psf, "lame_encode_buffer returned %d\n", nbytes) ;
+ break ;
+ } ;
+
+ if (nbytes)
+ { writen = psf_fwrite (pmpeg->block, 1, nbytes, psf) ;
+ if (writen != nbytes)
+ { psf_log_printf (psf, "*** Warning : short write (%d != %d).\n", writen, nbytes) ;
+ } ;
+ } ;
+
+ total += writecount ;
+ len -= writecount ;
+ } ;
+
+ return total ;
+}
+
+
+static inline void
+normalize_float (float *dest, const float *src, sf_count_t count, float norm_fact)
+{ while (--count >= 0)
+ { dest [count] = src [count] * norm_fact ;
+ } ;
+}
+
+
+static sf_count_t
+mpeg_l3_encode_write_float_stereo (SF_PRIVATE *psf, const float *ptr, sf_count_t len)
+{ BUF_UNION ubuf ;
+ MPEG_L3_ENC_PRIVATE *pmpeg = (MPEG_L3_ENC_PRIVATE*) psf->codec_data ;
+ sf_count_t total = 0 ;
+ int nbytes, writecount, writen ;
+
+ if ((psf->error = mpeg_l3_encoder_construct (psf)))
+ return 0 ;
+
+ const sf_count_t max_samples = SF_MIN (ARRAY_LEN (ubuf.fbuf), pmpeg->frame_samples) ;
+ while (len)
+ { writecount = SF_MIN (len, max_samples) ;
+
+ if (psf->norm_float)
+ nbytes = lame_encode_buffer_interleaved_ieee_float (pmpeg->lamef, ptr + total, writecount / 2, pmpeg->block, pmpeg->block_len) ;
+ else
+ { /* Lame lacks a non-normalized interleaved float write. Bummer. */
+ normalize_float (ubuf.fbuf, ptr + total, writecount, 1.0 / (float) 0x8000) ;
+ nbytes = lame_encode_buffer_interleaved_ieee_float (pmpeg->lamef, ubuf.fbuf, writecount / 2, pmpeg->block, pmpeg->block_len) ;
+ }
+
+ if (nbytes < 0)
+ { psf_log_printf (psf, "lame_encode_buffer returned %d\n", nbytes) ;
+ break ;
+ } ;
+
+ if (nbytes)
+ { writen = psf_fwrite (pmpeg->block, 1, nbytes, psf) ;
+ if (writen != nbytes)
+ { psf_log_printf (psf, "*** Warning : short write (%d != %d).\n", writen, nbytes) ;
+ } ;
+ } ;
+
+ total += writecount ;
+ len -= writecount ;
+ } ;
+
+ return total ;
+}
+
+
+static inline void
+normalize_double (double *dest, const double *src, sf_count_t count, double norm_fact)
+{ while (--count >= 0)
+ { dest [count] = src [count] * norm_fact ;
+ } ;
+}
+
+
+static sf_count_t
+mpeg_l3_encode_write_double_mono (SF_PRIVATE *psf, const double *ptr, sf_count_t len)
+{ BUF_UNION ubuf ;
+ MPEG_L3_ENC_PRIVATE *pmpeg = (MPEG_L3_ENC_PRIVATE*) psf->codec_data ;
+ sf_count_t total = 0 ;
+ int nbytes, writecount, writen ;
+
+ if ((psf->error = mpeg_l3_encoder_construct (psf)))
+ return 0 ;
+
+ const sf_count_t max_samples = SF_MIN (ARRAY_LEN (ubuf.dbuf), pmpeg->frame_samples) ;
+ while (len)
+ { writecount = SF_MIN (len, max_samples) ;
+
+ if (psf->norm_double)
+ nbytes = lame_encode_buffer_ieee_double (pmpeg->lamef, ptr + total, NULL, writecount, pmpeg->block, pmpeg->block_len) ;
+ else
+ { /* Lame lacks non-normalized double writing */
+ normalize_double (ubuf.dbuf, ptr + total, writecount, 1.0 / (double) 0x8000) ;
+ nbytes = lame_encode_buffer_ieee_double (pmpeg->lamef, ubuf.dbuf, NULL, writecount, pmpeg->block, pmpeg->block_len) ;
+ }
+
+ if (nbytes < 0)
+ { psf_log_printf (psf, "lame_encode_buffer returned %d\n", nbytes) ;
+ break ;
+ } ;
+
+ if (nbytes)
+ { writen = psf_fwrite (pmpeg->block, 1, nbytes, psf) ;
+ if (writen != nbytes)
+ { psf_log_printf (psf, "*** Warning : short write (%d != %d).\n", writen, nbytes) ;
+ } ;
+ } ;
+
+ total += writecount ;
+ len -= writecount ;
+ } ;
+
+ return total ;
+}
+
+
+static sf_count_t
+mpeg_l3_encode_write_double_stereo (SF_PRIVATE *psf, const double *ptr, sf_count_t len)
+{ BUF_UNION ubuf ;
+ MPEG_L3_ENC_PRIVATE *pmpeg = (MPEG_L3_ENC_PRIVATE*) psf->codec_data ;
+ sf_count_t total = 0 ;
+ int nbytes, writecount, writen ;
+
+ if ((psf->error = mpeg_l3_encoder_construct (psf)))
+ return 0 ;
+
+ const sf_count_t max_samples = SF_MIN (ARRAY_LEN (ubuf.dbuf), pmpeg->frame_samples) ;
+ while (len)
+ { writecount = SF_MIN (len, max_samples) ;
+
+ if (psf->norm_double)
+ nbytes = lame_encode_buffer_interleaved_ieee_double (pmpeg->lamef, ptr + total, writecount / 2, pmpeg->block, pmpeg->block_len) ;
+ else
+ { /* Lame lacks interleaved non-normalized double writing */
+ normalize_double (ubuf.dbuf, ptr + total, writecount, 1.0 / (double) 0x8000) ;
+ nbytes = lame_encode_buffer_interleaved_ieee_double (pmpeg->lamef, ubuf.dbuf, writecount / 2, pmpeg->block, pmpeg->block_len) ;
+ }
+
+ if (nbytes < 0)
+ { psf_log_printf (psf, "lame_encode_buffer returned %d\n", nbytes) ;
+ break ;
+ } ;
+
+ if (nbytes)
+ { writen = psf_fwrite (pmpeg->block, 1, nbytes, psf) ;
+ if (writen != nbytes)
+ { psf_log_printf (psf, "*** Warning : short write (%d != %d).\n", writen, nbytes) ;
+ } ;
+ } ;
+
+ total += writecount ;
+ len -= writecount ;
+ } ;
+
+ return total ;
+}
+
+#else /* HAVE_MPEG */
+
+int
+mpeg_l3_encoder_init (SF_PRIVATE *psf, int UNUSED (vbr))
+{ psf_log_printf (psf, "This version of libsndfile was compiled without MPEG Layer 3 encoding support.\n") ;
+ return SFE_UNIMPLEMENTED ;
+} /* mpeg_l3_encoder_init */
+
+#endif
if (psf->file.mode == SFM_WRITE)
samplesperblock = 2 + 2 * (blockalign - 7 * psf->sf.channels) / psf->sf.channels ;
- if (blockalign < 7 * psf->sf.channels)
- { psf_log_printf (psf, "*** Error blockalign (%d) should be > %d.\n", blockalign, 7 * psf->sf.channels) ;
+ /* There's 7 samples per channel in the preamble of each block */
+ if (samplesperblock < 7 * psf->sf.channels)
+ { psf_log_printf (psf, "*** Error samplesperblock (%d) should be >= %d.\n", samplesperblock, 7 * psf->sf.channels) ;
+ return SFE_INTERNAL ;
+ } ;
+
+ if (2 * blockalign < samplesperblock * psf->sf.channels)
+ { psf_log_printf (psf, "*** Error blockalign (%d) should be >= %d.\n", blockalign, samplesperblock * psf->sf.channels / 2) ;
return SFE_INTERNAL ;
} ;
return 1 ;
} ;
- if ((k = psf_fread (pms->block, 1, pms->blocksize, psf)) != pms->blocksize)
+ if ((k = (int) psf_fread (pms->block, 1, pms->blocksize, psf)) != pms->blocksize)
{ psf_log_printf (psf, "*** Warning : short read (%d != %d).\n", k, pms->blocksize) ;
if (k <= 0)
return 1 ;
while (len > 0)
{ readcount = (len > 0x10000000) ? 0x10000000 : (int) len ;
- if ((count = msadpcm_read_block (psf, pms, ptr, readcount)) <= 0)
+ if ((count = (int) msadpcm_read_block (psf, pms, ptr, readcount)) <= 0)
return -1 ;
total += count ;
sptr = ubuf.sbuf ;
bufferlen = ARRAY_LEN (ubuf.sbuf) ;
while (len > 0)
- { readcount = (len >= bufferlen) ? bufferlen : len ;
+ { readcount = (len >= bufferlen) ? bufferlen : (int) len ;
- if ((count = msadpcm_read_block (psf, pms, sptr, readcount)) <= 0)
+ if ((count = (int) msadpcm_read_block (psf, pms, sptr, readcount)) <= 0)
return -1 ;
for (k = 0 ; k < readcount ; k++)
sptr = ubuf.sbuf ;
bufferlen = ARRAY_LEN (ubuf.sbuf) ;
while (len > 0)
- { readcount = (len >= bufferlen) ? bufferlen : len ;
+ { readcount = (len >= bufferlen) ? bufferlen : (int) len ;
- if ((count = msadpcm_read_block (psf, pms, sptr, readcount)) <= 0)
+ if ((count = (int) msadpcm_read_block (psf, pms, sptr, readcount)) <= 0)
return -1 ;
for (k = 0 ; k < readcount ; k++)
sptr = ubuf.sbuf ;
bufferlen = ARRAY_LEN (ubuf.sbuf) ;
while (len > 0)
- { readcount = (len >= bufferlen) ? bufferlen : len ;
+ { readcount = (len >= bufferlen) ? bufferlen : (int) len ;
- if ((count = msadpcm_read_block (psf, pms, sptr, readcount)) <= 0)
+ if ((count = (int) msadpcm_read_block (psf, pms, sptr, readcount)) <= 0)
return -1 ;
for (k = 0 ; k < readcount ; k++)
/* Write the block to disk. */
- if ((k = psf_fwrite (pms->block, 1, pms->blocksize, psf)) != pms->blocksize)
+ if ((k = (int) psf_fwrite (pms->block, 1, pms->blocksize, psf)) != pms->blocksize)
psf_log_printf (psf, "*** Warning : short write (%d != %d).\n", k, pms->blocksize) ;
memset (pms->samples, 0, pms->samplesperblock * sizeof (short)) ;
while (len > 0)
{ writecount = (len > 0x10000000) ? 0x10000000 : (int) len ;
- count = msadpcm_write_block (psf, pms, ptr, writecount) ;
+ count = (int) msadpcm_write_block (psf, pms, ptr, writecount) ;
total += count ;
len -= count ;
sptr = ubuf.sbuf ;
bufferlen = ARRAY_LEN (ubuf.sbuf) ;
while (len > 0)
- { writecount = (len >= bufferlen) ? bufferlen : len ;
+ { writecount = (len >= bufferlen) ? bufferlen : (int) len ;
for (k = 0 ; k < writecount ; k++)
sptr [k] = ptr [total + k] >> 16 ;
- count = msadpcm_write_block (psf, pms, sptr, writecount) ;
+ count = (int) msadpcm_write_block (psf, pms, sptr, writecount) ;
total += count ;
len -= writecount ;
if (count != writecount)
sptr = ubuf.sbuf ;
bufferlen = ARRAY_LEN (ubuf.sbuf) ;
while (len > 0)
- { writecount = (len >= bufferlen) ? bufferlen : len ;
+ { writecount = (len >= bufferlen) ? bufferlen : (int) len ;
for (k = 0 ; k < writecount ; k++)
sptr [k] = psf_lrintf (normfact * ptr [total + k]) ;
- count = msadpcm_write_block (psf, pms, sptr, writecount) ;
+ count = (int) msadpcm_write_block (psf, pms, sptr, writecount) ;
total += count ;
len -= writecount ;
if (count != writecount)
sptr = ubuf.sbuf ;
bufferlen = ARRAY_LEN (ubuf.sbuf) ;
while (len > 0)
- { writecount = (len >= bufferlen) ? bufferlen : len ;
+ { writecount = (len >= bufferlen) ? bufferlen : (int) len ;
for (k = 0 ; k < writecount ; k++)
sptr [k] = psf_lrint (normfact * ptr [total + k]) ;
- count = msadpcm_write_block (psf, pms, sptr, writecount) ;
+ count = (int) msadpcm_write_block (psf, pms, sptr, writecount) ;
total += count ;
len -= writecount ;
if (count != writecount)
psf_nms_adpcm_decode_block (SF_PRIVATE *psf, NMS_ADPCM_PRIVATE *pnms)
{ int k ;
- if ((k = psf_fread (pnms->block, sizeof (short), pnms->shortsperblock, psf)) != pnms->shortsperblock)
+ if ((k = (int) psf_fread (pnms->block, sizeof (short), pnms->shortsperblock, psf)) != pnms->shortsperblock)
{ psf_log_printf (psf, "*** Warning : short read (%d != %d).\n", k, pnms->shortsperblock) ;
memset (pnms->block + (k * sizeof (short)), 0, (pnms->shortsperblock - k) * sizeof (short)) ;
} ;
sptr = ubuf.sbuf ;
bufferlen = SF_BUFFER_LEN / sizeof (short) ;
while (len > 0)
- { readcount = (len >= bufferlen) ? bufferlen : len ;
+ { readcount = (len >= bufferlen) ? bufferlen : (int) len ;
count = nms_adpcm_read_block (psf, pnms, sptr, readcount) ;
for (k = 0 ; k < readcount ; k++)
sptr = ubuf.sbuf ;
bufferlen = SF_BUFFER_LEN / sizeof (short) ;
while (len > 0)
- { readcount = (len >= bufferlen) ? bufferlen : len ;
+ { readcount = (len >= bufferlen) ? bufferlen : (int) len ;
count = nms_adpcm_read_block (psf, pnms, sptr, readcount) ;
for (k = 0 ; k < readcount ; k++)
ptr [total + k] = normfact * sptr [k] ;
sptr = ubuf.sbuf ;
bufferlen = SF_BUFFER_LEN / sizeof (short) ;
while (len > 0)
- { readcount = (len >= bufferlen) ? bufferlen : len ;
+ { readcount = (len >= bufferlen) ? bufferlen : (int) len ;
count = nms_adpcm_read_block (psf, pnms, sptr, readcount) ;
for (k = 0 ; k < readcount ; k++)
ptr [total + k] = normfact * (double) (sptr [k]) ;
endswap_short_array ((signed short *) pnms->block, pnms->shortsperblock) ;
/* Write the block to disk. */
- if ((k = psf_fwrite (pnms->block, sizeof (short), pnms->shortsperblock, psf)) != pnms->shortsperblock)
+ if ((k = (int) psf_fwrite (pnms->block, sizeof (short), pnms->shortsperblock, psf)) != pnms->shortsperblock)
psf_log_printf (psf, "*** Warning : short write (%d != %d).\n", k, pnms->shortsperblock) ;
pnms->sample_curr = 0 ;
sptr = ubuf.sbuf ;
bufferlen = SF_BUFFER_LEN / sizeof (short) ;
while (len > 0)
- { writecount = (len >= bufferlen) ? bufferlen : len ;
+ { writecount = (len >= bufferlen) ? bufferlen : (int) len ;
for (k = 0 ; k < writecount ; k++)
sptr [k] = ptr [total + k] >> 16 ;
count = nms_adpcm_write_block (psf, pnms, sptr, writecount) ;
sptr = ubuf.sbuf ;
bufferlen = SF_BUFFER_LEN / sizeof (short) ;
while (len > 0)
- { writecount = (len >= bufferlen) ? bufferlen : len ;
+ { writecount = (len >= bufferlen) ? bufferlen : (int) len ;
for (k = 0 ; k < writecount ; k++)
sptr [k] = psf_lrintf (normfact * ptr [total + k]) ;
count = nms_adpcm_write_block (psf, pnms, sptr, writecount) ;
sptr = ubuf.sbuf ;
bufferlen = SF_BUFFER_LEN / sizeof (short) ;
while (len > 0)
- { writecount = (len >= bufferlen) ? bufferlen : len ;
+ { writecount = (len >= bufferlen) ? bufferlen : (int) len ;
for (k = 0 ; k < writecount ; k++)
sptr [k] = psf_lrint (normfact * ptr [total + k]) ;
count = nms_adpcm_write_block (psf, pnms, sptr, writecount) ;
opus_print_header (SF_PRIVATE *psf, OpusHeader *h)
{ psf_log_printf (psf, "Opus Header Metadata\n") ;
psf_log_printf (psf, " OggOpus version : %d\n", h->version) ;
- psf_log_printf (psf, " Channels : %d\n", h->channels) ;
- psf_log_printf (psf, " Preskip : %d samples @48kHz\n", h->preskip) ;
+ psf_log_printf (psf, " Channels : %d\n", h->channels) ;
+ psf_log_printf (psf, " Preskip : %d samples @48kHz\n", h->preskip) ;
psf_log_printf (psf, " Input Samplerate : %d Hz\n", h->input_samplerate) ;
- psf_log_printf (psf, " Gain : %d.%d\n", arith_shift_right (h->gain & 0xF0, 8), h->gain & 0x0F) ;
+ psf_log_printf (psf, " Gain : %d.%d\n", arith_shift_right (h->gain & 0xF0, 8), h->gain & 0x0F) ;
psf_log_printf (psf, " Channel Mapping : ") ;
switch (h->channel_mapping)
{ case 0 : psf_log_printf (psf, "0 (mono or stereo)\n") ; break ;
{ int i ;
psf_log_printf (psf, " streams total : %d\n", h->nb_streams) ;
psf_log_printf (psf, " streams coupled : %d\n", h->nb_coupled) ;
- psf_log_printf (psf, " stream mapping : [") ;
+ psf_log_printf (psf, " stream mapping : [") ;
for (i = 0 ; i < h->channels - 1 ; i++)
psf_log_printf (psf, "%d,", h->stream_map [i]) ;
psf_log_printf (psf, "%d]\n", h->stream_map [i]) ;
/*
+** Copyright (C) 2018-2021 Arthur Taylor <art@ified.ca>
** Copyright (C) 2002-2016 Erik de Castro Lopo <erikd@mega-nerd.com>
** Copyright (C) 2002-2005 Michael Smith <msmith@xiph.org>
** Copyright (C) 2007 John ffitch
*/
/*
-** Much of this code is based on the examples in libvorbis from the
+** Much of this code is based on the examples in libvorbis from the
** XIPHOPHORUS Company http://www.xiph.org/ which has a BSD-style Licence
** Copyright (c) 2002, Xiph.org Foundation
**
#include "ogg.h"
+/* How many seconds in the future to not bother bisection searching for. */
+#define VORBIS_SEEK_THRESHOLD 2
+
typedef int convert_func (SF_PRIVATE *psf, int, void *, int, int, float **) ;
static int vorbis_read_header (SF_PRIVATE *psf) ;
static int vorbis_close (SF_PRIVATE *psf) ;
static int vorbis_command (SF_PRIVATE *psf, int command, void *data, int datasize) ;
static int vorbis_byterate (SF_PRIVATE *psf) ;
-static sf_count_t vorbis_calculate_page_duration (SF_PRIVATE *psf) ;
+static int vorbis_calculate_granulepos (SF_PRIVATE *psf, uint64_t *gp_out) ;
+static int vorbis_skip (SF_PRIVATE *psf, uint64_t target_gp) ;
+static int vorbis_seek_trysearch (SF_PRIVATE *psf, uint64_t target_gp) ;
static sf_count_t vorbis_seek (SF_PRIVATE *psf, int mode, sf_count_t offset) ;
static sf_count_t vorbis_read_s (SF_PRIVATE *psf, short *ptr, sf_count_t len) ;
static sf_count_t vorbis_read_i (SF_PRIVATE *psf, int *ptr, sf_count_t len) ;
{ SF_STR_ALBUM, "Album" },
{ SF_STR_LICENSE, "License" },
{ SF_STR_TRACKNUMBER, "Tracknumber" },
- { SF_STR_GENRE, "Genre" },
+ { SF_STR_GENRE, "Genre" },
} ;
typedef struct
-{ /* Count current location */
- sf_count_t loc ;
+{ /* Current granule position. */
+ uint64_t gp ;
/* Struct that stores all the static vorbis bitstream settings */
vorbis_info vinfo ;
/* Struct that stores all the bitstream user comments */
vorbis_comment vcomment ;
- /* Ventral working state for the packet->PCM decoder */
+ /* Central working state for the packet->PCM decoder */
vorbis_dsp_state vdsp ;
/* Local working space for packet->PCM decode */
vorbis_block vblock ;
-
/* Encoding quality in range [0.0, 1.0]. */
double quality ;
-
- /* Current granule position. */
- uint64_t pcm_current ;
/* Offset of the first samples' granule position. */
uint64_t pcm_start ;
/* Last valid samples' granule position. */
vorbis_read_header (SF_PRIVATE *psf)
{ OGG_PRIVATE *odata = (OGG_PRIVATE *) psf->container_data ;
VORBIS_PRIVATE *vdata = (VORBIS_PRIVATE *) psf->codec_data ;
- sf_count_t duration ;
int printed_metadata_msg = 0 ;
- int i, k, nn ;
+ int i, nn ;
+ sf_count_t last_page ;
+ sf_count_t saved_offset ;
/*
** The first page of the Ogg stream we are told to try and open as Vorbis
** Vorbis decoder.
**
** The next two packets in order are the comment and codebook headers.
- ** They're likely large and may span multiple pages. Thus we reead
- ** and submit data until we get our two pacakets, watching that no
+ ** They're likely large and may span multiple pages. Thus we read
+ ** and submit data until we get our two packets, watching that no
** pages are missing. If a page is missing, error out ; losing a
** header page is the only place where missing data is fatal.
*/
psf->dataoffset = ogg_sync_ftell (psf) ;
/*
- ** Caculate the granule position offset. The first page with a payload
+ ** Calculate the granule position offset. The first page with a payload
** packet shouldn't end in a continued packet. The difference between the
** page's granule position and the sum of frames on the page tells us the
** granule position offset.
** See https://xiph.org/vorbis/doc/Vorbis_I_spec.html#x1-132000A.2
*/
ogg_stream_unpack_page (psf, odata) ;
- vdata->pcm_start = odata->pkt [odata->pkt_len - 1].granulepos ;
- duration = vorbis_calculate_page_duration (psf) ;
-
- if (duration < (sf_count_t) vdata->pcm_start)
- vdata->pcm_start -= duration ;
- else
- vdata->pcm_start = 0 ;
+ vorbis_calculate_granulepos (psf, &vdata->pcm_start) ;
+ vdata->gp = vdata->pcm_start ;
/*
** Find the end of the stream, save it. Only works if the file is seekable.
*/
- vdata->loc = vdata->pcm_start ;
vdata->pcm_end = (uint64_t) -1 ;
psf->datalength = psf->filelength ;
if (!psf->is_pipe)
- { sf_count_t last_page ;
- sf_count_t saved_offset ;
-
- saved_offset = ogg_sync_ftell (psf) ;
+ { saved_offset = ogg_sync_ftell (psf) ;
last_page = ogg_sync_last_page_before (psf, odata, &vdata->pcm_end, psf->filelength, odata->ostream.serialno) ;
if (last_page > 0)
{ if (!ogg_page_eos (&odata->opage))
psf_log_printf (psf, "PCM end : unknown\n") ;
/* Throw the comments plus a few lines about the bitstream we're decoding. */
- for (k = 0 ; k < ARRAY_LEN (vorbis_metatypes) ; k++)
+ for (i = 0 ; i < ARRAY_LEN (vorbis_metatypes) ; i++)
{ char *dd ;
- dd = vorbis_comment_query (&vdata->vcomment, vorbis_metatypes [k].name, 0) ;
+ dd = vorbis_comment_query (&vdata->vcomment, vorbis_metatypes [i].name, 0) ;
if (dd == NULL)
continue ;
printed_metadata_msg = 1 ;
} ;
- psf_store_string (psf, vorbis_metatypes [k].id, dd) ;
- psf_log_printf (psf, " %-10s : %s\n", vorbis_metatypes [k].name, dd) ;
+ psf_store_string (psf, vorbis_metatypes [i].id, dd) ;
+ psf_log_printf (psf, " %-10s : %s\n", vorbis_metatypes [i].name, dd) ;
} ;
psf_log_printf (psf, "End\n") ;
/* Local state for most of the decode so multiple block decodes can
** proceed in parallel. We could init multiple vorbis_block structures
- ** for vd here. */
+ ** for vdsp here. */
vorbis_block_init (&vdata->vdsp, &vdata->vblock) ;
return 0 ;
if (ret)
return SFE_BAD_OPEN_FORMAT ;
- vdata->loc = 0 ;
+ vdata->gp = 0 ;
/* add a comment */
vorbis_comment_init (&vdata->vcomment) ;
switch (psf->strings.data [k].type)
{ case SF_STR_TITLE : name = "TITLE" ; break ;
- case SF_STR_COPYRIGHT : name = "COPYRIGHT" ; break ;
+ case SF_STR_COPYRIGHT : name = "COPYRIGHT" ; break ;
case SF_STR_SOFTWARE : name = "SOFTWARE" ; break ;
case SF_STR_ARTIST : name = "ARTIST" ; break ;
case SF_STR_COMMENT : name = "COMMENT" ; break ;
case SF_STR_DATE : name = "DATE" ; break ;
case SF_STR_ALBUM : name = "ALBUM" ; break ;
case SF_STR_LICENSE : name = "LICENSE" ; break ;
- case SF_STR_TRACKNUMBER : name = "Tracknumber" ; break ;
- case SF_STR_GENRE : name = "Genre" ; break ;
+ case SF_STR_TRACKNUMBER : name = "Tracknumber" ; break ;
+ case SF_STR_GENRE : name = "Genre" ; break ;
default : continue ;
} ;
len -= samples ;
/* tell libvorbis how many samples we actually consumed */
vorbis_synthesis_read (&vdata->vdsp, samples) ;
- vdata->loc += samples ;
+ vdata->gp += samples ;
if (len == 0)
- return i ; /* Is this necessary */
+ return i ;
} ;
/* Out of samples, load the next packet. */
if (nn <= 0)
return i ;
if (nn == 2)
- { /* Ran over a hole. loc is now out of date, need to recalculate. */
- vdata->loc = odata->pkt [odata->pkt_len - 1].granulepos ;
- vdata->loc -= vorbis_calculate_page_duration (psf) ;
+ { /* Ran over a hole. gp is now out of date, need to recalculate. */
+ vorbis_synthesis_restart (&vdata->vdsp) ;
+ vorbis_calculate_granulepos (psf, &vdata->gp) ;
}
} ;
} ;
} ;
- vdata->loc += in_frames ;
+ vdata->gp += in_frames ;
} /* vorbis_write_data */
return lens ;
} /* vorbis_write_d */
+static int
+vorbis_skip (SF_PRIVATE *psf, uint64_t target)
+{ OGG_PRIVATE *odata = (OGG_PRIVATE *) psf->container_data ;
+ VORBIS_PRIVATE *vdata = (VORBIS_PRIVATE *) psf->codec_data ;
+ ogg_packet *pkt ;
+ int thisblock, lastblock, nn ;
+ const int blocksize = vorbis_info_blocksize (&vdata->vinfo, 1) ;
+
+ /* Read out any samples that may be in the decoder from a seek without a
+ ** search. */
+ thisblock = vorbis_synthesis_pcmout (&vdata->vdsp, NULL) ;
+ if (thisblock > 0)
+ { if ((uint64_t) thisblock + vdata->gp >= target)
+ thisblock = SF_MIN (thisblock, (int) (target - vdata->gp)) ;
+
+ vorbis_synthesis_read (&vdata->vdsp, thisblock) ;
+ vdata->gp += thisblock ;
+ if (vdata->gp == target)
+ return 0 ;
+ } ;
+
+ /* Read through packets that are before our target */
+ lastblock = 0 ;
+ for ( ; vdata->gp < target ; )
+ { /* Ensure there are unpacked packets. */
+ if (odata->pkt_indx == odata->pkt_len)
+ { /* Page out of packets, load and unpack the next page. */
+ nn = ogg_stream_unpack_page (psf, odata) ;
+ if (nn < 0)
+ return nn ;
+ if (nn == 0)
+ break ;
+ if (nn == 2)
+ { /* Ran over a hole. gp is now out of date, need to recalculate. */
+ vorbis_synthesis_restart (&vdata->vdsp) ;
+ vorbis_calculate_granulepos (psf, &vdata->gp) ;
+ if (target < vdata->gp)
+ { /* Our target is inside the hole :-( */
+ return 0 ;
+ } ;
+ } ;
+ } ;
+
+ pkt = &odata->pkt [odata->pkt_indx] ;
+ thisblock = vorbis_packet_blocksize (&vdata->vinfo, pkt) ;
+ if (thisblock < 0)
+ { /* Not an audio packet */
+ odata->pkt_indx++ ;
+ continue ;
+ } ;
+
+ if (lastblock)
+ { vdata->gp += ((lastblock + thisblock) / 4) ;
+ } ;
+
+ /* Check to see if the block contains our target */
+ if (vdata->gp + ((thisblock + blocksize) / 4) >= target)
+ break ;
+
+ /* Block is before the target. Track for state, but don't decode. */
+ odata->pkt_indx++ ;
+ vorbis_synthesis_trackonly (&vdata->vblock, pkt) ;
+ vorbis_synthesis_blockin (&vdata->vdsp, &vdata->vblock) ;
+ lastblock = thisblock ;
+ } ;
+
+ /* We are at the correct block, but still need to consume samples to reach
+ ** our target. */
+ vorbis_read_sample (psf, (void *) NULL, (target - vdata->gp) * psf->sf.channels, vorbis_rnull) ;
+
+ return 0 ;
+} /* vorbis_skip */
+
+static int
+vorbis_seek_trysearch (SF_PRIVATE *psf, uint64_t target_gp)
+{ OGG_PRIVATE *odata = (OGG_PRIVATE *) psf->container_data ;
+ VORBIS_PRIVATE *vdata = (VORBIS_PRIVATE *) psf->codec_data ;
+ uint64_t best_gp, search_target_gp ;
+ int ret ;
+
+ /* Can't bisect a file we don't know the end of (cannot seek). */
+ if (vdata->pcm_end == (uint64_t) -1)
+ return 0 ;
+
+ /* If the target is for the near future, don't bother bisecting, just skip
+ ** to it. */
+ if (target_gp >= vdata->gp &&
+ target_gp - vdata->gp < ((unsigned) (VORBIS_SEEK_THRESHOLD) * psf->sf.samplerate))
+ return 0 ;
+
+ /* Search for a position a half large-block before our target. As Vorbis is
+ ** lapped, every sample position come from two blocks, the "left" half of
+ ** one block and the "right" half of the previous block. The granule
+ ** position of an Ogg page of a Vorbis stream is the sample offset of the
+ ** last finished sample in the stream that can be decoded from a page. A
+ ** page also contains another half-block of samples waiting to be lapped
+ ** with the first half-block of samples from the next page.
+ **
+ ** Searching for a sample one half of a large block before our target
+ ** guarantees we always load a page containing the previous half block
+ ** required to decode the target. Downside is we can't use best_gp
+ ** parameter of the page seek function. */
+ search_target_gp = vorbis_info_blocksize (&vdata->vinfo, 1) / 2 ;
+ search_target_gp = search_target_gp < target_gp ? target_gp - search_target_gp : 0 ;
+
+ ret = ogg_stream_seek_page_search (psf, odata, search_target_gp, vdata->pcm_start,
+ vdata->pcm_end, &best_gp, psf->dataoffset, vdata->last_page) ;
+ if (ret < 0)
+ return ret ;
+
+ ret = ogg_stream_unpack_page (psf, odata) ;
+ if (ret > 0)
+ { /* Reset the decoder, recalculate position */
+ vorbis_synthesis_restart (&vdata->vdsp) ;
+ ret = vorbis_calculate_granulepos (psf, &vdata->gp) ;
+ } ;
+
+ return ret ;
+} /* vorbis_seek_trysearch */
+
static sf_count_t
vorbis_seek (SF_PRIVATE *psf, int UNUSED (mode), sf_count_t offset)
{ OGG_PRIVATE *odata = (OGG_PRIVATE *) psf->container_data ;
VORBIS_PRIVATE *vdata = (VORBIS_PRIVATE *) psf->codec_data ;
- sf_count_t target ;
+ uint64_t target_gp ;
int ret ;
if (odata == NULL || vdata == NULL)
} ;
if (psf->file.mode == SFM_READ)
- { target = offset + vdata->pcm_start ;
+ { target_gp = (uint64_t) offset + vdata->pcm_start ;
- /*
- ** If the end of the file is know, and the seek isn't for the near
- ** future, do a search of the file for a good place to start.
- */
- ret = 0 ;
- if ((vdata->pcm_end != (uint64_t) -1) &&
- (target < vdata->loc || target - vdata->loc > (2 * psf->sf.samplerate)))
- { uint64_t best_gp ;
-
- best_gp = vdata->pcm_start ;
-
- ret = ogg_stream_seek_page_search (psf, odata, target, vdata->pcm_start,
- vdata->pcm_end, &best_gp, psf->dataoffset, vdata->last_page) ;
- if (ret >= 0)
- { ret = ogg_stream_unpack_page (psf, odata) ;
- if (ret == 1)
- { vdata->loc = best_gp ;
- vorbis_synthesis_restart (&vdata->vdsp) ;
- } ;
- } ;
- } ;
+ ret = vorbis_seek_trysearch (psf, target_gp) ;
- if (ret >= 0 && offset + (sf_count_t) vdata->pcm_start >= vdata->loc)
- target = offset + vdata->pcm_start - vdata->loc ;
- else
+ if (ret < 0 || vdata->gp > target_gp)
{ /* Search failed (bad data?), reset to the beginning of the stream. */
+ psf_log_printf (psf, "Vorbis: Seek search failed. Reading through stream from start.\n") ;
ogg_stream_reset_serialno (&odata->ostream, odata->ostream.serialno) ;
odata->pkt_len = 0 ;
odata->pkt_indx = 0 ;
ogg_sync_fseek (psf, psf->dataoffset, SEEK_SET) ;
- vdata->loc = 0 ;
+ vdata->gp = vdata->pcm_start ;
vorbis_synthesis_restart (&vdata->vdsp) ;
- target = offset ;
} ;
- while (target > 0)
- { sf_count_t m = target > 4096 ? 4096 : target ;
-
- /*
- ** Need to multiply by channels here because the seek is done in
- ** terms of frames and the read function is done in terms of
- ** samples.
- */
- vorbis_read_sample (psf, (void *) NULL, m * psf->sf.channels, vorbis_rnull) ;
-
- target -= m ;
- } ;
+ vorbis_skip (psf, target_gp) ;
- return vdata->loc - vdata->pcm_start ;
+ return vdata->gp - vdata->pcm_start ;
} ;
- return 0 ;
+ psf->error = SFE_BAD_SEEK ;
+ return ((sf_count_t) -1) ;
} /* vorbis_seek */
-
static int
vorbis_byterate (SF_PRIVATE *psf)
{
return -1 ;
} /* vorbis_byterate */
-static sf_count_t
-vorbis_calculate_page_duration (SF_PRIVATE *psf)
+static int
+vorbis_calculate_granulepos (SF_PRIVATE *psf, uint64_t *gp_out)
{ OGG_PRIVATE *odata = (OGG_PRIVATE *) psf->container_data ;
VORBIS_PRIVATE *vdata = (VORBIS_PRIVATE *) psf->codec_data ;
- long thisblock, lastblock ;
- sf_count_t duration ;
- int i ;
-
- lastblock = -1 ;
- duration = 0 ;
- for (i = 0 ; i < odata->pkt_len ; i++)
- { thisblock = vorbis_packet_blocksize (&vdata->vinfo, &(odata->pkt [i])) ;
- if (thisblock >= 0)
- { if (lastblock != -1)
- duration += (lastblock + thisblock) >> 2 ;
- lastblock = thisblock ;
+ ogg_packet *pkt ;
+ uint64_t last_gp ;
+ int thisblock, lastblock, i ;
+ unsigned duration ;
+
+ /* Calculate the granule position when dropped into the middle of a stream
+ ** with an un-primed decoder.
+ **
+ ** Normally the last unpacked packet contains the granule position of the
+ ** last completed sample from decoding all the blocks in the page's
+ ** packets. By calculating how many samples we can decode from the blocks
+ ** in the page's packets and subtracting it from the final packet's granule
+ ** position we get the position of the first sample to be output from the
+ ** decoder after it primes. That is, the current granule position.
+ **
+ ** However, there is an ambiguity if this is the last page of a stream. The
+ ** last page of a stream may have a granule position of fewer samples than
+ ** the page actually contains. The excess samples are padding leftovers
+ ** for and exact sample length file. */
+
+ if (odata->pkt_len > 0)
+ { /* Calculate how many samples can be decoded from blocks in this page,
+ ** accounting for the fact that blocks are 1/2 lapped. */
+ lastblock = -1 ;
+ duration = 0 ;
+ pkt = odata->pkt ;
+ for (i = 0 ; i < odata->pkt_len ; i++)
+ { thisblock = vorbis_packet_blocksize (&vdata->vinfo, &pkt [i]) ;
+ if (thisblock >= 0)
+ { if (lastblock != -1)
+ duration += (lastblock + thisblock) >> 2 ;
+ lastblock = thisblock ;
+ } ;
+ } ;
+
+ pkt = &odata->pkt [odata->pkt_len - 1] ;
+ last_gp = pkt->granulepos ;
+ if (last_gp == (uint64_t) -1)
+ { psf_log_printf (psf, "Vorbis: Ogg page has no granule position, cannot calculate sample position!\n") ;
+ psf->error = SFE_MALFORMED_FILE ;
+ return -1 ;
+ } ;
+
+ if (pkt->e_o_s)
+ { if (last_gp <= duration)
+ { /* Corner case: One page stream. Ogg/Vorbis spec dictates the
+ ** granule position offset MUST be zero, hence this first (and
+ ** only) page must start at 0. */
+ *gp_out = 0 ;
+ return 1 ;
+ } ;
+
+ /* Otherwise, we cannot know where we are without looking at the
+ ** blocks of the previous page. (The granule position of the
+ ** previous page is not enough, we need the block sizes.)
+ **
+ ** We avoid this case by never allowing a bisection search to seek
+ ** beyond the second-to-last page, so the last page is always
+ ** approached with a known location and never dropped into.
+ **
+ ** The only way we should be able to end up here is if there was a
+ ** hole in stream just before the last page, in which case all bets
+ ** are off anyways. */
+ psf_log_printf (psf, "Vorbis: Cannot calculate ambiguous last page duration. Sample count may be wrong.\n") ;
} ;
+
+ if (last_gp < duration)
+ { psf_log_printf (psf, "Vorbis: Granule position is nonsensical! (Missing end-of-stream marker?)\n") ;
+ psf->error = SFE_MALFORMED_FILE ;
+ return -1 ;
+ } ;
+
+ *gp_out = last_gp - duration ;
+ return 1 ;
} ;
- return duration ;
-}
+ return 0 ;
+} /* vorbis_calculate_granulepos */
#else /* HAVE_EXTERNAL_XIPH_LIBS */
} ;
/* Read the block. */
- if ((k = psf_fread (ppaf24->block, 1, ppaf24->blocksize, psf)) != ppaf24->blocksize)
+ if ((k = (int) psf_fread (ppaf24->block, 1, ppaf24->blocksize, psf)) != ppaf24->blocksize)
psf_log_printf (psf, "*** Warning : short read (%d != %d).\n", k, ppaf24->blocksize) ;
/* Do endian swapping if necessary. */
iptr = ubuf.ibuf ;
bufferlen = ARRAY_LEN (ubuf.ibuf) ;
while (len > 0)
- { readcount = (len >= bufferlen) ? bufferlen : len ;
+ { readcount = (len >= bufferlen) ? bufferlen : (int) len ;
count = paf24_read (psf, ppaf24, iptr, readcount) ;
for (k = 0 ; k < readcount ; k++)
ptr [total + k] = iptr [k] >> 16 ;
iptr = ubuf.ibuf ;
bufferlen = ARRAY_LEN (ubuf.ibuf) ;
while (len > 0)
- { readcount = (len >= bufferlen) ? bufferlen : len ;
+ { readcount = (len >= bufferlen) ? bufferlen : (int) len ;
count = paf24_read (psf, ppaf24, iptr, readcount) ;
for (k = 0 ; k < readcount ; k++)
ptr [total + k] = normfact * iptr [k] ;
iptr = ubuf.ibuf ;
bufferlen = ARRAY_LEN (ubuf.ibuf) ;
while (len > 0)
- { readcount = (len >= bufferlen) ? bufferlen : len ;
+ { readcount = (len >= bufferlen) ? bufferlen : (int) len ;
count = paf24_read (psf, ppaf24, iptr, readcount) ;
for (k = 0 ; k < readcount ; k++)
ptr [total + k] = normfact * iptr [k] ;
} ;
/* Write block to disk. */
- if ((k = psf_fwrite (ppaf24->block, 1, ppaf24->blocksize, psf)) != ppaf24->blocksize)
+ if ((k = (int) psf_fwrite (ppaf24->block, 1, ppaf24->blocksize, psf)) != ppaf24->blocksize)
psf_log_printf (psf, "*** Warning : short write (%d != %d).\n", k, ppaf24->blocksize) ;
if (ppaf24->sample_count < ppaf24->write_block * PAF24_SAMPLES_PER_BLOCK + ppaf24->write_count)
iptr = ubuf.ibuf ;
bufferlen = ARRAY_LEN (ubuf.ibuf) ;
while (len > 0)
- { writecount = (len >= bufferlen) ? bufferlen : len ;
+ { writecount = (len >= bufferlen) ? bufferlen : (int) len ;
for (k = 0 ; k < writecount ; k++)
iptr [k] = ptr [total + k] << 16 ;
count = paf24_write (psf, ppaf24, iptr, writecount) ;
iptr = ubuf.ibuf ;
bufferlen = ARRAY_LEN (ubuf.ibuf) ;
while (len > 0)
- { writecount = (len >= bufferlen) ? bufferlen : len ;
+ { writecount = (len >= bufferlen) ? bufferlen : (int) len ;
for (k = 0 ; k < writecount ; k++)
iptr [k] = psf_lrintf (normfact * ptr [total + k]) ;
count = paf24_write (psf, ppaf24, iptr, writecount) ;
iptr = ubuf.ibuf ;
bufferlen = ARRAY_LEN (ubuf.ibuf) ;
while (len > 0)
- { writecount = (len >= bufferlen) ? bufferlen : len ;
+ { writecount = (len >= bufferlen) ? bufferlen : (int) len ;
for (k = 0 ; k < writecount ; k++)
iptr [k] = psf_lrint (normfact * ptr [total+k]) ;
count = paf24_write (psf, ppaf24, iptr, writecount) ;
else if ((SF_CODEC (psf->sf.format)) == SF_FORMAT_PCM_U8)
chars = SF_CHARS_UNSIGNED ;
- if (CPU_IS_BIG_ENDIAN)
- psf->data_endswap = (psf->endian == SF_ENDIAN_BIG) ? SF_FALSE : SF_TRUE ;
- else
- psf->data_endswap = (psf->endian == SF_ENDIAN_LITTLE) ? SF_FALSE : SF_TRUE ;
+#if CPU_IS_BIG_ENDIAN
+ psf->data_endswap = (psf->endian == SF_ENDIAN_BIG) ? SF_FALSE : SF_TRUE ;
+#else
+ psf->data_endswap = (psf->endian == SF_ENDIAN_LITTLE) ? SF_FALSE : SF_TRUE ;
+#endif
if (psf->file.mode == SFM_READ || psf->file.mode == SFM_RDWR)
{ switch (psf->bytewidth * 0x10000 + psf->endian + chars)
static inline void
sc2s_array (const signed char *src, int count, short *dest)
-{ while (--count >= 0)
- { dest [count] = ((uint16_t) src [count]) << 8 ;
+{ for (int i = 0 ; i < count ; i++)
+ { dest [i] = ((uint16_t) src [i]) << 8 ;
} ;
} /* sc2s_array */
static inline void
uc2s_array (const unsigned char *src, int count, short *dest)
-{ while (--count >= 0)
- { dest [count] = (((uint32_t) src [count]) - 0x80) << 8 ;
+{ for (int i = 0 ; i < count ; i++)
+ { dest [i] = (((uint32_t) src [i]) - 0x80) << 8 ;
} ;
} /* uc2s_array */
static inline void
let2s_array (const tribyte *src, int count, short *dest)
-{ while (--count >= 0)
- dest [count] = LET2H_16_PTR (src [count].bytes) ;
+{ for (int i = 0 ; i < count ; i++)
+ dest [i] = LET2H_16_PTR (src [i].bytes) ;
} /* let2s_array */
static inline void
bet2s_array (const tribyte *src, int count, short *dest)
-{ while (--count >= 0)
- dest [count] = BET2H_16_PTR (src [count].bytes) ;
+{ for (int i = 0 ; i < count ; i++)
+ dest [i] = BET2H_16_PTR (src [i].bytes) ;
} /* bet2s_array */
static inline void
lei2s_array (const int *src, int count, short *dest)
{ int value ;
- while (--count >= 0)
- { value = LE2H_32 (src [count]) ;
- dest [count] = value >> 16 ;
+ for (int i = 0 ; i < count ; i++)
+ { value = LE2H_32 (src [i]) ;
+ dest [i] = value >> 16 ;
} ;
} /* lei2s_array */
bei2s_array (const int *src, int count, short *dest)
{ int value ;
- while (--count >= 0)
- { value = BE2H_32 (src [count]) ;
- dest [count] = value >> 16 ;
+ for (int i = 0 ; i < count ; i++)
+ { value = BE2H_32 (src [i]) ;
+ dest [i] = value >> 16 ;
} ;
} /* bei2s_array */
static inline void
sc2i_array (const signed char *src, int count, int *dest)
-{ while (--count >= 0)
- { dest [count] = arith_shift_left ((int) src [count], 24) ;
+{ for (int i = 0 ; i < count ; i++)
+ { dest [i] = arith_shift_left ((int) src [i], 24) ;
} ;
} /* sc2i_array */
static inline void
uc2i_array (const unsigned char *src, int count, int *dest)
-{ while (--count >= 0)
- { dest [count] = arith_shift_left (((int) src [count]) - 128, 24) ;
+{ for (int i = 0 ; i < count ; i++)
+ { dest [i] = arith_shift_left (((int) src [i]) - 128, 24) ;
} ;
} /* uc2i_array */
bes2i_array (const short *src, int count, int *dest)
{ short value ;
- while (--count >= 0)
- { value = BE2H_16 (src [count]) ;
- dest [count] = arith_shift_left (value, 16) ;
+ for (int i = 0 ; i < count ; i++)
+ { value = BE2H_16 (src [i]) ;
+ dest [i] = arith_shift_left (value, 16) ;
} ;
} /* bes2i_array */
les2i_array (const short *src, int count, int *dest)
{ short value ;
- while (--count >= 0)
- { value = LE2H_16 (src [count]) ;
- dest [count] = arith_shift_left (value, 16) ;
+ for (int i = 0 ; i < count ; i++)
+ { value = LE2H_16 (src [i]) ;
+ dest [i] = arith_shift_left (value, 16) ;
} ;
} /* les2i_array */
static inline void
bet2i_array (const tribyte *src, int count, int *dest)
-{ while (--count >= 0)
- dest [count] = psf_get_be24 (src [count].bytes, 0) ;
+{ for (int i = 0 ; i < count ; i++)
+ dest [i] = psf_get_be24 (src [i].bytes, 0) ;
} /* bet2i_array */
static inline void
let2i_array (const tribyte *src, int count, int *dest)
-{ while (--count >= 0)
- dest [count] = psf_get_le24 (src [count].bytes, 0) ;
+{ for (int i = 0 ; i < count ; i++)
+ dest [i] = psf_get_le24 (src [i].bytes, 0) ;
} /* let2i_array */
/*--------------------------------------------------------------------------
static inline void
sc2f_array (const signed char *src, int count, float *dest, float normfact)
-{ while (--count >= 0)
- dest [count] = ((float) src [count]) * normfact ;
+{ for (int i = 0 ; i < count ; i++)
+ dest [i] = ((float) src [i]) * normfact ;
} /* sc2f_array */
static inline void
uc2f_array (const unsigned char *src, int count, float *dest, float normfact)
-{ while (--count >= 0)
- dest [count] = (((int) src [count]) - 128) * normfact ;
+{ for (int i = 0 ; i < count ; i++)
+ dest [i] = (((int) src [i]) - 128) * normfact ;
} /* uc2f_array */
static inline void
les2f_array (const short *src, int count, float *dest, float normfact)
{ short value ;
- while (--count >= 0)
- { value = src [count] ;
+ for (int i = 0 ; i < count ; i++)
+ { value = src [i] ;
value = LE2H_16 (value) ;
- dest [count] = ((float) value) * normfact ;
+ dest [i] = ((float) value) * normfact ;
} ;
} /* les2f_array */
bes2f_array (const short *src, int count, float *dest, float normfact)
{ short value ;
- while (--count >= 0)
- { value = src [count] ;
+ for (int i = 0 ; i < count ; i++)
+ { value = src [i] ;
value = BE2H_16 (value) ;
- dest [count] = ((float) value) * normfact ;
+ dest [i] = ((float) value) * normfact ;
} ;
} /* bes2f_array */
let2f_array (const tribyte *src, int count, float *dest, float normfact)
{ int value ;
- while (--count >= 0)
- { value = psf_get_le24 (src [count].bytes, 0) ;
- dest [count] = ((float) value) * normfact ;
+ for (int i = 0 ; i < count ; i++)
+ { value = psf_get_le24 (src [i].bytes, 0) ;
+ dest [i] = ((float) value) * normfact ;
} ;
} /* let2f_array */
bet2f_array (const tribyte *src, int count, float *dest, float normfact)
{ int value ;
- while (--count >= 0)
- { value = psf_get_be24 (src [count].bytes, 0) ;
- dest [count] = ((float) value) * normfact ;
+ for (int i = 0 ; i < count ; i++)
+ { value = psf_get_be24 (src [i].bytes, 0) ;
+ dest [i] = ((float) value) * normfact ;
} ;
} /* bet2f_array */
lei2f_array (const int *src, int count, float *dest, float normfact)
{ int value ;
- while (--count >= 0)
- { value = src [count] ;
+ for (int i = 0 ; i < count ; i++)
+ { value = src [i] ;
value = LE2H_32 (value) ;
- dest [count] = ((float) value) * normfact ;
+ dest [i] = ((float) value) * normfact ;
} ;
} /* lei2f_array */
bei2f_array (const int *src, int count, float *dest, float normfact)
{ int value ;
- while (--count >= 0)
- { value = src [count] ;
+ for (int i = 0 ; i < count ; i++)
+ { value = src [i] ;
value = BE2H_32 (value) ;
- dest [count] = ((float) value) * normfact ;
+ dest [i] = ((float) value) * normfact ;
} ;
} /* bei2f_array */
static inline void
sc2d_array (const signed char *src, int count, double *dest, double normfact)
-{ while (--count >= 0)
- dest [count] = ((double) src [count]) * normfact ;
+{ for (int i = 0 ; i < count ; i++)
+ dest [i] = ((double) src [i]) * normfact ;
} /* sc2d_array */
static inline void
uc2d_array (const unsigned char *src, int count, double *dest, double normfact)
-{ while (--count >= 0)
- dest [count] = (((int) src [count]) - 128) * normfact ;
+{ for (int i = 0 ; i < count ; i++)
+ dest [i] = (((int) src [i]) - 128) * normfact ;
} /* uc2d_array */
static inline void
les2d_array (const short *src, int count, double *dest, double normfact)
{ short value ;
- while (--count >= 0)
- { value = src [count] ;
+ for (int i = 0 ; i < count ; i++)
+ { value = src [i] ;
value = LE2H_16 (value) ;
- dest [count] = ((double) value) * normfact ;
+ dest [i] = ((double) value) * normfact ;
} ;
} /* les2d_array */
bes2d_array (const short *src, int count, double *dest, double normfact)
{ short value ;
- while (--count >= 0)
- { value = src [count] ;
+ for (int i = 0 ; i < count ; i++)
+ { value = src [i] ;
value = BE2H_16 (value) ;
- dest [count] = ((double) value) * normfact ;
+ dest [i] = ((double) value) * normfact ;
} ;
} /* bes2d_array */
let2d_array (const tribyte *src, int count, double *dest, double normfact)
{ int value ;
- while (--count >= 0)
- { value = psf_get_le24 (src [count].bytes, 0) ;
- dest [count] = ((double) value) * normfact ;
+ for (int i = 0 ; i < count ; i++)
+ { value = psf_get_le24 (src [i].bytes, 0) ;
+ dest [i] = ((double) value) * normfact ;
} ;
} /* let2d_array */
bet2d_array (const tribyte *src, int count, double *dest, double normfact)
{ int value ;
- while (--count >= 0)
- { value = psf_get_be24 (src [count].bytes, 0) ;
- dest [count] = ((double) value) * normfact ;
+ for (int i = 0 ; i < count ; i++)
+ { value = psf_get_be24 (src [i].bytes, 0) ;
+ dest [i] = ((double) value) * normfact ;
} ;
} /* bet2d_array */
lei2d_array (const int *src, int count, double *dest, double normfact)
{ int value ;
- while (--count >= 0)
- { value = src [count] ;
+ for (int i = 0 ; i < count ; i++)
+ { value = src [i] ;
value = LE2H_32 (value) ;
- dest [count] = ((double) value) * normfact ;
+ dest [i] = ((double) value) * normfact ;
} ;
} /* lei2d_array */
bei2d_array (const int *src, int count, double *dest, double normfact)
{ int value ;
- while (--count >= 0)
- { value = src [count] ;
+ for (int i = 0 ; i < count ; i++)
+ { value = src [i] ;
value = BE2H_32 (value) ;
- dest [count] = ((double) value) * normfact ;
+ dest [i] = ((double) value) * normfact ;
} ;
} /* bei2d_array */
static inline void
s2sc_array (const short *src, signed char *dest, int count)
-{ while (--count >= 0)
- dest [count] = src [count] >> 8 ;
+{ for (int i = 0 ; i < count ; i++)
+ dest [i] = src [i] >> 8 ;
} /* s2sc_array */
static inline void
s2uc_array (const short *src, unsigned char *dest, int count)
-{ while (--count >= 0)
- dest [count] = (src [count] >> 8) + 0x80 ;
+{ for (int i = 0 ; i < count ; i++)
+ dest [i] = (src [i] >> 8) + 0x80 ;
} /* s2uc_array */
static inline void
s2let_array (const short *src, tribyte *dest, int count)
-{ while (--count >= 0)
- { dest [count].bytes [0] = 0 ;
- dest [count].bytes [1] = src [count] ;
- dest [count].bytes [2] = src [count] >> 8 ;
+{ for (int i = 0 ; i < count ; i++)
+ { dest [i].bytes [0] = 0 ;
+ dest [i].bytes [1] = src [i] ;
+ dest [i].bytes [2] = src [i] >> 8 ;
} ;
} /* s2let_array */
static inline void
s2bet_array (const short *src, tribyte *dest, int count)
-{ while (--count >= 0)
- { dest [count].bytes [2] = 0 ;
- dest [count].bytes [1] = src [count] ;
- dest [count].bytes [0] = src [count] >> 8 ;
+{ for (int i = 0 ; i < count ; i++)
+ { dest [i].bytes [2] = 0 ;
+ dest [i].bytes [1] = src [i] ;
+ dest [i].bytes [0] = src [i] >> 8 ;
} ;
} /* s2bet_array */
s2lei_array (const short *src, int *dest, int count)
{ unsigned char *ucptr ;
- ucptr = ((unsigned char*) dest) + 4 * count ;
- while (--count >= 0)
- { ucptr -= 4 ;
+ for (int i = 0 ; i < count ; i++)
+ { ucptr = (unsigned char*) &dest [i] ;
ucptr [0] = 0 ;
ucptr [1] = 0 ;
- ucptr [2] = src [count] ;
- ucptr [3] = src [count] >> 8 ;
+ ucptr [2] = src [i] ;
+ ucptr [3] = src [i] >> 8 ;
} ;
} /* s2lei_array */
s2bei_array (const short *src, int *dest, int count)
{ unsigned char *ucptr ;
- ucptr = ((unsigned char*) dest) + 4 * count ;
- while (--count >= 0)
- { ucptr -= 4 ;
- ucptr [0] = src [count] >> 8 ;
- ucptr [1] = src [count] ;
+ for (int i = 0 ; i < count ; i++)
+ { ucptr = (unsigned char*) &dest [i] ;
+ ucptr [0] = src [i] >> 8 ;
+ ucptr [1] = src [i] ;
ucptr [2] = 0 ;
ucptr [3] = 0 ;
} ;
static inline void
i2sc_array (const int *src, signed char *dest, int count)
-{ while (--count >= 0)
- dest [count] = (src [count] >> 24) ;
+{ for (int i = 0 ; i < count ; i++)
+ dest [i] = (src [i] >> 24) ;
} /* i2sc_array */
static inline void
i2uc_array (const int *src, unsigned char *dest, int count)
-{ while (--count >= 0)
- dest [count] = ((src [count] >> 24) + 128) ;
+{ for (int i = 0 ; i < count ; i++)
+ dest [i] = ((src [i] >> 24) + 128) ;
} /* i2uc_array */
static inline void
i2bes_array (const int *src, short *dest, int count)
{ unsigned char *ucptr ;
- ucptr = ((unsigned char*) dest) + 2 * count ;
- while (--count >= 0)
- { ucptr -= 2 ;
- ucptr [0] = src [count] >> 24 ;
- ucptr [1] = src [count] >> 16 ;
+ for (int i = 0 ; i < count ; i++)
+ { ucptr = (unsigned char*) &dest [i] ;
+ ucptr [0] = src [i] >> 24 ;
+ ucptr [1] = src [i] >> 16 ;
} ;
} /* i2bes_array */
i2les_array (const int *src, short *dest, int count)
{ unsigned char *ucptr ;
- ucptr = ((unsigned char*) dest) + 2 * count ;
- while (--count >= 0)
- { ucptr -= 2 ;
- ucptr [0] = src [count] >> 16 ;
- ucptr [1] = src [count] >> 24 ;
+ for (int i = 0 ; i < count ; i++)
+ { ucptr = (unsigned char*) &dest [i] ;
+ ucptr [0] = src [i] >> 16 ;
+ ucptr [1] = src [i] >> 24 ;
} ;
} /* i2les_array */
i2let_array (const int *src, tribyte *dest, int count)
{ int value ;
- while (--count >= 0)
- { value = src [count] >> 8 ;
- dest [count].bytes [0] = value ;
- dest [count].bytes [1] = value >> 8 ;
- dest [count].bytes [2] = value >> 16 ;
+ for (int i = 0 ; i < count ; i++)
+ { value = src [i] >> 8 ;
+ dest [i].bytes [0] = value ;
+ dest [i].bytes [1] = value >> 8 ;
+ dest [i].bytes [2] = value >> 16 ;
} ;
} /* i2let_array */
i2bet_array (const int *src, tribyte *dest, int count)
{ int value ;
- while (--count >= 0)
- { value = src [count] >> 8 ;
- dest [count].bytes [2] = value ;
- dest [count].bytes [1] = value >> 8 ;
- dest [count].bytes [0] = value >> 16 ;
+ for (int i = 0 ; i < count ; i++)
+ { value = src [i] >> 8 ;
+ dest [i].bytes [2] = value ;
+ dest [i].bytes [1] = value >> 8 ;
+ dest [i].bytes [0] = value >> 16 ;
} ;
} /* i2bet_array */
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.scbuf, sizeof (signed char), bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.scbuf, sizeof (signed char), bufferlen, psf) ;
sc2s_array (ubuf.scbuf, readcount, ptr + total) ;
total += readcount ;
if (readcount < bufferlen)
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.ucbuf, sizeof (unsigned char), bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.ucbuf, sizeof (unsigned char), bufferlen, psf) ;
uc2s_array (ubuf.ucbuf, readcount, ptr + total) ;
total += readcount ;
if (readcount < bufferlen)
pcm_read_bes2s (SF_PRIVATE *psf, short *ptr, sf_count_t len)
{ int total ;
- total = psf_fread (ptr, sizeof (short), len, psf) ;
- if (CPU_IS_LITTLE_ENDIAN)
- endswap_short_array (ptr, len) ;
+ total = (int) psf_fread (ptr, sizeof (short), len, psf) ;
+#if CPU_IS_LITTLE_ENDIAN
+ endswap_short_array (ptr, len) ;
+#endif
return total ;
} /* pcm_read_bes2s */
{ int total ;
total = psf_fread (ptr, sizeof (short), len, psf) ;
- if (CPU_IS_BIG_ENDIAN)
- endswap_short_array (ptr, len) ;
+#if CPU_IS_BIG_ENDIAN
+ endswap_short_array (ptr, len) ;
+#endif
return total ;
} /* pcm_read_les2s */
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.ucbuf, SIZEOF_TRIBYTE, bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.ucbuf, SIZEOF_TRIBYTE, bufferlen, psf) ;
bet2s_array ((tribyte*) (ubuf.ucbuf), readcount, ptr + total) ;
total += readcount ;
if (readcount < bufferlen)
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.ucbuf, SIZEOF_TRIBYTE, bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.ucbuf, SIZEOF_TRIBYTE, bufferlen, psf) ;
let2s_array ((tribyte*) (ubuf.ucbuf), readcount, ptr + total) ;
total += readcount ;
if (readcount < bufferlen)
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.ibuf, sizeof (int), bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.ibuf, sizeof (int), bufferlen, psf) ;
bei2s_array (ubuf.ibuf, readcount, ptr + total) ;
total += readcount ;
if (readcount < bufferlen)
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.ibuf, sizeof (int), bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.ibuf, sizeof (int), bufferlen, psf) ;
lei2s_array (ubuf.ibuf, readcount, ptr + total) ;
total += readcount ;
if (readcount < bufferlen)
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.scbuf, sizeof (signed char), bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.scbuf, sizeof (signed char), bufferlen, psf) ;
sc2i_array (ubuf.scbuf, readcount, ptr + total) ;
total += readcount ;
if (readcount < bufferlen)
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.ucbuf, sizeof (unsigned char), bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.ucbuf, sizeof (unsigned char), bufferlen, psf) ;
uc2i_array (ubuf.ucbuf, readcount, ptr + total) ;
total += readcount ;
if (readcount < bufferlen)
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.sbuf, sizeof (short), bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.sbuf, sizeof (short), bufferlen, psf) ;
bes2i_array (ubuf.sbuf, readcount, ptr + total) ;
total += readcount ;
if (readcount < bufferlen)
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.sbuf, sizeof (short), bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.sbuf, sizeof (short), bufferlen, psf) ;
les2i_array (ubuf.sbuf, readcount, ptr + total) ;
total += readcount ;
if (readcount < bufferlen)
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.ucbuf, SIZEOF_TRIBYTE, bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.ucbuf, SIZEOF_TRIBYTE, bufferlen, psf) ;
bet2i_array ((tribyte*) (ubuf.ucbuf), readcount, ptr + total) ;
total += readcount ;
if (readcount < bufferlen)
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.ucbuf, SIZEOF_TRIBYTE, bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.ucbuf, SIZEOF_TRIBYTE, bufferlen, psf) ;
let2i_array ((tribyte*) (ubuf.ucbuf), readcount, ptr + total) ;
total += readcount ;
if (readcount < bufferlen)
{ int total ;
total = psf_fread (ptr, sizeof (int), len, psf) ;
- if (CPU_IS_LITTLE_ENDIAN)
- endswap_int_array (ptr, len) ;
+#if CPU_IS_LITTLE_ENDIAN
+ endswap_int_array (ptr, len) ;
+#endif
return total ;
} /* pcm_read_bei2i */
{ int total ;
total = psf_fread (ptr, sizeof (int), len, psf) ;
- if (CPU_IS_BIG_ENDIAN)
- endswap_int_array (ptr, len) ;
+#if CPU_IS_BIG_ENDIAN
+ endswap_int_array (ptr, len) ;
+#endif
return total ;
} /* pcm_read_lei2i */
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.scbuf, sizeof (signed char), bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.scbuf, sizeof (signed char), bufferlen, psf) ;
sc2f_array (ubuf.scbuf, readcount, ptr + total, normfact) ;
total += readcount ;
if (readcount < bufferlen)
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.ucbuf, sizeof (unsigned char), bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.ucbuf, sizeof (unsigned char), bufferlen, psf) ;
uc2f_array (ubuf.ucbuf, readcount, ptr + total, normfact) ;
total += readcount ;
if (readcount < bufferlen)
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.sbuf, sizeof (short), bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.sbuf, sizeof (short), bufferlen, psf) ;
bes2f_array (ubuf.sbuf, readcount, ptr + total, normfact) ;
total += readcount ;
if (readcount < bufferlen)
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.sbuf, sizeof (short), bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.sbuf, sizeof (short), bufferlen, psf) ;
les2f_array (ubuf.sbuf, readcount, ptr + total, normfact) ;
total += readcount ;
if (readcount < bufferlen)
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.ucbuf, SIZEOF_TRIBYTE, bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.ucbuf, SIZEOF_TRIBYTE, bufferlen, psf) ;
bet2f_array ((tribyte*) (ubuf.ucbuf), readcount, ptr + total, normfact) ;
total += readcount ;
if (readcount < bufferlen)
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.ucbuf, SIZEOF_TRIBYTE, bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.ucbuf, SIZEOF_TRIBYTE, bufferlen, psf) ;
let2f_array ((tribyte*) (ubuf.ucbuf), readcount, ptr + total, normfact) ;
total += readcount ;
if (readcount < bufferlen)
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.ibuf, sizeof (int), bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.ibuf, sizeof (int), bufferlen, psf) ;
bei2f_array (ubuf.ibuf, readcount, ptr + total, normfact) ;
total += readcount ;
if (readcount < bufferlen)
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.ibuf, sizeof (int), bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.ibuf, sizeof (int), bufferlen, psf) ;
lei2f_array (ubuf.ibuf, readcount, ptr + total, normfact) ;
total += readcount ;
if (readcount < bufferlen)
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.scbuf, sizeof (signed char), bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.scbuf, sizeof (signed char), bufferlen, psf) ;
sc2d_array (ubuf.scbuf, readcount, ptr + total, normfact) ;
total += readcount ;
if (readcount < bufferlen)
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.ucbuf, sizeof (unsigned char), bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.ucbuf, sizeof (unsigned char), bufferlen, psf) ;
uc2d_array (ubuf.ucbuf, readcount, ptr + total, normfact) ;
total += readcount ;
if (readcount < bufferlen)
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.sbuf, sizeof (short), bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.sbuf, sizeof (short), bufferlen, psf) ;
bes2d_array (ubuf.sbuf, readcount, ptr + total, normfact) ;
total += readcount ;
if (readcount < bufferlen)
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.sbuf, sizeof (short), bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.sbuf, sizeof (short), bufferlen, psf) ;
les2d_array (ubuf.sbuf, readcount, ptr + total, normfact) ;
total += readcount ;
if (readcount < bufferlen)
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.ucbuf, SIZEOF_TRIBYTE, bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.ucbuf, SIZEOF_TRIBYTE, bufferlen, psf) ;
bet2d_array ((tribyte*) (ubuf.ucbuf), readcount, ptr + total, normfact) ;
total += readcount ;
if (readcount < bufferlen)
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.ucbuf, SIZEOF_TRIBYTE, bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.ucbuf, SIZEOF_TRIBYTE, bufferlen, psf) ;
let2d_array ((tribyte*) (ubuf.ucbuf), readcount, ptr + total, normfact) ;
total += readcount ;
if (readcount < bufferlen)
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.ibuf, sizeof (int), bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.ibuf, sizeof (int), bufferlen, psf) ;
bei2d_array (ubuf.ibuf, readcount, ptr + total, normfact) ;
total += readcount ;
if (readcount < bufferlen)
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.ibuf, sizeof (int), bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.ibuf, sizeof (int), bufferlen, psf) ;
lei2d_array (ubuf.ibuf, readcount, ptr + total, normfact) ;
total += readcount ;
if (readcount < bufferlen)
{ if (len < bufferlen)
bufferlen = (int) len ;
s2sc_array (ptr + total, ubuf.scbuf, bufferlen) ;
- writecount = psf_fwrite (ubuf.scbuf, sizeof (signed char), bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.scbuf, sizeof (signed char), bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
{ if (len < bufferlen)
bufferlen = (int) len ;
s2uc_array (ptr + total, ubuf.ucbuf, bufferlen) ;
- writecount = psf_fwrite (ubuf.ucbuf, sizeof (unsigned char), bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.ucbuf, sizeof (unsigned char), bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
static sf_count_t
pcm_write_s2bes (SF_PRIVATE *psf, const short *ptr, sf_count_t len)
-{ BUF_UNION ubuf ;
+{
+#if CPU_IS_BIG_ENDIAN
+ return psf_fwrite (ptr, sizeof (short), len, psf) ;
+#else
+ BUF_UNION ubuf ;
int bufferlen, writecount ;
sf_count_t total = 0 ;
- if (CPU_IS_BIG_ENDIAN)
- return psf_fwrite (ptr, sizeof (short), len, psf) ;
- else
-
bufferlen = ARRAY_LEN (ubuf.sbuf) ;
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
endswap_short_copy (ubuf.sbuf, ptr + total, bufferlen) ;
- writecount = psf_fwrite (ubuf.sbuf, sizeof (short), bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.sbuf, sizeof (short), bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
} ;
return total ;
+#endif
} /* pcm_write_s2bes */
static sf_count_t
pcm_write_s2les (SF_PRIVATE *psf, const short *ptr, sf_count_t len)
-{ BUF_UNION ubuf ;
+{
+#if CPU_IS_LITTLE_ENDIAN
+ return psf_fwrite (ptr, sizeof (short), len, psf) ;
+#else
+ BUF_UNION ubuf ;
int bufferlen, writecount ;
sf_count_t total = 0 ;
- if (CPU_IS_LITTLE_ENDIAN)
- return psf_fwrite (ptr, sizeof (short), len, psf) ;
-
bufferlen = ARRAY_LEN (ubuf.sbuf) ;
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
endswap_short_copy (ubuf.sbuf, ptr + total, bufferlen) ;
- writecount = psf_fwrite (ubuf.sbuf, sizeof (short), bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.sbuf, sizeof (short), bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
} ;
return total ;
+#endif
} /* pcm_write_s2les */
static sf_count_t
{ if (len < bufferlen)
bufferlen = (int) len ;
s2bet_array (ptr + total, (tribyte*) (ubuf.ucbuf), bufferlen) ;
- writecount = psf_fwrite (ubuf.ucbuf, SIZEOF_TRIBYTE, bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.ucbuf, SIZEOF_TRIBYTE, bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
{ if (len < bufferlen)
bufferlen = (int) len ;
s2let_array (ptr + total, (tribyte*) (ubuf.ucbuf), bufferlen) ;
- writecount = psf_fwrite (ubuf.ucbuf, SIZEOF_TRIBYTE, bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.ucbuf, SIZEOF_TRIBYTE, bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
{ if (len < bufferlen)
bufferlen = (int) len ;
s2bei_array (ptr + total, ubuf.ibuf, bufferlen) ;
- writecount = psf_fwrite (ubuf.ibuf, sizeof (int), bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.ibuf, sizeof (int), bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
{ if (len < bufferlen)
bufferlen = (int) len ;
s2lei_array (ptr + total, ubuf.ibuf, bufferlen) ;
- writecount = psf_fwrite (ubuf.ibuf, sizeof (int), bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.ibuf, sizeof (int), bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
{ if (len < bufferlen)
bufferlen = (int) len ;
i2sc_array (ptr + total, ubuf.scbuf, bufferlen) ;
- writecount = psf_fwrite (ubuf.scbuf, sizeof (signed char), bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.scbuf, sizeof (signed char), bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
{ if (len < bufferlen)
bufferlen = (int) len ;
i2uc_array (ptr + total, ubuf.ucbuf, bufferlen) ;
- writecount = psf_fwrite (ubuf.ucbuf, sizeof (signed char), bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.ucbuf, sizeof (signed char), bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
{ if (len < bufferlen)
bufferlen = (int) len ;
i2bes_array (ptr + total, ubuf.sbuf, bufferlen) ;
- writecount = psf_fwrite (ubuf.sbuf, sizeof (short), bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.sbuf, sizeof (short), bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
{ if (len < bufferlen)
bufferlen = (int) len ;
i2les_array (ptr + total, ubuf.sbuf, bufferlen) ;
- writecount = psf_fwrite (ubuf.sbuf, sizeof (short), bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.sbuf, sizeof (short), bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
{ if (len < bufferlen)
bufferlen = (int) len ;
i2bet_array (ptr + total, (tribyte*) (ubuf.ucbuf), bufferlen) ;
- writecount = psf_fwrite (ubuf.ucbuf, SIZEOF_TRIBYTE, bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.ucbuf, SIZEOF_TRIBYTE, bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
{ if (len < bufferlen)
bufferlen = (int) len ;
i2let_array (ptr + total, (tribyte*) (ubuf.ucbuf), bufferlen) ;
- writecount = psf_fwrite (ubuf.ucbuf, SIZEOF_TRIBYTE, bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.ucbuf, SIZEOF_TRIBYTE, bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
static sf_count_t
pcm_write_i2bei (SF_PRIVATE *psf, const int *ptr, sf_count_t len)
-{ BUF_UNION ubuf ;
+{
+#if CPU_IS_BIG_ENDIAN
+ return psf_fwrite (ptr, sizeof (int), len, psf) ;
+#else
+ BUF_UNION ubuf ;
int bufferlen, writecount ;
sf_count_t total = 0 ;
- if (CPU_IS_BIG_ENDIAN)
- return psf_fwrite (ptr, sizeof (int), len, psf) ;
-
bufferlen = ARRAY_LEN (ubuf.ibuf) ;
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
endswap_int_copy (ubuf.ibuf, ptr + total, bufferlen) ;
- writecount = psf_fwrite (ubuf.ibuf, sizeof (int), bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.ibuf, sizeof (int), bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
} ;
return total ;
+#endif
} /* pcm_write_i2bei */
static sf_count_t
pcm_write_i2lei (SF_PRIVATE *psf, const int *ptr, sf_count_t len)
-{ BUF_UNION ubuf ;
+{
+#if CPU_IS_LITTLE_ENDIAN
+ return psf_fwrite (ptr, sizeof (int), len, psf) ;
+#else
+ BUF_UNION ubuf ;
int bufferlen, writecount ;
sf_count_t total = 0 ;
- if (CPU_IS_LITTLE_ENDIAN)
- return psf_fwrite (ptr, sizeof (int), len, psf) ;
-
bufferlen = ARRAY_LEN (ubuf.ibuf) ;
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
endswap_int_copy (ubuf.ibuf, ptr + total, bufferlen) ;
- writecount = psf_fwrite (ubuf.ibuf, sizeof (int), bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.ibuf, sizeof (int), bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
} ;
return total ;
+#endif
} /* pcm_write_i2lei */
/*------------------------------------------------------------------------------
normfact = normalize ? (1.0 * 0x7F) : 1.0 ;
- while (--count >= 0)
- { dest [count] = psf_lrintf (src [count] * normfact) ;
+ for (int i = 0 ; i < count ; i++)
+ { dest [i] = psf_lrintf (src [i] * normfact) ;
} ;
} /* f2sc_array */
normfact = normalize ? (8.0 * 0x10000000) : (1.0 * 0x1000000) ;
- while (--count >= 0)
- { scaled_value = src [count] * normfact ;
- if (CPU_CLIPS_POSITIVE == 0 && scaled_value >= (1.0 * 0x7FFFFFFF))
- { dest [count] = 127 ;
+ for (int i = 0 ; i < count ; i++)
+ { scaled_value = src [i] * normfact ;
+#if CPU_CLIPS_POSITIVE == 0
+ if (scaled_value >= (1.0 * 0x7FFFFFFF))
+ { dest [i] = 127 ;
continue ;
} ;
- if (CPU_CLIPS_NEGATIVE == 0 && scaled_value <= (-8.0 * 0x10000000))
- { dest [count] = -128 ;
+#endif
+#if CPU_CLIPS_NEGATIVE == 0
+ if (scaled_value <= (-8.0 * 0x10000000))
+ { dest [i] = -128 ;
continue ;
} ;
+#endif
- dest [count] = psf_lrintf (scaled_value) >> 24 ;
+ dest [i] = psf_lrintf (scaled_value) >> 24 ;
} ;
} /* f2sc_clip_array */
{ if (len < bufferlen)
bufferlen = (int) len ;
convert (ptr + total, ubuf.scbuf, bufferlen, psf->norm_float) ;
- writecount = psf_fwrite (ubuf.scbuf, sizeof (signed char), bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.scbuf, sizeof (signed char), bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
normfact = normalize ? (1.0 * 0x7F) : 1.0 ;
- while (--count >= 0)
- { dest [count] = psf_lrintf (src [count] * normfact) + 128 ;
+ for (int i = 0 ; i < count ; i++)
+ { dest [i] = psf_lrintf (src [i] * normfact) + 128 ;
} ;
} /* f2uc_array */
normfact = normalize ? (8.0 * 0x10000000) : (1.0 * 0x1000000) ;
- while (--count >= 0)
- { scaled_value = src [count] * normfact ;
- if (CPU_CLIPS_POSITIVE == 0 && scaled_value >= (1.0 * 0x7FFFFFFF))
- { dest [count] = 0xFF ;
+ for (int i = 0 ; i < count ; i++)
+ { scaled_value = src [i] * normfact ;
+#if CPU_CLIPS_POSITIVE == 0
+ if (scaled_value >= (1.0 * 0x7FFFFFFF))
+ { dest [i] = 0xFF ;
continue ;
} ;
- if (CPU_CLIPS_NEGATIVE == 0 && scaled_value <= (-8.0 * 0x10000000))
- { dest [count] = 0 ;
+#endif
+#if CPU_CLIPS_NEGATIVE == 0
+ if (scaled_value <= (-8.0 * 0x10000000))
+ { dest [i] = 0 ;
continue ;
} ;
+#endif
- dest [count] = (psf_lrintf (scaled_value) >> 24) + 128 ;
+ dest [i] = (psf_lrintf (scaled_value) >> 24) + 128 ;
} ;
} /* f2uc_clip_array */
{ if (len < bufferlen)
bufferlen = (int) len ;
convert (ptr + total, ubuf.ucbuf, bufferlen, psf->norm_float) ;
- writecount = psf_fwrite (ubuf.ucbuf, sizeof (unsigned char), bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.ucbuf, sizeof (unsigned char), bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
short value ;
normfact = normalize ? (1.0 * 0x7FFF) : 1.0 ;
- ucptr = ((unsigned char*) dest) + 2 * count ;
- while (--count >= 0)
- { ucptr -= 2 ;
- value = psf_lrintf (src [count] * normfact) ;
+ for (int i = 0 ; i < count ; i++)
+ { ucptr = (unsigned char*) &dest [i] ;
+ value = psf_lrintf (src [i] * normfact) ;
ucptr [1] = value ;
ucptr [0] = value >> 8 ;
} ;
int value ;
normfact = normalize ? (8.0 * 0x10000000) : (1.0 * 0x10000) ;
- ucptr = ((unsigned char*) dest) + 2 * count ;
- while (--count >= 0)
- { ucptr -= 2 ;
- scaled_value = src [count] * normfact ;
- if (CPU_CLIPS_POSITIVE == 0 && scaled_value >= (1.0 * 0x7FFFFFFF))
+ for (int i = 0 ; i < count ; i++)
+ { ucptr = (unsigned char*) &dest [i] ;
+ scaled_value = src [i] * normfact ;
+#if CPU_CLIPS_POSITIVE == 0
+ if (scaled_value >= (1.0 * 0x7FFFFFFF))
{ ucptr [1] = 0xFF ;
ucptr [0] = 0x7F ;
continue ;
} ;
- if (CPU_CLIPS_NEGATIVE == 0 && scaled_value <= (-8.0 * 0x10000000))
+#endif
+#if CPU_CLIPS_NEGATIVE == 0
+ if (scaled_value <= (-8.0 * 0x10000000))
{ ucptr [1] = 0x00 ;
ucptr [0] = 0x80 ;
continue ;
} ;
+#endif
value = psf_lrintf (scaled_value) ;
ucptr [1] = value >> 16 ;
{ if (len < bufferlen)
bufferlen = (int) len ;
convert (ptr + total, ubuf.sbuf, bufferlen, psf->norm_float) ;
- writecount = psf_fwrite (ubuf.sbuf, sizeof (short), bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.sbuf, sizeof (short), bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
int value ;
normfact = normalize ? (1.0 * 0x7FFF) : 1.0 ;
- ucptr = ((unsigned char*) dest) + 2 * count ;
- while (--count >= 0)
- { ucptr -= 2 ;
- value = psf_lrintf (src [count] * normfact) ;
+ for (int i = 0 ; i < count ; i++)
+ { ucptr = (unsigned char*) &dest [i] ;
+ value = psf_lrintf (src [i] * normfact) ;
ucptr [0] = value ;
ucptr [1] = value >> 8 ;
} ;
int value ;
normfact = normalize ? (8.0 * 0x10000000) : (1.0 * 0x10000) ;
- ucptr = ((unsigned char*) dest) + 2 * count ;
- while (--count >= 0)
- { ucptr -= 2 ;
- scaled_value = src [count] * normfact ;
- if (CPU_CLIPS_POSITIVE == 0 && scaled_value >= (1.0 * 0x7FFFFFFF))
+ for (int i = 0 ; i < count ; i++)
+ { ucptr = (unsigned char*) &dest [i] ;
+ scaled_value = src [i] * normfact ;
+#if CPU_CLIPS_POSITIVE == 0
+ if (scaled_value >= (1.0 * 0x7FFFFFFF))
{ ucptr [0] = 0xFF ;
ucptr [1] = 0x7F ;
continue ;
} ;
- if (CPU_CLIPS_NEGATIVE == 0 && scaled_value <= (-8.0 * 0x10000000))
+#endif
+#if CPU_CLIPS_NEGATIVE == 0
+ if (scaled_value <= (-8.0 * 0x10000000))
{ ucptr [0] = 0x00 ;
ucptr [1] = 0x80 ;
continue ;
} ;
+#endif
value = psf_lrintf (scaled_value) ;
ucptr [0] = value >> 16 ;
{ if (len < bufferlen)
bufferlen = (int) len ;
convert (ptr + total, ubuf.sbuf, bufferlen, psf->norm_float) ;
- writecount = psf_fwrite (ubuf.sbuf, sizeof (short), bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.sbuf, sizeof (short), bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
normfact = normalize ? (1.0 * 0x7FFFFF) : 1.0 ;
- while (--count >= 0)
- { value = psf_lrintf (src [count] * normfact) ;
- dest [count].bytes [0] = value ;
- dest [count].bytes [1] = value >> 8 ;
- dest [count].bytes [2] = value >> 16 ;
+ for (int i = 0 ; i < count ; i++)
+ { value = psf_lrintf (src [i] * normfact) ;
+ dest [i].bytes [0] = value ;
+ dest [i].bytes [1] = value >> 8 ;
+ dest [i].bytes [2] = value >> 16 ;
} ;
} /* f2let_array */
normfact = normalize ? (8.0 * 0x10000000) : (1.0 * 0x100) ;
- while (--count >= 0)
- { scaled_value = src [count] * normfact ;
- if (CPU_CLIPS_POSITIVE == 0 && scaled_value >= (1.0 * 0x7FFFFFFF))
- { dest [count].bytes [0] = 0xFF ;
- dest [count].bytes [1] = 0xFF ;
- dest [count].bytes [2] = 0x7F ;
+ for (int i = 0 ; i < count ; i++)
+ { scaled_value = src [i] * normfact ;
+#if CPU_CLIPS_POSITIVE == 0
+ if (scaled_value >= (1.0 * 0x7FFFFFFF))
+ { dest [i].bytes [0] = 0xFF ;
+ dest [i].bytes [1] = 0xFF ;
+ dest [i].bytes [2] = 0x7F ;
continue ;
} ;
- if (CPU_CLIPS_NEGATIVE == 0 && scaled_value <= (-8.0 * 0x10000000))
- { dest [count].bytes [0] = 0x00 ;
- dest [count].bytes [1] = 0x00 ;
- dest [count].bytes [2] = 0x80 ;
+#endif
+#if CPU_CLIPS_NEGATIVE == 0
+ if (scaled_value <= (-8.0 * 0x10000000))
+ { dest [i].bytes [0] = 0x00 ;
+ dest [i].bytes [1] = 0x00 ;
+ dest [i].bytes [2] = 0x80 ;
continue ;
} ;
+#endif
value = psf_lrintf (scaled_value) ;
- dest [count].bytes [0] = value >> 8 ;
- dest [count].bytes [1] = value >> 16 ;
- dest [count].bytes [2] = value >> 24 ;
+ dest [i].bytes [0] = value >> 8 ;
+ dest [i].bytes [1] = value >> 16 ;
+ dest [i].bytes [2] = value >> 24 ;
} ;
} /* f2let_clip_array */
{ if (len < bufferlen)
bufferlen = (int) len ;
convert (ptr + total, (tribyte*) (ubuf.ucbuf), bufferlen, psf->norm_float) ;
- writecount = psf_fwrite (ubuf.ucbuf, SIZEOF_TRIBYTE, bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.ucbuf, SIZEOF_TRIBYTE, bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
normfact = normalize ? (1.0 * 0x7FFFFF) : 1.0 ;
- while (--count >= 0)
- { value = psf_lrintf (src [count] * normfact) ;
- dest [count].bytes [0] = value >> 16 ;
- dest [count].bytes [1] = value >> 8 ;
- dest [count].bytes [2] = value ;
+ for (int i = 0 ; i < count ; i++)
+ { value = psf_lrintf (src [i] * normfact) ;
+ dest [i].bytes [0] = value >> 16 ;
+ dest [i].bytes [1] = value >> 8 ;
+ dest [i].bytes [2] = value ;
} ;
} /* f2bet_array */
normfact = normalize ? (8.0 * 0x10000000) : (1.0 * 0x100) ;
- while (--count >= 0)
- { scaled_value = src [count] * normfact ;
- if (CPU_CLIPS_POSITIVE == 0 && scaled_value >= (1.0 * 0x7FFFFFFF))
- { dest [count].bytes [0] = 0x7F ;
- dest [count].bytes [1] = 0xFF ;
- dest [count].bytes [2] = 0xFF ;
+ for (int i = 0 ; i < count ; i++)
+ { scaled_value = src [i] * normfact ;
+#if CPU_CLIPS_POSITIVE == 0
+ if (scaled_value >= (1.0 * 0x7FFFFFFF))
+ { dest [i].bytes [0] = 0x7F ;
+ dest [i].bytes [1] = 0xFF ;
+ dest [i].bytes [2] = 0xFF ;
continue ;
} ;
- if (CPU_CLIPS_NEGATIVE == 0 && scaled_value <= (-8.0 * 0x10000000))
- { dest [count].bytes [0] = 0x80 ;
- dest [count].bytes [1] = 0x00 ;
- dest [count].bytes [2] = 0x00 ;
+#endif
+#if CPU_CLIPS_NEGATIVE == 0
+ if (scaled_value <= (-8.0 * 0x10000000))
+ { dest [i].bytes [0] = 0x80 ;
+ dest [i].bytes [1] = 0x00 ;
+ dest [i].bytes [2] = 0x00 ;
continue ;
} ;
+#endif
value = psf_lrint (scaled_value) ;
- dest [count].bytes [0] = value >> 24 ;
- dest [count].bytes [1] = value >> 16 ;
- dest [count].bytes [2] = value >> 8 ;
+ dest [i].bytes [0] = value >> 24 ;
+ dest [i].bytes [1] = value >> 16 ;
+ dest [i].bytes [2] = value >> 8 ;
} ;
} /* f2bet_clip_array */
{ if (len < bufferlen)
bufferlen = (int) len ;
convert (ptr + total, (tribyte*) (ubuf.ucbuf), bufferlen, psf->norm_float) ;
- writecount = psf_fwrite (ubuf.ucbuf, SIZEOF_TRIBYTE, bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.ucbuf, SIZEOF_TRIBYTE, bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
int value ;
normfact = normalize ? (1.0 * 0x7FFFFFFF) : 1.0 ;
- ucptr = ((unsigned char*) dest) + 4 * count ;
- while (--count >= 0)
- { ucptr -= 4 ;
- value = psf_lrintf (src [count] * normfact) ;
+
+ for (int i = 0 ; i < count ; i++)
+ { ucptr = (unsigned char*) &dest [i] ;
+ value = psf_lrintf (src [i] * normfact) ;
ucptr [0] = value >> 24 ;
ucptr [1] = value >> 16 ;
ucptr [2] = value >> 8 ;
int value ;
normfact = normalize ? (8.0 * 0x10000000) : 1.0 ;
- ucptr = ((unsigned char*) dest) + 4 * count ;
- while (--count >= 0)
- { ucptr -= 4 ;
- scaled_value = src [count] * normfact ;
- if (CPU_CLIPS_POSITIVE == 0 && scaled_value >= 1.0 * 0x7FFFFFFF)
+ for (int i = 0 ; i < count ; i++)
+ { ucptr = (unsigned char*) &dest [i] ;
+ scaled_value = src [i] * normfact ;
+#if CPU_CLIPS_POSITIVE == 0
+ if (scaled_value >= 1.0 * 0x7FFFFFFF)
{ ucptr [0] = 0x7F ;
ucptr [1] = 0xFF ;
ucptr [2] = 0xFF ;
ucptr [3] = 0xFF ;
continue ;
} ;
- if (CPU_CLIPS_NEGATIVE == 0 && scaled_value <= (-8.0 * 0x10000000))
+#endif
+#if CPU_CLIPS_NEGATIVE == 0
+ if (scaled_value <= (-8.0 * 0x10000000))
{ ucptr [0] = 0x80 ;
ucptr [1] = 0x00 ;
ucptr [2] = 0x00 ;
ucptr [3] = 0x00 ;
continue ;
} ;
+#endif
value = psf_lrintf (scaled_value) ;
ucptr [0] = value >> 24 ;
{ if (len < bufferlen)
bufferlen = (int) len ;
convert (ptr + total, ubuf.ibuf, bufferlen, psf->norm_float) ;
- writecount = psf_fwrite (ubuf.ibuf, sizeof (int), bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.ibuf, sizeof (int), bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
int value ;
normfact = normalize ? (1.0 * 0x7FFFFFFF) : 1.0 ;
- ucptr = ((unsigned char*) dest) + 4 * count ;
- while (--count >= 0)
- { ucptr -= 4 ;
- value = psf_lrintf (src [count] * normfact) ;
+ for (int i = 0 ; i < count ; i++)
+ { ucptr = (unsigned char*) &dest [i] ;
+ value = psf_lrintf (src [i] * normfact) ;
ucptr [0] = value ;
ucptr [1] = value >> 8 ;
ucptr [2] = value >> 16 ;
int value ;
normfact = normalize ? (8.0 * 0x10000000) : 1.0 ;
- ucptr = ((unsigned char*) dest) + 4 * count ;
- while (--count >= 0)
- { ucptr -= 4 ;
- scaled_value = src [count] * normfact ;
- if (CPU_CLIPS_POSITIVE == 0 && scaled_value >= (1.0 * 0x7FFFFFFF))
+ for (int i = 0 ; i < count ; i++)
+ { ucptr = (unsigned char*) &dest [i] ;
+ scaled_value = src [i] * normfact ;
+#if CPU_CLIPS_POSITIVE == 0
+ if (scaled_value >= (1.0 * 0x7FFFFFFF))
{ ucptr [0] = 0xFF ;
ucptr [1] = 0xFF ;
ucptr [2] = 0xFF ;
ucptr [3] = 0x7F ;
continue ;
} ;
- if (CPU_CLIPS_NEGATIVE == 0 && scaled_value <= (-8.0 * 0x10000000))
+#endif
+#if CPU_CLIPS_NEGATIVE == 0
+ if (scaled_value <= (-8.0 * 0x10000000))
{ ucptr [0] = 0x00 ;
ucptr [1] = 0x00 ;
ucptr [2] = 0x00 ;
ucptr [3] = 0x80 ;
continue ;
} ;
+#endif
value = psf_lrintf (scaled_value) ;
ucptr [0] = value ;
{ if (len < bufferlen)
bufferlen = (int) len ;
convert (ptr + total, ubuf.ibuf, bufferlen, psf->norm_float) ;
- writecount = psf_fwrite (ubuf.ibuf, sizeof (int), bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.ibuf, sizeof (int), bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
normfact = normalize ? (1.0 * 0x7F) : 1.0 ;
- while (--count >= 0)
- { dest [count] = psf_lrint (src [count] * normfact) ;
+ for (int i = 0 ; i < count ; i++)
+ { dest [i] = psf_lrint (src [i] * normfact) ;
} ;
} /* d2sc_array */
normfact = normalize ? (8.0 * 0x10000000) : (1.0 * 0x1000000) ;
- while (--count >= 0)
- { scaled_value = src [count] * normfact ;
- if (CPU_CLIPS_POSITIVE == 0 && scaled_value >= (1.0 * 0x7FFFFFFF))
- { dest [count] = 127 ;
+ for (int i = 0 ; i < count ; i++)
+ { scaled_value = src [i] * normfact ;
+#if CPU_CLIPS_POSITIVE == 0
+ if (scaled_value >= (1.0 * 0x7FFFFFFF))
+ { dest [i] = 127 ;
continue ;
} ;
- if (CPU_CLIPS_NEGATIVE == 0 && scaled_value <= (-8.0 * 0x10000000))
- { dest [count] = -128 ;
+#endif
+#if CPU_CLIPS_NEGATIVE == 0
+ if (scaled_value <= (-8.0 * 0x10000000))
+ { dest [i] = -128 ;
continue ;
} ;
+#endif
- dest [count] = psf_lrintf (scaled_value) >> 24 ;
+ dest [i] = psf_lrintf (scaled_value) >> 24 ;
} ;
} /* d2sc_clip_array */
{ if (len < bufferlen)
bufferlen = (int) len ;
convert (ptr + total, ubuf.scbuf, bufferlen, psf->norm_double) ;
- writecount = psf_fwrite (ubuf.scbuf, sizeof (signed char), bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.scbuf, sizeof (signed char), bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
normfact = normalize ? (1.0 * 0x7F) : 1.0 ;
- while (--count >= 0)
- { dest [count] = psf_lrint (src [count] * normfact) + 128 ;
+ for (int i = 0 ; i < count ; i++)
+ { dest [i] = psf_lrint (src [i] * normfact) + 128 ;
} ;
} /* d2uc_array */
normfact = normalize ? (8.0 * 0x10000000) : (1.0 * 0x1000000) ;
- while (--count >= 0)
- { scaled_value = src [count] * normfact ;
- if (CPU_CLIPS_POSITIVE == 0 && scaled_value >= (1.0 * 0x7FFFFFFF))
- { dest [count] = 255 ;
+ for (int i = 0 ; i < count ; i++)
+ { scaled_value = src [i] * normfact ;
+#if CPU_CLIPS_POSITIVE == 0
+ if (scaled_value >= (1.0 * 0x7FFFFFFF))
+ { dest [i] = 255 ;
continue ;
} ;
- if (CPU_CLIPS_NEGATIVE == 0 && scaled_value <= (-8.0 * 0x10000000))
- { dest [count] = 0 ;
+#endif
+#if CPU_CLIPS_NEGATIVE == 0
+ if (scaled_value <= (-8.0 * 0x10000000))
+ { dest [i] = 0 ;
continue ;
} ;
+#endif
- dest [count] = (psf_lrint (src [count] * normfact) >> 24) + 128 ;
+ dest [i] = (psf_lrint (src [i] * normfact) >> 24) + 128 ;
} ;
} /* d2uc_clip_array */
{ if (len < bufferlen)
bufferlen = (int) len ;
convert (ptr + total, ubuf.ucbuf, bufferlen, psf->norm_double) ;
- writecount = psf_fwrite (ubuf.ucbuf, sizeof (unsigned char), bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.ucbuf, sizeof (unsigned char), bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
double normfact ;
normfact = normalize ? (1.0 * 0x7FFF) : 1.0 ;
- ucptr = ((unsigned char*) dest) + 2 * count ;
- while (--count >= 0)
- { ucptr -= 2 ;
- value = psf_lrint (src [count] * normfact) ;
+ for (int i = 0 ; i < count ; i++)
+ { ucptr = (unsigned char*) &dest [i] ;
+ value = psf_lrint (src [i] * normfact) ;
ucptr [1] = value ;
ucptr [0] = value >> 8 ;
} ;
int value ;
normfact = normalize ? (8.0 * 0x10000000) : (1.0 * 0x10000) ;
- ucptr = ((unsigned char*) dest) + 2 * count ;
- while (--count >= 0)
- { ucptr -= 2 ;
- scaled_value = src [count] * normfact ;
- if (CPU_CLIPS_POSITIVE == 0 && scaled_value >= (1.0 * 0x7FFFFFFF))
+ for (int i = 0 ; i < count ; i++)
+ { ucptr = (unsigned char*) &dest [i] ;
+ scaled_value = src [i] * normfact ;
+#if CPU_CLIPS_POSITIVE == 0
+ if (scaled_value >= (1.0 * 0x7FFFFFFF))
{ ucptr [1] = 0xFF ;
ucptr [0] = 0x7F ;
continue ;
} ;
- if (CPU_CLIPS_NEGATIVE == 0 && scaled_value <= (-8.0 * 0x10000000))
+#endif
+#if CPU_CLIPS_NEGATIVE == 0
+ if (scaled_value <= (-8.0 * 0x10000000))
{ ucptr [1] = 0x00 ;
ucptr [0] = 0x80 ;
continue ;
} ;
+#endif
value = psf_lrint (scaled_value) ;
ucptr [1] = value >> 16 ;
{ if (len < bufferlen)
bufferlen = (int) len ;
convert (ptr + total, ubuf.sbuf, bufferlen, psf->norm_double) ;
- writecount = psf_fwrite (ubuf.sbuf, sizeof (short), bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.sbuf, sizeof (short), bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
double normfact ;
normfact = normalize ? (1.0 * 0x7FFF) : 1.0 ;
- ucptr = ((unsigned char*) dest) + 2 * count ;
- while (--count >= 0)
- { ucptr -= 2 ;
- value = psf_lrint (src [count] * normfact) ;
+ for (int i = 0 ; i < count ; i++)
+ { ucptr = (unsigned char*) &dest [i] ;
+ value = psf_lrint (src [i] * normfact) ;
ucptr [0] = value ;
ucptr [1] = value >> 8 ;
} ;
double normfact, scaled_value ;
normfact = normalize ? (8.0 * 0x10000000) : (1.0 * 0x10000) ;
- ucptr = ((unsigned char*) dest) + 2 * count ;
- while (--count >= 0)
- { ucptr -= 2 ;
- scaled_value = src [count] * normfact ;
- if (CPU_CLIPS_POSITIVE == 0 && scaled_value >= (1.0 * 0x7FFFFFFF))
+ for (int i = 0 ; i < count ; i++)
+ { ucptr = (unsigned char*) &dest [i] ;
+ scaled_value = src [i] * normfact ;
+#if CPU_CLIPS_POSITIVE == 0
+ if (scaled_value >= (1.0 * 0x7FFFFFFF))
{ ucptr [0] = 0xFF ;
ucptr [1] = 0x7F ;
continue ;
} ;
- if (CPU_CLIPS_NEGATIVE == 0 && scaled_value <= (-8.0 * 0x10000000))
+#endif
+#if CPU_CLIPS_NEGATIVE == 0
+ if (scaled_value <= (-8.0 * 0x10000000))
{ ucptr [0] = 0x00 ;
ucptr [1] = 0x80 ;
continue ;
} ;
+#endif
value = psf_lrint (scaled_value) ;
ucptr [0] = value >> 16 ;
{ if (len < bufferlen)
bufferlen = (int) len ;
convert (ptr + total, ubuf.sbuf, bufferlen, psf->norm_double) ;
- writecount = psf_fwrite (ubuf.sbuf, sizeof (short), bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.sbuf, sizeof (short), bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
normfact = normalize ? (1.0 * 0x7FFFFF) : 1.0 ;
- while (--count >= 0)
- { value = psf_lrint (src [count] * normfact) ;
- dest [count].bytes [0] = value ;
- dest [count].bytes [1] = value >> 8 ;
- dest [count].bytes [2] = value >> 16 ;
+ for (int i = 0 ; i < count ; i++)
+ { value = psf_lrint (src [i] * normfact) ;
+ dest [i].bytes [0] = value ;
+ dest [i].bytes [1] = value >> 8 ;
+ dest [i].bytes [2] = value >> 16 ;
} ;
} /* d2let_array */
normfact = normalize ? (8.0 * 0x10000000) : (1.0 * 0x100) ;
- while (--count >= 0)
- { scaled_value = src [count] * normfact ;
- if (CPU_CLIPS_POSITIVE == 0 && scaled_value >= (1.0 * 0x7FFFFFFF))
- { dest [count].bytes [0] = 0xFF ;
- dest [count].bytes [1] = 0xFF ;
- dest [count].bytes [2] = 0x7F ;
+ for (int i = 0 ; i < count ; i++)
+ { scaled_value = src [i] * normfact ;
+#if CPU_CLIPS_POSITIVE == 0
+ if (scaled_value >= (1.0 * 0x7FFFFFFF))
+ { dest [i].bytes [0] = 0xFF ;
+ dest [i].bytes [1] = 0xFF ;
+ dest [i].bytes [2] = 0x7F ;
continue ;
} ;
- if (CPU_CLIPS_NEGATIVE == 0 && scaled_value <= (-8.0 * 0x10000000))
- { dest [count].bytes [0] = 0x00 ;
- dest [count].bytes [1] = 0x00 ;
- dest [count].bytes [2] = 0x80 ;
+#endif
+#if CPU_CLIPS_NEGATIVE == 0
+ if (scaled_value <= (-8.0 * 0x10000000))
+ { dest [i].bytes [0] = 0x00 ;
+ dest [i].bytes [1] = 0x00 ;
+ dest [i].bytes [2] = 0x80 ;
continue ;
} ;
+#endif
value = psf_lrint (scaled_value) ;
- dest [count].bytes [0] = value >> 8 ;
- dest [count].bytes [1] = value >> 16 ;
- dest [count].bytes [2] = value >> 24 ;
+ dest [i].bytes [0] = value >> 8 ;
+ dest [i].bytes [1] = value >> 16 ;
+ dest [i].bytes [2] = value >> 24 ;
} ;
} /* d2let_clip_array */
{ if (len < bufferlen)
bufferlen = (int) len ;
convert (ptr + total, (tribyte*) (ubuf.ucbuf), bufferlen, psf->norm_double) ;
- writecount = psf_fwrite (ubuf.ucbuf, SIZEOF_TRIBYTE, bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.ucbuf, SIZEOF_TRIBYTE, bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
normfact = normalize ? (1.0 * 0x7FFFFF) : 1.0 ;
- while (--count >= 0)
- { value = psf_lrint (src [count] * normfact) ;
- dest [count].bytes [2] = value ;
- dest [count].bytes [1] = value >> 8 ;
- dest [count].bytes [0] = value >> 16 ;
+ for (int i = 0 ; i < count ; i++)
+ { value = psf_lrint (src [i] * normfact) ;
+ dest [i].bytes [2] = value ;
+ dest [i].bytes [1] = value >> 8 ;
+ dest [i].bytes [0] = value >> 16 ;
} ;
} /* d2bet_array */
normfact = normalize ? (8.0 * 0x10000000) : (1.0 * 0x100) ;
- while (--count >= 0)
- { scaled_value = src [count] * normfact ;
- if (CPU_CLIPS_POSITIVE == 0 && scaled_value >= (1.0 * 0x7FFFFFFF))
- { dest [count].bytes [2] = 0xFF ;
- dest [count].bytes [1] = 0xFF ;
- dest [count].bytes [0] = 0x7F ;
+ for (int i = 0 ; i < count ; i++)
+ { scaled_value = src [i] * normfact ;
+#if CPU_CLIPS_POSITIVE == 0
+ if (scaled_value >= (1.0 * 0x7FFFFFFF))
+ { dest [i].bytes [2] = 0xFF ;
+ dest [i].bytes [1] = 0xFF ;
+ dest [i].bytes [0] = 0x7F ;
continue ;
} ;
- if (CPU_CLIPS_NEGATIVE == 0 && scaled_value <= (-8.0 * 0x10000000))
- { dest [count].bytes [2] = 0x00 ;
- dest [count].bytes [1] = 0x00 ;
- dest [count].bytes [0] = 0x80 ;
+#endif
+#if CPU_CLIPS_NEGATIVE == 0
+ if (scaled_value <= (-8.0 * 0x10000000))
+ { dest [i].bytes [2] = 0x00 ;
+ dest [i].bytes [1] = 0x00 ;
+ dest [i].bytes [0] = 0x80 ;
continue ;
} ;
+#endif
value = psf_lrint (scaled_value) ;
- dest [count].bytes [2] = value >> 8 ;
- dest [count].bytes [1] = value >> 16 ;
- dest [count].bytes [0] = value >> 24 ;
+ dest [i].bytes [2] = value >> 8 ;
+ dest [i].bytes [1] = value >> 16 ;
+ dest [i].bytes [0] = value >> 24 ;
} ;
} /* d2bet_clip_array */
{ if (len < bufferlen)
bufferlen = (int) len ;
convert (ptr + total, (tribyte*) (ubuf.ucbuf), bufferlen, psf->norm_double) ;
- writecount = psf_fwrite (ubuf.ucbuf, SIZEOF_TRIBYTE, bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.ucbuf, SIZEOF_TRIBYTE, bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
double normfact ;
normfact = normalize ? (1.0 * 0x7FFFFFFF) : 1.0 ;
- ucptr = ((unsigned char*) dest) + 4 * count ;
- while (--count >= 0)
- { ucptr -= 4 ;
- value = psf_lrint (src [count] * normfact) ;
+ for (int i = 0 ; i < count ; i++)
+ { ucptr = (unsigned char*) &dest [i] ;
+ value = psf_lrint (src [i] * normfact) ;
ucptr [0] = value >> 24 ;
ucptr [1] = value >> 16 ;
ucptr [2] = value >> 8 ;
double normfact, scaled_value ;
normfact = normalize ? (8.0 * 0x10000000) : 1.0 ;
- ucptr = ((unsigned char*) dest) + 4 * count ;
- while (--count >= 0)
- { ucptr -= 4 ;
- scaled_value = src [count] * normfact ;
- if (CPU_CLIPS_POSITIVE == 0 && scaled_value >= (1.0 * 0x7FFFFFFF))
+ for (int i = 0 ; i < count ; i++)
+ { ucptr = (unsigned char*) &dest [i] ;
+ scaled_value = src [i] * normfact ;
+#if CPU_CLIPS_POSITIVE == 0
+ if (scaled_value >= (1.0 * 0x7FFFFFFF))
{ ucptr [3] = 0xFF ;
ucptr [2] = 0xFF ;
ucptr [1] = 0xFF ;
ucptr [0] = 0x7F ;
continue ;
} ;
- if (CPU_CLIPS_NEGATIVE == 0 && scaled_value <= (-8.0 * 0x10000000))
+#endif
+#if CPU_CLIPS_NEGATIVE == 0
+ if (scaled_value <= (-8.0 * 0x10000000))
{ ucptr [3] = 0x00 ;
ucptr [2] = 0x00 ;
ucptr [1] = 0x00 ;
ucptr [0] = 0x80 ;
continue ;
} ;
+#endif
value = psf_lrint (scaled_value) ;
ucptr [0] = value >> 24 ;
{ if (len < bufferlen)
bufferlen = (int) len ;
convert (ptr + total, ubuf.ibuf, bufferlen, psf->norm_double) ;
- writecount = psf_fwrite (ubuf.ibuf, sizeof (int), bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.ibuf, sizeof (int), bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
double normfact ;
normfact = normalize ? (1.0 * 0x7FFFFFFF) : 1.0 ;
- ucptr = ((unsigned char*) dest) + 4 * count ;
- while (--count >= 0)
- { ucptr -= 4 ;
- value = psf_lrint (src [count] * normfact) ;
+ for (int i = 0 ; i < count ; i++)
+ { ucptr = (unsigned char*) &dest [i] ;
+ value = psf_lrint (src [i] * normfact) ;
ucptr [0] = value ;
ucptr [1] = value >> 8 ;
ucptr [2] = value >> 16 ;
double normfact, scaled_value ;
normfact = normalize ? (8.0 * 0x10000000) : 1.0 ;
- ucptr = ((unsigned char*) dest) + 4 * count ;
- while (--count >= 0)
- { ucptr -= 4 ;
- scaled_value = src [count] * normfact ;
- if (CPU_CLIPS_POSITIVE == 0 && scaled_value >= (1.0 * 0x7FFFFFFF))
+ for (int i = 0 ; i < count ; i++)
+ { ucptr = (unsigned char*) &dest [i] ;
+ scaled_value = src [i] * normfact ;
+#if CPU_CLIPS_POSITIVE == 0
+ if (scaled_value >= (1.0 * 0x7FFFFFFF))
{ ucptr [0] = 0xFF ;
ucptr [1] = 0xFF ;
ucptr [2] = 0xFF ;
ucptr [3] = 0x7F ;
continue ;
} ;
- if (CPU_CLIPS_NEGATIVE == 0 && scaled_value <= (-8.0 * 0x10000000))
+#endif
+#if CPU_CLIPS_NEGATIVE == 0
+ if (scaled_value <= (-8.0 * 0x10000000))
{ ucptr [0] = 0x00 ;
ucptr [1] = 0x00 ;
ucptr [2] = 0x00 ;
ucptr [3] = 0x80 ;
continue ;
} ;
+#endif
value = psf_lrint (scaled_value) ;
ucptr [0] = value ;
{ if (len < bufferlen)
bufferlen = (int) len ;
convert (ptr + total, ubuf.ibuf, bufferlen, psf->norm_double) ;
- writecount = psf_fwrite (ubuf.ibuf, sizeof (int), bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.ibuf, sizeof (int), bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
else
psf_log_printf (psf, "%M : 0x%x (should be 0xFFFFFFFF)\n %M\n", RF64_MARKER, WAVE_MARKER) ;
- while (NOT (done))
+ while (!done)
{
marker = chunk_size = 0 ;
psf_binheader_readf (psf, "em4", &marker, &chunk_size) ;
if (psf->datalength + psf->dataoffset < psf->filelength)
psf->dataend = psf->datalength + psf->dataoffset ;
- if (NOT (psf->sf.seekable) || psf->dataoffset < 0)
+ if (!psf->sf.seekable || psf->dataoffset < 0)
break ;
/* Seek past data and continue reading header. */
psf->dataoffset = psf->header.indx ;
- if (NOT (has_data))
+ if (!has_data)
psf_fseek (psf, psf->dataoffset, SEEK_SET) ;
else if (current > 0)
psf_fseek (psf, current, SEEK_SET) ;
/* Very start of resource fork. */
psf_binheader_writef (psf, "E444", BHW4 (rsrc.data_offset), BHW4 (rsrc.map_offset), BHW4 (rsrc.data_length)) ;
- psf_binheader_writef (psf, "Eop", BHWo (0x30), BHWp (psf->file.name.c)) ;
+ psf_binheader_writef (psf, "Eop", BHWo (0x30), BHWp (psf->file.name)) ;
psf_binheader_writef (psf, "Eo2mm", BHWo (0x50), BHW2 (0), BHWm (Sd2f_MARKER), BHWm (lsf1_MARKER)) ;
/* Very start of resource map. */
for (blockcount = 0 ; bytesread < psf->filelength ; blockcount++)
{
- bytesread += psf_fread (&marker, 1, 2, psf) ;
+ bytesread += (int) psf_fread (&marker, 1, 2, psf) ;
if (marker == 0)
break ;
return 1 ;
} ;
- if ((k = psf_fread (psds->read_data, 1, SDS_BLOCK_SIZE, psf)) != SDS_BLOCK_SIZE)
+ if ((k = (int) psf_fread (psds->read_data, 1, SDS_BLOCK_SIZE, psf)) != SDS_BLOCK_SIZE)
psf_log_printf (psf, "*** Warning : short read (%d != %d).\n", k, SDS_BLOCK_SIZE) ;
if (psds->read_data [0] != 0xF0)
return 1 ;
} ;
- if ((k = psf_fread (psds->read_data, 1, SDS_BLOCK_SIZE, psf)) != SDS_BLOCK_SIZE)
+ if ((k = (int) psf_fread (psds->read_data, 1, SDS_BLOCK_SIZE, psf)) != SDS_BLOCK_SIZE)
psf_log_printf (psf, "*** Warning : short read (%d != %d).\n", k, SDS_BLOCK_SIZE) ;
if (psds->read_data [0] != 0xF0)
return 1 ;
} ;
- if ((k = psf_fread (psds->read_data, 1, SDS_BLOCK_SIZE, psf)) != SDS_BLOCK_SIZE)
+ if ((k = (int) psf_fread (psds->read_data, 1, SDS_BLOCK_SIZE, psf)) != SDS_BLOCK_SIZE)
psf_log_printf (psf, "*** Warning : short read (%d != %d).\n", k, SDS_BLOCK_SIZE) ;
if (psds->read_data [0] != 0xF0)
iptr = ubuf.ibuf ;
bufferlen = ARRAY_LEN (ubuf.ibuf) ;
while (len > 0)
- { readcount = (len >= bufferlen) ? bufferlen : len ;
+ { readcount = (len >= bufferlen) ? bufferlen : (int) len ;
count = sds_read (psf, psds, iptr, readcount) ;
for (k = 0 ; k < readcount ; k++)
ptr [total + k] = iptr [k] >> 16 ;
iptr = ubuf.ibuf ;
bufferlen = ARRAY_LEN (ubuf.ibuf) ;
while (len > 0)
- { readcount = (len >= bufferlen) ? bufferlen : len ;
+ { readcount = (len >= bufferlen) ? bufferlen : (int) len ;
count = sds_read (psf, psds, iptr, readcount) ;
for (k = 0 ; k < readcount ; k++)
ptr [total + k] = normfact * iptr [k] ;
iptr = ubuf.ibuf ;
bufferlen = ARRAY_LEN (ubuf.ibuf) ;
while (len > 0)
- { readcount = (len >= bufferlen) ? bufferlen : len ;
+ { readcount = (len >= bufferlen) ? bufferlen : (int) len ;
count = sds_read (psf, psds, iptr, readcount) ;
for (k = 0 ; k < readcount ; k++)
ptr [total + k] = normfact * iptr [k] ;
psds->write_data [SDS_BLOCK_SIZE - 2] = checksum ;
psds->write_data [SDS_BLOCK_SIZE - 1] = 0xF7 ;
- if ((k = psf_fwrite (psds->write_data, 1, SDS_BLOCK_SIZE, psf)) != SDS_BLOCK_SIZE)
+ if ((k = (int) psf_fwrite (psds->write_data, 1, SDS_BLOCK_SIZE, psf)) != SDS_BLOCK_SIZE)
psf_log_printf (psf, "*** Warning : psf_fwrite (%d != %d).\n", k, SDS_BLOCK_SIZE) ;
psds->write_block ++ ;
psds->write_data [SDS_BLOCK_SIZE - 2] = checksum ;
psds->write_data [SDS_BLOCK_SIZE - 1] = 0xF7 ;
- if ((k = psf_fwrite (psds->write_data, 1, SDS_BLOCK_SIZE, psf)) != SDS_BLOCK_SIZE)
+ if ((k = (int) psf_fwrite (psds->write_data, 1, SDS_BLOCK_SIZE, psf)) != SDS_BLOCK_SIZE)
psf_log_printf (psf, "*** Warning : psf_fwrite (%d != %d).\n", k, SDS_BLOCK_SIZE) ;
psds->write_block ++ ;
psds->write_data [SDS_BLOCK_SIZE - 2] = checksum ;
psds->write_data [SDS_BLOCK_SIZE - 1] = 0xF7 ;
- if ((k = psf_fwrite (psds->write_data, 1, SDS_BLOCK_SIZE, psf)) != SDS_BLOCK_SIZE)
+ if ((k = (int) psf_fwrite (psds->write_data, 1, SDS_BLOCK_SIZE, psf)) != SDS_BLOCK_SIZE)
psf_log_printf (psf, "*** Warning : psf_fwrite (%d != %d).\n", k, SDS_BLOCK_SIZE) ;
psds->write_block ++ ;
iptr = ubuf.ibuf ;
bufferlen = ARRAY_LEN (ubuf.ibuf) ;
while (len > 0)
- { writecount = (len >= bufferlen) ? bufferlen : len ;
+ { writecount = (len >= bufferlen) ? bufferlen : (int) len ;
for (k = 0 ; k < writecount ; k++)
iptr [k] = arith_shift_left (ptr [total + k], 16) ;
count = sds_write (psf, psds, iptr, writecount) ;
iptr = ubuf.ibuf ;
bufferlen = ARRAY_LEN (ubuf.ibuf) ;
while (len > 0)
- { writecount = (len >= bufferlen) ? bufferlen : len ;
+ { writecount = (len >= bufferlen) ? bufferlen : (int) len ;
for (k = 0 ; k < writecount ; k++)
iptr [k] = normfact * ptr [total + k] ;
count = sds_write (psf, psds, iptr, writecount) ;
iptr = ubuf.ibuf ;
bufferlen = ARRAY_LEN (ubuf.ibuf) ;
while (len > 0)
- { writecount = (len >= bufferlen) ? bufferlen : len ;
+ { writecount = (len >= bufferlen) ? bufferlen : (int) len ;
for (k = 0 ; k < writecount ; k++)
iptr [k] = normfact * ptr [total + k] ;
count = sds_write (psf, psds, iptr, writecount) ;
#include <stdint.h>
#include <inttypes.h>
+#ifndef __has_builtin
+#define __has_builtin(x) 0
+#endif
+
#if HAVE_BYTESWAP_H /* Linux, any CPU */
#include <byteswap.h>
#define ENDSWAP_32(x) (bswap_32 (x))
#define ENDSWAP_64(x) (bswap_64 (x))
-#elif defined __has_builtin
+#elif __has_builtin(__builtin_bswap16) && __has_builtin(__builtin_bswap32) && __has_builtin(__builtin_bswap64)
-#if __has_builtin (__builtin_bswap16)
#define ENDSWAP_16(x) ((int16_t) __builtin_bswap16 ((uint16_t) x))
-#endif
-
-#if __has_builtin (__builtin_bswap32)
#define ENDSWAP_32(x) ((int32_t) __builtin_bswap32 ((uint32_t) x))
-#endif
-
-#if __has_builtin (__builtin_bswap64)
#define ENDSWAP_64(x) ((int64_t) __builtin_bswap64 ((uint64_t) x))
-#endif
#elif COMPILER_IS_GCC
psf_get_be64 (const uint8_t *ptr, int offset)
{ int64_t value ;
- value = ((uint32_t) ptr [offset]) << 24 ;
- value += ptr [offset + 1] << 16 ;
- value += ptr [offset + 2] << 8 ;
+ value = (int64_t) ((uint64_t) ptr [offset] << 24) ;
+ value += (int64_t) ((uint64_t) ptr [offset + 1] << 16) ;
+ value += (int64_t) ((uint64_t) ptr [offset + 2] << 8) ;
value += ptr [offset + 3] ;
value = (int64_t) (((uint64_t) value) << 32) ;
- value += ((uint32_t) ptr [offset + 4]) << 24 ;
- value += ptr [offset + 5] << 16 ;
- value += ptr [offset + 6] << 8 ;
+ value += (int64_t) ((uint64_t) ptr [offset + 4] << 24) ;
+ value += (int64_t) ((uint64_t) ptr [offset + 5] << 16) ;
+ value += (int64_t) ((uint64_t) ptr [offset + 6] << 8) ;
value += ptr [offset + 7] ;
return value ;
} /* psf_get_be64 */
static inline int64_t
psf_get_le64 (const uint8_t *ptr, int offset)
-{ int64_t value ;
-
- value = ((uint32_t) ptr [offset + 7]) << 24 ;
- value += ptr [offset + 6] << 16 ;
- value += ptr [offset + 5] << 8 ;
+{ int64_t value = (int64_t) ((uint64_t) ptr [offset + 7] << 24) ;
+ value += (int64_t) ((uint64_t) ptr [offset + 6] << 16) ;
+ value += (int64_t) ((uint64_t) ptr [offset + 5] << 8) ;
value += ptr [offset + 4] ;
value = (int64_t) (((uint64_t) value) << 32) ;
- value += ((uint32_t) ptr [offset + 3]) << 24 ;
- value += ptr [offset + 2] << 16 ;
- value += ptr [offset + 1] << 8 ;
+ value += (int64_t) ((uint64_t) ptr [offset + 3] << 24) ;
+ value += (int64_t) ((uint64_t) ptr [offset + 2] << 16) ;
+ value += (int64_t) ((uint64_t) ptr [offset + 1] << 8) ;
value += ptr [offset] ;
return value ;
} /* psf_get_le64 */
static inline int32_t
psf_get_be32 (const uint8_t *ptr, int offset)
-{ int32_t value ;
-
- value = ((uint32_t) ptr [offset]) << 24 ;
+{ int32_t value = ((uint32_t) ptr [offset]) << 24 ;
value += ptr [offset + 1] << 16 ;
value += ptr [offset + 2] << 8 ;
value += ptr [offset + 3] ;
static inline int32_t
psf_get_le32 (const uint8_t *ptr, int offset)
-{ int32_t value ;
-
- value = ((uint32_t) ptr [offset + 3]) << 24 ;
+{ int32_t value = ((uint32_t) ptr [offset + 3]) << 24 ;
value += ptr [offset + 2] << 16 ;
value += ptr [offset + 1] << 8 ;
value += ptr [offset] ;
static inline int32_t
psf_get_be24 (const uint8_t *ptr, int offset)
-{ int32_t value ;
-
- value = ((uint32_t) ptr [offset]) << 24 ;
+{ int32_t value = ((uint32_t) ptr [offset]) << 24 ;
value += ptr [offset + 1] << 16 ;
value += ptr [offset + 2] << 8 ;
return value ;
static inline int32_t
psf_get_le24 (const uint8_t *ptr, int offset)
-{ int32_t value ;
-
- value = ((uint32_t) ptr [offset + 2]) << 24 ;
+{ int32_t value = ((uint32_t) ptr [offset + 2]) << 24 ;
value += ptr [offset + 1] << 16 ;
value += ptr [offset] << 8 ;
return value ;
static inline void
endswap_short_array (short *ptr, int len)
-{ short temp ;
-
- while (--len >= 0)
- { temp = ptr [len] ;
- ptr [len] = ENDSWAP_16 (temp) ;
+{
+ for (int i = 0 ; i < len ; i++)
+ { short temp = ptr [i] ;
+ ptr [i] = ENDSWAP_16 (temp) ;
} ;
} /* endswap_short_array */
static inline void
endswap_short_copy (short *dest, const short *src, int len)
{
- while (--len >= 0)
- { dest [len] = ENDSWAP_16 (src [len]) ;
+ for (int i = 0 ; i < len ; i++)
+ { dest [i] = ENDSWAP_16 (src [i]) ;
} ;
} /* endswap_short_copy */
static inline void
endswap_int_array (int *ptr, int len)
-{ int temp ;
-
- while (--len >= 0)
- { temp = ptr [len] ;
- ptr [len] = ENDSWAP_32 (temp) ;
+{
+ for (int i = 0 ; i < len ; i++)
+ { int temp = ptr [i] ;
+ ptr [i] = ENDSWAP_32 (temp) ;
} ;
} /* endswap_int_array */
static inline void
endswap_int_copy (int *dest, const int *src, int len)
{
- while (--len >= 0)
- { dest [len] = ENDSWAP_32 (src [len]) ;
+ for (int i = 0 ; i < len ; i++)
+ { dest [i] = ENDSWAP_32 (src [i]) ;
} ;
} /* endswap_int_copy */
static inline void
endswap_int64_t_array (int64_t *ptr, int len)
-{ int64_t value ;
-
- while (--len >= 0)
- { value = ptr [len] ;
- ptr [len] = ENDSWAP_64 (value) ;
+{
+ for (int i = 0 ; i < len ; i++)
+ { int64_t value = ptr [i] ;
+ ptr [i] = ENDSWAP_64 (value) ;
} ;
} /* endswap_int64_t_array */
static inline void
endswap_int64_t_copy (int64_t *dest, const int64_t *src, int len)
-{ int64_t value ;
-
- while (--len >= 0)
- { value = src [len] ;
- dest [len] = ENDSWAP_64 (value) ;
+{
+ for (int i = 0 ; i < len ; i++)
+ { int64_t value = src [i] ;
+ dest [i] = ENDSWAP_64 (value) ;
} ;
} /* endswap_int64_t_copy */
#include <io.h>
#endif
+#ifdef _WIN32
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#endif
+
#define SNDFILE_MAGICK 0x1234C0DE
#ifdef __APPLE__
{ SFE_FILENAME_TOO_LONG , "Error : Supplied filename too long." },
{ SFE_NEGATIVE_RW_LEN , "Error : Length parameter passed to read/write is negative." },
- { SFE_OPUS_BAD_SAMPLERATE , "Error : Opus only supports sample rates of 8000, 12000, 16000, 24000 and 48000." },
+ { SFE_OPUS_BAD_SAMPLERATE , "Error : Opus only supports sample rates of 8000, 12000, 16000, 24000, and 48000." },
+
+ { SFE_MPEG_BAD_SAMPLERATE , "Error : MPEG-1/2/2.5 only supports sample rates of 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, and 48000." },
+
+ { SFE_CAF_NOT_CAF , "Error : Not a CAF file." },
+ { SFE_CAF_NO_DESC , "Error : No 'desc' marker in CAF file." },
+ { SFE_CAF_BAD_PEAK , "Error : Bad 'PEAK' chunk in CAF file." },
+
+ { SFE_AVR_NOT_AVR , "Error : Not an AVR file." },
+ { SFE_AVR_BAD_REZ_SIGN , "Error : Bad rez/sign combination." },
+
+ { SFE_MPC_NO_MARKER , "Error : No marker in MPC2K file." },
{ SFE_MAX_ERROR , "Maximum error number." },
{ SFE_MAX_ERROR + 1 , NULL }
static int validate_sfinfo (SF_INFO *sfinfo) ;
static int validate_psf (SF_PRIVATE *psf) ;
static void save_header_info (SF_PRIVATE *psf) ;
-static int copy_filename (SF_PRIVATE *psf, const char *path) ;
static int psf_close (SF_PRIVATE *psf) ;
static int try_resource_fork (SF_PRIVATE * psf) ;
SNDFILE*
sf_open (const char *path, int mode, SF_INFO *sfinfo)
{ SF_PRIVATE *psf ;
+ const char *utf8path_ptr ;
+#ifdef _WIN32
+ LPWSTR wpath ;
+ int nResult ;
+ int wpath_len ;
+ char utf8path [SF_FILENAME_LEN] ;
+ DWORD dwError ;
+#endif
/* Ultimate sanity check. */
assert (sizeof (sf_count_t) == 8) ;
psf_log_printf (psf, "File : %s\n", path) ;
- if (copy_filename (psf, path) != 0)
+#ifdef _WIN32
+ nResult = MultiByteToWideChar (CP_ACP, 0, path, -1, NULL, 0) ;
+ if (nResult == 0)
+ { sf_errno = SF_ERR_UNSUPPORTED_ENCODING ;
+ psf_close (psf) ;
+ return NULL ;
+ } ;
+
+ wpath_len = nResult ;
+ wpath = malloc (wpath_len * sizeof (WCHAR)) ;
+ if (!wpath)
+ { sf_errno = SFE_MALLOC_FAILED ;
+ psf_close (psf) ;
+ return NULL ;
+ } ;
+
+ nResult = MultiByteToWideChar (CP_ACP, 0, path, -1, wpath, wpath_len) ;
+ if (nResult == 0)
+ { sf_errno = SF_ERR_UNSUPPORTED_ENCODING ;
+ free (wpath) ;
+ psf_close (psf) ;
+ return NULL ;
+ } ;
+
+ nResult = WideCharToMultiByte (CP_UTF8, 0, wpath, wpath_len, NULL, 0, NULL,
+ NULL) ;
+ if (nResult == 0)
+ { sf_errno = SF_ERR_UNSUPPORTED_ENCODING ;
+ free (wpath) ;
+ psf_close (psf) ;
+ return NULL ;
+ } ;
+
+ nResult = WideCharToMultiByte (CP_UTF8, 0, wpath, wpath_len, utf8path,
+ SF_FILENAME_LEN, NULL, NULL) ;
+
+ free (wpath) ;
+
+ if (nResult == 0)
+ { dwError = GetLastError () ;
+ if (dwError == ERROR_INSUFFICIENT_BUFFER)
+ sf_errno = SFE_FILENAME_TOO_LONG ;
+ else
+ sf_errno = SF_ERR_UNSUPPORTED_ENCODING ;
+ psf_close (psf) ;
+ return NULL ;
+ } ;
+
+ utf8path_ptr = utf8path ;
+#else
+ utf8path_ptr = path ;
+#endif
+
+ if (psf_copy_filename (psf, utf8path_ptr) != 0)
{ sf_errno = psf->error ;
+ psf_close (psf) ;
return NULL ;
} ;
} ;
psf_init_files (psf) ;
- copy_filename (psf, "") ;
+ psf_copy_filename (psf, "") ;
psf->file.mode = mode ;
psf_set_file (psf, fd) ;
if ((subformat == SF_FORMAT_NMS_ADPCM_16 || subformat == SF_FORMAT_NMS_ADPCM_24 ||
subformat == SF_FORMAT_NMS_ADPCM_32) && info->channels == 1)
return 1 ;
+ if (subformat == SF_FORMAT_MPEG_LAYER_III && info->channels <= 2)
+ return 1 ;
break ;
case SF_FORMAT_WAVEX :
if (subformat == SF_FORMAT_FLOAT || subformat == SF_FORMAT_DOUBLE)
return 1 ;
break ;
+
+ case SF_FORMAT_MPEG :
+ if (info->channels > 2)
+ return 0 ;
+ if (endian != SF_ENDIAN_FILE)
+ return 0 ;
+ if (subformat == SF_FORMAT_MPEG_LAYER_I || subformat == SF_FORMAT_MPEG_LAYER_II || subformat == SF_FORMAT_MPEG_LAYER_III)
+ return 1 ;
+ break ;
default : break ;
} ;
return SF_FALSE ;
} ;
- if (NOT (broadcast_var_set (psf, data, datasize)))
+ if (!broadcast_var_set (psf, data, datasize))
return SF_FALSE ;
if (psf->write_header)
{ psf->error = SFE_CMD_HAS_DATA ;
return SF_FALSE ;
} ;
- if (NOT (cart_var_set (psf, data, datasize)))
+ if (!cart_var_set (psf, data, datasize))
return SF_FALSE ;
if (psf->write_header)
psf->write_header (psf, SF_TRUE) ;
} ;
/* More checking here. */
- psf_log_printf (psf, "Resource fork : %s\n", psf->rsrc.path.c) ;
+ psf_log_printf (psf, "Resource fork : %s\n", psf->rsrc.path) ;
return SF_FORMAT_SD2 ;
} /* try_resource_fork */
char buffer [16] ;
int format = 0 ;
- if ((cptr = strrchr (psf->file.name.c, '.')) == NULL)
+ if ((cptr = strrchr (psf->file.name, '.')) == NULL)
return 0 ;
cptr ++ ;
psf->sf.samplerate = 8000 ;
format = SF_FORMAT_RAW | SF_FORMAT_GSM610 ;
}
+ else if (strcmp (cptr, "mp3") == 0)
+ { /*
+ * MPEG streams are quite tollerate of crap. If we couldn't identify a
+ * MP3 stream, but it has a .mp3 extension, let libmpg123 have a try.
+ */
+ format = SF_FORMAT_MPEG ;
+ }
/* For RAW files, make sure the dataoffset if set correctly. */
if ((SF_CONTAINER (format)) == SF_FORMAT_RAW)
guess_file_type (SF_PRIVATE *psf)
{ uint32_t buffer [3], format ;
+retry:
if (psf_binheader_readf (psf, "b", &buffer, SIGNED_SIZEOF (buffer)) != SIGNED_SIZEOF (buffer))
{ psf->error = SFE_BAD_FILE_READ ;
return 0 ;
if (buffer [0] == MAKE_MARKER ('R', 'F', '6', '4') && buffer [2] == MAKE_MARKER ('W', 'A', 'V', 'E'))
return SF_FORMAT_RF64 ;
+ if ((buffer [0] & MAKE_MARKER (0xFF, 0xE0, 0, 0)) == MAKE_MARKER (0xFF, 0xE0, 0, 0) && /* Frame sync */
+ (buffer [0] & MAKE_MARKER (0, 0x18, 0, 0)) != MAKE_MARKER (0, 0x08, 0, 0) && /* Valid MPEG version */
+ (buffer [0] & MAKE_MARKER (0, 0x06, 0, 0)) != MAKE_MARKER (0, 0, 0, 0) && /* Valid layer description */
+ (buffer [0] & MAKE_MARKER (0, 0, 0xF0, 0)) != MAKE_MARKER (0, 0, 0xF0, 0) && /* Valid bitrate */
+ (buffer [0] & MAKE_MARKER (0, 0, 0x0C, 0)) != MAKE_MARKER (0, 0, 0x0C, 0)) /* Valid samplerate */
+ return SF_FORMAT_MPEG ;
+
if (buffer [0] == MAKE_MARKER ('I', 'D', '3', 2) || buffer [0] == MAKE_MARKER ('I', 'D', '3', 3)
|| buffer [0] == MAKE_MARKER ('I', 'D', '3', 4))
{ psf_log_printf (psf, "Found 'ID3' marker.\n") ;
if (id3_skip (psf))
- return guess_file_type (psf) ;
+ goto retry ;
return 0 ;
} ;
static int
validate_sfinfo (SF_INFO *sfinfo)
-{ if (sfinfo->samplerate < 1)
+{ if ((sfinfo->samplerate < 1) || (sfinfo->samplerate > SF_MAX_SAMPLERATE))
return 0 ;
if (sfinfo->frames < 0)
return 0 ;
- if (sfinfo->channels < 1)
+ if ((sfinfo->channels < 1) || (sfinfo->channels > SF_MAX_CHANNELS))
return 0 ;
if ((SF_CONTAINER (sfinfo->format)) == 0)
return 0 ;
{ snprintf (sf_parselog, sizeof (sf_parselog), "%s", psf->parselog.buf) ;
} /* save_header_info */
-static int
-copy_filename (SF_PRIVATE *psf, const char *path)
-{ const char *ccptr ;
- char *cptr ;
-
- if (strlen (path) > 1 && strlen (path) - 1 >= sizeof (psf->file.path.c))
- { psf->error = SFE_FILENAME_TOO_LONG ;
- return psf->error ;
- } ;
-
- snprintf (psf->file.path.c, sizeof (psf->file.path.c), "%s", path) ;
- if ((ccptr = strrchr (path, '/')) || (ccptr = strrchr (path, '\\')))
- ccptr ++ ;
- else
- ccptr = path ;
-
- snprintf (psf->file.name.c, sizeof (psf->file.name.c), "%s", ccptr) ;
-
- /* Now grab the directory. */
- snprintf (psf->file.dir.c, sizeof (psf->file.dir.c), "%s", path) ;
- if ((cptr = strrchr (psf->file.dir.c, '/')) || (cptr = strrchr (psf->file.dir.c, '\\')))
- cptr [1] = 0 ;
- else
- psf->file.dir.c [0] = 0 ;
-
- return 0 ;
-} /* copy_filename */
-
/*==============================================================================
*/
error = mpc2k_open (psf) ;
break ;
+ case SF_FORMAT_MPEG :
+ error = mpeg_open (psf) ;
+ break ;
+
/* Lite remove end */
default :
/* Actual embedded files. */
break ;
+ case SF_FORMAT_MPEG :
case SF_FORMAT_FLAC :
/* Flac with an ID3v2 header? */
break ;
psf_log_printf (psf, " %M : %u\n", marker, chunk_size) ;
- if (strlen (psf->file.name.c) != chunk_size)
- { if (chunk_size > sizeof (psf->file.name.c) - 1)
+ if (strlen (psf->file.name) != chunk_size)
+ { if (chunk_size > sizeof (psf->file.name) - 1)
return SFE_SVX_BAD_NAME_LENGTH ;
- psf_binheader_readf (psf, "b", psf->file.name.c, chunk_size) ;
- psf->file.name.c [chunk_size] = 0 ;
+ psf_binheader_readf (psf, "b", psf->file.name, chunk_size) ;
+ psf->file.name [chunk_size] = 0 ;
}
else
psf_binheader_readf (psf, "j", chunk_size) ;
if ((chunk_size = psf_ftell (psf)) & 0x03)
{ psf_log_printf (psf, " Unknown chunk marker at position %d. Resynching.\n", chunk_size - 4) ;
- psf_binheader_readf (psf, "j", -3) ;
+ chunk_size = chunk_size & 3 ;
+ psf_binheader_readf (psf, "j", 4 - chunk_size) ;
break ;
} ;
psf_log_printf (psf, "*** Unknown chunk marker (%X) at position %D. Exiting parser.\n", marker, psf_ftell (psf) - 8) ;
psf_binheader_writef (psf, "Em44", BHWm (CHAN_MARKER), BHW4 (4), BHW4 (6)) ;
/* Filename and annotation strings. */
- psf_binheader_writef (psf, "Emsms", BHWm (NAME_MARKER), BHWs (psf->file.name.c), BHWm (ANNO_MARKER), BHWs (annotation)) ;
+ psf_binheader_writef (psf, "Emsms", BHWm (NAME_MARKER), BHWs (psf->file.name), BHWm (ANNO_MARKER), BHWs (annotation)) ;
/* BODY marker and size. */
psf_binheader_writef (psf, "Etm8", BHWm (BODY_MARKER), BHW8 ((psf->datalength < 0) ?
static void
test_broadcast_var_zero (void)
{ SF_PRIVATE sf_private, *psf ;
+#ifdef _MSC_VER
SF_BROADCAST_INFO_VAR (0) bi ;
+#else
+ SF_BROADCAST_INFO_VAR () bi ;
+#endif
psf = &sf_private ;
memset (psf, 0, sizeof (sf_private)) ;
memset (psf, 0, sizeof (sf_private)) ;
psf->file.mode = SFM_WRITE ;
- snprintf (psf->file.path.c, sizeof (psf->file.path.c), "%s", filename) ;
+ snprintf (psf->file.path, sizeof (psf->file.path), "%s", filename) ;
if (psf_fopen (psf) != 0)
{ printf ("\n\nError : failed to open file '%s' for write.\n\n", filename) ;
memset (psf, 0, sizeof (sf_private)) ;
psf->file.mode = SFM_READ ;
- snprintf (psf->file.path.c, sizeof (psf->file.path.c), "%s", filename) ;
+ snprintf (psf->file.path, sizeof (psf->file.path), "%s", filename) ;
if (psf_fopen (psf) != 0)
{ printf ("\n\nError : failed to open file '%s' for read.\n\n", filename) ;
} ;
psf->file.mode = SFM_READ ;
- snprintf (psf->file.path.c, sizeof (psf->file.path.c), "%s", filename) ;
+ snprintf (psf->file.path, sizeof (psf->file.path), "%s", filename) ;
/* Test that open for read fails if the file doesn't exist. */
error = psf_fopen (psf) ;
test_close_or_die (psf, __LINE__) ;
- unlink (psf->file.path.c) ;
+ unlink (psf->file.path) ;
/* Test file open in read/write mode for a non-existant file. */
psf->file.mode = SFM_RDWR ;
test_close_or_die (psf, __LINE__) ;
- unlink (psf->file.path.c) ;
+ unlink (psf->file.path) ;
puts ("ok") ;
} /* file_open_test */
memset (&sf_data, 0, sizeof (sf_data)) ;
psf = &sf_data ;
- snprintf (psf->file.path.c, sizeof (psf->file.path.c), "%s", filename) ;
+ snprintf (psf->file.path, sizeof (psf->file.path), "%s", filename) ;
/* Test file open in write mode. */
psf->file.mode = SFM_WRITE ;
memset (buffer, 0xEE, sizeof (buffer)) ;
psf = &sf_data ;
- snprintf (psf->file.path.c, sizeof (psf->file.path.c), "%s", filename) ;
+ snprintf (psf->file.path, sizeof (psf->file.path), "%s", filename) ;
/*
** Open the file write mode, write 0xEE data and then extend the file
for (k = 0 ; k < SIGNED_SIZEOF (buffer) / 2 ; k++)
if (buffer [k] != 0xEE)
- { printf ("\n\nLine %d : buffer [%d] = %d (should be 0xEE)\n\n", __LINE__, k, buffer [k]) ;
+ { printf ("\n\nLine %d : buffer [%d] = %hhu (should be 0xEE)\n\n", __LINE__, k, buffer [k]) ;
exit (1) ;
} ;
for (k = SIGNED_SIZEOF (buffer) / 2 ; k < SIGNED_SIZEOF (buffer) ; k++)
if (buffer [k] != 0)
- { printf ("\n\nLine %d : buffer [%d] = %d (should be 0)\n\n", __LINE__, k, buffer [k]) ;
+ { printf ("\n\nLine %d : buffer [%d] = %hhu (should be 0)\n\n", __LINE__, k, buffer [k]) ;
exit (1) ;
} ;
memset (&sf_data, 0, sizeof (sf_data)) ;
psf = &sf_data ;
psf->file.mode = SFM_READ ;
- snprintf (psf->file.path.c, sizeof (psf->file.path.c), "%s", filename) ;
+ snprintf (psf->file.path, sizeof (psf->file.path), "%s", filename) ;
test_open_or_die (psf, __LINE__) ;
/* Gather basic info before setting offset. */
/* Test printing of strings. */
CMP_4_ARGS (__LINE__, errors, "B %s, %3s, %8s, %-8s", "str") ;
+ CMP_4_ARGS (__LINE__, errors, "B %.2s, %.8s, %-8.8s, %-4.2s", "str") ;
+
if (errors)
{ puts ("\nExiting due to errors.\n") ;
exit (1) ;
static inline void
ulaw2s_array (unsigned char *buffer, int count, short *ptr)
-{ while (--count >= 0)
- ptr [count] = ulaw_decode [(int) buffer [count]] ;
+{ for (int i = 0 ; i < count ; i++)
+ ptr [i] = ulaw_decode [(int) buffer [i]] ;
} /* ulaw2s_array */
static inline void
ulaw2i_array (unsigned char *buffer, int count, int *ptr)
-{ while (--count >= 0)
- ptr [count] = ((uint32_t) ulaw_decode [buffer [count]]) << 16 ;
+{ for (int i = 0 ; i < count ; i++)
+ ptr [i] = ((uint32_t) ulaw_decode [buffer [i]]) << 16 ;
} /* ulaw2i_array */
static inline void
ulaw2f_array (unsigned char *buffer, int count, float *ptr, float normfact)
-{ while (--count >= 0)
- ptr [count] = normfact * ulaw_decode [(int) buffer [count]] ;
+{ for (int i = 0 ; i < count ; i++)
+ ptr [i] = normfact * ulaw_decode [(int) buffer [i]] ;
} /* ulaw2f_array */
static inline void
ulaw2d_array (const unsigned char *buffer, int count, double *ptr, double normfact)
-{ while (--count >= 0)
- ptr [count] = normfact * ulaw_decode [(int) buffer [count]] ;
+{ for (int i = 0 ; i < count ; i++)
+ ptr [i] = normfact * ulaw_decode [(int) buffer [i]] ;
} /* ulaw2d_array */
static inline void
s2ulaw_array (const short *ptr, int count, unsigned char *buffer)
-{ while (--count >= 0)
- { if (ptr [count] >= 0)
- buffer [count] = ulaw_encode [ptr [count] / 4] ;
+{ for (int i = 0 ; i < count ; i++)
+ { if (ptr [i] >= 0)
+ buffer [i] = ulaw_encode [ptr [i] / 4] ;
else
- buffer [count] = 0x7F & ulaw_encode [ptr [count] / -4] ;
+ buffer [i] = 0x7F & ulaw_encode [ptr [i] / -4] ;
} ;
} /* s2ulaw_array */
static inline void
i2ulaw_array (const int *ptr, int count, unsigned char *buffer)
-{ while (--count >= 0)
- { if (ptr [count] == INT_MIN)
- buffer [count] = ulaw_encode [INT_MAX >> (16 + 2)] ;
- else if (ptr [count] >= 0)
- buffer [count] = ulaw_encode [ptr [count] >> (16 + 2)] ;
+{ for (int i = 0 ; i < count ; i++)
+ { if (ptr [i] == INT_MIN)
+ buffer [i] = ulaw_encode [INT_MAX >> (16 + 2)] ;
+ else if (ptr [i] >= 0)
+ buffer [i] = ulaw_encode [ptr [i] >> (16 + 2)] ;
else
- buffer [count] = 0x7F & ulaw_encode [-ptr [count] >> (16 + 2)] ;
+ buffer [i] = 0x7F & ulaw_encode [-ptr [i] >> (16 + 2)] ;
} ;
} /* i2ulaw_array */
static inline void
f2ulaw_array (const float *ptr, int count, unsigned char *buffer, float normfact)
-{ while (--count >= 0)
- { if (ptr [count] >= 0)
- buffer [count] = ulaw_encode [psf_lrintf (normfact * ptr [count])] ;
+{ for (int i = 0 ; i < count ; i++)
+ { if (ptr [i] >= 0)
+ buffer [i] = ulaw_encode [psf_lrintf (normfact * ptr [i])] ;
else
- buffer [count] = 0x7F & ulaw_encode [- psf_lrintf (normfact * ptr [count])] ;
+ buffer [i] = 0x7F & ulaw_encode [- psf_lrintf (normfact * ptr [i])] ;
} ;
} /* f2ulaw_array */
static inline void
d2ulaw_array (const double *ptr, int count, unsigned char *buffer, double normfact)
-{ while (--count >= 0)
- { if (!isfinite (ptr [count]))
- buffer [count] = 0 ;
- else if (ptr [count] >= 0)
- buffer [count] = ulaw_encode [psf_lrint (normfact * ptr [count])] ;
+{ for (int i = 0 ; i < count ; i++)
+ { if (!isfinite (ptr [i]))
+ buffer [i] = 0 ;
+ else if (ptr [i] >= 0)
+ buffer [i] = ulaw_encode [psf_lrint (normfact * ptr [i])] ;
else
- buffer [count] = 0x7F & ulaw_encode [- psf_lrint (normfact * ptr [count])] ;
+ buffer [i] = 0x7F & ulaw_encode [- psf_lrint (normfact * ptr [i])] ;
} ;
} /* d2ulaw_array */
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.ucbuf, 1, bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.ucbuf, 1, bufferlen, psf) ;
ulaw2s_array (ubuf.ucbuf, readcount, ptr + total) ;
total += readcount ;
if (readcount < bufferlen)
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.ucbuf, 1, bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.ucbuf, 1, bufferlen, psf) ;
ulaw2i_array (ubuf.ucbuf, readcount, ptr + total) ;
total += readcount ;
if (readcount < bufferlen)
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.ucbuf, 1, bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.ucbuf, 1, bufferlen, psf) ;
ulaw2f_array (ubuf.ucbuf, readcount, ptr + total, normfact) ;
total += readcount ;
if (readcount < bufferlen)
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.ucbuf, 1, bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.ucbuf, 1, bufferlen, psf) ;
ulaw2d_array (ubuf.ucbuf, readcount, ptr + total, normfact) ;
total += readcount ;
if (readcount < bufferlen)
{ if (len < bufferlen)
bufferlen = (int) len ;
s2ulaw_array (ptr + total, bufferlen, ubuf.ucbuf) ;
- writecount = psf_fwrite (ubuf.ucbuf, 1, bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.ucbuf, 1, bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
{ if (len < bufferlen)
bufferlen = (int) len ;
i2ulaw_array (ptr + total, bufferlen, ubuf.ucbuf) ;
- writecount = psf_fwrite (ubuf.ucbuf, 1, bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.ucbuf, 1, bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
{ if (len < bufferlen)
bufferlen = (int) len ;
f2ulaw_array (ptr + total, bufferlen, ubuf.ucbuf, normfact) ;
- writecount = psf_fwrite (ubuf.ucbuf, 1, bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.ucbuf, 1, bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
{ if (len < bufferlen)
bufferlen = (int) len ;
d2ulaw_array (ptr + total, bufferlen, ubuf.ucbuf, normfact) ;
- writecount = psf_fwrite (ubuf.ucbuf, 1, bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.ucbuf, 1, bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
while (indx < len)
{ pvox->code_count = (len - indx > IMA_OKI_ADPCM_PCM_LEN) ? IMA_OKI_ADPCM_CODE_LEN : (len - indx + 1) / 2 ;
- if ((k = psf_fread (pvox->codes, 1, pvox->code_count, psf)) != pvox->code_count)
+ if ((k = (int) psf_fread (pvox->codes, 1, pvox->code_count, psf)) != pvox->code_count)
{ if (psf_ftell (psf) != psf->filelength)
psf_log_printf (psf, "*** Warning : short read (%d != %d).\n", k, pvox->code_count) ;
if (k == 0)
ima_oki_adpcm_encode_block (pvox) ;
- if ((k = psf_fwrite (pvox->codes, 1, pvox->code_count, psf)) != pvox->code_count)
+ if ((k = (int) psf_fwrite (pvox->codes, 1, pvox->code_count, psf)) != pvox->code_count)
psf_log_printf (psf, "*** Warning : short write (%d != %d).\n", k, pvox->code_count) ;
indx += pvox->pcm_count ;
psf_binheader_readf (psf, "j", 8 - (psf->header.indx & 0x7)) ;
/* Generate hash of 16 byte marker. */
- marker = chunk_size = 0 ;
+ marker = 0 ;
+ chunk_size = 0 ;
+
bytesread = psf_binheader_readf (psf, "eh8", &marker, &chunk_size) ;
if (bytesread == 0)
break ;
#define wvpk_MARKER (MAKE_MARKER ('w', 'v', 'p', 'k'))
#define OggS_MARKER (MAKE_MARKER ('O', 'g', 'g', 'S'))
+/* ID3v1 trailer which can show up at the end and erronerously look like a chunk. */
+#define TAG__MARKER (MAKE_MARKER ('T', 'A', 'G', 0))
+#define TAG__MARKER_MASK (MAKE_MARKER (0xff, 0xff, 0xff, 0))
+
#define WAVLIKE_PEAK_CHUNK_SIZE(ch) (2 * sizeof (int) + ch * (sizeof (float) + sizeof (int)))
enum
-{ HAVE_RIFF = 0x01,
- HAVE_WAVE = 0x02,
- HAVE_fmt = 0x04,
- HAVE_fact = 0x08,
- HAVE_PEAK = 0x10,
- HAVE_data = 0x20,
- HAVE_other = 0x80000000
+{ HAVE_RIFF = 1 << 0,
+ HAVE_WAVE = 1 << 1,
+ HAVE_fmt = 1 << 2,
+ HAVE_fact = 1 << 3,
+ HAVE_PEAK = 1 << 4,
+ HAVE_data = 1 << 5,
+ HAVE_other = 1 << 6
} ;
-
/* known WAVEFORMATEXTENSIBLE GUIDS */
static const EXT_SUBFORMAT MSGUID_SUBTYPE_PCM =
{ 0x00000001, 0x0000, 0x0010, { 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 }
psf->sf.frames = 0 ;
} ;
+#if (ENABLE_EXPERIMENTAL_CODE == 0)
+ /* For now, don't support writing MPEGLAYER3 WAVs, as we can't guarentee that
+ ** such a file written by libsndfile would have the same length when opened again.
+ */
+ if (subformat == SF_FORMAT_MPEG_LAYER_III)
+ return SFE_UNSUPPORTED_ENCODING ;
+#endif
+
if (subformat == SF_FORMAT_IMA_ADPCM || subformat == SF_FORMAT_MS_ADPCM)
{ blockalign = wavlike_srate2blocksize (psf->sf.samplerate * psf->sf.channels) ;
framesperblock = -1 ; /* Corrected later. */
error = gsm610_init (psf) ;
break ;
+ case SF_FORMAT_MPEG_LAYER_III :
+ error = mpeg_init (psf, SF_BITRATE_MODE_CONSTANT, SF_FALSE) ;
+ break ;
+
default : return SFE_UNIMPLEMENTED ;
} ;
break ;
} ;
+ if ((marker & TAG__MARKER_MASK) == TAG__MARKER &&
+ psf_ftell (psf) - 8 + 128 == psf->filelength)
+ { psf_log_printf (psf, "*** Hit ID3v1 trailer. Exiting parser.\n") ;
+ chunk_size = 128 ;
+ done = SF_TRUE ;
+ parsestage |= HAVE_other ;
+ break ;
+ } ;
+
if (psf_isprint ((marker >> 24) & 0xFF) && psf_isprint ((marker >> 16) & 0xFF)
&& psf_isprint ((marker >> 8) & 0xFF) && psf_isprint (marker & 0xFF))
{ psf_log_printf (psf, "*** %M : %u (unknown marker)\n", marker, chunk_size) ;
break ;
case WAVE_FORMAT_NMS_VBXADPCM :
- *blockalign = wav_fmt->min.blockalign ;
- *framesperblock = 160 ;
switch (wav_fmt->min.bitwidth)
{ case 2 :
psf->sf.format = SF_FORMAT_WAV | SF_FORMAT_NMS_ADPCM_16 ;
psf->sf.format = SF_FORMAT_WAV | SF_FORMAT_G721_32 ;
break ;
+ case WAVE_FORMAT_MPEGLAYER3 :
+ psf->sf.format = SF_FORMAT_WAV | SF_FORMAT_MPEG_LAYER_III ;
+ if (parsestage & HAVE_fact)
+ psf->sf.frames = fact_chunk.frames ;
+ break ;
+
default : return SFE_UNIMPLEMENTED ;
} ;
add_fact_chunk = SF_TRUE ;
break ;
+#if (ENABLE_EXPERIMENTAL_CODE == 0)
+ case SF_FORMAT_MPEG_LAYER_III :
+ { int bytespersec, blockalign, flags, blocksize, samplesperblock, codecdelay ;
+
+ /* Intended to be set as the average sample rate.
+ ** TODO: Maybe re-write this on close with final average
+ ** byterate? */
+ bytespersec = psf->byterate (psf) ;
+
+ /* Average block size. Info only I think. */
+ blocksize = (1152 * bytespersec) / psf->sf.samplerate ;
+
+ /* Can be set to block size IFF the block size is
+ ** constant, set to 1 otherwise. Constant sized
+ ** MPEG block streams are uncommon (CBR @ 32kHz and
+ ** 48kHz only. Meh. */
+ blockalign = 1 ;
+
+ /* TODO: Only flags defined are padding-type. I /think/
+ ** Lame does ISO style padding by default, which has a
+ ** flag value of 0.
+ */
+ flags = 0 ;
+
+ /* Should only vary per MPEG 1.0/2.0 vs '2.5'.
+ ** TODO: Move this out to MPEG specific place? */
+ samplesperblock = psf->sf.samplerate >= 32000 ? 1152 : 576 ;
+
+ /* Set as 0 if unknown.
+ ** TODO: Plumb this cleanly from Lame.
+ */
+ codecdelay = 0 ;
+
+ /* fmt chunk. */
+ fmt_size = 2 + 2 + 4 + 4 + 2 + 2 + 2 + 2 + 4 + 2 + 2 + 2 ;
+
+ /* fmt : size, WAV format type, channels. */
+ psf_binheader_writef (psf, "422", BHW4 (fmt_size), BHW2 (WAVE_FORMAT_MPEGLAYER3), BHW2 (psf->sf.channels)) ;
+
+ /* fmt : samplerate, bytespersec. */
+ psf_binheader_writef (psf, "44", BHW4 (psf->sf.samplerate), BHW4 (bytespersec)) ;
+
+ /* fmt : blockalign, bitwidth, extrabytes, id. */
+ psf_binheader_writef (psf, "2222", BHW2 (blockalign), BHW2 (0), BHW2 (12), BHW2 (1)) ;
+
+ /* fmt : flags, blocksize, samplesperblock, codecdelay */
+ psf_binheader_writef (psf, "4222", BHW4 (flags), BHW2 (blocksize), BHW2 (samplesperblock), BHW2 (codecdelay)) ;
+ } ;
+
+ add_fact_chunk = SF_TRUE ;
+ break ;
+#endif
+
default : return SFE_UNIMPLEMENTED ;
} ;
psf_log_printf (psf, " SMPTE Format : %u\n", dword) ;
bytesread += psf_binheader_readf (psf, "4", &dword) ;
- snprintf (buffer, sizeof (buffer), "%02d:%02d:%02d %02d",
- (dword >> 24) & 0x7F, (dword >> 16) & 0x7F, (dword >> 8) & 0x7F, dword & 0x7F) ;
+ snprintf (buffer, sizeof (buffer), "%02"PRIu32 ":%02"PRIu32 ":%02"PRIu32
+ " %02"PRIu32 "", (dword >> 24) & 0x7F, (dword >> 16) & 0x7F,
+ (dword >> 8) & 0x7F, dword & 0x7F) ;
psf_log_printf (psf, " SMPTE Offset : %s\n", buffer) ;
bytesread += psf_binheader_readf (psf, "4", &loop_count) ;
{ switch (wav_fmt->format)
{ case WAVE_FORMAT_GSM610 :
case WAVE_FORMAT_IPP_ITU_G_723_1 :
+ case WAVE_FORMAT_MPEGLAYER3 :
psf_log_printf (psf, " Bit Width : %d\n", wav_fmt->min.bitwidth) ;
break ;
default :
{ switch (wav_fmt->format)
{ case WAVE_FORMAT_GSM610 :
case WAVE_FORMAT_IPP_ITU_G_723_1 :
- psf_log_printf (psf, " Bit Width : %d (should be 0)\n", wav_fmt->min.bitwidth) ;
+ case WAVE_FORMAT_MPEGLAYER3 :
+ psf_log_printf (psf, " Bit Width : %d (should be 0)\n", wav_fmt->min.bitwidth) ;
break ;
default :
psf_log_printf (psf, " Bit Width : %d\n", wav_fmt->min.bitwidth) ;
psf_log_printf (psf, " Samples/Block : %d\n", wav_fmt->gsm610.samplesperblock) ;
break ;
+ case WAVE_FORMAT_MPEGLAYER3 :
+ bytesread += psf_binheader_readf (psf, "24222", &(wav_fmt->mpeg3.extrabytes),
+ &(wav_fmt->mpeg3.id), &(wav_fmt->mpeg3.flags), &(wav_fmt->mpeg3.blocksize),
+ &(wav_fmt->mpeg3.samplesperblock), &(wav_fmt->mpeg3.codecdelay)) ;
+
+ psf_log_printf (psf, " Bytes/sec : %d\n", wav_fmt->mpeg3.bytespersec) ;
+ psf_log_printf (psf, " Extra Bytes : %d\n", wav_fmt->mpeg3.extrabytes) ;
+ if (wav_fmt->mpeg3.id != 1)
+ psf_log_printf (psf, " ID : %d (unknown, should be 1)\n", wav_fmt->mpeg3.id) ;
+ else
+ psf_log_printf (psf, " ID : MPEGLAYER3_ID_MPEG\n") ;
+ psf_log_printf (psf, " Flags : 0x%08x\n", wav_fmt->mpeg3.flags) ;
+ psf_log_printf (psf, " Block Size : %d\n", wav_fmt->mpeg3.blocksize) ;
+ psf_log_printf (psf, " Samples/Block : %d\n", wav_fmt->mpeg3.samplesperblock) ;
+ psf_log_printf (psf, " Codec Delay : %d samples\n", wav_fmt->mpeg3.codecdelay) ;
+ break ;
+
case WAVE_FORMAT_EXTENSIBLE :
if (wav_fmt->ext.bytespersec != wav_fmt->ext.samplerate * wav_fmt->ext.blockalign)
psf_log_printf (psf, " Bytes/sec : %d (should be %d)\n", wav_fmt->ext.bytespersec, wav_fmt->ext.samplerate * wav_fmt->ext.blockalign) ;
return 0 ;
} ;
- if (chunksize >= sizeof (SF_CART_INFO_16K))
+ /*
+ ** SF_CART_INFO_16K has an extra field 'tag_text_size' that isn't part
+ ** of the chunk, so don't include it in the size check.
+ */
+ if (chunksize >= sizeof (SF_CART_INFO_16K) - 4)
{ psf_log_printf (psf, "cart : %u too big to be handled\n", chunksize) ;
psf_binheader_readf (psf, "j", chunksize) ;
return 0 ;
} GSM610_WAV_FMT ;
typedef struct
+{ unsigned short format ;
+ unsigned short channels ;
+ unsigned int samplerate ;
+ unsigned int bytespersec ;
+ unsigned short blockalign ;
+ unsigned short bitwidth ;
+ unsigned short extrabytes ;
+ unsigned short id ;
+ unsigned int flags ;
+ unsigned short blocksize ;
+ unsigned short samplesperblock ;
+ unsigned short codecdelay ;
+} MPEGLAYER3_WAV_FMT ;
+
+typedef struct
{ unsigned int esf_field1 ;
unsigned short esf_field2 ;
unsigned short esf_field3 ;
G72x_ADPCM_WAV_FMT g72x ;
EXTENSIBLE_WAV_FMT ext ;
GSM610_WAV_FMT gsm610 ;
+ MPEGLAYER3_WAV_FMT mpeg3 ;
WAV_FMT_SIZE20 size20 ;
char padding [512] ;
} WAV_FMT ;
#if OS_IS_WIN32
#include <windows.h>
-#define ENABLE_SNDFILE_WINDOWS_PROTOTYPES 1
#include "sndfile.h"
#include "common.h"
extern int sf_errno ;
-static void copy_filename (SF_PRIVATE * psf, LPCWSTR wpath) ;
-
SNDFILE*
sf_wchar_open (LPCWSTR wpath, int mode, SF_INFO *sfinfo)
{ SF_PRIVATE *psf ;
- char utf8name [512] ;
+ char utf8name [SF_BUFFER_LEN] ;
+ DWORD dwError ;
if ((psf = psf_allocate ()) == NULL)
{ sf_errno = SFE_MALLOC_FAILED ;
psf_init_files (psf) ;
if (WideCharToMultiByte (CP_UTF8, 0, wpath, -1, utf8name, sizeof (utf8name), NULL, NULL) == 0)
- psf->file.path.wc [0] = 0 ;
+ { dwError = GetLastError () ;
+ if (dwError == ERROR_INSUFFICIENT_BUFFER)
+ sf_errno = SFE_FILENAME_TOO_LONG ;
+ else
+ sf_errno = SF_ERR_UNSUPPORTED_ENCODING ;
+
+ sf_close (psf) ;
+
+ return NULL ;
+ } ;
psf_log_printf (psf, "File : '%s' (utf-8 converted from ucs-2)\n", utf8name) ;
- copy_filename (psf, wpath) ;
- psf->file.use_wchar = SF_TRUE ;
+ psf_copy_filename (psf, utf8name) ;
psf->file.mode = mode ;
psf->error = psf_fopen (psf) ;
return psf_open_file (psf, sfinfo) ;
} /* sf_wchar_open */
-
-static void
-copy_filename (SF_PRIVATE *psf, LPCWSTR wpath)
-{ const wchar_t *cwcptr ;
- wchar_t *wcptr ;
-
- wcsncpy (psf->file.path.wc, wpath, ARRAY_LEN (psf->file.path.wc)) ;
- psf->file.path.wc [ARRAY_LEN (psf->file.path.wc) - 1] = 0 ;
- if ((cwcptr = wcsrchr (wpath, '/')) || (cwcptr = wcsrchr (wpath, '\\')))
- cwcptr ++ ;
- else
- cwcptr = wpath ;
-
- wcsncpy (psf->file.name.wc, cwcptr, ARRAY_LEN (psf->file.name.wc)) ;
- psf->file.name.wc [ARRAY_LEN (psf->file.name.wc) - 1] = 0 ;
-
- /* Now grab the directory. */
- wcsncpy (psf->file.dir.wc, wpath, ARRAY_LEN (psf->file.dir.wc)) ;
- psf->file.dir.wc [ARRAY_LEN (psf->file.dir.wc) - 1] = 0 ;
-
- if ((wcptr = wcsrchr (psf->file.dir.wc, '/')) || (wcptr = wcsrchr (psf->file.dir.wc, '\\')))
- wcptr [1] = 0 ;
- else
- psf->file.dir.wc [0] = 0 ;
-
- return ;
-} /* copy_filename */
-
#endif
bufferlen = ARRAY_LEN (ubuf.sbuf) ;
while (total > 0)
{ len = (total > bufferlen) ? bufferlen : total ;
- total -= dpcm_read_dles2s (psf, ubuf.sbuf, len) ;
+ total -= (int) dpcm_read_dles2s (psf, ubuf.sbuf, len) ;
} ;
}
else
bufferlen = ARRAY_LEN (ubuf.sbuf) ;
while (total > 0)
{ len = (total > bufferlen) ? bufferlen : total ;
- total -= dpcm_read_dsc2s (psf, ubuf.sbuf, len) ;
+ total -= (int) dpcm_read_dsc2s (psf, ubuf.sbuf, len) ;
} ;
} ;
psf_binheader_writef (psf, "b", BHWv (pxi->sample_name), BHWz (sizeof (pxi->sample_name))) ;
-
-
-
-
/* Header construction complete so write it out. */
psf_fwrite (psf->header.ptr, psf->header.indx, 1, psf) ;
psf_log_printf (psf, " size : %d\n", sample_sizes [k]) ;
-
-
psf_log_printf (psf, " loop\n begin : %d\n end : %d\n", loop_begin, loop_end) ;
psf_log_printf (psf, " volume : %u\n f. tune : %d\n flags : 0x%02X ",
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.scbuf, sizeof (signed char), bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.scbuf, sizeof (signed char), bufferlen, psf) ;
dsc2s_array (pxi, ubuf.scbuf, readcount, ptr + total) ;
total += readcount ;
if (readcount < bufferlen)
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.scbuf, sizeof (signed char), bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.scbuf, sizeof (signed char), bufferlen, psf) ;
dsc2i_array (pxi, ubuf.scbuf, readcount, ptr + total) ;
total += readcount ;
if (readcount < bufferlen)
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.scbuf, sizeof (signed char), bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.scbuf, sizeof (signed char), bufferlen, psf) ;
dsc2f_array (pxi, ubuf.scbuf, readcount, ptr + total, normfact) ;
total += readcount ;
if (readcount < bufferlen)
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.scbuf, sizeof (signed char), bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.scbuf, sizeof (signed char), bufferlen, psf) ;
dsc2d_array (pxi, ubuf.scbuf, readcount, ptr + total, normfact) ;
total += readcount ;
if (readcount < bufferlen)
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.sbuf, sizeof (short), bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.sbuf, sizeof (short), bufferlen, psf) ;
dles2s_array (pxi, ubuf.sbuf, readcount, ptr + total) ;
total += readcount ;
if (readcount < bufferlen)
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.sbuf, sizeof (short), bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.sbuf, sizeof (short), bufferlen, psf) ;
dles2i_array (pxi, ubuf.sbuf, readcount, ptr + total) ;
total += readcount ;
if (readcount < bufferlen)
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.sbuf, sizeof (short), bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.sbuf, sizeof (short), bufferlen, psf) ;
dles2f_array (pxi, ubuf.sbuf, readcount, ptr + total, normfact) ;
total += readcount ;
if (readcount < bufferlen)
while (len > 0)
{ if (len < bufferlen)
bufferlen = (int) len ;
- readcount = psf_fread (ubuf.sbuf, sizeof (short), bufferlen, psf) ;
+ readcount = (int) psf_fread (ubuf.sbuf, sizeof (short), bufferlen, psf) ;
dles2d_array (pxi, ubuf.sbuf, readcount, ptr + total, normfact) ;
total += readcount ;
if (readcount < bufferlen)
{ if (len < bufferlen)
bufferlen = (int) len ;
s2dsc_array (pxi, ptr + total, ubuf.scbuf, bufferlen) ;
- writecount = psf_fwrite (ubuf.scbuf, sizeof (signed char), bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.scbuf, sizeof (signed char), bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
{ if (len < bufferlen)
bufferlen = (int) len ;
i2dsc_array (pxi, ptr + total, ubuf.scbuf, bufferlen) ;
- writecount = psf_fwrite (ubuf.scbuf, sizeof (signed char), bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.scbuf, sizeof (signed char), bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
{ if (len < bufferlen)
bufferlen = (int) len ;
f2dsc_array (pxi, ptr + total, ubuf.scbuf, bufferlen, normfact) ;
- writecount = psf_fwrite (ubuf.scbuf, sizeof (signed char), bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.scbuf, sizeof (signed char), bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
{ if (len < bufferlen)
bufferlen = (int) len ;
d2dsc_array (pxi, ptr + total, ubuf.scbuf, bufferlen, normfact) ;
- writecount = psf_fwrite (ubuf.scbuf, sizeof (signed char), bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.scbuf, sizeof (signed char), bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
{ if (len < bufferlen)
bufferlen = (int) len ;
s2dles_array (pxi, ptr + total, ubuf.sbuf, bufferlen) ;
- writecount = psf_fwrite (ubuf.sbuf, sizeof (short), bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.sbuf, sizeof (short), bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
{ if (len < bufferlen)
bufferlen = (int) len ;
i2dles_array (pxi, ptr + total, ubuf.sbuf, bufferlen) ;
- writecount = psf_fwrite (ubuf.sbuf, sizeof (short), bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.sbuf, sizeof (short), bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
{ if (len < bufferlen)
bufferlen = (int) len ;
f2dles_array (pxi, ptr + total, ubuf.sbuf, bufferlen, normfact) ;
- writecount = psf_fwrite (ubuf.sbuf, sizeof (short), bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.sbuf, sizeof (short), bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
{ if (len < bufferlen)
bufferlen = (int) len ;
d2dles_array (pxi, ptr + total, ubuf.sbuf, bufferlen, normfact) ;
- writecount = psf_fwrite (ubuf.sbuf, sizeof (short), bufferlen, psf) ;
+ writecount = (int) psf_fwrite (ubuf.sbuf, sizeof (short), bufferlen, psf) ;
total += writecount ;
if (writecount < bufferlen)
break ;
pxi->last_16 = last_val ;
} /* d2dles_array */
-
print_test_name ("alaw_test", "encoder") ;
- filename = "test.raw" ;
+ filename = "alaw_test.raw" ;
sf_info_setup (&sfinfo, SF_FORMAT_RAW | SF_FORMAT_ALAW, 44100, 1) ;
#define LOG_BUFFER_SIZE 1024
static void chunk_test (const char *filename, int format) ;
-static void wav_subchunk_test (size_t chunk_size) ;
-static void large_free_test (const char *filename, int format, size_t chunk_size) ;
+static void wav_subchunk_test (unsigned int chunk_size) ;
+static void large_free_test (const char *filename, int format, unsigned int chunk_size) ;
int
main (int argc, char *argv [])
snprintf (chunk_info.id, sizeof (chunk_info.id), "Test") ;
chunk_info.id_size = 4 ;
chunk_info.data = strdup (testdata) ;
- chunk_info.datalen = strlen (chunk_info.data) ;
+ chunk_info.datalen = (unsigned int) strlen (chunk_info.data) ;
length_before = chunk_info.datalen ;
chunk_info.id_size = 4 ;
chunk_info.data = strdup (testdata [i]) ;
- chunk_info.datalen = strlen (chunk_info.data) ;
+ chunk_info.datalen = (unsigned int) strlen (chunk_info.data) ;
length_before [i] = chunk_info.datalen ;
static void
-wav_subchunk_test (size_t chunk_size)
+wav_subchunk_test (unsigned int chunk_size)
{ SNDFILE * file ;
SF_INFO sfinfo ;
SF_CHUNK_INFO chunk_info ;
short audio [16] ;
int err, value ;
- snprintf (filename, sizeof (filename), "subchunk_%04d.wav", (int) chunk_size) ;
+ snprintf (filename, sizeof (filename), "subchunk_%04u.wav", chunk_size) ;
print_test_name (__func__, filename) ;
exit_if_true (sizeof (chunk_data) < chunk_size, "\n\nLine %d : sizeof (data) < chunk_size\n\n", __LINE__) ;
snprintf (chunk_info.id, sizeof (chunk_info.id), "LIST") ;
chunk_info.id_size = 4 ;
chunk_info.data = chunk_data ;
- chunk_info.datalen = chunk_size ;
+ chunk_info.datalen = (unsigned int) chunk_size ;
err = sf_set_chunk (file, &chunk_info) ;
exit_if_true (
} /* wav_subchunk_test */
static void
-large_free_test (const char *filename, int format, size_t chunk_size)
+large_free_test (const char *filename, int format, unsigned int chunk_size)
{ SNDFILE * file ;
SF_INFO sfinfo ;
SF_CHUNK_INFO chunk_info ;
{ /* Preliminary float/double normalisation tests. More testing
** is done in the program 'floating_point_test'.
*/
- float_norm_test ("float.wav") ;
- double_norm_test ("double.wav") ;
+ float_norm_test ("cmd_float.wav") ;
+ double_norm_test ("cmd_double.wav") ;
test_count ++ ;
} ;
/* Create float_data with all values being less than 1.0. */
for (k = 0 ; k < BUFFER_LEN / 2 ; k++)
- float_data [k] = (k + 5) / (2.0 * BUFFER_LEN) ;
+ float_data [k] = (k + 5) / (2.0f * BUFFER_LEN) ;
for (k = BUFFER_LEN / 2 ; k < BUFFER_LEN ; k++)
- float_data [k] = (k + 5) ;
+ float_data [k] = (float) (k + 5) ;
if (! (file = sf_open (filename, SFM_WRITE, &sfinfo)))
{ printf ("Line %d: sf_open_write failed with error : ", __LINE__) ;
/* Normalisation is on by default so no need to do anything here. */
- if ((k = sf_write_float (file, float_data, BUFFER_LEN / 2)) != BUFFER_LEN / 2)
+ if ((k = (unsigned int) sf_write_float (file, float_data, BUFFER_LEN / 2)) != BUFFER_LEN / 2)
{ printf ("Line %d: sf_write_float failed with short write (%d ->%d)\n", __LINE__, BUFFER_LEN, k) ;
exit (1) ;
} ;
/* Turn normalisation off. */
sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
- if ((k = sf_write_float (file, float_data + BUFFER_LEN / 2, BUFFER_LEN / 2)) != BUFFER_LEN / 2)
+ if ((k = (unsigned int) sf_write_float (file, float_data + BUFFER_LEN / 2, BUFFER_LEN / 2)) != BUFFER_LEN / 2)
{ printf ("Line %d: sf_write_float failed with short write (%d ->%d)\n", __LINE__, BUFFER_LEN, k) ;
exit (1) ;
} ;
} ;
/* Read float_data and check that it is normalised (ie default). */
- if ((k = sf_read_float (file, float_data, BUFFER_LEN)) != BUFFER_LEN)
+ if ((k = (unsigned int) sf_read_float (file, float_data, BUFFER_LEN)) != BUFFER_LEN)
{ printf ("\n\nLine %d: sf_read_float failed with short read (%d ->%d)\n", __LINE__, BUFFER_LEN, k) ;
exit (1) ;
} ;
sf_seek (file, 0, SEEK_SET) ;
sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
- if ((k = sf_read_float (file, float_data, BUFFER_LEN)) != BUFFER_LEN)
+ if ((k = (unsigned int) sf_read_float (file, float_data, BUFFER_LEN)) != BUFFER_LEN)
{ printf ("\n\nLine %d: sf_read_float failed with short read (%d ->%d)\n", __LINE__, BUFFER_LEN, k) ;
exit (1) ;
} ;
sf_seek (file, 0, SEEK_SET) ;
sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_TRUE) ;
- if ((k = sf_read_float (file, float_data, BUFFER_LEN)) != BUFFER_LEN)
+ if ((k = (unsigned int) sf_read_float (file, float_data, BUFFER_LEN)) != BUFFER_LEN)
{ printf ("\n\nLine %d: sf_read_float failed with short read (%d ->%d)\n", __LINE__, BUFFER_LEN, k) ;
exit (1) ;
} ;
/* Normailsation is on by default so no need to do anything here. */
/*-sf_command (file, "set-norm-double", "true", 0) ;-*/
- if ((k = sf_write_double (file, double_data, BUFFER_LEN / 2)) != BUFFER_LEN / 2)
+ if ((k = (unsigned int) sf_write_double (file, double_data, BUFFER_LEN / 2)) != BUFFER_LEN / 2)
{ printf ("Line %d: sf_write_double failed with short write (%d ->%d)\n", __LINE__, BUFFER_LEN, k) ;
exit (1) ;
} ;
/* Turn normalisation off. */
sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
- if ((k = sf_write_double (file, double_data + BUFFER_LEN / 2, BUFFER_LEN / 2)) != BUFFER_LEN / 2)
+ if ((k = (unsigned int) sf_write_double (file, double_data + BUFFER_LEN / 2, BUFFER_LEN / 2)) != BUFFER_LEN / 2)
{ printf ("Line %d: sf_write_double failed with short write (%d ->%d)\n", __LINE__, BUFFER_LEN, k) ;
exit (1) ;
} ;
} ;
/* Read double_data and check that it is normalised (ie default). */
- if ((k = sf_read_double (file, double_data, BUFFER_LEN)) != BUFFER_LEN)
+ if ((k = (unsigned int) sf_read_double (file, double_data, BUFFER_LEN)) != BUFFER_LEN)
{ printf ("\n\nLine %d: sf_read_double failed with short read (%d ->%d)\n", __LINE__, BUFFER_LEN, k) ;
exit (1) ;
} ;
sf_seek (file, 0, SEEK_SET) ;
sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
- if ((k = sf_read_double (file, double_data, BUFFER_LEN)) != BUFFER_LEN)
+ if ((k = (unsigned int) sf_read_double (file, double_data, BUFFER_LEN)) != BUFFER_LEN)
{ printf ("\n\nLine %d: sf_read_double failed with short read (%d ->%d)\n", __LINE__, BUFFER_LEN, k) ;
exit (1) ;
} ;
sf_seek (file, 0, SEEK_SET) ;
sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_TRUE) ;
- if ((k = sf_read_double (file, double_data, BUFFER_LEN)) != BUFFER_LEN)
+ if ((k = (unsigned int) sf_read_double (file, double_data, BUFFER_LEN)) != BUFFER_LEN)
{ printf ("\n\nLine %d: sf_read_double failed with short read (%d ->%d)\n", __LINE__, BUFFER_LEN, k) ;
exit (1) ;
} ;
/* Now test subtype formats. */
sf_command (NULL, SFC_GET_FORMAT_SUBTYPE_COUNT, &count, sizeof (int)) ;
- if (count < 0 || count > 30)
+ if (count < 0 || count > 33)
{ printf ("Line %d: Weird count.\n", __LINE__) ;
exit (1) ;
} ;
sfinfo.channels = 1 ;
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
- if (sf_command (file, SFC_SET_CUE, write_cue, cues_size) == SF_FALSE)
+ if (sf_command (file, SFC_SET_CUE, write_cue, (int) cues_size) == SF_FALSE)
{ printf ("\n\nLine %d : sf_command (SFC_SET_CUE) failed with %d cues, datasize %zu --> error: %s\n\n", __LINE__, count, cues_size, sf_strerror (file)) ;
exit (1) ;
} ;
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
- if (sf_command (file, SFC_GET_CUE, read_cue, cues_size) == SF_FALSE)
+ if (sf_command (file, SFC_GET_CUE, read_cue, (int) cues_size) == SF_FALSE)
{ printf ("\n\nLine %d : sf_command (SFC_GET_CUE) failed with %d cues, datasize %zu --> error: %s\n\n", __LINE__, count, cues_size, sf_strerror (file)) ;
exit (1) ;
} ;
exit (1) ;
} ;
- bc_write.coding_history_size = strlen (supplied_history) ;
+ bc_write.coding_history_size = (uint32_t) strlen (supplied_history) ;
bc_write.coding_history_size = snprintf (bc_write.coding_history, sizeof (bc_write.coding_history), "%s", supplied_history) ;
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
for (k = 0 ; bc_write.coding_history_size < 512 ; k++)
{ snprintf (bc_write.coding_history + bc_write.coding_history_size,
sizeof (bc_write.coding_history) - bc_write.coding_history_size, "line %4d\n", k) ;
- bc_write.coding_history_size = strlen (bc_write.coding_history) ;
+ bc_write.coding_history_size = (uint32_t) strlen (bc_write.coding_history) ;
} ;
exit_if_true (bc_write.coding_history_size < 512,
ca_write.level_reference = 42 ;
snprintf (ca_write.url, sizeof (ca_write.url), "http://www.test.com/test_url") ;
snprintf (ca_write.tag_text, sizeof (ca_write.tag_text), "tag text test! \r\n") ; // must be terminated \r\n to be valid
- ca_write.tag_text_size = strlen (ca_write.tag_text) ;
+ ca_write.tag_text_size = (uint32_t) strlen (ca_write.tag_text) ;
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
if (sf_command (file, SFC_SET_CART_INFO, &ca_write, sizeof (ca_write)) == SF_FALSE)
cinfo.level_reference = 42 ;
snprintf (cinfo.url, sizeof (cinfo.url), "http://www.test.com/test_url") ;
snprintf (cinfo.tag_text, sizeof (cinfo.tag_text), "tag text test!\r\n") ;
- cinfo.tag_text_size = strlen (cinfo.tag_text) ;
+ cinfo.tag_text_size = (uint32_t) strlen (cinfo.tag_text) ;
file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, SF_TRUE, __LINE__) ;
frames = sfinfo.frames ;
#define SAMPLE_RATE 16000
#define DATA_LENGTH (SAMPLE_RATE)
+static const char CMP_TEST_PREFIX[] = "cmp" ;
+
static float data_out [DATA_LENGTH] ;
static inline float
float max_abs = 0.0 ;
unsigned k ;
+ get_unique_test_name (&filename, CMP_TEST_PREFIX) ;
+
print_test_name ("vorbis_test", filename) ;
/* Generate float data. */
sf_close (file) ;
for (k = 0 ; k < ARRAY_LEN (float_data) ; k ++)
- max_abs = max_float (max_abs, fabs (float_data [k])) ;
+ max_abs = max_float (max_abs, fabsf (float_data [k])) ;
exit_if_true (max_abs > 1.023,
"\n\nLine %d : max_abs %f should be < 1.023.\n\n", __LINE__, max_abs) ;
double quality ;
int k ;
+ get_unique_test_name (&filename, CMP_TEST_PREFIX) ;
+
snprintf (q3_fname, sizeof (q3_fname), "q3_%s", filename) ;
snprintf (q6_fname, sizeof (q6_fname), "q6_%s", filename) ;
sf_close (q3_file) ;
sf_close (q6_file) ;
- q3_size = file_length (q3_fname) ;
- q6_size = file_length (q6_fname) ;
+ q3_size = (int) file_length (q3_fname) ;
+ q6_size = (int) file_length (q6_fname) ;
exit_if_true (q3_size >= q6_size,
"\n\nLine %d : q3 size (%d) >= q6 size (%d)\n\n", __LINE__, q3_size, q6_size) ;
" vorbis - test Ogg/Vorbis\n"
" flac - test FLAC\n"
" opus - test Opus\n"
+ " mpeg - test mpeg\n"
" all - perform all tests\n",
argv [0]) ;
exit (0) ;
} ;
- if (! HAVE_EXTERNAL_XIPH_LIBS)
- { puts (" No Ogg/Vorbis tests because Ogg/Vorbis support was not compiled in.") ;
- return 0 ;
- } ;
-
if (strcmp (argv [1], "all") == 0)
all_tests = 1 ;
if (all_tests || strcmp (argv [1], "vorbis") == 0)
- { vorbis_test () ;
- compression_size_test (SF_FORMAT_OGG | SF_FORMAT_VORBIS, "vorbis.oga") ;
- tests ++ ;
+ { if (HAVE_EXTERNAL_XIPH_LIBS)
+ { vorbis_test () ;
+ compression_size_test (SF_FORMAT_OGG | SF_FORMAT_VORBIS, "vorbis.oga") ;
+ tests ++ ;
+ }
+ else
+ puts (" No Ogg Vorbis tests because support was not compiled in.") ;
} ;
if (all_tests || strcmp (argv [1], "flac") == 0)
- { compression_size_test (SF_FORMAT_FLAC | SF_FORMAT_PCM_16, "pcm16.flac") ;
- tests ++ ;
+ { if (HAVE_EXTERNAL_XIPH_LIBS)
+ { compression_size_test (SF_FORMAT_FLAC | SF_FORMAT_PCM_16, "pcm16.flac") ;
+ tests ++ ;
+ }
+ else
+ puts (" No FLAC tests because support was not compiled in.") ;
} ;
if (all_tests || strcmp (argv [1], "opus") == 0)
- { compression_size_test (SF_FORMAT_OGG | SF_FORMAT_OPUS, "opus.opus") ;
- tests ++ ;
+ { if (HAVE_EXTERNAL_XIPH_LIBS)
+ { compression_size_test (SF_FORMAT_OGG | SF_FORMAT_OPUS, "opus.opus") ;
+ tests ++ ;
+ }
+ else
+ puts (" No Opus tests because support was not compiled in.") ;
+ } ;
+
+ if (all_tests || strcmp (argv [1], "mpeg") == 0)
+ { if (HAVE_MPEG)
+ { compression_size_test (SF_FORMAT_MPEG | SF_FORMAT_MPEG_LAYER_III, "mpeg.mp3") ;
+ tests ++ ;
+ }
+ else
+ puts (" No MPEG tests because support was not compiled in.") ;
} ;
return 0 ;
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
- if ((k = sf_read_int (file, read_buf, BUFFER_SIZE)) != BUFFER_SIZE)
+ if ((k = (int) sf_read_int (file, read_buf, BUFFER_SIZE)) != BUFFER_SIZE)
{ printf ("Error (line %d) : Only read %d/%d.frames.\n", __LINE__, k, BUFFER_SIZE) ;
exit (1) ;
}
#include "sf_unistd.h"
#endif
-#if OS_IS_WIN32
-#include <windows.h>
-#endif
-
#include <sndfile.h>
#include "utils.h"
if (sf_close (sndfile) == 0)
{
+ printf ("\n\nLine %d : sf_close should not have returned zero.\n", __LINE__) ;
#if OS_IS_WIN32
- OSVERSIONINFOEX osvi ;
-
- memset (&osvi, 0, sizeof (OSVERSIONINFOEX)) ;
- osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFOEX) ;
-
- if (GetVersionEx ((OSVERSIONINFO *) &osvi))
- { printf ("\n\nLine %d : sf_close should not have returned zero.\n", __LINE__) ;
- printf ("\nHowever, this is a known bug in version %d.%d of windows so we'll ignore it.\n\n",
- (int) osvi.dwMajorVersion, (int) osvi.dwMinorVersion) ;
- } ;
+ printf ("\nHowever, this is a known bug on windows platform so we'll ignore it.\n\n") ;
#else
- printf ("\n\nLine %d : sf_close should not have returned zero.\n", __LINE__) ;
exit (1) ;
#endif
} ;
sndfile = sf_open (filename, SFM_READ, &sfinfo) ;
exit_if_true (sndfile != NULL,
- "\n\nLine %d : SNDFILE* pointer (%p) should ne NULL.\n", __LINE__, sndfile
+ "\n\nLine %d : SNDFILE* pointer (%p) should be NULL.\n", __LINE__, (void *) sndfile
) ;
k = sf_error (sndfile) ;
#define SAMPLE_RATE 16000
+static const char FPT_TEST_PREFIX[] = "fpt" ;
+
static void float_scaled_test (const char *filename, int allow_exit, int replace_float, int filetype, double target_snr) ;
static void double_scaled_test (const char *filename, int allow_exit, int replace_float, int filetype, double target_snr) ;
[+ FOR float_type +][+ FOR int_type +][+ FOR endian_type
-+]static void [+ (get "float_name") +]_[+ (get "int_name") +]_[+ (get "end_name") +]_test (const char * filename) ;
++]static void [+ (get "float_name") +]_[+ (get "int_name") +]_[+ (get "end_name") +]_test (const char * filename, int replace_float) ;
[+ ENDFOR endian_type +][+ ENDFOR int_type +][+ ENDFOR float_type
+]
float_scaled_test ("opus.opus", allow_exit, SF_FALSE, SF_FORMAT_OGG | SF_FORMAT_OPUS, -32.0) ;
#endif
+#if HAVE_MPEG
+ float_scaled_test ("mpeg.mp3", allow_exit, SF_FALSE, SF_FORMAT_MPEG | SF_FORMAT_MPEG_LAYER_III, -52.0) ;
+#endif
+
float_scaled_test ("replace_float.raw", allow_exit, SF_TRUE, SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_FLOAT, -163.0) ;
/*==============================================================================
double_scaled_test ("opus.opus", allow_exit, SF_FALSE, SF_FORMAT_OGG | SF_FORMAT_OPUS, -32.0) ;
#endif
+#if HAVE_MPEG
+ double_scaled_test ("mpeg.mp3", allow_exit, SF_FALSE, SF_FORMAT_MPEG | SF_FORMAT_MPEG_LAYER_III, -52.0) ;
+#endif
+
double_scaled_test ("replace_double.raw", allow_exit, SF_TRUE, SF_FORMAT_RAW | SF_FORMAT_DOUBLE, -201.0) ;
putchar ('\n') ;
/* Float int tests. */
-[+ FOR float_type +][+ FOR int_type +][+ FOR endian_type
-+] [+ (get "float_name") +]_[+ (get "int_name") +]_[+ (get "end_name") +]_test ("[+ (get "float_name") +]_[+ (get "int_name") +]_[+ (get "end_name") +].au") ;
-[+ ENDFOR endian_type +][+ ENDFOR int_type +][+ ENDFOR float_type
-+]
+[+ FOR float_type +][+ FOR int_type +][+ FOR endian_type +]
+[+ (get "float_name") +]_[+ (get "int_name") +]_[+ (get "end_name") +]_test ("[+ (get "float_name") +]_[+ (get "int_name") +]_[+ (get "end_name") +].au", SF_FALSE) ;
+[+ (get "float_name") +]_[+ (get "int_name") +]_[+ (get "end_name") +]_test ("[+ (get "float_name") +]_[+ (get "int_name") +]_[+ (get "end_name") +]_replace.au", SF_TRUE) ;
+[+ ENDFOR endian_type +][+ ENDFOR int_type +][+ ENDFOR float_type +]
return 0 ;
} /* main */
double snr ;
int byterate ;
+ get_unique_test_name (&filename, FPT_TEST_PREFIX) ;
print_test_name ("float_scaled_test", filename) ;
gen_windowed_sine_float (float_data, DFT_DATA_LENGTH, 0.9999) ;
double snr ;
int byterate ;
+ get_unique_test_name (&filename, FPT_TEST_PREFIX) ;
print_test_name ("double_scaled_test", filename) ;
gen_windowed_sine_double (double_data, DFT_DATA_LENGTH, 0.9999) ;
[+ FOR float_type +][+ FOR int_type +][+ FOR endian_type
+]
static void
-[+ (get "float_name") +]_[+ (get "int_name") +]_[+ (get "end_name") +]_test (const char * filename)
+[+ (get "float_name") +]_[+ (get "int_name") +]_[+ (get "end_name") +]_test (const char * filename, int replace_float)
{ SNDFILE *file ;
SF_INFO sfinfo ;
int max ;
unsigned k ;
+ get_unique_test_name (&filename, FPT_TEST_PREFIX) ;
print_test_name ("[+ (get "float_name") +]_[+ (get "int_name") +]_[+ (get "end_name") +]_test", filename) ;
gen_windowed_sine_[+ (get "float_name") +] ([+ (get "float_name") +]_data, ARRAY_LEN ([+ (get "float_name") +]_data), 0.9999) ;
sfinfo.format = [+ (get "end_type") +] | SF_FORMAT_AU | [+ (get "minor_type") +] ;
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
+ sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
test_write_[+ (get "float_name") +]_or_die (file, 0, [+ (get "float_name") +]_data, ARRAY_LEN ([+ (get "float_name") +]_data), __LINE__) ;
sf_close (file) ;
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
+ sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
if (sfinfo.frames != ARRAY_LEN ([+ (get "float_name") +]_data))
{ printf ("\n\nLine %d: Incorrect number of frames in file (too short). (%" PRId64 " should be %d)\n", __LINE__, sfinfo.frames, DFT_DATA_LENGTH) ;
__LINE__
) ;
+ /* Only have decode, not encode support for MPEG Layer I and II */
+ if (subtype_fmt_info.format == SF_FORMAT_MPEG_LAYER_I ||
+ subtype_fmt_info.format == SF_FORMAT_MPEG_LAYER_II)
+ continue ;
+
+ /* MPEG Layer III in WAV is decode only currently */
+ if (subtype_fmt_info.format == SF_FORMAT_MPEG_LAYER_III &&
+ major_fmt_info.format == SF_FORMAT_WAV)
+ continue ;
+
snprintf (filename, sizeof (filename), "format-check.%s", major_fmt_info.extension) ;
sndfile = sf_open (filename, SFM_WRITE, &info) ;
output = calloc (len, sizeof (float)) ;
- maxabs = crappy_snare (output, len, 0, 0.95, maxabs) ;
- maxabs = crappy_snare (output, len, len / 4, 0.85, maxabs) ;
- maxabs = crappy_snare (output, len, 2 * len / 4, 0.85, maxabs) ;
- crappy_snare (output, len, 3 * len / 4, 0.85, maxabs) ;
+ maxabs = crappy_snare (output, len, 0, 0.95f, maxabs) ;
+ maxabs = crappy_snare (output, len, len / 4, 0.85f, maxabs) ;
+ maxabs = crappy_snare (output, len, 2 * len / 4, 0.85f, maxabs) ;
+ crappy_snare (output, len, 3 * len / 4, 0.85f, maxabs) ;
write_mono_file (filename, format, 44100, output, len) ;
static inline float
rand_float (void)
-{ return rand () / (0.5 * RAND_MAX) - 1.0 ;
+{ return rand () / (0.5f * (float) RAND_MAX) - 1.0f ;
} /* rand_float */
static float
crappy_snare (float *output, int len, int offset, float gain, float maxabs)
{ int k ;
- float env = 0.0 ;
+ float env = 0.0f ;
for (k = offset ; k < len && env < gain ; k++)
- { env += 0.03 ;
+ { env += 0.03f ;
output [k] += env * rand_float () ;
- maxabs = SF_MAX (maxabs, fabs (output [k])) ;
+ maxabs = SF_MAX (maxabs, fabsf (output [k])) ;
} ;
for ( ; k < len && env > 1e-8 ; k++)
- { env *= 0.995 ;
+ { env *= 0.995f ;
output [k] += env * rand_float () ;
- maxabs = SF_MAX (maxabs, fabs (output [k])) ;
+ maxabs = SF_MAX (maxabs, fabsf (output [k])) ;
} ;
return maxabs ;
update_seek_int_test ("header_int.aiff", SF_FORMAT_AIFF) ;
update_seek_float_test ("header_float.aiff", SF_FORMAT_AIFF) ;
update_seek_double_test ("header_double.aiff", SF_FORMAT_AIFF) ;
- header_shrink_test ("header_shrink.wav", SF_FORMAT_AIFF) ;
+ header_shrink_test ("header_shrink.aiff", SF_FORMAT_AIFF) ;
extra_header_test ("extra.aiff", SF_FORMAT_AIFF) ;
test_count++ ;
} ;
{
old_test () ;
- headerless_test ("raw.vox", SF_FORMAT_VOX_ADPCM, SF_FORMAT_RAW | SF_FORMAT_VOX_ADPCM) ;
- headerless_test ("raw.gsm", SF_FORMAT_GSM610, SF_FORMAT_RAW | SF_FORMAT_GSM610) ;
+ headerless_test ("headerless.vox", SF_FORMAT_VOX_ADPCM, SF_FORMAT_RAW | SF_FORMAT_VOX_ADPCM) ;
+ headerless_test ("headerless.gsm", SF_FORMAT_GSM610, SF_FORMAT_RAW | SF_FORMAT_GSM610) ;
- headerless_test ("raw.snd", SF_FORMAT_ULAW, SF_FORMAT_RAW | SF_FORMAT_ULAW) ;
- headerless_test ("raw.au" , SF_FORMAT_ULAW, SF_FORMAT_RAW | SF_FORMAT_ULAW) ;
+ headerless_test ("headerless.snd", SF_FORMAT_ULAW, SF_FORMAT_RAW | SF_FORMAT_ULAW) ;
+ headerless_test ("headerless.au" , SF_FORMAT_ULAW, SF_FORMAT_RAW | SF_FORMAT_ULAW) ;
return 0 ;
} /* main */
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
- if ((k = sf_write_short (file, buffer, BUFFER_SIZE)) != BUFFER_SIZE)
+ if ((k = (int) sf_write_short (file, buffer, BUFFER_SIZE)) != BUFFER_SIZE)
{ printf ("Line %d: sf_write_short failed with short write (%d => %d).\n", __LINE__, BUFFER_SIZE, k) ;
fflush (stdout) ;
puts (sf_strerror (file)) ;
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
- if ((k = sf_write_short (file, buffer, BUFFER_SIZE)) != BUFFER_SIZE)
+ if ((k = (int) sf_write_short (file, buffer, BUFFER_SIZE)) != BUFFER_SIZE)
{ printf ("Line %d: sf_write_short failed with short write (%d => %d).\n", __LINE__, BUFFER_SIZE, k) ;
fflush (stdout) ;
puts (sf_strerror (file)) ;
check_log_buffer_or_die (file, __LINE__) ;
- if ((k = sf_read_short (file, buffer, BUFFER_SIZE)) != BUFFER_SIZE)
+ if ((k = (int) sf_read_short (file, buffer, BUFFER_SIZE)) != BUFFER_SIZE)
{ printf ("Line %d: short read (%d).\n", __LINE__, k) ;
exit (1) ;
} ;
#if OS_IS_WIN32
#include <windows.h>
-#define ENABLE_SNDFILE_WINDOWS_PROTOTYPES 1
#endif
#include "sndfile.h"
{ int value = k / 32 ;
int_data [k] = (value & 1 ? -1 : 1) * value ;
short_data [k] = int_data [k] ;
- float_data [k] = int_data [k] / 32000.0 ;
+ float_data [k] = int_data [k] / 32000.0f ;
double_data [k] = int_data [k] / 32000.0 ;
}
#define LCT_MAX(x, y) ((x) > (y) ? (x) : (y))
+static const char LCT_TEST_PREFIX[] = "lct" ;
+
static void lcomp_test_short (const char *filename, int filetype, int chan, double margin) ;
static void lcomp_test_int (const char *filename, int filetype, int chan, double margin) ;
static void lcomp_test_float (const char *filename, int filetype, int chan, double margin) ;
sf_count_t datalen ;
short *orig, *data ;
+ get_unique_test_name (&filename, LCT_TEST_PREFIX) ;
print_test_name ("lcomp_test_short", filename) ;
datalen = BUFFER_SIZE / channels ;
data = data_buffer.s ;
orig = orig_buffer.s ;
- gen_signal_double (orig_buffer.d, 32000.0, channels, datalen) ;
+ gen_signal_double (orig_buffer.d, 32000.0, channels, (int) datalen) ;
for (k = 0 ; k < channels * datalen ; k++)
orig [k] = (short) (orig_buffer.d [k]) ;
for (k = 0 ; k < datalen ; k++)
{ if (error_function (data [k], orig [k], margin))
{ printf ("\n\nLine %d: Incorrect sample A (#%d : %d should be %d).\n", __LINE__, k, data [k], orig [k]) ;
- oct_save_short (orig, data, datalen) ;
+ oct_save_short (orig, data, (int) datalen) ;
exit (1) ;
} ;
half_max_abs = LCT_MAX (half_max_abs, abs (data [k] / 2)) ;
exit (1) ;
} ;
- if ((k = sf_readf_short (file, data, datalen)) != sfinfo.frames - datalen)
+ if ((k = (int) sf_readf_short (file, data, datalen)) != sfinfo.frames - datalen)
{ printf ("\n\nLine %d: Incorrect read length (%" PRId64 " should be %d).\n", __LINE__,
channels * sfinfo.frames - datalen, k) ;
exit (1) ;
/* Now test sf_seek function. */
- if ((k = sf_seek (file, 0, SEEK_SET)) != 0)
+ if ((k = (int) sf_seek (file, 0, SEEK_SET)) != 0)
{ printf ("\n\nLine %d: Seek to start of file failed (%d).\n", __LINE__, k) ;
exit (1) ;
} ;
seekpos = BUFFER_SIZE / 10 ;
/* Check seek from start of file. */
- if ((k = sf_seek (file, seekpos, SEEK_SET)) != seekpos)
+ if ((k = (int) sf_seek (file, seekpos, SEEK_SET)) != seekpos)
{ printf ("Seek to start of file + %d failed (%d).\n", seekpos, k) ;
exit (1) ;
} ;
exit (1) ;
} ;
- if ((k = sf_seek (file, 0, SEEK_CUR)) != seekpos + 1)
+ if ((k = (int) sf_seek (file, 0, SEEK_CUR)) != seekpos + 1)
{ printf ("\n\nLine %d: sf_seek (SEEK_CUR) with 0 offset failed (%d should be %d)\n", __LINE__, k, seekpos + 1) ;
exit (1) ;
} ;
- seekpos = sf_seek (file, 0, SEEK_CUR) + BUFFER_SIZE / 5 ;
- k = sf_seek (file, BUFFER_SIZE / 5, SEEK_CUR) ;
+ seekpos = (int) sf_seek (file, 0, SEEK_CUR) + BUFFER_SIZE / 5 ;
+ k = (int) sf_seek (file, BUFFER_SIZE / 5, SEEK_CUR) ;
test_readf_short_or_die (file, 0, data, 1, __LINE__) ;
if (error_function (1.0 * data [0], 1.0 * orig [seekpos * channels], margin) || k != seekpos)
{ printf ("\n\nLine %d: sf_seek (forwards, SEEK_CUR) followed by sf_readf_short failed (%d, %d) (%d, %d).\n", __LINE__, data [0], orig [seekpos * channels], k, seekpos + 1) ;
- oct_save_short (orig, data, datalen) ;
+ oct_save_short (orig, data, (int) datalen) ;
exit (1) ;
} ;
- seekpos = sf_seek (file, 0, SEEK_CUR) - 20 ;
+ seekpos = (int) sf_seek (file, 0, SEEK_CUR) - 20 ;
/* Check seek backward from current position. */
- k = sf_seek (file, -20, SEEK_CUR) ;
+ k = (int) sf_seek (file, -20, SEEK_CUR) ;
test_readf_short_or_die (file, 0, data, 1, __LINE__) ;
if (error_function (1.0 * data [0], 1.0 * orig [seekpos * channels], margin) || k != seekpos)
{ printf ("\nLine %d: sf_seek (backwards, SEEK_CUR) followed by sf_readf_short failed (%d, %d) (%d, %d).\n", __LINE__, data [0], orig [seekpos * channels], k, seekpos) ;
/* Check that read past end of file returns number of items. */
sf_seek (file, sfinfo.frames, SEEK_SET) ;
- if ((k = sf_readf_short (file, data, datalen)) != 0)
+ if ((k = (int) sf_readf_short (file, data, datalen)) != 0)
{ printf ("\n\nLine %d: Return value from sf_readf_short past end of file incorrect (%d).\n", __LINE__, k) ;
exit (1) ;
} ;
/* Check seek backward from end. */
- if ((k = sf_seek (file, 5 - sfinfo.frames, SEEK_END)) != 5)
+ if ((k = (int) sf_seek (file, 5 - sfinfo.frames, SEEK_END)) != 5)
{ printf ("\n\nLine %d: sf_seek (SEEK_END) returned %d instead of %d.\n", __LINE__, k, 5) ;
exit (1) ;
} ;
double scale, max_val ;
int *orig, *data ;
+ get_unique_test_name (&filename, LCT_TEST_PREFIX) ;
print_test_name ("lcomp_test_int", filename) ;
datalen = BUFFER_SIZE / channels ;
data = data_buffer.i ;
orig = orig_buffer.i ;
- gen_signal_double (orig_buffer.d, max_val, channels, datalen) ;
+ gen_signal_double (orig_buffer.d, max_val, channels, (int) datalen) ;
for (k = 0 ; k < channels * datalen ; k++)
orig [k] = lrint (orig_buffer.d [k]) ;
for (k = 0 ; k < datalen ; k++)
{ if (error_function (data [k] / scale, orig [k] / scale, margin))
{ printf ("\nLine %d: Incorrect sample (#%d : %f should be %f).\n", __LINE__, k, data [k] / scale, orig [k] / scale) ;
- oct_save_int (orig, data, datalen) ;
+ oct_save_int (orig, data, (int) datalen) ;
exit (1) ;
} ;
half_max_abs = LCT_MAX (half_max_abs, abs (data [k] / 2)) ;
exit (1) ;
} ;
- if ((k = sf_readf_int (file, data, datalen)) != sfinfo.frames - datalen)
+ if ((k = (int) sf_readf_int (file, data, datalen)) != sfinfo.frames - datalen)
{ printf ("\n\nLine %d: Incorrect read length (%" PRId64 " should be %d).\n", __LINE__,
channels * sfinfo.frames - datalen, k) ;
exit (1) ;
/* Now test sf_seek function. */
- if ((k = sf_seek (file, 0, SEEK_SET)) != 0)
+ if ((k = (int) sf_seek (file, 0, SEEK_SET)) != 0)
{ printf ("\n\nLine %d: Seek to start of file failed (%d).\n", __LINE__, k) ;
exit (1) ;
} ;
seekpos = BUFFER_SIZE / 10 ;
/* Check seek from start of file. */
- if ((k = sf_seek (file, seekpos, SEEK_SET)) != seekpos)
+ if ((k = (int) sf_seek (file, seekpos, SEEK_SET)) != seekpos)
{ printf ("Seek to start of file + %" PRId64 " failed (%d).\n", seekpos, k) ;
exit (1) ;
} ;
exit (1) ;
} ;
- if ((k = sf_seek (file, 0, SEEK_CUR)) != seekpos + 1)
+ if ((k = (int) sf_seek (file, 0, SEEK_CUR)) != seekpos + 1)
{ printf ("\n\nLine %d: sf_seek (SEEK_CUR) with 0 offset failed (%d should be %" PRId64 ")\n", __LINE__, k, seekpos + 1) ;
exit (1) ;
} ;
seekpos = sf_seek (file, 0, SEEK_CUR) + BUFFER_SIZE / 5 ;
- k = sf_seek (file, BUFFER_SIZE / 5, SEEK_CUR) ;
+ k = (int) sf_seek (file, BUFFER_SIZE / 5, SEEK_CUR) ;
test_readf_int_or_die (file, 0, data, 1, __LINE__) ;
if (error_function (1.0 * data [0], 1.0 * orig [seekpos * channels], margin) || k != seekpos)
{ printf ("\nLine %d: sf_seek (forwards, SEEK_CUR) followed by sf_readf_int failed (%d, %d) (%d, %" PRId64 ").\n", __LINE__, data [0], orig [seekpos * channels], k, seekpos + 1) ;
seekpos = sf_seek (file, 0, SEEK_CUR) - 20 ;
/* Check seek backward from current position. */
- k = sf_seek (file, -20, SEEK_CUR) ;
+ k = (int) sf_seek (file, -20, SEEK_CUR) ;
test_readf_int_or_die (file, 0, data, 1, __LINE__) ;
if (error_function (1.0 * data [0], 1.0 * orig [seekpos * channels], margin) || k != seekpos)
{ printf ("\nLine %d: sf_seek (backwards, SEEK_CUR) followed by sf_readf_int failed (%d, %d) (%d, %" PRId64 ").\n", __LINE__, data [0], orig [seekpos * channels], k, seekpos) ;
/* Check that read past end of file returns number of items. */
sf_seek (file, sfinfo.frames, SEEK_SET) ;
- if ((k = sf_readf_int (file, data, datalen)) != 0)
+ if ((k = (int) sf_readf_int (file, data, datalen)) != 0)
{ printf ("\n\nLine %d: Return value from sf_readf_int past end of file incorrect (%d).\n", __LINE__, k) ;
exit (1) ;
} ;
/* Check seek backward from end. */
- if ((k = sf_seek (file, 5 - sfinfo.frames, SEEK_END)) != 5)
+ if ((k = (int) sf_seek (file, 5 - sfinfo.frames, SEEK_END)) != 5)
{ printf ("\n\nLine %d: sf_seek (SEEK_END) returned %d instead of %d.\n", __LINE__, k, 5) ;
exit (1) ;
} ;
float *orig, *data ;
double half_max_abs ;
+ get_unique_test_name (&filename, LCT_TEST_PREFIX) ;
print_test_name ("lcomp_test_float", filename) ;
datalen = BUFFER_SIZE / channels ;
data = data_buffer.f ;
orig = orig_buffer.f ;
- gen_signal_double (orig_buffer.d, 32000.0, channels, datalen) ;
+ gen_signal_double (orig_buffer.d, 32000.0, channels, (int) datalen) ;
for (k = 0 ; k < channels * datalen ; k++)
- orig [k] = orig_buffer.d [k] ;
+ orig [k] = (float) orig_buffer.d [k] ;
sfinfo.samplerate = SAMPLE_RATE ;
sfinfo.frames = 123456789 ; /* Ridiculous value. */
for (k = 0 ; k < datalen ; k++)
{ if (error_function (data [k], orig [k], margin))
{ printf ("\nLine %d: Incorrect sample A (#%d : %f should be %f).\n", __LINE__, k, data [k], orig [k]) ;
- oct_save_float (orig, data, datalen) ;
+ oct_save_float (orig, data, (int) datalen) ;
exit (1) ;
} ;
half_max_abs = LCT_MAX (half_max_abs, fabs (0.5 * data [k])) ;
exit (1) ;
} ;
- if ((k = sf_readf_float (file, data, datalen)) != sfinfo.frames - datalen)
+ if ((k = (int) sf_readf_float (file, data, datalen)) != sfinfo.frames - datalen)
{ printf ("\n\nLine %d: Incorrect read length (%" PRId64 " should be %d).\n", __LINE__,
channels * sfinfo.frames - datalen, k) ;
exit (1) ;
/* Now test sf_seek function. */
- if ((k = sf_seek (file, 0, SEEK_SET)) != 0)
+ if ((k = (int) sf_seek (file, 0, SEEK_SET)) != 0)
{ printf ("\n\nLine %d: Seek to start of file failed (%d).\n", __LINE__, k) ;
exit (1) ;
} ;
seekpos = BUFFER_SIZE / 10 ;
/* Check seek from start of file. */
- if ((k = sf_seek (file, seekpos, SEEK_SET)) != seekpos)
+ if ((k = (int) sf_seek (file, seekpos, SEEK_SET)) != seekpos)
{ printf ("Seek to start of file + %d failed (%d).\n", seekpos, k) ;
exit (1) ;
} ;
exit (1) ;
} ;
- if ((k = sf_seek (file, 0, SEEK_CUR)) != seekpos + 1)
+ if ((k = (int) sf_seek (file, 0, SEEK_CUR)) != seekpos + 1)
{ printf ("\n\nLine %d: sf_seek (SEEK_CUR) with 0 offset failed (%d should be %d)\n", __LINE__, k, seekpos + 1) ;
exit (1) ;
} ;
- seekpos = sf_seek (file, 0, SEEK_CUR) + BUFFER_SIZE / 5 ;
- k = sf_seek (file, BUFFER_SIZE / 5, SEEK_CUR) ;
+ seekpos = (int) sf_seek (file, 0, SEEK_CUR) + BUFFER_SIZE / 5 ;
+ k = (int) sf_seek (file, BUFFER_SIZE / 5, SEEK_CUR) ;
test_readf_float_or_die (file, 0, data, 1, __LINE__) ;
if (error_function (data [0], orig [seekpos * channels], margin) || k != seekpos)
{ printf ("\nLine %d: sf_seek (forwards, SEEK_CUR) followed by sf_readf_float failed (%f, %f) (%d, %d).\n", __LINE__, data [0], orig [seekpos * channels], k, seekpos + 1) ;
exit (1) ;
} ;
- seekpos = sf_seek (file, 0, SEEK_CUR) - 20 ;
+ seekpos = (int) sf_seek (file, 0, SEEK_CUR) - 20 ;
/* Check seek backward from current position. */
- k = sf_seek (file, -20, SEEK_CUR) ;
+ k = (int) sf_seek (file, -20, SEEK_CUR) ;
test_readf_float_or_die (file, 0, data, 1, __LINE__) ;
if (error_function (data [0], orig [seekpos * channels], margin) || k != seekpos)
{ printf ("\nLine %d: sf_seek (backwards, SEEK_CUR) followed by sf_readf_float failed (%f, %f) (%d, %d).\n", __LINE__, data [0], orig [seekpos * channels], k, seekpos) ;
/* Check that read past end of file returns number of items. */
sf_seek (file, sfinfo.frames, SEEK_SET) ;
- if ((k = sf_readf_float (file, data, datalen)) != 0)
+ if ((k = (int) sf_readf_float (file, data, datalen)) != 0)
{ printf ("\n\nLine %d: Return value from sf_readf_float past end of file incorrect (%d).\n", __LINE__, k) ;
exit (1) ;
} ;
/* Check seek backward from end. */
- if ((k = sf_seek (file, 5 - sfinfo.frames, SEEK_END)) != 5)
+ if ((k = (int) sf_seek (file, 5 - sfinfo.frames, SEEK_END)) != 5)
{ printf ("\n\nLine %d: sf_seek (SEEK_END) returned %d instead of %d.\n", __LINE__, k, 5) ;
exit (1) ;
} ;
double *orig, *data ;
double half_max_abs ;
+ get_unique_test_name (&filename, LCT_TEST_PREFIX) ;
print_test_name ("lcomp_test_double", filename) ;
datalen = BUFFER_SIZE / channels ;
data = data_buffer.d ;
orig = orig_buffer.d ;
- gen_signal_double (orig_buffer.d, 32000.0, channels, datalen) ;
+ gen_signal_double (orig_buffer.d, 32000.0, channels, (int) datalen) ;
for (k = 0 ; k < channels * datalen ; k++)
orig [k] = orig_buffer.d [k] ;
for (k = 0 ; k < datalen ; k++)
{ if (error_function (data [k], orig [k], margin))
{ printf ("\nLine %d: Incorrect sample A (#%d : %f should be %f).\n", __LINE__, k, data [k], orig [k]) ;
- oct_save_double (orig, data, datalen) ;
+ oct_save_double (orig, data, (int) datalen) ;
exit (1) ;
} ;
half_max_abs = LCT_MAX (half_max_abs, ABS (0.5 * data [k])) ;
exit (1) ;
} ;
- if ((k = sf_readf_double (file, data, datalen)) != sfinfo.frames - datalen)
+ if ((k = (int) sf_readf_double (file, data, datalen)) != sfinfo.frames - datalen)
{ printf ("\n\nLine %d: Incorrect read length (%" PRId64 " should be %d).\n", __LINE__,
channels * sfinfo.frames - datalen, k) ;
exit (1) ;
/* Now test sf_seek function. */
- if ((k = sf_seek (file, 0, SEEK_SET)) != 0)
+ if ((k = (int) sf_seek (file, 0, SEEK_SET)) != 0)
{ printf ("\n\nLine %d: Seek to start of file failed (%d).\n", __LINE__, k) ;
exit (1) ;
} ;
seekpos = BUFFER_SIZE / 10 ;
/* Check seek from start of file. */
- if ((k = sf_seek (file, seekpos, SEEK_SET)) != seekpos)
+ if ((k = (int) sf_seek (file, seekpos, SEEK_SET)) != seekpos)
{ printf ("Seek to start of file + %d failed (%d).\n", seekpos, k) ;
exit (1) ;
} ;
exit (1) ;
} ;
- if ((k = sf_seek (file, 0, SEEK_CUR)) != seekpos + 1)
+ if ((k = (int) sf_seek (file, 0, SEEK_CUR)) != seekpos + 1)
{ printf ("\n\nLine %d: sf_seek (SEEK_CUR) with 0 offset failed (%d should be %d)\n", __LINE__, k, seekpos + 1) ;
exit (1) ;
} ;
- seekpos = sf_seek (file, 0, SEEK_CUR) + BUFFER_SIZE / 5 ;
- k = sf_seek (file, BUFFER_SIZE / 5, SEEK_CUR) ;
+ seekpos = (int) sf_seek (file, 0, SEEK_CUR) + BUFFER_SIZE / 5 ;
+ k = (int) sf_seek (file, BUFFER_SIZE / 5, SEEK_CUR) ;
test_readf_double_or_die (file, 0, data, 1, __LINE__) ;
if (error_function (data [0], orig [seekpos * channels], margin) || k != seekpos)
{ printf ("\nLine %d: sf_seek (forwards, SEEK_CUR) followed by sf_readf_double failed (%f, %f) (%d, %d).\n", __LINE__, data [0], orig [seekpos * channels], k, seekpos + 1) ;
exit (1) ;
} ;
- seekpos = sf_seek (file, 0, SEEK_CUR) - 20 ;
+ seekpos = (int) sf_seek (file, 0, SEEK_CUR) - 20 ;
/* Check seek backward from current position. */
- k = sf_seek (file, -20, SEEK_CUR) ;
+ k = (int) sf_seek (file, -20, SEEK_CUR) ;
test_readf_double_or_die (file, 0, data, 1, __LINE__) ;
if (error_function (data [0], orig [seekpos * channels], margin) || k != seekpos)
{ printf ("\nLine %d: sf_seek (backwards, SEEK_CUR) followed by sf_readf_double failed (%f, %f) (%d, %d).\n", __LINE__, data [0], orig [seekpos * channels], k, seekpos) ;
/* Check that read past end of file returns number of items. */
sf_seek (file, sfinfo.frames, SEEK_SET) ;
- if ((k = sf_readf_double (file, data, datalen)) != 0)
+ if ((k = (int) sf_readf_double (file, data, datalen)) != 0)
{ printf ("\n\nLine %d: Return value from sf_readf_double past end of file incorrect (%d).\n", __LINE__, k) ;
exit (1) ;
} ;
/* Check seek backward from end. */
- if ((k = sf_seek (file, 5 - sfinfo.frames, SEEK_END)) != 5)
+ if ((k = (int) sf_seek (file, 5 - sfinfo.frames, SEEK_END)) != 5)
{ printf ("\n\nLine %d: sf_seek (SEEK_END) returned %d instead of %d.\n", __LINE__, k, 5) ;
exit (1) ;
} ;
short *orig, *data, *smooth ;
channels = 1 ;
+
+ get_unique_test_name (&filename, LCT_TEST_PREFIX) ;
print_test_name ("sdlcomp_test_short", filename) ;
datalen = BUFFER_SIZE ;
data = data_buffer.s ;
smooth = smooth_buffer.s ;
- gen_signal_double (orig_buffer.d, 32000.0, channels, datalen) ;
+ gen_signal_double (orig_buffer.d, 32000.0, channels, (int) datalen) ;
for (k = 0 ; k < datalen ; k++)
- orig [k] = lrint (orig_buffer.d [k]) ;
+ orig [k] = (short) lrint (orig_buffer.d [k]) ;
sfinfo.samplerate = SAMPLE_RATE ;
sfinfo.frames = 123456789 ; /* Ridiculous value. */
if ((filetype & SF_FORMAT_SUBMASK) == SF_FORMAT_OPUS && !check_opus_version (file))
{ sf_close (file) ;
+ unlink (filename) ;
return ;
} ;
test_readf_short_or_die (file, 0, data, datalen, __LINE__) ;
memcpy (smooth, orig, datalen * sizeof (short)) ;
- smoothed_diff_short (data, datalen) ;
- smoothed_diff_short (smooth, datalen) ;
+ smoothed_diff_short (data, (unsigned int) datalen) ;
+ smoothed_diff_short (smooth, (unsigned int) datalen) ;
- half_max_abs = 0.0 ;
+ half_max_abs = 0 ;
for (k = 0 ; k < datalen ; k++)
{ if (error_function (1.0 * data [k], 1.0 * smooth [k], margin))
{ printf ("\nLine %d: Incorrect sample (#%d : %d should be %d).\n", __LINE__, k, data [k], smooth [k]) ;
- oct_save_short (orig, smooth, datalen) ;
+ oct_save_short (orig, smooth, (int) datalen) ;
exit (1) ;
} ;
- half_max_abs = LCT_MAX (half_max_abs, ABS (0.5 * data [k])) ;
+ half_max_abs = (int) (LCT_MAX (half_max_abs, ABS (0.5 * data [k]))) ;
} ;
if (half_max_abs < 1)
exit (1) ;
} ;
- if ((k = sf_read_short (file, data, datalen)) != sfinfo.frames - datalen)
+ if ((k = (int) sf_read_short (file, data, datalen)) != sfinfo.frames - datalen)
{ printf ("\n\nLine %d: Incorrect read length (%d should be %" PRId64 ").\n", __LINE__, k, sfinfo.frames - datalen) ;
exit (1) ;
} ;
/* Now test sf_seek function. */
if (sfinfo.seekable)
- { if ((k = sf_seek (file, 0, SEEK_SET)) != 0)
+ { if ((k = (int) sf_seek (file, 0, SEEK_SET)) != 0)
{ printf ("\n\nLine %d: Seek to start of file failed (%d).\n", __LINE__, k) ;
exit (1) ;
} ;
for (m = 0 ; m < 3 ; m++)
{ test_readf_short_or_die (file, m, data, datalen / 7, __LINE__) ;
- smoothed_diff_short (data, datalen / 7) ;
+ smoothed_diff_short (data, (unsigned int) (datalen / 7)) ;
memcpy (smooth, orig + m * datalen / 7, datalen / 7 * sizeof (short)) ;
- smoothed_diff_short (smooth, datalen / 7) ;
+ smoothed_diff_short (smooth, (unsigned int) (datalen / 7)) ;
for (k = 0 ; k < datalen / 7 ; k++)
if (error_function (1.0 * data [k], 1.0 * smooth [k], margin))
seekpos = BUFFER_SIZE / 10 ;
/* Check seek from start of file. */
- if ((k = sf_seek (file, seekpos, SEEK_SET)) != seekpos)
+ if ((k = (int) sf_seek (file, seekpos, SEEK_SET)) != seekpos)
{ printf ("Seek to start of file + %d failed (%d).\n", seekpos, k) ;
exit (1) ;
} ;
exit (1) ;
} ;
- if ((k = sf_seek (file, 0, SEEK_CUR)) != seekpos + 1)
+ if ((k = (int) sf_seek (file, 0, SEEK_CUR)) != seekpos + 1)
{ printf ("\n\nLine %d: sf_seek (SEEK_CUR) with 0 offset failed (%d should be %d)\n", __LINE__, k, seekpos + 1) ;
exit (1) ;
} ;
- seekpos = sf_seek (file, 0, SEEK_CUR) + BUFFER_SIZE / 5 ;
- k = sf_seek (file, BUFFER_SIZE / 5, SEEK_CUR) ;
+ seekpos = (int) sf_seek (file, 0, SEEK_CUR) + BUFFER_SIZE / 5 ;
+ k = (int) sf_seek (file, BUFFER_SIZE / 5, SEEK_CUR) ;
test_readf_short_or_die (file, 0, data, 1, __LINE__) ;
if (error_function (1.0 * data [0], 1.0 * orig [seekpos * channels], margin) || k != seekpos)
{ printf ("\nLine %d: sf_seek (forwards, SEEK_CUR) followed by sf_read_short failed (%d, %d) (%d, %d).\n", __LINE__, data [0], orig [seekpos * channels], k, seekpos + 1) ;
exit (1) ;
} ;
- seekpos = sf_seek (file, 0, SEEK_CUR) - 20 ;
+ seekpos = (int) sf_seek (file, 0, SEEK_CUR) - 20 ;
/* Check seek backward from current position. */
- k = sf_seek (file, -20, SEEK_CUR) ;
+ k = (int) sf_seek (file, -20, SEEK_CUR) ;
test_readf_short_or_die (file, 0, data, 1, __LINE__) ;
if (error_function (1.0 * data [0], 1.0 * orig [seekpos * channels], margin) || k != seekpos)
{ printf ("\nLine %d: sf_seek (backwards, SEEK_CUR) followed by sf_read_short failed (%d, %d) (%d, %d).\n", __LINE__, data [0], orig [seekpos * channels], k, seekpos) ;
/* Check that read past end of file returns number of items. */
sf_seek (file, sfinfo.frames, SEEK_SET) ;
- if ((k = sf_read_short (file, data, datalen)) != 0)
+ if ((k = (int) sf_read_short (file, data, datalen)) != 0)
{ printf ("\n\nLine %d: Return value from sf_read_short past end of file incorrect (%d).\n", __LINE__, k) ;
exit (1) ;
} ;
/* Check seek backward from end. */
- if ((k = sf_seek (file, 5 - sfinfo.frames, SEEK_END)) != 5)
+ if ((k = (int) sf_seek (file, 5 - sfinfo.frames, SEEK_END)) != 5)
{ printf ("\n\nLine %d: sf_seek (SEEK_END) returned %d instead of %d.\n", __LINE__, k, 5) ;
exit (1) ;
} ;
channels = 1 ;
+ get_unique_test_name (&filename, LCT_TEST_PREFIX) ;
print_test_name ("sdlcomp_test_int", filename) ;
datalen = BUFFER_SIZE ;
data = data_buffer.i ;
smooth = smooth_buffer.i ;
- gen_signal_double (orig_buffer.d, 32000.0 * scale, channels, datalen) ;
+ gen_signal_double (orig_buffer.d, 32000.0 * scale, channels, (int) datalen) ;
for (k = 0 ; k < datalen ; k++)
orig [k] = lrint (orig_buffer.d [k]) ;
if ((filetype & SF_FORMAT_SUBMASK) == SF_FORMAT_OPUS && !check_opus_version (file))
{ sf_close (file) ;
+ unlink (filename) ;
return ;
} ;
test_readf_int_or_die (file, 0, data, datalen, __LINE__) ;
memcpy (smooth, orig, datalen * sizeof (int)) ;
- smoothed_diff_int (data, datalen) ;
- smoothed_diff_int (smooth, datalen) ;
+ smoothed_diff_int (data, (unsigned int) datalen) ;
+ smoothed_diff_int (smooth, (unsigned int) datalen) ;
half_max_abs = abs (data [0] >> 16) ;
for (k = 1 ; k < datalen ; k++)
{ if (error_function (data [k] / scale, smooth [k] / scale, margin))
{ printf ("\nLine %d: Incorrect sample (#%d : %d should be %d).\n", __LINE__, k, data [k], smooth [k]) ;
- oct_save_int (orig, smooth, datalen) ;
+ oct_save_int (orig, smooth, (int) datalen) ;
exit (1) ;
} ;
half_max_abs = LCT_MAX (half_max_abs, abs (data [k] / 2)) ;
exit (1) ;
} ;
- if ((k = sf_readf_int (file, data, datalen)) != sfinfo.frames - datalen)
+ if ((k = (int) sf_readf_int (file, data, datalen)) != sfinfo.frames - datalen)
{ printf ("\n\nLine %d: Incorrect read length (%d should be %" PRId64 ").\n", __LINE__, k, sfinfo.frames - datalen) ;
exit (1) ;
} ;
/* Now test sf_seek function. */
if (sfinfo.seekable)
- { if ((k = sf_seek (file, 0, SEEK_SET)) != 0)
+ { if ((k = (int) sf_seek (file, 0, SEEK_SET)) != 0)
{ printf ("\n\nLine %d: Seek to start of file failed (%d).\n", __LINE__, k) ;
exit (1) ;
} ;
for (m = 0 ; m < 3 ; m++)
{ test_readf_int_or_die (file, m, data, datalen / 7, __LINE__) ;
- smoothed_diff_int (data, datalen / 7) ;
+ smoothed_diff_int (data, (unsigned int) (datalen / 7)) ;
memcpy (smooth, orig + m * datalen / 7, datalen / 7 * sizeof (int)) ;
- smoothed_diff_int (smooth, datalen / 7) ;
+ smoothed_diff_int (smooth, (unsigned int) (datalen / 7)) ;
for (k = 0 ; k < datalen / 7 ; k++)
if (error_function (data [k] / scale, smooth [k] / scale, margin))
seekpos = BUFFER_SIZE / 10 ;
/* Check seek from start of file. */
- if ((k = sf_seek (file, seekpos, SEEK_SET)) != seekpos)
+ if ((k = (int) sf_seek (file, seekpos, SEEK_SET)) != seekpos)
{ printf ("Seek to start of file + %d failed (%d).\n", seekpos, k) ;
exit (1) ;
} ;
exit (1) ;
} ;
- if ((k = sf_seek (file, 0, SEEK_CUR)) != seekpos + 1)
+ if ((k = (int) sf_seek (file, 0, SEEK_CUR)) != seekpos + 1)
{ printf ("\n\nLine %d: sf_seek (SEEK_CUR) with 0 offset failed (%d should be %d)\n", __LINE__, k, seekpos + 1) ;
exit (1) ;
} ;
- seekpos = sf_seek (file, 0, SEEK_CUR) + BUFFER_SIZE / 5 ;
- k = sf_seek (file, BUFFER_SIZE / 5, SEEK_CUR) ;
+ seekpos = (int) sf_seek (file, 0, SEEK_CUR) + BUFFER_SIZE / 5 ;
+ k = (int) sf_seek (file, BUFFER_SIZE / 5, SEEK_CUR) ;
test_readf_int_or_die (file, 0, data, 1, __LINE__) ;
if (error_function (1.0 * data [0], 1.0 * orig [seekpos * channels], margin) || k != seekpos)
{ printf ("\nLine %d: sf_seek (forwards, SEEK_CUR) followed by sf_readf_int failed (%d, %d) (%d, %d).\n", __LINE__, data [0], orig [seekpos * channels], k, seekpos + 1) ;
exit (1) ;
} ;
- seekpos = sf_seek (file, 0, SEEK_CUR) - 20 ;
+ seekpos = (int) sf_seek (file, 0, SEEK_CUR) - 20 ;
/* Check seek backward from current position. */
- k = sf_seek (file, -20, SEEK_CUR) ;
+ k = (int) sf_seek (file, -20, SEEK_CUR) ;
test_readf_int_or_die (file, 0, data, 1, __LINE__) ;
if (error_function (1.0 * data [0], 1.0 * orig [seekpos * channels], margin) || k != seekpos)
{ printf ("\nLine %d: sf_seek (backwards, SEEK_CUR) followed by sf_readf_int failed (%d, %d) (%d, %d).\n", __LINE__, data [0], orig [seekpos * channels], k, seekpos) ;
/* Check that read past end of file returns number of items. */
sf_seek (file, sfinfo.frames, SEEK_SET) ;
- if ((k = sf_readf_int (file, data, datalen)) != 0)
+ if ((k = (int) sf_readf_int (file, data, datalen)) != 0)
{ printf ("\n\nLine %d: Return value from sf_readf_int past end of file incorrect (%d).\n", __LINE__, k) ;
exit (1) ;
} ;
/* Check seek backward from end. */
- if ((k = sf_seek (file, 5 - sfinfo.frames, SEEK_END)) != 5)
+ if ((k = (int) sf_seek (file, 5 - sfinfo.frames, SEEK_END)) != 5)
{ printf ("\n\nLine %d: sf_seek (SEEK_END) returned %d instead of %d.\n", __LINE__, k, 5) ;
exit (1) ;
} ;
channels = 1 ;
+ get_unique_test_name (&filename, LCT_TEST_PREFIX) ;
print_test_name ("sdlcomp_test_float", filename) ;
switch ((filetype & SF_FORMAT_SUBMASK))
data = data_buffer.f ;
smooth = smooth_buffer.f ;
- gen_signal_double (orig_buffer.d, 32000.0 / scale, channels, datalen) ;
+ gen_signal_double (orig_buffer.d, 32000.0 / scale, channels, (int) datalen) ;
for (k = 0 ; k < datalen ; k++)
- orig [k] = orig_buffer.d [k] ;
+ orig [k] = (float) orig_buffer.d [k] ;
sfinfo.samplerate = SAMPLE_RATE ;
sfinfo.frames = 123456789 ; /* Ridiculous value. */
if ((filetype & SF_FORMAT_SUBMASK) == SF_FORMAT_OPUS && !check_opus_version (file))
{ sf_close (file) ;
+ unlink (filename) ;
return ;
} ;
test_read_float_or_die (file, 0, data, datalen, __LINE__) ;
memcpy (smooth, orig, datalen * sizeof (float)) ;
- smoothed_diff_float (data, datalen) ;
- smoothed_diff_float (smooth, datalen) ;
+ smoothed_diff_float (data, (unsigned int) datalen) ;
+ smoothed_diff_float (smooth, (unsigned int) datalen) ;
half_max_abs = fabs (data [0]) ;
for (k = 1 ; k < datalen ; k++)
{ if (error_function (data [k] * scale, smooth [k] * scale, margin))
{ printf ("\nLine %d: Incorrect sample (#%d : %d should be %d).\n", __LINE__, k, (int) (data [k] * scale), (int) (smooth [k] * scale)) ;
- oct_save_float (orig, smooth, datalen) ;
+ oct_save_float (orig, smooth, (int) datalen) ;
exit (1) ;
} ;
half_max_abs = LCT_MAX (half_max_abs, ABS (0.5 * data [k] * scale)) ;
exit (1) ;
} ;
- if ((k = sf_read_float (file, data, datalen)) != sfinfo.frames - datalen)
+ if ((k = (int) sf_read_float (file, data, datalen)) != sfinfo.frames - datalen)
{ printf ("\n\nLine %d: Incorrect read length (%d should be %" PRId64 ").\n", __LINE__, k, sfinfo.frames - datalen) ;
exit (1) ;
} ;
/* Now test sf_seek function. */
if (sfinfo.seekable)
- { if ((k = sf_seek (file, 0, SEEK_SET)) != 0)
+ { if ((k = (int) sf_seek (file, 0, SEEK_SET)) != 0)
{ printf ("\n\nLine %d: Seek to start of file failed (%d).\n", __LINE__, k) ;
exit (1) ;
} ;
for (m = 0 ; m < 3 ; m++)
{ test_read_float_or_die (file, 0, data, datalen / 7, __LINE__) ;
- smoothed_diff_float (data, datalen / 7) ;
+ smoothed_diff_float (data, (unsigned int) (datalen / 7)) ;
memcpy (smooth, orig + m * datalen / 7, datalen / 7 * sizeof (float)) ;
- smoothed_diff_float (smooth, datalen / 7) ;
+ smoothed_diff_float (smooth, (unsigned int) (datalen / 7)) ;
for (k = 0 ; k < datalen / 7 ; k++)
if (error_function (data [k] * scale, smooth [k] * scale, margin))
seekpos = BUFFER_SIZE / 10 ;
/* Check seek from start of file. */
- if ((k = sf_seek (file, seekpos, SEEK_SET)) != seekpos)
+ if ((k = (int) sf_seek (file, seekpos, SEEK_SET)) != seekpos)
{ printf ("Seek to start of file + %d failed (%d).\n", seekpos, k) ;
exit (1) ;
} ;
exit (1) ;
} ;
- if ((k = sf_seek (file, 0, SEEK_CUR)) != seekpos + 1)
+ if ((k = (int) sf_seek (file, 0, SEEK_CUR)) != seekpos + 1)
{ printf ("\n\nLine %d: sf_seek (SEEK_CUR) with 0 offset failed (%d should be %d)\n", __LINE__, k, seekpos + 1) ;
exit (1) ;
} ;
- seekpos = sf_seek (file, 0, SEEK_CUR) + BUFFER_SIZE / 5 ;
- k = sf_seek (file, BUFFER_SIZE / 5, SEEK_CUR) ;
+ seekpos = (int) sf_seek (file, 0, SEEK_CUR) + BUFFER_SIZE / 5 ;
+ k = (int) sf_seek (file, BUFFER_SIZE / 5, SEEK_CUR) ;
test_read_float_or_die (file, 0, data, channels, __LINE__) ;
if (error_function (data [0] * scale, orig [seekpos * channels] * scale, margin) || k != seekpos)
{ printf ("\nLine %d: sf_seek (forwards, SEEK_CUR) followed by sf_read_float failed (%d, %d) (%d, %d).\n", __LINE__, (int) (data [0] * scale), (int) (orig [seekpos * channels] * scale), k, seekpos + 1) ;
exit (1) ;
} ;
- seekpos = sf_seek (file, 0, SEEK_CUR) - 20 ;
+ seekpos = (int) sf_seek (file, 0, SEEK_CUR) - 20 ;
/* Check seek backward from current position. */
- k = sf_seek (file, -20, SEEK_CUR) ;
+ k = (int) sf_seek (file, -20, SEEK_CUR) ;
test_read_float_or_die (file, 0, data, channels, __LINE__) ;
if (error_function (data [0] * scale, orig [seekpos * channels] * scale, margin) || k != seekpos)
{ printf ("\nLine %d: sf_seek (backwards, SEEK_CUR) followed by sf_read_float failed (%d, %d) (%d, %d).\n", __LINE__, (int) (data [0] * scale), (int) (orig [seekpos * channels] * scale), k, seekpos) ;
/* Check that read past end of file returns number of items. */
sf_seek (file, sfinfo.frames, SEEK_SET) ;
- if ((k = sf_read_float (file, data, datalen)) != 0)
+ if ((k = (int) sf_read_float (file, data, datalen)) != 0)
{ printf ("\n\nLine %d: Return value from sf_read_float past end of file incorrect (%d).\n", __LINE__, k) ;
exit (1) ;
} ;
/* Check seek backward from end. */
- if ((k = sf_seek (file, 5 - sfinfo.frames, SEEK_END)) != 5)
+ if ((k = (int) sf_seek (file, 5 - sfinfo.frames, SEEK_END)) != 5)
{ printf ("\n\nLine %d: sf_seek (SEEK_END) returned %d instead of %d.\n", __LINE__, k, 5) ;
exit (1) ;
} ;
double *orig, *data, *smooth, half_max_abs, scale ;
channels = 1 ;
+
+ get_unique_test_name (&filename, LCT_TEST_PREFIX) ;
print_test_name ("sdlcomp_test_double", filename) ;
switch ((filetype & SF_FORMAT_SUBMASK))
data = data_buffer.d ;
smooth = smooth_buffer.d ;
- gen_signal_double (orig_buffer.d, 32000.0 / scale, channels, datalen) ;
+ gen_signal_double (orig_buffer.d, 32000.0 / scale, channels, (int) datalen) ;
sfinfo.samplerate = SAMPLE_RATE ;
sfinfo.frames = 123456789 ; /* Ridiculous value. */
if ((filetype & SF_FORMAT_SUBMASK) == SF_FORMAT_OPUS && !check_opus_version (file))
{ sf_close (file) ;
+ unlink (filename) ;
return ;
} ;
test_read_double_or_die (file, 0, data, datalen, __LINE__) ;
memcpy (smooth, orig, datalen * sizeof (double)) ;
- smoothed_diff_double (data, datalen) ;
- smoothed_diff_double (smooth, datalen) ;
+ smoothed_diff_double (data, (unsigned int) datalen) ;
+ smoothed_diff_double (smooth, (unsigned int) datalen) ;
half_max_abs = 0.0 ;
for (k = 0 ; k < datalen ; k++)
{ if (error_function (data [k] * scale, smooth [k] * scale, margin))
{ printf ("\n\nLine %d: Incorrect sample (#%d : %d should be %d).\n", __LINE__, k, (int) (data [k] * scale), (int) (smooth [k] * scale)) ;
- oct_save_double (orig, smooth, datalen) ;
+ oct_save_double (orig, smooth, (int) datalen) ;
exit (1) ;
} ;
half_max_abs = LCT_MAX (half_max_abs, 0.5 * fabs (data [k] * scale)) ;
exit (1) ;
} ;
- if ((k = sf_read_double (file, data, datalen)) != sfinfo.frames - datalen)
+ if ((k = (int) sf_read_double (file, data, datalen)) != sfinfo.frames - datalen)
{ printf ("\n\nLine %d: Incorrect read length (%d should be %" PRId64 ").\n", __LINE__, k, sfinfo.frames - datalen) ;
exit (1) ;
} ;
/* Now test sf_seek function. */
if (sfinfo.seekable)
- { if ((k = sf_seek (file, 0, SEEK_SET)) != 0)
+ { if ((k = (int) sf_seek (file, 0, SEEK_SET)) != 0)
{ printf ("\n\nLine %d: Seek to start of file failed (%d).\n", __LINE__, k) ;
exit (1) ;
} ;
for (m = 0 ; m < 3 ; m++)
{ test_read_double_or_die (file, m, data, datalen / 7, __LINE__) ;
- smoothed_diff_double (data, datalen / 7) ;
+ smoothed_diff_double (data, (unsigned int) (datalen / 7)) ;
memcpy (smooth, orig + m * datalen / 7, datalen / 7 * sizeof (double)) ;
- smoothed_diff_double (smooth, datalen / 7) ;
+ smoothed_diff_double (smooth, (unsigned int) (datalen / 7)) ;
for (k = 0 ; k < datalen / 7 ; k++)
if (error_function (data [k] * scale, smooth [k] * scale, margin))
seekpos = BUFFER_SIZE / 10 ;
/* Check seek from start of file. */
- if ((k = sf_seek (file, seekpos, SEEK_SET)) != seekpos)
+ if ((k = (int) sf_seek (file, seekpos, SEEK_SET)) != seekpos)
{ printf ("Seek to start of file + %d failed (%d).\n", seekpos, k) ;
exit (1) ;
} ;
exit (1) ;
} ;
- if ((k = sf_seek (file, 0, SEEK_CUR)) != seekpos + 1)
+ if ((k = (int) sf_seek (file, 0, SEEK_CUR)) != seekpos + 1)
{ printf ("\n\nLine %d: sf_seek (SEEK_CUR) with 0 offset failed (%d should be %d)\n", __LINE__, k, seekpos + 1) ;
exit (1) ;
} ;
- seekpos = sf_seek (file, 0, SEEK_CUR) + BUFFER_SIZE / 5 ;
- k = sf_seek (file, BUFFER_SIZE / 5, SEEK_CUR) ;
+ seekpos = (int) sf_seek (file, 0, SEEK_CUR) + BUFFER_SIZE / 5 ;
+ k = (int) sf_seek (file, BUFFER_SIZE / 5, SEEK_CUR) ;
test_read_double_or_die (file, 0, data, channels, __LINE__) ;
if (error_function (data [0] * scale, orig [seekpos * channels] * scale, margin) || k != seekpos)
{ printf ("\nLine %d: sf_seek (forwards, SEEK_CUR) followed by sf_read_double failed (%d, %d) (%d, %d).\n", __LINE__, (int) (data [0] * scale), (int) (orig [seekpos * channels] * scale), k, seekpos + 1) ;
exit (1) ;
} ;
- seekpos = sf_seek (file, 0, SEEK_CUR) - 20 ;
+ seekpos = (int) sf_seek (file, 0, SEEK_CUR) - 20 ;
/* Check seek backward from current position. */
- k = sf_seek (file, -20, SEEK_CUR) ;
+ k = (int) sf_seek (file, -20, SEEK_CUR) ;
test_read_double_or_die (file, 0, data, channels, __LINE__) ;
if (error_function (data [0] * scale, orig [seekpos * channels] * scale, margin) || k != seekpos)
{ printf ("\nLine %d: sf_seek (backwards, SEEK_CUR) followed by sf_read_double failed (%d, %d) (%d, %d).\n", __LINE__, (int) (data [0] * scale), (int) (orig [seekpos * channels] * scale), k, seekpos) ;
/* Check that read past end of file returns number of items. */
sf_seek (file, sfinfo.frames, SEEK_SET) ;
- if ((k = sf_read_double (file, data, datalen)) != 0)
+ if ((k = (int) sf_read_double (file, data, datalen)) != 0)
{ printf ("\n\nLine %d: Return value from sf_read_double past end of file incorrect (%d).\n", __LINE__, k) ;
exit (1) ;
} ;
/* Check seek backward from end. */
- if ((k = sf_seek (file, 5 - sfinfo.frames, SEEK_END)) != 5)
+ if ((k = (int) sf_seek (file, 5 - sfinfo.frames, SEEK_END)) != 5)
{ printf ("\n\nLine %d: sf_seek (SEEK_END) returned %d instead of %d.\n", __LINE__, k, 5) ;
exit (1) ;
} ;
short *orig, *data ;
int k ;
+ get_unique_test_name (&filename, LCT_TEST_PREFIX) ;
print_test_name ("read_raw_test", filename) ;
datalen = ARRAY_LEN (orig_buffer.s) / 2 ;
orig = orig_buffer.s ;
data = data_buffer.s ;
- gen_signal_double (orig_buffer.d, 32000.0, channels, datalen) ;
+ gen_signal_double (orig_buffer.d, 32000.0, channels, (int) datalen) ;
for (k = 0 ; k < datalen ; k++)
- orig [k] = lrint (orig_buffer.d [k]) ;
+ orig [k] = (short) lrint (orig_buffer.d [k]) ;
sfinfo.samplerate = SAMPLE_RATE ;
sfinfo.frames = 123456789 ; /* Ridiculous value. */
/* Calculate the smoothed sample-to-sample difference. */
for (k = 0 ; k < datalen - 1 ; k++)
- { memory = 0.7 * memory + (1 - 0.7) * (data [k+1] - data [k]) ;
+ { memory = (float) (0.7 * memory + (1 - 0.7) * (data [k+1] - data [k])) ;
data [k] = memory ;
} ;
data [datalen-1] = data [datalen-2] ;
--- /dev/null
+/*
+** Copyright (C) 2007-2019 Erik de Castro Lopo <erikd@mega-nerd.com>
+** Copyright (C) 2019 John ffitch <jpff@codemist.co.uk>
+**
+** 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 "sfconfig.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#if HAVE_UNISTD_H
+#include <unistd.h>
+#else
+#include "sf_unistd.h"
+#endif
+
+#include <math.h>
+
+#include <sndfile.h>
+
+#include "utils.h"
+
+#define SAMPLE_RATE 44100
+#define DATA_LENGTH (SAMPLE_RATE / 8)
+
+typedef union
+{ double d [DATA_LENGTH] ;
+ float f [DATA_LENGTH] ;
+ int i [DATA_LENGTH] ;
+ short s [DATA_LENGTH] ;
+} BUFFER ;
+
+static BUFFER data_out ;
+static BUFFER data_in ;
+
+static void
+mpeg_short_test (void)
+{ const char * filename = "mpeg_short.mp3" ;
+
+ SNDFILE * file ;
+ SF_INFO sfinfo ;
+ short seek_data [10] ;
+ unsigned k ;
+
+ print_test_name ("mpeg_short_test", filename) ;
+
+ /* Generate float data. */
+ gen_windowed_sine_float (data_out.f, ARRAY_LEN (data_out.f), 1.0 * 0x7F00) ;
+
+ /* Convert to shorteger. */
+ for (k = 0 ; k < ARRAY_LEN (data_out.s) ; k++)
+ data_out.s [k] = lrintf (data_out.f [k]) ;
+
+ memset (&sfinfo, 0, sizeof (sfinfo)) ;
+
+ /* Set up output file type. */
+ sfinfo.format = SF_FORMAT_MPEG | SF_FORMAT_MPEG_LAYER_III ;
+ sfinfo.channels = 1 ;
+ sfinfo.samplerate = SAMPLE_RATE ;
+
+ /* Write the output file. */
+ file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_FALSE, __LINE__) ;
+ test_write_short_or_die (file, 0, data_out.s, ARRAY_LEN (data_out.s), __LINE__) ;
+ sf_close (file) ;
+
+ /* Read the file in again. */
+ memset (&sfinfo, 0, sizeof (sfinfo)) ;
+
+ file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
+ test_read_short_or_die (file, 0, data_in.s, ARRAY_LEN (data_in.s), __LINE__) ;
+ sf_close (file) ;
+
+ puts ("ok") ;
+
+ /* Test seeking. */
+ print_test_name ("mpeg_seek_test", filename) ;
+
+ file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
+
+ test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ;
+ test_read_short_or_die (file, 0, seek_data, ARRAY_LEN (seek_data), __LINE__) ;
+ compare_short_or_die (seek_data, data_in.s + 10, ARRAY_LEN (seek_data), __LINE__) ;
+
+ /* Test seek to end of file. */
+ test_seek_or_die (file, 0, SEEK_END, sfinfo.frames, sfinfo.channels, __LINE__) ;
+
+ sf_close (file) ;
+
+ puts ("ok") ;
+
+ unlink (filename) ;
+} /* mpeg_short_test */
+
+static void
+mpeg_int_test (void)
+{ const char * filename = "mpeg_int.mp3" ;
+
+ SNDFILE * file ;
+ SF_INFO sfinfo ;
+ int seek_data [10] ;
+ unsigned k ;
+
+ print_test_name ("mpeg_int_test", filename) ;
+
+ /* Generate float data. */
+ gen_windowed_sine_float (data_out.f, ARRAY_LEN (data_out.f), 1.0 * 0x7FFF0000) ;
+
+ /* Convert to integer. */
+ for (k = 0 ; k < ARRAY_LEN (data_out.i) ; k++)
+ data_out.i [k] = lrintf (data_out.f [k]) ;
+
+ memset (&sfinfo, 0, sizeof (sfinfo)) ;
+
+ /* Set up output file type. */
+ sfinfo.format = SF_FORMAT_MPEG | SF_FORMAT_MPEG_LAYER_III ;
+ sfinfo.channels = 1 ;
+ sfinfo.samplerate = SAMPLE_RATE ;
+
+ /* Write the output file. */
+ file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_FALSE, __LINE__) ;
+ test_write_int_or_die (file, 0, data_out.i, ARRAY_LEN (data_out.i), __LINE__) ;
+ sf_close (file) ;
+
+ /* Read the file in again. */
+ memset (&sfinfo, 0, sizeof (sfinfo)) ;
+
+ file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
+ test_read_int_or_die (file, 0, data_in.i, ARRAY_LEN (data_in.i), __LINE__) ;
+ sf_close (file) ;
+
+ puts ("ok") ;
+
+ /* Test seeking. */
+ print_test_name ("mpeg_seek_test", filename) ;
+
+ file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
+
+ test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ;
+ test_read_int_or_die (file, 0, seek_data, ARRAY_LEN (seek_data), __LINE__) ;
+ compare_int_or_die (seek_data, data_in.i + 10, ARRAY_LEN (seek_data), __LINE__) ;
+
+ sf_close (file) ;
+
+ puts ("ok") ;
+
+ unlink (filename) ;
+} /* mpeg_int_test */
+
+static void
+mpeg_float_test (void)
+{ const char * filename = "mpeg_float.mp3" ;
+
+ SNDFILE * file ;
+ SF_INFO sfinfo ;
+ float seek_data [10] ;
+
+ print_test_name ("mpeg_float_test", filename) ;
+
+ gen_windowed_sine_float (data_out.f, ARRAY_LEN (data_out.f), 0.95) ;
+
+ memset (&sfinfo, 0, sizeof (sfinfo)) ;
+
+ /* Set up output file type. */
+ sfinfo.format = SF_FORMAT_MPEG | SF_FORMAT_MPEG_LAYER_III ;
+ sfinfo.channels = 1 ;
+ sfinfo.samplerate = SAMPLE_RATE ;
+
+ /* Write the output file. */
+ file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_FALSE, __LINE__) ;
+ test_write_float_or_die (file, 0, data_out.f, ARRAY_LEN (data_out.f), __LINE__) ;
+ sf_close (file) ;
+
+ /* Read the file in again. */
+ memset (&sfinfo, 0, sizeof (sfinfo)) ;
+
+ file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
+ test_read_float_or_die (file, 0, data_in.f, ARRAY_LEN (data_in.f), __LINE__) ;
+ sf_close (file) ;
+
+ puts ("ok") ;
+
+ /* Test seeking. */
+ print_test_name ("mpeg_seek_test", filename) ;
+
+ file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
+
+ test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ;
+ test_read_float_or_die (file, 0, seek_data, ARRAY_LEN (seek_data), __LINE__) ;
+ compare_float_or_die (seek_data, data_in.f + 10, ARRAY_LEN (seek_data), __LINE__) ;
+
+ sf_close (file) ;
+
+ puts ("ok") ;
+
+ unlink (filename) ;
+} /* mpeg_float_test */
+
+static void
+mpeg_double_test (void)
+{ const char * filename = "mpeg_double.mp3" ;
+
+ SNDFILE * file ;
+ SF_INFO sfinfo ;
+ double seek_data [10] ;
+
+ print_test_name ("mpeg_double_test", filename) ;
+
+ gen_windowed_sine_double (data_out.d, ARRAY_LEN (data_out.d), 0.95) ;
+
+ memset (&sfinfo, 0, sizeof (sfinfo)) ;
+
+ /* Set up output file type. */
+ sfinfo.format = SF_FORMAT_MPEG | SF_FORMAT_MPEG_LAYER_III ;
+ sfinfo.channels = 1 ;
+ sfinfo.samplerate = SAMPLE_RATE ;
+
+ /* Write the output file. */
+ file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_FALSE, __LINE__) ;
+ test_write_double_or_die (file, 0, data_out.d, ARRAY_LEN (data_out.d), __LINE__) ;
+ sf_close (file) ;
+
+ /* Read the file in again. */
+ memset (&sfinfo, 0, sizeof (sfinfo)) ;
+
+ file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
+ test_read_double_or_die (file, 0, data_in.d, ARRAY_LEN (data_in.d), __LINE__) ;
+ sf_close (file) ;
+
+ puts ("ok") ;
+
+ /* Test seeking. */
+ print_test_name ("mpeg_seek_test", filename) ;
+
+ file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
+
+ test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ;
+ test_read_double_or_die (file, 0, seek_data, ARRAY_LEN (seek_data), __LINE__) ;
+ compare_double_or_die (seek_data, data_in.d + 10, ARRAY_LEN (seek_data), __LINE__) ;
+
+ sf_close (file) ;
+
+ puts ("ok") ;
+
+ unlink (filename) ;
+} /* mpeg_double_test */
+
+
+static void
+mpeg_stereo_seek_test (const char * filename, int format)
+{ static float data [SAMPLE_RATE] ;
+ static float stereo_out [SAMPLE_RATE * 2] ;
+
+ SNDFILE * file ;
+ SF_INFO sfinfo ;
+ sf_count_t pos ;
+ unsigned k ;
+
+ print_test_name (__func__, filename) ;
+
+ gen_windowed_sine_float (data, ARRAY_LEN (data), 0.95) ;
+ for (k = 0 ; k < ARRAY_LEN (data) ; k++)
+ { stereo_out [2 * k] = data [k] ;
+ stereo_out [2 * k + 1] = data [ARRAY_LEN (data) - k - 1] ;
+ } ;
+
+ memset (&sfinfo, 0, sizeof (sfinfo)) ;
+
+ /* Set up output file type. */
+ sfinfo.format = format ;
+ sfinfo.channels = 2 ;
+ sfinfo.samplerate = SAMPLE_RATE ;
+
+ /* Write the output file. */
+ file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_FALSE, __LINE__) ;
+ test_write_float_or_die (file, 0, stereo_out, ARRAY_LEN (stereo_out), __LINE__) ;
+ sf_close (file) ;
+
+ /* Open file in again for reading. */
+ memset (&sfinfo, 0, sizeof (sfinfo)) ;
+ file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
+
+ /* Read in the whole file. */
+ test_read_float_or_die (file, 0, stereo_out, ARRAY_LEN (stereo_out), __LINE__) ;
+
+ /* Now hammer seeking code. */
+ test_seek_or_die (file, 234, SEEK_SET, 234, sfinfo.channels, __LINE__) ;
+ test_readf_float_or_die (file, 0, data, 10, __LINE__) ;
+ compare_float_or_die (data, stereo_out + (234 * sfinfo.channels), 10, __LINE__) ;
+
+ test_seek_or_die (file, 442, SEEK_SET, 442, sfinfo.channels, __LINE__) ;
+ test_readf_float_or_die (file, 0, data, 10, __LINE__) ;
+ compare_float_or_die (data, stereo_out + (442 * sfinfo.channels), 10, __LINE__) ;
+
+ test_seek_or_die (file, 12, SEEK_CUR, 442 + 10 + 12, sfinfo.channels, __LINE__) ;
+ test_readf_float_or_die (file, 0, data, 10, __LINE__) ;
+ compare_float_or_die (data, stereo_out + ((442 + 10 + 12) * sfinfo.channels), 10, __LINE__) ;
+
+ test_seek_or_die (file, 12, SEEK_CUR, 442 + 20 + 24, sfinfo.channels, __LINE__) ;
+ test_readf_float_or_die (file, 0, data, 10, __LINE__) ;
+ compare_float_or_die (data, stereo_out + ((442 + 20 + 24) * sfinfo.channels), 10, __LINE__) ;
+
+ pos = 500 - sfinfo.frames ;
+ test_seek_or_die (file, pos, SEEK_END, 500, sfinfo.channels, __LINE__) ;
+ test_readf_float_or_die (file, 0, data, 10, __LINE__) ;
+ compare_float_or_die (data, stereo_out + (500 * sfinfo.channels), 10, __LINE__) ;
+
+ pos = 10 - sfinfo.frames ;
+ test_seek_or_die (file, pos, SEEK_END, 10, sfinfo.channels, __LINE__) ;
+ test_readf_float_or_die (file, 0, data, 10, __LINE__) ;
+ compare_float_or_die (data, stereo_out + (10 * sfinfo.channels), 10, __LINE__) ;
+
+ sf_close (file) ;
+
+ puts ("ok") ;
+ unlink (filename) ;
+} /* mpeg_stereo_seek_test */
+
+
+int
+main (void)
+{
+ if (HAVE_MPEG)
+ { mpeg_short_test () ;
+ mpeg_int_test () ;
+ mpeg_float_test () ;
+ mpeg_double_test () ;
+
+ mpeg_stereo_seek_test ("mpeg_seek.mp3", SF_FORMAT_MPEG | SF_FORMAT_MPEG_LAYER_III) ;
+ }
+ else
+ puts (" No MPEG tests because mpg123/lame support was not compiled in.") ;
+ return 0 ;
+} /* main */
+
printf ("This offset : %" PRId64 "\n", embed_info.offset + embed_info.length) ;
} ;
- if (lseek (fd, embed_info.offset + embed_info.length, SEEK_SET) < 0)
+ if (lseek (fd, (long) (embed_info.offset + embed_info.length), SEEK_SET) < 0)
{ printf ("\n\nLine %d: lseek failed : %s\n", __LINE__, strerror (errno)) ;
exit (1) ;
} ;
/* Convert to short. */
for (k = 0 ; k < ARRAY_LEN (data_out.s) ; k++)
- data_out.s [k] = lrintf (data_out.f [k]) ;
+ data_out.s [k] = (short) lrintf (data_out.f [k]) ;
memset (&sfinfo, 0, sizeof (sfinfo)) ;
/* Convert to shorteger. */
for (k = 0 ; k < ARRAY_LEN (data_out.s) ; k++)
- data_out.s [k] = lrintf (data_out.f [k]) ;
+ data_out.s [k] = (short) lrintf (data_out.f [k]) ;
memset (&sfinfo, 0, sizeof (sfinfo)) ;
} ;
total = 0 ;
- while ((k = sf_read_short (file, data + total, BUFFER_LEN - total)) > 0)
+ while ((k = (int) sf_read_short (file, data + total, BUFFER_LEN - total)) > 0)
total += k ;
if (total != count)
while (total < count)
{ this_write = (count - total > 1024) ? 1024 : count - total ;
- if ((k = sf_write_short (file, data + total, this_write)) != this_write)
+ if ((k = (int) sf_write_short (file, data + total, this_write)) != this_write)
{ fprintf (stderr, "sf_write_short # %d failed with short write (%d -> %d)\n", count, this_write, k) ;
exit (1) ;
} ;
#define BUFFER_LEN (1 << 10)
#define LOG_BUFFER_SIZE 1024
+static const char STR_TEST_PREFIX[] = "str" ;
+
static void string_start_test (const char *filename, int typemajor) ;
static void string_start_end_test (const char *filename, int typemajor) ;
static void string_multi_set_test (const char *filename, int typemajor) ;
test_count++ ;
} ;
+ if (do_all || ! strcmp (argv [1], "mpeg"))
+ { if (HAVE_MPEG)
+ string_start_test ("mpeg.mp3", SF_FORMAT_MPEG | SF_FORMAT_MPEG_LAYER_III) ;
+ else
+ puts (" No MP3 tests because MPEG support was not compiled in.") ;
+ test_count++ ;
+ } ;
+
if (do_all || ! strcmp (argv [1], "ogg"))
{ if (HAVE_EXTERNAL_XIPH_LIBS)
string_start_test ("vorbis.oga", SF_FORMAT_OGG | SF_FORMAT_VORBIS) ;
long_title [] = "This is a very long and very boring title for this file",
long_artist [] = "The artist who kept on changing its name",
genre [] = "The genre",
- trackno [] = "Track three" ;
+ trackno [] = "Track three",
+ id3v1_genre [] = "Rock",
+ year [] = "2001" ;
static short data_out [BUFFER_LEN] ;
SF_INFO sfinfo ;
int errors = 0 ;
+ get_unique_test_name (&filename, STR_TEST_PREFIX) ;
print_test_name ("string_start_end_test", filename) ;
memset (&sfinfo, 0, sizeof (sfinfo)) ;
int errors = 0 ;
int typemajor = SF_FORMAT_TYPEMASK & formattype ;
+ get_unique_test_name (&filename, STR_TEST_PREFIX) ;
print_test_name ("string_start_test", filename) ;
memset (&sfinfo, 0, sizeof (sfinfo)) ;
break ;
case SF_FORMAT_OGG | SF_FORMAT_VORBIS :
+ case SF_FORMAT_MPEG | SF_FORMAT_MPEG_LAYER_III :
break ;
default :
sf_set_string (file, SF_STR_ARTIST, artist) ;
sf_set_string (file, SF_STR_COPYRIGHT, copyright) ;
sf_set_string (file, SF_STR_COMMENT, comment) ;
- sf_set_string (file, SF_STR_DATE, date) ;
sf_set_string (file, SF_STR_ALBUM, album) ;
sf_set_string (file, SF_STR_LICENSE, license) ;
+ if (typemajor == SF_FORMAT_MPEG)
+ { sf_set_string (file, SF_STR_GENRE, id3v1_genre) ;
+ sf_set_string (file, SF_STR_DATE, year) ;
+ }
+ else
+ { sf_set_string (file, SF_STR_DATE, date) ;
+ } ;
/* Write data to file. */
test_write_short_or_die (file, 0, data_out, BUFFER_LEN, __LINE__) ;
printf (" Bad filename : %s\n", cptr) ;
} ;
- cptr = sf_get_string (file, SF_STR_COPYRIGHT) ;
- if (cptr == NULL || strcmp (copyright, cptr) != 0)
- { if (errors++ == 0)
- puts ("\n") ;
- printf (" Bad copyright : %s\n", cptr) ;
- } ;
+ if (typemajor != SF_FORMAT_MPEG)
+ { cptr = sf_get_string (file, SF_STR_COPYRIGHT) ;
+ if (cptr == NULL || strcmp (copyright, cptr) != 0)
+ { if (errors++ == 0)
+ puts ("\n") ;
+ printf (" Bad copyright : %s\n", cptr) ;
+ } ;
- cptr = sf_get_string (file, SF_STR_SOFTWARE) ;
- if (cptr == NULL || strstr (cptr, software) != cptr)
- { if (errors++ == 0)
- puts ("\n") ;
- printf (" Bad software : %s\n", cptr) ;
+ cptr = sf_get_string (file, SF_STR_SOFTWARE) ;
+ if (cptr == NULL || strstr (cptr, software) != cptr)
+ { if (errors++ == 0)
+ puts ("\n") ;
+ printf (" Bad software : %s\n", cptr) ;
+ } ;
+
+ if (cptr && str_count (cptr, "libsndfile") != 1)
+ { if (errors++ == 0)
+ puts ("\n") ;
+ printf (" Bad software : %s\n", cptr) ;
+ } ;
} ;
- if (cptr && str_count (cptr, "libsndfile") != 1)
- { if (errors++ == 0)
- puts ("\n") ;
- printf (" Bad software : %s\n", cptr) ;
+ if (typemajor == SF_FORMAT_MPEG)
+ { cptr = sf_get_string (file, SF_STR_GENRE) ;
+ if (cptr == NULL || strcmp (id3v1_genre, cptr) != 0)
+ { if (errors++ == 0)
+ puts ("\n") ;
+ printf (" Bad genre : %s\n", cptr) ;
+ } ;
} ;
cptr = sf_get_string (file, SF_STR_ARTIST) ;
printf (" Bad comment : %s\n", cptr) ;
} ;
- if (typemajor != SF_FORMAT_AIFF)
- { cptr = sf_get_string (file, SF_STR_DATE) ;
- if (cptr == NULL || strcmp (date, cptr) != 0)
- { if (errors++ == 0)
- puts ("\n") ;
- printf (" Bad date : %s\n", cptr) ;
- } ;
+ switch (typemajor)
+ { case SF_FORMAT_AIFF :
+ /* not supported */
+ break ;
+
+ case SF_FORMAT_MPEG :
+ /* id3 only supports years */
+ cptr = sf_get_string (file, SF_STR_DATE) ;
+ if (cptr == NULL || strcmp (year, cptr) != 0)
+ { if (errors++ == 0)
+ puts ("\n") ;
+ printf (" Bad date : %s\n", cptr) ;
+ } ;
+ break ;
+
+ default :
+ cptr = sf_get_string (file, SF_STR_DATE) ;
+ if (cptr == NULL || strcmp (date, cptr) != 0)
+ { if (errors++ == 0)
+ puts ("\n") ;
+ printf (" Bad date : %s\n", cptr) ;
+ } ;
+ break ;
} ;
if (typemajor != SF_FORMAT_WAV && typemajor != SF_FORMAT_AIFF)
} ;
} ;
- if (typemajor != SF_FORMAT_WAV && typemajor != SF_FORMAT_AIFF && typemajor != SF_FORMAT_RF64)
- { cptr = sf_get_string (file, SF_STR_LICENSE) ;
- if (cptr == NULL || strcmp (license, cptr) != 0)
- { if (errors++ == 0)
- puts ("\n") ;
- printf (" Bad license : %s\n", cptr) ;
- } ;
+ switch (typemajor)
+ { case SF_FORMAT_WAV :
+ case SF_FORMAT_AIFF :
+ case SF_FORMAT_RF64 :
+ case SF_FORMAT_MPEG :
+ /* not supported */
+ break ;
+
+ default:
+ cptr = sf_get_string (file, SF_STR_LICENSE) ;
+ if (cptr == NULL || strcmp (license, cptr) != 0)
+ { if (errors++ == 0)
+ puts ("\n") ;
+ printf (" Bad license : %s\n", cptr) ;
+ } ;
} ;
if (errors > 0)
SF_INFO sfinfo ;
int count ;
+ get_unique_test_name (&filename, STR_TEST_PREFIX) ;
print_test_name (__func__, filename) ;
memset (&sfinfo, 0, sizeof (sfinfo)) ;
sf_count_t frames ;
const char * str ;
+ get_unique_test_name (&filename, STR_TEST_PREFIX) ;
print_test_name (__func__, filename) ;
create_short_sndfile (filename, typemajor | SF_FORMAT_PCM_16, 2) ;
sf_count_t frames = BUFFER_LEN ;
const char * str ;
+ get_unique_test_name (&filename, STR_TEST_PREFIX) ;
print_test_name (__func__, filename) ;
memset (&sfinfo, 0, sizeof (sfinfo)) ;
software_string_test (const char *filename)
{ size_t k ;
+ get_unique_test_name (&filename, STR_TEST_PREFIX) ;
print_test_name (__func__, filename) ;
for (k = 0 ; k < 50 ; k++)
sf_count_t frames ;
const char * str ;
+ get_unique_test_name (&filename, STR_TEST_PREFIX) ;
print_test_name (__func__, filename) ;
/* Create a file that contains some strings. Then open the file in RDWR mode and
const char * str ;
const int GROW_BUFFER_AMOUNT = 4 ; /* this should be less than half the size of the string header */
+ get_unique_test_name (&filename, STR_TEST_PREFIX) ;
print_test_name (__func__, filename) ;
/* Create a short file. */
echo " $sfversion passed tests on OPUS files."
echo "----------------------------------------------------------------------"
+# mpeg-tests
+./tests/mpeg_test@EXEEXT@
+./tests/compression_size_test@EXEEXT@ mpeg
+./tests/string_test@EXEEXT@ mpeg
+
+echo "----------------------------------------------------------------------"
+echo " $sfversion passed tests on MPEG files."
+echo "----------------------------------------------------------------------"
+
# io-tests
./tests/stdio_test@EXEEXT@
./tests/pipe_test@EXEEXT@
print_test_name ("ulaw_test", "encoder") ;
- filename = "test.raw" ;
+ filename = "ulaw_test.raw" ;
sf_info_setup (&sfinfo, SF_FORMAT_RAW | SF_FORMAT_ULAW, 44100, 1) ;
void increment_open_file_count (void) ;
void check_open_file_count_or_die (int lineno) ;
+void get_unique_test_name (const char ** filename, const char * test) ;
+
#ifdef SNDFILE_H
static inline void
} /* check_open_file_count_or_die */
void
+get_unique_test_name (const char ** filename, const char * test)
+{ static char buffer [1024] ;
+
+ snprintf (buffer, sizeof (buffer), "%s_%s", test, *filename) ;
+
+ *filename = buffer ;
+} /* get_unique_test_name */
+
+void
write_mono_file (const char * filename, int format, int srate, float * output, int len)
{ SNDFILE * file ;
SF_INFO sfinfo ;
fflush (stdout) ;
puts (sf_strerror (NULL)) ;
- dump_data_to_file (fname, vio_data.data, vio_data.length) ;
+ dump_data_to_file (fname, vio_data.data, (unsigned int) vio_data.length) ;
exit (1) ;
} ;
#define SILLY_WRITE_COUNT (234)
+static const char WRT_TEST_PREFIX[] = "wrt" ;
+
[+ FOR data_type
+]static void pcm_test_[+ (get "type_name") +] (const char *str, int format, int long_file_ok) ;
[+ ENDFOR data_type
/* Sd2 files cannot be opened from an existing file descriptor. */
allow_fd = ((format & SF_FORMAT_TYPEMASK) == SF_FORMAT_SD2) ? SF_FALSE : SF_TRUE ;
+ get_unique_test_name (&filename, WRT_TEST_PREFIX) ;
print_test_name ("pcm_test_[+ (get "type_name") +]", filename) ;
sfinfo.samplerate = 44100 ;
/* Sd2 files cannot be opened from an existing file descriptor. */
allow_fd = ((format & SF_FORMAT_TYPEMASK) == SF_FORMAT_SD2) ? SF_FALSE : SF_TRUE ;
+ get_unique_test_name (&filename, WRT_TEST_PREFIX) ;
print_test_name ("empty_file_test", filename) ;
unlink (filename) ;
--- /dev/null
+{
+ "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg/master/scripts/vcpkg.schema.json",
+ "name": "libsndfile",
+ "description": "A library for reading and writing audio files",
+ "version-semver": "1.1.0",
+ "default-features": [
+ "external-libs",
+ "mpeg"
+ ],
+ "features": {
+ "external-libs": {
+ "description": "Enable FLAC, Vorbis, and Opus codecs",
+ "dependencies": [
+ "libvorbis",
+ "libflac",
+ "opus"
+ ]
+ },
+ "mpeg": {
+ "description": "Enable MPEG codecs",
+ "dependencies": [
+ "mpg123",
+ "mp3lame"
+ ]
+ },
+ "regtest": {
+ "description": "Build regtest",
+ "dependencies": [
+ "sqlite3"
+ ]
+ },
+ "experimental": {
+ "description": "Enable experimental code",
+ "dependencies": [
+ "speex"
+ ]
+ }
+ }
+}