Skip to content

Commit b62499e

Browse files
committed
Bump rodio and fix warnings.
1 parent 80a0aad commit b62499e

8 files changed

Lines changed: 211 additions & 44 deletions

File tree

Cargo.lock

Lines changed: 177 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

kord/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,12 @@ parse_duration0 = { version = "3", optional = true }
9090

9191
# cli
9292
clap = { version = "4", features = ["derive"], optional = true }
93-
futures = { version = "0.3.31", optional = true }
93+
futures = { version = "0.3", optional = true }
9494

9595
# audio
96-
rodio = { version = "0.19.0", default-features = false, features = [
96+
rodio = { version = "0.21", default-features = false, features = [
9797
"symphonia",
98+
"playback",
9899
], optional = true }
99100

100101
# analyze_base

kord/src/analyze/file.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::{
88
time::Duration,
99
};
1010

11-
use rodio::{buffer::SamplesBuffer, Decoder, OutputStream, Source};
11+
use rodio::{buffer::SamplesBuffer, Decoder, OutputStreamBuilder, Sink, Source};
1212

1313
use crate::core::{base::Res, note::Note};
1414

@@ -26,7 +26,7 @@ pub fn get_audio_data_from_file(file: impl AsRef<Path>, start: Option<Duration>,
2626
let path = file.as_ref();
2727
let start = start.unwrap_or_default();
2828

29-
let decoder = Decoder::new(File::open(path)?)?.skip_duration(start).convert_samples();
29+
let decoder = Decoder::new(File::open(path)?)?.skip_duration(start);
3030

3131
let num_channels = decoder.channels();
3232
let sample_rate = decoder.sample_rate();
@@ -53,15 +53,18 @@ pub fn preview_audio_file_clip(file: impl AsRef<Path>, start: Option<Duration>,
5353
#[coverage(off)]
5454
pub fn preview_audio_clip(stream: impl Read + Seek + Send + Sync + 'static, start: Option<Duration>, end: Option<Duration>) -> Res<()> {
5555
let start = start.unwrap_or_default();
56-
let decoder = Decoder::new(stream)?.skip_duration(start).convert_samples();
56+
let decoder = Decoder::new(stream)?.skip_duration(start);
5757

58-
let (_stream, stream_handle) = OutputStream::try_default()?;
58+
let stream = OutputStreamBuilder::open_default_stream()?;
59+
let sink = Sink::connect_new(stream.mixer());
5960

6061
if let Some(end) = end {
61-
stream_handle.play_raw(decoder.take_duration(end - start))?;
62+
stream.mixer().add(decoder.take_duration(end - start));
63+
sink.play();
6264
sleep(end - start);
6365
} else if let Some(duration) = decoder.total_duration() {
64-
stream_handle.play_raw(decoder)?;
66+
stream.mixer().add(decoder);
67+
sink.play();
6568
sleep(duration);
6669
} else {
6770
let channels = decoder.channels();
@@ -70,7 +73,8 @@ pub fn preview_audio_clip(stream: impl Read + Seek + Send + Sync + 'static, star
7073

7174
let time = Duration::from_secs((samples.len() as f32 / sample_rate).ceil() as u64);
7275

73-
stream_handle.play_raw(SamplesBuffer::new(channels, sample_rate as u32, samples))?;
76+
stream.mixer().add(SamplesBuffer::new(channels, sample_rate as u32, samples));
77+
sink.play();
7478

7579
sleep(time);
7680
}

kord/src/core/base.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use std::time::Duration;
66

77
#[cfg(feature = "audio")]
8-
use rodio::{OutputStream, OutputStreamHandle, Sink};
8+
use rodio::{OutputStream, Sink};
99

1010
/// Global result type.
1111
pub type Res<T> = anyhow::Result<T>;
@@ -53,19 +53,14 @@ pub trait Parsable {
5353
#[cfg(feature = "audio")]
5454
pub struct PlaybackHandle {
5555
_stream: OutputStream,
56-
_stream_handle: OutputStreamHandle,
5756
_sinks: Vec<Sink>,
5857
}
5958

6059
#[cfg(feature = "audio")]
6160
impl PlaybackHandle {
6261
/// Creates a new [`PlayableResult`].
63-
pub fn new(stream: OutputStream, stream_handle: OutputStreamHandle, sinks: Vec<Sink>) -> Self {
64-
Self {
65-
_stream: stream,
66-
_stream_handle: stream_handle,
67-
_sinks: sinks,
68-
}
62+
pub fn new(stream_handle: OutputStream, sinks: Vec<Sink>) -> Self {
63+
Self { _stream: stream_handle, _sinks: sinks }
6964
}
7065
}
7166

0 commit comments

Comments
 (0)