Playing a MIDI file clogs up the heap with millions of com.sun.media.sound.ModelSource[]

ساخت وبلاگ

Vote count: 0

As the title says, i have a game that plays a MIDI file in the background. This appears to create millions of instances of com.sun.media.sound.ModelSource[], taking up lots of RAM, causing GC lag spikes and probably clearing some SoftReferences (i'm not sure if they does). I don't have any other sound related code and it also does not appear to be related to the size of the soundbank I use. Is there any way to improve the memory footprint?

My code:

public class MusicPlayer { private Sequencer player; private Synthesizer synth; private Soundbank bank; private boolean paused = false; private boolean ready = false; public MusicPlayer() { try { // Initialize MIDI output player = MidiSystem.getSequencer(false); synth = MidiSystem.getSynthesizer(); bank = MidiSystem.getSoundbank(new BufferedInputStream(getClass().getResourceAsStream("path/to/soundbank.sf2"))); player.open(); synth.open(); player.getTransmitter().setReceiver(synth.getReceiver()); synth.loadAllInstruments(bank); } catch (Exception e) { System.err.println("MUSIC INITIALIZATION ERROR: n" + e.toString()); } } /** * Starts playing a new track */ public void play(String name) { try { Sequence track = Loader.getSong(name); player.stop(); player.setSequence(track); player.setMicrosecondPosition(0); // Rewind if needed player.setLoopCount(Sequencer.LOOP_CONTINUOUSLY); paused = false; ready = true; player.start(); // And here we go! } catch (Exception e) { System.err.println("MUSIC PLAY ERROR: n" + e.toString()); retu; } } /** * Pauses the currently playing track */ public void pause() { if (!paused && ready) { player.stop(); paused = true; } } /** * Unpauses the currently playing track */ public void unpause() { if (paused && ready) { player.start(); paused = false; } }
}
asked 1 min ago

back soft...
ما را در سایت back soft دنبال می کنید

برچسب : نویسنده : استخدام کار backsoft بازدید : 226 تاريخ : يکشنبه 12 ارديبهشت 1395 ساعت: 3:32