Browse code

[NCSF] Move track allocation into the SSEQ command handler.

This was suggested by fincs after I found some sequences that appeared
to do track allocations later in them than expected originally.

Naram Qashat authored on 2014/10/15 18:03:10
Showing 4 changed files
... ...
@@ -8,53 +8,57 @@ team for their open-source Nintendo DS emulator.
8 8
 
9 9
 Version History
10 10
 ---------------
11
-  v1.0 - 2013-03-25 - Initial Version
12
-  v1.1 - 2013-04-02 - Fixed crash upon seeking backwards (also causes crash
13
-                      in XMPlay on stopping).
14
-                    - Added version number to the plugin description.
15
-                    - Added 3 more interpolation options: B-spline, Hermite,
16
-                      and Optimal.
17
-  v1.2 - 2013-04-07 - Fixed crash if Winamp tries to access a file that no
18
-                      longer exists, reported by Caitsith2.
19
-                    - Utilized the SSEQ's volume from the INFO section.
20
-                    - Minor optimizations.
21
-  v1.3 - 2013-04-10 - Added more interpolation methods, cleanup of interpolation
22
-                      code, and stopped using slope to determine points outside
23
-                      the sample in an attempt to prevent clipping or popping.
24
-                    - Made it so certain changes in the configuration dialog
25
-                      will apply immediately after clicking OK.
26
-                    - Minor optimizations.
27
-  v1.4 - 2013-04-12 - Removed the Optimal, Lagrange, and Hermite interpolations,
28
-                      added in 2nd-order Osculating interpolation.
29
-                    - Changed handling of start/end of SWAV data to use the
30
-                      closest data point instead of only the current one.
31
-  v1.5 - 2013-04-18 - Implemented circular interpolation buffer to fix
32
-                      interpolation, thanks to kode54 for the code.
33
-  v1.6 - 2013-04-23 - Added Lanczos (Sinc) interpolation. Also modified Cosine
34
-                      interpolation to use a lookup table instead.
35
-  v1.7 - 2013-04-26 - Fixed Lanczos interpolation a bit (thanks to kode54), also
36
-                      allowed the plugin to handle 32-bit samples.
37
-v1.7.1 - 2013-04-26 - Minor update to scale the phase offset, thanks to kode54.
38
-  v1.8 - 2013-05-07 - Replaced Lanczos window for Sinc with the Hann window.
39
-                    - Added a ring buffer designed to work with SWAVs, replaces
40
-                      kode54's implementation (still have to give him big thanks
41
-                      for the original implementation).
42
-                    - Corrected clamping issue which caused some clipping-like
43
-                      effects.
44
-v1.8.1 - 2014-06-17 - Reverted Sinc interpolation back to the Lanczos window.
45
-  v1.9 - 2014-09-28 - Removed the Cosine, B-Spline, and Osculating
46
-                      interpolations, added 4-point and 6-point Legrange
47
-                      interpolations in their place.
48
-                    - Updated zlib to v1.2.8.
49
-v1.9.1 - 2014-10-05 - Fixed volume issues that stemmed from how FeOS Sound
50
-                      System was handling volume. Utilized some code from the
51
-                      Nintendo DS SDK to help fix this.
52
-                    - Added a clone of DeSmuME's Sound View that only shows up
53
-                      in debug builds, was used to help me identify the above
54
-                      issue to fix it.
55
- v1.10 - 2014-10-13 - Implemented the random, variable, and conditional
56
-                      commands.
57
-                    - Fixed loop counter.
11
+   v1.0 - 2013-03-25 - Initial Version
12
+   v1.1 - 2013-04-02 - Fixed crash upon seeking backwards (also causes crash
13
+                       in XMPlay on stopping).
14
+                     - Added version number to the plugin description.
15
+                     - Added 3 more interpolation options: B-spline, Hermite,
16
+                       and Optimal.
17
+   v1.2 - 2013-04-07 - Fixed crash if Winamp tries to access a file that no
18
+                       longer exists, reported by Caitsith2.
19
+                     - Utilized the SSEQ's volume from the INFO section.
20
+                     - Minor optimizations.
21
+   v1.3 - 2013-04-10 - Added more interpolation methods, cleanup of interpolation
22
+                       code, and stopped using slope to determine points outside
23
+                       the sample in an attempt to prevent clipping or popping.
24
+                     - Made it so certain changes in the configuration dialog
25
+                       will apply immediately after clicking OK.
26
+                     - Minor optimizations.
27
+   v1.4 - 2013-04-12 - Removed the Optimal, Lagrange, and Hermite interpolations,
28
+                       added in 2nd-order Osculating interpolation.
29
+                     - Changed handling of start/end of SWAV data to use the
30
+                       closest data point instead of only the current one.
31
+   v1.5 - 2013-04-18 - Implemented circular interpolation buffer to fix
32
+                       interpolation, thanks to kode54 for the code.
33
+   v1.6 - 2013-04-23 - Added Lanczos (Sinc) interpolation. Also modified Cosine
34
+                       interpolation to use a lookup table instead.
35
+   v1.7 - 2013-04-26 - Fixed Lanczos interpolation a bit (thanks to kode54), also
36
+                       allowed the plugin to handle 32-bit samples.
37
+ v1.7.1 - 2013-04-26 - Minor update to scale the phase offset, thanks to kode54.
38
+   v1.8 - 2013-05-07 - Replaced Lanczos window for Sinc with the Hann window.
39
+                     - Added a ring buffer designed to work with SWAVs, replaces
40
+                       kode54's implementation (still have to give him big thanks
41
+                       for the original implementation).
42
+                     - Corrected clamping issue which caused some clipping-like
43
+                       effects.
44
+ v1.8.1 - 2014-06-17 - Reverted Sinc interpolation back to the Lanczos window.
45
+   v1.9 - 2014-09-28 - Removed the Cosine, B-Spline, and Osculating
46
+                       interpolations, added 4-point and 6-point Legrange
47
+                       interpolations in their place.
48
+                     - Updated zlib to v1.2.8.
49
+ v1.9.1 - 2014-10-05 - Fixed volume issues that stemmed from how FeOS Sound
50
+                       System was handling volume.
51
+                     - Stopped utilizing SSEQ's volume from the INFO section, as
52
+                       it seemed like it wasn't used in the real thing.
53
+                     - Added a clone of DeSmuME's Sound View that only shows up
54
+                       in debug builds, was used to help me identify the above
55
+                       issue to fix it.
56
+  v1.10 - 2014-10-13 - Implemented the random, variable, and conditional
57
+                       commands.
58
+                     - Fixed loop counter.
59
+v1.10.1 - 2014-10-15 - Moved track allocation into the SSEQ command handler on a
60
+                       suggestion from fincs when I had found a sequence that
61
+                       allocated tracks later than expected originally.
58 62
 
