Skip to content

theashraf/rminiaudio

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rminiaudio

Ergonomic Rust bindings for miniaudio, a single-file audio playback and capture library.

Features

  • Safe, idiomatic Rust API with builder pattern
  • Audio playback and capture with closure-based callbacks
  • Device enumeration
  • Cross-platform: macOS, Linux, Windows

Installation

Add to your Cargo.toml:

[dependencies]
rminiaudio = { path = "." }

System Dependencies

Platform Requirements
macOS Xcode Command Line Tools (ships with CoreAudio)
Linux libasound2-dev (ALSA), libclang-dev (for bindgen)
Windows MSVC build tools

Ubuntu/Debian:

sudo apt-get install libasound2-dev libclang-dev

Quick Start

use rminiaudio::{Context, DeviceConfig, DeviceType, Format};

fn main() {
    let ctx = Context::new().expect("failed to init audio context");

    // List playback devices
    for dev in ctx.playback_devices().unwrap() {
        println!("  {}", dev.name);
    }

    // Play a 440 Hz sine wave
    let sample_rate = 44100u32;
    let mut phase = 0.0f32;

    let config = DeviceConfig::new(DeviceType::Playback)
        .sample_rate(sample_rate)
        .channels(2)
        .format(Format::F32)
        .data_callback(move |output, _input| {
            for frame in output.chunks_exact_mut(2) {
                let sample = (phase * 2.0 * std::f32::consts::PI).sin() * 0.2;
                frame[0] = sample;
                frame[1] = sample;
                phase += 440.0 / sample_rate as f32;
                if phase >= 1.0 { phase -= 1.0; }
            }
        });

    let device = ctx.create_device(config).unwrap();
    device.start().unwrap();
    std::thread::sleep(std::time::Duration::from_secs(3));
    // Device stops and cleans up on drop
}

Examples

cargo run --example simple_playback

License

MIT OR Apache-2.0

About

Rust bindings for miniaudio

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages