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
23 #include <linux/cdrom.h>
24 #include <sys/ioctl.h>
35 static int cdfile = -1;
36 static char cd_dev[64] = "/dev/cdrom";
39 void CDAudio_SysEject (void)
44 if (ioctl(cdfile, CDROMEJECT) == -1)
45 Con_DPrint("ioctl CDROMEJECT failed\n");
49 void CDAudio_SysCloseDoor (void)
54 if (ioctl(cdfile, CDROMCLOSETRAY) == -1)
55 Con_DPrint("ioctl CDROMCLOSETRAY failed\n");
58 int CDAudio_SysGetAudioDiskInfo (void)
60 struct cdrom_tochdr tochdr;
65 if (ioctl(cdfile, CDROMREADTOCHDR, &tochdr) == -1)
67 Con_DPrint("ioctl CDROMREADTOCHDR failed\n");
71 if (tochdr.cdth_trk0 < 1)
73 Con_DPrint("CDAudio: no music tracks\n");
77 return tochdr.cdth_trk1;
81 float CDAudio_SysGetVolume (void)
83 struct cdrom_volctrl vol;
88 if (ioctl (cdfile, CDROMVOLREAD, &vol) == -1)
90 Con_DPrint("ioctl CDROMVOLREAD failed\n");
94 return (vol.channel0 + vol.channel1) / 2.0f / 255.0f;
98 void CDAudio_SysSetVolume (float volume)
100 struct cdrom_volctrl vol;
105 vol.channel0 = vol.channel1 = volume * 255;
106 vol.channel2 = vol.channel3 = 0;
108 if (ioctl (cdfile, CDROMVOLCTRL, &vol) == -1)
109 Con_DPrint("ioctl CDROMVOLCTRL failed\n");
113 int CDAudio_SysPlay (qbyte track)
115 struct cdrom_tocentry entry;
121 // don't try to play a non-audio track
122 entry.cdte_track = track;
123 entry.cdte_format = CDROM_MSF;
124 if (ioctl(cdfile, CDROMREADTOCENTRY, &entry) == -1)
126 Con_DPrint("ioctl CDROMREADTOCENTRY failed\n");
129 if (entry.cdte_ctrl == CDROM_DATA_TRACK)
131 Con_Printf("CDAudio: track %i is not audio\n", track);
138 ti.cdti_trk0 = track;
139 ti.cdti_trk1 = track;
143 if (ioctl(cdfile, CDROMPLAYTRKIND, &ti) == -1)
145 Con_DPrint("ioctl CDROMPLAYTRKIND failed\n");
149 if (ioctl(cdfile, CDROMRESUME) == -1)
151 Con_DPrint("ioctl CDROMRESUME failed\n");
159 int CDAudio_SysStop (void)
164 if (ioctl(cdfile, CDROMSTOP) == -1)
166 Con_DPrintf("ioctl CDROMSTOP failed (%d)\n", errno);
173 int CDAudio_SysPause (void)
178 if (ioctl(cdfile, CDROMPAUSE) == -1)
180 Con_DPrint("ioctl CDROMPAUSE failed\n");
188 int CDAudio_SysResume (void)
193 if (ioctl(cdfile, CDROMRESUME) == -1)
194 Con_DPrint("ioctl CDROMRESUME failed\n");
199 int CDAudio_SysUpdate (void)
201 struct cdrom_subchnl subchnl;
202 static time_t lastchk = 0;
204 if (cdPlaying && lastchk < time(NULL))
206 lastchk = time(NULL) + 2; //two seconds between chks
207 subchnl.cdsc_format = CDROM_MSF;
208 if (ioctl(cdfile, CDROMSUBCHNL, &subchnl) == -1)
210 Con_DPrint("ioctl CDROMSUBCHNL failed\n");
214 if (subchnl.cdsc_audiostatus != CDROM_AUDIO_PLAY &&
215 subchnl.cdsc_audiostatus != CDROM_AUDIO_PAUSED)
219 CDAudio_Play(cdPlayTrack, true);
222 cdPlayTrack = subchnl.cdsc_trk;
228 void CDAudio_SysInit (void)
232 // COMMANDLINEOPTION: Linux Sound: -cddev <devicepath> chooses which CD drive to use
233 if ((i = COM_CheckParm("-cddev")) != 0 && i < com_argc - 1)
234 strlcpy(cd_dev, com_argv[i + 1], sizeof(cd_dev));
237 int CDAudio_SysStartup (void)
239 if ((cdfile = open(cd_dev, O_RDONLY | O_NONBLOCK)) == -1)
241 Con_DPrintf("CDAudio_SysStartup: open of \"%s\" failed (%i)\n",
250 void CDAudio_SysShutdown (void)