-
Notifications
You must be signed in to change notification settings - Fork 235
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'rust-audio/master' into test-fixes
- Loading branch information
Showing
23 changed files
with
595 additions
and
367 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use cpal::traits::HostTrait; | ||
use cpal::{BufferSize, SampleFormat, SampleRate}; | ||
use rodio::source::SineWave; | ||
use rodio::Source; | ||
use std::error::Error; | ||
use std::thread; | ||
use std::time::Duration; | ||
|
||
fn main() -> Result<(), Box<dyn Error>> { | ||
// You can use any other output device that can be queried from CPAL. | ||
let default_device = cpal::default_host() | ||
.default_output_device() | ||
.ok_or("No default audio output device is found.")?; | ||
let stream_handle = rodio::OutputStreamBuilder::from_device(default_device)? | ||
// No need to set all parameters explicitly here, | ||
// the defaults were set from the device's description. | ||
.with_buffer_size(BufferSize::Fixed(256)) | ||
.with_sample_rate(SampleRate(48_000)) | ||
.with_sample_format(SampleFormat::F32) | ||
// Note that the function below still tries alternative configs if the specified one fails. | ||
// If you need to only use the exact specified configuration, | ||
// then use OutputStreamBuilder::open_stream() instead. | ||
.open_stream_or_fallback()?; | ||
let mixer = stream_handle.mixer(); | ||
|
||
let wave = SineWave::new(740.0) | ||
.amplify(0.1) | ||
.take_duration(Duration::from_secs(1)); | ||
mixer.add(wave); | ||
|
||
println!("Beep..."); | ||
thread::sleep(Duration::from_millis(1500)); | ||
|
||
Ok(()) | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
use std::error::Error; | ||
use std::io::BufReader; | ||
|
||
fn main() { | ||
let (_stream, handle) = rodio::OutputStream::try_default().unwrap(); | ||
let sink = rodio::Sink::try_new(&handle).unwrap(); | ||
fn main() -> Result<(), Box<dyn Error>> { | ||
let stream_handle = rodio::OutputStreamBuilder::open_default_stream()?; | ||
let sink = rodio::Sink::connect_new(&stream_handle.mixer()); | ||
|
||
let file = std::fs::File::open("assets/music.flac").unwrap(); | ||
sink.append(rodio::Decoder::new(BufReader::new(file)).unwrap()); | ||
let file = std::fs::File::open("assets/music.flac")?; | ||
sink.append(rodio::Decoder::new(BufReader::new(file))?); | ||
|
||
sink.sleep_until_end(); | ||
|
||
Ok(()) | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
use std::error::Error; | ||
use std::io::BufReader; | ||
|
||
fn main() { | ||
let (_stream, handle) = rodio::OutputStream::try_default().unwrap(); | ||
let sink = rodio::Sink::try_new(&handle).unwrap(); | ||
fn main() -> Result<(), Box<dyn Error>> { | ||
let stream_handle = rodio::OutputStreamBuilder::open_default_stream()?; | ||
let sink = rodio::Sink::connect_new(&stream_handle.mixer()); | ||
|
||
let file = std::fs::File::open("assets/music.m4a").unwrap(); | ||
sink.append(rodio::Decoder::new(BufReader::new(file)).unwrap()); | ||
let file = std::fs::File::open("assets/music.m4a")?; | ||
sink.append(rodio::Decoder::new(BufReader::new(file))?); | ||
|
||
sink.sleep_until_end(); | ||
|
||
Ok(()) | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
use std::error::Error; | ||
use std::io::BufReader; | ||
|
||
fn main() { | ||
let (_stream, handle) = rodio::OutputStream::try_default().unwrap(); | ||
let sink = rodio::Sink::try_new(&handle).unwrap(); | ||
fn main() -> Result<(), Box<dyn Error>> { | ||
let stream_handle = rodio::OutputStreamBuilder::open_default_stream()?; | ||
let sink = rodio::Sink::connect_new(&stream_handle.mixer()); | ||
|
||
let file = std::fs::File::open("assets/music.mp3").unwrap(); | ||
sink.append(rodio::Decoder::new(BufReader::new(file)).unwrap()); | ||
let file = std::fs::File::open("assets/music.mp3")?; | ||
sink.append(rodio::Decoder::new(BufReader::new(file))?); | ||
|
||
sink.sleep_until_end(); | ||
|
||
Ok(()) | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
use std::error::Error; | ||
use std::io::BufReader; | ||
|
||
fn main() { | ||
let (_stream, handle) = rodio::OutputStream::try_default().unwrap(); | ||
let sink = rodio::Sink::try_new(&handle).unwrap(); | ||
fn main() -> Result<(), Box<dyn Error>> { | ||
let stream_handle = rodio::OutputStreamBuilder::open_default_stream()?; | ||
let sink = rodio::Sink::connect_new(&stream_handle.mixer()); | ||
|
||
let file = std::fs::File::open("assets/music.ogg").unwrap(); | ||
sink.append(rodio::Decoder::new(BufReader::new(file)).unwrap()); | ||
let file = std::fs::File::open("assets/music.ogg")?; | ||
sink.append(rodio::Decoder::new(BufReader::new(file))?); | ||
|
||
sink.sleep_until_end(); | ||
|
||
Ok(()) | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
use std::error::Error; | ||
use std::io::BufReader; | ||
|
||
fn main() { | ||
let (_stream, handle) = rodio::OutputStream::try_default().unwrap(); | ||
let sink = rodio::Sink::try_new(&handle).unwrap(); | ||
fn main() -> Result<(), Box<dyn Error>> { | ||
let stream_handle = rodio::OutputStreamBuilder::open_default_stream()?; | ||
let sink = rodio::Sink::connect_new(&stream_handle.mixer()); | ||
|
||
let file = std::fs::File::open("assets/music.wav").unwrap(); | ||
sink.append(rodio::Decoder::new(BufReader::new(file)).unwrap()); | ||
let file = std::fs::File::open("assets/music.wav")?; | ||
sink.append(rodio::Decoder::new(BufReader::new(file))?); | ||
|
||
sink.sleep_until_end(); | ||
|
||
Ok(()) | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
use rodio::Source; | ||
use std::error::Error; | ||
use std::io::BufReader; | ||
use std::time::Duration; | ||
|
||
fn main() { | ||
let (_stream, handle) = rodio::OutputStream::try_default().unwrap(); | ||
let sink = rodio::Sink::try_new(&handle).unwrap(); | ||
fn main() -> Result<(), Box<dyn Error>> { | ||
let stream_handle = rodio::OutputStreamBuilder::open_default_stream()?; | ||
let sink = rodio::Sink::connect_new(&stream_handle.mixer()); | ||
|
||
let file = std::fs::File::open("assets/music.ogg").unwrap(); | ||
let source = rodio::Decoder::new(BufReader::new(file)).unwrap(); | ||
let file = std::fs::File::open("assets/music.ogg")?; | ||
let source = rodio::Decoder::new(BufReader::new(file))?; | ||
let with_reverb = source.buffered().reverb(Duration::from_millis(40), 0.7); | ||
sink.append(with_reverb); | ||
|
||
sink.sleep_until_end(); | ||
|
||
Ok(()) | ||
} |
Oops, something went wrong.