Created
August 31, 2017 21:46
-
-
Save yilinwei/7ee42dc1616aaef24661f1630b3c2f6f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[derive(Debug)] | |
struct Tone { | |
position: isize | |
} | |
impl cubeb::StreamCallback for Tone { | |
type Frame = cubeb::MonoFrame<i16>; | |
fn data_callback(&mut self, input: &[cubeb::MonoFrame<i16>], _: &mut [cubeb::MonoFrame<i16>]) -> isize { | |
self.position += 1; | |
println!("{:?}", input); | |
if(self.position > 30) { | |
0 as isize | |
} else { | |
input.len() as isize | |
} | |
} | |
fn state_callback(&mut self, state: cubeb::State) { | |
println!("stream {:?}", state); | |
} | |
} | |
fn main() { | |
let params = cubeb::StreamParamsBuilder::new() | |
.format(STREAM_FORMAT) | |
.rate(SAMPLE_FREQUENCY) | |
.channels(1) | |
.layout(cubeb::ChannelLayout::Mono) | |
.take(); | |
let ctx = Context::init("foo", None).unwrap(); | |
let id = ctx.backend_id(); | |
let stream_init_opts = cubeb::StreamInitOptionsBuilder::new() | |
.stream_name("Cubeb tone (mono)") | |
.input_stream_param(¶ms) | |
.latency(4096) | |
.take(); | |
let t = Tone { position: 0 }; | |
let stream = ctx.stream_init( | |
&stream_init_opts, | |
t | |
).expect("Failed to create cubeb stream"); | |
stream.start().unwrap(); | |
println!("STARTED"); | |
thread::sleep(Duration::from_millis(3000)); | |
println!("ATTEMPT STOP"); | |
let r = stream.stop().unwrap(); | |
println!("STOPPED"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment