Crates.io | mpv-audio |
lib.rs | mpv-audio |
version | 0.1.1 |
source | src |
created_at | 2018-05-20 21:01:55.822519 |
updated_at | 2018-05-20 21:11:49.867996 |
description | Provides a simple cross-platform streaming audio API based on mpv |
homepage | |
repository | https://bitbucket.org/SoniEx2/mpv-audio |
max_upload_size | |
id | 66373 |
size | 16,929 |
mpv-audio is a Rust crate that provides a simple, cross-platform streaming audio output API, powered by mpv.
It Just Works™!
extern crate mpv_audio;
use mpv_audio::*;
use std::io::prelude::*;
fn main() {
let mut stream = AudioOut::open(AudioFormat::S8, 8000, 1).expect("Couldn't open audio output");
let mut array = [0u8; 128];
let mut f: f32 = 0.0;
loop {
{
let mut writer: &mut [u8] = &mut array;
while !writer.is_empty() {
writer.write(&[(f.sin()*127.5-0.5) as i8 as u8]).ok();
f += 0.125; // 0b0.001
if f >= std::f32::consts::PI*4. {
f -= std::f32::consts::PI*4.;
}
}
}
stream.write_all(&array).expect("couldn't write");
}
}