adrenak / univoice-audiosource-output

MIT License
3 stars 1 forks source link

Voice Stutter #3

Open ImNotTiara opened 1 year ago

ImNotTiara commented 1 year ago

I'm having an issue where the voice output starts stuttering after some time or if the local player experiences a brief freeze (can be manually reproduced by pausing and unpausing the editor).

I assume it has to do something with the audio buffer falling behind without recovering?

In the "UniVoiceAudioSourceOutput.New" i have a minSegCount of 2 and a segCount of 4. Maybe i've just configured it incorrectly?

adrenak commented 1 year ago

What's your segLen? I try to have a segCount segLen of about 5 seconds and a minSegCount segLen of 1 second. That reduces stutter but adds to the latency. It's a tradeoff

ImNotTiara commented 1 year ago

My segDataLen is 1600.

I did some further debugging and it seems to happen in the Feed method where "locIdx" and "bufferIndex" will desync have the same values. They will have the same values until the local player experiences yet another brief freeze which causes them to bump into sync again.

One solution would be to reset the buffer to force it into sync again. I currently do this by disabling and re-enabling the gameobject. There must be another proper way to do this.

adrenak commented 1 year ago

I see, that is a good catch, I'll introduce something to do it without disabling the gameobject. Has this solved your issue properly? If not, with a segDataLen of 1600, and I'm assuming you're on 16000Hz, your minSegCount of 2 means the audio starts playing when the buffer has just 200ms of audio. If you have fluctuating network latency you can easily exhaust it. I'd recommend changing it to atleast 5 so you keep .5 seconds of playable audio before playback starts. That also means a .5 second delay in audio reception. And segCount to 25 so the buffer has 2.5 so that if you exhaust playable audiot, it'll take you 2.5 seconds to go around the buffer and end up with 2.5 seconds of playable audio.

I'll make some improvements to the buffer, your suggestion is helpful and I have other features in mind too.

ImNotTiara commented 1 year ago

From my testing of basically playing music over the network for more than 2 hours it seems to have indeed "solved" it, even when trying my best to make it break which is really good. A single small stutter here and there which is totally fine (will probably be even less noticeable when a proper buffer reset compared to my method of doing it).

And yeah segDataLen of 1600 with 16000Hz indeed. I guess i'm really pushing the limits of trying to have it as low-latency as possible which could/will cause issues with bad connections and i should definitely play around with the configuration.

Thank you!

adrenak commented 1 year ago

Glad to hear that! So the enable/disable method with largera values i suggested? Btw thanks for the heavy testing I really appreciate it!

ImNotTiara commented 1 year ago

No, the test was conducted using my low-latency values. And no problems! Thank you for maintaining and providing this awesome framework!

Ahmed310 commented 11 months ago

My segDataLen is 1600.

I did some further debugging and it seems to happen in the Feed method where "locIdx" and "bufferIndex" will desync have the same values. They will have the same values until the local player experiences yet another brief freeze which causes them to bump into sync again.

One solution would be to reset the buffer to force it into sync again. I currently do this by disabling and re-enabling the gameobject. There must be another proper way to do this.

@ImNotTiara can you elaborate it more how enabling & disabling the gameobject has fixed it?

Ahmed310 commented 11 months ago

I see, that is a good catch, I'll introduce something to do it without disabling the gameobject. Has this solved your issue properly? If not, with a segDataLen of 1600, and I'm assuming you're on 16000Hz, your minSegCount of 2 means the audio starts playing when the buffer has just 200ms of audio. If you have fluctuating network latency you can easily exhaust it. I'd recommend changing it to atleast 5 so you keep .5 seconds of playable audio before playback starts. That also means a .5 second delay in audio reception. And segCount to 25 so the buffer has 2.5 so that if you exhaust playable audiot, it'll take you 2.5 seconds to go around the buffer and end up with 2.5 seconds of playable audio.

I'll make some improvements to the buffer, your suggestion is helpful and I have other features in mind too.

I'm also facing voice stutters, can you point me to the right direction which buffer to clear/rest to make it disappear.