Skip to content

Conversation

@SomeTroglodyte
Copy link
Collaborator

@SomeTroglodyte SomeTroglodyte commented Oct 30, 2025

This is an experiment, but so far it works.

Inspiration was #13932 (comment) where I found that Red & Black project wrapping MiniAudio - I plonked it in removing a lot of workaround crud - and lo and behold it seems to work very very well. The lib is still young and if we decide to go for it, they're open to calls for help/improvements.

Plus:

  • Seems reliable and easy to use
  • Remove kludges like HardenGdxAudio or the retries/delays when playing simple sounds
  • The music player now shows time into track and track length on a smoothly moving slider - the lib has length and position and seek
  • flac and possibly soon opus support

Minus:

  • Android untested
  • I can't get the "echo" node I'm using for playRepeated() to stop echoing, but otherwise it sounds so much better.
  • ogg files and files loaded from jar don't report their length, mp3's from mods do just fine edit: and ogg too unless loaded in streaming mode - which I've turned off for them. Edit: actually irrelevant, as the music player doesn't offer jar assets.
  • The timer in MusicController is still left in there, though it should be easy to eliminate it, as the library has its own fade code which is easy and works out of the box without surprises. What I'm missing is an event or callback to get notified when the fade ends - same as I'm missing the callback for a normal end of a track - the timer sees those by checking isPlaying, and that still works with only trivial changes...
  • With gdx-miniaudio 0.6, increases jar size by 5% / 2,6MB

So - questions:

  • Is the more permissive license (Apache 2.0) of that library a blocker? I abhor legalese and my brain just shuts down with that crud, but would we need to add documentation to make that inclusion aggressor-proof?
  • Is this move attractive to anyone else but me? It could solve # 13932 - at least I'm pretty hopeful.

References:

@SomeTroglodyte

This comment was marked as outdated.

@RobLoach
Copy link
Collaborator

Thanks for putting in the effort here. I was able to hear city ambience, listen to music, and get leader voices without issue. I would be curious to see if we could get this to work without adopting MiniAudio though. Haven't done the debugging around it yet myself, but I have a suspicion it's inconsistent audio frequencies.

@fgnm
Copy link

fgnm commented Oct 30, 2025

Hi! Thanks for considering gdx-miniaudio as a replacement for Gdx.audio. I'd be very happy to help supporting this transition, so feel free to open any kind of issues on the main repo, I'll to my best to get them fixed, also the author of miniaudio is very collaborative, so on the support point of view you are covered :)

Few notes I have on this PR:

  • Apache 2.0 license is the same of libGDX, it's very permissive and you'll have absolutely no troubles to use it combined with any other licenses. MiniAudio has even more permissive license so I don't think you'll have troubles on that side.
  • I advice to use OpenSL instead of AAudio on Android platform. You can disable AAudio using MAContextConfiguration#androidUseAAudio and set it to false. We have observed that AAudio suffers of very strange issues linked to the OS or bad implementation by the vendors, nothing MiniAudio or gdx-miniaudio can do.. At this moment OpenSL is just more stable. Unless you really needs the low latency features of AAudio, and I don't think Unciv needs this!
  • Currently the only real annoying thing in MiniAudio is that files cannot be read directly from the jar archive, and if you load them from memory (without prior extraction to an installation folder) you'll loose the length info (even if this issue will be fixed in miniaudio v0.12 once released)

@SomeTroglodyte
Copy link
Collaborator Author

  • license is the same of libGDX

Ah, proves how blocked my brain is when it comes to legalese.

AAudio suffers of very strange

Yeah, some of the code this PR removes is a kludge for Android-specific fails under Gdx.audio. But as said, I haven't tested on roid at all - yet. I'm slightly hesitant in part because avd's have become so incredibly slow as compared to ~2 years ago. Means I let it simmer to build courage before plugging the cable into my actual private phone. Actually, that's laziness - I should have one or two or three S5's lying around, and there should be some not too old LOS for those.

