-
Notifications
You must be signed in to change notification settings - Fork 293
Use builder to init output stream #641
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
184b383
Support buffer size selection
PetrGlad dd48390
Make configurable buffer API public
PetrGlad 5d42375
Correct API signatures
PetrGlad 4c62dd3
Bump version
PetrGlad 1a8d63a
Reduce API changes
PetrGlad c17712f
Reformat code
PetrGlad 08207b1
Merge branch 'master' into configurable-buffer-size
PetrGlad dd1edbb
WIP, simplify output stream initialization
PetrGlad e82b208
WIP. Implementing OpenStreamBuilder
PetrGlad fcfbabc
Revert to using mixer as default output
PetrGlad 7154439
Remove source plug prototype
PetrGlad e2c74a5
Streamline default stream logic
PetrGlad dbd1d1f
Remove Criterion dependency
PetrGlad 5cfe61f
Update a basic example
PetrGlad cabdda7
Update tests and examples
PetrGlad 352c399
Add example comments
PetrGlad 2ee0a3c
Merge remote-tracking branch 'rust-audio/master' into init-revamp
PetrGlad c5850ab
Sync Cargo.toml with master branch
PetrGlad 83c0025
Update doc examples
PetrGlad 179d41a
Reformat code
PetrGlad af92566
Cleanup
PetrGlad ebc673e
Cleanup, remove unnecessay imports
PetrGlad b720273
Revert extra changes for merge request
PetrGlad 689670d
UPdate documentation
PetrGlad 6a6e94c
Rename dynamic_mixer.rs
PetrGlad 1af733e
Cleanup: fix lint warnings
PetrGlad 6f6385b
Add documentation for output stream public exports
PetrGlad 77c50cd
Clarify API documentation
PetrGlad 4101ae9
Remove unwrap and expect from example code
PetrGlad 0ba6021
Hide OutputStreamConfig struct
PetrGlad 95060b1
Stream initialization fix
PetrGlad 678df03
Custom output stream config example
PetrGlad d1d5726
Rename try_open_stream and try_default_stream
PetrGlad c23ec2c
Update documentation
PetrGlad 5972eeb
Update CHANGELOG.md
PetrGlad 435222a
Merge remote-tracking branch 'rust-audio/master' into init-revamp
PetrGlad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| 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 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
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
| 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 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
| 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 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
| 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 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
| 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 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
| 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 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
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
| 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.