Skip to content

Commit

Permalink
PlatformPlayer: wavPlayer shall open its clip on prefetch()
Browse files Browse the repository at this point in the history
Getting scarce MIDI resources on realize() seems fine (and is
required for Phoenix Wright). Death Race on the other hand, shows
that for the WavPlayer, it has to happen on prefetch(), with those
scarce resources being freed on deallocate, otherwise the game
will keep opening new clips nonstop.

Should also fix other jars, Death Race is just very easy to notice
since it reloads a lot of wav streams on each race.
  • Loading branch information
AShiningRay committed Dec 3, 2024
1 parent 8caa14f commit 0580297
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/org/recompile/mobile/PlatformPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -608,11 +608,16 @@ public wavPlayer(InputStream stream)

public void realize()
{
state = Player.REALIZED;
}

public void prefetch()
{
try
{
wavClip = AudioSystem.getClip();
wavClip.open(wavStream);
state = Player.REALIZED;
state = Player.PREFETCHED;
}
catch (Exception e)
{
Expand All @@ -621,8 +626,6 @@ public void realize()
}
}

public void prefetch() { state = Player.PREFETCHED; }

public void start()
{
if(getMediaTime() >= getDuration()) { setMediaTime(0); }
Expand Down Expand Up @@ -653,7 +656,7 @@ public void stop()
notifyListeners(PlayerListener.STOPPED, getMediaTime());
}

public void deallocate() { } // Prefetch does "nothing" in each internal player so deallocate must also do nothing
public void deallocate() { wavClip.close(); }

public void close()
{
Expand Down

0 comments on commit 0580297

Please sign in to comment.