Yes.... so, for some reason unknown to me, my Music class instances fail to stop or free the song assigned to them. As a result, songs are able to overlap, even if I free the previous song from an object before reassigning, like so:
if (song != null)
{
song.Free();
}
song = new Music(map.musicFilename);
song.Play();
The following code is executed upon initialization of my program.
FMOD.create();
FSound.FSOUND_SetMixer(FSound.FSOUND_MIXER_QUALITY_FPU);
FSound.FSOUND_Init(48000, 64, FSound.FSOUND_INIT_USEDEFAULTMIDISYNTH);
The following is my code for my Music wrapper.
package trouser;
import org.lwjgl.fmod3.*;
public class Music
{
public static final int NONE = 0;
public static final int MODULE = 1;
public static final int STREAM = 2;
public int musicType;
public FSoundStream stream;
public int streamChannel;
public FMusicModule mod;
public Music(String filename)
{
if (Helper.getExtension(filename).equalsIgnoreCase("mp3")
|| Helper.getExtension(filename).equalsIgnoreCase("mpeg3")
|| Helper.getExtension(filename).equalsIgnoreCase("ogg"))
{
this.musicType = STREAM;
this.stream = FSound.FSOUND_Stream_Open(filename, FSound.FSOUND_LOOP_NORMAL, 0, 0);
if (stream == null)
{
this.musicType = NONE;
System.out.println("Song \"" + filename + "\" could not be loaded.");
}
}
else
{
this.musicType = MODULE;
this.mod = FMusic.FMUSIC_LoadSong(filename);
if (this.mod == null)
{
this.musicType = NONE;
System.out.println("Song \"" + filename + "\" could not be loaded.");
}
else
{
FMusic.FMUSIC_SetLooping(this.mod, true);
}
}
}
public void Play()
{
if (this.musicType == NONE) return;
else if (this.musicType == STREAM)
{
streamChannel = FSound.FSOUND_Stream_Play(FSound.FSOUND_FREE, this.stream);
return;
}
else if (this.musicType == MODULE)
{
FMusic.FMUSIC_PlaySong(this.mod);
return;
}
}
public void SetVolume(int volume)
{
if (this.musicType == NONE) return;
else if (this.musicType == STREAM)
{
FSound.FSOUND_SetVolume(this.streamChannel, volume * 256 / 100);
return;
}
else if (this.musicType == MODULE)
{
FMusic.FMUSIC_SetMasterVolume(this.mod, volume * 256 / 100);
return;
}
}
public void Stop()
{
if (this.musicType == NONE) return;
else if (this.musicType == STREAM)
{
FSound.FSOUND_Stream_Stop(this.stream);
return;
}
else if (this.musicType == MODULE)
{
FMusic.FMUSIC_StopSong(this.mod);
return;
}
}
public void Free()
{
this.Stop();
if (this.musicType == NONE) return;
else if (this.musicType == STREAM)
{
FSound.FSOUND_Stream_Close(this.stream);
this.stream = null;
this.musicType = NONE;
return;
}
else if (this.musicType == MODULE)
{
FMusic.FMUSIC_FreeSong(this.mod);
this.mod = null;
this.musicType = NONE;
return;
}
}
}
Any help is much appreciated, I'm sure I must be overlooking a small detail.