2012-01-15 09:34:46 +00:00
|
|
|
# libsndfile
|
|
|
|
|
2020-10-05 07:11:47 +00:00
|
|
|
![C/C++ CI](https://github.com/libsndfile/libsndfile/workflows/C/C++%20CI/badge.svg)
|
2015-08-07 09:48:51 +00:00
|
|
|
|
2012-01-15 09:34:46 +00:00
|
|
|
libsndfile is a C library for reading and writing files containing sampled audio
|
|
|
|
data.
|
|
|
|
|
|
|
|
## Hacking
|
|
|
|
|
2012-01-15 10:23:56 +00:00
|
|
|
The canonical source code repository for libsndfile is at
|
2020-10-05 07:11:47 +00:00
|
|
|
[http://libsndfile.github.io/libsndfile/][github].
|
2012-01-15 09:34:46 +00:00
|
|
|
|
2012-01-15 10:23:56 +00:00
|
|
|
You can grab the source code using:
|
2012-01-15 09:34:46 +00:00
|
|
|
|
2020-10-05 07:11:47 +00:00
|
|
|
git clone https://github.com/libsndfile/libsndfile.git
|
2012-01-15 10:23:56 +00:00
|
|
|
|
2016-07-16 09:34:17 +00:00
|
|
|
For building for Android see [BuildingForAndroid][BuildingForAndroid].
|
|
|
|
|
2020-08-26 07:17:32 +00:00
|
|
|
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.
|
2016-07-02 07:18:37 +00:00
|
|
|
|
2016-07-26 08:41:17 +00:00
|
|
|
Setting up a build environment for libsndfile on Debian or Ubuntu is as simple as:
|
2018-08-30 06:06:57 +00:00
|
|
|
|
|
|
|
sudo apt install autoconf autogen automake build-essential libasound2-dev \
|
2019-11-09 22:02:30 +00:00
|
|
|
libflac-dev libogg-dev libtool libvorbis-dev libopus-dev pkg-config python
|
2018-08-30 06:06:57 +00:00
|
|
|
|
2016-07-26 08:41:17 +00:00
|
|
|
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:
|
2018-08-30 06:06:57 +00:00
|
|
|
|
2020-07-13 22:57:04 +00:00
|
|
|
brew install autoconf autogen automake flac libogg libtool libvorbis opus pkg-config
|
2018-08-30 06:06:57 +00:00
|
|
|
|
2016-07-26 08:41:17 +00:00
|
|
|
Once the build environment has been set up, building and testing libsndfile is
|
|
|
|
as simple as:
|
2012-01-15 10:23:56 +00:00
|
|
|
|
2018-08-30 06:06:57 +00:00
|
|
|
./autogen.sh
|
|
|
|
./configure --enable-werror
|
|
|
|
make
|
|
|
|
make check
|
2012-01-15 10:23:56 +00:00
|
|
|
|
2018-08-30 06:06:57 +00:00
|
|
|
## The CMake build system
|
2016-07-02 07:18:37 +00:00
|
|
|
|
2020-08-26 07:17:32 +00:00
|
|
|
Although Autotools is the primary and recommended build toolchain, CMake meta
|
|
|
|
build generator is also available. The build process with CMake takes
|
2017-04-13 06:11:02 +00:00
|
|
|
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](https://cmake.org/cmake/help/latest/manual/cmake-generators.7.html).
|
2016-07-02 07:18:37 +00:00
|
|
|
|
2018-08-30 06:06:57 +00:00
|
|
|
Some IDE support CMake natively or with plugins, check you IDE documentation
|
|
|
|
for details.
|
|
|
|
|
2017-04-13 06:11:02 +00:00
|
|
|
### Requirements
|
2016-07-02 07:18:37 +00:00
|
|
|
|
2017-04-13 06:11:02 +00:00
|
|
|
1. C99-compliant compiler toolchain (tested with GCC, Clang and Visual
|
|
|
|
Studio 2015)
|
|
|
|
2. CMake 3.1.3 or newer
|
2016-07-02 07:18:37 +00:00
|
|
|
|
2017-04-13 06:11:02 +00:00
|
|
|
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
|
2018-08-30 06:06:57 +00:00
|
|
|
cd CMakeBuild
|
2017-04-13 06:11:02 +00:00
|
|
|
|
|
|
|
Then run `cmake` command with directory where CMakeLists.txt script is located
|
|
|
|
as argument (relative paths are supported):
|
|
|
|
|
2018-08-30 06:06:57 +00:00
|
|
|
cmake ..
|
2017-04-13 06:11:02 +00:00
|
|
|
|
|
|
|
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](https://cmake.org/cmake/help/latest/manual/cmake-generators.7.html)
|
|
|
|
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:
|
|
|
|
|
2018-08-30 06:06:57 +00:00
|
|
|
* `BUILD_SHARED_LIBS` - build shared library (DLL under Windows) when `ON`,
|
2019-10-24 06:42:02 +00:00
|
|
|
build static library othervise. This option is `OFF` by default.
|
2018-08-30 06:06:57 +00:00
|
|
|
* `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.
|
2019-11-09 22:02:30 +00:00
|
|
|
* `ENABLE_EXTERNAL_LIBS` - enable Ogg, Vorbis, FLAC and Opus support. This
|
|
|
|
option is available and set to `ON` if all dependency libraries were found.
|
2018-08-30 06:06:57 +00:00
|
|
|
* `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
|
|
|
|
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](https://cmake.org/cmake/help/latest/module/CPack.html) support.
|
|
|
|
This option is `ON` by default.
|
|
|
|
* `ENABLE_PACKAGE_CONFIG` - generate and install [package config file](https://cmake.org/cmake/help/latest/manual/cmake-packages.7.html#config-file-packages).
|
2020-08-18 06:27:43 +00:00
|
|
|
* `INSTALL_PKGCONFIG_MODULE` - generate and install [pkg-config module](https://people.freedesktop.org/~dbn/pkg-config-guide.html).
|
2020-09-30 04:32:17 +00:00
|
|
|
* `INSTALL_MANPAGES` - install [man pages](https://en.wikipedia.org/wiki/Man_page) for programs. This option is `ON` by default
|
2020-08-28 04:54:31 +00:00
|
|
|
|
2018-08-30 06:06:57 +00:00
|
|
|
* `ENABLE_STATIC_RUNTIME` - enable static runtime on Windows platform, `OFF` by
|
2020-08-23 08:57:21 +00:00
|
|
|
default (CMake < 3.15).
|
2020-03-08 05:28:46 +00:00
|
|
|
|
2020-08-23 08:57:21 +00:00
|
|
|
**Note**: For MSVC compiler this option is deprecated and disabled for CMake >= 3.15, see
|
|
|
|
policy [CMP0091](https://cmake.org/cmake/help/latest/policy/CMP0091.html).
|
|
|
|
Use `CMAKE_MSVC_RUNTIME_LIBRARY` option instead.
|
2018-08-30 06:06:57 +00:00
|
|
|
* `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 preffered
|
|
|
|
because you can search library using package manager or CMake's
|
|
|
|
`find_library` command on any platform using the same `sndfile` name.
|
|
|
|
|
|
|
|
Deprecated options:
|
|
|
|
|
|
|
|
* `DISABLE_EXTERNAL_LIBS` - disable Ogg, Vorbis and FLAC support. Replaced by
|
|
|
|
`ENABLE_EXTERNAL_LIBS`
|
|
|
|
* `DISABLE_CPU_CLIP` - disable tricky cpu specific clipper. Replaced by
|
|
|
|
`ENABLE_CPU_CLIP`
|
|
|
|
* `BUILD_STATIC_LIBS` - build static library. Use `BUILD_SHARED_LIBS` instead
|
|
|
|
|
|
|
|
### Linking from CMake projects
|
|
|
|
|
2020-08-03 09:11:31 +00:00
|
|
|
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`:
|
2020-03-08 05:28:46 +00:00
|
|
|
|
|
|
|
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:
|
2018-08-30 06:06:57 +00:00
|
|
|
|
|
|
|
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)
|
2017-04-13 06:11:02 +00:00
|
|
|
|
|
|
|
### Notes for Windows users
|
|
|
|
|
|
|
|
First advice - set `ENABLE_STATIC_RUNTIME` to ON. This will remove dependencies
|
|
|
|
on runtime DLLs.
|
|
|
|
|
2020-03-08 05:28:46 +00:00
|
|
|
Second advice is about Ogg, Vorbis FLAC and Opus support. Searching external
|
2018-08-30 06:06:57 +00:00
|
|
|
libraries under Windows is a little bit tricky. The best way is to use
|
2017-04-13 06:11:02 +00:00
|
|
|
[Vcpkg](https://github.com/Microsoft/vcpkg). You need to install static libogg,
|
2019-11-09 22:02:30 +00:00
|
|
|
libvorbis, libflac and libopus libraries:
|
2017-04-13 06:11:02 +00:00
|
|
|
|
|
|
|
vcpkg install libogg:x64-windows-static libvorbis:x64-windows-static
|
2020-03-08 05:28:46 +00:00
|
|
|
libflac:x64-windows-static opus:x64-windows-static libogg:x86-windows-static
|
|
|
|
libvorbis:x86-windows-static libflac:x86-windows-static opus:x86-windows-static
|
2017-04-13 06:11:02 +00:00
|
|
|
|
|
|
|
Then and 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:
|
|
|
|
|
|
|
|
-DVCPKG_TARGET_TRIPLET=x64-windows-static
|
2016-07-02 07:18:37 +00:00
|
|
|
|
2018-08-30 06:06:57 +00:00
|
|
|
## Submitting Patches
|
2012-01-15 10:23:56 +00:00
|
|
|
|
2017-03-13 13:52:11 +00:00
|
|
|
See [CONTRIBUTING.md](CONTRIBUTING.md) for details.
|
2012-01-15 11:13:33 +00:00
|
|
|
|
2016-07-26 08:41:17 +00:00
|
|
|
[brew]: http://brew.sh/
|
2020-10-05 07:11:47 +00:00
|
|
|
[github]: http://libsndfile.github.io/libsndfile/
|
|
|
|
[BuildingForAndroid]: https://github.com/libsndfile/libsndfile/blob/master/Building-for-Android.md
|