Convert Figma logo to code with AI

kcat logoopenal-soft

OpenAL Soft is a software implementation of the OpenAL 3D audio API.

2,152
523
2,152
228

Top Related Projects

C library for cross-platform real-time audio input and output

1,489

A set of C++ classes that provide a common API for realtime audio input/output across Linux (native ALSA, JACK, PulseAudio and OSS), Macintosh OS X (CoreAudio and JACK), and Windows (DirectSound, ASIO, and WASAPI) operating systems.

Audio playback and capture library written in C, in a single source file.

9,377

Simple Directmedia Layer

Quick Overview

OpenAL Soft is an open-source, cross-platform audio library that provides a high-level API for playing back audio in a variety of formats. It is a fork of the original OpenAL library and aims to provide a more feature-rich and well-maintained implementation.

Pros

  • Cross-Platform: OpenAL Soft is available on a wide range of platforms, including Windows, macOS, Linux, and various mobile operating systems.
  • Flexible Audio Playback: The library supports a variety of audio formats, including WAV, FLAC, Ogg Vorbis, and more, allowing for flexible audio playback in applications.
  • Spatial Audio: OpenAL Soft provides support for spatial audio, enabling the creation of immersive 3D audio experiences.
  • Active Development: The project is actively maintained, with regular updates and bug fixes, ensuring a reliable and up-to-date library.

Cons

  • Limited Documentation: The project's documentation could be more comprehensive, making it challenging for new users to get started.
  • Steep Learning Curve: Integrating OpenAL Soft into a project may require a significant amount of time and effort, especially for developers unfamiliar with audio programming.
  • Dependency on External Libraries: OpenAL Soft relies on several external libraries, which can add complexity to the build process and deployment.
  • Potential Performance Issues: Depending on the complexity of the audio setup and the hardware, OpenAL Soft may not always provide optimal performance, especially in resource-constrained environments.

Code Examples

Here are a few code examples demonstrating the usage of OpenAL Soft:

  1. Basic Audio Playback:
#include <AL/al.h>
#include <AL/alc.h>

int main() {
    ALCdevice *device = alcOpenDevice(NULL);
    ALCcontext *context = alcCreateContext(device, NULL);
    alcMakeContextCurrent(context);

    ALuint source, buffer;
    alGenSources(1, &source);
    alGenBuffers(1, &buffer);

    // Load audio data into the buffer
    alBufferData(buffer, AL_FORMAT_MONO16, audio_data, audio_size, sample_rate);
    alSourcei(source, AL_BUFFER, buffer);

    alSourcePlay(source);

    // Wait for the audio to finish playing
    ALint state;
    do {
        alGetSourcei(source, AL_SOURCE_STATE, &state);
    } while (state == AL_PLAYING);

    alDeleteSources(1, &source);
    alDeleteBuffers(1, &buffer);
    alcDestroyContext(context);
    alcCloseDevice(device);

    return 0;
}
  1. Spatial Audio Positioning:
#include <AL/al.h>
#include <AL/alc.h>

int main() {
    ALCdevice *device = alcOpenDevice(NULL);
    ALCcontext *context = alcCreateContext(device, NULL);
    alcMakeContextCurrent(context);

    ALuint source, buffer;
    alGenSources(1, &source);
    alGenBuffers(1, &buffer);

    // Load audio data into the buffer
    alBufferData(buffer, AL_FORMAT_MONO16, audio_data, audio_size, sample_rate);
    alSourcei(source, AL_BUFFER, buffer);

    // Set the source position
    alSource3f(source, AL_POSITION, 10.0f, 0.0f, 0.0f);

    alSourcePlay(source);

    // Wait for the audio to finish playing
    ALint state;
    do {
        alGetSourcei(source, AL_SOURCE_STATE, &state);
    } while (state == AL_PLAYING);

    alDeleteSources(1, &source);
    alDeleteBuffers(1, &buffer);
    alcDestroyContext(context);
    alcCloseDevice(device);

    return 0;
}
  1. Environmental Audio Effects:
#include <AL/al.h>
#include <AL/

Competitor Comparisons

C library for cross-platform real-time audio input and output

Pros of libsoundio

  • Cross-platform support: libsoundio provides a cross-platform API, allowing developers to write audio applications that work on multiple operating systems.
  • Low-level access: libsoundio offers a low-level interface to the underlying audio system, giving developers more control and flexibility.
  • Asynchronous I/O: libsoundio supports asynchronous I/O, which can be beneficial for real-time audio applications.

Cons of libsoundio

  • Smaller community: OpenAL-Soft has a larger community and more widespread adoption compared to libsoundio.
  • Limited documentation: The documentation for libsoundio may not be as comprehensive as that of OpenAL-Soft.
  • Fewer features: OpenAL-Soft provides a more feature-rich set of capabilities, such as support for 3D audio and HRTF processing.

Code Comparison

Here's a brief code comparison between OpenAL-Soft and libsoundio:

OpenAL-Soft (kcat/openal-soft):

