1
0
Fork
You've already forked libsndfile-fork
0
No description
  • C 82.4%
  • Smarty 6.1%
  • CMake 3.6%
  • M4 2.7%
  • C++ 1.5%
  • Other 3.6%
Find a file
2025年11月12日 14:22:13 +01:00
.github/workflows github: bump upload-artifact to v4 for cifuzz action 2024年11月16日 10:22:19 -08:00
cmake Update for cmake 4 2025年05月14日 14:09:12 +05:00
docs Update api.md 2025年02月06日 16:13:00 +01:00
examples Fix various typos 2023年08月18日 14:27:39 +05:00
include sndfile.hh: add operator != 2024年06月25日 10:47:50 +05:00
m4 m4/: update macros 2025年02月06日 16:05:11 +01:00
man Improvements for the Sndio backend support 2024年06月25日 10:48:17 +05:00
Octave Do not use old variable INCLUDES and use modern AM_INIT_AUTOMAKE invocation. 2013年04月07日 20:05:08 +10:00
ossfuzz ossfuzz: fix sometimes undefined default case 2023年10月20日 13:58:12 +05:00
programs Correctly request Sndio support 2025年02月07日 11:09:50 +01:00
regtest Fix various typos 2023年08月18日 14:27:39 +05:00
Scripts scripts: Fix cstyle regex escaping 2024年11月16日 10:22:19 -08:00
src Update src/ogg.c 2025年11月12日 14:22:13 +01:00
tests Remove more unused varibles, closes #1015 2024年05月26日 16:13:19 +05:00
Win32 Make build system completely non-recursive 2017年09月26日 19:35:56 +10:00
.editorconfig Add .editorconfig 2017年04月03日 20:23:49 +10:00
.gitattributes Exclude repository-configuration from git-archive 2020年11月12日 15:36:08 +05:00
.gitignore Switch release tarballs .bz2 -> .xz 2021年09月05日 15:01:09 +02:00
AUTHORS Add info about current maintainers and releaser 2021年01月23日 18:10:18 +05:00
Building-for-Android.md Remove autogen.sh 2022年09月24日 12:51:49 +02:00
ChangeLog Update documentaton links 2020年10月05日 12:21:19 +05:00
CHANGELOG.md Disable autogen make rules if autogen cannot be found 2023年08月13日 19:37:59 +02:00
CMakeLists.txt revert fb8c4dbb1d 2025年11月12日 14:15:38 +01:00
CODEOWNERS Add CODEOWNERS file 2020年10月13日 08:44:32 +05:00
configure.ac Correctly request Sndio support 2025年02月07日 11:09:50 +01:00
CONTRIBUTING.md Update commit message contributing guidlines 2021年02月18日 12:10:30 +05:00
COPYING First snapshot of the public project. 2007年05月14日 19:55:24 +10:00
make_lite.py Clean out cruft. 2008年04月05日 20:13:47 +11:00
Makefile.am Makefile.am: fixup ossfuzz LDADD 2023年10月20日 13:58:12 +05:00
NEWS.OLD fix typo 2023年03月16日 18:19:23 +05:00
README Fix typo ( #903 ) 2023年01月11日 13:19:28 +05:00
README.md Update README.md 2024年02月10日 07:50:29 +05:00
SECURITY.md Update SECURITY.md ( #938 ) 2023年05月25日 06:06:45 +05:00
sndfile.pc.in Update sndfile.pc for MPEG support 2021年05月25日 16:17:04 +05:00
vcpkg.json Bump version numbers ( #902 ) 2023年01月11日 13:18:09 +05:00

libsndfile

C/C++ CI

libsndfile is a C library for reading and writing files containing sampled audio data.

Authors

The libsndfile project was originally developed and maintained by Erik de Castro Lopo erikd@mega-nerd.com aka @erikd. The project was developed on Github at https://github.com/erikd/libsndfile.

After the release of version 1.0.30, @erikd transferred the project to the libsndfile team, see AUTHORS for details.

Hacking

The canonical source code repository for libsndfile is at https://github.com/libsndfile/libsndfile.

You can grab the source code using:

git clone https://github.com/libsndfile/libsndfile.git

For building for Android see BuildingForAndroid.

There are currently two build systems: the traditional GNU autotool based one and modern CMake based build system. Use of the CMake build system is documented below.

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 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 mpg123 pkg-config

Once the build environment has been set up, building and testing libsndfile is as simple as:

autoreconf -vif
./configure --enable-werror
make
make check

The CMake build system

Although Autotools is the primary and recommended build toolchain, CMake meta build generator is also available. The build process with CMake takes place in two stages. First, standard build files are created from configuration scripts. Then the platform's native build tools are used for the actual building. CMake can produce Microsoft Visual Studio project and solution files, Unix Makefiles, Xcode projects and many more.

Some IDE support CMake natively or with plugins, check you IDE documentation for details.

Requirements

  1. C99-compliant compiler toolchain (tested with GCC, Clang and Visual Studio 2015)
  2. CMake 3.1.3 or newer

There are some recommended packages to enable all features of libsndfile:

  1. Ogg, Vorbis and FLAC libraries and headers to enable these formats support
  2. ALSA development package under Linux to build sndfile-play utility
  3. Sndio development package under BSD to build sndfile-play utility

Building from command line

CMake can handle out-of-place builds, enabling several builds from the same source tree, and cross-compilation. The ability to build a directory tree outside the source tree is a key feature, ensuring that if a build directory is removed, the source files remain unaffected.

mkdir CMakeBuild
cd CMakeBuild

Then run cmake command with directory where CMakeLists.txt script is located as argument (relative paths are supported):

cmake ..

This command will configure and write build script or solution to CMakeBuild directory. CMake is smart enough to create Unix makefiles under Linux or Visual Studio solution if you have Visual Studio installed, but you can configure generator with -G command line parameter:

cmake .. -G"Unix Makefiles"

The build procedure depends on the selected generator. With "Unix Makefiles" you can type:

make & make install

With "Visual Studio" and some other generators you can open solution or project from CMakeBuild directory and build using IDE.

Finally, you can use unified command:

cmake --build .

CMake also provides Qt-based cross platform GUI, cmake-gui. Using it is trivial and does not require detailed explanations.

Configuring CMake

You can pass additional options with /D<parameter>=<value> when you run cmake command. Some useful system options:

  • CMAKE_C_FLAGS - additional C compiler flags
  • CMAKE_BUILD_TYPE - configuration type, DEBUG, RELEASE, RELWITHDEBINFO or MINSIZEREL. DEBUG is default
  • CMAKE_INSTALL_PREFIX - build install location, the same as --prefix option of configure script

Useful libsndfile options:

  • BUILD_SHARED_LIBS - build shared library (DLL under Windows) when ON, build static library otherwise. This option is OFF by default.

  • BUILD_PROGRAMS - build libsndfile's utilities from programs/ directory, ON by default.

  • BUILD_EXAMPLES - build examples, ON by default.

  • BUILD_TESTING - build tests. Then you can run tests with ctest command, 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_BOW_DOCS - enable black-on-white documentation theme, OFF by default.

  • ENABLE_EXPERIMENTAL - enable experimental code. Don't use it if you are not sure. This option is OFF by default.

  • ENABLE_CPACK - enable CPack support. This option is ON by default.

  • ENABLE_PACKAGE_CONFIG - generate and install package config file.

  • INSTALL_PKGCONFIG_MODULE - generate and install pkg-config module.

  • INSTALL_MANPAGES - install man pages for programs. This option is ON by default

  • ENABLE_STATIC_RUNTIME - enable static runtime on Windows platform (MSVC and MinGW), OFF by default.

    Note: For MSVC compiler this option is deprecated for CMake >= 3.15, see policy CMP0091. Use CMAKE_MSVC_RUNTIME_LIBRARY option instead.

    Note: For MinGW toolchain this option is experimental. If you enabled it and then disabled again, you need to clear CMake cache (delete CMakeCache.txt).

  • ENABLE_COMPATIBLE_LIBSNDFILE_NAME - set DLL name to libsndfile-1.dll (canonical name) on Windows platform, sndfile.dll otherwise, OFF by default. Library name can be different depending on platform. The well known DLL name on Windows platform is libsndfile-1.dll, because the only way to build Windows library before was MinGW toolchain with Autotools. This name is native for MinGW ecosystem, Autotools constructs it using MinGW platform rules from sndfile target. But when you build with CMake using native Windows compiler, the name is sndfile.dll. This is name for native Windows platform, because Windows has no library naming rules. It is preferred because you can search library using package manager or CMake's find_library command on any platform using the same sndfile name.

  • ENABLE_SSE2 - add compiler flag to enable SSE2 if required, ON by default.

    This option is for X86 and GCC compatible compilers configurations only.

    If you compile for other SIMD set, e.g. AVX2, you may want to set ENABLE_SSE2 to OFF.

    Note: This option is not active for X64 configuration, because SSE2 is always available in this mode and all optimizations are enabled by default.

Deprecated options:

  • DISABLE_EXTERNAL_LIBS - disable Ogg, Vorbis and FLAC support. Replaced by ENABLE_EXTERNAL_LIBS
  • BUILD_STATIC_LIBS - build static library. Use BUILD_SHARED_LIBS instead

Linking from CMake projects

First you need to add FindOgg.cmake, FindVorbis.cmake, FindFLAC.cmake and FindOpus.cmake files to some directory inside your CMake project (usually cmake) and add it to CMAKE_MODULE_PATH:

project(SomeApplication)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

Now you can search libsndfile library from your CMakeLists.txt with this command:

find_package(SndFile)

SndFile_FOUND is set to ON when library is found.

If libsndfile dependency is critical, you can add REQUIRED to find_package:

find_package(SndFile REQUIRED)

With with option find_package will terminate configuration process if libsndfile is not found.

You can also add version check:

find_package(SndFile 1.0.29)

find_package will report error, if libsndfile version is < 1.0.29.

You can combine REQUIRED and version if you need.

To link libsndfile library use:

target_link_libraries(my_application PRIVATE SndFile::sndfile)

Notes for Windows users

System CRT library

First advice about Visual Studio system CRT libraries, it is system code linked as static or dynamic library to every C application.

You can find related option in Visual Studio project properties:

C/C++ -> Code Generation -> Runtime Library

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:

"The program can't start because <crt-dll-name>.dll is missing from your computer. Try reinstalling the program to fix this problem. "

To avoid this, you may want to enable static CRT library linking. In this case the size of your DLL will increase slightly the size will increase slightly, but you can redistribute the libsndfile DLL without having to install the correct version of the system CRT library.

CMake project will use dynamic system CRT libraries by default, just like Visual Studio does. But you can change it using ENABLE_STATIC_RUNTIME or CMAKE_MSVC_RUNTIME_LIBRARY options.

Note: You cannot use both options at the same time, it will lead to a configuration error.

If you have CMake >= 3.15 you should use CMAKE_MSVC_RUNTIME_LIBRARY option.

This will enable static linking:

cmake .. -D"MultiThreaded$<$<CONFIG:Debug>:Debug>"

You can use libsndfile ENABLE_STATIC_RUNTIME option to to control CRT library linking for CMake project: OFF or unset (default) for dynamic, and ON for static linking:

cmake .. -DENABLE_STATIC_RUNTIME=ON

Note: This option is deprecated and may be removed in far future because we have standard option CMAKE_MSVC_RUNTIME_LIBRARY now.

Using Vcpkg package manager

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.

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 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 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.

Submitting Patches

See CONTRIBUTING.md for details.