Run rustfmt on the code (#162)

This commit is contained in:
tomaka 2017-10-11 13:24:49 +02:00 • committed by GitHub
parent cdcef96279
commit 2028d5907f
13 changed files with 622 additions and 399 deletions

View file

@ -20,12 +20,17 @@ impl Executor for MyExecutor {
fn main() {
let endpoint = cpal::default_endpoint().expect("Failed to get default endpoint");
let format = endpoint.supported_formats().unwrap().next().expect("Failed to get endpoint format");
let format = endpoint
.supported_formats()
.unwrap()
.next()
.expect("Failed to get endpoint format");
let event_loop = cpal::EventLoop::new();
let executor = Arc::new(MyExecutor);
let (mut voice, stream) = cpal::Voice::new(&endpoint, &format, &event_loop).expect("Failed to create a voice");
let (mut voice, stream) = cpal::Voice::new(&endpoint, &format, &event_loop)
.expect("Failed to create a voice");
// Produce a sinusoid of maximum amplitude.
let samples_rate = format.samples_rate.0 as f32;
@ -36,22 +41,37 @@ fn main() {
task::spawn(stream.for_each(move |buffer| -> Result<_, ()> {
match buffer {
cpal::UnknownTypeBuffer::U16(mut buffer) => {
for (sample, value) in buffer.chunks_mut(format.channels.len()).zip(&mut data_source) {
for (sample, value) in buffer
.chunks_mut(format.channels.len())
.zip(&mut data_source)
{
let value = ((value * 0.5 + 0.5) * std::u16::MAX as f32) as u16;
for out in sample.iter_mut() { *out = value; }
for out in sample.iter_mut() {
*out = value;
}
}
},
cpal::UnknownTypeBuffer::I16(mut buffer) => {
for (sample, value) in buffer.chunks_mut(format.channels.len()).zip(&mut data_source) {
for (sample, value) in buffer
.chunks_mut(format.channels.len())
.zip(&mut data_source)
{
let value = (value * std::i16::MAX as f32) as i16;
for out in sample.iter_mut() { *out = value; }
for out in sample.iter_mut() {
*out = value;
}
}
},
cpal::UnknownTypeBuffer::F32(mut buffer) => {
for (sample, value) in buffer.chunks_mut(format.channels.len()).zip(&mut data_source) {
for out in sample.iter_mut() { *out = value; }
for (sample, value) in buffer
.chunks_mut(format.channels.len())
.zip(&mut data_source)
{
for out in sample.iter_mut() {
*out = value;
}
}
},
};
@ -59,14 +79,12 @@ fn main() {
Ok(())
})).execute(executor);
thread::spawn(move || {
loop {
thread::sleep(Duration::from_millis(500));
voice.pause();
thread::sleep(Duration::from_millis(500));
voice.play();
}
});
thread::spawn(move || loop {
thread::sleep(Duration::from_millis(500));
voice.pause();
thread::sleep(Duration::from_millis(500));
voice.play();
});
event_loop.run();
}

View file

@ -2,14 +2,19 @@ extern crate cpal;
fn main() {
let endpoints = cpal::endpoints();
println!("Endpoints: ");
for (endpoint_index, endpoint) in endpoints.enumerate() {
println!("{}. Endpoint \"{}\" Audio formats: ", endpoint_index + 1, endpoint.name());
println!("{}. Endpoint \"{}\" Audio formats: ",
endpoint_index + 1,
endpoint.name());
let formats = match endpoint.supported_formats() {
Ok(f) => f,
Err(e) => { println!("Error: {:?}", e); continue; }
Err(e) => {
println!("Error: {:?}", e);
continue;
},
};
for (format_index, format) in formats.enumerate() {