Mercurial > hg > dmlib
annotate jssplr.c @ 219:b4eb9b59fef3
Fix envelope loops.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 07 Oct 2012 23:13:17 +0300 |
parents | c619c8b6f696 |
children | b0407a4c0a11 |
rev | line source |
---|---|
0 | 1 /* |
2 * miniJSS - Module playing routines | |
3 * Programmed and designed by Matti 'ccr' Hamalainen | |
142 | 4 * (C) Copyright 2006-2012 Tecnic Software productions (TNSP) |
0 | 5 */ |
6 #include "jssplr.h" | |
7 | |
8 // FIXME!! FIX ME! | |
9 #include <math.h> | |
10 | |
11 /* Miscellaneous tables | |
12 */ | |
13 #define jmpNSineTable (256) | |
14 static int *jmpSineTable = NULL; | |
15 | |
16 | |
17 static const Sint16 jmpXMAmigaPeriodTab[13 * 8] = { | |
18 907, 900, 894, 887, 881, 875, 868, 862, 856, 850, 844, 838, | |
19 832, 826, 820, 814, 808, 802, 796, 791, 785, 779, 774, 768, | |
20 762, 757, 752, 746, 741, 736, 730, 725, 720, 715, 709, 704, | |
21 699, 694, 689, 684, 678, 675, 670, 665, 660, 655, 651, 646, | |
22 640, 636, 632, 628, 623, 619, 614, 610, 604, 601, 597, 592, | |
23 588, 584, 580, 575, 570, 567, 563, 559, 555, 551, 547, 543, | |
24 538, 535, 532, 528, 524, 520, 516, 513, 508, 505, 502, 498, | |
25 494, 491, 487, 484, 480, 477, 474, 470, 467, 463, 460, 457, | |
26 | |
27 453, 450, 447, 443, 440, 437, 434, 431 | |
28 }; | |
29 | |
30 | |
31 #define jmpNMODEffectTable (36) | |
32 static const char jmpMODEffectTable[jmpNMODEffectTable] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | |
33 | |
34 | |
35 /* Helper functions | |
36 */ | |
136 | 37 static int jmpNoteToAmigaPeriod(int note, int finetune) |
0 | 38 { |
154 | 39 int tmp = dmClamp(note + finetune + 8, 0, 103); |
0 | 40 return jmpXMAmigaPeriodTab[tmp]; |
41 } | |
42 | |
43 | |
44 static int jmpGetPeriodFromNote(JSSPlayer *mp, int note, int finetune) | |
45 { | |
46 int res; | |
47 | |
48 if (JMPGETMODFLAGS(mp, jmdfAmigaPeriods)) | |
49 { | |
50 int mfinetune = finetune / 16, | |
51 mnote = (note % 12) * 8, | |
52 moctave = note / 12, | |
53 period1, period2; | |
54 | |
55 period1 = jmpNoteToAmigaPeriod(mnote, mfinetune); | |
56 | |
57 if (finetune < 0) | |
58 { | |
59 mfinetune--; | |
60 finetune = -finetune; | |
61 } else | |
62 mfinetune++; | |
63 | |
64 period2 = jmpNoteToAmigaPeriod(mnote, mfinetune); | |
65 | |
66 mfinetune = finetune & 15; | |
67 period1 *= (16 - mfinetune); | |
68 period2 *= mfinetune; | |
69 | |
70 res = ((period1 + period2) * 2) >> moctave; | |
71 | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
72 //fprintf(stderr, "jmpGetAmigaPeriod(%d, %d) = %d\n", note, finetune, res); |
0 | 73 } |
74 else | |
75 { | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
76 //fprintf(stderr, "jmpGetLinearPeriod(%d, %d) = %d\n", note, finetune, res); |
0 | 77 //res = ((120 - note) << 6) - (finetune / 2); |
78 res = 7680 - (note * 64) - (finetune / 2); | |
79 if (res < 1) res = 1; | |
80 } | |
81 | |
82 return res; | |
83 } | |
84 | |
85 | |
193
b778cc2fe7c8
Create a separate new frequency flag (vs. new pitch), for future changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
86 static void jmpCSetPitch(JSSPlayer *mp, JSSPlayerChannel *chn, int value) |
0 | 87 { |
88 if (value > 0) | |
89 { | |
90 if (JMPGETMODFLAGS(mp, jmdfAmigaPeriods)) | |
91 { | |
92 // Frequency = 8363*1712 / Period | |
193
b778cc2fe7c8
Create a separate new frequency flag (vs. new pitch), for future changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
93 chn->cfreq = chn->freq = 14317456 / value; |
0 | 94 } |
95 else | |
96 { | |
97 // Frequency = Frequency = 8363*2^((6*12*16*4 - Period) / (12*16*4)) | |
193
b778cc2fe7c8
Create a separate new frequency flag (vs. new pitch), for future changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
98 chn->cfreq = chn->freq = 8363.0f * pow(2.0f, (4608.0f - (double) value) / 768.0f); |
0 | 99 } |
218 | 100 |
101 JMPSETNDFLAGS(cdfNewFreq); | |
0 | 102 } |
103 } | |
104 | |
105 | |
144
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
106 static void jmpCSetVolume(JSSPlayer * mp, JSSPlayerChannel *chn, int channel, int volume, int init) |
0 | 107 { |
108 assert(mp != NULL); | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
109 assert(mp->device != NULL); |
0 | 110 |
154 | 111 volume = dmClamp(volume, mpMinVol, mpMaxVol); |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
112 |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
113 //fprintf(stderr, "chn %d: vol=%d, fad=%d, env=%d\n", channel, volume, chn->fadeOutVol, chn->volumeEnv.value); |
157 | 114 |
188
47c327fb321a
Another cleanup, remove the "future player" data prediction hack, it is not needed.
Matti Hamalainen <ccr@tnsp.org>
parents:
187
diff
changeset
|
115 jvmSetVolumeRamp(mp->device, channel, |
47c327fb321a
Another cleanup, remove the "future player" data prediction hack, it is not needed.
Matti Hamalainen <ccr@tnsp.org>
parents:
187
diff
changeset
|
116 init ? 0 : jvmGetVolume(mp->device, channel), |
47c327fb321a
Another cleanup, remove the "future player" data prediction hack, it is not needed.
Matti Hamalainen <ccr@tnsp.org>
parents:
187
diff
changeset
|
117 (chn->fadeOutVol * chn->volumeEnv.value * volume) / (16 * 65536), |
47c327fb321a
Another cleanup, remove the "future player" data prediction hack, it is not needed.
Matti Hamalainen <ccr@tnsp.org>
parents:
187
diff
changeset
|
118 init ? 5 : 0); |
0 | 119 } |
120 | |
121 | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
122 static void jmpCSetPanning(JSSPlayer * mp, JSSPlayerChannel *chn, int channel, int panning) |
0 | 123 { |
124 assert(mp != NULL); | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
125 assert(mp->device != NULL); |
0 | 126 |
188
47c327fb321a
Another cleanup, remove the "future player" data prediction hack, it is not needed.
Matti Hamalainen <ccr@tnsp.org>
parents:
187
diff
changeset
|
127 jvmSetPanRamp(mp->device, channel, |
47c327fb321a
Another cleanup, remove the "future player" data prediction hack, it is not needed.
Matti Hamalainen <ccr@tnsp.org>
parents:
187
diff
changeset
|
128 jvmGetPan(mp->device, channel), |
47c327fb321a
Another cleanup, remove the "future player" data prediction hack, it is not needed.
Matti Hamalainen <ccr@tnsp.org>
parents:
187
diff
changeset
|
129 panning + (((chn->panningEnv.value - 32) * (128 - abs(panning - 128))) / 32), |
47c327fb321a
Another cleanup, remove the "future player" data prediction hack, it is not needed.
Matti Hamalainen <ccr@tnsp.org>
parents:
187
diff
changeset
|
130 0); |
0 | 131 } |
132 | |
133 | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
134 static BOOL jmpExecEnvelope(JSSEnvelope *env, JSSPlayerEnvelope *pe, BOOL keyOff) |
0 | 135 { |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
136 int point = 0; |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
137 |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
138 if (!pe->exec) |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
139 return FALSE; |
0 | 140 |
189 | 141 // Find current point, if not last point |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
142 while (point < env->npoints - 1) |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
143 { |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
144 if (pe->frame >= env->points[point + 1].frame) |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
145 point++; |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
146 else |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
147 break; |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
148 } |
189 | 149 |
219 | 150 if (env->flags & jenvfLooped && pe->frame >= env->points[env->loopE].frame) |
151 { | |
152 point = env->loopS; | |
153 pe->frame = env->points[env->loopS].frame; | |
154 pe->value = env->points[point].value; | |
155 } | |
156 | |
189 | 157 // Check for last point |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
158 if (pe->frame >= env->points[env->npoints - 1].frame) |
0 | 159 { |
219 | 160 point = env->npoints - 1; |
161 pe->exec = FALSE; | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
162 pe->value = env->points[point].value; |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
163 } |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
164 else |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
165 { |
189 | 166 // Linearly interpolate the value between current and next point |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
167 JSSEnvelopePoint |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
168 *ep1 = &env->points[point], |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
169 *ep2 = &env->points[point + 1]; |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
170 |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
171 int delta = ep2->frame - ep1->frame; |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
172 if (delta > 0) |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
173 pe->value = ep1->value + ((ep2->value - ep1->value) * (pe->frame - ep1->frame)) / delta; |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
174 else |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
175 pe->value = ep1->value; |
0 | 176 } |
177 | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
178 if (pe->exec) |
0 | 179 { |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
180 // The frame counter IS processed even if the envelope is not! |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
181 if ((env->flags & jenvfSustain) && point == env->sustain && |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
182 env->points[point].frame == env->points[env->sustain].frame) |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
183 { |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
184 if (keyOff) |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
185 pe->frame++; |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
186 } else |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
187 pe->frame++; |
0 | 188 } |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
189 |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
190 return TRUE; |
0 | 191 } |
192 | |
193 | |
61
a33e47232161
Silence some "unused parameter" warnings.
Matti Hamalainen <ccr@tnsp.org>
parents:
55
diff
changeset
|
194 static void jmpProcessExtInstrument(JSSPlayerChannel *chn, int channel) |
0 | 195 { |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
196 JSSExtInstrument *inst = chn->extInstrument; |
61
a33e47232161
Silence some "unused parameter" warnings.
Matti Hamalainen <ccr@tnsp.org>
parents:
55
diff
changeset
|
197 (void) channel; |
0 | 198 |
199 // Get the instrument for envelope data | |
200 if (!inst) return; | |
201 | |
202 // Process the autovibrato | |
203 /* | |
204 FIXME fix me FIX me!!! todo. | |
205 */ | |
206 | |
207 if (inst->volumeEnv.flags & jenvfUsed) | |
208 { | |
169
13f27b9882bc
Backed out changeset 21f54947eb18. No, it isn't. :(
Matti Hamalainen <ccr@tnsp.org>
parents:
168
diff
changeset
|
209 // Process the instrument volume fadeout |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
210 if (chn->keyOff && chn->fadeOutVol > 0 && inst->fadeOut > 0) |
169
13f27b9882bc
Backed out changeset 21f54947eb18. No, it isn't. :(
Matti Hamalainen <ccr@tnsp.org>
parents:
168
diff
changeset
|
211 { |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
212 int tmp = chn->fadeOutVol - inst->fadeOut; |
169
13f27b9882bc
Backed out changeset 21f54947eb18. No, it isn't. :(
Matti Hamalainen <ccr@tnsp.org>
parents:
168
diff
changeset
|
213 if (tmp < 0) tmp = 0; |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
214 chn->fadeOutVol = tmp; |
169
13f27b9882bc
Backed out changeset 21f54947eb18. No, it isn't. :(
Matti Hamalainen <ccr@tnsp.org>
parents:
168
diff
changeset
|
215 |
13f27b9882bc
Backed out changeset 21f54947eb18. No, it isn't. :(
Matti Hamalainen <ccr@tnsp.org>
parents:
168
diff
changeset
|
216 JMPSETNDFLAGS(cdfNewVolume); |
13f27b9882bc
Backed out changeset 21f54947eb18. No, it isn't. :(
Matti Hamalainen <ccr@tnsp.org>
parents:
168
diff
changeset
|
217 } |
13f27b9882bc
Backed out changeset 21f54947eb18. No, it isn't. :(
Matti Hamalainen <ccr@tnsp.org>
parents:
168
diff
changeset
|
218 |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
219 // Execute the volume envelope |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
220 if (jmpExecEnvelope(&inst->volumeEnv, &chn->volumeEnv, chn->keyOff)) |
0 | 221 JMPSETNDFLAGS(cdfNewVolume); |
222 } | |
223 else | |
224 { | |
225 // If the envelope is not used, set max volume | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
226 chn->volumeEnv.value = mpMaxVol; |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
227 chn->fadeOutVol = chn->keyOff ? 0 : mpMaxFadeoutVol; |
174
520c18f581c7
Fix handling of fadeouts when volume envelope is not enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
228 JMPSETNDFLAGS(cdfNewVolume); |
0 | 229 } |
230 | |
231 if (inst->panningEnv.flags & jenvfUsed) | |
232 { | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
233 // Process the panning envelope |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
234 if (jmpExecEnvelope(&inst->panningEnv, &chn->panningEnv, chn->keyOff)) |
0 | 235 JMPSETNDFLAGS(cdfNewPanPos); |
236 } | |
237 else | |
238 { | |
239 // If the envelope is not used, set center panning | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
240 if (chn->panningEnv.value != mpPanCenter) |
0 | 241 { |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
242 chn->panningEnv.value = mpPanCenter; |
0 | 243 JMPSETNDFLAGS(cdfNewPanPos); |
244 } | |
245 } | |
246 } | |
247 | |
248 | |
249 /* | |
250 * The player | |
251 */ | |
252 JSSPlayer *jmpInit(JSSMixer *pDevice) | |
253 { | |
254 JSSPlayer *mp; | |
255 | |
256 // Initialize global tables | |
257 if (jmpSineTable == NULL) | |
258 { | |
259 int i; | |
260 if ((jmpSineTable = dmMalloc(jmpNSineTable * sizeof(int))) == NULL) | |
261 JSSERROR(DMERR_MALLOC, NULL, "Could not allocate memory for sinus table.\n"); | |
262 | |
263 for (i = 0; i < 256; i++) | |
264 { | |
265 float f = ((float) i * M_PI * 2.0f) / 256.0f; | |
266 jmpSineTable[i] = (int) (sin(f) * 2048.0f); | |
267 } | |
268 } | |
269 | |
270 // Allocate a player structure | |
271 mp = dmMalloc0(sizeof(JSSPlayer)); | |
144
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
272 if (mp == NULL) |
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
273 JSSERROR(DMERR_MALLOC, NULL, "Could not allocate memory for player structure.\n"); |
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
274 |
0 | 275 // Set variables |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
276 mp->device = pDevice; |
144
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
277 |
0 | 278 #ifdef JSS_SUP_THREADS |
279 mp->mutex = dmCreateMutex(); | |
280 #endif | |
281 | |
282 return mp; | |
283 } | |
284 | |
285 | |
286 int jmpClose(JSSPlayer * mp) | |
287 { | |
288 if (mp == NULL) | |
289 return DMERR_NULLPTR; | |
290 | |
291 // Stop player | |
292 jmpStop(mp); | |
293 | |
294 // Deallocate resources | |
295 #ifdef JSS_SUP_THREADS | |
296 dmDestroyMutex(mp->mutex); | |
297 #endif | |
298 | |
299 // Clear structure | |
300 memset(mp, 0, sizeof(JSSPlayer)); | |
301 dmFree(mp); | |
302 | |
303 return DMERR_OK; | |
304 } | |
305 | |
306 | |
307 /* Reset the envelopes for given channel. | |
308 */ | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
309 static void jmpResetEnvelope(JSSPlayerEnvelope *env) |
0 | 310 { |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
311 env->frame = env->value = 0; |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
312 env->exec = TRUE; |
0 | 313 } |
314 | |
315 | |
316 /* Clear module player structure | |
317 */ | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
318 void jmpClearChannel(JSSPlayerChannel *chn) |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
319 { |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
320 memset(chn, 0, sizeof(JSSPlayerChannel)); |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
321 |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
322 chn->note = jsetNotSet; |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
323 chn->ninstrument = jsetNotSet; |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
324 chn->nextInstrument = jsetNotSet; |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
325 chn->panning = mpPanCenter; |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
326 chn->panningEnv.value = mpPanCenter; |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
327 } |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
328 |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
329 |
0 | 330 void jmpClearPlayer(JSSPlayer * mp) |
331 { | |
332 int i; | |
333 assert(mp != NULL); | |
334 JSS_LOCK(mp); | |
335 | |
336 // Initialize general variables | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
337 mp->patternDelay = 0; |
170 | 338 mp->newRowSet = FALSE; |
339 mp->newOrderSet = FALSE; | |
340 mp->tick = jsetNotSet; | |
341 mp->row = 0; | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
342 mp->lastPatLoopRow = 0; |
0 | 343 |
344 // Initialize channel data | |
345 for (i = 0; i < jsetNChannels; i++) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
346 jmpClearChannel(&mp->channels[i]); |
0 | 347 |
348 JSS_UNLOCK(mp); | |
349 } | |
350 | |
351 | |
352 /* Set module | |
353 */ | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
354 void jmpSetModule(JSSPlayer * mp, JSSModule * module) |
0 | 355 { |
356 assert(mp != NULL); | |
357 JSS_LOCK(mp); | |
358 | |
359 jmpStop(mp); | |
360 jmpClearPlayer(mp); | |
361 | |
188
47c327fb321a
Another cleanup, remove the "future player" data prediction hack, it is not needed.
Matti Hamalainen <ccr@tnsp.org>
parents:
187
diff
changeset
|
362 mp->module = module; |
0 | 363 |
364 JSS_UNLOCK(mp); | |
365 } | |
366 | |
367 | |
368 /* Stop playing | |
369 */ | |
370 void jmpStop(JSSPlayer * mp) | |
371 { | |
372 assert(mp != NULL); | |
373 JSS_LOCK(mp); | |
374 | |
375 if (mp->isPlaying) | |
376 { | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
377 jvmRemoveCallback(mp->device); |
0 | 378 mp->isPlaying = FALSE; |
379 } | |
380 | |
381 JSS_UNLOCK(mp); | |
382 } | |
383 | |
384 | |
385 /* Resume playing | |
386 */ | |
387 void jmpResume(JSSPlayer * mp) | |
388 { | |
389 assert(mp != NULL); | |
390 JSS_LOCK(mp); | |
391 | |
392 if (!mp->isPlaying) | |
393 { | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
394 int result = jvmSetCallback(mp->device, jmpExec, (void *) mp); |
0 | 395 if (result != DMERR_OK) |
396 JSSERROR(result,, "Could not initialize callback for player.\n"); | |
397 | |
398 mp->isPlaying = TRUE; | |
399 } | |
400 | |
401 JSS_UNLOCK(mp); | |
402 } | |
403 | |
404 | |
405 /* Sets new order using given value as reference. | |
406 * Jumps over skip-points and invalid values, loops | |
407 * to first order if enabled. | |
408 */ | |
409 static void jmpSetNewOrder(JSSPlayer * mp, int order) | |
410 { | |
411 BOOL orderOK; | |
412 int pattern; | |
413 | |
414 pattern = jsetOrderEnd; | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
415 mp->order = jsetNotSet; |
0 | 416 orderOK = FALSE; |
417 | |
418 while (!orderOK) | |
419 { | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
420 if (order < 0 || order >= mp->module->norders) |
0 | 421 { |
422 jmpStop(mp); | |
423 orderOK = TRUE; | |
424 } | |
425 else | |
426 { | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
427 pattern = mp->module->orderList[order]; |
0 | 428 if (pattern == jsetOrderSkip) |
429 { | |
430 order++; | |
431 } | |
432 else | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
433 if (pattern >= mp->module->npatterns || pattern == jsetOrderEnd) |
0 | 434 { |
435 jmpStop(mp); | |
436 orderOK = TRUE; | |
437 } | |
438 else | |
439 { | |
440 // All OK | |
441 orderOK = TRUE; | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
442 mp->pattern = mp->module->patterns[pattern]; |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
443 mp->npattern = pattern; |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
444 mp->order = order; |
0 | 445 } |
446 } | |
447 } | |
448 } | |
449 | |
450 | |
451 /* Set new tempo-value of the player. | |
452 */ | |
136 | 453 static void jmpSetTempo(JSSPlayer * mp, int tempo) |
0 | 454 { |
455 assert(mp != NULL); | |
456 JSS_LOCK(mp); | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
457 assert(mp->device != NULL); |
0 | 458 |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
459 mp->tempo = tempo; |
186
dc22e3f77c9a
Fix tempo (callback frequency) calculation.
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
460 jvmSetCallbackFreq(mp->device, (mp->device->outFreq * 5) / (tempo * 2)); |
0 | 461 JSS_UNLOCK(mp); |
462 } | |
463 | |
464 | |
136 | 465 static void jmpClearChannels(JSSPlayer * mp) |
0 | 466 { |
467 int i; | |
468 assert(mp != NULL); | |
469 JSS_LOCK(mp); | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
470 assert(mp->device != NULL); |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
471 assert(mp->module != NULL); |
0 | 472 |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
473 for (i = 0; i < mp->module->nchannels; i++) |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
474 jvmStop(mp->device, i); |
0 | 475 |
172
cfb087000db3
Clear player channel data as well in here.
Matti Hamalainen <ccr@tnsp.org>
parents:
171
diff
changeset
|
476 // Initialize channel data |
cfb087000db3
Clear player channel data as well in here.
Matti Hamalainen <ccr@tnsp.org>
parents:
171
diff
changeset
|
477 for (i = 0; i < jsetNChannels; i++) |
cfb087000db3
Clear player channel data as well in here.
Matti Hamalainen <ccr@tnsp.org>
parents:
171
diff
changeset
|
478 jmpClearChannel(&mp->channels[i]); |
cfb087000db3
Clear player channel data as well in here.
Matti Hamalainen <ccr@tnsp.org>
parents:
171
diff
changeset
|
479 |
0 | 480 JSS_UNLOCK(mp); |
481 } | |
482 | |
483 | |
484 /* Starts playing module from a given ORDER. | |
485 */ | |
181
879b2488340a
Clean up player logic some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
486 static int jmpPlayStart(JSSPlayer *mp) |
879b2488340a
Clean up player logic some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
487 { |
879b2488340a
Clean up player logic some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
488 int result; |
879b2488340a
Clean up player logic some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
489 |
879b2488340a
Clean up player logic some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
490 mp->speed = mp->module->defSpeed; |
879b2488340a
Clean up player logic some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
491 jmpSetTempo(mp, mp->module->defTempo); |
879b2488340a
Clean up player logic some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
492 |
879b2488340a
Clean up player logic some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
493 result = jvmSetCallback(mp->device, jmpExec, (void *) mp); |
879b2488340a
Clean up player logic some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
494 if (result != DMERR_OK) |
879b2488340a
Clean up player logic some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
495 { |
879b2488340a
Clean up player logic some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
496 JSSERROR(result, result, "Could not initialize callback for player.\n"); |
879b2488340a
Clean up player logic some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
497 } |
879b2488340a
Clean up player logic some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
498 |
879b2488340a
Clean up player logic some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
499 mp->isPlaying = TRUE; |
879b2488340a
Clean up player logic some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
500 return DMERR_OK; |
879b2488340a
Clean up player logic some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
501 } |
879b2488340a
Clean up player logic some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
502 |
879b2488340a
Clean up player logic some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
503 |
182
9024d249e47a
Add a new function jmpChangeOrder() to change orderlist position "on fly",
Matti Hamalainen <ccr@tnsp.org>
parents:
181
diff
changeset
|
504 int jmpChangeOrder(JSSPlayer *mp, int order) |
9024d249e47a
Add a new function jmpChangeOrder() to change orderlist position "on fly",
Matti Hamalainen <ccr@tnsp.org>
parents:
181
diff
changeset
|
505 { |
9024d249e47a
Add a new function jmpChangeOrder() to change orderlist position "on fly",
Matti Hamalainen <ccr@tnsp.org>
parents:
181
diff
changeset
|
506 assert(mp != NULL); |
9024d249e47a
Add a new function jmpChangeOrder() to change orderlist position "on fly",
Matti Hamalainen <ccr@tnsp.org>
parents:
181
diff
changeset
|
507 |
9024d249e47a
Add a new function jmpChangeOrder() to change orderlist position "on fly",
Matti Hamalainen <ccr@tnsp.org>
parents:
181
diff
changeset
|
508 JSS_LOCK(mp); |
9024d249e47a
Add a new function jmpChangeOrder() to change orderlist position "on fly",
Matti Hamalainen <ccr@tnsp.org>
parents:
181
diff
changeset
|
509 assert(mp->module != NULL); |
9024d249e47a
Add a new function jmpChangeOrder() to change orderlist position "on fly",
Matti Hamalainen <ccr@tnsp.org>
parents:
181
diff
changeset
|
510 |
9024d249e47a
Add a new function jmpChangeOrder() to change orderlist position "on fly",
Matti Hamalainen <ccr@tnsp.org>
parents:
181
diff
changeset
|
511 jmpClearChannels(mp); |
9024d249e47a
Add a new function jmpChangeOrder() to change orderlist position "on fly",
Matti Hamalainen <ccr@tnsp.org>
parents:
181
diff
changeset
|
512 jmpClearPlayer(mp); |
9024d249e47a
Add a new function jmpChangeOrder() to change orderlist position "on fly",
Matti Hamalainen <ccr@tnsp.org>
parents:
181
diff
changeset
|
513 |
9024d249e47a
Add a new function jmpChangeOrder() to change orderlist position "on fly",
Matti Hamalainen <ccr@tnsp.org>
parents:
181
diff
changeset
|
514 jmpSetNewOrder(mp, order); |
9024d249e47a
Add a new function jmpChangeOrder() to change orderlist position "on fly",
Matti Hamalainen <ccr@tnsp.org>
parents:
181
diff
changeset
|
515 if (mp->order == jsetNotSet) |
9024d249e47a
Add a new function jmpChangeOrder() to change orderlist position "on fly",
Matti Hamalainen <ccr@tnsp.org>
parents:
181
diff
changeset
|
516 { |
9024d249e47a
Add a new function jmpChangeOrder() to change orderlist position "on fly",
Matti Hamalainen <ccr@tnsp.org>
parents:
181
diff
changeset
|
517 JSS_UNLOCK(mp); |
9024d249e47a
Add a new function jmpChangeOrder() to change orderlist position "on fly",
Matti Hamalainen <ccr@tnsp.org>
parents:
181
diff
changeset
|
518 JSSERROR(DMERR_NOT_SUPPORTED, DMERR_NOT_SUPPORTED, |
9024d249e47a
Add a new function jmpChangeOrder() to change orderlist position "on fly",
Matti Hamalainen <ccr@tnsp.org>
parents:
181
diff
changeset
|
519 "Could not start playing from given order #%i\n", order); |
9024d249e47a
Add a new function jmpChangeOrder() to change orderlist position "on fly",
Matti Hamalainen <ccr@tnsp.org>
parents:
181
diff
changeset
|
520 } |
9024d249e47a
Add a new function jmpChangeOrder() to change orderlist position "on fly",
Matti Hamalainen <ccr@tnsp.org>
parents:
181
diff
changeset
|
521 |
9024d249e47a
Add a new function jmpChangeOrder() to change orderlist position "on fly",
Matti Hamalainen <ccr@tnsp.org>
parents:
181
diff
changeset
|
522 JSS_UNLOCK(mp); |
9024d249e47a
Add a new function jmpChangeOrder() to change orderlist position "on fly",
Matti Hamalainen <ccr@tnsp.org>
parents:
181
diff
changeset
|
523 return DMERR_OK; |
9024d249e47a
Add a new function jmpChangeOrder() to change orderlist position "on fly",
Matti Hamalainen <ccr@tnsp.org>
parents:
181
diff
changeset
|
524 } |
9024d249e47a
Add a new function jmpChangeOrder() to change orderlist position "on fly",
Matti Hamalainen <ccr@tnsp.org>
parents:
181
diff
changeset
|
525 |
9024d249e47a
Add a new function jmpChangeOrder() to change orderlist position "on fly",
Matti Hamalainen <ccr@tnsp.org>
parents:
181
diff
changeset
|
526 |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
527 int jmpPlayOrder(JSSPlayer * mp, int order) |
0 | 528 { |
529 int result; | |
530 assert(mp != NULL); | |
531 | |
532 JSS_LOCK(mp); | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
533 assert(mp->module != NULL); |
0 | 534 |
535 // Stop if already playing | |
536 jmpStop(mp); | |
537 jmpClearChannels(mp); | |
181
879b2488340a
Clean up player logic some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
538 jmpClearPlayer(mp); |
0 | 539 |
540 // Check starting order | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
541 jmpSetNewOrder(mp, order); |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
542 if (mp->order == jsetNotSet) |
0 | 543 { |
544 JSS_UNLOCK(mp); | |
545 JSSERROR(DMERR_NOT_SUPPORTED, DMERR_NOT_SUPPORTED, | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
546 "Could not start playing from given order #%i\n", order); |
0 | 547 } |
548 | |
181
879b2488340a
Clean up player logic some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
549 if ((result = jmpPlayStart(mp)) != DMERR_OK) |
0 | 550 { |
551 JSS_UNLOCK(mp); | |
181
879b2488340a
Clean up player logic some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
552 return result; |
0 | 553 } |
554 | |
555 JSS_UNLOCK(mp); | |
181
879b2488340a
Clean up player logic some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
556 return DMERR_OK; |
0 | 557 } |
558 | |
559 | |
560 /* Play given pattern | |
561 */ | |
562 int jmpPlayPattern(JSSPlayer * mp, int pattern) | |
563 { | |
564 int result; | |
565 assert(mp != NULL); | |
566 JSS_LOCK(mp); | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
567 assert(mp->module != NULL); |
0 | 568 |
569 // Stop if already playing | |
570 jmpStop(mp); | |
571 jmpClearPlayer(mp); | |
572 | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
573 mp->npattern = pattern; |
0 | 574 |
181
879b2488340a
Clean up player logic some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
575 if ((result = jmpPlayStart(mp)) != DMERR_OK) |
0 | 576 { |
577 JSS_UNLOCK(mp); | |
181
879b2488340a
Clean up player logic some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
578 return result; |
0 | 579 } |
580 | |
581 JSS_UNLOCK(mp); | |
181
879b2488340a
Clean up player logic some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
582 return DMERR_OK; |
0 | 583 } |
584 | |
585 | |
586 /* Set volume for given module channel. | |
587 */ | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
588 static void jmpSetVolume(JSSPlayerChannel * chn, int channel, int volume) |
0 | 589 { |
61
a33e47232161
Silence some "unused parameter" warnings.
Matti Hamalainen <ccr@tnsp.org>
parents:
55
diff
changeset
|
590 (void) channel; |
a33e47232161
Silence some "unused parameter" warnings.
Matti Hamalainen <ccr@tnsp.org>
parents:
55
diff
changeset
|
591 |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
592 chn->volume = dmClamp(volume, mpMinVol, mpMaxVol); |
0 | 593 JMPSETNDFLAGS(cdfNewVolume); |
594 } | |
595 | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
596 #define jmpChangeVolume(Q, Z, X) jmpSetVolume(Q, Z, chn->volume + (X)) |
0 | 597 |
598 | |
599 /* Change the pitch of given channel by ADelta. | |
600 */ | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
601 static void jmpChangePitch(JSSPlayerChannel *chn, int channel, int delta) |
0 | 602 { |
603 int value; | |
61
a33e47232161
Silence some "unused parameter" warnings.
Matti Hamalainen <ccr@tnsp.org>
parents:
55
diff
changeset
|
604 (void) channel; |
0 | 605 |
606 // Calculate new pitch and check it | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
607 value = chn->pitch + delta; |
0 | 608 if (value < 0) |
609 value = 0; | |
610 | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
611 chn->pitch = value; |
0 | 612 JMPSETNDFLAGS(cdfNewPitch); |
613 } | |
614 | |
615 | |
616 /* Do a note portamento (pitch slide) effect for given module channel. | |
617 */ | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
618 static void jmpDoPortamento(JSSPlayerChannel * chn, int channel) |
0 | 619 { |
61
a33e47232161
Silence some "unused parameter" warnings.
Matti Hamalainen <ccr@tnsp.org>
parents:
55
diff
changeset
|
620 (void) channel; |
a33e47232161
Silence some "unused parameter" warnings.
Matti Hamalainen <ccr@tnsp.org>
parents:
55
diff
changeset
|
621 |
0 | 622 // Check for zero parameter |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
623 if (chn->iLastPortaToNoteParam == 0) |
0 | 624 { |
625 JMPSETNDFLAGS(cdfNewPitch); | |
626 return; | |
627 } | |
628 | |
629 /* Slide the pitch of channel to the destination value | |
630 * with speed of iLastPortaToNoteParam[] * 4 and stop when it equals. | |
631 */ | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
632 if (chn->pitch < chn->iLastPortaToNotePitch) |
0 | 633 { |
175 | 634 // Increase pitch UP |
635 jmpChangePitch(chn, channel, chn->iLastPortaToNoteParam * 4); | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
636 if (chn->pitch > chn->iLastPortaToNotePitch) |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
637 chn->pitch = chn->iLastPortaToNotePitch; |
175 | 638 } |
639 else | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
640 if (chn->pitch > chn->iLastPortaToNotePitch) |
175 | 641 { |
642 // Decrease pitch DOWN | |
643 jmpChangePitch(chn, channel, -(chn->iLastPortaToNoteParam * 4)); | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
644 if (chn->pitch < chn->iLastPortaToNotePitch) |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
645 chn->pitch = chn->iLastPortaToNotePitch; |
0 | 646 } |
647 } | |
648 | |
649 | |
650 /* Do a tremolo effect for given module channel. | |
651 */ | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
652 static void jmpDoTremolo(JSSPlayer * mp, JSSPlayerChannel *chn, int channel) |
0 | 653 { |
654 int delta, pos, depth; | |
655 | |
656 // Check settings | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
657 if (chn->tremolo.depth == 0 || chn->tremolo.speed == 0) |
0 | 658 return; |
659 | |
660 // Get position of tremolo waveform | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
661 pos = chn->tremolo.pos & 255; |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
662 depth = chn->tremolo.depth; |
0 | 663 |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
664 switch (chn->tremolo.wc & 3) |
0 | 665 { |
666 case 0: // Sine-wave | |
667 delta = (jmpSineTable[pos] * depth) / 2048; | |
668 break; | |
669 | |
670 case 1: // Ramp down | |
671 delta = ((pos - 128) * depth) / 128; | |
672 break; | |
673 | |
674 case 2: // Square | |
675 delta = (((pos & 128) - 64) * depth) / 64; | |
676 break; | |
677 | |
678 default: | |
679 return; | |
680 } | |
681 | |
682 // Set the new volume | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
683 jmpCSetVolume(mp, chn, channel, chn->volume + delta, FALSE); |
0 | 684 |
685 // Advance tremolo waveform position | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
686 chn->tremolo.pos += chn->tremolo.speed; |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
687 if (chn->tremolo.pos > 255) |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
688 chn->tremolo.pos = 0; |
0 | 689 } |
690 | |
691 | |
692 /* Do a vibrato effect for given module channel. | |
693 */ | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
694 static void jmpDoVibrato(JSSPlayer * mp, JSSPlayerChannel *chn, int channel) |
0 | 695 { |
696 int delta, pos, depth; | |
697 | |
698 // Check settings | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
699 if (chn->vibrato.depth == 0 || chn->vibrato.speed == 0) |
0 | 700 return; |
701 | |
702 // Get position of vibrato waveform | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
703 pos = chn->vibrato.pos & 255; |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
704 depth = chn->vibrato.depth; |
0 | 705 |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
706 switch (chn->vibrato.wc & 3) |
0 | 707 { |
708 case 0: // Sine-wave | |
709 delta = (jmpSineTable[pos] * depth) / 2048; | |
710 break; | |
711 | |
712 case 1: // Ramp down | |
713 delta = ((pos - 128) * depth) / 16; | |
714 break; | |
715 | |
716 case 2: // Square | |
717 delta = (((pos & 128) - 64) * depth) / 8; | |
718 break; | |
719 | |
720 default: | |
721 return; | |
722 } | |
723 | |
724 // Set the new frequency | |
210 | 725 jmpCSetPitch(mp, chn, chn->pitch + delta); |
0 | 726 |
727 // Advance vibrato waveform position | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
728 chn->vibrato.pos += chn->vibrato.speed; |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
729 if (chn->vibrato.pos > 255) |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
730 chn->vibrato.pos = 0; |
0 | 731 } |
732 | |
733 | |
734 /* Do a volume slide effect for given module channel. | |
735 */ | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
736 static void jmpDoVolumeSlide(JSSPlayerChannel * chn, int channel, int param) |
0 | 737 { |
738 int paramX, paramY; | |
739 | |
740 JMPMAKEPARAM(param, paramX, paramY) | |
741 | |
742 if (paramY == 0) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
743 jmpChangeVolume(chn, channel, paramX); |
0 | 744 if (paramX == 0) |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
745 jmpChangeVolume(chn, channel, -paramY); |
0 | 746 } |
747 | |
748 | |
749 /* Execute a pattern loop effect/command for given module channel. | |
750 * | |
751 * This routine works for most of the supported formats, as they | |
752 * use the 'standard' implementation ascending from MOD. However, | |
753 * here is included also a slightly kludgy implementation of the | |
754 * FT2 patloop bug. | |
755 */ | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
756 static void jmpDoPatternLoop(JSSPlayer * mp, JSSPlayerChannel *chn, int channel, int paramY) |
0 | 757 { |
61
a33e47232161
Silence some "unused parameter" warnings.
Matti Hamalainen <ccr@tnsp.org>
parents:
55
diff
changeset
|
758 (void) channel; |
a33e47232161
Silence some "unused parameter" warnings.
Matti Hamalainen <ccr@tnsp.org>
parents:
55
diff
changeset
|
759 |
0 | 760 // Check what we need to do |
761 if (paramY > 0) | |
762 { | |
763 // SBx/E6x loops 'x' times | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
764 if (chn->iPatLoopCount == 1) |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
765 chn->iPatLoopCount = 0; |
0 | 766 else |
767 { | |
768 // Check if we need to set the count | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
769 if (chn->iPatLoopCount == 0) |
175 | 770 chn->iPatLoopCount = paramY + 1; |
0 | 771 |
772 // Loop to specified row | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
773 chn->iPatLoopCount--; |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
774 mp->newRow = chn->iPatLoopRow; |
0 | 775 mp->newRowSet = TRUE; |
776 } | |
777 } | |
778 else | |
779 { | |
780 // SB0/E60 sets the loop start point | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
781 chn->iPatLoopRow = mp->row; |
0 | 782 |
783 // This is here because of the infamous FT2 patloop bug | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
784 mp->lastPatLoopRow = mp->row; |
0 | 785 } |
786 } | |
787 | |
788 | |
789 /* Do arpeggio effect | |
790 */ | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
791 static void jmpDoArpeggio(JSSPlayer * mp, JSSPlayerChannel *chn, int channel, int paramY, int paramX) |
0 | 792 { |
218 | 793 JSSInstrument *inst = chn->instrument; |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
794 |
218 | 795 if (inst != NULL) |
0 | 796 { |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
797 int tmp = chn->note; |
218 | 798 if (tmp == jsetNotSet || tmp == jsetNoteOff) |
799 return; | |
800 | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
801 switch (mp->tick & 3) |
0 | 802 { |
803 case 1: | |
804 tmp += paramX; | |
805 break; | |
806 case 2: | |
807 tmp += paramY; | |
808 break; | |
809 } | |
218 | 810 |
811 tmp = dmClamp(tmp + inst->ERelNote, 0, 119); | |
812 jmpCSetPitch(mp, chn, jmpGetPeriodFromNote(mp, tmp, inst->EFineTune)); | |
0 | 813 } |
814 } | |
815 | |
816 | |
817 /* | |
818 * Process pattern effects | |
819 */ | |
820 static void jmpProcessRowEffect(JSSPlayer * mp, int channel, JSSNote * currNote) | |
821 { | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
822 JSSPlayerChannel *chn = &(mp->channels[channel]); |
0 | 823 int param, paramX, paramY; |
824 char effect; | |
825 | |
826 param = currNote->param; | |
827 JMPMAKEPARAM(param, paramX, paramY); | |
828 JMPGETEFFECT(effect, currNote->effect); | |
829 | |
830 switch (effect) | |
831 { | |
832 case '0': // 0xy = Arpeggio | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
833 jmpDoArpeggio(mp, chn, channel, paramX, paramY); |
0 | 834 break; |
835 | |
836 case 'W': // Used widely in demo-music as MIDAS Sound System sync-command | |
837 case 'Q': // SoundTracker/OpenCP: Qxx = Set LP filter resonance | |
838 case 'Z': // SoundTracker/OpenCP: Zxx = Set LP filter cutoff freq | |
839 break; | |
840 | |
841 case '1': | |
842 case '2': // 1xy = Portamento Up, 2xy = Portamento Down : IMPL.VERIFIED | |
843 if (param) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
844 chn->iLastPortaParam = param; |
0 | 845 break; |
846 | |
847 case '3': // 3xy = Porta To Note | |
848 if (param) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
849 chn->iLastPortaToNoteParam = param; |
0 | 850 |
170 | 851 if (currNote->note != jsetNotSet && currNote->note != jsetNoteOff) |
852 { | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
853 chn->iLastPortaToNotePitch = chn->pitch; |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
854 chn->pitch = chn->oldPitch; |
193
b778cc2fe7c8
Create a separate new frequency flag (vs. new pitch), for future changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
855 JMPUNSETNDFLAGS(cdfNewPitch); |
0 | 856 } |
857 break; | |
858 | |
859 case '4': // 4xy = Vibrato : IMPL.VERIFIED | |
860 if (paramX) | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
861 chn->vibrato.speed = paramX; |
0 | 862 |
863 if (paramY) | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
864 chn->vibrato.depth = paramY; |
0 | 865 |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
866 if ((chn->vibrato.wc & 4) == 0) |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
867 chn->vibrato.pos = 0; |
0 | 868 break; |
869 | |
870 case '5': // 5xy = Portamento + Volume Slide | |
871 case '6': // 6xy = Vibrato + Volume slide | |
872 if (param) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
873 chn->iLastVolSlideParam = param; |
0 | 874 break; |
875 | |
876 case '7': // 7xy = Tremolo | |
877 if (paramX) | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
878 chn->tremolo.speed = paramX; |
0 | 879 |
880 if (paramY) | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
881 chn->tremolo.depth = paramY; |
0 | 882 |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
883 if ((chn->tremolo.wc & 4) == 0) |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
884 chn->tremolo.pos = 0; |
0 | 885 break; |
886 | |
887 case '8': // 8xx = Set Panning | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
888 chn->panning = param; |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
889 JMPSETNDFLAGS(cdfNewPanPos); |
0 | 890 break; |
891 | |
892 case '9': // 9xx = Set Sample Offset : IMPL.VERIFIED | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
893 if (chn->newDataFlags & cdfNewPitch) |
30 | 894 { |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
895 chn->position = param * 0x100; |
0 | 896 JMPSETNDFLAGS(cdfNewPos); |
897 } | |
898 break; | |
899 | |
900 case 'A': // Axy = Volume Slide : IMPL.VERIFIED | |
901 if (param) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
902 chn->iLastVolSlideParam = param; |
0 | 903 break; |
904 | |
905 case 'B': // Bxx = Pattern Jump : IMPL.VERIFIED | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
906 mp->newOrder = param; |
0 | 907 mp->newOrderSet = TRUE; |
908 mp->jumpFlag = TRUE; | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
909 mp->lastPatLoopRow = 0; |
0 | 910 break; |
911 | |
912 case 'C': // Cxx = Set Volume : IMPL.VERIFIED | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
913 jmpSetVolume(chn, channel, param); |
0 | 914 break; |
915 | |
916 case 'D': // Dxx = Pattern Break : IMPL.VERIFIED | |
917 // Compute the new row | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
918 mp->newRow = (paramX * 10) + paramY; |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
919 if (mp->newRow >= mp->pattern->nrows) |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
920 mp->newRow = 0; |
0 | 921 |
922 mp->newRowSet = TRUE; | |
923 | |
924 // Now we do some tricky tests | |
925 if (!mp->breakFlag && !mp->jumpFlag) { | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
926 mp->newOrder = mp->order + 1; |
0 | 927 mp->newOrderSet = TRUE; |
928 } | |
929 | |
930 mp->breakFlag = TRUE; | |
931 break; | |
932 | |
933 case 'E': // Exy = Special Effects | |
934 switch (paramX) { | |
935 case 0x00: // E0x - Set filter (NOT SUPPORTED) | |
936 JMPDEBUG("Set Filter used, UNSUPPORTED"); | |
937 break; | |
938 | |
939 case 0x01: // E1x - Fine Portamento Up | |
940 if (paramY) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
941 chn->iCLastFinePortamentoUpParam = paramY; |
0 | 942 |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
943 jmpChangePitch(chn, channel, -(chn->iCLastFinePortamentoUpParam * 4)); |
0 | 944 break; |
945 | |
946 case 0x02: // E2x - Fine Portamento Down | |
947 if (paramY) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
948 chn->iCLastFinePortamentoDownParam = paramY; |
0 | 949 |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
950 jmpChangePitch(chn, channel, (chn->iCLastFinePortamentoDownParam * 4)); |
0 | 951 break; |
952 | |
953 case 0x03: // E3x - Glissando Control (NOT SUPPORTED) | |
954 break; | |
955 | |
956 case 0x04: // E4x - Set Vibrato waveform | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
957 chn->vibrato.wc = paramY; |
0 | 958 break; |
959 | |
960 case 0x05: // E5x - Set Finetune | |
961 JMPDEBUG("Set Finetune used, UNIMPLEMENTED"); | |
962 break; | |
963 | |
964 case 0x06: // E6x - Set Pattern Loop | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
965 jmpDoPatternLoop(mp, chn, channel, paramY); |
0 | 966 break; |
967 | |
968 case 0x07: // E7x - Set Tremolo waveform | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
969 chn->tremolo.wc = paramY; |
0 | 970 break; |
971 | |
972 case 0x08: // E8x - Set Pan Position | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
973 chn->panning = (paramY * 16); |
0 | 974 JMPSETNDFLAGS(cdfNewPanPos); |
975 break; | |
976 | |
977 case 0x09: // E9x - Retrig note | |
978 JMPDEBUG("Retrig Note used, UNIMPLEMENTED"); | |
979 break; | |
980 | |
981 case 0x0a: // EAx - Fine Volumeslide Up | |
982 if (paramY) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
983 chn->iCLastFineVolumeslideUpParam = paramY; |
0 | 984 |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
985 jmpChangeVolume(chn, channel, chn->iCLastFineVolumeslideUpParam); |
0 | 986 break; |
987 | |
988 case 0x0b: // EBx - Fine Volumeslide Down | |
989 if (paramY) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
990 chn->iCLastFineVolumeslideDownParam = paramY; |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
991 jmpChangeVolume(chn, channel, -(chn->iCLastFineVolumeslideDownParam)); |
0 | 992 break; |
993 | |
994 case 0x0c: // ECx - Set Note Cut (NOT PROCESSED IN TICK0) | |
995 break; | |
996 | |
997 case 0x0d: // EDx - Set Note Delay : IMPL.VERIFIED | |
998 if (paramY > 0) | |
999 { | |
1000 // Save the ND-flags, then clear | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1001 chn->iSaveNDFlags = chn->newDataFlags; |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1002 chn->newDataFlags = 0; |
0 | 1003 // TODO .. does this only affect NOTE or also instrument? |
1004 } | |
1005 break; | |
1006 | |
1007 case 0x0e: // EEx - Set Pattern Delay : IMPL.VERIFIED | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1008 mp->patternDelay = paramY; |
0 | 1009 break; |
1010 | |
1011 case 0x0f: // EFx - Invert Loop (NOT SUPPORTED) | |
1012 JMPDEBUG("Invert Loop used, UNSUPPORTED"); | |
1013 break; | |
1014 | |
1015 default: | |
1016 JMPDEBUG("Unsupported special command used"); | |
1017 } | |
1018 break; | |
1019 | |
1020 case 'F': // Fxy = Set Speed / Tempo : IMPL.VERIFIED | |
1021 if (param > 0) | |
1022 { | |
1023 if (param < 0x20) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1024 mp->speed = param; |
0 | 1025 else |
1026 jmpSetTempo(mp, param); | |
1027 } | |
1028 break; | |
1029 | |
1030 case 'G': // Gxx = Global Volume | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1031 mp->globalVol = param; |
0 | 1032 JMPSETNDFLAGS(cdfNewGlobalVol); |
1033 break; | |
1034 | |
1035 | |
1036 case 'H': // Hxx = Global Volume Slide | |
1037 JMPDEBUG("Global Volume Slide used, UNIMPLEMENTED"); | |
1038 break; | |
1039 | |
1040 case 'K': // Kxx = Key-off (Same as key-off note) | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1041 chn->keyOff = TRUE; |
0 | 1042 break; |
1043 | |
1044 case 'L': // Lxx = Set Envelope Position | |
1045 JMPDEBUG("Set Envelope Position used, NOT verified with FT2"); | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1046 chn->panningEnv.frame = param; |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1047 chn->volumeEnv.frame = param; |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1048 chn->panningEnv.exec = TRUE; |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1049 chn->volumeEnv.exec = TRUE; |
0 | 1050 break; |
1051 | |
1052 case 'R': // Rxy = Multi Retrig note | |
1053 JMPDEBUG("Multi Retrig Note used, UNIMPLEMENTED"); | |
1054 break; | |
1055 | |
1056 case 'T': // Txy = Tremor | |
1057 if (param) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1058 chn->iLastTremorParam = param; |
0 | 1059 break; |
1060 | |
1061 case 'X': // Xxy = Extra Fine Portamento | |
1062 switch (paramX) | |
1063 { | |
1064 case 0x01: // X1y - Extra Fine Portamento Up | |
1065 if (paramY) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1066 chn->iCLastExtraFinePortamentoUpParam = paramY; |
0 | 1067 |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1068 jmpChangePitch(chn, channel, - chn->iCLastExtraFinePortamentoUpParam); |
0 | 1069 break; |
1070 | |
1071 case 0x02: // X2y - Extra Fine Portamento Down | |
1072 if (paramY) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1073 chn->iCLastExtraFinePortamentoDownParam = paramY; |
0 | 1074 |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1075 jmpChangePitch(chn, channel, chn->iCLastExtraFinePortamentoUpParam); |
0 | 1076 break; |
1077 | |
1078 default: | |
1079 JMPDEBUG("Unsupported value in Extra Fine Portamento command!"); | |
1080 break; | |
1081 } | |
1082 break; | |
1083 | |
1084 default: | |
1085 JMPDEBUG("Unsupported effect"); | |
1086 break; | |
1087 } | |
1088 } | |
1089 | |
1090 | |
1091 static void jmpProcessNewRow(JSSPlayer * mp, int channel) | |
1092 { | |
1093 JSSNote *currNote; | |
215
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1094 BOOL newNote = FALSE, newExtInstrument = FALSE; |
0 | 1095 int tmp, paramX, paramY; |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1096 JSSPlayerChannel *chn = &(mp->channels[channel]); |
0 | 1097 |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1098 JMPGETNOTE(currNote, mp->row, channel); |
0 | 1099 |
1100 // Check for a new note/keyoff here | |
1101 if (currNote->note == jsetNoteOff) | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1102 chn->keyOff = TRUE; |
0 | 1103 else |
1104 if (currNote->note >= 0 && currNote->note <= 96) | |
1105 { | |
1106 newNote = TRUE; | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1107 chn->note = currNote->note; |
215
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1108 chn->keyOff = FALSE; |
0 | 1109 } |
1110 | |
1111 // Check for new instrument | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1112 if (currNote->instrument != jsetNotSet) |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1113 { |
0 | 1114 /* Envelopes and ext.instrument fadeout are initialized always if |
1115 * new instrument is set, even if the instrument does not exist. | |
1116 */ | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1117 jmpResetEnvelope(&chn->volumeEnv); |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1118 jmpResetEnvelope(&chn->panningEnv); |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1119 chn->keyOff = FALSE; |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1120 chn->fadeOutVol = mpMaxFadeoutVol; |
0 | 1121 |
215
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1122 JMPSETNDFLAGS(cdfNewPanPos | cdfPlay | cdfNewVolume); |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1123 |
0 | 1124 // We save the instrument number here for later use |
215
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1125 chn->nextInstrument = currNote->instrument; |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1126 newExtInstrument = TRUE; |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1127 } |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1128 |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1129 |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1130 if (newNote) |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1131 { |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1132 if (chn->nextInstrument >= 0 && |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1133 chn->nextInstrument < mp->module->nextInstruments && |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1134 mp->module->extInstruments[chn->nextInstrument] != NULL) |
177
eb293aa7a671
Cleanup the player logic a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
1135 { |
215
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1136 chn->extInstrument = mp->module->extInstruments[chn->nextInstrument]; |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1137 } |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1138 else |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1139 { |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1140 chn->extInstrument = NULL; |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1141 chn->instrument = NULL; |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1142 chn->ninstrument = jsetNotSet; |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1143 } |
0 | 1144 |
215
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1145 if (chn->extInstrument != NULL) |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1146 { |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1147 tmp = chn->extInstrument->sNumForNotes[chn->note]; |
0 | 1148 |
215
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1149 if (tmp >= 0 && tmp < mp->module->ninstruments && |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1150 mp->module->instruments[tmp] != NULL) |
180
bc8019c38ba5
Refactoring of the note triggering and other player logic, fixes various
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
1151 { |
215
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1152 if (chn->ninstrument != tmp) |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1153 JMPSETNDFLAGS(cdfNewInstr); |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1154 |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1155 chn->ninstrument = tmp; |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1156 chn->instrument = mp->module->instruments[chn->ninstrument]; |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1157 |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1158 if (newExtInstrument) |
197 | 1159 { |
215
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1160 chn->volume = chn->instrument->volume; |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1161 chn->panning = chn->instrument->EPanning; |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1162 JMPSETNDFLAGS(cdfNewPanPos | cdfNewVolume); |
197 | 1163 } |
180
bc8019c38ba5
Refactoring of the note triggering and other player logic, fixes various
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
1164 } |
0 | 1165 } |
215
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1166 |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1167 if (chn->instrument != NULL) |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1168 { |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1169 JSSInstrument *inst = chn->instrument; |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1170 |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1171 // Save old pitch for later use |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1172 chn->oldPitch = chn->pitch; |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1173 |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1174 chn->position = 0; |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1175 |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1176 // Compute new pitch |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1177 tmp = dmClamp(chn->note + inst->ERelNote, 0, 119); |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1178 chn->pitch = jmpGetPeriodFromNote(mp, tmp, inst->EFineTune); |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1179 JMPSETNDFLAGS(cdfNewPitch | cdfPlay | cdfNewPos); |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1180 } |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1181 else |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1182 { |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1183 chn->volume = 0; |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1184 chn->panning = jchPanMiddle; |
217
9fa6a00b294c
Actually stop the sample playing, in addition to setting volume to zero.
Matti Hamalainen <ccr@tnsp.org>
parents:
215
diff
changeset
|
1185 JMPSETNDFLAGS(cdfStop | cdfNewPanPos | cdfNewVolume); |
215
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1186 } |
0 | 1187 } |
1188 | |
1189 // Process the volume column | |
1190 JMPMAKEPARAM(currNote->volume, paramX, paramY); | |
1191 | |
1192 switch (paramX) | |
1193 { | |
214 | 1194 case 0x0: |
1195 case 0x1: | |
1196 case 0x2: | |
1197 case 0x3: | |
1198 case 0x4: | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1199 jmpSetVolume(chn, channel, currNote->volume); |
0 | 1200 break; |
1201 | |
214 | 1202 case 0x7: // Dx = Fine Volumeslide Down : IMPL.VERIFIED |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1203 jmpChangeVolume(chn, channel, -paramY); |
0 | 1204 break; |
1205 | |
214 | 1206 case 0x8: // Ux = Fine Volumeslide Up : IMPL.VERIFIED |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1207 jmpChangeVolume(chn, channel, paramY); |
0 | 1208 break; |
1209 | |
214 | 1210 case 0x9: // Sx = Set vibrato speed : IMPL.VERIFIED |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1211 chn->vibrato.speed = paramY; |
0 | 1212 break; |
1213 | |
214 | 1214 case 0xa: // Vx = Vibrato : IMPL.VERIFIED |
0 | 1215 if (paramY) |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1216 chn->vibrato.depth = paramY; |
0 | 1217 break; |
1218 | |
214 | 1219 case 0xe: // Mx = Porta To Note : IMPL.VERIFIED |
0 | 1220 if (paramY) |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1221 chn->iLastPortaToNoteParam = paramY; |
0 | 1222 |
175 | 1223 if (currNote->note != jsetNotSet && currNote->note != jsetNoteOff) |
1224 { | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1225 chn->iLastPortaToNotePitch = chn->pitch; |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1226 chn->pitch = chn->oldPitch; |
180
bc8019c38ba5
Refactoring of the note triggering and other player logic, fixes various
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
1227 JMPUNSETNDFLAGS(cdfNewPitch | cdfPlay); |
0 | 1228 } |
1229 break; | |
1230 } | |
1231 | |
1232 // ...And finally process the Normal effects | |
1233 if (currNote->effect != jsetNotSet) | |
1234 jmpProcessRowEffect(mp, channel, currNote); | |
1235 } | |
1236 | |
1237 | |
1238 static void jmpProcessEffects(JSSPlayer * mp, int channel) | |
1239 { | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1240 JSSPlayerChannel *chn = &(mp->channels[channel]); |
0 | 1241 JSSNote *currNote; |
1242 int param, paramX, paramY, tmp; | |
1243 char effect; | |
1244 | |
1245 // Process the volume column effects | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1246 JMPGETNOTE(currNote, mp->row, channel); |
0 | 1247 JMPMAKEPARAM(currNote->volume, paramX, paramY); |
1248 | |
1249 switch (paramX) | |
1250 { | |
1251 case 0x05: // -x = Volumeslide Down : IMPL.VERIFIED | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1252 jmpChangeVolume(chn, channel, -paramY); |
0 | 1253 break; |
1254 | |
1255 case 0x06: // +x = Volumeslide Down : IMPL.VERIFIED | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1256 jmpChangeVolume(chn, channel, paramY); |
0 | 1257 break; |
1258 | |
1259 case 0x0a: // Vx = Vibrato : IMPL.VERIFIED | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1260 jmpDoVibrato(mp, chn, channel); |
0 | 1261 break; |
1262 | |
1263 case 0x0e: // Mx = Porta To Note : IMPL.VERIFIED | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1264 jmpDoPortamento(chn, channel); |
0 | 1265 break; |
1266 } | |
1267 | |
1268 // ...And finally process the Normal effects | |
1269 if (currNote->effect == jsetNotSet) | |
1270 return; | |
1271 | |
1272 param = currNote->param; | |
1273 JMPMAKEPARAM(param, paramX, paramY); | |
1274 JMPGETEFFECT(effect, currNote->effect); | |
1275 | |
1276 switch (effect) | |
1277 { | |
1278 case '0': // 0xy = Arpeggio | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1279 jmpDoArpeggio(mp, chn, channel, paramX, paramY); |
0 | 1280 break; |
1281 | |
1282 case '1': // 1xy = Portamento Up | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1283 if (chn->iLastPortaParam > 0) |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1284 jmpChangePitch(chn, channel, -(chn->iLastPortaParam * 4)); |
0 | 1285 break; |
1286 | |
1287 case '2': // 2xy = Portamento Down | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1288 if (chn->iLastPortaParam > 0) |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1289 jmpChangePitch(chn, channel, (chn->iLastPortaParam * 4)); |
0 | 1290 break; |
1291 | |
1292 case '3': // 3xy = Porta To Note | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1293 jmpDoPortamento(chn, channel); |
0 | 1294 break; |
1295 | |
1296 case '4': // 4xy = Vibrato | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1297 jmpDoVibrato(mp, chn, channel); |
0 | 1298 break; |
1299 | |
1300 case '5': // 5xy = Portamento + Volume Slide | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1301 jmpDoPortamento(chn, channel); |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1302 jmpDoVolumeSlide(chn, channel, chn->iLastVolSlideParam); |
0 | 1303 break; |
1304 | |
1305 case '6': // 6xy = Vibrato + Volume Slide | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1306 jmpDoVibrato(mp, chn, channel); |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1307 jmpDoVolumeSlide(chn, channel, chn->iLastVolSlideParam); |
0 | 1308 break; |
1309 | |
1310 case '7': // 7xy = Tremolo | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1311 jmpDoTremolo(mp, chn, channel); |
0 | 1312 break; |
1313 | |
1314 case 'A': // Axy = Volume slide | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1315 jmpDoVolumeSlide(chn, channel, chn->iLastVolSlideParam); |
0 | 1316 break; |
1317 | |
1318 case 'E': // Exy = Special Effects | |
1319 switch (paramX) | |
1320 { | |
1321 case 0x0c: // ECx - Set Note Cut | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1322 if (mp->tick == paramY) |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1323 jmpSetVolume(chn, channel, jsetMinVol); |
0 | 1324 break; |
1325 | |
1326 case 0x0d: // EDx - Set Note Delay | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1327 if (mp->tick == paramY) |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1328 chn->newDataFlags = chn->iSaveNDFlags; |
0 | 1329 break; |
1330 } | |
1331 break; | |
1332 | |
1333 case 'T': // Txy = Tremor | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1334 JMPMAKEPARAM(chn->iLastTremorParam, paramX, paramY) |
0 | 1335 paramX++; |
1336 paramY++; | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1337 tmp = (chn->iTremorCount % (paramX + paramY)); |
0 | 1338 if (tmp < paramX) |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1339 jmpCSetVolume(mp, chn, channel, chn->volume, FALSE); |
0 | 1340 else |
144
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
1341 jmpCSetVolume(mp, chn, channel, jsetMinVol, FALSE); |
0 | 1342 |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1343 chn->iTremorCount = (tmp + 1); |
0 | 1344 break; |
1345 } | |
1346 } | |
1347 | |
1348 | |
1349 /* This is the main processing callback-loop of a module player. | |
1350 * It processes the ticks, calling the needed jmpProcessNewRow() | |
1351 * and jmpProcessEffects() methods for processing the module playing. | |
1352 */ | |
1353 void jmpExec(void *pDEV, void *pMP) | |
1354 { | |
1355 JSSPlayer *mp; | |
1356 JSSMixer *dev; | |
146
3226778033fd
Move variable a bit further into the block where it is actually used.
Matti Hamalainen <ccr@tnsp.org>
parents:
145
diff
changeset
|
1357 int channel; |
0 | 1358 |
1359 // Check some things via assert() | |
1360 mp = (JSSPlayer *) pMP; | |
1361 JSS_LOCK(mp); | |
1362 | |
1363 dev = (JSSMixer *) pDEV; | |
144
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
1364 |
0 | 1365 // Check if we are playing |
1366 if (!mp->isPlaying) | |
1367 goto out; | |
1368 | |
1369 // Clear channel new data flags | |
1370 mp->jumpFlag = FALSE; | |
1371 mp->breakFlag = FALSE; | |
1372 | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1373 for (channel = 0; channel < jsetNChannels; channel++) |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1374 mp->channels[channel].newDataFlags = 0; |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1375 |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1376 //fprintf(stderr, "1: tick=%d, order=%d, iPattern=%d, row=%d\n", mp->tick, mp->order, mp->npattern, mp->row); |
0 | 1377 |
1378 // Check for init-tick | |
187 | 1379 if (mp->tick == jsetNotSet) |
0 | 1380 { |
1381 // Initialize pattern | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1382 mp->newRow = 0; |
0 | 1383 mp->newRowSet = TRUE; |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1384 mp->tick = mp->speed; |
187 | 1385 mp->patternDelay = 0; |
0 | 1386 } |
1387 | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1388 //fprintf(stderr, "2: tick=%d, order=%d, iPattern=%d, row=%d\n", mp->tick, mp->order, mp->npattern, mp->row); |
0 | 1389 |
1390 // Check if we are playing | |
1391 if (!mp->isPlaying) | |
1392 goto out; | |
1393 | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1394 assert(mp->pattern); |
0 | 1395 |
1396 // Update the tick | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1397 mp->tick++; |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1398 if (mp->tick >= mp->speed) |
0 | 1399 { |
1400 // Re-init tick counter | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1401 mp->tick = 0; |
0 | 1402 |
1403 // Check pattern delay | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1404 if (mp->patternDelay > 0) |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1405 mp->patternDelay--; |
0 | 1406 else |
1407 { | |
1408 // New pattern row | |
1409 if (mp->newRowSet) | |
1410 { | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1411 mp->row = mp->newRow; |
0 | 1412 mp->newRowSet = FALSE; |
1413 } else | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1414 mp->row++; |
0 | 1415 |
1416 // Check for end of pattern | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1417 if (mp->row >= mp->pattern->nrows) |
0 | 1418 { |
1419 // Go to next order | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1420 if (mp->order != jsetNotSet) |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1421 jmpSetNewOrder(mp, mp->order + 1); |
0 | 1422 else |
1423 mp->isPlaying = FALSE; | |
1424 | |
1425 // Check for FT2 quirks | |
1426 if (JMPGETMODFLAGS(mp, jmdfFT2Replay)) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1427 mp->row = mp->lastPatLoopRow; |
0 | 1428 else |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1429 mp->row = 0; |
0 | 1430 } |
1431 | |
1432 if (!mp->isPlaying) | |
1433 goto out; | |
1434 | |
1435 // Check current order | |
1436 if (mp->newOrderSet) | |
1437 { | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1438 jmpSetNewOrder(mp, mp->newOrder); |
0 | 1439 mp->newOrderSet = FALSE; |
1440 } | |
1441 | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1442 //fprintf(stderr, "3: tick=%d, order=%d, iPattern=%d, row=%d\n", mp->tick, mp->order, mp->npattern, mp->row); |
0 | 1443 |
1444 if (!mp->isPlaying) | |
1445 goto out; | |
1446 | |
1447 // TICK #0: Process new row | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1448 for (channel = 0; channel < mp->module->nchannels; channel++) |
0 | 1449 jmpProcessNewRow(mp, channel); |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1450 } // patternDelay |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1451 } // tick |
0 | 1452 else |
1453 { | |
1454 // Implement FT2's pattern delay-effect: don't update effects while on patdelay | |
1455 if (!JMPGETMODFLAGS(mp, jmdfFT2Replay) || | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1456 (JMPGETMODFLAGS(mp, jmdfFT2Replay) && mp->patternDelay <= 0)) |
0 | 1457 { |
1458 // TICK n: Process the effects | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1459 for (channel = 0; channel < mp->module->nchannels; channel++) |
0 | 1460 jmpProcessEffects(mp, channel); |
1461 } | |
1462 } | |
1463 | |
1464 // Check if playing has stopped | |
1465 if (!mp->isPlaying) | |
1466 goto out; | |
1467 | |
1468 // Update player data to audio device/mixer | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1469 for (channel = 0; channel < mp->module->nchannels; channel++) |
0 | 1470 { |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1471 JSSPlayerChannel *chn = &mp->channels[channel]; |
146
3226778033fd
Move variable a bit further into the block where it is actually used.
Matti Hamalainen <ccr@tnsp.org>
parents:
145
diff
changeset
|
1472 int flags; |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1473 |
0 | 1474 // Process extended instruments |
61
a33e47232161
Silence some "unused parameter" warnings.
Matti Hamalainen <ccr@tnsp.org>
parents:
55
diff
changeset
|
1475 jmpProcessExtInstrument(chn, channel); |
0 | 1476 |
1477 // Check NDFlags and update channel data | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1478 flags = chn->newDataFlags; |
144
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
1479 if (!flags) |
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
1480 continue; |
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
1481 |
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
1482 // Check if we stop? |
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
1483 if (flags & cdfStop) |
0 | 1484 { |
144
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
1485 jvmStop(mp->device, channel); |
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
1486 } |
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
1487 else |
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
1488 { |
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
1489 // No, handle other flags |
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
1490 if (flags & cdfNewInstr) |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1491 { |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1492 JSSInstrument *instr = chn->instrument; |
144
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
1493 if (instr != NULL) |
0 | 1494 { |
144
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
1495 jvmSetSample(mp->device, channel, |
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
1496 instr->data, instr->size, |
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
1497 instr->loopS, instr->loopE, |
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
1498 instr->flags); |
0 | 1499 } |
180
bc8019c38ba5
Refactoring of the note triggering and other player logic, fixes various
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
1500 } |
bc8019c38ba5
Refactoring of the note triggering and other player logic, fixes various
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
1501 |
bc8019c38ba5
Refactoring of the note triggering and other player logic, fixes various
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
1502 if (flags & cdfPlay) |
144
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
1503 jvmPlay(mp->device, channel); |
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
1504 |
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
1505 if (flags & cdfNewPitch) |
193
b778cc2fe7c8
Create a separate new frequency flag (vs. new pitch), for future changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1506 jmpCSetPitch(mp, chn, chn->pitch); |
b778cc2fe7c8
Create a separate new frequency flag (vs. new pitch), for future changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1507 |
218 | 1508 if (flags & (cdfNewFreq | cdfNewPitch)) |
193
b778cc2fe7c8
Create a separate new frequency flag (vs. new pitch), for future changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1509 jvmSetFreq(mp->device, channel, chn->freq); |
0 | 1510 |
144
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
1511 if (flags & cdfNewPos) |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1512 jvmSetPos(mp->device, channel, chn->position); |
0 | 1513 |
144
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
1514 if (flags & cdfNewVolume) |
196
dea742428ac6
Adjust volume ramping logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
195
diff
changeset
|
1515 jmpCSetVolume(mp, chn, channel, chn->volume, flags & (cdfNewInstr | cdfPlay)); |
0 | 1516 |
144
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
1517 if (flags & cdfNewPanPos) |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1518 jmpCSetPanning(mp, chn, channel, chn->panning); |
0 | 1519 |
144
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
1520 if (flags & cdfNewGlobalVol) |
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
1521 jvmSetGlobalVol(mp->device, mp->globalVol); |
0 | 1522 } |
1523 } | |
1524 | |
1525 out: | |
1526 JSS_UNLOCK(mp); | |
1527 } |