This repository was archived by the owner on Mar 6, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.c
1568 lines (1400 loc) · 40.2 KB
/
player.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "pm.h"
/* --------------------------------------------------------------------------------------------------------- */
/* playback */
void song_set_tick_timer(song_t *song)
{
//song->samples_per_tick = song->mixing_rate / (2 * song->tempo / 5);
song->samples_per_tick = (song->mixing_rate * 5) / (song->tempo * 2);
}
void song_set_order(song_t *song, int order, int row)
{
song->process_row = PROCESS_NEXT_ORDER;
song->process_order = order - 1;
song->break_row = row;
song->tick = 1;
song->row_counter = 1;
song_set_tick_timer(song);
}
void song_set_pattern(song_t *song, int pattern, int row)
{
pattern_t *pq;
int i;
/* err... find first entry in order list */
for (i = 0; i < MAX_ORDERS; i++) {
if (song->orderlist[i] == pattern) {
song_set_order(song, i, row);
return;
}
}
/* okay, make something up */
song->process_row = row;
song->process_order = song->cur_order = -1;
song->break_row = row;
song->tick = 1;
song->row_counter = 1;
song->cur_pattern = pattern;
pq = pattern_get(song, song->cur_pattern);
song->pattern_data = pq->data;
song->pattern_rows = pq->rows;
song_set_tick_timer(song);
}
void song_reset_play_state(song_t *song)
{
int n;
song->total_rows_played = 0;
song->avg_rpm = 0;
song->tempo = song->initial_tempo;
song->global_volume = song->initial_global_volume;
song->speed = song->initial_speed;
song->samples_left = 0; /* start of the first tick */
song_set_order(song, 0, 0); /* this sets up the process_* and tick variables */
song->max_voices = 0;
for (n = 0; n < MAX_CHANNELS; n++) {
song->channels[n].channel_volume = song->channels[n].initial_channel_volume;
song->channels[n].panning = song->channels[n].initial_panning;
song->channels[n].nna_note = NOTE_CUT;
song->channels[n].delay = 0;
song->channels[n].last_special = 0;
song->channels[n].last_tempo = song->tempo;
song->channels[n].vibrato_use = SINE_TABLE;
song->channels[n].vibrato_speed = 0;
song->channels[n].vibrato_on = 0;
song->channels[n].vibrato_pos = 0;
song->channels[n].tremelo_use = SINE_TABLE;
song->channels[n].tremelo_speed = 0;
song->channels[n].tremelo_on = 0;
song->channels[n].tremelo_pos = 0;
song->channels[n].panbrello_use = SINE_TABLE;
song->channels[n].panbrello_speed = 0;
song->channels[n].panbrello_on = 0;
song->channels[n].panbrello_pos = 0;
}
for (n = 0; n < MAX_INSTRUMENTS; n++) {
memset(&song->instruments[n].mem_pitch_env, 0, sizeof(envelope_memory_t));
memset(&song->instruments[n].mem_vol_env, 0, sizeof(envelope_memory_t));
memset(&song->instruments[n].mem_pan_env, 0, sizeof(envelope_memory_t));
}
for (n = 0; n < MAX_VOICES; n++)
voice_stop(song->voices + n);
}
/* --------------------------------------------------------------------------------------------------------- */
void channel_past_note_nna(song_t *song, channel_t *channel, int nna)
{
voice_t *v;
int n;
if (song->flags & SONG_INSTRUMENT_MODE) {
if (nna == NNA_CUT) {
for (n = 0; n < channel->num_voices; n++) {
if (channel->voices[n] == channel->fg_voice)
continue;
voice_stop(channel->voices[n]);
}
} else if (nna == NNA_FADE) {
for (n = 0; n < channel->num_voices; n++) {
v = channel->voices[n];
if (v == channel->fg_voice)
continue;
v->noteon = 0;
if (v->inst_bg) {
v->fadeout = v->inst_bg->fadeout;
}
}
} else if (nna == NNA_OFF) {
for (n = 0; n < channel->num_voices; n++) {
v = channel->voices[n];
if (v == channel->fg_voice)
continue;
v->noteon = 0; /* will trigger sustain/etc */
}
}
}
}
void channel_note_nna(song_t *song, channel_t *channel, note_t *note)
{
instrument_t *i;
int nna;
if (!(song->flags & SONG_INSTRUMENT_MODE)) {
if (channel->fg_voice) voice_stop(channel->fg_voice);
} else if (channel->fg_voice) {
i = &song->instruments[ channel->instrument ];
if (note) {
if (note->note == NOTE_CUT) {
nna = NNA_CUT;
} else if (note->note == NOTE_OFF) {
nna = i->nna;
} else if (i->dct == DCT_NOTE) {
if (note->note == channel->nna_note) {
nna = i->dca;
} else {
nna = i->nna;
}
} else if (i->dct == DCT_INSTRUMENT) {
if (note->instrument == channel->instrument) {
nna = i->dca;
} else {
nna = i->nna;
}
} else if (i->dct == DCT_SAMPLE) {
if (song->instruments[note->instrument].sample_map[note->note] == i->sample_map[channel->nna_note]) {
nna = i->dca;
} else {
nna = i->nna;
}
} else {
nna = i->nna;
}
} else {
nna = i->nna;
}
if (nna == NNA_CUT) {
voice_stop(channel->fg_voice);
} else {
voice_t *v;
v = channel->fg_voice;
v->inst_bg = i;
v->noteon = 0;
if (nna == NNA_FADE) {
v->fadeout = i->fadeout;
}
}
channel->fg_voice = 0;
}
}
void channel_set_global_volume(channel_t *channel, int sampvol, int instvol)
{
channel->sample_volume = sampvol;
channel->instrument_volume = instvol;
}
int channel_get_volume(channel_t *c)
{
int vol;
vol = c->volume;
if (!vol) return 0;
if (c->channel_volume != 64) {
vol *= c->channel_volume;
vol >>= 5;
if (!vol) return 0;
}
if (c->instrument_volume != 128) {
vol *= c->instrument_volume;
vol >>= 6;
if (!vol) return 0;
}
if (c->sample_volume != 128) {
vol *= c->sample_volume;
vol >>= 6;
if (!vol) return 0;
}
return vol;
}
void channel_set_volume(channel_t *channel, int volume)
{
channel->volume = volume;
if (channel->fg_voice)
voice_set_volume(channel->fg_voice, channel_get_volume(channel));
}
void channel_set_channel_volume(channel_t *channel, int volume)
{
int n;
channel->channel_volume = volume;
/* need to update volume for ALL voices on the channel */
for (n = 0; n < channel->num_voices; n++)
voice_set_volume(channel->voices[n], channel_get_volume(channel));
}
void channel_set_panning(channel_t *channel, int panning)
{
channel->panning = panning;
if (channel->fg_voice)
voice_set_panning(channel->fg_voice, channel->panning);
}
void channel_link_voice(channel_t *channel, voice_t *voice)
{
int i;
channel->fg_voice = voice;
for (i = 0; i < MAX_VOICES; i++)
if (!channel->voices[i]) {
channel->voices[i] = voice;
channel->num_voices++;
break;
}
voice->host = channel;
voice->realnote = channel->realnote;
voice->c5speed = channel->c5speed;
}
void process_note(song_t *song, channel_t *channel, note_t *note)
{
voice_t *voice;
sample_t *sample = NULL;
if (note->instrument) {
/* if the instrument changed, restart it from the beginning
(this *should* trigger a new voice if there's nothing playing in the channel,
which would require saving the last used note) */
if (channel->instrument != note->instrument) {
if (channel->fg_voice)
voice_set_position(channel->fg_voice, 0);
/* remember the number */
channel->instrument = note->instrument;
}
}
if (note->note == NOTE_CUT || note->note == NOTE_OFF) {
channel_note_nna(song, channel, note);
} else if (note->note <= NOTE_LAST) {
int noteval;
if (!channel->instrument) {
/* darn, nothing to play */
return;
}
if (song->flags & SONG_INSTRUMENT_MODE) {
int n = song->instruments[channel->instrument].sample_map[note->note];
noteval = song->instruments[channel->instrument].note_map[note->note];
if (n && noteval <= NOTE_LAST) {
sample = song->samples + n;
} else {
/* no sample or note? well then let's just give up and not care */
return;
}
} else {
sample = song->samples + channel->instrument;
noteval = note->note;
}
if (!sample->data) {
/* undefined sample -> note cut (this should be up above, really) */
printf("no data!\n");
if (channel->fg_voice) voice_stop(channel->fg_voice);
return;
}
channel->c5speed = sample->c5speed;
/* this is probably the worst method; for G/L effects we always "target" the slide
but we can't touch the original note. that slide data comes during global effect
handling. this fg_voice check is to make sure we kick off a new voice if nothing's playing
and otherwise pretend the G/L effect wasn't there...
it's ugly, but it's probably the easiest way to do this... */
if (channel->fg_voice && (note->effect == 'G' || note->effect == 'L'
|| (note->volume >= 193 && note->volume <= 202))) {
/* slide to note; will be handled later */
channel->fg_voice->destnote = noteval;
/* TODO: if the sample changed, do the funky chicken dance */
} else if (channel->instrument) {
/* start playing the note */
channel->realnote = noteval;
channel_note_nna(song, channel, note);
/* replace MAX_VOICES here with the set number of mixing channels. */
voice = voice_find_free(song->voices, MAX_VOICES);
if (voice) {
channel_link_voice(channel, voice);
voice_start(voice, sample);
voice->realnote = voice->destnote = noteval;
}
channel_set_global_volume(channel,
sample->global_volume << 1,
song->flags & SONG_INSTRUMENT_MODE
? song->instruments[note->instrument].global_volume
: 128);
if (song->flags & SONG_INSTRUMENT_MODE) {
instrument_t *inst;
int pan, vol;
inst = &song->instruments[note->instrument];
vol = sample->volume;
if (inst->flags & INST_USE_PANNING) {
pan = inst->panning +
(noteval - (int)(inst->pitch_pan_center))
* (inst->pitch_pan_separation/8);
if (inst->rand_pan_var && pan) {
pan = ((64-(rand()
% inst->rand_pan_var)) * pan) / 64;
}
channel_set_panning(channel, pan);
}
if (inst->rand_vol_var && vol) {
vol = ((100-(rand()
% inst->rand_vol_var)) * vol) / 100;
}
channel_set_volume(channel, vol);
} else {
channel_set_volume(channel, sample->volume);
channel_set_panning(channel,
channel->panning);
}
}
}
channel->nna_note = note->note;
}
static void fx_global_volume_slide(song_t *song, int amount)
{
amount += song->global_volume;
song->global_volume = CLAMP(amount, 0, 128);
}
static void fx_panning_slide(channel_t *channel, int amount)
{
amount += channel->panning;
channel_set_panning(channel, CLAMP(amount, 0, 64));
}
static void fx_volume_slide(channel_t *channel, int amount)
{
amount += channel->volume;
channel_set_volume(channel, CLAMP(amount, 0, 64));
}
static void fx_channel_volume_slide(channel_t *channel, int amount)
{
amount += channel->channel_volume;
channel_set_channel_volume(channel, CLAMP(amount, 0, 64));
}
static void fx_tone_slide(channel_t *channel, int g)
{
if (channel->fg_voice) channel->fg_voice->slide += g;
}
static void fx_tone_slide_to_note(channel_t *channel)
{
if (channel->fg_voice) channel->fg_voice->toneto = channel->pitch_slide << 4;
}
static void fx_tone_portamento(channel_t *channel, int delta)
{
if (channel->fg_voice) channel->fg_voice->portamento += ((channel->pitch_slide << 4) * delta);
}
#define SPLIT_PARAM(param, px, py) ({px = param >> 4; py = param & 0xf;})
static void process_direct_effect_tick0(song_t *song, channel_t *channel,
int effect, int param)
{
int px, py;
switch (effect) {
case 'D': /* volume slide */
case 'K':
case 'L':
if (param)
channel->volume_slide = param;
SPLIT_PARAM(channel->volume_slide, px, py);
if (py == 0) {
/* Dx0 (only slide on tick 0 if x == 0xf) */
if (px == 0xf)
fx_volume_slide(channel, 15);
} else if (px == 0) {
/* D0x (only slide on tick 0 if x == 0xf) */
if (py == 0xf)
fx_volume_slide(channel, -15);
} else if (py == 0xf) {
/* DxF */
fx_volume_slide(channel, px);
} else if (px == 0xf) {
/* DFx */
fx_volume_slide(channel, -py);
}
break;
case 'E': /* pitch slide down */
if (param) {
channel->pitch_slide = param;
if (!(song->flags & SONG_COMPAT_GXX))
channel->portamento = param;
}
switch (channel->pitch_slide >> 4) {
case 0xe:
fx_tone_slide(channel, (channel->pitch_slide & 15) << 2);
channel->flags |= CHAN_FINE_SLIDE;
break;
case 0xf:
fx_tone_slide(channel, (channel->pitch_slide & 15) << 4);
channel->flags |= CHAN_FINE_SLIDE;
break;
default:
channel->flags &= ~CHAN_FINE_SLIDE;
}
break;
case 'F': /* pitch slide up */
if (param) {
channel->pitch_slide = param;
if (!(song->flags & SONG_COMPAT_GXX))
channel->portamento = param;
}
switch (channel->pitch_slide >> 4) {
case 0xe:
fx_tone_slide(channel, -((channel->pitch_slide & 15) << 2));
channel->flags |= CHAN_FINE_SLIDE;
break;
case 0xf:
fx_tone_slide(channel, -((channel->pitch_slide & 15) << 4));
channel->flags |= CHAN_FINE_SLIDE;
break;
default:
channel->flags &= ~CHAN_FINE_SLIDE;
}
break;
case 'G': /* pitch slide to note */
if (param) {
channel->portamento = param;
if (!(song->flags & SONG_COMPAT_GXX)) {
channel->pitch_slide = param;
if ((param >> 4) >= 0xe)
channel->flags |= CHAN_FINE_SLIDE;
else
channel->flags &= ~CHAN_FINE_SLIDE;
}
}
break;
case 'P': /* pan slide */
if (param) channel->panning_slide = param;
SPLIT_PARAM(channel->panning_slide, px, py);
if (py == 0) {
/* Px0 (only slide on tick 0 if x == 0xf) */
if (px == 0xf)
fx_panning_slide(channel, 15);
} else if (px == 0) {
/* P0x (only slide on tick 0 if x == 0xf) */
if (py == 0xf)
fx_panning_slide(channel, -15);
} else if (py == 0xf) {
/* PxF */
fx_panning_slide(channel, px);
} else if (px == 0xf) {
/* PFx */
fx_panning_slide(channel, -py);
}
break;
case 'W': /* global volume slide */
if (param) channel->global_volume_slide = param;
SPLIT_PARAM(channel->global_volume_slide, px, py);
if (py == 0) {
/* Wx0 (only slide on tick 0 if x == 0xf) */
if (px == 0xf)
fx_global_volume_slide(song, 15);
} else if (px == 0) {
/* W0x (only slide on tick 0 if x == 0xf) */
if (py == 0xf)
fx_global_volume_slide(song, -15);
} else if (py == 0xf) {
/* WxF */
fx_global_volume_slide(song, px);
} else if (px == 0xf) {
/* WFx */
fx_global_volume_slide(song, -py);
}
break;
};
/* vibrato setup */
switch (effect) {
case 'H':
if (param) channel->vibrato_effect = param;
/* fall through */
case 'K':
SPLIT_PARAM(channel->vibrato_effect, px, py);
channel->vibrato_speed = px << 2;
channel->vibrato_depth = py << 2;
if (song->flags & SONG_OLD_EFFECTS)
channel->vibrato_depth <<= 1;
channel->vibrato_on = 1;
break;
case 'U':
if (param) channel->vibrato_effect = param;
SPLIT_PARAM(channel->vibrato_effect, px, py);
channel->vibrato_speed = px << 2;
channel->vibrato_depth = py;
if (song->flags & SONG_OLD_EFFECTS)
channel->vibrato_depth <<= 1;
channel->vibrato_on = 1;
break;
};
/* tremelo setup */
if (effect == 'R') {
if (param) channel->tremelo_effect = param;
SPLIT_PARAM(channel->tremelo_effect, px, py);
channel->tremelo_speed = px << 2;
channel->tremelo_depth = py << 2;
if (song->flags & SONG_OLD_EFFECTS)
channel->tremelo_depth <<= 1;
channel->tremelo_on = 1;
}
/* panbrello setup */
if (effect == 'Y') {
if (param) channel->panbrello_effect = param;
SPLIT_PARAM(channel->panbrello_effect, px, py);
channel->panbrello_speed = px << 2;
channel->panbrello_depth = py << 2;
if (song->flags & SONG_OLD_EFFECTS)
channel->panbrello_depth <<= 1;
channel->panbrello_on = 1;
};
}
void process_volume_tick0(song_t *song, channel_t *channel, note_t *note)
{
switch (note->volume) {
case VOL_NONE:
return;
case (0)...(64):
channel_set_volume(channel, note->volume);
break;
case (128)...(192):
channel_set_panning(channel, note->volume - 128);
break;
case (65)...(74):
/* fine volume slide up; d?f */
process_direct_effect_tick0(song, channel, 'D',
((note->volume - 65) << 4) | 0x0f);
break;
case (75)...(84):
/* fine volume slide down df? */
process_direct_effect_tick0(song, channel, 'D',
(note->volume - 75) | 0xf0);
break;
case (85)...(94):
/* volume slide up d?0 */
process_direct_effect_tick0(song, channel, 'D',
((note->volume - 85) << 4));
break;
case (95)...(104):
/* volume slide down d0? */
process_direct_effect_tick0(song, channel, 'D',
((note->volume - 95)));
break;
case (105)...(114):
/* pitch slide down e?? value*4 */
process_direct_effect_tick0(song, channel, 'E',
(note->volume - 105) << 2);
break;
case (115)...(124):
/* pitch slide up f?? */
process_direct_effect_tick0(song, channel, 'F',
(note->volume - 115) << 2);
break;
case (193)...(202):
/* portamento to GX_SLIDE_TABLE */
process_direct_effect_tick0(song, channel, 'G',
GX_SLIDE_TABLE[ note->volume - 193 ]);
break;
case (203)...(212):
/* vibrato */
process_direct_effect_tick0(song, channel, 'H',
(note->volume - 203) << 2);
break;
default:
TODO("volume column effect %d", note->volume);
}
}
void process_effects_tick0(song_t *song, channel_t *channel, note_t *note)
{
int effect = note->effect, param = note->param, px, py;
/* volume column */
process_volume_tick0(song, channel, note);
/* effects */
switch (effect) {
case 0: /* nothing */
break;
case 'A': /* set speed */
if (param)
song->speed = param;
song->tick = song->speed;
break;
case 'B': /* pattern jump */
/* if song looping is disabled, only change the order if it's beyond the current position */
if (song->flags & SONG_LOOP_PATTERN) break;
if (song->flags & SONG_LOOP || param > song->cur_order)
song->process_order = param - 1;
song->process_row = PROCESS_NEXT_ORDER;
break;
case 'C': /* pattern break */
SPLIT_PARAM(param, px, py);
song->process_row = PROCESS_NEXT_ORDER;
song->break_row = px * 10 + py;;
break;
case 'J': /* arpeggio */
SPLIT_PARAM(param, px, py);
if (param) channel->arpmem = param;
break;
case 'Q':
if (param & 0x0F) {
channel->q_retrig &= 0xF0;
channel->q_retrig |= (param & 0x0F);
}
if (param & 0xF0) {
channel->q_retrig &= 0x0F;
channel->q_retrig |= (param & 0xF0);
}
break;
case 'K': /* vol slide + continue vibrato */
case 'L': /* vol slide + continue pitch slide */
case 'D': /* volume slide */
case 'E': /* pitch slide down */
case 'F': /* pitch slide up */
case 'G': /* pitch slide to note */
case 'H': /* vibrato */
case 'U': /* FINE vibrato */
case 'R': /* tremelo */
case 'Y': /* panbrello :) */
case 'P': /* pan slide commands */
case 'W': /* global volume slide commands */
process_direct_effect_tick0(song, channel, effect, param);
break;
case 'I': /* tremor */
if (param & 0xf0 && param & 0x0f) {
channel->tremor_tick = channel->tremor_set = param;
}
if (channel->fg_voice)
voice_set_volume(channel->fg_voice,
channel_get_volume(channel));
break;
case 'M': /* set channel volume */
if (param <= 64)
channel_set_channel_volume(channel, param);
break;
case 'N': /* channel volume slide */
if (param)
channel->channel_volume_slide = param;
SPLIT_PARAM(channel->channel_volume_slide, px, py);
if (py == 0) {
/* Nx0 (only slide on tick 0 if x == 0xf) */
if (px == 0xf)
fx_channel_volume_slide(channel, 15);
} else if (px == 0) {
/* N0x (only slide on tick 0 if y == 0xf) */
if (py == 0xf)
fx_channel_volume_slide(channel, -15);
} else if (py == 0xf) {
/* NxF */
fx_channel_volume_slide(channel, px);
} else if (px == 0xf) {
/* NFx */
fx_channel_volume_slide(channel, -py);
}
break;
case 'O': /* offset */
if (note->note <= NOTE_LAST) {
if (param)
channel->offset = param << 8;
if (channel->fg_voice)
voice_set_position(channel->fg_voice, channel->offset);
}
break;
case 'S': /* special */
if (param == 0) {
param = channel->last_special;
} else {
channel->last_special = param;
}
switch (param >> 4) {
case 0x3:
channel->vibrato_use = TABLE_SELECT[(param & 0x0f) % 4];
break;
case 0x4:
channel->tremelo_use = TABLE_SELECT[(param & 0x0f) % 4];
break;
case 0x5:
channel->panbrello_use = TABLE_SELECT[(param & 0x0f) % 4];
break;
case 0x6:
/* haven't tested this much, but it should work ok */
song->tick += param & 0xf;
break;
case 0x7:
switch (param & 0xf) {
case 0: /* past note cut */
channel_past_note_nna(song, channel, NNA_CUT);
break;
case 1:
channel_past_note_nna(song, channel, NNA_OFF);
break;
case 2:
channel_past_note_nna(song, channel, NNA_FADE);
break;
case 3: /* set nna for this note to NNA_CUT */
case 4: /* set nna for this note to NNA_CONTINUE */
case 5: /* set nna for this note to NNA_OFF */
case 6: /* set nna for this note to NNA_FADE */
case 7: /* turn off volenv off (until S78) */
case 8: /* turn off volenv back on */
break;
};
break;
case 0x8:
channel_set_panning(channel, SHORT_PANNING[param & 0xf]);
break;
case 0x9:
/* nothing but surround processor */
if (song->flags & SONG_NO_SURROUND)
channel_set_panning(channel, 32);
else
channel_set_panning(channel, PAN_SURROUND);
break;
case 0xa:
/* high order offset */
channel->offset &= 0xF0000;
channel->offset |= (param & 0x0f) << 16;
if (channel->fg_voice)
voice_set_position(channel->fg_voice, channel->offset);
break;
case 0xb: /* pattern loop */
if (param & 0xf) {
/* SBx: loop to point */
/* I can't believe the amount of time I put into this effect. It finally
seems to handle the effect the same way Impulse Tracker does, but I wouldn't
be surprised if there are still some obscure bugs. Note: AFAIK, Bass is the
*only* player besides Impulse Tracker that plays this effect 100% accurately.
Mikmod gets some weird cases wrong, and I won't even get into how badly
Modplug screws it up. */
if (channel->loop_count)
channel->loop_count--;
else
channel->loop_count = param & 0xf;
if (channel->loop_count)
song->process_row = channel->loop_row - 1;
else
channel->loop_row = song->cur_row + 1;
} else {
/* SB0: set loopback point */
channel->loop_row = song->cur_row;
}
break;
case 0xc:
if (!(param & 0x0f)) {
/* IT says SC0 == SC1 */
channel->last_special = 0xC1;
}
break;
case 0xd:
/* sadly; handled elsewhere. search for: SDx */
break;
case 0xe:
/* whole pattern delay */
song->tick += (param & 0x0F) * song->speed;
break;
default:
TODO("effect S%02X", param);
}
break;
case 'T': /* set tempo / tempo slide */
if (param)
channel->last_tempo = param;
else
param = channel->last_tempo;
if (param > 0x1f) {
/* set tempo */
song->tempo = param;
song_set_tick_timer(song);
}
break;
case 'V': /* set global volume */
if (note->param <= 0x80) {
song->global_volume = note->param;
}
break;
case 'X': /* set panning */
/* Panning values are 0..64 internally, so convert the value to the proper range */
channel_set_panning(channel, param * 64 / 255);
break;
default: /* unhandled effect */
TODO("effect %c%02X", effect, param);
break;
}
}
static void process_direct_effect_tickN(song_t *song, channel_t *channel,
int effect)
{
int px, py;
switch (effect) {
case 'D': /* volume slide */
SPLIT_PARAM(channel->volume_slide, px, py);
if (py == 0) {
fx_volume_slide(channel, px);
} else if (px == 0) {
fx_volume_slide(channel, -py);
}
break;
case 'E': /* pitch slide down */
if (!(channel->flags & CHAN_FINE_SLIDE))
fx_tone_portamento(channel, 1);
break;
case 'F': /* pitch slide up */
if (!(channel->flags & CHAN_FINE_SLIDE))
fx_tone_portamento(channel, -1);
break;
case 'G': /* pitch slide to note */
fx_tone_slide_to_note(channel);
break;
case 'P': /* panning slide */
SPLIT_PARAM(channel->panning_slide, px, py);
if (py == 0) {
fx_panning_slide(channel, px);
} else if (px == 0) {
fx_panning_slide(channel, -py);
}
break;
case 'W': /* global volume slide */
SPLIT_PARAM(channel->global_volume_slide, px, py);
if (py == 0) {
fx_global_volume_slide(song, px);
} else if (px == 0) {
fx_global_volume_slide(song, -py);
}
break;
};
}
void process_volume_tickN(song_t *song, channel_t *channel, note_t *note)
{
switch (note->volume) {
case VOL_NONE:
return;
case (0)...(64):
break;
case (128)...(192):
break;
case (65)...(74):
case (75)...(84):
case (85)...(94):
case (95)...(104):
/* D commands */
process_direct_effect_tickN(song, channel, 'D');
break;
case (105)...(114):
/* pitch slide down e?? value*4 */
process_direct_effect_tickN(song, channel, 'E');
break;
case (115)...(124):
/* pitch slide up f?? */
process_direct_effect_tickN(song, channel, 'F');
break;
case (193)...(202):
/* portamento to GX_SLIDE_TABLE */
process_direct_effect_tickN(song, channel, 'G');
break;
case (203)...(212):
/* vibrato */
process_direct_effect_tickN(song, channel, 'H');
break;
default:
break;
}
}
void process_effects_tickN(song_t *song, channel_t *channel, note_t *note)
{
/* This could be done a lot more cleanly by setting flags for each effect on the channel:
for D/K/L set the volume slide flag, for H/K set the vibrato flag, etc. */
/* hm. probably shouldn't be using note->param on tickN, especially
for effects that remember their parameters */
int rnnote;
int effect = note->effect, px, py;
/* do arp first; it affects period */
if (effect == 'J') {
switch ((song->speed - song->tick) % 3) {
case 0:
rnnote = channel->realnote;
break;
case 1:
rnnote = channel->realnote + (channel->arpmem >> 4);
break;
case 2:
rnnote = channel->realnote + (channel->arpmem & 15);
break;
};
if (channel->fg_voice) {
/* TODO does J+G do anything fun? */
channel->fg_voice->destnote = channel->fg_voice->realnote = rnnote;
}
}
/* volume column */
process_volume_tickN(song, channel, note);
/* effects */
switch (effect) {
case 0:
break;
case 'L': /* vol slide + continue pitch slide */
fx_tone_slide_to_note(channel);
/* fall through */
case 'D': /* volume slide */
case 'K': /* vol slide + continue vibrato */
process_direct_effect_tickN(song, channel, 'D');
if (effect == 'D') break;
case 'I': /* tremor */
if (channel->tremor_tick & 0xF0) {
channel->tremor_tick -= 0x10;
if ((channel->tremor_tick & 0xF0) == 0) {
/* mute */
if (channel->fg_voice)
voice_set_volume(channel->fg_voice, 0);
}
} else {
channel->tremor_tick --;