-
-
Notifications
You must be signed in to change notification settings - Fork 5
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
Bug: radio reception is sometimes choppy #72
Comments
mill-j reported that he mostly got it working now. (debug mode for the plugin is always on with <1.0 versions, so must be manually turned off in the makefile) |
One reason for choppy audio may be that the audio processing is too slow. @mill-j, you might look at the timestamps in the logfile when receiving audio. You can deduce if the time it takes to process takes longer than allowed (PCM frame spacing / 20ms), probably we need to optimize the code there. |
I'll see what I can find. Just noticed if I start two RadioGUI instances and have only one radio in each then audio is great. If i add three it's worse than two. |
That would also suggest something "too slow" in the audio loop ( However the contrary: I was able to receive radio from about 100 fake clients (lua bots, but from the perspective of your own plugin, that's not known and they behave like normal clients) without choppy audio... |
Another cause could be:
|
@mill-j to quickly try out if its a locking issue, just remove the lock statements in the audio callback. If that helps, we probably need a exclusive locking at least in the writer (and gc thread) where the structure or the data changes (like adding/removing clients or radios). |
Removing the lock fgcom_remotecfg_mtx.lock(); and fgcom_remotecfg_mtx.unlock(); from mumble_onAudioSourceFetched does not seem to make any difference in audio. |
Hm then it’s probably something else. |
@mill-j Aside from the log: can you please try to do the following:
If we deduce by this which function introduces it, reenable the other functions to see if it can be isolated this way. Thanks! |
StutterLog.txt I had already tested without fgcom_audio_makeMono several days ago. I still haven't got around to testing the rest. |
After disabling the functions in audio.cpp it is no better. I do know the stuttering is the result from low resources: With two RadioGui Instances with 3 radios each. The two mumble clients are each maxing out a cpu core at 100%. Disconnecting only RadioGUI and not doing anything wth mumble will get the cpu uasge down to normal. So somehow we need to optimize for lower end computers. |
This is a very good finding. The question is where recently all this cpu is burned. |
Hm, we already found out sometime so that the audio receiving callback is too slow.
So a probable solution may be to decouple that from the data processing and just let it work on results gained in another thread:
that way we should save alot of processing while retaining nearly instant change updates: the update of the signal cache would only occur when needed (radio state change, location change, frequency, ptt etc), not like now where we calculate that for every voice packet! |
Sounds like a great idea. We should probably create an AudioOptimization branch. Testing on low end hardware will be no problem for me ;) My lenovo is fast compared to any of my other machines. |
Hm, i currently try to rewrite that. Let's see if i can deal with that. |
Maybe as an alternative - i think you already experimented with the update rate of the incoming packets, didn't you?
Maybe this helps: Thread.sleep(1000); // try 1 times per second This will ease the processing of the UDP server, because he tries to consume packets as fast as possible. That would be a whole lot easier than the rewrite. |
Aside from the idea with throttling the RadioGUI UDP thread, i found the following based on your log.
The slow is between the following lines, maybe also the radio model calculations are slow too. fgcom-mumble/client/mumble-plugin/fgcom-mumble.cpp Lines 884 to 916 in 88e74b8
|
I think you are correct, it seems the delay is still right after volume='1.000000'
Slowing the send rate in RadioGUI had no affect on the audio. It does make the ptt less responsive, however it appears to be much easier on the cpu. We might need to tweek to for optimal balance. Edit: I added several more debug messages:
The results show a little closer where the time is lost:
|
Just added commit to master, which lets user tweak easily (fgfs protocol can be tweaked at the protocol invocation at fgfs launcher): ae64242 (in the Options dialog) EDIT: as it turns out this is quite cool. Tuning the radioGUI down to 1Hz makes the debug log way more readable. |
Hey, @mill-j The basic idea was, based on your findings, to optimize around the frequency matching. Because of the internal data structures (and the need to support arbitary strings as "frequency") we need to do alot of string mangling.
With old code it takes 4ms here on my machine to calculate the match:
With the new code, it takes 2ms, so this might be a small step forward.
Can you try this branch, if it helps? What are the times now at your box? |
Oh and while playing with gprof, i found out that because we currently don't compile with compiler optimizations, the code is at least 10 times slower that it has to be. As a result, i changed the makefile so we have
I now really wonder:
|
Built master with make plugin. Results are perfect. Even with 4 radios in each RadioGUI and send rate 10mhz. The same is true about the Issue-72_audioOptimization branch built with make all-debug. Although the debug version seemed to take more cpu, it did not stutter or chop audio. I also tested with flightgear. It now works with my favorite plane, the new Piper Warrior II! Audio sounds amazing. |
Wow, now THAT are good news! It turned out it was not a problem with the code per se, but a missing compile optimizing flag. Before we close this, what do you think?
I would vote for „abandon the branch“ because i could not measure a significant gain, but the code is more complicated and harder to maintain. |
I'm fine with master the way it is. I see no performance difference between master and branch. |
Reported by mill-j:
Identified mumble branch state:
FGCom-mumble commit is 4b3ed22
I could not reproduce this here on my box (on mumble commit deb74a66348 "FIX: C&P error in API implementation" with 4b3ed22).
maybe this is a side effect of client version mismatch?
(This may have been introduced by mumbles commit c7ebe95030 "Synchronized API calls")
may be related to #58 as there are restructuring tips
The text was updated successfully, but these errors were encountered: