LabSound is a C++ graph-based audio engine

Overview

macOS iOS Windows Linux Android

LabSound is a C++ graph-based audio engine. LabSound originated as a fork of WebKit's WebAudio implementation, as used in Google's Chrome and Apple's Safari.

LabSound implements many aspects of the WebAudio specification while extending its functionality with an improved API, new graph nodes, bugfixes, and performance improvements.

The engine is packaged as a batteries-included static library meant for integration in many types of software: games, visualizers, interactive installations, live coding environments, VST plugins, audio editing/sequencing applications, and more.

LabSound homepage.

Features

  • Compatibility with the WebAudio API
  • Audio asset loading via libnyquist
  • Binaural audio via IRCAM HRTF database
  • Additional effect & generator nodes (ADSR, noise, stereo delay, and more)
  • Compile-time arbitrary function node for DSP processing
  • Basic signal analysis nodes (time & frequency)
  • Input node (microphone)
  • Non-realtime graph processing & wav export
  • Thread safety model for multi-threaded apps (e.g. gui)
  • SIMD-accelerated channel mixing routines

Platforms

LabSound supports a variety of backends, including RtAudio and CoreAudio.

LabSound is currently tested on

  • Windows 10
  • macOS 10.10 to current
  • Ubuntu 18.04, using the ALSA and Pulse back ends.

In the past, LabSound has been demonstrated to work on iOS, Android, and Linux via JACK.

Building

Users of LabSound are expected to compile LabSound from source. While most dependencies are included as code in the repository, libnyquist is bundled as a git submodule so it is required that new users clone the repository with the --recursive option.

The submodules can be fetched after a clone with git submodule update --init --recursive

LabSound and libnyquist require a C++14 or greater compiler.

Building with Cmake

LabSound has a CMakeLists.txt at the root directory, and all the associated CMake files are in the cmake/ subfolder. In the following examples, the build is done in a nested build directory. This is not required, it's shown for illustrative purposes. You may put the build and the install prefix anywhere you like.

On macOs and Windows:

mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=../../labsound-distro ..
cmake --build . --target install --config Release

On Linux, a backend must be selected, using one of ALSA, Pulse, or Jack. To build with ALSA:

mkdir build
cd build
cmake -DLABSOUND_ASOUND=1 ..
cmake --build . --target install --config Release

On Raspberry Pi, as on Linux, a backend must be selected. The currently tested configuration is ALSA. Be sure to install the asound development libraries before building.

sudo apt install libasound2-dev

On iOS:

mkdir build
cd build
cmake -G "Xcode" -DCMAKE_TOOLCHAIN_FILE=../cmake/ios-toolchain.cmake -DCMAKE_INSTALL_PREFIX=../../labsound-distro-ios ..
cmake --build . --target install --config Release

Examples

LabSound is bundled with many samples. Project files can be found in the examples/ subfolder.

Using the Library

Users should link against liblabsound.a on OSX and labsound.lib on Windows. LabSound also requires symbols from libnyquist, although both the Visual Studio solution and the XCode workspace will build this dependency alongside the core library.

On OSX, new applications also require the following frameworks:

  • Cocoa
  • Accelerate
  • CoreAudio
  • AudioUnit
  • AudioToolbox
  • libnyquist.a

On Windows, new applications also require the following libraries:

  • dsound.lib
  • dxguid.lib
  • winmm.lib
  • libnyquist.lib

For convenience, LabSound.h is used as an index header file with all public nodes included for easy application development.

LabSound includes an HRTF implementation. This creates an additional dependency on a folder of impulse wav files when a PannerNode is configured to use PanningMode::HRTF. The constructor of PannerNode will take an additional path to the sample directory relative to the current working directory.

WebAudio Compatibility

LabSound is derived from one of the original WebAudio implementations, but does not maintain full compatibility with the spec. In many cases, LabSound has deliberately deviated from the spec for performance or API usability reasons. This is expected to continue into the future as new functionality is added to the engine. It possible to reformulate most WebAudio API sample code written in JS as a LabSound sketch (modulo obvious architectual considerations of JavaScript vs C++).

License

LabSound is released under the simplified BSD 2 clause license. All LabSound dependencies are under similar permissive licenses. Further details are located in the LICENSE and COPYING files.

