Minor cd_sdl.c cleanups from uhexen2. Reorganized cdaudio volume

handling. If volume is 0, don't bother advancing and pause.


git-svn-id: http://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@351 af15c1b1-3010-417e-b628-4374ebc0bcbd
This commit is contained in:
sezero 2010-12-30 14:55:25 +00:00
parent d0ae9d2d65
commit f4b0b373cb
1 changed files with 33 additions and 33 deletions

View File

@ -108,14 +108,12 @@ void CDAudio_Play(byte track, qboolean looping)
{
if (playTrack == track)
return;
CDAudio_Stop ();
CDAudio_Stop();
}
if (SDL_CDPlay(cd_handle, cd_handle->track[track-1].offset, cd_handle->track[track-1].length) == -1)
{
// ok, check for status now
int cd_status = SDL_CDStatus(cd_handle);
if (cd_status > 0)
Con_Printf ("CDAudio_Play: Unable to play %d: %s\n", track, SDL_GetError ());
return;
@ -137,7 +135,7 @@ void CDAudio_Play(byte track, qboolean looping)
endOfTrack += 2.0;
pausetime = -1.0;
if (!hw_vol_works && bgmvolume.value == 0.0)
if (bgmvolume.value == 0) /* don't bother advancing */
CDAudio_Pause ();
}
@ -269,12 +267,12 @@ static void CD_f (void)
if (Q_strcasecmp(command, "remap") == 0)
{
ret = Cmd_Argc () - 2;
ret = Cmd_Argc() - 2;
if (ret <= 0)
{
for (n = 1; n < 100; n++)
if (remap[n] != n)
Con_Printf (" %u -> %u\n", n, remap[n]);
Con_Printf(" %u -> %u\n", n, remap[n]);
return;
}
for (n = 1; n <= ret; n++)
@ -284,7 +282,7 @@ static void CD_f (void)
if (!cdValid)
{
CDAudio_GetAudioDiskInfo ();
CDAudio_GetAudioDiskInfo();
if (!cdValid)
{
Con_Printf("No CD in player.\n");
@ -359,9 +357,9 @@ static void CD_f (void)
Con_Printf ("%u tracks\n", cd_handle->numtracks);
if (playing)
Con_Printf ("Currently %s track %u\n", playLooping ? "looping" : "playing", playTrack);
Con_Printf("Currently %s track %u\n", playLooping ? "looping" : "playing", playTrack);
else if (wasPlaying)
Con_Printf ("Paused %s track %u\n", playLooping ? "looping" : "playing", playTrack);
Con_Printf("Paused %s track %u\n", playLooping ? "looping" : "playing", playTrack);
if (playing || wasPlaying)
{
@ -373,7 +371,7 @@ static void CD_f (void)
current_min, current_sec, current_frame * 60 / CD_FPS,
length_min, length_sec, length_frame * 60 / CD_FPS);
}
Con_Printf ("Volume is %f\n", bgmvolume.value);
Con_Printf("Volume is %f\n", bgmvolume.value);
return;
}
@ -394,30 +392,28 @@ static qboolean CD_SetVolume (void *unused)
return false;
}
static qboolean CDAudio_SetVolume (cvar_t *var)
static qboolean CDAudio_SetVolume (float value)
{
if (!cd_handle || !enabled)
return false;
if (var->value < 0.0)
Cvar_SetValue (var->name, 0.0);
else if (var->value > 1.0)
Cvar_SetValue (var->name, 1.0);
old_cdvolume = var->value;
if (hw_vol_works)
old_cdvolume = value;
if (value == 0.0f)
CDAudio_Pause ();
else
CDAudio_Resume();
if (!hw_vol_works)
{
return false;
}
else
{
/* FIXME: write proper code in here when SDL
supports cdrom volume control some day. */
return CD_SetVolume (NULL);
}
else
{
if (old_cdvolume == 0.0)
CDAudio_Pause ();
else
CDAudio_Resume();
return false;
}
}
void CDAudio_Update(void)
@ -428,7 +424,13 @@ void CDAudio_Update(void)
return;
if (old_cdvolume != bgmvolume.value)
CDAudio_SetVolume (&bgmvolume);
{
if (bgmvolume.value < 0)
Cvar_Set ("bgmvolume", "0.0");
else if (bgmvolume.value > 1)
Cvar_Set ("bgmvolume", "1.0");
CDAudio_SetVolume (bgmvolume.value);
}
if (playing && realtime > endOfTrack)
{
@ -554,7 +556,7 @@ int CDAudio_Init(void)
}
if (cd_dev == -1)
cd_dev = 0; // default drive
cd_dev = 0; /* default drive */
cd_handle = SDL_CDOpen(cd_dev);
if (!cd_handle)
@ -579,10 +581,9 @@ int CDAudio_Init(void)
Cmd_AddCommand ("cd", CD_f);
// cd hardware volume: no SDL support at present.
hw_vol_works = CD_GetVolume (NULL);
hw_vol_works = CD_GetVolume (NULL); /* no SDL support at present. */
if (hw_vol_works)
hw_vol_works = CDAudio_SetVolume (&bgmvolume);
hw_vol_works = CDAudio_SetVolume (bgmvolume.value);
return 0;
}
@ -592,9 +593,8 @@ void CDAudio_Shutdown(void)
if (!cd_handle)
return;
CDAudio_Stop();
// cd hardware volume: no SDL support at present.
// if (hw_vol_works)
// CD_SetVolume (NULL);
if (hw_vol_works)
CD_SetVolume (NULL); /* no SDL support at present. */
SDL_CDClose(cd_handle);
cd_handle = NULL;
cd_dev = -1;