Browse code

Fix warning about invalid index.

Naram Qashat authored on 2021/03/21 13:14:35
Showing 1 changed files
... ...
@@ -105,14 +105,17 @@ int Player::ChannelAlloc(ChannelAllocateType type, int priority)
105 105
 		int thisChnNo = chnArray[i];
106 106
 		if (!this->allowedChannels[thisChnNo])
107 107
 			continue;
108
-		Channel &thisChn = this->channels[thisChnNo];
109
-		Channel &curChn = this->channels[curChnNo];
110
-		if (curChnNo != -1 && thisChn.prio >= curChn.prio)
108
+		if (curChnNo != -1)
111 109
 		{
112
-			if (thisChn.prio != curChn.prio)
113
-				continue;
114
-			if (curChn.vol <= thisChn.vol)
115
-				continue;
110
+			Channel &thisChn = this->channels[thisChnNo];
111
+			Channel &curChn = this->channels[curChnNo];
112
+			if (curChnNo != -1 && thisChn.prio >= curChn.prio)
113
+			{
114
+				if (thisChn.prio != curChn.prio)
115
+					continue;
116
+				if (curChn.vol <= thisChn.vol)
117
+					continue;
118
+			}
116 119
 		}
117 120
 		curChnNo = thisChnNo;
118 121
 	}
Browse code

Various changes:

* Use enum class instead of enum (except for the enums for the resource IDs, not really necessary there).
* For NCSF specifically, included a function to convert an enum class to its underlying integral type (as this is needed for use with the std::bitset class).
* Cleanup headers so all the ones needed in a file are explicitly included even if they may possibly be included in another header.
* Used forward declarations in a few spots.
* Explicitly namespaced all (u)int*_t uses (this might seem like overkill, but it helps me see when the standard types are being used with a simple search for std::).
* Made sure it all builds with MinGW-w64 as well (both gcc and clang).
* Removed some std::move from DialogBuilder.cpp based on clang's warnings for that.
* Replaced use of std::copy_n on strings in DialogBuilder.cpp with my CopyToString functions that use wcscpy.
* Replaced CHAR_MIN/CHAR_MAX in eqstr.h and ltstr.h with std::numeric_limits<char>::min/max().

Naram Qashat authored on 2021/03/21 03:16:45
Showing 1 changed files
... ...
@@ -7,14 +7,18 @@
7 7
  * https://github.com/fincs/FSS
8 8
  */
9 9
 
10
+#include <algorithm>
11
+#include <cstdint>
10 12
 #include "Player.h"
13
+#include "SSEQ.h"
11 14
 #include "common.h"
15
+#include "consts.h"
12 16
 
13 17
 Player::Player() : prio(0), nTracks(0), tempo(0), tempoCount(0), tempoRate(0), masterVol(0), sseqVol(0), sseq(nullptr), allowedChannels(0), sampleRate(0),
