-
Notifications
You must be signed in to change notification settings - Fork 286
SourcesQueueOutput can peek metadata from next source #812
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
Changes from all commits
1022b63
1b510f0
06752a7
5257f7b
4d73ca9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -73,7 +73,7 @@ impl SamplesBuffer { | |
| impl Source for SamplesBuffer { | ||
| #[inline] | ||
| fn current_span_len(&self) -> Option<usize> { | ||
| None | ||
| Some(self.data.len() - self.pos) | ||
| } | ||
|
|
||
| #[inline] | ||
|
|
@@ -126,7 +126,7 @@ impl Iterator for SamplesBuffer { | |
|
|
||
| #[inline] | ||
| fn size_hint(&self) -> (usize, Option<usize>) { | ||
| (self.data.len(), Some(self.data.len())) | ||
| (self.data.len() - self.pos, Some(self.data.len() - self.pos)) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -113,6 +113,8 @@ pub struct SourcesQueueOutput { | |
| } | ||
|
|
||
| const THRESHOLD: usize = 512; | ||
| const SILENCE_SAMPLE_RATE: SampleRate = nz!(44100); | ||
| const SILENCE_CHANNELS: ChannelCount = nz!(1); | ||
|
|
||
| impl Source for SourcesQueueOutput { | ||
| #[inline] | ||
|
|
@@ -154,12 +156,28 @@ impl Source for SourcesQueueOutput { | |
|
|
||
| #[inline] | ||
| fn channels(&self) -> ChannelCount { | ||
| self.current.channels() | ||
| // current_span_len() should never return 0 unless the source is empty, so this is a cheeky hint | ||
| if self.current.current_span_len() != Some(0) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like the cheekiness 😄 How much sense do you think it would make to add an |
||
| self.current.channels() | ||
| } else if let Some((next, _)) = self.input.next_sounds.lock().unwrap().first() { | ||
| next.channels() | ||
| } else { | ||
| // If keep_alive_if_empty is true, then it'll be mono 44.1khz silence -- otherwise it doesn't matter what it is | ||
| SILENCE_CHANNELS | ||
| } | ||
| } | ||
|
|
||
| #[inline] | ||
| fn sample_rate(&self) -> SampleRate { | ||
| self.current.sample_rate() | ||
| // current_span_len() should never return 0 unless the source is empty, so this is a cheeky hint | ||
| if self.current.current_span_len() != Some(0) { | ||
| self.current.sample_rate() | ||
| } else if let Some((next, _)) = self.input.next_sounds.lock().unwrap().first() { | ||
| next.sample_rate() | ||
| } else { | ||
| // If keep_alive_if_empty is true, then it'll be mono 44.1khz silence -- otherwise it doesn't matter what it is | ||
| SILENCE_SAMPLE_RATE | ||
| } | ||
| } | ||
|
|
||
| #[inline] | ||
|
|
@@ -221,7 +239,11 @@ impl SourcesQueueOutput { | |
| let mut next = self.input.next_sounds.lock().unwrap(); | ||
|
|
||
| if next.is_empty() { | ||
| let silence = Box::new(Zero::new_samples(nz!(1), nz!(44100), THRESHOLD)) as Box<_>; | ||
| let silence = Box::new(Zero::new_samples( | ||
| SILENCE_CHANNELS, | ||
| SILENCE_SAMPLE_RATE, | ||
| THRESHOLD, | ||
| )) as Box<_>; | ||
| if self.input.keep_alive_if_empty.load(Ordering::Acquire) { | ||
| // Play a short silence in order to avoid spinlocking. | ||
| (silence, None) | ||
|
|
@@ -247,7 +269,6 @@ mod tests { | |
| use crate::source::Source; | ||
|
|
||
| #[test] | ||
| #[ignore] // FIXME: samples rate and channel not updated immediately after transition | ||
| fn basic() { | ||
| let (tx, mut rx) = queue::queue(false); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The contract is that
current_span_lenreturns the length of the span / buffer regardless of its current position. That's forsize_hintto do.