Corrected issue with terminating the SSEQ player by actually making it stop properly.
Corrected issue with terminating the SSEQ player by actually making it stop properly.

--- a/src/in_ncsf/SSEQPlayer/Player.cpp
+++ b/src/in_ncsf/SSEQPlayer/Player.cpp
@@ -1,7 +1,7 @@
 /*
  * SSEQ Player - Player structure
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
- * Last modification on 2013-03-30
+ * Last modification on 2013-04-01
  *
  * Adapted from source code of FeOS Sound System
  * By fincs
@@ -57,6 +57,35 @@
 	this->tempoCount = 0;
 	this->tempoRate = 0x100;
 	this->masterVol = 0; // this is actually the highest level
+}
+
+void Player::FreeTracks()
+{
+	for (uint8_t i = 0; i < this->nTracks; ++i)
+		this->tracks[this->trackIds[i]].Free();
+	this->nTracks = 0;
+}
+
+void Player::Stop(bool bKillSound)
+{
+	this->ClearState();
+	for (uint8_t i = 0; i < this->nTracks; ++i)
+	{
+		uint8_t trackId = this->trackIds[i];
+		this->tracks[trackId].ClearState();
+		for (int j = 0; j < 16; ++j)
+		{
+			Channel &chn = this->channels[j];
+			if (chn.state != CS_NONE && chn.trackId == trackId)
+			{
+				if (bKillSound)
+					chn.Kill();
+				else
+					chn.Release();
+			}
+		}
+	}
+	this->FreeTracks();
 }
 
 int Player::ChannelAlloc(int type, int priority)

--- a/src/in_ncsf/SSEQPlayer/Player.h
+++ b/src/in_ncsf/SSEQPlayer/Player.h
@@ -1,7 +1,7 @@
 /*
  * SSEQ Player - Player structure
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
- * Last modification on 2013-03-21
+ * Last modification on 2013-04-01
  *
  * Adapted from source code of FeOS Sound System
  * By fincs
@@ -35,6 +35,8 @@
 
 	bool Setup(const SSEQ *sseq);
 	void ClearState();
+	void FreeTracks();
+	void Stop(bool bKillSound);
 	int ChannelAlloc(int type, int prio);
 	int TrackAlloc();
 	void Run();

--- a/src/in_ncsf/SSEQPlayer/Track.cpp
+++ b/src/in_ncsf/SSEQPlayer/Track.cpp
@@ -1,7 +1,7 @@
 /*
  * SSEQ Player - Track structure
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
- * Last modification on 2013-03-30
+ * Last modification on 2013-04-01
  *
  * Adapted from source code of FeOS Sound System
  * By fincs
@@ -84,6 +84,12 @@
 	this->modSpeed = 16;
 	this->modDelay = 10;
 	this->modDepth = 0;
+}
+
+void Track::Free()
+{
+	this->state.reset();
+	this->updateFlags.reset();
 }
 
 int Track::NoteOn(int key, int vel, int len)

--- a/src/in_ncsf/SSEQPlayer/Track.h
+++ b/src/in_ncsf/SSEQPlayer/Track.h
@@ -1,7 +1,7 @@
 /*
  * SSEQ Player - Track structure
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
- * Last modification on 2013-03-21
+ * Last modification on 2013-04-01
  *
  * Adapted from source code of FeOS Sound System
  * By fincs
@@ -52,6 +52,7 @@
 	void Init(uint8_t handle, Player *ply, const uint8_t *pos, int n);
 	void Zero();
 	void ClearState();
+	void Free();
 	int NoteOn(int key, int vel, int len);
 	int NoteOnTie(int key, int vel);
 	void ReleaseAllNotes();

--- a/src/in_ncsf/XSFPlayer_NCSF.cpp
+++ b/src/in_ncsf/XSFPlayer_NCSF.cpp
@@ -1,7 +1,7 @@
 /*
  * xSF - NCSF Player
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
- * Last modification on 2013-03-30
+ * Last modification on 2013-04-01
  *
  * Partially based on the vio*sf framework
  *
@@ -194,6 +194,11 @@
 	}
 }
 
+void XSFPlayer_NCSF::Terminate()
+{
+	this->player.Stop(true);
+}
+
 void XSFPlayer_NCSF::SetInterpolation(unsigned interpolation)
 {
 	this->player.interpolation = static_cast<Interpolation>(interpolation);

--- a/src/in_ncsf/XSFPlayer_NCSF.h
+++ b/src/in_ncsf/XSFPlayer_NCSF.h
@@ -1,7 +1,7 @@
 /*
  * xSF - NCSF Player
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
- * Last modification on 2013-03-30
+ * Last modification on 2013-04-01
  *
  * Partially based on the vio*sf framework
  *
@@ -36,7 +36,7 @@
 	XSFPlayer_NCSF(const std::wstring &filename);
 	bool Load();
 	void GenerateSamples(std::vector<uint8_t> &buf, unsigned offset, unsigned samples);
-	void Terminate() { }
+	void Terminate();
 
 	void SetInterpolation(unsigned interpolation);
 	void SetMutes(const std::bitset<16> &newMutes);