Closed ElekKartofelek closed 1 month ago
Can confirm this happens, with any non-44100 Hz mic. If it's lower than 44100Hz it will be pitched up and for higher Hz mics it will be pitched down.
I can't look at this right now, but it seems that it's a mistake in these hint_range settings I put in here: https://github.com/goatchurchprime/two-voip-godot-4/blob/main/src/audio_stream_opus_chunked.cpp#L51
If you need it now, the github actions @DmitriySalnikov set up for me are very robust so if you fork this and change those numbers it will rebuild it for you in a few minutes.
When the sample rates are the same (48k), it bypasses the resampler. Hopefully there isn't a bug here. Both of these opus libraries only work with 48k so this resampling is necessary if you have the less optimal 44.1k as many systems do. I'd like to use the resampler in the godot engine (the pitch setting) to get rid of my resampling code, but haven't got round to it.
The bigger problem with the wrong sampling isn't the change of pitch so much that the audio tracks take a different amount of time to play, so the comms are quickly out of sync or starved.
I've made a release, which seems to work in the simple case, and prints errors instead of crashes when you set the sample rate different to 8000,12000,16000,24000,48000 https://github.com/goatchurchprime/two-voip-godot-4/actions/runs/11093736993
If you set the audiosamplerate to 48000 don't forget to set the audiosample size to 960
Did this work? I can change the settings to the my project (General -> Audio -> Driver -> mix_rate) and the audio from the mic comes in lower that it should be, probably because my laptop is ignoring it.
Is it the case that you have some external USB mic that provides 48KHz data, even though the engine is running at 44.1KHz? I'd like more details, as I've only been using my system mic.
I've merged in some changes to functions you probably don't use that let me resample without applying the opus compression. Resampling to a lower bitrate like 8KHz doesn't change the size of the Opus packets, which is a good sign that it's compressing the underlying voice sound, not the data it is given.
In my case it worked perfectly! After setting audiosamplerate to 48000 and samplesize to 960 audio is now in sync and pitched correctly (tested on two separate machines) 😁👍
For some reason my audio interface doesn't allow 44100 Hz mic input so it's stuck to 48000 Hz. AudioEffectOpusChunked has some settings that probably would be able to fix my issue but Audiosamplerate can't be changed to anything else than 44100 and Opussamplerate outright crashes the engine on any change.
I've already tried setting audio sample rate in Project Settings to 48Khz but nothing changed at all.
https://github.com/user-attachments/assets/d6055ad9-79b7-4f19-946f-23af8d38e30a