ALCdevice *device = alcOpenDevice(NULL);
ALCcontext *context = alcCreateContext(device, NULL);
alcMakeContextCurrent(context);

ALuint source;
alGenSources(1, &source);
alSourcef(source, AL_PITCH, 1.0f);
alSourcef(source, AL_GAIN, 1.0f);
alSource3f(source, AL_POSITION, 0.0f, 0.0f, 0.0f);
alSource3f(source, AL_VELOCITY, 0.0f, 0.0f, 0.0f);
alSourcei(source, AL_BUFFER, buffer);
alSourcePlay(source);

libsoundio (andrewrk/libsoundio):

struct SoundIoOutStream *outstream;
soundio_outstream_open(outstream);
soundio_outstream_start(outstream);

int frame_count = 1024;
float **frames = malloc(sizeof(float *) * outstream->layout.channel_count);
for (int i = 0; i < outstream->layout.channel_count; i++) {
    frames[i] = malloc(sizeof(float) * frame_count);
}

soundio_outstream_begin_write(outstream, &frames, &frame_count);
soundio_outstream_end_write(outstream);
1,489

A set of C++ classes that provide a common API for realtime audio input/output across Linux (native ALSA, JACK, PulseAudio and OSS), Macintosh OS X (CoreAudio and JACK), and Windows (DirectSound, ASIO, and WASAPI) operating systems.

Pros of rtaudio

  • Supports a wide range of audio APIs, including ASIO, JACK, CoreAudio, and more, making it more versatile than OpenAL-Soft.
  • Provides a simple and consistent API for cross-platform audio programming.
  • Actively maintained with regular updates and bug fixes.

Cons of rtaudio

  • Smaller community and fewer resources compared to the larger OpenAL-Soft project.
  • May have fewer features and optimizations compared to the more specialized OpenAL-Soft library.
  • Requires more manual configuration and setup compared to the more plug-and-play nature of OpenAL-Soft.

Code Comparison

OpenAL-Soft (kcat/openal-soft):

ALCdevice *device = alcOpenDevice(NULL);
ALCcontext *context = alcCreateContext(device, NULL);
alcMakeContextCurrent(context);

alGenSources(1, &source);
alSourcef(source, AL_PITCH, 1.0f);
alSourcef(source, AL_GAIN, 1.0f);
alSource3f(source, AL_POSITION, 0.0f, 0.0f, 0.0f);
alSource3f(source, AL_VELOCITY, 0.0f, 0.0f, 0.0f);
alSourcei(source, AL_BUFFER, buffer);

rtaudio (thestk/rtaudio):

RtAudio audio;
if (audio.getDeviceCount() < 1) {
    std::cout << "No audio devices found!" << std::endl;
    return 0;
}

RtAudio::StreamParameters parameters;
parameters.deviceId = audio.getDefaultOutputDevice();
parameters.nChannels = 2;
parameters.firstChannel = 0;

audio.openStream(&parameters, NULL, RTAUDIO_FLOAT32, 44100, &bufferSize, &callback, (void*)&data);
audio.startStream();

Audio playback and capture library written in C, in a single source file.

Pros of miniaudio

  • Simplicity: miniaudio is a single-file audio library, making it easy to integrate into projects without the overhead of a larger library.
  • Cross-platform: miniaudio supports a wide range of platforms, including Windows, macOS, Linux, and embedded systems.
  • Flexibility: miniaudio provides a simple and flexible API that allows developers to easily customize the library to their specific needs.

Cons of miniaudio

  • Limited features: Compared to OpenAL-soft, miniaudio has a more limited set of features, such as fewer audio file format support and less advanced audio processing capabilities.
  • Smaller community: OpenAL-soft has a larger and more active community, which can mean more support, documentation, and third-party integrations.
  • Potential performance trade-offs: The simplicity and single-file design of miniaudio may come with some performance trade-offs compared to a more comprehensive library like OpenAL-soft.

Code Comparison

OpenAL-soft (kcat/openal-soft):

ALCdevice *device = alcOpenDevice(NULL);
ALCcontext *context = alcCreateContext(device, NULL);
alcMakeContextCurrent(context);

ALuint source;
alGenSources(1, &source);
alSourcef(source, AL_PITCH, 1.0f);
alSourcef(source, AL_GAIN, 1.0f);
alSource3f(source, AL_POSITION, 0.0f, 0.0f, 0.0f);
alSource3f(source, AL_VELOCITY, 0.0f, 0.0f, 0.0f);
alSourcei(source, AL_BUFFER, buffer);
alSourcePlay(source);

miniaudio (mackron/miniaudio):

ma_device_config config = ma_device_config_init(ma_device_type_playback);
config.playback.format   = ma_format_f32;
config.playback.channels = 2;
config.sampleRate        = 44100;
ma_device device;
ma_device_init(NULL, &config, &device);
ma_device_start(&device);

