bool CDROM_Interface_SDL::SetDevice (char* path, int forceCD) 
{ 
	char buffer[512];
	strcpy(buffer,path);
	upcase(buffer);

	int num = SDL_CDNumDrives();
	if ((forceCD>=0) && (forceCD<num)) {
		driveID = forceCD;
	        cd = SDL_CDOpen(driveID);
	        SDL_CDStatus(cd);
	   	return true;
	};	
	
	const char* cdname = 0;
	for (int i=0; i<num; i++) {
		cdname = SDL_CDName(i);
		if (strcmp(buffer,cdname)==0) {
			cd = SDL_CDOpen(i);
			SDL_CDStatus(cd);
			driveID = i;
			return true;
		};
	};
	return false; 
};
Exemple #2
0
bool CDROM_Interface_SDL::GetAudioTrackInfo(int track, TMSF& start, unsigned char& attr) {
    if (CD_INDRIVE(SDL_CDStatus(cd))) {
        FRAMES_TO_MSF(cd->track[track-1].offset,&start.min,&start.sec,&start.fr);
        attr	= cd->track[track-1].type<<4;//sdl uses 0 for audio and 4 for data. instead of 0x00 and 0x40
    }
    return CD_INDRIVE(SDL_CDStatus(cd));
}
Exemple #3
0
void CDAudio_Update()
{
	if(!cd_id || !enabled) return;
	if(cd_volume && cd_volume->value != cdvolume)
	{
		if(cdvolume)
		{
			Cvar_SetValue("cd_volume",0.0);
			CDAudio_Pause();
		}
		else
		{
			Cvar_SetValue("cd_volume",1.0);
			CDAudio_Resume();
		}
		cdvolume = cd_volume->value;
		return;
	}
	
	if(cd_nocd->value)
	{
		CDAudio_Stop();
		return;
	}
	
	if(playLooping && 
	   (SDL_CDStatus(cd_id) != CD_PLAYING) && 
	   (SDL_CDStatus(cd_id) != CD_PAUSED))
	{
		CDAudio_Play(lastTrack,true);
	}
}
Exemple #4
0
bool CDROM_Interface_SDL::GetAudioStatus(bool& playing, bool& pause) {
    if (CD_INDRIVE(SDL_CDStatus(cd))) {
        playing = (cd->status==CD_PLAYING);
        pause	= (cd->status==CD_PAUSED);
    }
    return CD_INDRIVE(SDL_CDStatus(cd));
}
bool CDROM_Interface_SDL::GetAudioTrackInfo (int track, TMSF& start, unsigned char& attr)
{
	if (CD_INDRIVE(SDL_CDStatus(cd))) {
		FRAMES_TO_MSF(cd->track[track-1].offset+150,&start.min,&start.sec,&start.fr);
		attr	= cd->track[track-1].type;
	}
	return CD_INDRIVE(SDL_CDStatus(cd));	
};
Exemple #6
0
bool CDROM_Interface_SDL::GetAudioTracks(int& stTrack, int& end, TMSF& leadOut) {

    if (CD_INDRIVE(SDL_CDStatus(cd))) {
        stTrack		= 1;
        end			= cd->numtracks;
        FRAMES_TO_MSF(cd->track[cd->numtracks].offset,&leadOut.min,&leadOut.sec,&leadOut.fr);
    }
    return CD_INDRIVE(SDL_CDStatus(cd));
}
Exemple #7
0
bool CDROM_Interface_SDL::GetMediaTrayStatus(bool& mediaPresent, bool& mediaChanged, bool& trayOpen) {
    SDL_CDStatus(cd);
    mediaPresent = (cd->status!=CD_TRAYEMPTY) && (cd->status!=CD_ERROR);
    mediaChanged = (oldLeadOut!=cd->track[cd->numtracks].offset);
    trayOpen	 = !mediaPresent;
    oldLeadOut	 = cd->track[cd->numtracks].offset;
    if (mediaChanged) SDL_CDStatus(cd);
    return true;
}
Exemple #8
0
bool CDROM_Interface_SDL::GetAudioSub(unsigned char& attr, unsigned char& track, unsigned char& index, TMSF& relPos, TMSF& absPos) {
    if (CD_INDRIVE(SDL_CDStatus(cd))) {
        track	= cd->cur_track;
        index	= cd->cur_track;
        attr	= cd->track[track].type<<4;
        FRAMES_TO_MSF(cd->cur_frame,&relPos.min,&relPos.sec,&relPos.fr);
        FRAMES_TO_MSF(cd->cur_frame+cd->track[track].offset,&absPos.min,&absPos.sec,&absPos.fr);
    }
    return CD_INDRIVE(SDL_CDStatus(cd));
}
Exemple #9
0
int RBAPeekPlayStatus()
{
	if (!s_cd)
		return 0;

	if (SDL_CDStatus(s_cd) == CD_PLAYING)
		return 1;
	else if (SDL_CDStatus(s_cd) == CD_PAUSED)	// hack so it doesn't keep restarting paused music
		return -1;
	
	return 0;
}
Exemple #10
0
int RBAPauseResume()
{
	if (!s_cd) return 0;

	if (SDL_CDStatus(s_cd) == CD_PLAYING)
		SDL_CDPause(s_cd);
	else if (SDL_CDStatus(s_cd) == CD_PAUSED)
		SDL_CDResume(s_cd);
	else
		return 0;

	return 1;
}
Exemple #11
0
int CDAudio_Init()
{
	if((cls.state == ca_dedicated) || COM_CheckParm("-nocdaudio"))
		return -1;
		
	cd_id = SDL_CDOpen(0);
	if(!cd_id)
	{
		Con_Printf("CDAudio_Init: Unable to open default CD-ROM drive: %s\n",
			SDL_GetError());
		return -1;
	}
	
	initialized = true;
	enabled = true;
	cdValid = true;
	
	if(!CD_INDRIVE(SDL_CDStatus(cd_id)))
	{
		Con_Printf("CDAudio_Init: No CD in drive.\n");
		cdValid = false;
	}
	if(!cd_id->numtracks)
	{
		Con_Printf("CDAudio_Init: CD contains no audio tracks.\n");
		cdValid = false;
	}
	Cmd_AddCommand("cd",CD_f);
	Con_Printf("CD Audio Initialized.\n");
	return 0;
}
Exemple #12
0
/**************************************************************************
 *
 * function: CDAudio_GetAudioDiskInfo
 *
 * description:
 * set number of tracks if CD is available
 *
 **************************************************************************/