supporting this

Don't worry, I've got a list - mainly ma_sound_set_end_callback - but I'll let that mature for now and go play something completely different 🙃

@SomeTroglodyte
Copy link
Collaborator Author

Thanks for putting in the effort here. I was able to hear city ambience, listen to music, and get leader voices without issue. I would be curious to see if we could get this to work without adopting MiniAudio though. Haven't done the debugging around it yet myself, but I have a suspicion it's inconsistent audio frequencies.

Matches my experience. This PR is early stage, known areas needing attention (optimizing engine sample rate being one of them), and still the very first Ctrl-F9 was stable and played everything... I really was quite baffled.

But "without adopting MiniAudio" - you must be joking. That's the whole point! Under Gdx there's layers and people, and under this too. Gdx - a team that is active but seemingly hasn't looked at audio for quite a while and down below that - no activity for years. Here it's almost just one brain per layer, but those are active and obviously - to me - both (throth?) clever and thorough and cooperative.

@SomeTroglodyte
Copy link
Collaborator Author

@RobLoach > audio frequencies

You can now edit your GameSettings.json, add ,"audioConfig":{"logLevels":["ERROR","WARNING","INFO","DEVICES"],"engine":{"sampleRate":22050}} (e.g.) before the closing curly, and start experimenting from there. Do add -DnoLog= -DonlyLog=GdxMiniAudio to the props to see the log output.

A perfect "no-resampling through the entire pipeline" won't be possible though, one - I don't even believe our standard sounds all have the same rate, though I remember once making an effort, two - mods, three - the native sample rate of the output devices varies widely. Not even two samsungs were the same last time I looked, long ago.

@github-actions
Copy link

github-actions bot commented Nov 4, 2025

This pull request has conflicts, please resolve those before we can evaluate the pull request.

# Conflicts:
#	core/src/com/unciv/utils/Log.kt
@github-actions
Copy link

github-actions bot commented Nov 5, 2025

Conflicts have been resolved.

@github-actions github-actions bot removed the Conflicts label Nov 5, 2025
@SomeTroglodyte
Copy link
Collaborator Author

Edited original post: + flac + jar size, some outdated marked/removed

@github-actions
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

# Conflicts:
#	core/src/com/unciv/UncivGame.kt
#	core/src/com/unciv/logic/files/UncivFiles.kt
#	core/src/com/unciv/ui/popups/options/SoundTab.kt
#	core/src/com/unciv/ui/screens/worldscreen/mainmenu/WorldScreenMusicPopup.kt
#	desktop/src/com/unciv/app/desktop/DesktopLauncher.kt
#	desktop/src/com/unciv/app/desktop/DesktopLogBackend.kt
@github-actions
Copy link

Conflicts have been resolved.

@github-actions
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@SomeTroglodyte
Copy link
Collaborator Author

Another argument in favour:
libgdx/libgdx#7712

# Conflicts:
#	core/src/com/unciv/ui/audio/SoundPlayer.kt
@github-actions
Copy link

Conflicts have been resolved.

@SomeTroglodyte
Copy link
Collaborator Author

  • Updated gdx-miniaudio version
  • Rewrote playRepeated so it sounds like before

See https://libgdx.com/wiki/audio/audio for another endorsement

@github-actions
Copy link

github-actions bot commented Dec 1, 2025

This pull request has conflicts, please resolve those before we can evaluate the pull request.

# Conflicts:
#	core/src/com/unciv/UncivGame.kt
@github-actions github-actions bot removed the Conflicts label Dec 1, 2025
@github-actions
Copy link

github-actions bot commented Dec 1, 2025

Conflicts have been resolved.

@github-actions
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

# Conflicts:
#	core/src/com/unciv/logic/files/UncivFiles.kt
@github-actions
Copy link

Conflicts have been resolved.

@github-actions
Copy link

github-actions bot commented Jan 4, 2026

This pull request has conflicts, please resolve those before we can evaluate the pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants