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 float CDAudio_SysGetVolume (void);
30 extern void CDAudio_SysSetVolume (float volume);
31 extern int CDAudio_SysPlay (qbyte track);
32 extern int CDAudio_SysStop (void);
33 extern int CDAudio_SysPause (void);
34 extern int CDAudio_SysResume (void);
35 extern int CDAudio_SysUpdate (void);
36 extern void CDAudio_SysInit (void);
37 extern int CDAudio_SysStartup (void);
38 extern void CDAudio_SysShutdown (void);
40 // used by menu to ghost CD audio slider
41 cvar_t cdaudioinitialized = {CVAR_READONLY,"cdaudioinitialized","0"};
43 static qboolean wasPlaying = false;
44 static qboolean initialized = false;
45 static qboolean enabled = false;
46 static float cdvolume;
47 static qbyte remap[100];
48 static qbyte maxTrack;
49 static int faketrack = -1;
51 static float saved_vol = 1.0f;
54 qboolean cdValid = false;
55 qboolean cdPlaying = false;
56 qboolean cdPlayLooping = false;
60 static void CDAudio_Eject (void)
69 static void CDAudio_CloseDoor (void)
74 CDAudio_SysCloseDoor();
77 static int CDAudio_GetAudioDiskInfo (void)
83 ret = CDAudio_SysGetAudioDiskInfo();
94 void CDAudio_Play (qbyte track, qboolean looping)
101 track = remap[track];
104 Con_DPrintf("CDAudio: Bad track number %u.\n", track);
108 if (cdPlaying && cdPlayTrack == track)
112 // Try playing a fake track (sound file) first
113 sfx = S_PrecacheSound (va ("cdtracks/track%02u.wav", track), false, true);
116 faketrack = S_StartSound (-1, 0, sfx, vec3_origin, cdvolume, 0);
120 S_LoopChannel (faketrack, true);
121 Con_DPrintf ("Fake CD track %u playing...\n", track);
125 // If we can't play a fake CD track, try the real one
130 CDAudio_GetAudioDiskInfo();
133 Con_Print ("No CD in player.\n");
138 if (track > maxTrack)
140 Con_Printf("CDAudio: Bad track number %u.\n", track);
144 if (CDAudio_SysPlay(track) == -1)
148 cdPlayLooping = looping;
157 void CDAudio_Stop (void)
159 if (!enabled || !cdPlaying)
164 S_StopChannel (faketrack);
167 else if (CDAudio_SysStop() == -1)
174 void CDAudio_Pause (void)
176 if (!enabled || !cdPlaying)
180 S_PauseChannel (faketrack, true);
181 else if (CDAudio_SysPause() == -1)
184 wasPlaying = cdPlaying;
189 void CDAudio_Resume (void)
191 if (!enabled || cdPlaying || !wasPlaying)
195 S_PauseChannel (faketrack, false);
196 else if (CDAudio_SysResume() == -1)
201 static void CD_f (void)
210 command = Cmd_Argv (1);
212 if (strcasecmp(command, "on") == 0)
218 if (strcasecmp(command, "off") == 0)
226 if (strcasecmp(command, "reset") == 0)
231 for (n = 0; n < 100; n++)
233 CDAudio_GetAudioDiskInfo();
237 if (strcasecmp(command, "remap") == 0)
239 ret = Cmd_Argc() - 2;
242 for (n = 1; n < 100; n++)
244 Con_Printf(" %u -> %u\n", n, remap[n]);
247 for (n = 1; n <= ret; n++)
248 remap[n] = atoi(Cmd_Argv (n+1));
252 if (strcasecmp(command, "close") == 0)
258 if (strcasecmp(command, "play") == 0)
260 CDAudio_Play((qbyte)atoi(Cmd_Argv (2)), false);
264 if (strcasecmp(command, "loop") == 0)
266 CDAudio_Play((qbyte)atoi(Cmd_Argv (2)), true);
270 if (strcasecmp(command, "stop") == 0)
276 if (strcasecmp(command, "pause") == 0)
282 if (strcasecmp(command, "resume") == 0)
288 if (strcasecmp(command, "eject") == 0)
290 if (cdPlaying && faketrack == -1)
297 if (strcasecmp(command, "info") == 0)
299 CDAudio_GetAudioDiskInfo ();
301 Con_Printf("%u tracks on CD.\n", maxTrack);
303 Con_Print ("No CD in player.\n");
305 Con_Printf("Currently %s track %u\n", cdPlayLooping ? "looping" : "playing", cdPlayTrack);
307 Con_Printf("Paused %s track %u\n", cdPlayLooping ? "looping" : "playing", cdPlayTrack);
308 Con_Printf("Volume is %f\n", cdvolume);
313 void CDAudio_SetVolume (float newvol)
315 // If the volume hasn't changed
316 if (newvol == cdvolume)
319 // If the CD has been muted
324 // If the CD has been unmuted
325 if (cdvolume == 0.0f)
329 S_SetChannelVolume (faketrack, newvol);
330 CDAudio_SysSetVolume (newvol);
336 void CDAudio_Update (void)
341 CDAudio_SetVolume (bgmvolume.value);
347 int CDAudio_Init (void)
351 if (cls.state == ca_dedicated)
354 if (COM_CheckParm("-nocdaudio") || COM_CheckParm("-safe"))
359 for (i = 0; i < 100; i++)
362 Cvar_RegisterVariable(&cdaudioinitialized);
363 Cvar_SetValueQuick(&cdaudioinitialized, true);
366 Cmd_AddCommand("cd", CD_f);
371 int CDAudio_Startup (void)
373 CDAudio_SysStartup ();
375 if (CDAudio_GetAudioDiskInfo())
377 Con_DPrint("CDAudio_Init: No CD in player.\n");
381 saved_vol = CDAudio_SysGetVolume ();
382 if (saved_vol < 0.0f)
384 Con_DPrint ("Can't get initial CD volume\n");
388 Con_DPrintf ("Initial CD volume: %g\n", saved_vol);
392 Con_DPrint("CD Audio Initialized\n");
397 void CDAudio_Shutdown (void)
402 CDAudio_SysSetVolume (saved_vol);
405 CDAudio_SysShutdown();