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