14
-	interpolation(INTERPOLATION_NONE)
18
+	interpolation(Interpolation::None)
15 19
 {
16 20
 	std::fill_n(&this->trackIds[0], FSS_TRACKCOUNT, 0);
17
-	for (int8_t i = 0; i < 16; ++i)
21
+	for (std::int8_t i = 0; i < 16; ++i)
18 22
 	{
19 23
 		this->channels[i].chnId = i;
20 24
 		this->channels[i].ply = this;
... ...
@@ -55,7 +59,7 @@ void Player::ClearState()
55 59
 // Original FSS Function: Player_FreeTracks
56 60
 void Player::FreeTracks()
57 61
 {
58
-	for (uint8_t i = 0; i < this->nTracks; ++i)
62
+	for (std::uint8_t i = 0; i < this->nTracks; ++i)
59 63
 		this->tracks[this->trackIds[i]].Free();
60 64
 	this->nTracks = 0;
61 65
 }
... ...
@@ -64,14 +68,14 @@ void Player::FreeTracks()
64 68
 void Player::Stop(bool bKillSound)
65 69
 {
66 70
 	this->ClearState();
67
-	for (uint8_t i = 0; i < this->nTracks; ++i)
71
+	for (std::uint8_t i = 0; i < this->nTracks; ++i)
68 72
 	{
69
-		uint8_t trackId = this->trackIds[i];
73
+		std::uint8_t trackId = this->trackIds[i];
70 74
 		this->tracks[trackId].ClearState();
71 75
 		for (int j = 0; j < 16; ++j)
72 76
 		{
73 77
 			Channel &chn = this->channels[j];
74
-			if (chn.state != CS_NONE && chn.trackId == trackId)
78
+			if (chn.state != ChannelState::None && chn.trackId == trackId)
75 79
 			{
76 80
 				if (bKillSound)
77 81
 					chn.Kill();
... ...
@@ -84,16 +88,16 @@ void Player::Stop(bool bKillSound)
84 88
 }
85 89
 
86 90
 // Original FSS Function: Chn_Alloc
87
-int Player::ChannelAlloc(int type, int priority)
91
+int Player::ChannelAlloc(ChannelAllocateType type, int priority)
88 92
 {
89
-	static const uint8_t pcmChnArray[] = { 4, 5, 6, 7, 2, 0, 3, 1, 8, 9, 10, 11, 14, 12, 15, 13 };
90
-	static const uint8_t psgChnArray[] = { 8, 9, 10, 11, 12, 13 };
91
-	static const uint8_t noiseChnArray[] = { 14, 15 };
92
-	static const uint8_t arraySizes[] = { sizeof(pcmChnArray), sizeof(psgChnArray), sizeof(noiseChnArray) };
93
-	static const uint8_t *const arrayArray[] = { pcmChnArray, psgChnArray, noiseChnArray };
93
+	static const std::uint8_t pcmChnArray[] = { 4, 5, 6, 7, 2, 0, 3, 1, 8, 9, 10, 11, 14, 12, 15, 13 };
94
+	static const std::uint8_t psgChnArray[] = { 8, 9, 10, 11, 12, 13 };
95
+	static const std::uint8_t noiseChnArray[] = { 14, 15 };
96
+	static const std::uint8_t arraySizes[] = { sizeof(pcmChnArray), sizeof(psgChnArray), sizeof(noiseChnArray) };
97
+	static const std::uint8_t *const arrayArray[] = { pcmChnArray, psgChnArray, noiseChnArray };
94 98
 
95
-	auto chnArray = arrayArray[type];
96
-	int arraySize = arraySizes[type];
99
+	auto chnArray = arrayArray[ToIntegral(type)];
100
+	int arraySize = arraySizes[ToIntegral(type)];
97 101
 
98 102
 	int curChnNo = -1;
99 103
 	for (int i = 0; i < arraySize; ++i)
... ...
@@ -126,10 +130,10 @@ int Player::TrackAlloc()
126 130
 	for (int i = 0; i < FSS_MAXTRACKS; ++i)
127 131
 	{
128 132
 		Track &thisTrk = this->tracks[i];
129
-		if (!thisTrk.state[TS_ALLOCBIT])
133
+		if (!thisTrk.state[ToIntegral(TrackState::AllocateBit)])
130 134
 		{
131 135
 			thisTrk.Zero();
132
-			thisTrk.state.set(TS_ALLOCBIT);
136
+			thisTrk.state.set(ToIntegral(TrackState::AllocateBit));
133 137
 			thisTrk.updateFlags.reset();
134 138
 			return i;
135 139
 		}
... ...
@@ -143,7 +147,7 @@ void Player::Run()
143 147
 	while (this->tempoCount >= 240)
144 148
 	{
145 149
 		this->tempoCount -= 240;
146
-		for (uint8_t i = 0; i < this->nTracks; ++i)
150
+		for (std::uint8_t i = 0; i < this->nTracks; ++i)
147 151
 			this->tracks[this->trackIds[i]].Run();
148 152
 	}
149 153
 	this->tempoCount += (static_cast<int>(this->tempo) * static_cast<int>(this->tempoRate)) >> 8;
Browse code

Replace memcpy/memset with std::copy_n/std::fill_n.

Naram Qashat authored on 2021/03/19 16:25:21
Showing 1 changed files
... ...
@@ -13,13 +13,13 @@
13 13
 Player::Player() : prio(0), nTracks(0), tempo(0), tempoCount(0), tempoRate(0), masterVol(0), sseqVol(0), sseq(nullptr), allowedChannels(0), sampleRate(0),
14 14
 	interpolation(INTERPOLATION_NONE)
15 15
 {
16
-	memset(this->trackIds, 0, sizeof(this->trackIds));
16
+	std::fill_n(&this->trackIds[0], FSS_TRACKCOUNT, 0);
17 17
 	for (int8_t i = 0; i < 16; ++i)
18 18
 	{
19 19
 		this->channels[i].chnId = i;
20 20
 		this->channels[i].ply = this;
21 21
 	}
22
-	memset(this->variables, -1, sizeof(this->variables));
22
+	std::fill_n(&this->variables[0], 32, -1);
23 23
 }
24 24
 
25 25
 // Original FSS Function: Player_Setup
... ...
@@ -49,7 +49,7 @@ void Player::ClearState()
49 49
 	this->tempoCount = 0;
50 50
 	this->tempoRate = 0x100;
51 51
 	this->masterVol = 0; // this is actually the highest level
52
-	memset(this->variables, -1, sizeof(this->variables));
52
+	std::fill_n(&this->variables[0], 32, -1);
53 53
 }
54 54
 
55 55
 // Original FSS Function: Player_FreeTracks
Browse code

Remove last modification date from files.

(I never remember to update these and besides, GitHub history can show when they were last modified.)

Naram Qashat authored on 2021/03/19 10:58:12
Showing 1 changed files
... ...
@@ -1,7 +1,6 @@
1 1
 /*
2 2
  * SSEQ Player - Player structure
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2014-10-25
5 4
  *
6 5
  * Adapted from source code of FeOS Sound System
7 6
  * By fincs
Browse code

Various updates:

* Fix build with Visual Studio, updating projects to Visual Studio 2019 (as that is what I have installed).
* Changed C++ language standard to C++ 17.
* Add files for in_2sf's spu from Coda's recent commit.
* Add files for zlib now that it is being included as a submodule (removes the need for the zlib DLL as well).
* Remove common.props (due to the aforementioned zlib inclusion as well as the winamp headers also being in the project now).
* Minor NCSF file in the SSEQ player, the check for when to process tracks should've been >=, not >.

Naram Qashat authored on 2021/03/15 22:34:25
Showing 1 changed files
... ...
@@ -141,7 +141,7 @@ int Player::TrackAlloc()
141 141
 // Original FSS Function: Player_Run
142 142
 void Player::Run()
143 143
 {
144
-	while (this->tempoCount > 240)
144
+	while (this->tempoCount >= 240)
145 145
 	{
146 146
 		this->tempoCount -= 240;
147 147
 		for (uint8_t i = 0; i < this->nTracks; ++i)
Browse code

[NCSF] Super minor cleanups.

Naram Qashat authored on 2020/08/07 23:25:58
Showing 1 changed files
... ...
@@ -15,7 +15,7 @@ Player::Player() : prio(0), nTracks(0), tempo(0), tempoCount(0), tempoRate(0), m
15 15
 	interpolation(INTERPOLATION_NONE)
16 16
 {
17 17
 	memset(this->trackIds, 0, sizeof(this->trackIds));
18
-	for (size_t i = 0; i < 16; ++i)
18
+	for (int8_t i = 0; i < 16; ++i)
19 19
 	{
20 20
 		this->channels[i].chnId = i;
21 21
 		this->channels[i].ply = this;
Browse code

[NCSF] Utilize the PLAYER blocks in the SDAT if they exist.

Backwards compatibility is kept by treating the lack of PLAYER info as
if all channels are able to be allocated.

Naram Qashat authored on 2014/10/25 23:12:53
Showing 1 changed files
... ...
@@ -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-23
4
+ * Last modification on 2014-10-25
5 5
  *
6 6
  * Adapted from source code of FeOS Sound System
7 7
  * By fincs
... ...
@@ -11,7 +11,8 @@
11 11
 #include "Player.h"
12 12
 #include "common.h"
13 13
 
14
-Player::Player() : prio(0), nTracks(0), tempo(0), tempoCount(0), tempoRate(0), masterVol(0), sseqVol(0), sseq(nullptr), sampleRate(0), interpolation(INTERPOLATION_NONE)
14
+Player::Player() : prio(0), nTracks(0), tempo(0), tempoCount(0), tempoRate(0), masterVol(0), sseqVol(0), sseq(nullptr), allowedChannels(0), sampleRate(0),
15
+	interpolation(INTERPOLATION_NONE)
15 16
 {
16 17
 	memset(this->trackIds, 0, sizeof(this->trackIds));
17 18
 	for (size_t i = 0; i < 16; ++i)
... ...
@@ -99,6 +100,8 @@ int Player::ChannelAlloc(int type, int priority)
99 100
 	for (int i = 0; i < arraySize; ++i)
100 101
 	{
101 102
 		int thisChnNo = chnArray[i];
103
+		if (!this->allowedChannels[thisChnNo])
104
+			continue;
102 105
 		Channel &thisChn = this->channels[thisChnNo];
103 106
 		Channel &curChn = this->channels[curChnNo];
104 107
 		if (curChnNo != -1 && thisChn.prio >= curChn.prio)
Browse code

[NCSF] Bump version number for the previous fixes.

Naram Qashat authored on 2014/10/23 23:27:37
Showing 1 changed files
... ...
@@ -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-18
4
+ * Last modification on 2014-10-23
5 5
  *
6 6
  * Adapted from source code of FeOS Sound System
7 7
  * By fincs
Browse code

[NCSF] Documented what FSS functions were originally used.

* Changed default of modDelay to 0.
* Also minor cleanup.

Naram Qashat authored on 2014/10/23 23:19:16
Showing 1 changed files
... ...
@@ -15,10 +15,14 @@ Player::Player() : prio(0), nTracks(0), tempo(0), tempoCount(0), tempoRate(0), m
15 15
 {
16 16
 	memset(this->trackIds, 0, sizeof(this->trackIds));
17 17
 	for (size_t i = 0; i < 16; ++i)
18
+	{
18 19
 		this->channels[i].chnId = i;
20
+		this->channels[i].ply = this;
21
+	}
19 22
 	memset(this->variables, -1, sizeof(this->variables));
20 23
 }
21 24
 
25
+// Original FSS Function: Player_Setup
22 26
 bool Player::Setup(const SSEQ *sseqToPlay)
23 27
 {
24 28
 	this->sseq = sseqToPlay;
... ...
@@ -38,6 +42,7 @@ bool Player::Setup(const SSEQ *sseqToPlay)
38 42
 	return true;
39 43
 }
40 44
 
45
+// Original FSS Function: Player_ClearState
41 46
 void Player::ClearState()
42 47
 {
43 48
 	this->tempo = 120;
... ...
@@ -47,6 +52,7 @@ void Player::ClearState()
47 52
 	memset(this->variables, -1, sizeof(this->variables));
48 53
 }
49 54
 
55
+// Original FSS Function: Player_FreeTracks
50 56
 void Player::FreeTracks()
51 57
 {
52 58
 	for (uint8_t i = 0; i < this->nTracks; ++i)
... ...
@@ -54,6 +60,7 @@ void Player::FreeTracks()
54 60
 	this->nTracks = 0;
55 61
 }
56 62
 
63
+// Original FSS Function: Player_Stop
57 64
 void Player::Stop(bool bKillSound)
58 65
 {
59 66
 	this->ClearState();
... ...
@@ -76,6 +83,7 @@ void Player::Stop(bool bKillSound)
76 83
 	this->FreeTracks();
77 84
 }
78 85
 
86
+// Original FSS Function: Chn_Alloc
79 87
 int Player::ChannelAlloc(int type, int priority)
80 88
 {
81 89
 	static const uint8_t pcmChnArray[] = { 4, 5, 6, 7, 2, 0, 3, 1, 8, 9, 10, 11, 14, 12, 15, 13 };
... ...
@@ -105,12 +113,12 @@ int Player::ChannelAlloc(int type, int priority)
105 113
 
106 114
 	if (curChnNo == -1 || priority < this->channels[curChnNo].prio)
107 115
 		return -1;
108
-	this->channels[curChnNo].ply = this;
109 116
 	this->channels[curChnNo].noteLength = -1;
110 117
 	this->channels[curChnNo].vol = 0x7FF;
111 118
 	return curChnNo;
112 119
 }
113 120
 
121
+// Original FSS Function: Track_Alloc
114 122
 int Player::TrackAlloc()
115 123
 {
116 124
 	for (int i = 0; i < FSS_MAXTRACKS; ++i)
... ...
@@ -127,6 +135,7 @@ int Player::TrackAlloc()
127 135
 	return -1;
128 136
 }
129 137
 
138
+// Original FSS Function: Player_Run
130 139
 void Player::Run()
131 140
 {
132 141
 	while (this->tempoCount > 240)
... ...
@@ -146,6 +155,7 @@ void Player::UpdateTracks()
146 155
 		this->tracks[i].updateFlags.reset();
147 156
 }
148 157
 
158
+// Original FSS Function: Snd_Timer
149 159
 void Player::Timer()
150 160
 {
151 161
 	this->UpdateTracks();
Browse code

[NCSF] Reversed the order of the PSG and Noise channel allocations.

This was suggested by fincs as the proper way to fix channels being
cutoff incorrectly.
(Also moved volume assignment so it was less duplicated.)

Naram Qashat authored on 2014/10/23 23:05:57
Showing 1 changed files
... ...
@@ -79,8 +79,8 @@ void Player::Stop(bool bKillSound)
79 79
 int Player::ChannelAlloc(int type, int priority)
80 80
 {
81 81
 	static const uint8_t pcmChnArray[] = { 4, 5, 6, 7, 2, 0, 3, 1, 8, 9, 10, 11, 14, 12, 15, 13 };
82
-	static const uint8_t psgChnArray[] = { 13, 12, 11, 10, 9, 8 };
83
-	static const uint8_t noiseChnArray[] = { 15, 14 };
82
+	static const uint8_t psgChnArray[] = { 8, 9, 10, 11, 12, 13 };
83
+	static const uint8_t noiseChnArray[] = { 14, 15 };
84 84
 	static const uint8_t arraySizes[] = { sizeof(pcmChnArray), sizeof(psgChnArray), sizeof(noiseChnArray) };
85 85
 	static const uint8_t *const arrayArray[] = { pcmChnArray, psgChnArray, noiseChnArray };
86 86
 
... ...
@@ -107,7 +107,7 @@ int Player::ChannelAlloc(int type, int priority)
107 107
 		return -1;
108 108
 	this->channels[curChnNo].ply = this;
109 109
 	this->channels[curChnNo].noteLength = -1;
110
-	this->channels[curChnNo].vol = 0;
110
+	this->channels[curChnNo].vol = 0x7FF;
111 111
 	return curChnNo;
112 112
 }
113 113
 
Browse code

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

Naram Qashat authored on 2014/10/18 04:20:53
Showing 1 changed files
... ...
@@ -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-15
4
+ * Last modification on 2014-10-18
5 5
  *
6 6
  * Adapted from source code of FeOS Sound System
7 7
  * By fincs
... ...
@@ -11,7 +11,7 @@
11 11
 #include "Player.h"
12 12
 #include "common.h"
13 13
 
14
-Player::Player() : prio(0), nTracks(0), tempo(0), tempoCount(0), tempoRate(0), masterVol(0), sseq(nullptr), sampleRate(0), interpolation(INTERPOLATION_NONE)
14
+Player::Player() : prio(0), nTracks(0), tempo(0), tempoCount(0), tempoRate(0), masterVol(0), sseqVol(0), sseq(nullptr), sampleRate(0), interpolation(INTERPOLATION_NONE)
15 15
 {
16 16
 	memset(this->trackIds, 0, sizeof(this->trackIds));
17 17
 	for (size_t i = 0; i < 16; ++i)
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 1 changed files
... ...
@@ -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
 
Browse code

[NCSF] Implemented the random, variable, and conditional commands. Also fixed loop counter.

Naram Qashat authored on 2014/10/13 18:00:29
Showing 1 changed files
... ...
@@ -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 2013-05-07
4
+ * Last modification on 2014-10-13
5 5
  *
6 6
  * Adapted from source code of FeOS Sound System
7 7
  * By fincs
... ...
@@ -16,6 +16,7 @@ Player::Player() : prio(0), nTracks(0), tempo(0), tempoCount(0), tempoRate(0), m
16 16
 	memset(this->trackIds, 0, sizeof(this->trackIds));
17 17
 	for (size_t i = 0; i < 16; ++i)
18 18
 		this->channels[i].chnId = i;
19
+	memset(this->variables, -1, sizeof(this->variables));
19 20
 }
20 21
 
21 22
 bool Player::Setup(const SSEQ *sseqToPlay)
... ...
@@ -57,6 +58,7 @@ void Player::ClearState()
57 58
 	this->tempoCount = 0;
58 59
 	this->tempoRate = 0x100;
59 60
 	this->masterVol = 0; // this is actually the highest level
61
+	memset(this->variables, -1, sizeof(this->variables));
60 62
 }
61 63
 
62 64
 void Player::FreeTracks()
Browse code

* Replaced Lanczos window with Hann window for the windowed sinc function in the NCSF plugin. * Added a ring buffer specifically designed for working with SWAVs to replace the one provided by kode54, still have to give him thanks for the original though. * Fixed clipping issue caused by invalid clamping values. * Minor fix to using the min()/max() functions of numeric_limits because Winamp's out.h includes windows.h without my specific wrapper to redefine things.

Naram Qashat authored on 2013/05/07 05:42:46
Showing 1 changed files
... ...
@@ -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 2013-04-18
4
+ * Last modification on 2013-05-07
5 5
  *
6 6
  * Adapted from source code of FeOS Sound System
7 7
  * By fincs
... ...
@@ -120,7 +120,6 @@ int Player::ChannelAlloc(int type, int priority)
120 120
 	this->channels[curChnNo].ply = this;
121 121
 	this->channels[curChnNo].noteLength = -1;
122 122
 	this->channels[curChnNo].vol = 0;
123
-	this->channels[curChnNo].clearHistory();
124 123
 	return curChnNo;
125 124
 }
126 125
 
Browse code

Implemented circular interpolation buffer to fix interpolation, thanks to kode54 for the code.

Naram Qashat authored on 2013/04/18 20:43:31
Showing 1 changed files
... ...
@@ -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 2013-04-01
4
+ * Last modification on 2013-04-18
5 5
  *
6 6
  * Adapted from source code of FeOS Sound System
7 7
  * By fincs
... ...
@@ -120,6 +120,7 @@ int Player::ChannelAlloc(int type, int priority)
120 120
 	this->channels[curChnNo].ply = this;
121 121
 	this->channels[curChnNo].noteLength = -1;
122 122
 	this->channels[curChnNo].vol = 0;
123
+	this->channels[curChnNo].clearHistory();
123 124
 	return curChnNo;
124 125
 }
125 126
 
Browse code

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

Naram Qashat authored on 2013/04/02 03:03:26
Showing 1 changed files
... ...
@@ -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 2013-03-30
4
+ * Last modification on 2013-04-01
5 5
  *
6 6
  * Adapted from source code of FeOS Sound System
7 7
  * By fincs
... ...
@@ -59,6 +59,35 @@ void Player::ClearState()
59 59
 	this->masterVol = 0; // this is actually the highest level
60 60
 }
61 61
 
62
+void Player::FreeTracks()
63
+{
64
+	for (uint8_t i = 0; i < this->nTracks; ++i)
65
+		this->tracks[this->trackIds[i]].Free();
66
+	this->nTracks = 0;
67
+}
68
+
69
+void Player::Stop(bool bKillSound)
70
+{
71
+	this->ClearState();
72
+	for (uint8_t i = 0; i < this->nTracks; ++i)
73
+	{
74
+		uint8_t trackId = this->trackIds[i];
75
+		this->tracks[trackId].ClearState();
76
+		for (int j = 0; j < 16; ++j)
77
+		{
78
+			Channel &chn = this->channels[j];
79
+			if (chn.state != CS_NONE && chn.trackId == trackId)
80
+			{
81
+				if (bKillSound)
82
+					chn.Kill();
83
+				else
84
+					chn.Release();
85
+			}
86
+		}
87
+	}
88
+	this->FreeTracks();
89
+}
90
+
62 91
 int Player::ChannelAlloc(int type, int priority)
63 92
 {
64 93
 	static const uint8_t pcmChnArray[] = { 4, 5, 6, 7, 2, 0, 3, 1, 8, 9, 10, 11, 14, 12, 15, 13 };
Browse code

Cleanup of some warnings, updating modification dates, using nullptr instead of NULL in some cases.

Naram Qashat authored on 2013/03/30 16:17:42
Showing 1 changed files
... ...
@@ -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 2013-03-25
4
+ * Last modification on 2013-03-30
5 5
  *
6 6
  * Adapted from source code of FeOS Sound System
7 7
  * By fincs
... ...
@@ -11,7 +11,7 @@
11 11
 #include "Player.h"
12 12
 #include "common.h"
13 13
 
14
-Player::Player() : prio(0), nTracks(0), tempo(0), tempoCount(0), tempoRate(0), masterVol(0), sseq(NULL), sampleRate(0), interpolation(INTERPOLATION_NONE)
14
+Player::Player() : prio(0), nTracks(0), tempo(0), tempoCount(0), tempoRate(0), masterVol(0), sseq(nullptr), sampleRate(0), interpolation(INTERPOLATION_NONE)
15 15
 {
16 16
 	memset(this->trackIds, 0, sizeof(this->trackIds));
17 17
 	for (size_t i = 0; i < 16; ++i)
... ...
@@ -25,7 +25,7 @@ bool Player::Setup(const SSEQ *sseqToPlay)
25 25
 	int firstTrack = this->TrackAlloc();
26 26
 	if (firstTrack == -1)
27 27
 		return false;
28
-	this->tracks[firstTrack].Init(firstTrack, this, NULL, 0);
28
+	this->tracks[firstTrack].Init(firstTrack, this, nullptr, 0);
29 29
 
30 30
 	this->nTracks = 1;
31 31
 	this->trackIds[0] = firstTrack;
Browse code

Import actual code.

Naram Qashat authored on 2013/03/26 02:41:19
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,140 @@
1
+/*
2
+ * SSEQ Player - Player structure
3
+ * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
+ * Last modification on 2013-03-25
5
+ *
6
+ * Adapted from source code of FeOS Sound System
7
+ * By fincs
8
+ * https://github.com/fincs/FSS
9
+ */
10
+
11
+#include "Player.h"
12
+#include "common.h"
13
+
14
+Player::Player() : prio(0), nTracks(0), tempo(0), tempoCount(0), tempoRate(0), masterVol(0), sseq(NULL), sampleRate(0), interpolation(INTERPOLATION_NONE)
15
+{
16
+	memset(this->trackIds, 0, sizeof(this->trackIds));
17
+	for (size_t i = 0; i < 16; ++i)
18
+		this->channels[i].chnId = i;
19
+}
20
+
21
+bool Player::Setup(const SSEQ *sseqToPlay)
22
+{
23
+	this->sseq = sseqToPlay;
24
+
25
+	int firstTrack = this->TrackAlloc();
26
+	if (firstTrack == -1)
27
+		return false;
28
+	this->tracks[firstTrack].Init(firstTrack, this, NULL, 0);
29
+
30
+	this->nTracks = 1;
31
+	this->trackIds[0] = firstTrack;
32
+
33
+	auto pData = &this->sseq->data[0];
34
+	if (*pData == 0xFE)
35
+		for (pData += 3; *pData == 0x93; ) // Prepare extra tracks
36
+		{
37
+			++pData;
38
+			int tNum = read8(&pData);
39
+			auto pos = &this->sseq->data[read24(&pData)];
40
+			int newTrack = this->TrackAlloc();
41
+			if (newTrack == -1)
42
+				continue;
43
+			this->tracks[newTrack].Init(newTrack, this, pos, tNum);
44
+			this->trackIds[this->nTracks++] = newTrack;
45
+		}
46
+
47
+	this->tracks[firstTrack].startPos = this->tracks[firstTrack].pos = pData;
48
+
49
+	this->ClearState();
50
+
51
+	return true;
52
+}
53
+
54
+void Player::ClearState()
55
+{
56
+	this->tempo = 120;
57
+	this->tempoCount = 0;
58
+	this->tempoRate = 0x100;
59
+	this->masterVol = 0; // this is actually the highest level
60
+}
61
+
62
+int Player::ChannelAlloc(int type, int priority)
63
+{
64
+	static const uint8_t pcmChnArray[] = { 4, 5, 6, 7, 2, 0, 3, 1, 8, 9, 10, 11, 14, 12, 15, 13 };
65
+	static const uint8_t psgChnArray[] = { 13, 12, 11, 10, 9, 8 };
66
+	static const uint8_t noiseChnArray[] = { 15, 14 };
67
+	static const uint8_t arraySizes[] = { sizeof(pcmChnArray), sizeof(psgChnArray), sizeof(noiseChnArray) };
68
+	static const uint8_t *const arrayArray[] = { pcmChnArray, psgChnArray, noiseChnArray };
69
+
70
+	auto chnArray = arrayArray[type];
71
+	int arraySize = arraySizes[type];
72
+
73
+	int curChnNo = -1;
74
+	for (int i = 0; i < arraySize; ++i)
75
+	{
76
+		int thisChnNo = chnArray[i];
77
+		Channel &thisChn = this->channels[thisChnNo];
78
+		Channel &curChn = this->channels[curChnNo];
79
+		if (curChnNo != -1 && thisChn.prio >= curChn.prio)
80
+		{
81
+			if (thisChn.prio != curChn.prio)
82
+				continue;
83
+			if (curChn.vol <= thisChn.vol)
84
+				continue;
85
+		}
86
+		curChnNo = thisChnNo;
87
+	}
88
+
89
+	if (curChnNo == -1 || priority < this->channels[curChnNo].prio)
90
+		return -1;
91
+	this->channels[curChnNo].ply = this;
92
+	this->channels[curChnNo].noteLength = -1;
93
+	this->channels[curChnNo].vol = 0;
94
+	return curChnNo;
95
+}
96
+
97
+int Player::TrackAlloc()
98
+{
99
+	for (int i = 0; i < FSS_MAXTRACKS; ++i)
100
+	{
101
+		Track &thisTrk = this->tracks[i];
102
+		if (!thisTrk.state[TS_ALLOCBIT])
103
+		{
104
+			thisTrk.Zero();
105
+			thisTrk.state.set(TS_ALLOCBIT);
106
+			thisTrk.updateFlags.reset();
107
+			return i;
108
+		}
109
+	}
110
+	return -1;
111
+}
112
+
113
+void Player::Run()
114
+{
115
+	while (this->tempoCount > 240)
116
+	{
117
+		this->tempoCount -= 240;
118
+		for (uint8_t i = 0; i < this->nTracks; ++i)
119
+			this->tracks[this->trackIds[i]].Run();
120
+	}
121
+	this->tempoCount += (static_cast<int>(this->tempo) * static_cast<int>(this->tempoRate)) >> 8;
122
+}
123
+
124
+void Player::UpdateTracks()
125
+{
126
+	for (int i = 0; i < 16; ++i)
127
+		this->channels[i].UpdateTrack();
128
+	for (int i = 0; i < FSS_MAXTRACKS; ++i)
129
+		this->tracks[i].updateFlags.reset();
130
+}
131
+
132
+void Player::Timer()
133
+{
134
+	this->UpdateTracks();
135
+
136
+	for (int i = 0; i < 16; ++i)
137
+		this->channels[i].Update();
138
+
139
+	this->Run();
140
+}