diff --git a/src/conversions/sample.rs b/src/conversions/sample.rs index 7ee97624..7f593f7a 100644 --- a/src/conversions/sample.rs +++ b/src/conversions/sample.rs @@ -67,7 +67,7 @@ where /// - For `u16`, silence corresponds to the value `u16::max_value() / 2`. The minimum and maximum /// amplitudes are represented by `0` and `u16::max_value()` respectively. /// - For `f32`, silence corresponds to the value `0.0`. The minimum and maximum amplitudes are -/// represented by `-1.0` and `1.0` respectively. +/// represented by `-1.0` and `1.0` respectively. /// /// You can implement this trait on your own type as well if you wish so. /// diff --git a/src/sink.rs b/src/sink.rs index 2de077d1..ac197708 100644 --- a/src/sink.rs +++ b/src/sink.rs @@ -102,6 +102,19 @@ impl Sink { /// Appends a sound to the queue of sounds to play. #[inline] pub fn append(&self, source: S) + where + S: Source + Send + 'static, + f32: FromSample, + S::Item: Sample + Send, + { + self.append_with_signal(source); + } + + /// Appends a sound to the queue of sounds to play + /// + /// When using the feature flag `crossbeam-channel` in rodio the `crossbeam_channel::Receiver` will be returned when the sound has finished playing. + #[inline] + pub fn append_with_signal(&self, source: S) -> Option> where S: Source + Send + 'static, f32: FromSample, @@ -159,7 +172,19 @@ impl Sink { .convert_samples(); self.sound_count.fetch_add(1, Ordering::Relaxed); let source = Done::new(source, self.sound_count.clone()); - *self.sleep_until_end.lock().unwrap() = Some(self.queue_tx.append_with_signal(source)); + let rx = self.queue_tx.append_with_signal(source); + + #[cfg(not(feature = "crossbeam-channel"))] + { + *self.sleep_until_end.lock().unwrap() = Some(rx); + None + } + + #[cfg(feature = "crossbeam-channel")] + { + *self.sleep_until_end.lock().unwrap() = Some(rx.clone()); + Some(rx) + } } /// Gets the volume of the sound.