-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsound.c
1708 lines (1375 loc) · 40.5 KB
/
sound.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
/*
Overgod
Copyright (C) 2005 Linley Henzell
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public Licence as published by
the Free Software Foundation; either version 2 of the Licence, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public Licence for more details.
You should have received a copy of the GNU General Public Licence
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
The GPL version 2 is included in this distribution in a file called
LICENCE.TXT. Use any text editor or the TYPE command to read it.
You should be able to reach me by sending an email to
l_henzell@yahoo.com.au.
File: sound.c
History:
11/9/2005 - Version 1.0 finalised
This file contains:
- sound initialisation and playing.
enums in sound.h
*/
#include "allegro.h"
#include <string.h>
#include "sound.h"
#include "config.h"
#include "globvars.h"
#include "math.h"
#include "stuff.h"
//DATAFILE *soundf;
//SAMPLE *sound_list [10];
//#define SOUND_OFF
#define BEAT 64
#define HALF_BEAT 32
#define QUARTER_BEAT 16
#define Q3_BEAT 48
#define SMALLEST_BEAT 16
#define MAX_PHRASES 80
#define MAX_PHRASE_LENGTH 150
#define MAX_OVERPHRASES 100
#define NO_TONES 56
#define BASE_TONE 50
// if 100, max tone = 43
int debug_sound [5];
enum
{
CHORD_MAJOR,
CHORD_MINOR,
CHORD_3,
NO_CHORDS
};
#define NO_JUMPS 7
#define NO_LONGPROGS 6
#define SIZE_LONGPROGS 25
enum
{
NOTE_0C,
NOTE_0CS,
NOTE_0D,
NOTE_0DS,
NOTE_0E,
NOTE_0F,
NOTE_0FS,
NOTE_0G,
NOTE_0GS,
NOTE_0A,
NOTE_0AS,
NOTE_0B,
NOTE_1C,
NOTE_1CS,
NOTE_1D,
NOTE_1DS,
NOTE_1E,
NOTE_1F,
NOTE_1FS,
NOTE_1G,
NOTE_1GS,
NOTE_1A,
NOTE_1AS,
NOTE_1B,
NOTE_2C,
NOTE_2CS,
NOTE_2D,
NOTE_2DS,
NOTE_2E,
NOTE_2F,
NOTE_2FS,
NOTE_2G,
NOTE_2GS,
NOTE_2A,
NOTE_2AS,
NOTE_2B,
NOTE_ENDNOTE
};
int long_prog [NO_LONGPROGS] [SIZE_LONGPROGS] =
{
{NOTE_1C, NOTE_1E, NOTE_1G, NOTE_2C, NOTE_1G, NOTE_1E, NOTE_0AS, NOTE_1D, NOTE_1F, NOTE_1AS, NOTE_1F, NOTE_0AS, NOTE_ENDNOTE},
{NOTE_1C, NOTE_1DS, NOTE_1C, NOTE_1F, NOTE_1C, NOTE_1FS, NOTE_1C, NOTE_1G, NOTE_1C, NOTE_1AS, NOTE_1C, NOTE_2C, NOTE_ENDNOTE},
{NOTE_1C, NOTE_2C, NOTE_1AS, NOTE_1G, NOTE_1FS, NOTE_1F, NOTE_1DS, NOTE_ENDNOTE},
{NOTE_1C, NOTE_1G, NOTE_2C, NOTE_1C, NOTE_1G, NOTE_2C, NOTE_1C, NOTE_2C, NOTE_ENDNOTE},
{NOTE_1C, NOTE_1E, NOTE_1G, NOTE_2C, NOTE_2E, NOTE_1G, NOTE_2C, NOTE_2E, NOTE_ENDNOTE},
{NOTE_1DS, NOTE_0G, NOTE_0AS, NOTE_0FS, NOTE_0G, NOTE_1C, NOTE_1FS, NOTE_1F, NOTE_ENDNOTE}
//{NOTE_1, NOTE_1, NOTE_1, NOTE_1, NOTE_1, NOTE_1, NOTE_1, NOTE_1, NOTE_1, NOTE_1, NOTE_1, NOTE_1, NOTE_1,
//{NOTE_1, NOTE_1, NOTE_1, NOTE_1, NOTE_1, NOTE_1, NOTE_1, NOTE_1, NOTE_1, NOTE_1, NOTE_1, NOTE_1, NOTE_1,
//{NOTE_1, NOTE_1, NOTE_1, NOTE_1, NOTE_1, NOTE_1, NOTE_1, NOTE_1, NOTE_1, NOTE_1, NOTE_1, NOTE_1, NOTE_1,
};
int chord_jumps [NO_CHORDS] [NO_JUMPS] =
{
{NOTE_1C, NOTE_1D, NOTE_1E, NOTE_1F, NOTE_1G, NOTE_1GS, NOTE_2C},
{NOTE_1C, NOTE_1D, NOTE_1DS, NOTE_1G, NOTE_1GS, NOTE_1B, NOTE_2C},
{NOTE_1C, NOTE_1D, NOTE_1E, NOTE_1F, NOTE_1G, NOTE_1GS, NOTE_2C}
};
int success_note [3];
int success_samp;
int success_step;
int success_base;
int tone [NO_TONES];
#define PROG_LENGTH 40
#define NO_PROGS 4
int progression [NO_PROGS] [PROG_LENGTH];
int prog_pos [NO_PROGS];
int prog_base [NO_PROGS];
int prog_length [NO_PROGS];
enum
{
BEAT_DRUM1,
BEAT_DRUM2,
BEAT_LOWDRUM,
BEAT_STICK,
BEAT_BELL_S,
BEAT_BASS,
BEAT_BASS2,
BEAT_STRING,
BEAT_TWIRM, // here and above: common beats. Below: rarer beats
BEAT_ZAPDRUM1,
BEAT_ZAPDRUM2,
BEAT_PPIPE,
BEAT_SPARKLE,
BEAT_BELL_L,
BEAT_MOSQ,
BEAT_SPACE,
BEAT_SWEEP,
BEAT_TING,
//BEAT_OBOE,
BEAT_REVERSE,
BEAT_SAW,
//BEAT_BASSOON,
BEAT_BRASS,
BEAT_CHOIR,
BEAT_FLUTE,
BEAT_ODD,
BEAT_REVERSE2,
BEAT_ACCORD,
NO_BEATS,
BEAT_EMPTY
};
struct beat_phrase_struct
{
int samp;
int pitch;
int rand_pitch;
int pan;
int rand_pan;
int melody;
int vol;
};
struct beat_phrase_struct beat_phrase [MAX_PHRASES] [MAX_PHRASE_LENGTH];
int over_beat_phrase [MAX_OVERPHRASES];
int bpos;
int over_bpos;
int phrase_length;
int over_phrase_length;
int over_phrase_loop_point;
#define MAX_MELODIES 5
#define MAX_MELODY_LENGTH 400
#define MAX_OVERMELODIES 20
enum
{
OVERMELODY_REPEAT,
OVERMELODY_FILL
}; // for overmelody_mode
struct overmelody_struct
{
int mel;
int key;
int start;
};
struct overmelody_struct overmelody [MAX_OVERMELODIES];
struct beat_phrase_struct melody [MAX_MELODIES] [MAX_MELODY_LENGTH];
int melody_active [MAX_MELODIES];
int mpos [MAX_MELODIES];
int over_mpos;
int over_mpos2;
int overmelodies;
int overmelody_mode;
int overmelody_fill_length;
int melodies_played;
int melody_length [MAX_MELODIES];
int mdelay [MAX_MELODIES];
//int total_melody_delay;
extern struct optionstruct options;
SAMPLE *beat [NO_BEATS];
//SAMPLE *sounds [NO_WAVS];
SAMPLE *new_sounds [NO_NWAVS];
char sound_active;
void check_sound(SAMPLE *samp);
void load_sample_in(int samp, const char *sfile);
void load_new_sample_in(int samp, const char *sfile);
void copy_phrase(int target, int source);
//void play_beat(int samp);
//void play_beatf(int samp, int freq);
void play_beatfvp(int samp, int freq, int vol, int pan);
void play_successfvp(int samp, int freq, int vol, int pan);
void init_beat(void);
void load_beat_sample_in(int samp, const char *sfile);
void calculate_beat(void);
void calculate_melody(int active);
void play_melody(void);
void copy_melody(int t, int s);
void add_note(int beat, int bp1, int bp2, int pitch, int rand_pitch, int pan, int vol, int mel);
void add_over_phrase(int phrase, int start, int finish);
void add_melody_note(int samp, int melody, int mp2, int pitch, int rand_pitch, int pan, int vol);
void add_melody_string1(int samp, int mp1, int length, int chords);
//void assign_beat(int index, int beaty, int subtype);
void create_progression(int which, int length, int key);
void play_success_sound(void);
//int ppos;
//int plength;
void init_sound(void)
{
#ifdef SOUND_OFF
return;
#endif
int i, j;
float t;
for (i = 0; i < NO_TONES; i ++)
{
t = (float) BASE_TONE;
for (j = 0; j < i; j ++)
{
t *= (float) (1000 + (1000 / 13)) / 1000;
}
tone [i] = t;
// saves me from having to remember how to use the pow function
}
sound_active = 1;
if (options.sound_init == 0)
{
// cprintf("\n\r\n\rSound disabled in proj.cfg.");
// allegro_message("\n\r\n\rSound disabled in config file.\n\r");
// allegro_message("\n\r\n\rSound disabled in config file.\n\r");
// rest(500);
sound_active = 0;
return;
}
reserve_voices(16, 0);
if (install_sound (DIGI_AUTODETECT, MIDI_NONE, NULL) == -1)
{
// allegro_message("\n\r\n\rSound autodetect failed.");
sound_active = 0;
// rest(300);
// do
// {
// } while (keypressed() == 0);
}
set_volume(255, 0);
load_new_sample_in(NWAV_ALARM, "alarm");
load_new_sample_in(NWAV_BANG, "bang");
load_new_sample_in(NWAV_BIGBANG, "bigbang");
load_new_sample_in(NWAV_BLAST, "blast");
load_new_sample_in(NWAV_BLOCK, "block");
load_new_sample_in(NWAV_BUMP, "bump");
load_new_sample_in(NWAV_BUMP2, "bump2");
load_new_sample_in(NWAV_BURST, "burst");
load_new_sample_in(NWAV_SHORTBURST, "bursts");
load_new_sample_in(NWAV_BURSTZ, "burstz");
load_new_sample_in(NWAV_BURSTZL, "burstzl");
load_new_sample_in(NWAV_CHIME, "chime");
load_new_sample_in(NWAV_CHIME2, "chime2");
load_new_sample_in(NWAV_CHIRP, "chirp2");
load_new_sample_in(NWAV_CLICK, "click");
load_new_sample_in(NWAV_CYMBAL, "cymbal");
load_new_sample_in(NWAV_DART, "dart");
load_new_sample_in(NWAV_DNO, "dno");
load_new_sample_in(NWAV_DRIVE, "drive");
// load_sample_in(WAV_ENGINE, "engine");
load_new_sample_in(NWAV_EXTRA, "extra");
load_new_sample_in(NWAV_EYE, "eye");
load_new_sample_in(NWAV_GAMEOVER, "gameover");
load_new_sample_in(NWAV_GBLAT, "gblat");
load_new_sample_in(NWAV_JET, "jet");
load_new_sample_in(NWAV_LAUNCH, "launch");
load_new_sample_in(NWAV_LZAP, "longzap");
load_new_sample_in(NWAV_MENU, "menu");
load_new_sample_in(NWAV_MINEBANG, "minebang"); // not mines - pulser arms
load_new_sample_in(NWAV_PHASE, "phase");
load_new_sample_in(NWAV_PPIPE, "ppipe");
load_new_sample_in(NWAV_PUFF, "puff");
load_new_sample_in(NWAV_REPAIR, "repair");
load_new_sample_in(NWAV_SEEKER, "seeker");
load_new_sample_in(NWAV_SHADOW, "shadow");
load_new_sample_in(NWAV_SZAP, "sharpzap");//szap");
load_new_sample_in(NWAV_SHIELD, "shield");
load_new_sample_in(NWAV_SHIELDE, "shielde");
load_new_sample_in(NWAV_SPAWN, "spawn");
load_new_sample_in(NWAV_SPLERK, "splerk");
load_new_sample_in(NWAV_BALL1, "squelch1");
load_new_sample_in(NWAV_MULTI, "squelch2");
load_new_sample_in(NWAV_SUCCESS, "success");
load_new_sample_in(NWAV_SYMBOL, "symbol");
load_new_sample_in(NWAV_TEETH, "teeth");
load_new_sample_in(NWAV_TWING, "twing"); // ouch sound
load_new_sample_in(NWAV_WARBLE, "warble");
load_new_sample_in(NWAV_WARBLEB, "warbleb");
load_new_sample_in(NWAV_WHINE, "whine4");
load_new_sample_in(NWAV_WORMS, "worms");
load_new_sample_in(NWAV_ZAPSTEP, "zapstep");
// load_new_sample_in(NWAV_, "");
/*
load_sample_in(WAV_CANNON, "zap");
load_sample_in(WAV_WOBBLE, "wobble");
load_sample_in(WAV_LONG_WOBBLE, "longwob");
load_sample_in(WAV_WARP_IN, "warp_in");
load_sample_in(WAV_BANG1, "bangs");
load_sample_in(WAV_WHINE, "whine");
load_sample_in(WAV_BUMP, "bump");
load_sample_in(WAV_BOSS2, "boss2");//_2");
load_sample_in(WAV_STING, "sting");
load_sample_in(WAV_HARD_ZAP, "hardzap");
load_sample_in(WAV_BLORT, "blort");
load_sample_in(WAV_BLAST, "blast");
load_sample_in(WAV_ALARM, "alarm");
load_sample_in(WAV_MISSILE, "missile");
load_sample_in(WAV_ZAPNOTE1, "zapnote1");
load_sample_in(WAV_ZAPNOTE2, "zapnote2");
load_sample_in(WAV_MINE, "mine");
load_sample_in(WAV_SHORTZAP, "shortzap");
load_sample_in(WAV_BLAT, "blat");
load_sample_in(WAV_SHORTZAP2, "shortz2");
load_sample_in(WAV_SUN, "sun");
load_sample_in(WAV_THRUM, "thrum");
load_sample_in(WAV_CROAK, "croak");
load_sample_in(WAV_MINEBANG, "minebang");
load_sample_in(WAV_ASPAWN, "aspawn");
load_sample_in(WAV_GAME_OVER, "gover2");
load_sample_in(WAV_TUBE, "tube");
load_sample_in(WAV_UPGRADE, "upgr");
load_sample_in(WAV_SHIELD, "shield");
load_sample_in(WAV_REPAIR, "repair");
load_sample_in(WAV_SEEKMINE, "seekmine");
load_sample_in(WAV_PLASMA, "plasma");
load_sample_in(WAV_LEVEL_END, "finish");
load_sample_in(WAV_MENU1, "menu1");
load_sample_in(WAV_MENU2, "menu2");
load_sample_in(WAV_EXTRA_SHIP, "extra");
load_sample_in(WAV_ORBITAL, "orbital");
load_sample_in(WAV_PICKUP_UPGRADE, "pickup");
load_sample_in(WAV_SEEKBLOB_BANG, "seekb");
load_sample_in(WAV_BUMP2, "bump2");
load_sample_in(WAV_HIT, "hit");
load_sample_in(WAV_HOSTILE, "buzzzap");
// load_sample_in(WAV_MUTATE, "mutate");
// load_sample_in(WAV_, "");
*/
init_beat();
// priority->sound_list[WAV_POP] = 1;
}
void load_new_sample_in(int samp, const char *sfile)
{
char sfile_name [50];
strcpy(sfile_name, ".//wavs//");
strcat(sfile_name, sfile);
strcat(sfile_name, ".wav");
new_sounds [samp] = load_sample(sfile_name);
if (new_sounds [samp] == NULL)
{
set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
allegro_message("Fatal Error: Unable to load sound file: %s", sfile_name);
exit(1);
}
}
/*void load_sample_in(int samp, const char *sfile)
{
char sfile_name [50];
strcpy(sfile_name, ".//sound//");
strcat(sfile_name, sfile);
strcat(sfile_name, ".wav");
sounds [samp] = load_sample(sfile_name);
if (sounds [samp] == NULL)
{
set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
allegro_message("Fatal Error: Unable to load sound file: %s", sfile_name);
exit(1);
}
}
*/
/*
void load_sample_in(SAMPLE *samp)
{
if (samp == NULL)
{
set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
allegro_message("Fatal Error: Unable to load sound file");
exit(1);
}
}
*/
/*
void play_sound(int sample)
{
#ifdef SOUND_OFF
return;
#endif
if (sound_active == 0 || options.sound_volume == 0) return;
play_sample(sounds [sample], (int) (250 * options.sound_volume) / 100, 127, 1000, 0);
}
*/
/*
void play_sound2(int sample, int frq, int vol, int pan)
{
#ifdef SOUND_OFF
return;
#endif
if (sound_active == 0 || options.sound_volume == 0) return;
play_sample(sounds [sample], (vol * options.sound_volume) / 100, pan, frq, 0);
}
void play_soundf(int sample, int frq)
{
#ifdef SOUND_OFF
return;
#endif
if (sound_active == 0 || options.sound_volume == 0) return;
play_sample(sounds [sample], (int) (255 * options.sound_volume) / 100, 127, frq, 0);
}
void play_sound_pos(int sample, int frq, int vol, int x2, int y2)
{
#ifdef SOUND_OFF
return;
#endif
if (sound_active == 0 || options.sound_volume == 0) return;
int pan = 127;
int vol2 = vol;
int distance;
int x1 = actor[player[game.single_player].actor_controlled].x;
int y1 = actor[player[game.single_player].actor_controlled].y;
distance = hypot(abs(x2 - x1), abs(y2 - y1)) / GRAIN;
if (distance > 1000)
return;
if (distance > 300)
{
distance -= 300;
distance = 1000 - distance;
vol2 *= distance; //(800 - (distance - 300));
vol2 /= 1000;
}
if (options.sound_mode == SOUNDMODE_MONO || game.users == 2)
pan = 127;
else
{
if (x1 == x2)
{
pan = 127;
}
else
{
if (x1 < x2 - (300 * GRAIN))
pan = 0;
else
{
if (x1 > x2 + (300 * GRAIN))
pan = 255;
else
{
if (x1 > x2)
{
pan = 127 + ((x1 - x2) * 125) / (300 * GRAIN);
}
else
{
pan = 127 - ((x2 - x1) * 125) / (300 * GRAIN);
}
}
}
}
if (options.sound_mode == SOUNDMODE_REVERSED)
pan = 255 - pan;
}
// stop_sample(sounds [sample]);
play_sample(sounds [sample], (vol2 * options.sound_volume) / 100, pan, frq, 0);
}
*/
void set_engine_sound(int a, int drive, int setting)
{
#ifdef SOUND_OFF
return;
#endif
}
void kill_drive_sounds(void)
{
#ifdef SOUND_OFF
return;
#endif
if (sound_active == 0)
return;
// if (actor[a].drive_sound [DRIVE_THRUST] > 0)
{
// stop_sample(sounds [WAV_ENGINE]);
}
}
/*
************************
Beat functions
************************
*/
void play_beats(void)
{
if (arena.level_finished == 1 && sound_active != 0)
{
play_success_sound();
return;
} // this is in play_beats, but it goes through whichever volume control is higher
if (sound_active == 0 || options.ambience_volume == 0)
return;
// if (options.ambience_volume == 0)
// return;
play_melody();
bpos ++;
if (bpos >= phrase_length)
{
bpos = 0;
over_bpos ++;
if (over_bpos >= over_phrase_length)
over_bpos = over_phrase_loop_point;
}
if (beat_phrase [over_beat_phrase [over_bpos]] [bpos].samp == BEAT_EMPTY)
return;
int tone_play = beat_phrase [over_beat_phrase [over_bpos]] [bpos].pitch;
if (beat_phrase [over_beat_phrase [over_bpos]] [bpos].rand_pitch != -1)
{
if (grand(5) != 0)
tone_play += chord_jumps [beat_phrase [over_beat_phrase [over_bpos]] [bpos].rand_pitch] [grand(NO_JUMPS)];
else
tone_play -= chord_jumps [beat_phrase [over_beat_phrase [over_bpos]] [bpos].rand_pitch] [grand(NO_JUMPS)];
}
/* int mel = beat_phrase [over_beat_phrase [over_bpos]] [bpos].melody;
if (mel != -1)
{
tone_play = prog_base [mel] + progression [mel] [prog_pos [mel]];
prog_pos [mel] ++;
if (prog_pos [mel] >= prog_length [mel])
prog_pos [mel] = 0;
}*/
if (beat_phrase [over_beat_phrase [over_bpos]] [bpos].samp != BEAT_EMPTY)
// if (FALSE)
{
play_beatfvp(beat_phrase [over_beat_phrase [over_bpos]] [bpos].samp,
// beat_phrase [over_beat_phrase [over_bpos]] [bpos].pitch + grand(beat_phrase [over_beat_phrase [over_bpos]] [bpos].rand_pitch),
tone [tone_play],
// note [beat_phrase [over_beat_phrase [over_bpos]] [bpos].pitch],
beat_phrase [over_beat_phrase [over_bpos]] [bpos].vol,
beat_phrase [over_beat_phrase [over_bpos]] [bpos].pan);
}
/*
if (ppos == 12 || ppos == 24)
play_beat(BEAT_LOWDRUM);
if (ppos == 17)
play_beat(BEAT_ZAPDRUM1);
*/
}
void calculate_beat(void)
{
if (sound_active == 0)
return;
int success_chord = grand(NO_CHORDS);
success_base = 1;
success_note [0] = chord_jumps [success_chord] [0];
success_note [1] = chord_jumps [success_chord] [grand(NO_JUMPS)];
success_note [2] = chord_jumps [success_chord] [grand(NO_JUMPS)];
success_samp = BEAT_STRING;
switch(grand(6))
{
case 0: success_samp = BEAT_STRING; break;
case 1: success_samp = BEAT_BELL_S; break;
case 2: success_samp = BEAT_BELL_L; break;
case 3: success_samp = BEAT_STRING; break;
case 4: success_samp = BEAT_SPARKLE; break;
case 5: success_samp = BEAT_ZAPDRUM2; break;
}
success_step = 1 + grand(3);
if (options.ambience_volume == 0)
return;
int i, j;
int basic_beat [5];
int split_phrase = 0;
if (grand(3) != 0)
split_phrase = 1;
if (grand(4) == 0)
split_phrase = 2;
for (i = 0; i < MAX_PHRASES; i ++)
{
for (j = 0; j < MAX_PHRASE_LENGTH; j ++)
{
beat_phrase[i] [j].samp = BEAT_EMPTY;
beat_phrase[i] [j].pitch = 1000;
beat_phrase[i] [j].rand_pitch = 0;
beat_phrase[i] [j].pan = 127;
beat_phrase[i] [j].rand_pan = 0;
beat_phrase[i] [j].melody = 0;
beat_phrase[i] [j].vol = 200;
}
}
// phrase_length = (20 + grand(25)) * (split_phrase + 1);
phrase_length = (15 + grand(20)) * (split_phrase + 1);
// phrase_length = (12 + grand(10)) * (split_phrase + 1);
if (grand(5) == 0)
phrase_length += 15;
// phrase_length = (10) * (split_phrase + 1);
/* basic_beat [0] = grand(BEAT_TWIRM + 1);
basic_beat [1] = grand(BEAT_TWIRM + 1);
basic_beat [2] = grand(BEAT_TWIRM + 1);
basic_beat [3] = grand(BEAT_TWIRM + 1);
basic_beat [4] = grand(BEAT_TWIRM + 1);*/
basic_beat [0] = grand(BEAT_TWIRM + 1);
basic_beat [1] = grand(BEAT_TWIRM + 1);
if (grand(4) == 0)
basic_beat [0] = grand(NO_BEATS);
if (grand(4) == 0)
basic_beat [1] = grand(NO_BEATS);
basic_beat [2] = grand(NO_BEATS);
basic_beat [3] = grand(NO_BEATS);
basic_beat [4] = grand(NO_BEATS);
int rand_note = -1;
// int prog_note = -1;
//nt no_progs = 0;
// int prog_active [NO_PROGS] = {0,0,0,0};
int base_phrase_length = phrase_length;
int num_phrases = 0;
// int mel_delay = 0;
// int mel_length;
// int mel_start;
// int mel_pos;
// int mel_delay_rand;
if (split_phrase == 1)
base_phrase_length /= 2;
if (split_phrase == 3)
base_phrase_length /= 3;
int basenote = 25;
int randnote = 27;
add_note(basic_beat [0], 0, grand(base_phrase_length), basenote + grand(randnote), -1, 127, 200, 0);
add_note(basic_beat [0], 0, grand(base_phrase_length), basenote + grand(randnote), -1, 127, 200, 0);
if (split_phrase > 0)
{
add_note(basic_beat [0], 0, base_phrase_length + grand(base_phrase_length), basenote + grand(randnote), -1, 127, 200, 0);
add_note(basic_beat [0], 0, base_phrase_length + grand(base_phrase_length), basenote + grand(randnote), -1, 127, 200, 0);
}
if (split_phrase > 1)
{
add_note(basic_beat [0], 0, (base_phrase_length * 2) + grand(base_phrase_length), basenote + grand(randnote), -1, 127, 200, 0);
add_note(basic_beat [0], 0, (base_phrase_length * 2) + grand(base_phrase_length), basenote + grand(randnote), -1, 127, 200, 0);
}
num_phrases ++;
copy_phrase(1, 0);
add_note(basic_beat [1], 1, grand(base_phrase_length), basenote + grand(randnote), -1, 127, 200, 0);
add_note(basic_beat [1], 1, grand(base_phrase_length), basenote + grand(randnote), -1, 127, 200, 0);
if (split_phrase > 0)
{
add_note(basic_beat [1], 1, base_phrase_length + grand(base_phrase_length), basenote + grand(randnote), -1, 127, 200, 0);
add_note(basic_beat [1], 1, base_phrase_length + grand(base_phrase_length), basenote + grand(randnote), -1, 127, 200, 0);
}
if (split_phrase > 1)
{
add_note(basic_beat [1], 0, (base_phrase_length * 2) + grand(base_phrase_length), basenote + grand(randnote), -1, 127, 200, 0);
add_note(basic_beat [1], 0, (base_phrase_length * 2) + grand(base_phrase_length), basenote + grand(randnote), -1, 127, 200, 0);
}
num_phrases ++;
copy_phrase(2, 1);
rand_note = grand(NO_CHORDS);
if (grand(15) != 0)
rand_note = -1;
add_note(basic_beat [2], 2, grand(base_phrase_length), basenote + grand(randnote), rand_note, 127, 200, -1);
if (split_phrase > 0)
add_note(basic_beat [2], 2, base_phrase_length + grand(base_phrase_length), basenote + grand(randnote), rand_note, 127, 200, -1);
if (split_phrase > 1)
add_note(basic_beat [2], 2, (base_phrase_length * 2) + grand(base_phrase_length), basenote + grand(randnote), rand_note, 127, 200, -1);
num_phrases ++;
// prog_note = -1;
if (grand(2) == 0)
{
calculate_melody(1);
}
else
{
calculate_melody(0);
copy_phrase(3, 2);
rand_note = grand(NO_CHORDS);
if (grand(15) != 0)
rand_note = -1;
add_note(basic_beat [3], 3, grand(base_phrase_length), basenote + grand(randnote), rand_note, 127, 200, -1);
if (split_phrase > 0)
add_note(basic_beat [3], 3, base_phrase_length + grand(base_phrase_length), basenote + grand(randnote), rand_note, 127, 200, -1);
if (split_phrase > 1)
add_note(basic_beat [3], 3, (base_phrase_length * 2) + grand(base_phrase_length), basenote + grand(randnote), rand_note, 127, 200, -1);
// add_note(basic_beat [0], 0, grand(phrase_length), 15 + grand(10), 0, 127, 200);
}
if (grand(2) == 0)
num_phrases ++;
/*
prog_note = -1;
copy_phrase(4, 3);
rand_note = grand(NO_CHORDS);
if (grand(3) != 0)
rand_note = -1;
if (grand(3) != 0)
{
prog_note = 2;
prog_active [2] = 1;
}
// if (prog_note == 2)
// no_progs ++;
add_note(basic_beat [4], 4, grand(base_phrase_length), 15 + grand(10), rand_note, 127, 200, prog_note);
if (split_phrase > 0)
add_note(basic_beat [4], 4, base_phrase_length + grand(base_phrase_length), 15 + grand(10), rand_note, 127, 200, prog_note);
if (split_phrase > 1)
add_note(basic_beat [4], 4, (base_phrase_length * 2) + grand(base_phrase_length), 15 + grand(10), rand_note, 127, 200, prog_note);
// add_note(basic_beat [1], 0, grand(phrase_length), 15 + grand(10), 0, 127, 200);
*/
int oplength = 7 + grand(5);
int pause_length = grand(3);
int up_to = 0, next_op = 0;
add_over_phrase(0, 0, MAX_OVERPHRASES);
if (split_phrase == 1)
{
// if (grand(3) != 0)
// no_progs *= 2;
oplength = 4 + grand(3);
}
if (split_phrase == 2)
{
// if (grand(3) != 0)
// no_progs *= 3;
oplength = 2 + grand(3);
}
// if (grand(8) == 0)
// no_progs = 4 + grand(3) - grand(3);
/* prog_length [0] = 8 + grand(3) - grand(3);
prog_length [1] = prog_length [0];
prog_length [2] = prog_length [0];
prog_length [3] = prog_length [0];
create_progression(0, prog_length [0], grand(NO_CHORDS));
create_progression(1, prog_length [1], grand(NO_CHORDS));
create_progression(2, prog_length [2], grand(NO_CHORDS));
create_progression(3, prog_length [3], grand(NO_CHORDS));
*/
// prog_length = no_progs;
for (i = 0; i < num_phrases; i ++)
{
next_op = up_to + oplength;
add_over_phrase(i, up_to + pause_length, next_op);
up_to = next_op;
}
/* add_over_phrase(0, 0, 9);
add_over_phrase(1, 10, 20);
add_over_phrase(2, 21, 30);
add_over_phrase(3, 31, 40);
add_over_phrase(4, 41, 50);*/
over_phrase_length = up_to;
over_phrase_loop_point = oplength * (1 + grand(3));
bpos = 0;
over_bpos = 0;
/* for (i = 0; i < NO_PROGS; i ++)
{
prog_pos [i] = 0;
prog_base [i] = 10 + grand(15);
} */
}
void add_note(int beat, int bp1, int bp2, int pitch, int rand_pitch, int pan, int vol, int mel)
{
if (bp1 >= MAX_PHRASES || bp2 >= MAX_PHRASE_LENGTH)
return;
if (pitch <= 0 || pitch >= NO_TONES)
return;
beat_phrase[bp1] [bp2].samp = beat;
beat_phrase[bp1] [bp2].pitch = pitch;
beat_phrase[bp1] [bp2].rand_pitch = rand_pitch;
if (grand(3) == 0)
beat_phrase[bp1] [bp2].pan = grand(255);
else
beat_phrase[bp1] [bp2].pan = pan;
if (options.sound_mode == SOUNDMODE_MONO)
beat_phrase[bp1] [bp2].pan = 127; // don't worry about reversing stereo; it doesn't matter
beat_phrase[bp1] [bp2].vol = vol;
beat_phrase[bp1] [bp2].melody = mel;
}
void add_over_phrase(int phrase, int start, int finish)
{
int i;
for (i = start; i < finish + 1; i ++)
{
if (i >= MAX_OVERPHRASES)
return;
over_beat_phrase [i] = phrase;
}
}
void copy_phrase(int target, int source)
{
int j;
if (source >= MAX_PHRASES || target >= MAX_PHRASES)
return;
for (j = 0; j < MAX_PHRASE_LENGTH; j ++)
{