2 Copyright (C) 1996-1997 Id Software, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 // Quake is a trademark of Id Software, Inc., (c) 1996 Id Software, Inc. All
25 // Prototypes of the system dependent functions
26 extern void CDAudio_SysEject (void);
27 extern void CDAudio_SysCloseDoor (void);
28 extern int CDAudio_SysGetAudioDiskInfo (void);
29 extern int CDAudio_SysPlay (qbyte track);
30 extern int CDAudio_SysStop (void);
31 extern int CDAudio_SysPause (void);
32 extern int CDAudio_SysResume (void);
33 extern int CDAudio_SysUpdate (void);
34 extern void CDAudio_SysInit (void);
35 extern int CDAudio_SysStartup (void);
36 extern void CDAudio_SysShutdown (void);
38 // used by menu to ghost CD audio slider
39 cvar_t cdaudioinitialized = {CVAR_READONLY,"cdaudioinitialized","0"};
41 static qboolean wasPlaying = false;
42 static qboolean initialized = false;
43 static qboolean enabled = false;
44 static float cdvolume;
45 static qbyte remap[100];
46 static qbyte maxTrack;
47 static int faketrack = -1;
50 qboolean cdValid = false;
51 qboolean cdPlaying = false;
52 qboolean cdPlayLooping = false;
56 static void CDAudio_Eject (void)
65 static void CDAudio_CloseDoor (void)
70 CDAudio_SysCloseDoor();
73 static int CDAudio_GetAudioDiskInfo (void)
79 ret = CDAudio_SysGetAudioDiskInfo();
90 void CDAudio_Play (qbyte track, qboolean looping)
100 Con_DPrintf("CDAudio: Bad track number %u.\n", track);
104 if (cdPlaying && cdPlayTrack == track)
108 // Try playing a fake track (sound file) first
109 sfx = S_PrecacheSound (va ("cdtracks/track%02u.wav", track), false);
112 faketrack = S_StartSound (-1, 0, sfx, vec3_origin, cdvolume, 0);
116 S_LoopChannel (faketrack, true);
117 Con_DPrintf ("Fake CD track %u playing...\n", track);
121 // If we can't play a fake CD track, try the real one
126 CDAudio_GetAudioDiskInfo();
129 Con_Print ("No CD in player.\n");
134 if (track > maxTrack)
136 Con_DPrintf("CDAudio: Bad track number %u.\n", track);
140 if (CDAudio_SysPlay(track) == -1)
144 cdPlayLooping = looping;
153 void CDAudio_Stop (void)
155 if (!enabled || !cdPlaying)
160 S_StopChannel (faketrack);
163 else if (CDAudio_SysStop() == -1)
170 void CDAudio_Pause (void)
172 if (!enabled || !cdPlaying)
176 S_PauseChannel (faketrack, true);
177 else if (CDAudio_SysPause() == -1)
180 wasPlaying = cdPlaying;
185 void CDAudio_Resume (void)
187 if (!enabled || cdPlaying || !wasPlaying)
191 S_PauseChannel (faketrack, false);
192 else if (CDAudio_SysResume() == -1)
197 static void CD_f (void)
206 command = Cmd_Argv (1);
208 if (strcasecmp(command, "on") == 0)
214 if (strcasecmp(command, "off") == 0)
222 if (strcasecmp(command, "reset") == 0)
227 for (n = 0; n < 100; n++)
229 CDAudio_GetAudioDiskInfo();
233 if (strcasecmp(command, "remap") == 0)
235 ret = Cmd_Argc() - 2;
238 for (n = 1; n < 100; n++)
240 Con_Printf(" %u -> %u\n", n, remap[n]);
243 for (n = 1; n <= ret; n++)
244 remap[n] = atoi(Cmd_Argv (n+1));
248 if (strcasecmp(command, "close") == 0)
254 if (strcasecmp(command, "play") == 0)
256 CDAudio_Play((qbyte)atoi(Cmd_Argv (2)), false);
260 if (strcasecmp(command, "loop") == 0)
262 CDAudio_Play((qbyte)atoi(Cmd_Argv (2)), true);
266 if (strcasecmp(command, "stop") == 0)
272 if (strcasecmp(command, "pause") == 0)
278 if (strcasecmp(command, "resume") == 0)
284 if (strcasecmp(command, "eject") == 0)
286 if (cdPlaying && faketrack == -1)
293 if (strcasecmp(command, "info") == 0)
295 CDAudio_GetAudioDiskInfo ();
297 Con_Printf("%u tracks on CD.\n", maxTrack);
299 Con_Print ("No CD in player.\n");
301 Con_Printf("Currently %s track %u\n", cdPlayLooping ? "looping" : "playing", cdPlayTrack);
303 Con_Printf("Paused %s track %u\n", cdPlayLooping ? "looping" : "playing", cdPlayTrack);
304 Con_Printf("Volume is %f\n", cdvolume);
309 void CDAudio_SetVolume (float newvol)
311 // If the volume hasn't changed
312 if (newvol == cdvolume)
315 // If the CD has been muted
320 // If the CD has been unmuted
321 if (cdvolume == 0.0f)
325 S_SetChannelVolume (faketrack, newvol);
328 // TODO: add support for the "real CD" mixer
335 void CDAudio_Update (void)
340 CDAudio_SetVolume (bgmvolume.value);
346 int CDAudio_Init (void)
350 if (cls.state == ca_dedicated)
353 if (COM_CheckParm("-nocdaudio") || COM_CheckParm("-safe"))
358 for (i = 0; i < 100; i++)
361 Cvar_RegisterVariable(&cdaudioinitialized);
362 Cvar_SetValueQuick(&cdaudioinitialized, true);
365 Cmd_AddCommand("cd", CD_f);
370 int CDAudio_Startup (void)
372 CDAudio_SysStartup ();
374 if (CDAudio_GetAudioDiskInfo())
376 Con_DPrint("CDAudio_Init: No CD in player.\n");
382 Con_DPrint("CD Audio Initialized\n");
387 void CDAudio_Shutdown (void)
392 CDAudio_SysShutdown();