Force queue to play sources on frame boundaries#455
Conversation
|
Would it be fine to include @rparrett's sound file here? |
|
I authored the RL.wav and consent to its use here. Also just super excited about this getting fixed up. Great work! |
There was a problem hiding this comment.
a .wav file of 4.61 MB is way too big of an addition. Check the other files in the directory, they are all less than 1 MB. Is that example needed for something? I don't think we should add it. Otherwise the PR is fine, good work getting to the root cause of it.
|
Forgot to compress. It's needed and only 200kb now. |
|
What's the license of the file? Can you maybe add it to README.md in the assets dir and explain the license? |
|
I'd need @rparrett to confirm but I assume it would be the same as any other contribution. |
|
I relinquish all rights to RL.wav and you may modify or license it however you wish. |
|
So it's MIT OR Apache then. Fine. |
|
Possibly fixes #369 too? |
|
Possibly, could you test it and see? Also @est31 do you know when this will be included in a release? |
|
@dis-da-moe I don't know, i think I want to do a cpal release first, then make a rodio release. |
|
@dis-da-moe Testing on master, the issue doesn't seem to be fixed. The beginning and end of the beep (pure sine wave) are weird. 25--13-34-39.mp4 |
|
That seems like a separate issue, I'm not sure what causes it. |
|
@dis-da-moe I had encountered the issue that this PR proposes to fix before, in #286. Have you considered what happens if the output channel count is not a factor of 512, like 11? Prior to this PR, the silence is hard-coded as a single channel 44100Hz sample at 10ms. That is a 441 samples long buffer, which does not make a stereo frame boundary. I had worked around the issue by simply hard-coding queue.rs, sink.rs and empty.rs to 2, since I only needed it to work with stereo output. Changing the sampling rate, or frame count, would've also worked; as long as it generates a buffer that is a multiple of the output stream channel count. |
|
I haven't considered it since I've never encountered a case where the channel count is not a factor of 512. I assumed that's why 512 was chosen as the length of |
Purpose
Problem
As I understand it, this is the issue:
keep_alive_if_emptyset to true, and it becomes empty, then it will push a silence lasting 10ms onto the queue.current_frame_lenwould have returned the worst case,512, and the silence lasts less than that.Solution
Zeroto add a method to create a silence with a certain number of frames.THRESHOLDcurrent_frame_lento returnTHRESHOLDif a silence will be played next.Other Changes
At first, I could only reproduce this issue in the bevy game engine where the time a sink is created to when a source is appended can be long. The
spatialexample was the only example where stereo sound mattered, and so the issue was actually audible. However it had a bug where the right ear was at-1and the left was at1, so that combined with the inconsistency of the bug made it hard to reproduce.To hopefully prevent stereo bugs in the future, I fixed the
spatialexample and made it clearer what was happening, and added astereoexample where the file is played in the right ear and then in the left.