Ejemplo n.º 1
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));
}
Ejemplo n.º 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));
}
Ejemplo n.º 3
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+150,&start.min,&start.sec,&start.fr);
		attr	= cd->track[track-1].type;
	}
	return CD_INDRIVE(SDL_CDStatus(cd));	
};
Ejemplo n.º 4
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));
}
Ejemplo n.º 5
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));
}
Ejemplo n.º 6
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;
}
Ejemplo n.º 7
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;
}
Ejemplo n.º 8
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;
}
Ejemplo n.º 9
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;
}
Ejemplo n.º 10
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;
}
Ejemplo n.º 11
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;
}
Ejemplo n.º 12
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();
}
Ejemplo n.º 13
0
Archivo: rbaudio.c Proyecto: btb/d2x
int RBAPlayTrack(int a)
{
	if (!initialised) return -1;

	if (CD_INDRIVE(SDL_CDStatus(s_cd)) ) {
		SDL_CDPlayTracks(s_cd, a-1, 0, 0, 0);
	}
	return a;
}
Ejemplo n.º 14
0
// plays tracks first through last, inclusive
int RBAPlayTracks(int first, int last)
{
if (!initialised)
	return 0;
if (!CD_INDRIVE(SDL_CDStatus(s_cd)))
	return 0;
if (0 > SDL_CDPlayTracks(s_cd, first - 1, 0, last - first + 1, 0))
	return 0;
return 1;
}
Ejemplo n.º 15
0
int RBAPlayTrack(int a)
{
	if (!s_cd) return -1;

	if (CD_INDRIVE(SDL_CDStatus(s_cd)) ) {
		if (SDL_CDPlayTracks(s_cd, a-1, 0, 0, 0) == 0)
			return a;
	}
	return -1;
}
Ejemplo n.º 16
0
int CDAudio_Init()
{
	cvar_t *cv;

	if (initialized)
		return 0;

	cv = Cvar_Get ("nocdaudio", "0", CVAR_NOSET);
	if (cv->value)
		return -1;

	cd_nocd = Cvar_Get ("cd_nocd", "0", CVAR_ARCHIVE );
	if ( cd_nocd->value)
		return -1;

	cd_volume = Cvar_Get ("cd_volume", "1", CVAR_ARCHIVE);

	if (SDL_WasInit(SDL_INIT_EVERYTHING) == 0) {
		if (SDL_Init(SDL_INIT_CDROM) < 0) {
			Com_Printf ("Couldn't init SDL cdrom: %s\n", SDL_GetError ());
			return -1;
		}
	} else if (SDL_WasInit(SDL_INIT_CDROM) == 0) {
		if (SDL_InitSubSystem(SDL_INIT_CDROM) < 0) {
			Com_Printf ("Couldn't init SDL cdrom: %s\n", SDL_GetError ());
			return -1;
		}
	}
	
	cd_id = SDL_CDOpen(0);
	if(!cd_id)
	{
		Com_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)))
	{
		Com_Printf("CDAudio_Init: No CD in drive.\n");
		cdValid = false;
	}
	if(!cd_id->numtracks)
	{
		Com_Printf("CDAudio_Init: CD contains no audio tracks.\n");
		cdValid = false;
	}
	Cmd_AddCommand("cd",CD_f);
	Com_Printf("CD Audio Initialized.\n");
	return 0;
}
Ejemplo n.º 17
0
// plays tracks first through last, inclusive
int RBAPlayTracks(int first, int last, void (*hook_finished)(void))
{
	if (!s_cd)
		return 0;

	if (CD_INDRIVE(SDL_CDStatus(s_cd)))
	{
		redbook_finished_hook = hook_finished;
		return SDL_CDPlayTracks(s_cd, first - 1, 0, last - first + 1, 0) == 0;
	}
	return 0;
}
Ejemplo n.º 18
0
void
CDAudio_Play ( int track, qboolean looping )
{
	CDstatus cd_stat;

	lastTrack = track + 1;

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

	cd_stat = SDL_CDStatus( cd_id );

	if ( !cdValid )
	{
		if ( !CD_INDRIVE( cd_stat ) || ( !cd_id->numtracks ) )
		{
			return;
		}

		cdValid = true;
	}

	if ( ( track < 1 ) || ( track >= cd_id->numtracks ) )
	{
		Com_DPrintf( "CDAudio: Bad track number: %d\n", track );
		return;
	}

	track--;

	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 ) )
	{
		Com_DPrintf( "CDAudio_Play: Unable to play track: %d (%s)\n", track + 1, SDL_GetError() );
		return;
	}

	playLooping = looping;
}
Ejemplo n.º 19
0
static int CDAudio_GetAudioDiskInfo(void)
{
	cdValid = false;

	if (!cd_handle)
		return -1;

	if ( ! CD_INDRIVE(SDL_CDStatus(cd_handle)) )
		return -1;

	cdValid = true;

	return 0;
}
Ejemplo n.º 20
0
int I_CDMusInit(void)
{
    int drive_num = 0;

    // The initialize function is re-invoked when the CD track play cheat
    // is used, so use the opportunity to call SDL_CDStatus() to update
    // the status of the drive.

    if (cd_handle == NULL)
    {
        if (SDL_Init(SDL_INIT_CDROM) < 0)
        {
            startup_error = "Failed to init CD subsystem.";
            cd_Error = 1;
            return -1;
        }

        // TODO: config variable to control CDROM to use.

        cd_handle = SDL_CDOpen(drive_num);

        if (cd_handle == NULL)
        {
            startup_error = "Failed to open CD-ROM drive.";
            cd_Error = 1;
            return -1;
        }

        cd_name = SDL_CDName(drive_num);
    }

    if (SDL_CDStatus(cd_handle) == CD_ERROR)
    {
        startup_error = "Failed to read CD status.";
        cd_Error = 1;
        return -1;
    }

    if (!CD_INDRIVE(cd_handle->status))
    {
        startup_error = "No CD in drive.";
        cd_Error = 1;
        return -1;
    }

    cd_Error = 0;

    return 0;
}
Ejemplo n.º 21
0
static int modcd_playtracks( INSTANCE * my, int * params )
{
    if ( params[0] < 0 || params[0] >= SDL_CDNumDrives() ) return 0;

    if ( sdl_cd == NULL || sdl_cdnum != params[0] )
    {
        if ( sdl_cd ) SDL_CDClose( sdl_cd );
        sdl_cd = SDL_CDOpen( params[0] );
        if ( sdl_cd == NULL ) return 0;
        sdl_cdnum = params[0];
    }

    if ( CD_INDRIVE( SDL_CDStatus( sdl_cd ) ) )
        return !SDL_CDPlayTracks( sdl_cd, params[1], 0, params[2], 0 );

    return 0;
}
Ejemplo n.º 22
0
CDstatus
SDL_CDStatus(SDL_CD * cdrom)
{
    CDstatus status;
    int i;
    Uint32 position;

    /* Check if the CD-ROM subsystem has been initialized */
    if (!CheckInit(1, &cdrom)) {
        return (CD_ERROR);
    }

    /* Get the current status of the drive */
    cdrom->numtracks = 0;
    cdrom->cur_track = 0;
    cdrom->cur_frame = 0;
    status = SDL_CDcaps.Status(cdrom, &i);
    position = (Uint32) i;
    cdrom->status = status;

    /* Get the table of contents, if there's a CD available */
    if (CD_INDRIVE(status)) {
        if (SDL_CDcaps.GetTOC(cdrom) < 0) {
            status = CD_ERROR;
        }
        /* If the drive is playing, get current play position */
        if ((status == CD_PLAYING) || (status == CD_PAUSED)) {
            for (i = 1; cdrom->track[i].offset <= position; ++i) {
                /* Keep looking */ ;
            }
#ifdef DEBUG_CDROM
            fprintf(stderr,
                    "Current position: %d, track = %d (offset is %d)\n",
                    position, i - 1, cdrom->track[i - 1].offset);
#endif
            cdrom->cur_track = i - 1;
            position -= cdrom->track[cdrom->cur_track].offset;
            cdrom->cur_frame = position;
        }
    }
    return (status);
}
Ejemplo n.º 23
0
int cd_resume()
{
//added on 01/03/99 by Matt Mueller
  if (nocdaudio) return 0;
//end addition -MM

#ifdef __DJGPP__
  if(bcd_resume())
#elif defined __SDL__
  if(CD_INDRIVE(SDL_CDStatus(cdrom)) && !SDL_CDResume(cdrom))
#else
  if(0)
#endif
   cd_playing = 1;
  else
   cd_playing = 0;

  cd_used = 1;
  return cd_playing;
}
Ejemplo n.º 24
0
CDstatus SDL_CDStatus(SDL_CD *cdrom)
{
	CDstatus status;
	int i;
	Uint32 position;

	
	if ( ! CheckInit(1, &cdrom) ) {
		return(CD_ERROR);
	}

	
	cdrom->numtracks = 0;
	cdrom->cur_track = 0;
	cdrom->cur_frame = 0;
	status = SDL_CDcaps.Status(cdrom, &i);
	position = (Uint32)i;
	cdrom->status = status;

	
	if ( CD_INDRIVE(status) ) {
		if ( SDL_CDcaps.GetTOC(cdrom) < 0 ) {
			status = CD_ERROR;
		}
		
		if ( (status == CD_PLAYING) || (status == CD_PAUSED) ) {
			for ( i=1; cdrom->track[i].offset <= position; ++i ) {
				;
			}
#ifdef DEBUG_CDROM
  fprintf(stderr, "Current position: %d, track = %d (offset is %d)\n",
				position, i-1, cdrom->track[i-1].offset);
#endif
			cdrom->cur_track = i-1;
			position -= cdrom->track[cdrom->cur_track].offset;
			cdrom->cur_frame = position;
		}
	}
	return(status);
}
Ejemplo n.º 25
0
static int CDAudio_GetAudioDiskInfo()
{
  cdValid = false;
  maxTrack = 0;
    
  cdStatus = SDL_CDStatus(cdrom);

  if (!CD_INDRIVE(cdStatus))
    {
      CONS_Printf(" No CD in drive\n");
      return -1;
    }
    
  if (cdStatus == CD_ERROR)
    {
      CONS_Printf(" CD Error: %s\n", SDL_GetError());
      return -1;
    }
    
  cdValid = true;
  maxTrack = cdrom->numtracks;
    
  return 0;
}
Ejemplo n.º 26
0
void SoundManager::StartMusic(const sint32 &InTrackNum)
{
	m_stopRedbookTemporarily = FALSE;

	if (!g_theProfileDB->IsUseRedbookAudio() || !c3files_HasCD()) return;

	if (m_noSound) return;

	if (m_usePlaySound) return;

	if (m_curTrack == -1) return;

#if defined(USE_SDL)
    if (!m_cdrom) {
        return;
    }

    CDstatus status = SDL_CDStatus(m_cdrom);

    if ((CD_ERROR == status) || (!CD_INDRIVE(status))) {
        return;
    }

	sint32 const numTracks = m_cdrom->numtracks;
#else
    if (!m_redbook) {
        return;
    }

	U32 status = AIL_redbook_status(m_redbook);

    if (status == REDBOOK_ERROR) {
        return;
    }
	
	if (AIL_redbook_track(m_redbook)) {
		AIL_redbook_stop(m_redbook);
	}

	sint32 const numTracks = AIL_redbook_tracks(m_redbook);
#endif

	if (numTracks <= s_startTrack) return;

	m_numTracks = numTracks;
	
	sint32 trackNum = InTrackNum;
	if (trackNum < 0) trackNum = 0;
	if (trackNum > m_numTracks) trackNum = m_numTracks;

	m_curTrack = trackNum;

#if defined(USE_SDL)
    SDL_CDPlayTracks(m_cdrom, trackNum, 0, 1, 0);
#else
	U32 start;
    U32 end;
	AIL_redbook_track_info(m_redbook, trackNum, &start, &end);

    // Why?
	TerminateAllSounds();

	AIL_redbook_play(m_redbook, start, end);
#endif
}
Ejemplo n.º 27
0
int main(int argc, char *argv[])
{
	int drive;
	int i;
	SDL_CD *cdrom;

	/* Initialize SDL first */
	if ( SDL_Init(SDL_INIT_CDROM) < 0 ) {
		fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
		return(1);
	}

	/* Find out how many CD-ROM drives are connected to the system */
	if ( SDL_CDNumDrives() == 0 ) {
		printf("No CD-ROM devices detected\n");
		quit(0);
	}
	printf("Drives available: %d\n", SDL_CDNumDrives());
	for ( i=0; i<SDL_CDNumDrives(); ++i ) {
		printf("Drive %d:  \"%s\"\n", i, SDL_CDName(i));
	}

	/* Open the CD-ROM */
	drive = 0;
	i=1;
	if ( argv[i] && isdigit(argv[i][0]) ) {
		drive = atoi(argv[i++]);
	}
	cdrom = SDL_CDOpen(drive);
	if ( cdrom == NULL ) {
		fprintf(stderr, "Couldn't open drive %d: %s\n", drive,
							SDL_GetError());
		quit(2);
	}
#ifdef TEST_NULLCD
	cdrom = NULL;
#endif
	
	/* Find out which function to perform */
	for ( ; argv[i]; ++i ) {
		if ( strcmp(argv[i], "-status") == 0 ) {
			/* PrintStatus(drive, cdrom); */
		} else
		if ( strcmp(argv[i], "-list") == 0 ) {
			ListTracks(cdrom);
		} else
		if ( strcmp(argv[i], "-play") == 0 ) {
			int strack, sframe;
			int ntrack, nframe;

			strack = 0;
			if ( argv[i+1] && isdigit(argv[i+1][0]) ) {
				strack = atoi(argv[++i]);
			}
			sframe = 0;
			if ( argv[i+1] && isdigit(argv[i+1][0]) ) {
				sframe = atoi(argv[++i]);
			}
			ntrack = 0;
			if ( argv[i+1] && isdigit(argv[i+1][0]) ) {
				ntrack = atoi(argv[++i]);
			}
			nframe = 0;
			if ( argv[i+1] && isdigit(argv[i+1][0]) ) {
				nframe = atoi(argv[++i]);
			}
			if ( CD_INDRIVE(SDL_CDStatus(cdrom)) ) {
				if ( SDL_CDPlayTracks(cdrom, strack, sframe,
							ntrack, nframe) < 0 ) {
					fprintf(stderr,
			"Couldn't play tracks %d/%d for %d/%d: %s\n",
				strack, sframe, ntrack, nframe, SDL_GetError());
				}
			} else {
				fprintf(stderr, "No CD in drive!\n");
			}
		} else
		if ( strcmp(argv[i], "-pause") == 0 ) {
			if ( SDL_CDPause(cdrom) < 0 ) {
				fprintf(stderr, "Couldn't pause CD: %s\n",
								SDL_GetError());
			}
		} else
		if ( strcmp(argv[i], "-resume") == 0 ) {
			if ( SDL_CDResume(cdrom) < 0 ) {
				fprintf(stderr, "Couldn't resume CD: %s\n",
								SDL_GetError());
			}
		} else
		if ( strcmp(argv[i], "-stop") == 0 ) {
			if ( SDL_CDStop(cdrom) < 0 ) {
				fprintf(stderr, "Couldn't eject CD: %s\n",
								SDL_GetError());
			}
		} else
		if ( strcmp(argv[i], "-eject") == 0 ) {
			if ( SDL_CDEject(cdrom) < 0 ) {
				fprintf(stderr, "Couldn't eject CD: %s\n",
								SDL_GetError());
			}
		} else
		if ( (strcmp(argv[i], "-sleep") == 0) &&
				(argv[i+1] && isdigit(argv[i+1][0])) ) {
			SDL_Delay(atoi(argv[++i]));
			printf("Delayed %d milliseconds\n", atoi(argv[i]));
		} else {
			PrintUsage(argv[0]);
			SDL_CDClose(cdrom);
			quit(1);
		}
	}
	PrintStatus(drive, cdrom);
	SDL_CDClose(cdrom);
	SDL_Quit();

	return(0);
}
Ejemplo n.º 28
0
void CDAudio_RandomPlay(void)
{
  int track, i = 0, free_tracks = 0;
  float f;
  CDstatus cd_stat;
  byte* track_bools;

  if (!cd_id || !enabled)
    return;

  track_bools = (byte*)malloc(cd_id->numtracks* sizeof(byte));

  if (track_bools == 0)
    return;

  //create array of available audio tracknumbers

  for (; i < cd_id->numtracks; i++)
    {
      track_bools[i] = cd_id->track[i].type == SDL_AUDIO_TRACK;
      free_tracks += track_bools[i];
    }

  if (!free_tracks)
    {
      Com_DPrintf("CDAudio_RandomPlay: Unable to find and play a random audio track, insert an audio cd please");
      goto free_end;
    }

  //choose random audio track
  do
    {
      do
	{
	  f = ((float)rand()) / ((float)RAND_MAX + 1.0);
	  track = (int)(cd_id->numtracks  * f);
	}
      while(!track_bools[track]);
      
      lastTrack = track+1;
      
      cd_stat=SDL_CDStatus(cd_id);
      
      if(!cdValid)
	{
	  if(!CD_INDRIVE(cd_stat) ||(!cd_id->numtracks)) 
	    {
	      goto free_end;
	    }
	  cdValid = true;
	}
      
      if(cd_stat == CD_PLAYING)
	{
	  if(cd_id->cur_track == track + 1) 
	    {
	      goto free_end;
	    }
	  CDAudio_Stop();
	}
      
      if (SDL_CDPlay(cd_id,cd_id->track[track].offset,
		     cd_id->track[track].length))
	{
	  track_bools[track] = 0;
	  free_tracks--;
	}
      else
	{
	  playLooping = true;
	  break;
	}
    }
  while (free_tracks > 0);

 free_end:
  free((void*)track_bools);
}