player_commands.c
16.7 KB
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
/********************************************************************
player_commands.c : Nintendo 64 Music Tools Programmers Library
(c) Copyright 1997/1998, Software Creations (Holdings) Ltd.
Version 3.14
Music player command functions. This file is included in the
'player.c' file directly.
*********************************************************************/
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Music Tools Sound Data Command Functions
[Parameters]
cp address of music player channel
ptr address of sound data
[Explanation]
Command functions for the commands embedded in the Music Tools sound data.
[Return value]
address of sound data after the command
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
/* NOTE THESE FUNCTIONS ARE ENTERED WITH THE POINTER ALREADY BEING ADVANCED PAST
THE COMMAND <cmd> VALUE */
/* Fstop - stop data processing
* Format: <cmd>
*/
static unsigned char *Fstop(channel_t *cp, unsigned char *ptr)
{
cp->pvolume = NULL;
cp->ppitchbend = NULL;
cp->song_addr = NULL;
cp->fx_addr = NULL;
cp->handle = 0;
cp->pending = NULL;
return (NULL);
}
/* Fwave - set wave number to be played
* Format: <cmd> <wave> or <cmd> <wave&0x7F00> <wave&0xFF)
*/
static unsigned char *Fwave(channel_t *cp, unsigned char *ptr)
{
unsigned short wave;
wave = *ptr++;
if(wave&0x80)
{
wave &= 0x7f;
wave <<= 8;
wave |= *ptr++;
}
cp->wave = wave;
return (ptr);
}
/* Fport - enable portamento
* Format: <cmd> <portamento>
*/
static unsigned char *Fport(channel_t *cp, unsigned char *ptr)
{
cp->port = *ptr++;
if (cp->port)
cp->port_base = cp->base_note;
return (ptr);
}
/* Fportoff - disable portamento
* Format: <cmd>
*/
static unsigned char *Fportoff(channel_t *cp, unsigned char *ptr)
{
cp->port = 0;
return (ptr);
}
/* Fdefa - set envelope
* Format: <cmd> <speed> <initial volume> <attack speed> <peak volume>
* <decay speed> <sustain volume> <release speed>
*/
static unsigned char *Fdefa(channel_t *cp, unsigned char *ptr)
{
unsigned char value;
// get envelope speed...
value = *ptr++;
if (value==0) // cannot be zero!!!
value=1;
cp->env_speed = value;
cp->env_speed_calc = 1024/value;
// get envelope initial volume level...
cp->env_init_vol = *ptr++;
// get attack speed...
value = *ptr++;
#ifdef _AUDIODEBUG
if (value==0)
{
osSyncPrintf("PLAYER_COMMANDS.C: Fdefa() attempting to set speed of zero.\n");
value=1;
}
#endif
cp->env_attack_speed = value;
// get peak volume...
cp->env_max_vol = *ptr++;
// get attack precalc value...
cp->env_attack_calc = (1.0 / ((float)value)) * ((float)(cp->env_max_vol-cp->env_init_vol));
// get decay speed...
value = *ptr++;
#ifdef _AUDIODEBUG
if (value==0)
{
osSyncPrintf("PLAYER_COMMANDS.C: Fdefa() attempting to set decay speed of zero.\n");
value=1;
}
#endif
cp->env_decay_speed = value;
// get sustain volume level...
cp->env_sustain_vol = *ptr++;
// get sustain precalc value...
cp->env_decay_calc = (1.0 / ((float)value)) * ((float)(cp->env_sustain_vol-cp->env_max_vol));
// get release speed...
value = *ptr++;
#ifdef _AUDIODEBUG
if (value==0)
{
osSyncPrintf("PLAYER_COMMANDS.C: Fdefa() attempting to set release speed of zero.\n");
value=1;
}
#endif
cp->env_release_speed = value;
cp->env_release_calc = 1.0 / ((float)value);
return (ptr);
}
/* Ftempo - set tempo
* Format: <cmd> <tempo>
*/
static unsigned char *Ftempo(channel_t *cp, unsigned char *ptr)
{
// tempo = bpm
// fps = mus_vsyncs_per_second
// 120 bpm = 96 fps
// therefore tempo = bmp(required)/120*96/mus_vsyncs_per_second
channel_t *sp;
int i;
int temp, temp2;
temp = (*ptr++)*256*96/120/mus_vsyncs_per_second;
temp2 = (temp*cp->temscale)>>7;
if (cp->fx_addr)
{
cp->channel_tempo=temp;
}
else
{
for (i=0, sp=mus_channels;i<max_channels;i++,sp++)
{
if (sp->song_addr==cp->song_addr)
{
sp->channel_tempo_save=temp;
sp->channel_tempo=temp2;
}
}
}
return (ptr);
}
/* Ftempo - set endit value
* Format: <cmd> <endit>
*/
static unsigned char *Fendit(channel_t *cp, unsigned char *ptr)
{
cp->endit=*ptr++;
cp->cutoff=0;
return (ptr);
}
/* Fcutoff - set cutoff value
* Format: <cmd> <cutoff&0xFF00> <cutoff&0xFF>
*/
static unsigned char *Fcutoff(channel_t *cp, unsigned char *ptr)
{
short tmp;
tmp = (*ptr++)<<8;
tmp |= *ptr++;
cp->cutoff = tmp;
cp->endit = 0;
return (ptr);
}
/* Fvibup - set positive vibrato
* Format: <cmd> <delay> <speed> <amount>
*/
static unsigned char *Fvibup(channel_t *cp, unsigned char *ptr)
{
cp->vib_delay = *ptr++;
cp->vib_speed = *ptr++;
cp->vib_amount = ((float)*ptr++)/50.0;
cp->vib_precalc = (2*3.1415926)/(float)cp->vib_speed;
return (ptr);
}
/* Fvibdown - set negative vibrato
* Format: <cmd> <delay> <speed> <amount>
*/
static unsigned char *Fvibdown(channel_t *cp, unsigned char *ptr)
{
cp->vib_delay = *ptr++;
cp->vib_speed = *ptr++;
cp->vib_amount = (-((float)*ptr++))/50.0;
cp->vib_precalc = (2*3.1415926)/(float)cp->vib_speed;
return (ptr);
}
/* Fviboff - disable vibrato
* Format: <cmd>
*/
static unsigned char *Fviboff(channel_t *cp, unsigned char *ptr)
{
cp->vib_speed=0;
cp->vibrato=0; // if its been switched off you want it back to a normal note
return (ptr);
}
/* Flength - set fixed length
* Format: <cmd> <length> or <cmd> <length&0x7F00> <length&0xFF)
*/
static unsigned char *Flength(channel_t *cp, unsigned char *ptr)
{
int length;
length = *ptr++;
if (length>=0x80)
{
length &= 0x7f;
length <<= 8;
length |= *ptr++;
}
cp->fixed_length = length;
return (ptr);
}
/* Fignore - set ignore length flag
* Format: <cmd>
*/
static unsigned char *Fignore(channel_t *cp, unsigned char *ptr)
{
cp->ignore = 1;
return (ptr);
}
/* Ftranspose - set transpose value
* Format: <cmd> <transpose>
*/
static unsigned char *Ftrans(channel_t *cp, unsigned char *ptr)
{
cp->transpose = *ptr++;
return (ptr);
}
/* Fignore_trans - set ignore transpose flag
* Format: <cmd>
*/
static unsigned char *Fignore_trans(channel_t *cp, unsigned char *ptr)
{
cp->ignore_transpose = 1;
return (ptr);
}
/* Fdistort - set distortion value
* Format: <cmd> <distort>
*/
static unsigned char *Fdistort(channel_t *cp, unsigned char *ptr)
{
int c;
float f;
c = (int)(*ptr++);
if(c&0x80)
c |= 0xffffff00; // signed chars don't work
f = (float)(c)/100.0;
cp->freqoffset -= cp->distort;
cp->freqoffset += f;
cp->distort = f;
return (ptr);
}
/* Fenvelope - set envelope from envelope table
* Format: <cmd> <index> or <cmd> <index&0x7F00> <index&0xFF)
*/
static unsigned char *Fenvelope(channel_t *cp, unsigned char *ptr)
{
int tmp;
tmp = *ptr++;
if(tmp&0x80)
{
tmp &= 0x7f;
tmp <<= 8;
tmp |= *ptr++;
}
(void)Fdefa(cp, &cp->song_addr->env_table[tmp*7]);
return (ptr);
}
/* Fenvoff - disable envelopes
* Format: <cmd>
*/
static unsigned char *Fenvoff(channel_t *cp, unsigned char *ptr)
{
cp->env_trigger_off = 1;
return (ptr);
}
/* Fenvoff - enable envelopes
* Format: <cmd>
*/
static unsigned char *Fenvon(channel_t *cp, unsigned char *ptr)
{
cp->env_trigger_off = 0;
return (ptr);
}
/* Ftroff - disable triggering
* Format: <cmd>
*/
static unsigned char *Ftroff(channel_t *cp, unsigned char *ptr)
{
cp->trigger_off = 1;
return (ptr);
}
/* Ftron - enable triggering
* Format: <cmd>
*/
static unsigned char *Ftron(channel_t *cp, unsigned char *ptr)
{
cp->trigger_off = 0;
return (ptr);
}
/* Ffor - start for-next loop (count of 0xFF is infinite)
* Format: <cmd> <count>
*/
static unsigned char *Ffor(channel_t *cp, unsigned char *ptr)
{
int index;
index = cp->for_stack_count;
cp->for_count[index] = *ptr++;
cp->for_stack[index] = ptr;
cp->for_stackvol[index] = cp->pvolume;
cp->for_stackpb[index] = cp->ppitchbend;
cp->for_volume[index] = cp->volume;
cp->for_pitchbend[index] = cp->pitchbend;
cp->for_vol_count[index] = cp->cont_vol_repeat_count;
cp->for_pb_count[index] = cp->cont_pb_repeat_count;
cp->for_stack_count++;
return (ptr);
}
/* Fnext - end for-next loop (count of 0xFF is infinite)
* Format: <cmd>
*/
static unsigned char *Fnext (channel_t *cp, unsigned char *ptr)
{
int index;
index = cp->for_stack_count-1;
/* infinite loop? */
if (cp->for_count[index]!=0xff)
{ /* still looping? */
if (--(cp->for_count[index])==0)
{
cp->for_stack_count = index;
index = -1;
}
}
/* unstack pointers if necessary */
if (index>-1)
{
ptr = cp->for_stack[index];
cp->pvolume = cp->for_stackvol[index];
cp->ppitchbend = cp->for_stackpb[index];
cp->volume = cp->for_volume[index];
cp->pitchbend = cp->for_pitchbend[index];
cp->cont_vol_repeat_count = cp->for_vol_count[index];
cp->cont_pb_repeat_count = cp->for_pb_count[index];
cp->pitchbend_precalc = cp->pitchbend*cp->bendrange;
}
return (ptr);
}
/* Fwobble - define wobble settings
* Format: <cmd> <amount> <on speed> <off speed>
*/
static unsigned char *Fwobble(channel_t *cp, unsigned char *ptr)
{
cp->wobble_amount = *ptr++;
cp->wobble_on_speed = *ptr++;
cp->wobble_off_speed = *ptr++;
return(ptr);
}
/* Fwobble - disable wobble
* Format: <cmd>
*/
static unsigned char *Fwobbleoff(channel_t *cp, unsigned char *ptr)
{
cp->wobble_on_speed = 0;
return (ptr);
}
/* Fvelon - enable velocity mode
* Format: <cmd>
*/
static unsigned char *Fvelon(channel_t *cp, unsigned char *ptr)
{
cp->velocity_on = 1;
return (ptr);
}
/* Fvelon - disable velocity mode
* Format: <cmd>
*/
static unsigned char *Fveloff(channel_t *cp, unsigned char *ptr)
{
cp->velocity_on = 0;
return (ptr);
}
/* Fvelon - enable default velocity mode
* Format: <cmd> <default velocity>
*/
/* default velocity map */
static unsigned char *Fvelocity(channel_t *cp, unsigned char *ptr)
{
cp->default_velocity = *ptr++;
cp->velocity_on = 0;
return (ptr);
}
/* Fpan - set pan position
* Format: <cmd> <pan*2>
*/
static unsigned char *Fpan(channel_t *cp, unsigned char *ptr)
{
cp->pan = (*ptr++)/2;
return (ptr);
}
/* Fstereo - OUTDATED
* Format: <cmd> <ignored> <ignored>
*/
static unsigned char *Fstereo(channel_t *cp, unsigned char *ptr)
{
return (ptr+2);
}
/* Fdrums - enable drum data
* Format: <cmd> <index>
* Format: <cmd> <index> or <cmd> <index&0x7F00> <index&0xFF)
*/
static unsigned char *Fdrums(channel_t *cp, unsigned char *ptr)
{
int index;
index = *ptr++;
if (index>=0x80)
{
index &=0x7f;
index <<=8;
index |= *ptr++;
}
cp->pdrums = &cp->song_addr->drum_table[index];
return (ptr);
}
/* Fdrumsoff - disable drum data
* Format: <cmd>
*/
static unsigned char *Fdrumsoff(channel_t *cp, unsigned char *ptr)
{
cp->pdrums = NULL;
return (ptr);
}
/* Fprint - display debugging info (DEBUG MODE ONLY!!!)
* Format: <cmd> <data to print>
*/
static unsigned char *Fprint(channel_t *cp, unsigned char *ptr)
{
#ifdef _AUDIODEBUG
osSyncPrintf("PLAYER_COMMANDS.C: Fprint() - %d (channel frame=%d)\n", *ptr++, cp->channel_frame);
return (ptr);
#else
ptr++;
return (ptr);
#endif
}
/* Fgoto - sound data ptr relative jump
* Format: <cmd> <song data offset&0xFF00> <song data offset&0xFF>
* <volume data offset&0xFF00> <volume data offset&0xFF>
* <pitchbend data offset&0xFF00> <pitchbend data offset&0xFF>
*/
static unsigned char *Fgoto(channel_t *cp, unsigned char *ptr)
{
int off, off1;
/* 2 bytes for song offset */
off1 = *ptr++<<8;
off1 += *ptr++;
/* get volume offset BEFORE updating pointer */
/* 2 bytes for volume offset (never inside a run length bit) */
off = *ptr++<<8;
off += *ptr++;
cp->pvolume = cp->pvolumebase+off;
cp->cont_vol_repeat_count = 1;
/* get pitchbend offset BEFORE updating pointer */
/* 2 bytes for pitchbend offset (never inside a run length bit) */
off = *ptr++<<8;
off += *ptr++;
cp->ppitchbend = cp->ppitchbendbase+off;
cp->cont_pb_repeat_count = 1;
return (cp->pbase+off1);
}
/* Freverb - set reverb value
* Format: <cmd> <reverb>
*/
static unsigned char *Freverb(channel_t *cp, unsigned char *ptr)
{
cp->reverb = *ptr++;
return (ptr);
}
/* FrandNote - set random transpose (within a range)
* Format: <cmd> <range> <offset>
*/
static unsigned char *FrandNote(channel_t *cp, unsigned char *ptr)
{
// rand_amount,rand_base -- 20,-3 would give -3 to 16 as the value
cp->transpose = __MusIntRandom(*ptr++);
cp->transpose += *ptr++;
return (ptr);
}
/* FrandVolume - set random volume level
* Format: <cmd> <range> <offset>
*/
static unsigned char *FrandVolume(channel_t *cp, unsigned char *ptr)
{
// rand_amount,base
cp->volume = __MusIntRandom(*ptr++);
cp->volume += *ptr++;
return (ptr);
}
/* FrandPan - set random pan position
* Format: <cmd> <range> <offset>
*/
static unsigned char *FrandPan(channel_t *cp, unsigned char *ptr)
{
// rand_amount,base
cp->pan = __MusIntRandom(*ptr++);
cp->pan += *ptr++;
return (ptr);
}
/* Fvolume - set volume level
* Format: <cmd> <volume>
*/
static unsigned char *Fvolume(channel_t *cp, unsigned char *ptr)
{
cp->volume = *ptr++;
return (ptr);
}
/* Fstartfx - start sound effect
* Format: <cmd> <number>
*/
static unsigned char *Fstartfx(channel_t *cp, unsigned char *ptr)
{
int i, number;
channel_t *sp;
unsigned long new_handle;
number = *ptr++;
if (number>=0x80)
number = ((number&0x7f)<<8)+*ptr++;
/* increase priority */
cp->priority++;
/* start sub effect */
new_handle = __MusIntFindChannelAndStart(cp->fx_addr, number, cp->volscale, cp->panscale, cp->priority);
/* decrease priority back to normal */
cp->priority--;
/* copy handle and sample bank setting */
if (new_handle)
{
for (i=0, sp=mus_channels; i<max_channels; i++, sp++)
{
if (sp->handle == new_handle)
{
sp->handle=cp->handle;
sp->sample_bank = cp->sample_bank;
}
}
}
return (ptr);
}
/* Fbendrange - set bend range
* Format: <cmd> <bend range>
*/
static unsigned char *Fbendrange(channel_t *cp, unsigned char *ptr)
{
cp->bendrange = (float)(*ptr++)*(1.0/64.0);
cp->pitchbend_precalc = cp->pitchbend*cp->bendrange;
return (ptr);
}
/* Command : Setup pan sweeping
Format : Csweep, speed */
static unsigned char *Fsweep(channel_t *cp, unsigned char *ptr)
{
cp->sweep_speed = *ptr++;
return (ptr);
}
/* Command : Change FX type
Format : Cchangefx, fxtype */
static unsigned char *Fchangefx(channel_t *cp, unsigned char *ptr)
{
int fxtype;
fxtype = *ptr++;
#ifdef SUPPORT_FXCHANGE
if (mus_songfxchange_flag==MUSBOOL_ON)
{
ChangeCustomEffect(fxtype);
}
#endif
return (ptr);
}
/* Command : Marker definition
Format : Cmarker, number, <rest length> or Cmarker, number, <rest&0x7f00>, <rest&0xff> */
static unsigned char *Fmarker(channel_t *cp, unsigned char *ptr)
{
int rest;
int number;
number = *ptr++; /* marker number */
rest = *ptr++;
if(rest&0x80)
{
rest &= 0x7f;
rest <<= 8;
rest |= *ptr++;
}
/* if not going to a marker but marker is found on the mastertrack try callback */
if ((cp->channel_flag&CHFLAG_MASTERTRACK) && !(cp->channel_flag&CHFLAG_PAUSE))
{
if (marker_callback)
marker_callback(cp->handle, number);
}
return (ptr);
}
/* Command : Disable fixed length mode (replaces Clength,0)
Format : Clength0 */
static unsigned char *Flength0(channel_t *cp, unsigned char *ptr)
{
cp->fixed_length = 0;
return (ptr);
}
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
/* array of functions for music data commands */
command_func_t jumptable[]=
{
{ Fstop }, //80
{ Fwave }, //81
{ Fport }, //82
{ Fportoff }, //83
{ Fdefa }, //84
{ Ftempo }, //85
{ Fcutoff }, //86
{ Fendit }, //87
{ Fvibup }, //88
{ Fvibdown }, //89
{ Fviboff }, //8a
{ Flength }, //8b
{ Fignore }, //8c
{ Ftrans }, //8d
{ Fignore_trans }, //8e
{ Fdistort }, //8f
{ Fenvelope }, //90
{ Fenvoff }, //91
{ Fenvon }, //92
{ Ftroff }, //93
{ Ftron }, //94
{ Ffor }, //95
{ Fnext }, //96
{ Fwobble }, //97
{ Fwobbleoff }, //98
{ Fvelon }, //99
{ Fveloff }, //9a
{ Fvelocity }, //9b
{ Fpan }, //9c
{ Fstereo }, //9d
{ Fdrums }, //9e
{ Fdrumsoff }, //9f
{ Fprint }, //a0
{ Fgoto }, //a1
{ Freverb }, //a2
{ FrandNote }, //a3
{ FrandVolume }, //a4
{ FrandPan }, //a5
{ Fvolume }, //a6
{ Fstartfx }, //a7
{ Fbendrange }, //a8
{ Fsweep }, //a9
{ Fchangefx }, //aa
{ Fmarker }, // ab
{ Flength0 }, // ac
};
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
/* end of file */