-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patha_music.c
230 lines (166 loc) · 5.13 KB
/
a_music.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
/*
Copyright (C) 1994-1995 Apogee Software, Ltd.
Copyright (C) 2023 Frenkel Smeijers
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, 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 License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/**********************************************************************
module: MUSIC.C
author: James R. Dose
date: March 25, 1994
Device independant music playback routines.
(c) Copyright 1994 James R. Dose. All Rights Reserved.
**********************************************************************/
#include "id_heads.h"
#include "dmx.h"
#include "a_al_mid.h"
#include "a_blast.h"
#include "a_midi.h"
#include "a_mpu401.h"
#include "a_music.h"
#include "a_taskmn.h"
static int32_t MUSIC_SoundDevice = AHW_NONE;
static midifuncs MUSIC_MidiFunctions;
static int32_t MUSIC_InitFM(midifuncs *Funcs);
static int32_t MUSIC_InitMidi(midifuncs *Funcs, int32_t Address);
int32_t MUSIC_GetSoundDevice(void)
{
return MUSIC_SoundDevice;
}
/*---------------------------------------------------------------------
Function: MUSIC_Init
Selects which sound device to use.
---------------------------------------------------------------------*/
int32_t MUSIC_Init(int32_t SoundCard, int32_t Address)
{
MUSIC_SoundDevice = SoundCard;
switch (SoundCard)
{
case AHW_ADLIB:
return MUSIC_InitFM(&MUSIC_MidiFunctions);
case AHW_MPU_401:
return MUSIC_InitMidi(&MUSIC_MidiFunctions, Address);
default:
return MUSIC_Error;
}
}
/*---------------------------------------------------------------------
Function: MUSIC_Shutdown
Terminates use of sound device.
---------------------------------------------------------------------*/
void MUSIC_Shutdown(void)
{
MIDI_StopSong();
switch (MUSIC_SoundDevice)
{
case AHW_ADLIB :
AL_Shutdown();
break;
case AHW_MPU_401:
MPU_Reset();
break;
}
}
/*---------------------------------------------------------------------
Function: MUSIC_SetVolume
Sets the volume of music playback.
---------------------------------------------------------------------*/
void MUSIC_SetVolume(int32_t volume)
{
if (MUSIC_SoundDevice == AHW_NONE)
return;
if (volume < 0)
volume = 0;
else if (volume > 255)
volume = 255;
MIDI_SetVolume(volume);
}
/*---------------------------------------------------------------------
Function: MUSIC_Continue
Continues playback of a paused song.
---------------------------------------------------------------------*/
void MUSIC_Continue(void)
{
MIDI_ContinueSong();
}
/*---------------------------------------------------------------------
Function: MUSIC_Pause
Pauses playback of a song.
---------------------------------------------------------------------*/
void MUSIC_Pause(void)
{
MIDI_PauseSong();
}
/*---------------------------------------------------------------------
Function: MUSIC_StopSong
Stops playback of current song.
---------------------------------------------------------------------*/
void MUSIC_StopSong(void)
{
MIDI_StopSong();
}
/*---------------------------------------------------------------------
Function: MUSIC_PlaySong
Begins playback of MIDI song.
---------------------------------------------------------------------*/
int32_t MUSIC_PlaySong(uint8_t *song, int32_t loopflag)
{
int32_t status;
switch (MUSIC_SoundDevice)
{
case AHW_ADLIB:
case AHW_MPU_401:
MIDI_StopSong();
status = MIDI_PlaySong(song, loopflag);
if (status != MIDI_Ok)
return MUSIC_Warning;
break;
default:
return MUSIC_Warning;
}
return MUSIC_Ok;
}
static int32_t MUSIC_InitFM(midifuncs *Funcs)
{
if (!AL_DetectFM())
return MUSIC_Error;
// Init the fm routines
AL_Init();
Funcs->NoteOff = AL_NoteOff;
Funcs->NoteOn = AL_NoteOn;
Funcs->PolyAftertouch = NULL;
Funcs->ControlChange = AL_ControlChange;
Funcs->ProgramChange = AL_ProgramChange;
Funcs->ChannelAftertouch = NULL;
Funcs->PitchBend = AL_SetPitchBend;
Funcs->SetVolume = NULL;
Funcs->GetVolume = NULL;
MIDI_SetMidiFuncs(Funcs);
return MUSIC_Ok;
}
static int32_t MUSIC_InitMidi(midifuncs *Funcs, int32_t Address)
{
BLASTER_SetupWaveBlaster();
if (MPU_Init(Address) != MPU_Ok)
return MUSIC_Error;
Funcs->NoteOff = MPU_NoteOff;
Funcs->NoteOn = MPU_NoteOn;
Funcs->PolyAftertouch = MPU_PolyAftertouch;
Funcs->ControlChange = MPU_ControlChange;
Funcs->ProgramChange = MPU_ProgramChange;
Funcs->ChannelAftertouch = MPU_ChannelAftertouch;
Funcs->PitchBend = MPU_PitchBend;
Funcs->SetVolume = NULL;
Funcs->GetVolume = NULL;
MIDI_SetMidiFuncs(Funcs);
return MUSIC_Ok;
}