ma_pcm_frames_t frames = ma_data_source_read_pcm_frames(data_source, buffer, 1024);
ma_device_write(&device, buffer, frames);
9,377

Simple Directmedia Layer

Pros of SDL

  • SDL provides a comprehensive set of APIs for various multimedia tasks, including window management, input handling, and audio/video playback.
  • SDL has a large and active community, with extensive documentation and a wide range of third-party libraries and tools available.
  • SDL is cross-platform, supporting a variety of operating systems, including Windows, macOS, and Linux.

Cons of SDL

  • SDL can have a steeper learning curve compared to OpenAL-Soft, especially for developers who are new to game development or multimedia programming.
  • SDL may have a larger memory footprint and higher resource requirements compared to OpenAL-Soft, which is more focused on audio-specific tasks.

Code Comparison

OpenAL-Soft (kcat/openal-soft):

ALCdevice *device;
ALCcontext *context;

device = alcOpenDevice(NULL);
context = alcCreateContext(device, NULL);
alcMakeContextCurrent(context);

// Set up audio sources and buffers
alGenSources(1, &source);
alGenBuffers(1, &buffer);
alBufferData(buffer, AL_FORMAT_MONO16, audio_data, audio_size, sample_rate);
alSourcei(source, AL_BUFFER, buffer);

SDL (libsdl-org/SDL):

SDL_Init(SDL_INIT_AUDIO);
SDL_AudioSpec want, have;
SDL_AudioDeviceID dev;

want.freq = 44100;
want.format = AUDIO_S16SYS;
want.channels = 2;
want.samples = 2048;
want.callback = my_audio_callback;
want.userdata = NULL;

dev = SDL_OpenAudioDevice(NULL, 0, &want, &have, 0);
SDL_PauseAudioDevice(dev, 0);

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

OpenAL Soft

master branch CI status : GitHub Actions Status Windows Build Status

OpenAL Soft is an LGPL-licensed, cross-platform, software implementation of the OpenAL 3D audio API. It's forked from the open-sourced Windows version available originally from openal.org's SVN repository (now defunct). OpenAL provides capabilities for playing audio in a virtual 3D environment. Distance attenuation, doppler shift, and directional sound emitters are among the features handled by the API. More advanced effects, including air absorption, occlusion, and environmental reverb, are available through the EFX extension. It also facilitates streaming audio, multi-channel buffers, and audio capture.

More information is available on the official website.

Source Install

To install OpenAL Soft, use your favorite shell to go into the build/ directory, and run:

cmake ..

Alternatively, you can use any available CMake front-end, like cmake-gui, ccmake, or your preferred IDE's CMake project parser.

Assuming configuration went well, you can then build it. The command cmake --build . will instruct CMake to build the project with the toolchain chosen during configuration (often GNU Make or NMake, although others are possible).

Please Note: Double check that the appropriate backends were detected. Often, complaints of no sound, crashing, and missing devices can be solved by making sure the correct backends are being used. CMake's output will identify which backends were enabled.

For most systems, you will likely want to make sure PipeWire, PulseAudio, and ALSA were detected (if your target system uses them). For Windows, make sure WASAPI was detected.

Building openal-soft - Using vcpkg

You can download and install openal-soft using the vcpkg dependency manager:

git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.sh
./vcpkg integrate install
./vcpkg install openal-soft

The openal-soft port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please create an issue or pull request on the vcpkg repository.

Utilities

The source package comes with an informational utility, openal-info, and is built by default. It prints out information provided by the ALC and AL sub- systems, including discovered devices, version information, and extensions.

Configuration

OpenAL Soft can be configured on a per-user and per-system basis. This allows users and sysadmins to control information provided to applications, as well as application-agnostic behavior of the library. See alsoftrc.sample for available settings.

Language Bindings

As a C API, OpenAL Soft can be used directly by any language that can use functions with C linkage. For languages that can't directly use C-style headers, bindings may be developed to allow code written in that language to call into the library. Some bindings for some languages are listed here.

C# Bindings:

  • OpenTK includes low-level C# bindings for the OpenAL API, including some extensions. It also includes utility libraries for math and linear algebra, which can be useful for 3D calculations.

Java Bindings:

  • JOAL, part of the JogAmp project, includes Java bindings for the OpenAL API, usable with OpenAL Soft. It also includes a higher level Sound3D Toolkit API and utility functions to make easier use of OpenAL features and capabilities.

Python Bindings:

  • PyOpenAL. Also includes methods to play wave files and, with PyOgg, also Vorbis, Opus, and FLAC.

Other bindings for these and other languages also exist. This list will grow as more bindings are found.

Acknowledgements

Special thanks go to:

  • Creative Labs for the original source code this is based off of.
  • Christopher Fitzgerald for the current reverb effect implementation, and helping with the low-pass and HRTF filters.
  • Christian Borss for the 3D panning code previous versions used as a base.
  • Ben Davis for the idea behind a previous version of the click-removal code.
  • Richard Furse for helping with my understanding of Ambisonics that is used by the various parts of the library.