[NCSF] Correctly handle the SSEQ volume from the INFO block.
[NCSF] Correctly handle the SSEQ volume from the INFO block.

--- a/src/in_ncsf/SSEQPlayer/Channel.cpp
+++ b/src/in_ncsf/SSEQPlayer/Channel.cpp
@@ -1,7 +1,7 @@
 /*
  * SSEQ Player - Channel structures
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
- * Last modification on 2014-10-05
+ * Last modification on 2014-10-18
  *
  * Adapted from source code of FeOS Sound System
  * By fincs
@@ -71,6 +71,7 @@
 void Channel::UpdateVol(const Track &trk)
 {
 	int finalVol = trk.ply->masterVol;
+	finalVol += trk.ply->sseqVol;
 	finalVol += Cnv_Sust(trk.vol);
 	finalVol += Cnv_Sust(trk.expr);
 	if (finalVol < -AMPL_K)

--- 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 2014-10-15
+ * Last modification on 2014-10-18
  *
  * Adapted from source code of FeOS Sound System
  * By fincs
@@ -11,7 +11,7 @@
 #include "Player.h"
 #include "common.h"
 
-Player::Player() : prio(0), nTracks(0), tempo(0), tempoCount(0), tempoRate(0), masterVol(0), sseq(nullptr), sampleRate(0), interpolation(INTERPOLATION_NONE)
+Player::Player() : prio(0), nTracks(0), tempo(0), tempoCount(0), tempoRate(0), masterVol(0), sseqVol(0), sseq(nullptr), sampleRate(0), interpolation(INTERPOLATION_NONE)
 {
 	memset(this->trackIds, 0, sizeof(this->trackIds));
 	for (size_t i = 0; i < 16; ++i)

--- 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 2014-10-13
+ * Last modification on 2014-10-18
  *
  * Adapted from source code of FeOS Sound System
  * By fincs
@@ -19,7 +19,7 @@
 {
 	uint8_t prio, nTracks;
 	uint16_t tempo, tempoCount, tempoRate /* 8.8 fixed point */;
-	int16_t masterVol;
+	int16_t masterVol, sseqVol;
 
 	const SSEQ *sseq;
 

--- a/src/in_ncsf/SSEQPlayer/common.h
+++ b/src/in_ncsf/SSEQPlayer/common.h
@@ -1,7 +1,7 @@
 /*
  * SSEQ Player - Common functions
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
- * Last modification on 2014-10-05
+ * Last modification on 2014-10-18
  *
  * Some code from FeOS Sound System
  * By fincs
@@ -159,6 +159,33 @@
 		return ((fall << 1) + 1) & 0xFFFF;
 	else
 		return (0x1E00 / (0x7E - fall)) & 0xFFFF;
+}
+
+inline int Cnv_Scale(int scale)
+{
+	static const int16_t lut[] =
+	{
+		-32768, -421, -361, -325, -300, -281, -265, -252,
+		-240, -230, -221, -212, -205, -198, -192, -186,
+		-180, -175, -170, -165, -161, -156, -152, -148,
+		-145, -141, -138, -134, -131, -128, -125, -122,
+		-120, -117, -114, -112, -110, -107, -105, -103,
+		-100, -98, -96, -94, -92, -90, -88, -86,
+		-85, -83, -81, -79, -78, -76, -74, -73,
+		-71, -70, -68, -67, -65, -64, -62, -61,
+		-60, -58, -57, -56, -54, -53, -52, -51,
+		-49, -48, -47, -46, -45, -43, -42, -41,
+		-40, -39, -38, -37, -36, -35, -34, -33,
+		-32, -31, -30, -29, -28, -27, -26, -25,
+		-24, -23, -23, -22, -21, -20, -19, -18,
+		-17, -17, -16, -15, -14, -13, -12, -12,
+		-11, -10, -9, -9, -8, -7, -6, -6,
+		-5, -4, -3, -3, -2, -1, -1, 0
+	};
+
+	if (scale & 0x80) // Supposedly invalid value...
+		scale = 0x7F; // Use apparently correct default
+	return lut[scale];
 }
 
 inline int Cnv_Sust(int sust)

--- 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 2014-10-13
+ * Last modification on 2014-10-18
  *
  * Partially based on the vio*sf framework
  *
@@ -173,10 +173,9 @@
 	file.data = &this->sdatData;
 	this->sdat.reset(new SDAT(file, this->sseq));
 	auto *sseqToPlay = this->sdat->sseq.get();
-	this->sseqVol = sseqToPlay->info.vol;
+	this->player.sseqVol = Cnv_Scale(sseqToPlay->info.vol);
 	this->player.sampleRate = this->sampleRate;
 	this->player.Setup(sseqToPlay);
-	//this->player.masterVol = sseqToPlay->info.vol;
 	this->player.Timer();
 	this->secondsPerSample = 1.0 / this->sampleRate;
 	this->secondsIntoPlayback = 0;
@@ -222,12 +221,6 @@
 				rightChannel += muldiv7(sample, chn.reg.panning);
 			}
 		}
-
-		leftChannel = muldiv7(leftChannel, 127 - this->player.masterVol);
-		rightChannel = muldiv7(rightChannel, 127 - this->player.masterVol);
-
-		//leftChannel = muldiv7(leftChannel, this->sseqVol);
-		//rightChannel = muldiv7(rightChannel, this->sseqVol);
 
 		buf[offset++] = leftChannel & 0xFF;
 		buf[offset++] = (leftChannel >> 8) & 0xFF;

--- 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 2014-10-05
+ * Last modification on 2014-10-18
  *
  * Partially based on the vio*sf framework
  *
@@ -23,7 +23,6 @@
 	std::vector<uint8_t> sdatData;
 	std::unique_ptr<SDAT> sdat;
 	Player player;
-	uint8_t sseqVol;
 	double secondsPerSample, secondsIntoPlayback, secondsUntilNextClock;
 	std::bitset<16> mutes;