ExPixel / miniaudio-rs

Rust bindings for miniaudio C library.
https://crates.io/crates/miniaudio
MIT License
49 stars 20 forks source link

Added basic support for decoders #16

Closed Nazariglez closed 4 years ago

Nazariglez commented 4 years ago

I want to help you to add support for files but it's my first binding to C (and I don't know C). I think that I have a starting point here to work and improve from, if you like it. However, I'm going to need some help or guidance to do this right.

(Related https://github.com/ExPixel/miniaudio-rs/issues/10)

This code works with this example:

pub fn file() {
    let mut decoder = Decoder::from_file("./fireEffect.mp3", None).unwrap();
    let mut config = DeviceConfig::new(DeviceType::Playback);
    config.playback_mut().set_format(decoder.output_format());
    config
        .playback_mut()
        .set_channels(decoder.output_channels());
    config.set_sample_rate(decoder.output_sample_rate());
    config.set_data_callback(move |_device, output, _frames| {
        decoder.read_pcm_frames(output);
    });

    config.set_stop_callback(|_device| {
        println!("Device Stopped.");
    });

    let device = Device::new(None, &config).expect("failed to open playback device");
    device.start().expect("failed to start device");

    println!("Device Backend: {:?}", device.context().backend());
    wait_for_enter();
    println!("Shutting Down...");
}

What do you think?

ExPixel commented 4 years ago

Looks good, thank you ☺️. Only thing left to do is fix the headers l because the name of the flags has changed a bit but I'll do that in a bit after meeting this.