static INT32 CDAudio_GetAudioDiskInfo(void)
{
	cdValid = SDL_FALSE;
	maxTrack = 0;

	if (!cdrom)
		return 0;//Alam: Lies!

	cdStatus = SDL_CDStatus(cdrom);

	if (!CD_INDRIVE(cdStatus))
	{
		CONS_Printf("%s", M_GetText("No CD in drive\n"));
		return -1;
	}

	if (cdStatus == CD_ERROR)
	{
		CONS_Printf(M_GetText("CD Error: %s\n"), SDL_GetError());
		return -1;
	}

	cdValid = SDL_TRUE;
	maxTrack = (Uint8)cdrom->numtracks;

	return 0;
}
Exemple #13
0
bool SdlAudioCDManager::play(int track, int numLoops, int startFrame, int duration, bool onlyEmulate) {
	// Prefer emulation
	if (DefaultAudioCDManager::play(track, numLoops, startFrame, duration, onlyEmulate))
		return true;

	// If we're set to only emulate, or have no CD, return here
	if (onlyEmulate || !_cdrom)
		return false;

	if (!numLoops && !startFrame)
		return false;

	// FIXME: Explain this.
	if (duration > 0)
		duration += 5;

	_cdTrack = track;
	_cdNumLoops = numLoops;
	_cdStartFrame = startFrame;

	SDL_CDStatus(_cdrom);
	if (startFrame == 0 && duration == 0)
		SDL_CDPlayTracks(_cdrom, track, 0, 1, 0);
	else
		SDL_CDPlayTracks(_cdrom, track, startFrame, 0, duration);
	_cdDuration = duration;
	_cdStopTime = 0;
	_cdEndTime = SDL_GetTicks() + _cdrom->track[track].length * 1000 / CD_FPS;

	return true;
}
Exemple #14
0
static PyObject*
cd_get_track_length (PyObject* self, PyObject* args)
{
    int cd_id = PyCD_AsID (self);
    SDL_CD* cdrom = cdrom_drivedata[cd_id];
    int track;

    if (!PyArg_ParseTuple (args, "i", &track)) {
        return NULL;
    }

    CDROM_INIT_CHECK ();
    if (!cdrom) {
        return RAISE (PyExc_SDLError, "CD drive not initialized");
    }
    SDL_CDStatus (cdrom);
    if (track < 0 || track >= cdrom->numtracks) {
        return RAISE (PyExc_IndexError, "Invalid track number");
    }
    if (cdrom->track[track].type != SDL_AUDIO_TRACK) {
        return PyFloat_FromDouble (0.0);
    }

    return PyFloat_FromDouble (cdrom->track[track].length / (double) CD_FPS);
}
Exemple #15
0
void RBAInit()
{
	int num_cds;
	int i,j;
	
	if (initialised) return;

	if (SDL_Init(SDL_INIT_CDROM) < 0)
	{
		Warning("SDL library initialisation failed: %s.",SDL_GetError());
		return;
	}

	num_cds = SDL_CDNumDrives();
	if (num_cds < 1)
	{
		con_printf(CON_NORMAL, "No cdrom drives found!\n");
#if defined(__APPLE__) || defined(macintosh)
		SDL_QuitSubSystem(SDL_INIT_CDROM);	// necessary for rescanning CDROMs
#endif
		return;
	}
	
	for (i = 0; i < num_cds; i++)
	{
		if (s_cd)
			SDL_CDClose(s_cd);
		s_cd = SDL_CDOpen(i);
		
		if (s_cd && CD_INDRIVE(SDL_CDStatus(s_cd)))
		{
			for (j = 0; j < s_cd->numtracks; j++)
			{
				if (s_cd->track[j].type == SDL_AUDIO_TRACK)
					break;
			}
			
			if (j != s_cd->numtracks)
				break;	// we've found an audio CD
		}
		else if (s_cd == NULL)
			Warning("Could not open cdrom %i for redbook audio:%s\n", i, SDL_GetError());
	}
	
	if (i == num_cds)
	{
		con_printf(CON_NORMAL, "No audio CDs found\n");
		if (s_cd)	// if there's no audio CD, say that there's no redbook and hence play MIDI instead
		{
			SDL_CDClose(s_cd);
			s_cd = NULL;
		}
#if defined(__APPLE__) || defined(macintosh)
		SDL_QuitSubSystem(SDL_INIT_CDROM);	// necessary for rescanning CDROMs
#endif
		return;
	}
	
	initialised = 1;
}
Exemple #16
0
int RBAGetNumberOfTracks()
{
	if (!initialised) 
		return -1;
	SDL_CDStatus(s_cd);
	return s_cd->numtracks;
}
Exemple #17
0
void cd_playtoggle()
{
//added on 01/03/99 by Matt Mueller
  if (nocdaudio) return;
//end addition -MM

#ifdef __DJGPP__
  if(bcd_now_playing())
#elif defined __SDL__
  if(SDL_CDStatus(cdrom)==CD_PLAYING)
#else
  if(0)
#endif
   {
     cd_stop();
     cd_playing=0;
   }
  else if(!cd_used)
   {
     cd_currenttrack = 0;
     cd_playtrack(cd_currenttrack);
   }
  else
   {
     cd_resume();
   }
 cd_used = 1;
}
Exemple #18
0
int cd_playtrack(int trackno)
{
 int track;
//added on 01/03/99 by Matt Mueller
  if (nocdaudio) return 0;
//end addition -MM

   if(trackno > MAX_TRACKS || trackno < 0)
    return 0;
  track = playlist[trackno];

#ifdef __DJGPP__
   if(bcd_play_track(&track))
#elif defined __SDL__
   if(CD_INDRIVE(SDL_CDStatus(cdrom)) && !SDL_CDPlayTracks(cdrom,track,0,1,0))
#else
   if(0)
#endif
    cd_playing = 1;
   else
    cd_playing = 0;

  cd_used = 1;
  return cd_playing;
}
Exemple #19
0
void CDAudio_Play(byte track, qboolean looping)
{
	CDstatus cd_stat;
	if(!cd_id || !enabled) return;
	
	if(!cdValid)
	{
		if(!CD_INDRIVE(cd_stat=SDL_CDStatus(cd_id)) ||(!cd_id->numtracks)) return;
		cdValid = true;
	}

	if((track < 1) || (track >= cd_id->numtracks))
	{
		Con_DPrintf("CDAudio: Bad track number: %d\n",track);
		return;
	}
	track--; /* Convert track from person to SDL value */
	if(cd_stat == CD_PLAYING)
	{
		if(cd_id->cur_track == track) return;
		CDAudio_Stop();
	}

	if(SDL_CDPlay(cd_id,cd_id->track[track].offset,
			  cd_id->track[track].length))
	{
		Con_DPrintf("CDAudio_Play: Unable to play track: %d\n",track+1);
		return;
	}
	playLooping = looping;
}
Exemple #20
0
void RBAInit()
{
	if (initialised) return;
	if (FindArg("-nocdrom")) return; 

	if (SDL_Init(SDL_INIT_CDROM) < 0)
	{
		Warning("SDL library initialisation failed: %s.",SDL_GetError());
		return;
	}

	if (SDL_CDNumDrives() == 0)
	{
		Warning("No cdrom drives found!\n");
		return;
	}
	s_cd = SDL_CDOpen(0);
	if (s_cd == NULL) {
		Warning("Could not open cdrom for redbook audio!\n");
		return;
	}

	SDL_CDStatus(s_cd); /* update the drive status */

	atexit(RBAExit);
	initialised = 1;
}
Exemple #21
0
void OSystem_SDL::updateCD() {
	if (!_cdrom)
		return;

	if (_cdStopTime != 0 && SDL_GetTicks() >= _cdStopTime) {
		SDL_CDStop(_cdrom);
		_cdNumLoops = 0;
		_cdStopTime = 0;
		return;
	}

	if (_cdNumLoops == 0 || SDL_GetTicks() < _cdEndTime)
		return;

	if (_cdNumLoops != 1 && SDL_CDStatus(_cdrom) != CD_STOPPED) {
		// Wait another second for it to be done
		_cdEndTime += 1000;
		return;
	}

	if (_cdNumLoops > 0)
		_cdNumLoops--;

	if (_cdNumLoops != 0) {
		if (_cdStartFrame == 0 && _cdDuration == 0)
			SDL_CDPlayTracks(_cdrom, _cdTrack, 0, 1, 0);
		else
			SDL_CDPlayTracks(_cdrom, _cdTrack, _cdStartFrame, 0, _cdDuration);
		_cdEndTime = SDL_GetTicks() + _cdrom->track[_cdTrack].length * 1000 / CD_FPS;
	}
}
Exemple #22
0
void SoundManager::TerminateMusic(void)
{
	if (!g_theProfileDB->IsUseRedbookAudio() || !c3files_HasCD()) return;

	if (m_noSound) return;

	if (m_usePlaySound) return;

#if !defined(USE_SDL)
	if (!m_redbook) return;
#else
    if (!m_cdrom) return;
#endif

	
	m_stopRedbookTemporarily = TRUE;

#if !defined(USE_SDL)
	if (AIL_redbook_track(m_redbook)) {		
		AIL_redbook_stop(m_redbook);
	}
#else
    CDstatus status = SDL_CDStatus(m_cdrom);

    if (CD_PLAYING == status) {
        SDL_CDStop(m_cdrom);
    }
#endif
}
Exemple #23
0
static void PrintStatus(int driveindex, SDL_CD *cdrom)
{
	CDstatus status;
	char *status_str;

	status = SDL_CDStatus(cdrom);
	switch (status) {
		case CD_TRAYEMPTY:
			status_str = "tray empty";
			break;
		case CD_STOPPED:
			status_str = "stopped";
			break;
		case CD_PLAYING:
			status_str = "playing";
			break;
		case CD_PAUSED:
			status_str = "paused";
			break;
		case CD_ERROR:
			status_str = "error state";
			break;
	}
	printf("Drive %d status: %s\n", driveindex, status_str);
	if ( status >= CD_PLAYING ) {
		int m, s, f;
		FRAMES_TO_MSF(cdrom->cur_frame, &m, &s, &f);
		printf("Currently playing track %d, %d:%2.2d\n",
			cdrom->track[cdrom->cur_track].id, m, s);
	}
}
Exemple #24
0
static void ListTracks(SDL_CD *cdrom)
{
	int i;
	int m, s, f;
	char* trtype;

	SDL_CDStatus(cdrom);
	printf("Drive tracks: %d\n", cdrom->numtracks);
	for ( i=0; i<cdrom->numtracks; ++i ) {
		FRAMES_TO_MSF(cdrom->track[i].length, &m, &s, &f);
		if ( f > 0 )
			++s;
		switch(cdrom->track[i].type)
		{
		    case SDL_AUDIO_TRACK:
			trtype="audio";
			break;
		    case SDL_DATA_TRACK:
			trtype="data";
			break;
		    default:
			trtype="unknown";
			break;
		}
		printf("\tTrack (index %d) %d: %d:%2.2d / %d [%s track]\n", i,
					cdrom->track[i].id, m, s, cdrom->track[i].length, trtype);
	}
}
Exemple #25
0
static int ValidateDrive( void )
{
	if( cd && SDL_CDStatus( cd ) > 0 )
		return cdValid = true;

	return cdValid = false;
}
Exemple #26
0
void CDAudio_SDL_CDDrive_f( void )
{
	int i;
	int numdrives = SDL_CDNumDrives();

	if( Cmd_Argc() != 2 ) {
		Con_Print( "cddrive <drivenr>\n" );
		return;
	}

	i = atoi( Cmd_Argv( 1 ) );
	if( i >= numdrives ) {
		Con_Printf("Only %i drives!\n", numdrives );
		return;
	}

	if( cd )
		SDL_CDClose( cd );

	cd = SDL_CDOpen( i );
	if( !cd ) {
		Con_Printf( "Couldn't open drive %i.\n", i );
		return;
	}

	if( !CD_INDRIVE( SDL_CDStatus( cd ) ) )
		Con_Printf( "No cd in drive %i.\n", i );
	else if( !IsAudioCD() )
		Con_Printf( "The CD in drive %i is not an audio CD.\n", i );

	ValidateDrive();
}
Exemple #27
0
int CDAudio_SysStartup (void)
{
	int i;
	int numdrives;

	numdrives = SDL_CDNumDrives();
	if( numdrives == -1 ) // was the CDROM system initialized correctly?
		return -1;

	Con_Printf( "Found %i cdrom drives.\n", numdrives );

	for( i = 0 ; i < numdrives ; i++, cd = NULL ) {
		cd = SDL_CDOpen( i );
		if( !cd ) {
			Con_Printf( "CD drive %i is invalid.\n", i );
			continue;
		}

		if( CD_INDRIVE( SDL_CDStatus( cd ) ) )
			if( IsAudioCD() )
				break;
			else
				Con_Printf( "The CD in drive %i is not an audio cd.\n", i );
		else
			Con_Printf( "No CD in drive %i.\n", i );

		SDL_CDClose( cd );
	}

	if( i == numdrives && !cd )
		return -1;

	return 0;
}
Exemple #28
0
void
CDAudio_Update ()
{
	static int cnt = 0;

	if ( !cd_id || !enabled )
	{
		return;
	}

	if ( cd_volume && ( cd_volume->value != cdvolume ) )
	{
		if ( cdvolume )
		{
			Cvar_SetValue( "cd_volume", 0.0 );
			CDAudio_Pause();
		}
		else
		{
			Cvar_SetValue( "cd_volume", 1.0 );
			CDAudio_Resume();
		}

		cdvolume = cd_volume->value;
		return;
	}

	/* this causes too much overhead to be executed every frame */
	if ( ++cnt == 16 )
	{
		cnt = 0;

		if ( cd_nocd->value )
		{
			CDAudio_Stop();
			return;
		}

		if ( playLooping &&
			 ( SDL_CDStatus( cd_id ) != CD_PLAYING ) &&
			 ( SDL_CDStatus( cd_id ) != CD_PAUSED ) )
		{
			CDAudio_Play( lastTrack, true );
		}
	}
}
Exemple #29
0
void CDAudio_Pause()
{
	if(!cd_id || !enabled) return;
	if(SDL_CDStatus(cd_id) != CD_PLAYING) return;

	if(SDL_CDPause(cd_id))
		Com_DPrintf("CDAudio_Pause: Failed to pause track.\n");
}
Exemple #30
0
void CDAudio_Resume()
{
	if(!cd_id || !enabled) return;
	if(SDL_CDStatus(cd_id) != CD_PAUSED) return;

	if(SDL_CDResume(cd_id))
		Com_DPrintf("CDAudio_Resume: Failed to resume track.\n");
}