[-] Correct FluidSynth player cleanup
This commit is contained in:
parent
a39d6d6e92
commit
f4b21b6282
3 changed files with 49 additions and 20 deletions
|
@ -78,6 +78,18 @@ enum _play_audio_flags_ {
|
|||
PlayAudioLoadOnDemand = 8 /// Load only if needed.
|
||||
};
|
||||
|
||||
/**
|
||||
** Fluidsynth flags
|
||||
*/
|
||||
#ifdef USE_FLUIDSYNTH
|
||||
enum SynthState
|
||||
{
|
||||
StateCleaned = 0,
|
||||
StateInitialized,
|
||||
StatePlaying
|
||||
};
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
-- Functions
|
||||
----------------------------------------------------------------------------*/
|
||||
|
@ -147,10 +159,12 @@ extern int InitSound();
|
|||
extern void QuitSound();
|
||||
|
||||
#ifdef USE_FLUIDSYNTH
|
||||
/// Gets the state of Fluidsynth player
|
||||
SynthState GetFluidSynthState();
|
||||
/// Init FluidSynth library
|
||||
extern int InitFluidSynth();
|
||||
// Cleans all FluidSynth data
|
||||
extern void CleanFluidSynth();
|
||||
extern void CleanFluidSynth(bool reinit = false);
|
||||
#endif
|
||||
|
||||
//@}
|
||||
|
|
|
@ -52,13 +52,6 @@ struct FluidSynthData {
|
|||
CFile *MIDIFile; /// MIDI file handle
|
||||
};
|
||||
|
||||
enum SynthState
|
||||
{
|
||||
StateCleaned = 0,
|
||||
StateInitialized,
|
||||
StatePlaying
|
||||
};
|
||||
|
||||
class CSynthesizer {
|
||||
public:
|
||||
CSynthesizer() : Settings(NULL), Synth(NULL), Player(NULL), State(StateCleaned) {}
|
||||
|
@ -157,22 +150,37 @@ CSampleFluidSynth::~CSampleFluidSynth()
|
|||
delete[] this->Buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
** Gets the state of Fluidsynth player
|
||||
**
|
||||
*/
|
||||
SynthState GetFluidSynthState()
|
||||
{
|
||||
return FluidSynthesizer.State;
|
||||
}
|
||||
|
||||
/**
|
||||
** Cleans FluidSynth data
|
||||
**
|
||||
*/
|
||||
void CleanFluidSynth()
|
||||
void CleanFluidSynth(bool reinit)
|
||||
{
|
||||
if (FluidSynthesizer.Player) {
|
||||
if (reinit) {
|
||||
delete_fluid_player(FluidSynthesizer.Player);
|
||||
FluidSynthesizer.Player = new_fluid_player(FluidSynthesizer.Synth);
|
||||
FluidSynthesizer.State = StateInitialized;
|
||||
} else {
|
||||
if (FluidSynthesizer.Player) {
|
||||
delete_fluid_player(FluidSynthesizer.Player);
|
||||
}
|
||||
if (FluidSynthesizer.Synth) {
|
||||
delete_fluid_synth(FluidSynthesizer.Synth);
|
||||
}
|
||||
if (FluidSynthesizer.Settings) {
|
||||
delete_fluid_settings(FluidSynthesizer.Settings);
|
||||
}
|
||||
FluidSynthesizer.State = StateCleaned;
|
||||
}
|
||||
if (FluidSynthesizer.Synth) {
|
||||
delete_fluid_synth(FluidSynthesizer.Synth);
|
||||
}
|
||||
if (FluidSynthesizer.Settings) {
|
||||
delete_fluid_settings(FluidSynthesizer.Settings);
|
||||
}
|
||||
FluidSynthesizer.State = StateCleaned;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -250,9 +258,7 @@ CSample *LoadFluidSynth(const char *name, int flags)
|
|||
}
|
||||
} else if (FluidSynthesizer.State == StatePlaying) {
|
||||
// Reinit the player
|
||||
delete_fluid_player(FluidSynthesizer.Player);
|
||||
FluidSynthesizer.Player = new_fluid_player(FluidSynthesizer.Synth);
|
||||
FluidSynthesizer.State = StateInitialized;
|
||||
CleanFluidSynth(true);
|
||||
}
|
||||
|
||||
strcpy_s(s, sizeof(s), name);
|
||||
|
|
|
@ -39,6 +39,10 @@
|
|||
|
||||
#include "sound_server.h"
|
||||
|
||||
#ifdef USE_FLUIDSYNTH
|
||||
#include "fluidsynth.h"
|
||||
#endif
|
||||
|
||||
#include "iocompat.h"
|
||||
#include "iolib.h"
|
||||
|
||||
|
@ -675,6 +679,11 @@ void StopMusic()
|
|||
{
|
||||
if (MusicPlaying) {
|
||||
MusicPlaying = false;
|
||||
#ifdef USE_FLUIDSYNTH
|
||||
if (GetFluidSynthState() == StatePlaying) {
|
||||
CleanFluidSynth(true);
|
||||
}
|
||||
#endif
|
||||
if (MusicChannel.Sample) {
|
||||
SDL_LockAudio();
|
||||
delete MusicChannel.Sample;
|
||||
|
|
Loading…
Reference in a new issue