Skip to content

Commit dd70cd4

Browse files
authored
Merge pull request #824 from RustAudio/rename-sink-and-stream
Rename sink and stream
2 parents ca2ca66 + ed8179d commit dd70cd4

42 files changed

Lines changed: 353 additions & 342 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4444
- Fixed `Zero::current_span_len` returning remaining samples instead of span length.
4545

4646
### Changed
47+
- Breaking: _Sink_ terms are replaced with _Player_ and _Stream_ terms replaced
48+
with _Sink_. This is a simple rename, functionality is identical.
49+
- `OutputStream` is now `MixerDeviceSink` (in anticipation of future
50+
`QueueDeviceSink`)
51+
- `OutputStreamBuilder` is now `DeviceSinkBuilder`
52+
- `open_stream_or_fallback` is now `open_sink_or_fallback`
53+
- `open_default_stream` is now `open_default_sink`
54+
- `open_stream` is now `open_mixer` (in anticipation of future `open_queue`)
55+
- `Sink` is now `Player`
56+
- `SpatialSink` is now `SpatialPlayer`
57+
- `StreamError` is now `OsSinkError`
4758
- `output_to_wav` renamed to `wav_to_file` and now takes ownership of the `Source`.
4859
- `Blue` noise generator uses uniform instead of Gaussian noise for better performance.
4960
- `Gaussian` noise generator has standard deviation of 0.6 for perceptual equivalence.
@@ -166,7 +177,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
166177
implementation.
167178

168179
### Fixed
169-
- `Sink.try_seek` now updates `controls.position` before returning. Calls to `Sink.get_pos`
180+
- `player.try_seek` now updates `controls.position` before returning. Calls to `player.get_pos`
170181
done immediately after a seek will now return the correct value.
171182

