Skip to content
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

Fixed ChannelVolume size_hint and added tests #440

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

dbartussek
Copy link

The current implementation of size_hint for ChannelVolume is broken for two reasons:

1. The number of samples in input and result should be the same, but each sample may produce more or less elements if channel count differs

To fix this, the size hint is first divided by the source channel count, then multiplied by the result channel count.

2. The sample currently being emitted is not taken into account

To fix this, we add how many times we will emit self.current_sample (=> How many channels still remain for this sample).

// The input source provides a number of samples (input_hint / channels);
// We return 1 item per channel per sample => * channel_volumes
let input_provides =
input_hint / (self.input.channels() as usize) * self.channel_volumes.len();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering about this part, what happens if input_hint is not a multiple of the channel number? Maybe we should first multiply by channel_volumes.len and then do the division? Or is that wrong?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switching the order would be wrong, we have to ceil the division.
If we divide first, a hint of 5 when mapping from stereo to stereo would result in 5 again, but 6 values will be returned.

So I will change the division to ceil, thank you for noticing this mistake.

@dvdsk dvdsk force-pushed the master branch 3 times, most recently from b10961c to a7f67b3 Compare October 10, 2024 00:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants