Conversation
a0b8f73 to
429345a
Compare
roderickvd
left a comment
There was a problem hiding this comment.
I see this is built on top of #903 so I didn't duplicate any of my review points there to here.
| } | ||
|
|
||
| /// A [`ConstSource`] adapted from a [`FixedSource`]. | ||
| pub struct IntoConstSource<const SR: u32, const CH: u16, S: FixedSource>(S); |
There was a problem hiding this comment.
This one and IntoDynamicSource should forward try_seek.
| } | ||
| } | ||
|
|
||
| impl<const SR: u32, const CH: u16, S> FixedSource for IntoFixedSource<SR, CH, S> |
| } | ||
|
|
||
| #[derive(Debug, Clone, Copy, thiserror::Error, PartialEq, Eq)] | ||
| pub struct ParamsMismatch { |
There was a problem hiding this comment.
Consider exporting this one so users can downcast to it.
| }; | ||
| } | ||
|
|
||
| macro_rules! iter_impl { |
There was a problem hiding this comment.
This seems misplaced or having the wrong name.
There was a problem hiding this comment.
how so? it is the documentation for FixedSource::collect_into_buffer and ConstSource::collect_into_buffer.
I'll expand the text a little to make that more clear.
There was a problem hiding this comment.
I thought it was out of place because the title was about building a SamplesBuffer, not about collecting into a buffer, and went on to describe a panic that wouldn't be occurring in new (the "builder") anymore, but in total_duration.
There was a problem hiding this comment.
As per #913 we should add the ability to create one with an arbitrary channel count. Over there we targeted it for phase 4, so just mentioning it here.
There was a problem hiding this comment.
For silence the idea is to always put it through a channel convertor. My hope being that the optimizer can figure it out. If that is false and perf. becomes an issue we could specialize it.
There was a problem hiding this comment.
Automatic optimization would be great, but how would that work?
There was a problem hiding this comment.
the compiler knows that Silence::next returns a constant value (namely: Some(0.0)).
Lets take this fragment of the channel convertor:
let result = match self.next_output_sample_pos {
0 => {
let value = self.input.next();
self.sample_repeat = value;
value
}
x if x < self.from.get() => self.input.next(),
1 => self.sample_repeat,
_ => Some(Sample::EQUILIBRIUM),
};
Every self.input.next() gets replaced with Some(0):
let result = match self.next_output_sample_pos {
0 => {
self.sample_repeat = 0.0;
0.0
}
x if x < self.from.get() => 0.0,
1 => self.sample_repeat,
_ => Some(0.0),
};
Now its simple to see that self.sample_repeat is also constant. So everywhere we see it replace with a 0.0.
let result = match self.next_output_sample_pos {
0 => {
0.0
}
x if x < self.from.get() => 0.0,
1 => 0.0,
_ => Some(0.0),
};
And this is now just a match statement returning 0.0 always so result can be set to 0.0.
There is some other stuff like self.from.get() and self.next_output_sample_pos() but that has also become dead code so the optimizer throws that out as well. And now we've gotten to the point where ChannelCountConvertor::next() can be replaced with just 0.0. This should domino up any audio pipeline.
Now if you put silence in a box and cast it to a Box... then this stops working.
Whether this all happens? It probably does, these are basic optimizations. You can never know for sure, sometimes a suggestion here and there is needed (a little #[inline] usually).
There was a problem hiding this comment.
Ah, thanks for that write-up, that makes sense. As long as it doesn't get fed into Rubato or something, because then all bets would be off I imagine.
Add fixed source to silence generator
93c0e6c to
f4f9169
Compare
review after #903 (this includes it's changes)
Tracking issue: #901
common::sourcemodule and macrosPlaceholderto have docs and examples point to not yet landed code