Issues
  • AudioScheduledSourceNode onended?

    AudioScheduledSourceNode onended?

    Hello again. I've been looking through the header of AudioScheduledSourceNode and found no mention of this event. When it ends, it ends, that's it.

    However, there is a lot of (JS) code that expects onended calback to be called. For example in three.js it leads to the warning 'THREE.Audio: Audio is already playing.'.

    If there actually is such an event, please point me in a right direction. And if there are no events in LabSound, then how those should be implemented?

    opened by raub 19
  • Building with cmake/make on macOS and Linux

    Building with cmake/make on macOS and Linux

    Hi. I'm trying to fire-off a cmake on macOS and run immediately into cmake errors. Same goes when I try to fire-off cmake on Debian 9 or CentOS 7. I fire-off the cmake by issuing "cmake ." at the clone's root.

    The problems I am seeing are:

    On macOS:

    1. The "clangdefaults.cmake" file is missing (work around: do a 'touch cmake/defaults/clangdefaults.cmake')
    2. Get the error "error: /arch:AVX: No such file or directory" (work around: comment out the 'target_compile_options(${proj} PRIVATE /arch:AVX /Zi )' line from cmake/defaults/CXXhelpers)
    3. With both these work-arounds in place, the makefiles get made and I issue a 'make' at the clone's root. I then get 42% into the build and get this compiler error:
    [ 42%] Building C object CMakeFiles/libnyquist.dir/third_party/libnyquist/src/VorbisDependencies.c.o
    In file included from /Users/jay/dev/repos/heynow/labsound/third_party/libnyquist/src/VorbisDependencies.c:62:
    In file included from /Users/jay/dev/repos/heynow/labsound/third_party/libnyquist/third_party/libvorbis/src/vorbisenc.c:155:
    /Users/jay/dev/repos/heynow/labsound/third_party/libnyquist/third_party/libvorbis/src/modes/setup_44.h:18:10: fatal error: 
          'modes/floor_all.h' file not found
    #include "modes/floor_all.h"
             ^~~~~~~~~~~~~~~~~~~
    

    Seems to me that the cmake didn't set things up fully for the third_party dependencies. What should I be doing differently here? Invoke cmake with some special arguments?

    A similar set of problems when building on Linux occur:

    1. The "gccdefaults" file is missing (work around: do a 'touch cmake/defaults/gccdefaults')
    2. Get the error "error: /arch:AVX: No such file or directory" (work around: comment out the 'target_compile_options(${proj} PRIVATE /arch:AVX /Zi )' line from cmake/defaults/CXXhelpers)
    3. With both of these work-arounds in place, the makefiles get made and I issue a 'make' at the clone's root. I then get 11% into the build and get this compiler error:
    [ 12%] Building C object CMakeFiles/libopus.dir/third_party/libnyquist/third_party/opus/opusfile/src/info.c.o
    In file included from /home/centos/LabSound/third_party/libnyquist/third_party/libogg/include/ogg/ogg.h:25:0,
                     from /home/centos/LabSound/third_party/libnyquist/third_party/opus/opusfile/include/opusfile.h:109,
                     from /home/centos/LabSound/third_party/libnyquist/third_party/opus/opusfile/src/include/internal.h:32,
                     from /home/centos/LabSound/third_party/libnyquist/third_party/opus/opusfile/src/info.c:16:
    /home/centos/LabSound/third_party/libnyquist/third_party/libogg/include/ogg/os_types.h:143:32: fatal error: ogg/config_types.h: No such file or directory
     #  include <ogg/config_types.h>
    

    Again, it seems like I'm missing something here using cmake. Or.. is it possible no one has recently done 'make' builds recently on this repository? Please advise, and, THANK YOU for your help.

    /Jay

    opened by jkoutavas 19
  • Running the example results in no wave file playback

    Running the example results in no wave file playback

    Hi there,

    I've just cloned the master again and tried running the example (e_simple) but noticed how the sine wave is playing but the audio file is not.

    I've also updated the library in a project that I am developing and have come across the exact same issue.

    Here is the log produced by running the example project:

    Toms-MacBook-Pro:bin tombutcher$ ./LabSoundExample 
    11:28:03 TRACE /Users/tombutcher/Projects/xxxxx/lib/LabSound/src/extended/LabSound.cpp:33: MakeAudioDeviceList()
    11:28:03 INFO  /Users/tombutcher/Projects/xxxxx/lib/LabSound/src/backends/RtAudio/AudioDevice_RtAudio.cpp:42: using rtaudio api macos_coreaudio
    11:28:03 TRACE /Users/tombutcher/Projects/xxxxx/lib/LabSound/src/extended/LabSound.cpp:39: GetDefaultOutputAudioDeviceIndex()
    11:28:03 TRACE /Users/tombutcher/Projects/xxxxx/lib/LabSound/src/extended/LabSound.cpp:45: GetDefaultInputAudioDeviceIndex()
    11:28:03 TRACE /Users/tombutcher/Projects/xxxxx/lib/LabSound/src/extended/LabSound.cpp:51: MakeRealtimeAudioContext()
    11:28:03 INFO  /Users/tombutcher/Projects/xxxxx/lib/LabSound/src/backends/RtAudio/AudioDevice_RtAudio.cpp:124: using output device idx: 1
    11:28:03 INFO  /Users/tombutcher/Projects/xxxxx/lib/LabSound/src/backends/RtAudio/AudioDevice_RtAudio.cpp:125: using output device name: Apple Inc.: Built-in Output
    11:28:03 INFO  /Users/tombutcher/Projects/xxxxx/lib/LabSound/src/backends/RtAudio/AudioDevice_RtAudio.cpp:130: using input device idx: -1
    11:28:03 INFO  /Users/tombutcher/Projects/xxxxx/lib/LabSound/src/core/AudioHardwareDeviceNode.cpp:47: MakePlatformSpecificDevice() 
    	* Sample Rate:     48000.000000 
    	* Input Channels:  0 
    	* Output Channels: 2   
    11:28:03 TRACE /Users/tombutcher/Projects/xxxxx/lib/LabSound/src/core/AudioContext.cpp:287: Begin UpdateGraphThread
    

    I've ensured that the samples folder copied from the assets directory is present:

    Toms-MacBook-Pro:bin tombutcher$ ls
    LabSoundExample	samples
    Toms-MacBook-Pro:bin tombutcher$ 
    

    The previous commit I used which worked was: https://github.com/LabSound/LabSound/commit/c0d778fef727432ad2280863e818280e6669c92e

    Sorry for annoying you guys by constantly submitting issues. This is a really good library.

    bug 
    opened by tom-23 18
  • AudioParams in Panner and Listener

    AudioParams in Panner and Listener

    According to the spec such properties as AudioListener::positionX must be of type AudioParam with gettable/settable value.

    In LabSound only direct void setPosition(float x, float y, float z) is available. And this is actually deprecated, because of reasons.

    Is there any plan on converting those into AudioParams?

    opened by raub 12
  • Samples playback does not work if no input device is available

    Samples playback does not work if no input device is available

    It seems that the samples do not play on Windows when no input device is available. If I enable/add an input device (stereo mix, mic etc.), the samples start playing.

    Poking around the code it looks like AudioDestinationWin always tries to open the input device in AudioDestinationWin::configure: dac.openStream(&outputParams, &inputParams ... which fails and closes the stream. Later in AudioDestinationWin::start, dac.startStream fails and render is never called.

    If I change AudioDestinationWin to not open or use input in render it fixes the issue, but it feels like a hack. Input should probably be optional on AudioDestination?

    bug pending merge 
    opened by Almost-Done 11
  • ASSERTION FAILED Error when trying to use the example app

    ASSERTION FAILED Error when trying to use the example app

    I'm trying to run Simple.h and I get this error:

    Thomass-Air:bin thomasbutcher$ ./LabSoundExample [/Volumes/DataSSD/MultiWAV/src/mw4/MultiWAV/multiwav/lib/LabSound/src/core/SampledAudioNode.cpp @ 169] ASSERTION FAILED: isLengthGood [/Volumes/DataSSD/MultiWAV/src/mw4/MultiWAV/multiwav/lib/LabSound/src/core/OscillatorNode.cpp @ 213] ASSERTION FAILED: quantumFrameOffset <= framesToProcess Segmentation fault: 11

    information needed 
    opened by tom-23 11
  • Is there a way to build this without external WebKit dependencies?

    Is there a way to build this without external WebKit dependencies?

    I'm trying to setup LabSound to build using gyp, and get it running on Windows, because I think it's a cool project. Unfortunately, it seems like a lot of the sources are looking for WebCore/WebCoreHeaderDetection.h, which is not in the repository. Am I configuring something incorrectly, or do you have some external dependencies that I can setup on my machine.

    opened by ZECTBynmo 10
  • SampledAudioNode::schedule(double when) should use absolute time

    SampledAudioNode::schedule(double when) should use absolute time

    opened by xioxin 9
  • Why nuke AudioBuffer?

    Why nuke AudioBuffer?

    So, speaking of WAA, they have this kind of interface:

    interface BaseAudioContext : EventTarget {
    ...
        AudioBuffer            createBuffer (unsigned long numberOfChannels, unsigned long length, float sampleRate);
        Promise<AudioBuffer>   decodeAudioData (ArrayBuffer audioData, optional DecodeSuccessCallback successCallback, optional DecodeErrorCallback errorCallback);
    

    And then those guys in threejs use it:

    	Object.assign( AudioLoader.prototype, {
    
    		load: function ( url, onLoad, onProgress, onError ) {
    
    			var loader = new FileLoader( this.manager );
    			loader.setResponseType( 'arraybuffer' );
    			loader.load( url, function ( buffer ) {
    
    				var context = AudioContext.getContext();
    
    				context.decodeAudioData( buffer, function ( audioBuffer ) {
    
    					onLoad( audioBuffer );
    
    				} );
    
    			}, onProgress, onError );
    
    		}
    
    	} );
    

    Well, that boders me a lot, since I'm currently investigating ways to port LabSound onto Node.js. But as LabSound does not comply with WAA standard so far, I would have to patch it first. This is why I ask if there is any meaningful explanation for 934b6bfc9b129ceafcd7f7f38c3cf8f218a2f36e ? Probably there were some issues with this class, or it was just a matter of over-optimization?

    opened by raub 9
  • How to crosscompile for Android

    How to crosscompile for Android

    Hello, I was trying to use LabSound in Android. I was encouraged when I saw the following in the README.md:

    In the past, LabSound has been demonstrated to work on iOS, Android, and Linux via JACK.

    However I'm quite new to crosscompilation and I must admit that I'm a little bit lost in the field. As extra information, I'm compiling from a 86x64 Linux (Ubuntu 18.04 distribution). Any advice or hint on how to compile this project for Android would be useful.

    Thank you so much.

    pending merge new backend 
    opened by jrojoCI3 8
  • v8 engine excluded?

    v8 engine excluded?

    One thing I notice in this implementation is that you seem to have left in merely the Web Audio objects without any reference to a DOM or to the v8 JavaScript engine. When I considered doing a similar project, my original thinking was that it might have been handy to have the JavaScript core floating about as well, to permit high-level scripting and interconnection of elements, and also hopefully to facilitate development of editors and the like for the object interconnect formats. What are your thoughts on development and representation of exchangeable node interconnect formats for audio engineers who don't know scripting or C++?

    opened by johnwbyrd 8
  • biquadfilter's high shelf and low shelf have no effect?

    biquadfilter's high shelf and low shelf have no effect?

    image

    (the curve that's showing up is because I captured an image with Brown instead of White noise)

    Not a LabSound issue... Here's the canonical WebAudio response curves; selecting the shelf variants, there doesn't seem to be any way to get a curve out of it, at least on Safari:

    https://rtoy.github.io/webaudio-hacks/more/biquad/biquad-coef.html

    The discussion here - https://github.com/WebAudio/web-audio-api-v2/issues/67 - seems to suggest that the behavior of the shelf modes is unsatisfactory.

    So the shelves seem to be broken on WebAudio/WebKit as well. I think we either need proper shelving filters added as a switch inside the BiquadFilter, or we need a new node with a good implementation. Unless if I'm missing something obvious, and there's a parameter to set on the shelves to make it do .... anything at all

    bug WebAudio compatibility 
    opened by meshula 0
  • In Android if switch audio devices it will cause stopping the playback.

    In Android if switch audio devices it will cause stopping the playback.

    I found a possible way to run the "ma_device_init" method again.

    I don't know how to get device change events via C++, so I have to trigger them manually for now.

    https://github.com/xioxin/LabSound/commit/7d0b8deb47d2a268b87bde9cdcb1729baa321638

    Is there a better solution?

    bug Android 
    opened by xioxin 3
  • Implement AudioContext close

    Implement AudioContext close

    Documentation is here - https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/close

    In summary -

    Close releases any system audio resources that it uses. It is asynchronous, returning a promise object that can wait() until all AudioContext-creation-blocking resources have been released

    Closed contexts cannot have new nodes created, but can decode audio data, create buffers, etc. It will forcibly release any system audio resources that might prevent additional AudioContexts from being created and used, suspend the progression of audio time in the audio context, and stop processing audio data.

    WebAudio compatibility 
    opened by meshula 0
  • How to build LabSound projects with Emscripten?

    How to build LabSound projects with Emscripten?

    I succeded building examples using emcmake cmake -DCMAKE_INSTALL_PREFIX='../labsound-distro-emcc' .. cmake --build . --target install

    but when I try to run the output .js file I get a console error: "RtApiDummy: This class provides no functionality".

    new backend 
    opened by DanieleCapuano 8
Releases(v1.0.1)
  • v1.0.1(Apr 12, 2021)

    Introduces working iOS, Android, and Raspberry Pi targets. Raspberry Pi requires libpulse-dev to be installed to compile.

    This is otherwise a maintenance release, fixing small regressions that slipped through in Release 1.0

    Source code(tar.gz)
    Source code(zip)
  • v1.0.0(Jan 16, 2021)

    This 1.0 release finalizes the API with functionality that allows full introspection of all nodes and attributes. To go with this 1.0, LabSoundGraphToy is also released at https://github.com/LabSound/LabSoundGraphToy to enable exploration of the library, its nodes, and its functionality.

    Source code(tar.gz)
    Source code(zip)
  • v0.14.0(Mar 15, 2020)

    • Removed many custom backends in favor of RtAudio and miniaudio
    • Consolidated demos into a single header
    • clang format applied to sources
    • cloning method added to AudioBus
    • Added Input and Output configuration structs to allow selection of devices
    • names added for params and settings for use in tools
    • Bus added as available Setting type
    • ADSRNode timing fixed
    • AnalyserNode can render output to any desired output buffer size by binning and interpolation
    • AudioDevice nodes added in major backend refactoring
    • ConvolverNode - new implementation
    • DiodeNode is now derived from AudioNode
    • OscillatorNode - new implementation
    • SuperSaw is now scheduled
    Source code(tar.gz)
    Source code(zip)
  • v0.13.0(Aug 18, 2019)

    AudioParams already exist for rate varying values on Audio Nodes. AudioParams are registered on nodes by name, and can be looked up by name. Non-rate varying parameters such as filter modes, buffer sizes, and so on could not be similarly looked up by name. AudioSettings are introduced in this release for non-rate varying parameters, such as filter modes, buffer sizes and so on. Settings for each AudioNode are documented in its corresponding header file. A vector of param or setting names can be fetched from an AudioNode and used to populate a user interface. Each fetched AudioSetting can be queried as to whether its last set type was a Uint32 or a Float, in order that user interfaces can self configure appropriately.

    Added some nullchecks to AudioChannel memory management as pointed out by harmonicvision

    Source code(tar.gz)
    Source code(zip)
  • v0.12.0(Jan 5, 2018)

    This release primarily cleans up how AudioNodes are connected to one another. Formerly, the connect(...) method was called directly on an AudioNode, taking the graph lock and effecting changes to the AudioContext itself. This is no longer the case. AudioContext is now the arbiter of all graph changes.

    Source code(tar.gz)
    Source code(zip)
  • v0.11.0(Jan 5, 2018)

  • v0.10.0(Jan 3, 2016)

PortAudio is a portable audio I/O library designed for cross-platform support of audio

PortAudio is a cross-platform, open-source C language library for real-time audio input and output.

PortAudio 668 Aug 2, 2022
Open source digital sound effects based on JACK audio connection kit.

Noiseworks Digital Audio Effects Repository Open source digital sound effects based on JACK audio connection kit. This repository is intended to provi

null 5 Jul 29, 2022
Capture audio from a microphone on your Raspberry Pi Pico or any RP2040 based board. 🎤

Capture audio from a microphone on your Raspberry Pi Pico or any RP2040 based board. ??

Arm Developer Ecosystem 107 Jul 31, 2022
A command line and keyboard based strategy-game written in c++, where audio-input determines the AI-strategy and lays the seed for the map-generation.

Table of contents Dissonance Premise Installation Requirements Installation Quick-guide Detailed installation guide Usage Logfiles Tests Uninstall Kno

fux 23 May 21, 2022
A simple and easy-to-use audio library based on miniaudio

raudio A simple and easy-to-use audio library based on miniaudio raudio forks from raylib.audio module to become an standalone library. Actually, it w

Ray 53 Aug 6, 2022
Twist A node-based audio synthesizer written in C++

Not maintained anymore! Twist A node-based audio synthesizer written in C++ Twist is the unexpected result of me trying to experiment with audio progr

Diego Lopes 123 Jun 29, 2022
Ncurses based audio tracker program inspired by goattracker and milkytracker

PLEBTracker PLEBTracker is a linux console based audio tracker program inspired by goattracker and milkytracker. Pattern editor, main song editor wind

Dan Frazier 91 Aug 5, 2022
A simple C++ library for reading and writing audio files.

AudioFile A simple header-only C++ library for reading and writing audio files. Current supported formats: WAV AIFF Author AudioFile is written and ma

Adam Stark 615 Aug 2, 2022
A C library for reading and writing sound files containing sampled audio data.

libsndfile libsndfile is a C library for reading and writing files containing sampled audio data. Authors The libsndfile project was originally develo

null 1k Aug 4, 2022
C library for cross-platform real-time audio input and output

libsoundio C library providing cross-platform audio input and output. The API is suitable for real-time software such as digital audio workstations as

Andrew Kelley 1.6k Aug 7, 2022
C++ Audio and Music DSP Library

_____ _____ ___ __ _ _____ __ __ __ ____ ____ / \\_ \\ \/ / |/ \| | | | \_ \/ \ | Y Y \/ /_ \> <| | Y Y \ | |_|

Mick Grierson 1.3k Aug 3, 2022
Single file audio playback and capture library written in C.

A single file library for audio playback and capture. Example - Documentation - Supported Platforms - Backends - Major Features - Building - Unofficia

David Reid 2.4k Aug 10, 2022
SimplE Lossless Audio

SELA SimplE Lossless Audio A lossless audio codec which aims to be as simple as possible while still having good enough compression ratios. Code Quali

Ratul Saha 206 May 11, 2022
Easy and efficient audio synthesis in C++

Tonic Fast and easy audio synthesis in C++. Prefer coding to patching? Love clean syntax? Care about performance? That's how we feel too, and why we m

null 466 Aug 9, 2022
An audio mixer that supports various file formats for Simple Directmedia Layer.

An audio mixer that supports various file formats for Simple Directmedia Layer.

Simple Directmedia Layer 143 Aug 9, 2022
Explore fractals in an audio-visual sandbox

Fractal Sound Explorer Explore fractals in an audio-visual sandbox Download executable on my itch.io page: https://codeparade.itch.io/fractal-sound-ex

null 945 Aug 5, 2022
Audio out with an FTDI UART cable

Audio out with an FTDI UART cable This encodes audio as either PDM (using a first order sigma-delta stage), 32-bits PWM or 64-bits PWM and sends it as

Konrad Beckmann 42 Jun 23, 2022
Sexy, audio-responsive effects on LED strips.

Striptease Sexy, audio-responsive effects on LED strips. For Teensy 4 with Audio Adapter Board, by PJRC. Quick demo Shooting video of LEDs is very tri

Luca Paolini 35 Jun 19, 2022
audio monitor filter for OBS Studio

Audio Monitor dock and filter for OBS Studio Plugin for OBS Studio to add Audio Monitor dock and filter. It allows you to put the audio of a OBS sourc

Exeldro 187 Jul 30, 2022