Feodor0090 / nmania

Vertical Scrolling Rhythm Game for J2ME
GNU General Public License v3.0
17 stars 2 forks source link

[question outside the game itself] j2me audio/sfx without lag (? #157

Closed rodrigo1593 closed 10 months ago

rodrigo1593 commented 10 months ago

well, i saw this was made with j2me, and i want to know if there is a way to play sounds or audio without lag. because at least with the info i saw online it was with prefetch & etc...

Feodor0090 commented 10 months ago

The short answer - read docs, where prefetch/loading process is exhaustively explained.

The longer one... Well, once you read docs you will know that realize step captures audio related hardware, prefetch loads data and start starts. Of course, no devices/"emulators" follow these specifications, so, at least on s40/s60 realize actually does nothing (because they support polyphony so you don't need to "capture" anything like in ASIO/ALSA) and prefetch only setups data streams (opens file/http/jar). So, calling start actually triggers stream reading (from memory/sd/http/something_else) which is the cause of the delay between start call and playback start. Also, player end (even without deallocate call) will automatically drop all buffers and trigger GC which causes JVM to lock up to 70-80ms.

So, at least on S40/S60 there is no way to do so. This is the reason why this game does not support hitsounds.

Feodor0090 commented 10 months ago

If you use non-"raster" audio (midi), its end of playback does not trigger GC. Also, startup time is faster than for "raster" formats (mp3/adpcm/aac/...) So your best chance is to checkout this repo to 2.6.0 or earlier, copypaste Multisample thing and try using it with MIDI sfxes.