Mercurial > hg > dmlib
annotate jssplr.c @ 217:9fa6a00b294c
Actually stop the sample playing, in addition to setting volume to zero.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 07 Oct 2012 21:45:24 +0300 |
parents | 5523ea253603 |
children | c619c8b6f696 |
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 } |
100 } | |
101 } | |
102 | |
103 | |
144
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
104 static void jmpCSetVolume(JSSPlayer * mp, JSSPlayerChannel *chn, int channel, int volume, int init) |
0 | 105 { |
106 assert(mp != NULL); | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
107 assert(mp->device != NULL); |
0 | 108 |
154 | 109 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
|
110 |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
111 //fprintf(stderr, "chn %d: vol=%d, fad=%d, env=%d\n", channel, volume, chn->fadeOutVol, chn->volumeEnv.value); |
157 | 112 |
188
47c327fb321a
Another cleanup, remove the "future player" data prediction hack, it is not needed.
Matti Hamalainen <ccr@tnsp.org>
parents:
187
diff
changeset
|
113 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
|
114 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
|
115 (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
|
116 init ? 5 : 0); |
0 | 117 } |
118 | |
119 | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
120 static void jmpCSetPanning(JSSPlayer * mp, JSSPlayerChannel *chn, int channel, int panning) |
0 | 121 { |
122 assert(mp != NULL); | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
123 assert(mp->device != NULL); |
0 | 124 |
188
47c327fb321a
Another cleanup, remove the "future player" data prediction hack, it is not needed.
Matti Hamalainen <ccr@tnsp.org>
parents:
187
diff
changeset
|
125 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
|
126 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
|
127 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
|
128 0); |
0 | 129 } |
130 | |
131 | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
132 static BOOL jmpExecEnvelope(JSSEnvelope *env, JSSPlayerEnvelope *pe, BOOL keyOff) |
0 | 133 { |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
134 int point = 0; |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
135 |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
136 if (!pe->exec) |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
137 return FALSE; |
0 | 138 |
189 | 139 // 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
|
140 while (point < env->npoints - 1) |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
141 { |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
142 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
|
143 point++; |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
144 else |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
145 break; |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
146 } |
189 | 147 |
148 // Check for last point | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
149 if (pe->frame >= env->points[env->npoints - 1].frame) |
0 | 150 { |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
151 if (env->flags & jenvfLooped) |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
152 { |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
153 point = env->loopS; |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
154 pe->frame = env->points[env->loopS].frame; |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
155 } |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
156 else |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
157 { |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
158 point = env->npoints - 1; |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
159 pe->exec = FALSE; |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
160 } |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
161 |
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 { |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
793 JSSInstrument *tempInst = chn->instrument; |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
794 |
0 | 795 if (tempInst) |
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; |
0 | 798 if (tmp == jsetNotSet || tmp == jsetNoteOff) return; |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
799 switch (mp->tick & 3) |
0 | 800 { |
801 case 1: | |
802 tmp += paramX; | |
803 break; | |
804 case 2: | |
805 tmp += paramY; | |
806 break; | |
807 } | |
193
b778cc2fe7c8
Create a separate new frequency flag (vs. new pitch), for future changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
808 jmpCSetPitch(mp, chn, jmpGetPeriodFromNote(mp, tmp + tempInst->ERelNote, tempInst->EFineTune)); |
0 | 809 } |
810 } | |
811 | |
812 | |
813 /* | |
814 * Process pattern effects | |
815 */ | |
816 static void jmpProcessRowEffect(JSSPlayer * mp, int channel, JSSNote * currNote) | |
817 { | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
818 JSSPlayerChannel *chn = &(mp->channels[channel]); |
0 | 819 int param, paramX, paramY; |
820 char effect; | |
821 | |
822 param = currNote->param; | |
823 JMPMAKEPARAM(param, paramX, paramY); | |
824 JMPGETEFFECT(effect, currNote->effect); | |
825 | |
826 switch (effect) | |
827 { | |
828 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
|
829 jmpDoArpeggio(mp, chn, channel, paramX, paramY); |
0 | 830 break; |
831 | |
832 case 'W': // Used widely in demo-music as MIDAS Sound System sync-command | |
833 case 'Q': // SoundTracker/OpenCP: Qxx = Set LP filter resonance | |
834 case 'Z': // SoundTracker/OpenCP: Zxx = Set LP filter cutoff freq | |
835 break; | |
836 | |
837 case '1': | |
838 case '2': // 1xy = Portamento Up, 2xy = Portamento Down : IMPL.VERIFIED | |
839 if (param) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
840 chn->iLastPortaParam = param; |
0 | 841 break; |
842 | |
843 case '3': // 3xy = Porta To Note | |
844 if (param) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
845 chn->iLastPortaToNoteParam = param; |
0 | 846 |
170 | 847 if (currNote->note != jsetNotSet && currNote->note != jsetNoteOff) |
848 { | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
849 chn->iLastPortaToNotePitch = chn->pitch; |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
850 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
|
851 JMPUNSETNDFLAGS(cdfNewPitch); |
0 | 852 } |
853 break; | |
854 | |
855 case '4': // 4xy = Vibrato : IMPL.VERIFIED | |
856 if (paramX) | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
857 chn->vibrato.speed = paramX; |
0 | 858 |
859 if (paramY) | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
860 chn->vibrato.depth = paramY; |
0 | 861 |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
862 if ((chn->vibrato.wc & 4) == 0) |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
863 chn->vibrato.pos = 0; |
0 | 864 break; |
865 | |
866 case '5': // 5xy = Portamento + Volume Slide | |
867 case '6': // 6xy = Vibrato + Volume slide | |
868 if (param) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
869 chn->iLastVolSlideParam = param; |
0 | 870 break; |
871 | |
872 case '7': // 7xy = Tremolo | |
873 if (paramX) | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
874 chn->tremolo.speed = paramX; |
0 | 875 |
876 if (paramY) | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
877 chn->tremolo.depth = paramY; |
0 | 878 |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
879 if ((chn->tremolo.wc & 4) == 0) |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
880 chn->tremolo.pos = 0; |
0 | 881 break; |
882 | |
883 case '8': // 8xx = Set Panning | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
884 chn->panning = param; |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
885 JMPSETNDFLAGS(cdfNewPanPos); |
0 | 886 break; |
887 | |
888 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
|
889 if (chn->newDataFlags & cdfNewPitch) |
30 | 890 { |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
891 chn->position = param * 0x100; |
0 | 892 JMPSETNDFLAGS(cdfNewPos); |
893 } | |
894 break; | |
895 | |
896 case 'A': // Axy = Volume Slide : IMPL.VERIFIED | |
897 if (param) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
898 chn->iLastVolSlideParam = param; |
0 | 899 break; |
900 | |
901 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
|
902 mp->newOrder = param; |
0 | 903 mp->newOrderSet = TRUE; |
904 mp->jumpFlag = TRUE; | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
905 mp->lastPatLoopRow = 0; |
0 | 906 break; |
907 | |
908 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
|
909 jmpSetVolume(chn, channel, param); |
0 | 910 break; |
911 | |
912 case 'D': // Dxx = Pattern Break : IMPL.VERIFIED | |
913 // 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
|
914 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
|
915 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
|
916 mp->newRow = 0; |
0 | 917 |
918 mp->newRowSet = TRUE; | |
919 | |
920 // Now we do some tricky tests | |
921 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
|
922 mp->newOrder = mp->order + 1; |
0 | 923 mp->newOrderSet = TRUE; |
924 } | |
925 | |
926 mp->breakFlag = TRUE; | |
927 break; | |
928 | |
929 case 'E': // Exy = Special Effects | |
930 switch (paramX) { | |
931 case 0x00: // E0x - Set filter (NOT SUPPORTED) | |
932 JMPDEBUG("Set Filter used, UNSUPPORTED"); | |
933 break; | |
934 | |
935 case 0x01: // E1x - Fine Portamento Up | |
936 if (paramY) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
937 chn->iCLastFinePortamentoUpParam = paramY; |
0 | 938 |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
939 jmpChangePitch(chn, channel, -(chn->iCLastFinePortamentoUpParam * 4)); |
0 | 940 break; |
941 | |
942 case 0x02: // E2x - Fine Portamento Down | |
943 if (paramY) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
944 chn->iCLastFinePortamentoDownParam = paramY; |
0 | 945 |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
946 jmpChangePitch(chn, channel, (chn->iCLastFinePortamentoDownParam * 4)); |
0 | 947 break; |
948 | |
949 case 0x03: // E3x - Glissando Control (NOT SUPPORTED) | |
950 break; | |
951 | |
952 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
|
953 chn->vibrato.wc = paramY; |
0 | 954 break; |
955 | |
956 case 0x05: // E5x - Set Finetune | |
957 JMPDEBUG("Set Finetune used, UNIMPLEMENTED"); | |
958 break; | |
959 | |
960 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
|
961 jmpDoPatternLoop(mp, chn, channel, paramY); |
0 | 962 break; |
963 | |
964 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
|
965 chn->tremolo.wc = paramY; |
0 | 966 break; |
967 | |
968 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
|
969 chn->panning = (paramY * 16); |
0 | 970 JMPSETNDFLAGS(cdfNewPanPos); |
971 break; | |
972 | |
973 case 0x09: // E9x - Retrig note | |
974 JMPDEBUG("Retrig Note used, UNIMPLEMENTED"); | |
975 break; | |
976 | |
977 case 0x0a: // EAx - Fine Volumeslide Up | |
978 if (paramY) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
979 chn->iCLastFineVolumeslideUpParam = paramY; |
0 | 980 |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
981 jmpChangeVolume(chn, channel, chn->iCLastFineVolumeslideUpParam); |
0 | 982 break; |
983 | |
984 case 0x0b: // EBx - Fine Volumeslide Down | |
985 if (paramY) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
986 chn->iCLastFineVolumeslideDownParam = paramY; |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
987 jmpChangeVolume(chn, channel, -(chn->iCLastFineVolumeslideDownParam)); |
0 | 988 break; |
989 | |
990 case 0x0c: // ECx - Set Note Cut (NOT PROCESSED IN TICK0) | |
991 break; | |
992 | |
993 case 0x0d: // EDx - Set Note Delay : IMPL.VERIFIED | |
994 if (paramY > 0) | |
995 { | |
996 // 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
|
997 chn->iSaveNDFlags = chn->newDataFlags; |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
998 chn->newDataFlags = 0; |
0 | 999 // TODO .. does this only affect NOTE or also instrument? |
1000 } | |
1001 break; | |
1002 | |
1003 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
|
1004 mp->patternDelay = paramY; |
0 | 1005 break; |
1006 | |
1007 case 0x0f: // EFx - Invert Loop (NOT SUPPORTED) | |
1008 JMPDEBUG("Invert Loop used, UNSUPPORTED"); | |
1009 break; | |
1010 | |
1011 default: | |
1012 JMPDEBUG("Unsupported special command used"); | |
1013 } | |
1014 break; | |
1015 | |
1016 case 'F': // Fxy = Set Speed / Tempo : IMPL.VERIFIED | |
1017 if (param > 0) | |
1018 { | |
1019 if (param < 0x20) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1020 mp->speed = param; |
0 | 1021 else |
1022 jmpSetTempo(mp, param); | |
1023 } | |
1024 break; | |
1025 | |
1026 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
|
1027 mp->globalVol = param; |
0 | 1028 JMPSETNDFLAGS(cdfNewGlobalVol); |
1029 break; | |
1030 | |
1031 | |
1032 case 'H': // Hxx = Global Volume Slide | |
1033 JMPDEBUG("Global Volume Slide used, UNIMPLEMENTED"); | |
1034 break; | |
1035 | |
1036 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
|
1037 chn->keyOff = TRUE; |
0 | 1038 break; |
1039 | |
1040 case 'L': // Lxx = Set Envelope Position | |
1041 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
|
1042 chn->panningEnv.frame = param; |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1043 chn->volumeEnv.frame = param; |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1044 chn->panningEnv.exec = TRUE; |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1045 chn->volumeEnv.exec = TRUE; |
0 | 1046 break; |
1047 | |
1048 case 'R': // Rxy = Multi Retrig note | |
1049 JMPDEBUG("Multi Retrig Note used, UNIMPLEMENTED"); | |
1050 break; | |
1051 | |
1052 case 'T': // Txy = Tremor | |
1053 if (param) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1054 chn->iLastTremorParam = param; |
0 | 1055 break; |
1056 | |
1057 case 'X': // Xxy = Extra Fine Portamento | |
1058 switch (paramX) | |
1059 { | |
1060 case 0x01: // X1y - Extra Fine Portamento Up | |
1061 if (paramY) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1062 chn->iCLastExtraFinePortamentoUpParam = paramY; |
0 | 1063 |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1064 jmpChangePitch(chn, channel, - chn->iCLastExtraFinePortamentoUpParam); |
0 | 1065 break; |
1066 | |
1067 case 0x02: // X2y - Extra Fine Portamento Down | |
1068 if (paramY) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1069 chn->iCLastExtraFinePortamentoDownParam = paramY; |
0 | 1070 |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1071 jmpChangePitch(chn, channel, chn->iCLastExtraFinePortamentoUpParam); |
0 | 1072 break; |
1073 | |
1074 default: | |
1075 JMPDEBUG("Unsupported value in Extra Fine Portamento command!"); | |
1076 break; | |
1077 } | |
1078 break; | |
1079 | |
1080 default: | |
1081 JMPDEBUG("Unsupported effect"); | |
1082 break; | |
1083 } | |
1084 } | |
1085 | |
1086 | |
1087 static void jmpProcessNewRow(JSSPlayer * mp, int channel) | |
1088 { | |
1089 JSSNote *currNote; | |
215
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1090 BOOL newNote = FALSE, newExtInstrument = FALSE; |
0 | 1091 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
|
1092 JSSPlayerChannel *chn = &(mp->channels[channel]); |
0 | 1093 |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1094 JMPGETNOTE(currNote, mp->row, channel); |
0 | 1095 |
1096 // Check for a new note/keyoff here | |
1097 if (currNote->note == jsetNoteOff) | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1098 chn->keyOff = TRUE; |
0 | 1099 else |
1100 if (currNote->note >= 0 && currNote->note <= 96) | |
1101 { | |
1102 newNote = TRUE; | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1103 chn->note = currNote->note; |
215
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1104 chn->keyOff = FALSE; |
0 | 1105 } |
1106 | |
1107 // 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
|
1108 if (currNote->instrument != jsetNotSet) |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1109 { |
0 | 1110 /* Envelopes and ext.instrument fadeout are initialized always if |
1111 * new instrument is set, even if the instrument does not exist. | |
1112 */ | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1113 jmpResetEnvelope(&chn->volumeEnv); |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1114 jmpResetEnvelope(&chn->panningEnv); |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1115 chn->keyOff = FALSE; |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1116 chn->fadeOutVol = mpMaxFadeoutVol; |
0 | 1117 |
215
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1118 JMPSETNDFLAGS(cdfNewPanPos | cdfPlay | cdfNewVolume); |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1119 |
0 | 1120 // 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
|
1121 chn->nextInstrument = currNote->instrument; |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1122 newExtInstrument = TRUE; |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1123 } |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1124 |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1125 |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1126 if (newNote) |
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 if (chn->nextInstrument >= 0 && |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1129 chn->nextInstrument < mp->module->nextInstruments && |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1130 mp->module->extInstruments[chn->nextInstrument] != NULL) |
177
eb293aa7a671
Cleanup the player logic a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
1131 { |
215
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1132 chn->extInstrument = mp->module->extInstruments[chn->nextInstrument]; |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1133 } |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1134 else |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1135 { |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1136 chn->extInstrument = NULL; |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1137 chn->instrument = NULL; |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1138 chn->ninstrument = jsetNotSet; |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1139 } |
0 | 1140 |
215
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1141 if (chn->extInstrument != NULL) |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1142 { |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1143 tmp = chn->extInstrument->sNumForNotes[chn->note]; |
0 | 1144 |
215
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1145 if (tmp >= 0 && tmp < mp->module->ninstruments && |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1146 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
|
1147 { |
215
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1148 if (chn->ninstrument != tmp) |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1149 JMPSETNDFLAGS(cdfNewInstr); |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1150 |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1151 chn->ninstrument = tmp; |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1152 chn->instrument = mp->module->instruments[chn->ninstrument]; |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1153 |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1154 if (newExtInstrument) |
197 | 1155 { |
215
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1156 chn->volume = chn->instrument->volume; |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1157 chn->panning = chn->instrument->EPanning; |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1158 JMPSETNDFLAGS(cdfNewPanPos | cdfNewVolume); |
197 | 1159 } |
180
bc8019c38ba5
Refactoring of the note triggering and other player logic, fixes various
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
1160 } |
0 | 1161 } |
215
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1162 |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1163 if (chn->instrument != NULL) |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1164 { |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1165 JSSInstrument *inst = chn->instrument; |
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 // Save old pitch for later use |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1168 chn->oldPitch = chn->pitch; |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1169 |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1170 chn->position = 0; |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1171 |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1172 // Compute new pitch |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1173 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
|
1174 chn->pitch = jmpGetPeriodFromNote(mp, tmp, inst->EFineTune); |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1175 JMPSETNDFLAGS(cdfNewPitch | cdfPlay | cdfNewPos); |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1176 } |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1177 else |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1178 { |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1179 chn->volume = 0; |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1180 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
|
1181 JMPSETNDFLAGS(cdfStop | cdfNewPanPos | cdfNewVolume); |
215
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1182 } |
0 | 1183 } |
1184 | |
1185 // Process the volume column | |
1186 JMPMAKEPARAM(currNote->volume, paramX, paramY); | |
1187 | |
1188 switch (paramX) | |
1189 { | |
214 | 1190 case 0x0: |
1191 case 0x1: | |
1192 case 0x2: | |
1193 case 0x3: | |
1194 case 0x4: | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1195 jmpSetVolume(chn, channel, currNote->volume); |
0 | 1196 break; |
1197 | |
214 | 1198 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
|
1199 jmpChangeVolume(chn, channel, -paramY); |
0 | 1200 break; |
1201 | |
214 | 1202 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
|
1203 jmpChangeVolume(chn, channel, paramY); |
0 | 1204 break; |
1205 | |
214 | 1206 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
|
1207 chn->vibrato.speed = paramY; |
0 | 1208 break; |
1209 | |
214 | 1210 case 0xa: // Vx = Vibrato : IMPL.VERIFIED |
0 | 1211 if (paramY) |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1212 chn->vibrato.depth = paramY; |
0 | 1213 break; |
1214 | |
214 | 1215 case 0xe: // Mx = Porta To Note : IMPL.VERIFIED |
0 | 1216 if (paramY) |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1217 chn->iLastPortaToNoteParam = paramY; |
0 | 1218 |
175 | 1219 if (currNote->note != jsetNotSet && currNote->note != jsetNoteOff) |
1220 { | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1221 chn->iLastPortaToNotePitch = chn->pitch; |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1222 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
|
1223 JMPUNSETNDFLAGS(cdfNewPitch | cdfPlay); |
0 | 1224 } |
1225 break; | |
1226 } | |
1227 | |
1228 // ...And finally process the Normal effects | |
1229 if (currNote->effect != jsetNotSet) | |
1230 jmpProcessRowEffect(mp, channel, currNote); | |
1231 } | |
1232 | |
1233 | |
1234 static void jmpProcessEffects(JSSPlayer * mp, int channel) | |
1235 { | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1236 JSSPlayerChannel *chn = &(mp->channels[channel]); |
0 | 1237 JSSNote *currNote; |
1238 int param, paramX, paramY, tmp; | |
1239 char effect; | |
1240 | |
1241 // 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
|
1242 JMPGETNOTE(currNote, mp->row, channel); |
0 | 1243 JMPMAKEPARAM(currNote->volume, paramX, paramY); |
1244 | |
1245 switch (paramX) | |
1246 { | |
1247 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
|
1248 jmpChangeVolume(chn, channel, -paramY); |
0 | 1249 break; |
1250 | |
1251 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
|
1252 jmpChangeVolume(chn, channel, paramY); |
0 | 1253 break; |
1254 | |
1255 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
|
1256 jmpDoVibrato(mp, chn, channel); |
0 | 1257 break; |
1258 | |
1259 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
|
1260 jmpDoPortamento(chn, channel); |
0 | 1261 break; |
1262 } | |
1263 | |
1264 // ...And finally process the Normal effects | |
1265 if (currNote->effect == jsetNotSet) | |
1266 return; | |
1267 | |
1268 param = currNote->param; | |
1269 JMPMAKEPARAM(param, paramX, paramY); | |
1270 JMPGETEFFECT(effect, currNote->effect); | |
1271 | |
1272 switch (effect) | |
1273 { | |
1274 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
|
1275 jmpDoArpeggio(mp, chn, channel, paramX, paramY); |
0 | 1276 break; |
1277 | |
1278 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
|
1279 if (chn->iLastPortaParam > 0) |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1280 jmpChangePitch(chn, channel, -(chn->iLastPortaParam * 4)); |
0 | 1281 break; |
1282 | |
1283 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
|
1284 if (chn->iLastPortaParam > 0) |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1285 jmpChangePitch(chn, channel, (chn->iLastPortaParam * 4)); |
0 | 1286 break; |
1287 | |
1288 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
|
1289 jmpDoPortamento(chn, channel); |
0 | 1290 break; |
1291 | |
1292 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
|
1293 jmpDoVibrato(mp, chn, channel); |
0 | 1294 break; |
1295 | |
1296 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
|
1297 jmpDoPortamento(chn, channel); |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1298 jmpDoVolumeSlide(chn, channel, chn->iLastVolSlideParam); |
0 | 1299 break; |
1300 | |
1301 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
|
1302 jmpDoVibrato(mp, chn, channel); |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1303 jmpDoVolumeSlide(chn, channel, chn->iLastVolSlideParam); |
0 | 1304 break; |
1305 | |
1306 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
|
1307 jmpDoTremolo(mp, chn, channel); |
0 | 1308 break; |
1309 | |
1310 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
|
1311 jmpDoVolumeSlide(chn, channel, chn->iLastVolSlideParam); |
0 | 1312 break; |
1313 | |
1314 case 'E': // Exy = Special Effects | |
1315 switch (paramX) | |
1316 { | |
1317 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
|
1318 if (mp->tick == paramY) |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1319 jmpSetVolume(chn, channel, jsetMinVol); |
0 | 1320 break; |
1321 | |
1322 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
|
1323 if (mp->tick == paramY) |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1324 chn->newDataFlags = chn->iSaveNDFlags; |
0 | 1325 break; |
1326 } | |
1327 break; | |
1328 | |
1329 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
|
1330 JMPMAKEPARAM(chn->iLastTremorParam, paramX, paramY) |
0 | 1331 paramX++; |
1332 paramY++; | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1333 tmp = (chn->iTremorCount % (paramX + paramY)); |
0 | 1334 if (tmp < paramX) |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1335 jmpCSetVolume(mp, chn, channel, chn->volume, FALSE); |
0 | 1336 else |
144
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
1337 jmpCSetVolume(mp, chn, channel, jsetMinVol, FALSE); |
0 | 1338 |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1339 chn->iTremorCount = (tmp + 1); |
0 | 1340 break; |
1341 } | |
1342 } | |
1343 | |
1344 | |
1345 /* This is the main processing callback-loop of a module player. | |
1346 * It processes the ticks, calling the needed jmpProcessNewRow() | |
1347 * and jmpProcessEffects() methods for processing the module playing. | |
1348 */ | |
1349 void jmpExec(void *pDEV, void *pMP) | |
1350 { | |
1351 JSSPlayer *mp; | |
1352 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
|
1353 int channel; |
0 | 1354 |
1355 // Check some things via assert() | |
1356 mp = (JSSPlayer *) pMP; | |
1357 JSS_LOCK(mp); | |
1358 | |
1359 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
|
1360 |
0 | 1361 // Check if we are playing |
1362 if (!mp->isPlaying) | |
1363 goto out; | |
1364 | |
1365 // Clear channel new data flags | |
1366 mp->jumpFlag = FALSE; | |
1367 mp->breakFlag = FALSE; | |
1368 | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1369 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
|
1370 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
|
1371 |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1372 //fprintf(stderr, "1: tick=%d, order=%d, iPattern=%d, row=%d\n", mp->tick, mp->order, mp->npattern, mp->row); |
0 | 1373 |
1374 // Check for init-tick | |
187 | 1375 if (mp->tick == jsetNotSet) |
0 | 1376 { |
1377 // Initialize pattern | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1378 mp->newRow = 0; |
0 | 1379 mp->newRowSet = TRUE; |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1380 mp->tick = mp->speed; |
187 | 1381 mp->patternDelay = 0; |
0 | 1382 } |
1383 | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1384 //fprintf(stderr, "2: tick=%d, order=%d, iPattern=%d, row=%d\n", mp->tick, mp->order, mp->npattern, mp->row); |
0 | 1385 |
1386 // Check if we are playing | |
1387 if (!mp->isPlaying) | |
1388 goto out; | |
1389 | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1390 assert(mp->pattern); |
0 | 1391 |
1392 // Update the tick | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1393 mp->tick++; |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1394 if (mp->tick >= mp->speed) |
0 | 1395 { |
1396 // 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
|
1397 mp->tick = 0; |
0 | 1398 |
1399 // Check pattern delay | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1400 if (mp->patternDelay > 0) |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1401 mp->patternDelay--; |
0 | 1402 else |
1403 { | |
1404 // New pattern row | |
1405 if (mp->newRowSet) | |
1406 { | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1407 mp->row = mp->newRow; |
0 | 1408 mp->newRowSet = FALSE; |
1409 } else | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1410 mp->row++; |
0 | 1411 |
1412 // 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
|
1413 if (mp->row >= mp->pattern->nrows) |
0 | 1414 { |
1415 // 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
|
1416 if (mp->order != jsetNotSet) |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1417 jmpSetNewOrder(mp, mp->order + 1); |
0 | 1418 else |
1419 mp->isPlaying = FALSE; | |
1420 | |
1421 // Check for FT2 quirks | |
1422 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
|
1423 mp->row = mp->lastPatLoopRow; |
0 | 1424 else |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1425 mp->row = 0; |
0 | 1426 } |
1427 | |
1428 if (!mp->isPlaying) | |
1429 goto out; | |
1430 | |
1431 // Check current order | |
1432 if (mp->newOrderSet) | |
1433 { | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1434 jmpSetNewOrder(mp, mp->newOrder); |
0 | 1435 mp->newOrderSet = FALSE; |
1436 } | |
1437 | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1438 //fprintf(stderr, "3: tick=%d, order=%d, iPattern=%d, row=%d\n", mp->tick, mp->order, mp->npattern, mp->row); |
0 | 1439 |
1440 if (!mp->isPlaying) | |
1441 goto out; | |
1442 | |
1443 // 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
|
1444 for (channel = 0; channel < mp->module->nchannels; channel++) |
0 | 1445 jmpProcessNewRow(mp, channel); |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1446 } // patternDelay |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1447 } // tick |
0 | 1448 else |
1449 { | |
1450 // Implement FT2's pattern delay-effect: don't update effects while on patdelay | |
1451 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
|
1452 (JMPGETMODFLAGS(mp, jmdfFT2Replay) && mp->patternDelay <= 0)) |
0 | 1453 { |
1454 // 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
|
1455 for (channel = 0; channel < mp->module->nchannels; channel++) |
0 | 1456 jmpProcessEffects(mp, channel); |
1457 } | |
1458 } | |
1459 | |
1460 // Check if playing has stopped | |
1461 if (!mp->isPlaying) | |
1462 goto out; | |
1463 | |
1464 // 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
|
1465 for (channel = 0; channel < mp->module->nchannels; channel++) |
0 | 1466 { |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1467 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
|
1468 int flags; |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1469 |
0 | 1470 // Process extended instruments |
61
a33e47232161
Silence some "unused parameter" warnings.
Matti Hamalainen <ccr@tnsp.org>
parents:
55
diff
changeset
|
1471 jmpProcessExtInstrument(chn, channel); |
0 | 1472 |
1473 // 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
|
1474 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
|
1475 if (!flags) |
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
1476 continue; |
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
1477 |
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
1478 // 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
|
1479 if (flags & cdfStop) |
0 | 1480 { |
144
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
1481 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
|
1482 } |
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
1483 else |
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
1484 { |
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
1485 // 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
|
1486 if (flags & cdfNewInstr) |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1487 { |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1488 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
|
1489 if (instr != NULL) |
0 | 1490 { |
144
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
1491 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
|
1492 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
|
1493 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
|
1494 instr->flags); |
0 | 1495 } |
180
bc8019c38ba5
Refactoring of the note triggering and other player logic, fixes various
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
1496 } |
bc8019c38ba5
Refactoring of the note triggering and other player logic, fixes various
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
1497 |
bc8019c38ba5
Refactoring of the note triggering and other player logic, fixes various
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
1498 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
|
1499 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
|
1500 |
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
1501 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
|
1502 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
|
1503 |
b778cc2fe7c8
Create a separate new frequency flag (vs. new pitch), for future changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1504 if (flags & (cdfNewPitch | cdfNewFreq)) |
b778cc2fe7c8
Create a separate new frequency flag (vs. new pitch), for future changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
1505 jvmSetFreq(mp->device, channel, chn->freq); |
0 | 1506 |
144
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
1507 if (flags & cdfNewPos) |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1508 jvmSetPos(mp->device, channel, chn->position); |
0 | 1509 |
144
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
1510 if (flags & cdfNewVolume) |
196
dea742428ac6
Adjust volume ramping logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
195
diff
changeset
|
1511 jmpCSetVolume(mp, chn, channel, chn->volume, flags & (cdfNewInstr | cdfPlay)); |
0 | 1512 |
144
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
1513 if (flags & cdfNewPanPos) |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1514 jmpCSetPanning(mp, chn, channel, chn->panning); |
0 | 1515 |
144
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
1516 if (flags & cdfNewGlobalVol) |
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
1517 jvmSetGlobalVol(mp->device, mp->globalVol); |
0 | 1518 } |
1519 } | |
1520 | |
1521 out: | |
1522 JSS_UNLOCK(mp); | |
1523 } |