Skip to content

Commit

Permalink
Merge pull request #21 from pedrolcl/more_build_options
Browse files Browse the repository at this point in the history
new build options added
  • Loading branch information
pedrolcl authored Sep 22, 2024
2 parents 8c1646d + ead851d commit 23bcf66
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 28 deletions.
24 changes: 22 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ project( sonivox
# GoogleTest requires at least C++14
set(CMAKE_CXX_STANDARD 14)

option(USE_44KHZ "Output 44100 Hz audio (instead of 22050 Hz)" TRUE)
option(USE_16BITS_SAMPLES "Use 16 bits samples (instead of 8 bit)" TRUE)
option(BUILD_SONIVOX_STATIC "Build the static library" TRUE)
option(BUILD_SONIVOX_SHARED "Build the shared library" TRUE)
option(BUILD_EXAMPLE "Build and install the example program" TRUE)
option(BUILD_TESTING "Build the unit tests" TRUE)
option(CMAKE_POSITION_INDEPENDENT_CODE "Whether to create position-independent targets" TRUE)
option(USE_44KHZ "Use 44kHz wavetable instead of 22kHz one" TRUE)
set(MAX_VOICES 64 CACHE STRING "Maximum number of voices")

include(GNUInstallDirs)
Expand Down Expand Up @@ -120,7 +122,6 @@ target_compile_definitions( sonivox-objects PRIVATE
EAS_WT_SYNTH
NUM_OUTPUT_CHANNELS=2
MAX_SYNTH_VOICES=${MAX_VOICES}
_16_BIT_SAMPLES
_FILTER_ENABLED
DLS_SYNTHESIZER
_REVERB_ENABLED
Expand All @@ -132,6 +133,16 @@ target_compile_definitions( sonivox-objects PRIVATE
#JET_INTERFACE
)

if (USE_16BITS_SAMPLES)
target_compile_definitions( sonivox-objects PRIVATE
_16_BIT_SAMPLES
)
else()
target_compile_definitions( sonivox-objects PRIVATE
_8_BIT_SAMPLES
)
endif()

if(USE_44KHZ)
target_compile_definitions( sonivox-objects PRIVATE
_SAMPLE_RATE_44100
Expand Down Expand Up @@ -288,3 +299,12 @@ if (BUILD_TESTING)
include( GoogleTest )
gtest_discover_tests( SonivoxTest EXTRA_ARGS "-P${CMAKE_CURRENT_SOURCE_DIR}/test/res/" DISCOVERY_TIMEOUT 300 )
endif()

# Example program
if (BUILD_EXAMPLE)
set(sonivox_DIR ${CMAKE_CURRENT_BINARY_DIR})
add_subdirectory(example)
install( TARGETS sonivoxrender
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
endif()
37 changes: 27 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,22 @@ You may find several projects already using this library as a git submodule:
* [Linux-SonivoxEas](https://github.com/pedrolcl/Linux-SonivoxEas) with ALSA Sequencer MIDI input and Pulseaudio output.
* [multiplatform-sonivoxeas](https://github.com/pedrolcl/multiplatform-sonivoxeas) with Drumstick::RT MIDI input and Qt Multimedia audio output.

The build system has two options: `BUILD_SONIVOX_STATIC` and `BUILD_SONIVOX_SHARED` to control the generation and install of both the static and shared libraries from the sources. Both options are ON by default.
Another option is `BUILD_TESTING`, also ON by default, to control if the unit tests are built, which require Google Test.
## Build options

The build system has the following options:

* `USE_44KHZ`: Renders 44100 Hz audio (ON by default). If set to OFF will output 22050 Hz audio.
* `USE_16BITS_SAMPLES`: Uses 16 bits samples (instead of 8 bit). ON by default. The rendered audio uses always 16 bits.
* `BUILD_SONIVOX_STATIC` and `BUILD_SONIVOX_SHARED`: to control the generation and install of both the static and shared libraries from the sources. Both options are ON by default (at least one must be selected).
* `BUILD_TESTING`: ON by default, to control if the unit tests are built, which require Google Test.
* `BUILD_EXAMPLE`: ON by default, to build and install the example program.
* `CMAKE_POSITION_INDEPENDENT_CODE`: Whether to create position-independent targets. ON By default.
* `MAX_VOICES`: Maximum number of voices. 64 by default.

See also the [CMake documentation](https://cmake.org/cmake/help/latest/index.html) for common build options.

## Differences with upstream

This fork currently reverts these commits:

* Full revert of [af41595](https://github.com/pedrolcl/platform_external_sonivox/commit/af41595537b044618234fe7dd9ebfcc652de1576) (Remove unused code from midi engine)
Expand All @@ -34,10 +46,9 @@ All the sources from the Android repository are kept in place, but some are not

You may find and use the installed libraries with `pkg-config` or the `find_package()` CMake command. The library API is documented in the 'docs' directory contents.

The 'example' directory contains a simple command line utility to render standard MIDI files into raw PCM audio streams. This utility can be compiled after building and installing sonivox in some prefix like `/usr`, `/usr/local`, or `$HOME/Sonivox`.
The CMake script contains three alternatives: using CMake only, using `pkg-config` and using sonivox as a subdirectory.
The 'example' directory contains a simple command line utility to render standard MIDI files into raw PCM audio streams. This utility may be compiled when building the library and also installed. You may find a standalone project containing this program here: https://github.com/pedrolcl/sonivox-example

Once compiled, you can use the program to listen MIDI files or to create MP3 files. These are the available command line options:
You can use the program to listen MIDI files or to create audio files (like MP3 or WAV). These are the available command line options:

~~~
$ ./sonivoxrender -h
Expand All @@ -50,17 +61,23 @@ Options:
-w n reverb wet: 0..32765.
~~~

The following examples assume the default option USE_44KHZ=ON:

Example 1: Render a MIDI file and save the rendered audio as a raw audio file:

$ sonivoxrender ants.mid > ants.pcm

Example 2: pipe the rendered audio thru the Linux ALSA 'aplay' utility:

$ sonivoxrender ants.mid | aplay -c 2 -f S16_LE -r 22050
$ sonivoxrender ants.mid | aplay -c 2 -f S16_LE -r 44100

Example 3: pipe the rendered audio thru the ['lame'](https://lame.sourceforge.io) utility creating a MP3 file:

Example 3: pipe the rendered audio thru the 'lame' utility creating a MP3 file:
$ sonivoxrender ants.mid | lame -r -s 44100 - ants.mp3

Example 4: pipe the rendered audio thru the ['sox'](https://sourceforge.net/projects/sox/) utility creating a WAV file:

$ sonivoxrender ants.mid | lame -r -s 22050 - ants.mp3
$ sonivoxrender ants.mid | sox -t s16 -c 2 -r 44100 - ants.wav

## Unit tests

Expand All @@ -83,9 +100,9 @@ There are two environment variables that you may set before running the tests (m

## License

Copyright (c) 2022-2023 Pedro López-Cabanillas.
Copyright (c) 2022-2024 Pedro López-Cabanillas.

Copyright (c) 2008-2023, The Android Open Source Project.
Copyright (c) 2008-2024, The Android Open Source Project.

Copyright (c) 2004-2006 Sonic Network Inc.

Expand Down
21 changes: 5 additions & 16 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,10 @@
limitations under the License.
]=========================================================================]

cmake_minimum_required(VERSION 3.14)
project( sonivoxrender LANGUAGES C )

# Alternative 1: Using CMake only and sonivox installed:
find_package ( sonivox CONFIG REQUIRED )
add_executable ( sonivoxrender sonivoxrender.c )
target_link_libraries ( sonivoxrender sonivox::sonivox-static )

# Alternative 2: Using pkg-config and sonivox installed:
#find_package ( PkgConfig REQUIRED )
#pkg_check_modules ( sonivox REQUIRED IMPORTED_TARGET sonivox-static )
#add_executable ( sonivoxrender sonivoxrender.c )
#target_link_libraries( sonivoxrender PkgConfig::sonivox )

# Alternative 3: sonivox in a subdirectory (for instance: a git submodule )
#add_subdirectory( sonivox )
#add_executable ( sonivoxrender sonivoxrender.c )
#target_link_libraries ( sonivoxrender sonivox::sonivox-static )
if (BUILD_SONIVOX_STATIC)
target_link_libraries ( sonivoxrender sonivox::sonivox-static )
elseif (BUILD_SONIVOX_SHARED)
target_link_libraries ( sonivoxrender sonivox::sonivox )
endif()

0 comments on commit 23bcf66

Please sign in to comment.