-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathsound.c
145 lines (114 loc) · 2.32 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
/*
* Elite - The New Kind.
*
* Reverse engineered from the BBC disk version of Elite.
* Additional material by C.J.Pinder.
*
* The original Elite code is (C) I.Bell & D.Braben 1984.
* This version re-engineered in C by C.J.Pinder 1999-2001.
*
* email: <[email protected]>
*
*
*/
/*
* sound.c
*/
#include <stdlib.h>
#include <allegro.h>
#include "sound.h"
#include "alg_data.h"
#define NUM_SAMPLES 14
extern DATAFILE *datafile;
static int sound_on;
struct sound_sample
{
SAMPLE *sample;
char filename[256];
int runtime;
int timeleft;
};
struct sound_sample sample_list[NUM_SAMPLES] =
{
{NULL, "launch.wav", 32, 0},
{NULL, "crash.wav", 7, 0},
{NULL, "dock.wav", 36, 0},
{NULL, "gameover.wav", 24, 0},
{NULL, "pulse.wav", 4, 0},
{NULL, "hitem.wav", 4, 0},
{NULL, "explode.wav", 23, 0},
{NULL, "ecm.wav", 23, 0},
{NULL, "missile.wav", 25, 0},
{NULL, "hyper.wav", 37, 0},
{NULL, "incom1.wav", 4, 0},
{NULL, "incom2.wav", 5, 0},
{NULL, "beep.wav", 2, 0},
{NULL, "boop.wav", 7, 0},
};
void snd_sound_startup (void)
{
int i;
/* Install a sound driver.. */
sound_on = 1;
if (install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, ".") != 0)
{
sound_on = 0;
return;
}
/* Load the sound samples... */
for (i = 0; i < NUM_SAMPLES; i++)
{
sample_list[i].sample = load_sample(sample_list[i].filename);
}
}
void snd_sound_shutdown (void)
{
int i;
if (!sound_on)
return;
for (i = 0; i < NUM_SAMPLES; i++)
{
if (sample_list[i].sample != NULL)
{
destroy_sample (sample_list[i].sample);
sample_list[i].sample = NULL;
}
}
}
void snd_play_sample (int sample_no)
{
if (!sound_on)
return;
if (sample_list[sample_no].timeleft != 0)
return;
sample_list[sample_no].timeleft = sample_list[sample_no].runtime;
play_sample (sample_list[sample_no].sample, 255, 128, 1000, FALSE);
}
void snd_update_sound (void)
{
int i;
for (i = 0; i < NUM_SAMPLES; i++)
{
if (sample_list[i].timeleft > 0)
sample_list[i].timeleft--;
}
}
void snd_play_midi (int midi_no, int repeat)
{
if (!sound_on)
return;
switch (midi_no)
{
case SND_ELITE_THEME:
play_midi (datafile[THEME].dat, repeat);
break;
case SND_BLUE_DANUBE:
play_midi (datafile[DANUBE].dat, repeat);
break;
}
}
void snd_stop_midi (void)
{
if (sound_on);
play_midi (NULL, TRUE);
}