bkacjios / lua-mumble

A lua module to connect to a mumble server and interact with it
MIT License
23 stars 4 forks source link

Audio playback stutter #23

Open duarm opened 6 months ago

duarm commented 6 months ago

Thanks for making lua-mumble!

Same as #5, audio playback via

local stream, err = client:play("music.ogg", 1, 1.0)

stutters from time to time (every 10~20 seconds), tested with a 48000Hz 2ch ogg file.

bkacjios commented 6 months ago

What hardware are you running this on? What is the servers max bitrate? If it's every 20-30 seconds I'm wondering if the ping/pong is somehow to blame..

duarm commented 6 months ago

I'm running both the bot and the server on my own machine. Not sure which hardware is relevant but assuming my cpu: AMD Ryzen 5 3600. My mumble-server.ini says bandwidth=558000, I'm printing the PING PONG messages and periodically, after around 1~3 seconds every 2 PONGS, a stutter happens, it's somewhat consistent so I think it's a good guess.

Built myself from source, I'm on arch. protobuf-c 1.5.0-2 libev 4.33-2

bkacjios commented 6 months ago

Thank you. Cool. I have a similar setup as you. I'll have a few ideas on what may be the cause.

bkacjios commented 6 months ago

Mind trying my async-connect branch? I added some changes which I think helped with the audio stuttering. Plus it uses the new audio packet format that was introduced in mumble 1.5.

To use this branch, mumble.connect is no longer blocking, which means you have to use auth in a OnConnect hook.

client:hook("OnConnect", function(client)
    print("OnConnect", client)
    client:auth("TestBot")
end)
duarm commented 6 months ago

Tested a bit and it got worse, It depends on the bitrate of the song I think, some high bitrate sections completely destroys the quality and stutters a lot, and the audio quality is much degraded, although I noticed the quality was not that great in the previous version either.

image audio.webm

bkacjios commented 6 months ago

I really don't get it.. Here's a recording I made of the bot playing a 48000hz, 2 channel, ogg file. To me, it sounds perfect.

image

Mumble-2024-05-09-13-01-14-192.168.1.205-TestBot.zip

Try messing around with this...

client:setAudioQuality(mumble.quality.LOW) -- LOW, MEDIUM, HIGH, BEST are all valid options
client:getEncoder():setBitRate(10000) -- Manually set the bitrate to whatever you want. 10k bitrate sounds AFWUL.

I need to rename setAudioQuality, since it's what the "audio per packet" setting in the mumble client does.

It basically sets how many audio frames we send per packet. LOW = 10 MEDIUM = 20 HIGH = 40 BEST = 60

More = higher latency and less chances for stutter. However, it can quickly cause it to overflow the packet buffer, making it stutter.

I think in your case, you would actually want it LOW. Still, setAudioQuality will try to automatically adjust the bitrate of the encoder to work for the servers settings.

You should be seeing a message like this in the console when running the bot.

[MUMBLE -  WARN] Server maximum network bandwidth is only 558 kbit/s. Audio quality auto-adjusted to 96 kbit/s (20 ms)
duarm commented 6 months ago

I've been fiddling with the values and setting audio to BEST seems to make it much better (both quality and stutter-wise). Sometimes when I change a song (via client:play()), the beggining of the new song stutters a lot but after 1 or 2 seconds it stabilizes, I'll do a more extensive test eventually, it's much better now

bkacjios commented 6 months ago

Very very strange.. But good to know.

bkacjios commented 6 months ago

I'm starting to think the audio issues is a bug with mumble itself. I've had my bot playing a song on loop for a few hours now. It's been totally fine. I reconnected myself (not the bot) to the server and suddenly the audio was stuttering like crazy. Reconnecting again fixed it. Not sure what's going on there.

davidebeatrici commented 6 months ago

Related: mumble-voip/mumble#6415