2 Copyright (C) 2004 Andreas Kirsch (used cd_null.c as template)
3 Copyright (C) 1996-1997 Id Software, Inc.
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 See the GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 SDL 1.2.7 and older seems to have a strange bug regarding CDPause and CDResume under WIN32.
28 If CDResume is called, it plays to end of the CD regardless what values for lasttrack and lastframe
29 were passed to CDPlayTracks.
32 // If one of the functions fails, it returns -1, if not 0
34 // SDL supports multiple cd devices - so we are going to support this, too.
35 static void CDAudio_SDL_CDDrive_f( void );
37 // we only support playing on CD at a time
40 static double pauseoffset;
41 static double endtime;
43 static int ValidateDrive( void )
45 if( cd && SDL_CDStatus( cd ) > 0 )
46 return cdValid = true;
48 return cdValid = false;
51 void CDAudio_SysEject (void)
57 void CDAudio_SysCloseDoor (void)
63 int CDAudio_SysGetAudioDiskInfo (void)
65 if( ValidateDrive() ) // everything > 0 is ok, 0 is trayempty and -1 is error
71 float CDAudio_SysGetVolume (void)
77 void CDAudio_SysSetVolume (float volume)
83 int CDAudio_SysPlay (qbyte track)
86 endtime = realtime + (float) cd->track[ track - 1 ].length / CD_FPS;
87 return SDL_CDPlayTracks( cd, track - 1, 0, track, 1 ); //FIXME: shall we play the whole cd or only the track?
91 int CDAudio_SysStop (void)
94 return SDL_CDStop( cd );
98 int CDAudio_SysPause (void)
101 pauseoffset = cd->cur_frame;
102 return SDL_CDPause( cd );
105 int CDAudio_SysResume (void)
108 endtime = realtime + (cd->track[ cdPlayTrack - 1 ].length - pauseoffset) / CD_FPS;
109 return SDL_CDPlayTracks( cd, cdPlayTrack - 1, (int)pauseoffset, cdPlayTrack, 0 );
112 int CDAudio_SysUpdate (void)
114 if( !cd || cd->status <= 0 ) {
118 if( endtime > 0.0 && realtime >= endtime )
119 if( SDL_CDStatus( cd ) == CD_STOPPED ){
122 CDAudio_SysPlay( cdPlayTrack );
130 void CDAudio_SysInit (void)
132 if( SDL_InitSubSystem( SDL_INIT_CDROM ) == -1 )
133 Con_Print( "Failed to init the CDROM SDL subsystem!\n" );
135 Cmd_AddCommand( "cddrive", CDAudio_SDL_CDDrive_f );
138 static int IsAudioCD( void )
141 for( i = 0 ; i < cd->numtracks ; i++ )
142 if( cd->track[ i ].type == SDL_AUDIO_TRACK )
147 int CDAudio_SysStartup (void)
152 numdrives = SDL_CDNumDrives();
153 if( numdrives == -1 ) // was the CDROM system initialized correctly?
156 Con_Printf( "Found %i cdrom drives.\n", numdrives );
158 for( i = 0 ; i < numdrives ; i++, cd = NULL ) {
159 cd = SDL_CDOpen( i );
161 Con_Printf( "CD drive %i is invalid.\n", i );
165 if( CD_INDRIVE( SDL_CDStatus( cd ) ) )
169 Con_Printf( "The CD in drive %i is not an audio cd.\n", i );
171 Con_Printf( "No CD in drive %i.\n", i );
176 if( i == numdrives && !cd )
184 void CDAudio_SysShutdown (void)
190 void CDAudio_SDL_CDDrive_f( void )
193 int numdrives = SDL_CDNumDrives();
195 if( Cmd_Argc() != 2 ) {
196 Con_Print( "cddrive <drivenr>\n" );
200 i = atoi( Cmd_Argv( 1 ) );
201 if( i >= numdrives ) {
202 Con_Printf("Only %i drives!\n", numdrives );
209 cd = SDL_CDOpen( i );
211 Con_Printf( "Couldn't open drive %i.\n", i );
215 if( !CD_INDRIVE( SDL_CDStatus( cd ) ) )
216 Con_Printf( "No cd in drive %i.\n", i );
217 else if( !IsAudioCD() )
218 Con_Printf( "The CD in drive %i is not an audio CD.\n", i );