Skip to content
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

Improve audio playback for both wav and midi streams #199

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Commits on Oct 21, 2023

  1. media: PlatformPlayer: Fix wav and midi incorrect loop count

    It appears that most java games (Gameloft ones, like Asphalt 4,
    Asphalt 6, Ferrari GT 3, Assassin's Creed Revelations and many
    others for example) set the loop count on both midi and wav streams
    as 1. This, however, translates to Java 8 looping those samples one
    time more than needed, so every sfx and bgm playback repeated two
    times instead of just one.
    
    By reducing the requested loop count by one and checking cases
    where J2ME apps might request loop count 0, pretty much all the
    aforementioned games have their audio playback fixed.
    AShiningRay committed Oct 21, 2023
    Configuration menu
    Copy the full SHA
    8909567 View commit details
    Browse the repository at this point in the history
  2. media: Manager: Limit the amount of MIDI "channels" for J2ME apps

    DOOM II as well as Orcs and Elves II appear to constantly allocate
    new MIDI samples whenever a different sample from the previously
    played one is loaded, and never deallocate any of their samples,
    resulting in memory leaks. While not the best solution to this,
    we can work around those leaks by imposing a hard limit on how many
    MIDI "channel slots" a J2ME app can populate.
    
    Currently set at 36 slots, it seems to be big enough for anything i
    tested so far, including Ferrari GT 3 which loads up many different
    MIDI BGMs alongside wav files (unrestricted, can allocate as many
    as needed) during a race.
    AShiningRay committed Oct 21, 2023
    Configuration menu
    Copy the full SHA
    49c2ca7 View commit details
    Browse the repository at this point in the history
  3. WavImaAdpcmDecoder: Change some variables from int to byte type

    Swapping them to byte variables helps indicate that they should not
    receive larger values.
    AShiningRay committed Oct 21, 2023
    Configuration menu
    Copy the full SHA
    7e5b227 View commit details
    Browse the repository at this point in the history
  4. WavImaAdpcmDecoder: Offload ADPCM decoding to a separate thread

    The main thread on FreeJ2ME is already pretty busy with graphics
    and everything else, we don't need ADPCM decoding clogging things
    up even further. This should help make decoding faster and reduce
    stuttering.
    AShiningRay committed Oct 21, 2023
    Configuration menu
    Copy the full SHA
    2509a43 View commit details
    Browse the repository at this point in the history

Commits on Oct 22, 2023

  1. Make the max amount of MIDI players a configurable setting

    Instead of relying on a fixed value for the max, a user setting
    for that allows more control and fine tuning for specific apps.
    AShiningRay committed Oct 22, 2023
    Configuration menu
    Copy the full SHA
    1aa4a1d View commit details
    Browse the repository at this point in the history
  2. Manager: Avoid deallocating streams that are currently running

    Previously, the logic behind deallocating streams only took into
    account if the player index had reached the end of the array, and
    started deallocating from its first position onwards. This was a
    problem because it is possible that some of those positions would
    still be running when FreeJ2ME went to deallocate them.
    
    Now it will also take into account whether the current position
    is running or not, and will only forcefully deallocate a position
    that's running if the entire array is allocated, and all the
    players are running, to make space for a new one.
    AShiningRay committed Oct 22, 2023
    Configuration menu
    Copy the full SHA
    0dfcb9a View commit details
    Browse the repository at this point in the history