#audio-devices #sound #multi-channel #play #record #stream

multichannel_audio

Play and record multichannel audio in Rust

4 releases

0.2.1 Aug 30, 2024
0.2.0 Aug 21, 2024
0.1.1 Aug 14, 2024
0.1.0 Aug 14, 2024

#209 in Audio

Download history 231/week @ 2024-08-11 141/week @ 2024-08-18 123/week @ 2024-08-25 20/week @ 2024-09-01

515 downloads per month

MIT license

6MB
802 lines

Multichannel Rust Audio

This library provides an easy to use audio library to play and record multi-channel audio.

It is inspired by Python Sounddevice and its beginner-friendly functions.

This library is primarily a wrapper around the CPAL crate. It abstracts the stream creation and provides simple play/record functions.

Currently only Linux and Windows are supported while using Focusrite audio interfaces. More support is planned in the future.

Getting Started

Add the following to your Cargo.toml file

[dependencies]
multichannel_audio = "0.1.0"

How To Use

  • If you are on Windows, please follow the directions in the CPAL Documentation in the ASIO on Windows section to set up the ASIO SDK.

  • Initialize the audio device once at the start of your program.

  • Prepare a 2-dimensional audio array with number of columns equal to the number of channels on your audio device. Ex. If playing on a stereo 2-channel device, your array would be 2 by x where x is the number of samples to play.

  • Record for a specified duration into a new 2-dimensional array. The same principles apply as playback for the shape of the data.

Examples

Play White Noise out of channel 1 of a 6-channel audio device at 48kHz sample rate

set_host_and_audio_device().unwrap();

let signal = generate_gaussian_white_noise(5.0, 48000, None);
let mut multichannel_signal = vec![vec![0; 5 * 48000]; 6];
multichannel_signal[0] = signal;

let audio_instance = audio_class::AudioInstance::new(48000).unwrap();
audio_instance.play(multichannel_signal).unwrap();

Record for 5 seconds

set_host_and_audio_device().unwrap();

let audio_instance = audio_class::AudioInstance::new(48000).unwrap();
let recording = audio_instance.record(5.0).unwrap();

Licence

Licensed under the MIT License (LICENSE or https://opensource.org/license/MIT)

Dependencies

~0.7–29MB
~426K SLoC