There's a new bug I've noticed: sometimes, an instrument will just
'disappear', and refuse to ever play again.
This stuff is practically impossible to debug, so I'm just throwing
things at the wall. This time, I'm going to make more use of the
`AXVoiceBegin` and `AXVoiceEnd` functions. I have no idea what
they're meant to do: code I found online uses it inconstently, and
Decaf doesn't have it implemented at all!
Hopefully, all of my problems have just been race conditions caused
by not using these guard functions (assuming that's what they are).
The previous method wasn't good enough: we were still maxing-out at
96 (did the Decaf devs misread that as hex? Is that why the
emulator's limit is 150 instead?).
Anyway, this new solution is a little brutish, but I can't think of
anything else that would work: right now, I have the Organya thread
constantly polling a linked-list of the currently-loaded sounds, and
checking if their voices have finished playing or not. If they've
finished, they get freed.
When AudioBackend_PlaySound is called, if checks if the sound's voice
has been freed or not, and reallocates it if it has.
There doesn't seem to be a noticable overhead to this, and it keeps
the number of currently-allocated voices *very* low (from 10 to 20 on
average).
I'm getting some rare audio hangs. I tried doing some
regression-testing, but it's so random that I'm getting anomalous
results. That said, there were suspicious results around this change
(and also the way `mix_data` is initialised/cleared), so I'm
reverting this for now, and restoring it next time I encounter a
hang.
Currently doesn't produce sound unless you stop Organya from calling
AudioBackend_CreateSound, because it exhausts the Wii U's 150-sound
pool before the SFX get any of them.