172183
### Changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ src/:
2020
- Follow [Rust API Guidelines](https://rust-lang.github.io/api-guidelines/)
2121
- Use `rustfmt` for formatting
2222
- Implement `Source` trait for new audio sources
23-
- Use `Sink` for playback management
23+
- Use `Player` for playback management
2424

2525
## Common Tasks
2626

UPGRADE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ No changes are required.
5656
The following Rodio *0.20* code:
5757
```rust
5858
let (_stream, handle) = rodio::OutputStream::try_default()?;
59-
let sink = rodio::Sink::try_new(&handle)?;
59+
let player = rodio::Player::try_new(&handle)?;
6060
```
6161
Should be written like this in Rodio *0.21*:
6262
```rust
6363
let stream_handle = rodio::OutputStreamBuilder::open_default_stream()?;
64-
let sink = rodio::Sink::connect_new(stream_handle.mixer());
64+
let player = rodio::Player::connect_new(stream_handle.mixer());
6565
```
6666

6767
The `SpatialSink` changes mirror those in `Sink` described above.

examples/automatic_gain_control.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use std::thread;
88
use std::time::Duration;
99

1010
fn main() -> Result<(), Box<dyn Error>> {
11-
let stream_handle = rodio::OutputStreamBuilder::open_default_stream()?;
12-
let sink = rodio::Sink::connect_new(stream_handle.mixer());
11+
let stream_handle = rodio::DeviceSinkBuilder::open_default_sink()?;
12+
let player = rodio::Player::connect_new(stream_handle.mixer());
1313

1414
// Decode the sound file into a source
1515
let file = File::open("assets/music.flac")?;
@@ -29,7 +29,7 @@ fn main() -> Result<(), Box<dyn Error>> {
2929

3030
// Add the source now equipped with automatic gain control and controlled via
3131
// periodic_access to the sink for the playback.
32-
sink.append(controlled);
32+
player.append(controlled);
3333

3434
// After 5 seconds of playback disable automatic gain control using the
3535
// shared AtomicBool `agc_enabled`. You could do this from another part
@@ -42,6 +42,6 @@ fn main() -> Result<(), Box<dyn Error>> {
4242
agc_enabled.store(false, Ordering::Relaxed);
4343

4444
// Keep the program running until the playback is complete.
45-
sink.sleep_until_end();
45+
player.sleep_until_end();
4646
Ok(())
4747
}

examples/basic.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ use std::thread;
66
use std::time::Duration;
77

88
fn main() -> Result<(), Box<dyn Error>> {
9-
let stream_handle = rodio::OutputStreamBuilder::open_default_stream()?;
9+
let stream_handle = rodio::DeviceSinkBuilder::open_default_sink()?;
1010
let mixer = stream_handle.mixer();
1111

1212
let beep1 = {
1313
// Play a WAV file.
1414
let file = std::fs::File::open("assets/beep.wav")?;
15-
let sink = rodio::play(mixer, BufReader::new(file))?;
16-
sink.set_volume(0.2);
17-
sink
15+
let player = rodio::play(mixer, BufReader::new(file))?;
16+
player.set_volume(0.2);
17+
player
1818
};
1919
println!("Started beep1");
2020
thread::sleep(Duration::from_millis(1500));
@@ -32,9 +32,9 @@ fn main() -> Result<(), Box<dyn Error>> {
3232
let beep3 = {
3333
// Play an OGG file.
3434
let file = std::fs::File::open("assets/beep3.ogg")?;
35-
let sink = rodio::play(mixer, BufReader::new(file))?;
36-
sink.set_volume(0.2);
37-
sink
35+
let player = rodio::play(mixer, BufReader::new(file))?;
36+
player.set_volume(0.2);
37+
player
3838
};
3939
println!("Started beep3");
4040
thread::sleep(Duration::from_millis(1500));

examples/callback_on_end.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ use std::sync::atomic::{AtomicU32, Ordering};
33
use std::sync::Arc;
44

55
fn main() -> Result<(), Box<dyn Error>> {
6-
let stream_handle = rodio::OutputStreamBuilder::open_default_stream()?;
7-
let sink = rodio::Sink::connect_new(stream_handle.mixer());
6+
let stream_handle = rodio::DeviceSinkBuilder::open_default_sink()?;
7+
let player = rodio::Player::connect_new(stream_handle.mixer());
88

99
let file = std::fs::File::open("assets/music.wav")?;
10-
sink.append(rodio::Decoder::try_from(file)?);
10+
player.append(rodio::Decoder::try_from(file)?);
1111

1212
// lets increment a number after `music.wav` has played. We are going to use atomics
1313
// however you could also use a `Mutex` or send a message through a `std::sync::mpsc`.
@@ -17,7 +17,7 @@ fn main() -> Result<(), Box<dyn Error>> {
1717
// playlist_pos into the closure. That way we can still access playlist_pos
1818
// after appending the EmptyCallback.
1919
let playlist_pos_clone = playlist_pos.clone();
20-
sink.append(rodio::source::EmptyCallback::new(Box::new(move || {
20+
player.append(rodio::source::EmptyCallback::new(Box::new(move || {
2121
println!("empty callback is now running");
2222
playlist_pos_clone.fetch_add(1, Ordering::Relaxed);
2323
})));
@@ -27,7 +27,7 @@ fn main() -> Result<(), Box<dyn Error>> {
2727
"playlist position is: {}",
2828
playlist_pos.load(Ordering::Relaxed)
2929
);
30-
sink.sleep_until_end();
30+
player.sleep_until_end();
3131
assert_eq!(playlist_pos.load(Ordering::Relaxed), 1);
3232
println!(
3333
"playlist position is: {}",

examples/custom_config.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ fn main() -> Result<(), Box<dyn Error>> {
1212
let default_device = cpal::default_host()
1313
.default_output_device()
1414
.ok_or("No default audio output device is found.")?;
15-
let stream_handle = rodio::OutputStreamBuilder::from_device(default_device)?
15+
let stream_handle = rodio::DeviceSinkBuilder::from_device(default_device)?
1616
// No need to set all parameters explicitly here,
1717
// the defaults were set from the device's description.
1818
.with_buffer_size(BufferSize::Fixed(256))
1919
.with_sample_rate(NonZero::new(48_000).unwrap())
2020
.with_sample_format(SampleFormat::F32)
2121
// Note that the function below still tries alternative configs if the specified one fails.
2222
// If you need to only use the exact specified configuration,
23-
// then use OutputStreamBuilder::open_stream() instead.
24-
.open_stream_or_fallback()?;
23+
// then use DeviceSinkBuilder::open_sink() instead.
24+
.open_sink_or_fallback()?;
2525
let mixer = stream_handle.mixer();
2626

2727
let wave = SineWave::new(740.0)

examples/distortion.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::time::Duration;
55

66
fn main() -> Result<(), Box<dyn Error>> {
77
// Open the default output stream and get the mixer
8-
let stream_handle = rodio::OutputStreamBuilder::open_default_stream()?;
8+
let stream_handle = rodio::DeviceSinkBuilder::open_default_sink()?;
99
let mixer = stream_handle.mixer();
1010

1111
// Create a sine wave source and apply distortion

examples/distortion_mp3.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ use std::error::Error;
33
use rodio::Source;
44

55
fn main() -> Result<(), Box<dyn Error>> {
6-
let stream_handle = rodio::OutputStreamBuilder::open_default_stream()?;
7-
let sink = rodio::Sink::connect_new(stream_handle.mixer());
6+
let stream_handle = rodio::DeviceSinkBuilder::open_default_sink()?;
7+
let player = rodio::Player::connect_new(stream_handle.mixer());
88

99
let file = std::fs::File::open("assets/music.mp3")?;
1010
// Apply distortion effect before appending to the sink
1111
let source = rodio::Decoder::try_from(file)?.distortion(4.0, 0.3);
12-
sink.append(source);
12+
player.append(source);
1313

14-
sink.sleep_until_end();
14+
player.sleep_until_end();
1515

1616
Ok(())
1717
}

examples/distortion_wav.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ use std::error::Error;
33
use rodio::Source;
44

55
fn main() -> Result<(), Box<dyn Error>> {
6-
let stream_handle = rodio::OutputStreamBuilder::open_default_stream()?;
7-
let sink = rodio::Sink::connect_new(stream_handle.mixer());
6+
let stream_handle = rodio::DeviceSinkBuilder::open_default_sink()?;
7+
let player = rodio::Player::connect_new(stream_handle.mixer());
88

99
let file = std::fs::File::open("assets/music.wav")?;
1010
// Apply distortion effect before appending to the sink
1111
let source = rodio::Decoder::try_from(file)?.distortion(4.0, 0.3);
12-
sink.append(source);
12+
player.append(source);
1313

14-
sink.sleep_until_end();
14+
player.sleep_until_end();
1515

1616
Ok(())
1717
}

0 commit comments

Comments
 (0)