-
Notifications
You must be signed in to change notification settings - Fork 238
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
Fix(484) - ChannelVolume misbehaving #493
base: master
Are you sure you want to change the base?
Conversation
0f059bd
to
50b6f40
Compare
50b6f40
to
1167092
Compare
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.
First thanks a lot for going after this issue. Does the example your PR adds reproduce the issue? I would love to have a test that reproduces it.
If I understand correctly your approach modifies the channel converter
and sample rate converter
to recognize the Empty
source. They do so by checking for its now nonsensical channel count
and sample rate
of zero.
An alternative would be removing the use of empty in queue
(used by Sink::try_new
) here:
Line 110 in a904566
current: Box<dyn Source<Item = S> + Send>, |
We could use a Option<()> there and make the None branch play 'empty' sounds.
On the other hand, Empty
probably has other valid uses....
Quite a difficult one this. I do not have any more time right now, ill come back to this.
src/source/empty.rs
Outdated
@@ -36,17 +39,17 @@ where | |||
{ | |||
#[inline] | |||
fn current_frame_len(&self) -> Option<usize> { | |||
None | |||
Some(0) |
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.
I am not sure about this change. None
means the frame length will not change going forward. I do not know what Some(0)
means. Filters/wrappers around the Empty
source will treat every new sample as a new frame and run code paths to handle that.
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.
I don't recall why I had that in there. I don't think it needs to be there. So I'll happily revert that change
Yes, it does, running the example on |
Nice, then I can try it out and play around a little with the PR |
I do not yet understand why I can not merge this until I understand everything around it. Unfortunately I do not have a lot of time allocated for this, so it could a bit. I'll keep you updated. |
That’s totally understandable. I am happy to help out getting it to a state where it fixes things and there’s an understanding of why it all works out |
b10961c
to
a7f67b3
Compare
I have some time now :) If you still have time to help out, could you rebase or merge master to resolve the conflict? As I understand the PR |
Oh and the changelog needs an update marking this is fixed now |
fbe90ab
to
f296cc9
Compare
Rebased to sort merge conflict |
Just rested the example after rebase; it has regressed to not sorting out the channel volumes correctly. I'll try to investigate and come up with some more in-depth unit tests as well to see if I can better isolate the issue. A preliminary test in |
This comment was marked as resolved.
This comment was marked as resolved.
I thought it repro'd but it didn't. I've pushed a working test for now. |
thanks! and thank you very much for hunting for the bug! |
0ee0413
to
073fdb1
Compare
Any update on this bug? I fear we're about to run into this issue as we try to use a 10 channel interface with our app that uses ChannelVolume. |
Not yet, I’m afraid. I’ve been busy with life events. I’ll have time to look into it more next week, hopefully |
src/sink.rs
Outdated
let v = vec![100.0f32]; | ||
let input = SamplesBuffer::new(1, 48000, v.clone()); | ||
|
||
// High rate to avoid immediate control. |
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.
Can you explain this comment?
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.
Honestly, no idea. I'll be spending the day today going through this throughly to actually try to understand what I did.
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.
I'm going to remove the test here. I don't think it's actually helpful to have there
@dvdsk BTW, what is the use case for I would split Looks like |
its only used in the spatial source (and indirectly in spatial sink):
|
If a limiter is different then a low pass/high pass/band pass filter then we do not have one atm. Might be a good add. |
We're currently using this to be able to output different sources onto different channels on a device, we have a scenario where we want to be able to do the following using a 10 channel USB audio interface:
with channels 9 and 10 silent. |
move channel from fix to constructor, add test Empty Source should not have a sample rate. Sample Rate Conversion to handle Empty source properly add more doc around Empty
b382da2
to
75f9f92
Compare
Having some time to look at this. I've rebased the branch and re-run my |
I've been testing this by using Loopback on macOS to setup a virtual interface with 6 output channels and setting it as the default output device and noting that the volume meters are displaying correctly the output levels needed. |
very nice! Thanks for putting in all this effort (reporting, finding fixing & testing!). I left a few comments on the source. It mainly comes down to this: I am afraid we might screw up ChannelVolume again in the future because the |
I've implemented |
9ea54c1
to
9f95a58
Compare
This is a major refactor touching all the parts. The idea behind it is that for the exceptional case of `Empty` we can supply None to either and otherwise we either have supplied values or some "sane" defaults available to use
9f95a58
to
39434d0
Compare
I was afraid adding all the options might reduce performance, but I am measuring a slight increase.. thats pretty neat. |
Folks, this change worries me because I do not understand where the actual problem is. Number of channels in Or did I miss something? I do not see any code that handles even number of channels differently, except |
// Side-notes: Also, I could not see any tests that check conversion to mono in I think |
And this is just theoretical, I am wondering if it makes sense to have typed streams, that are sequences of fixed size slices each containing all channel samples for a particular moment. This will make confusion of channels in a stream unlikely. |
So looking through the actual meat of the change here again. It looks like I am on the same page as you with concerns about the fragility of this. |
FWIW, the use case I was using channel volume for was having multiple mono-sources spatially located using distance-based amplitude panning (DBAP) which doesn't require phase-shifting. So I would setup an output with n-channels and have m-sources each with a channel volume backed DBAP Source based on the same principle as |
@DivineGod Feel free to file a ticket if you have particular suggestions on how to improve spatial. I think a test that demonstrates the problem is necessary for this issue. Do you use |
This PR will probably collect a few fixes that relate to #484 as I go through
rodio
to find all the issues that seem to prevent proper use ofChannelVolume
.I think I've identified a few areas that need attention, first being the
ChannelCountConverter
which is started with anEmpty
source whenSink::try_new
is called. This would cause an issue where the channel converter had the wrongto
count, as the actual source input channel count might not necessarily be 1 as the empty source was specifying. By settingEmpty
channels to 0 and handling the cases where they show up, we can more gracefully handle these issues.Next issue is an issue with the sample rate converter where if there's a mismatch the
ChannelVolume
once again seem to be messed up and not produce the right results. This might also have been identified in other issues; I've not triaged them all yet.