RtAudio Documentation

repository·master·Indexed 23 days ago

https://github.com/thestk/rtaudio

A cross-platform C++ library providing a unified API for real-time audio I/O. It abstracts audio backends including ALSA, JACK, and PulseAudio on Linux; CoreAudio and JACK on macOS; and DirectSound, ASIO, and WASAPI on Windows. Features include an object-oriented design, support for simultaneous multi-API usage, and a Python wrapper called PyRtAudio.

Tokens
665
Snippets
1
Records
5
Agent score
33%

What's inside RtAudio

  1. Overview of RtAudio

    master

    RtAudio is a C++ library providing a unified API for real-time audio input and output across multiple operating systems. It simplifies hardware interaction by providing a common interface for:

    • Linux: ALSA, JACK, PulseAudio, and OSS.
    • macOS: CoreAudio and JACK.
    • Windows: DirectSound, ASIO, and WASAPI.

    Key features include:

    • Object-oriented C++ design.
    • Single header and source file for easy integration.
    • Support for simultaneous multi-API usage.
    • Dynamic device connection and capability probing.
    • Automatic internal conversion for data formats, channel compensation, (de)interleaving, and byte-swapping.

    Core Concept: Audio Streams RtAudio uses the concept of audio streams to represent audio playback (output) or recording (input). You enumerate available devices and their capabilities, then specify them when opening a stream.

  2. Use RtAudio as a module

    master

    RtAudio can be used as a module. To enable this, you must build with the RTAUDIO_BUILD_MODULES flag.

    Once enabled, it is accessed via:

    import rt.audio;

    Namespaces are implicitly imported unless RTAUDIO_USE_NAMESPACE is defined. Classes can be accessed via the rt::audio namespace or the global namespace (e.g., rt::audio::RtApi or ::RtApi).

  3. Build and Install RtAudio

    master

    RtAudio can be built using several different build systems. By default, all detected audio APIs will be enabled. For specific backend API selection, refer to install.txt.

    Build Systems

    Autotools (Recommended for packaging):

    # From git
    ./autogen.sh; make
    
    # From tarball release
    ./configure; make

    CMake:

    mkdir build; cd build; ../cmake; make

    Meson:

    meson build; cd build; ninja

    vcpkg:

    ./bootstrap-vcpkg.sh; ./vcpkg integrate install; ./vcpkg install rtaudio

    Direct Integration

    RtAudio is designed as a single .cpp and .h file. You can copy these files directly into your project. If you do this, you must manually define the appropriate flags for the desired backend APIs.

  4. Install PyRtAudio

    master

    PyRtAudio is a Python wrapper for RtAudio used for real-time audio I/O operations. Installation is handled via Python's distutils. You must have a C++ compiler configured on your system to compile and install the module.

    To install, run the following command from the PyRtAudio directory:

    python setup.py install
  5. Handling 1-channel to stereo output

    master

    RtAudio does not automatically convert 1-channel (mono) output into 2-channel (stereo) output by duplicating values. If you require monophonic data to be projected to stereo output, you must:

    1. Open a 2-channel stream.
    2. Manually copy the mono data to both channels within your audio stream callback.