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, false);
116 faketrack = S_StartSound (-1, 0, sfx, vec3_origin, cdvolume, 0);
120 S_SetChannelFlag (faketrack, CHANNELFLAG_FORCELOOP, true);
121 S_SetChannelFlag (faketrack, CHANNELFLAG_FULLVOLUME, true);
122 Con_DPrintf ("Fake CD track %u playing...\n", track);
126 // If we can't play a fake CD track, try the real one
131 CDAudio_GetAudioDiskInfo();
134 Con_Print ("No CD in player.\n");
139 if (track > maxTrack)
141 Con_Printf("CDAudio: Bad track number %u.\n", track);
145 if (CDAudio_SysPlay(track) == -1)
149 cdPlayLooping = looping;
158 void CDAudio_Stop (void)
160 if (!enabled || !cdPlaying)
165 S_StopChannel (faketrack);
168 else if (CDAudio_SysStop() == -1)
175 void CDAudio_Pause (void)
177 if (!enabled || !cdPlaying)
181 S_SetChannelFlag (faketrack, CHANNELFLAG_PAUSED, true);
182 else if (CDAudio_SysPause() == -1)
185 wasPlaying = cdPlaying;
190 void CDAudio_Resume (void)
192 if (!enabled || cdPlaying || !wasPlaying)
196 S_SetChannelFlag (faketrack, CHANNELFLAG_PAUSED, false);
197 else if (CDAudio_SysResume() == -1)
202 static void CD_f (void)
211 command = Cmd_Argv (1);
213 if (strcasecmp(command, "on") == 0)
219 if (strcasecmp(command, "off") == 0)
227 if (strcasecmp(command, "reset") == 0)
232 for (n = 0; n < 100; n++)
234 CDAudio_GetAudioDiskInfo();
238 if (strcasecmp(command, "remap") == 0)
240 ret = Cmd_Argc() - 2;
243 for (n = 1; n < 100; n++)
245 Con_Printf(" %u -> %u\n", n, remap[n]);
248 for (n = 1; n <= ret; n++)
249 remap[n] = atoi(Cmd_Argv (n+1));
253 if (strcasecmp(command, "close") == 0)
259 if (strcasecmp(command, "play") == 0)
261 CDAudio_Play((qbyte)atoi(Cmd_Argv (2)), false);
265 if (strcasecmp(command, "loop") == 0)
267 CDAudio_Play((qbyte)atoi(Cmd_Argv (2)), true);
271 if (strcasecmp(command, "stop") == 0)
277 if (strcasecmp(command, "pause") == 0)
283 if (strcasecmp(command, "resume") == 0)
289 if (strcasecmp(command, "eject") == 0)
291 if (cdPlaying && faketrack == -1)
298 if (strcasecmp(command, "info") == 0)
300 CDAudio_GetAudioDiskInfo ();
302 Con_Printf("%u tracks on CD.\n", maxTrack);
304 Con_Print ("No CD in player.\n");
306 Con_Printf("Currently %s track %u\n", cdPlayLooping ? "looping" : "playing", cdPlayTrack);
308 Con_Printf("Paused %s track %u\n", cdPlayLooping ? "looping" : "playing", cdPlayTrack);
309 Con_Printf("Volume is %f\n", cdvolume);
314 void CDAudio_SetVolume (float newvol)
316 // If the volume hasn't changed
317 if (newvol == cdvolume)
320 // If the CD has been muted
325 // If the CD has been unmuted
326 if (cdvolume == 0.0f)
330 S_SetChannelVolume (faketrack, newvol);
331 CDAudio_SysSetVolume (newvol);
337 void CDAudio_Update (void)
342 CDAudio_SetVolume (bgmvolume.value);
348 int CDAudio_Init (void)
352 if (cls.state == ca_dedicated)
355 // COMMANDLINEOPTION: Sound: -nocdaudio disables CD audio support
356 if (COM_CheckParm("-nocdaudio") || COM_CheckParm("-safe"))
361 for (i = 0; i < 100; i++)
364 Cvar_RegisterVariable(&cdaudioinitialized);
365 Cvar_SetValueQuick(&cdaudioinitialized, true);
368 Cmd_AddCommand("cd", CD_f);
373 int CDAudio_Startup (void)
375 CDAudio_SysStartup ();
377 if (CDAudio_GetAudioDiskInfo())
379 Con_DPrint("CDAudio_Init: No CD in player.\n");
383 saved_vol = CDAudio_SysGetVolume ();
384 if (saved_vol < 0.0f)
386 Con_DPrint ("Can't get initial CD volume\n");
390 Con_DPrintf ("Initial CD volume: %g\n", saved_vol);
394 Con_DPrint("CD Audio Initialized\n");
399 void CDAudio_Shutdown (void)
404 CDAudio_SysSetVolume (saved_vol);
407 CDAudio_SysShutdown();