59 63
 This is a Winamp plugin to play NCSF files. NCSF is a PSF-style music format that
60 64
 uses SDAT files from Nintendo DS ROMs as it's "program".
... ...
@@ -1,7 +1,7 @@
1 1
 /*
2 2
  * SSEQ Player - Player structure
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2014-10-13
4
+ * Last modification on 2014-10-15
5 5
  *
6 6
  * Adapted from source code of FeOS Sound System
7 7
  * By fincs
... ...
@@ -31,21 +31,7 @@ bool Player::Setup(const SSEQ *sseqToPlay)
31 31
 	this->nTracks = 1;
32 32
 	this->trackIds[0] = firstTrack;
33 33
 
34
-	auto pData = &this->sseq->data[0];
35
-	if (*pData == 0xFE)
36
-		for (pData += 3; *pData == 0x93; ) // Prepare extra tracks
37
-		{
38
-			++pData;
39
-			int tNum = read8(&pData);
40
-			auto pos = &this->sseq->data[read24(&pData)];
41
-			int newTrack = this->TrackAlloc();
42
-			if (newTrack == -1)
43
-				continue;
44
-			this->tracks[newTrack].Init(newTrack, this, pos, tNum);
45
-			this->trackIds[this->nTracks++] = newTrack;
46
-		}
47
-
48
-	this->tracks[firstTrack].startPos = this->tracks[firstTrack].pos = pData;
34
+	this->tracks[firstTrack].startPos = this->tracks[firstTrack].pos = &this->sseq->data[0];
49 35
 
50 36
 	this->ClearState();
51 37
 
... ...
@@ -1,7 +1,7 @@
1 1
 /*
2 2
  * SSEQ Player - Track structure
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2014-10-13
4
+ * Last modification on 2014-10-15
5 5
  *
6 6
  * Adapted from source code of FeOS Sound System
7 7
  * By fincs
... ...
@@ -260,6 +260,9 @@ void Track::ReleaseAllNotes()
260 260
 
261 261
 enum SseqCommand
262 262
 {
263
+	SSEQ_CMD_ALLOCTRACK = 0xFE, // Silently ignored
264
+	SSEQ_CMD_OPENTRACK = 0x93,
265
+
263 266
 	SSEQ_CMD_REST = 0x80,
264 267
 	SSEQ_CMD_PATCH = 0x81,
265 268
 	SSEQ_CMD_PAN = 0xC0,
... ...
@@ -359,6 +362,7 @@ static inline uint8_t SseqCommandByteCount(int cmd)
359 362
 			case SSEQ_CMD_MUTE:
360 363
 				return 1;
361 364
 
365
+			case SSEQ_CMD_ALLOCTRACK:
362 366
 			case SSEQ_CMD_TEMPO:
363 367
 			case SSEQ_CMD_SWEEPPITCH:
364 368
 			case SSEQ_CMD_MODDELAY:
... ...
@@ -381,6 +385,9 @@ static inline uint8_t SseqCommandByteCount(int cmd)
381 385
 			case SSEQ_CMD_CMP_NE:
382 386
 				return 3;
383 387
 
388
+			case SSEQ_CMD_OPENTRACK:
389
+				return 4;
390
+
384 391
 			case SSEQ_CMD_FROMVAR:
385 392
 				return 1 | ExtraByteOnNoteOrVarOrCmp; // Technically 2 bytes with an additional 1, leaving 1 off because we will be reading it to determine if the additional byte is needed
386 393
 
... ...
@@ -510,6 +517,19 @@ void Track::Run()
510 517
 				// Main commands
511 518
 				//-----------------------------------------------------------------
512 519
 
520
+				case SSEQ_CMD_OPENTRACK:
521
+				{
522
+					int tNum = read8(pData);
523
+					auto pos = &this->ply->sseq->data[read24(pData)];
524
+					int newTrack = this->ply->TrackAlloc();
525
+					if (newTrack != -1)
526
+					{
527
+						this->ply->tracks[newTrack].Init(newTrack, this->ply, pos, tNum);
528
+						this->ply->trackIds[this->ply->nTracks++] = newTrack;
529
+					}
530
+					break;
531
+				}
532
+
513 533
 				case SSEQ_CMD_REST:
514 534
 					this->wait = this->overriding.val(pData, readvl);
515 535
 					break;
... ...
@@ -595,15 +615,10 @@ void Track::Run()
595 615
 						const uint8_t *rPos = this->stack[this->stackPos - 1].dest;
596 616
 						uint8_t &nR = this->loopCount[this->stackPos - 1];
597 617
 						uint8_t prevR = nR;
598
-						if (!prevR)
618
+						if (!prevR || --nR)
599 619
 							*pData = rPos;
600 620
 						else
601
-						{
602
-							if (--nR)
603
-								*pData = rPos;
604
-							else
605
-								--this->stackPos;
606
-						}
621
+							--this->stackPos;
607 622
 					}
608 623
 					break;
609 624
 
... ...
@@ -1,7 +1,7 @@
1 1
 /*
2 2
  * xSF - NCSF configuration
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2014-10-13
4
+ * Last modification on 2014-10-15
5 5
  *
6 6
  * Partially based on the vio*sf framework
7 7
  */
... ...
@@ -21,7 +21,7 @@ enum
21 21
 
22 22
 unsigned XSFConfig::initSampleRate = 44100;
23 23
 std::string XSFConfig::commonName = "NCSF Decoder";
24
-std::string XSFConfig::versionNumber = "1.10";
24
+std::string XSFConfig::versionNumber = "1.10.1";
25 25
 unsigned XSFConfig_NCSF::initInterpolation = 4;
26 26
 std::string XSFConfig_NCSF::initMutes = "0000000000000000";
27 27