spingle/source/sdl/cd_sdl.c

584 lines
12 KiB
C
Raw Normal View History

2019-11-24 20:45:15 -08:00
/*
* cd_sdl.c
*
* Copyright (C) 1996-1997 Id Software, Inc.
* Taken from the Twilight project with modifications
* to make it work with Hexen II: Hammer of Thyrion.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <SDL.h>
2019-11-24 22:41:23 -08:00
#if !defined(SDL_INIT_CDROM)
2019-11-24 20:45:15 -08:00
2019-11-24 22:41:23 -08:00
/* SDL dropped support for CD audio since v1.3.0 */
2019-11-24 20:45:15 -08:00
#include "cd_null.c"
2019-11-24 22:41:23 -08:00
#else /* defined(SDL_INIT_CDROM) */
2019-11-24 20:45:15 -08:00
2019-12-02 07:07:37 -08:00
#include "q_defs.h"
2019-11-24 22:41:23 -08:00
#include "cdaudio.h"
2019-11-24 20:45:15 -08:00
2019-11-25 15:28:38 -08:00
static bool cdValid = false;
2019-11-25 17:40:18 -08:00
static bool playing = false;
static bool wasPlaying = false;
static bool enabled = true;
2019-11-25 15:28:38 -08:00
static bool playLooping = false;
2019-11-25 17:40:18 -08:00
static byte remap[100];
static byte playTrack;
static double endOfTrack = -1.0, pausetime = -1.0;
static SDL_CD *cd_handle;
static int32_t cd_dev = -1;
static float old_cdvolume;
static bool hw_vol_works = true;
2019-11-24 20:45:15 -08:00
static void CDAudio_Eject(void)
{
2019-11-25 17:40:18 -08:00
if(!cd_handle || !enabled)
2019-11-24 20:45:15 -08:00
return;
2019-12-02 04:24:20 -08:00
#if PLATFORM_IS(LINUX)
2019-11-25 17:40:18 -08:00
SDL_CDStop(cd_handle); /* see CDAudio_Stop() */
2019-11-24 20:45:15 -08:00
#endif
2019-11-25 17:40:18 -08:00
if(SDL_CDEject(cd_handle) < 0)
Con_Printf("Unable to eject CD-ROM: %s\n", SDL_GetError());
2019-11-24 20:45:15 -08:00
}
2019-11-25 16:49:58 -08:00
static int32_t CDAudio_GetAudioDiskInfo(void)
2019-11-24 20:45:15 -08:00
{
cdValid = false;
2019-11-25 17:40:18 -08:00
if(!cd_handle)
2019-11-24 20:45:15 -08:00
return -1;
2019-11-25 17:40:18 -08:00
if(! CD_INDRIVE(SDL_CDStatus(cd_handle)))
2019-11-24 20:45:15 -08:00
return -1;
cdValid = true;
return 0;
}
2019-11-25 16:49:58 -08:00
int32_t CDAudio_Play(byte track, bool looping)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
int32_t len_m, len_s, len_f;
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
if(!cd_handle || !enabled)
2019-11-24 20:45:15 -08:00
return -1;
2019-11-25 17:40:18 -08:00
if(!cdValid)
2019-11-24 20:45:15 -08:00
{
CDAudio_GetAudioDiskInfo();
2019-11-25 17:40:18 -08:00
if(!cdValid)
2019-11-24 20:45:15 -08:00
return -1;
}
track = remap[track];
2019-11-25 17:40:18 -08:00
if(track < 1 || track > cd_handle->numtracks)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
Con_Printf("CDAudio_Play: Bad track number %" PRIi32 ".\n", track);
2019-11-24 20:45:15 -08:00
return -1;
}
2019-11-25 17:40:18 -08:00
if(cd_handle->track[track - 1].type == SDL_DATA_TRACK)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
Con_Printf("CDAudio_Play: track %" PRIi32 " is not audio\n", track);
2019-11-24 20:45:15 -08:00
return -1;
}
2019-11-25 17:40:18 -08:00
if(playing)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
if(playTrack == track)
2019-11-24 20:45:15 -08:00
return 0;
CDAudio_Stop();
}
2019-11-25 17:40:18 -08:00
if(SDL_CDPlay(cd_handle, cd_handle->track[track - 1].offset, cd_handle->track[track - 1].length) < 0)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
Con_Printf("CDAudio_Play: Unable to play track %" PRIi32 ": %s\n", track, SDL_GetError());
2019-11-24 20:45:15 -08:00
return -1;
}
playLooping = looping;
playTrack = track;
playing = true;
2019-11-25 17:40:18 -08:00
FRAMES_TO_MSF(cd_handle->track[track - 1].length, &len_m, &len_s, &len_f);
2019-11-24 20:45:15 -08:00
endOfTrack = realtime + ((double)len_m * 60.0) + (double)len_s + (double)len_f / (double)CD_FPS;
/* Add the pregap for the next track. This means that disc-at-once CDs
* won't loop smoothly, but they wouldn't anyway so it doesn't really
* matter. SDL doesn't give us pregap information anyway, so you'll
* just have to live with it. */
endOfTrack += 2.0;
pausetime = -1.0;
2019-11-25 17:40:18 -08:00
if(bgmvolume.value == 0) /* don't bother advancing */
CDAudio_Pause();
2019-11-24 20:45:15 -08:00
return 0;
}
void CDAudio_Stop(void)
{
2019-11-25 17:40:18 -08:00
if(!cd_handle || !enabled)
2019-11-24 20:45:15 -08:00
return;
2019-11-25 17:40:18 -08:00
if(!playing)
2019-11-24 20:45:15 -08:00
return;
2019-12-02 04:24:20 -08:00
#if PLATFORM_IS(LINUX)
2019-11-24 20:45:15 -08:00
/* Don't really stop, but just pause: On some devices, the CDROMSTOP
* ioctl causes any followup ioctls to fail for a considerable time.
* observed with a TSSTcorp CDW/DVD SH-M522C drive with TS05 and TS08
* firmware versions running under a 2.6.27.25 kernel, and with a
* Samsung DVD r/w drive running under 2.6.35.6 kernel.
* Therefore, avoid dead stops if playback may be resumed shortly. */
2019-11-25 17:40:18 -08:00
if(SDL_CDPause(cd_handle) < 0)
Con_Printf("CDAudio_Stop: Unable to stop CD-ROM (%s)\n", SDL_GetError());
2019-11-24 20:45:15 -08:00
#else
2019-11-25 17:40:18 -08:00
if(SDL_CDStop(cd_handle) < 0)
Con_Printf("CDAudio_Stop: Unable to stop CD-ROM (%s)\n", SDL_GetError());
2019-11-24 20:45:15 -08:00
#endif
wasPlaying = false;
playing = false;
pausetime = -1.0;
endOfTrack = -1.0;
}
void CDAudio_Pause(void)
{
2019-11-25 17:40:18 -08:00
if(!cd_handle || !enabled)
2019-11-24 20:45:15 -08:00
return;
2019-11-25 17:40:18 -08:00
if(!playing)
2019-11-24 20:45:15 -08:00
return;
2019-11-25 17:40:18 -08:00
if(SDL_CDPause(cd_handle) < 0)
Con_Printf("Unable to pause CD-ROM: %s\n", SDL_GetError());
2019-11-24 20:45:15 -08:00
wasPlaying = playing;
playing = false;
pausetime = realtime;
}
void CDAudio_Resume(void)
{
2019-11-25 17:40:18 -08:00
if(!cd_handle || !enabled)
2019-11-24 20:45:15 -08:00
return;
2019-11-25 17:40:18 -08:00
if(!cdValid)
2019-11-24 20:45:15 -08:00
return;
2019-11-25 17:40:18 -08:00
if(!wasPlaying)
2019-11-24 20:45:15 -08:00
return;
2019-11-25 17:40:18 -08:00
if(SDL_CDResume(cd_handle) < 0)
Con_Printf("Unable to resume CD-ROM: %s\n", SDL_GetError());
2019-11-24 20:45:15 -08:00
playing = true;
endOfTrack += realtime - pausetime;
pausetime = -1.0;
}
2019-11-25 17:40:18 -08:00
static int32_t get_first_audiotrk(void)
2019-11-24 20:45:15 -08:00
{
2019-11-25 16:49:58 -08:00
int32_t i;
2019-11-25 17:40:18 -08:00
for(i = 0; i < cd_handle->numtracks; ++i)
if(cd_handle->track[i].type != SDL_DATA_TRACK)
2019-11-24 20:45:15 -08:00
return ++i;
return 1;
}
2019-11-25 17:40:18 -08:00
static void CD_f(void)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
const char *command;
int32_t ret, n;
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
if(Cmd_Argc() < 2)
2019-11-24 20:45:15 -08:00
{
Con_Printf("commands:");
Con_Printf("on, off, reset, remap, \n");
Con_Printf("play, stop, loop, pause, resume\n");
Con_Printf("eject, info, next, prev\n");
return;
}
2019-11-25 17:40:18 -08:00
command = Cmd_Argv(1);
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
if(q_strcasecmp(command, "on") == 0)
2019-11-24 20:45:15 -08:00
{
enabled = true;
return;
}
2019-11-25 17:40:18 -08:00
if(q_strcasecmp(command, "off") == 0)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
if(playing)
2019-11-24 20:45:15 -08:00
CDAudio_Stop();
enabled = false;
return;
}
2019-11-25 17:40:18 -08:00
if(q_strcasecmp(command, "reset") == 0)
2019-11-24 20:45:15 -08:00
{
enabled = true;
2019-11-25 17:40:18 -08:00
if(playing)
2019-11-24 20:45:15 -08:00
CDAudio_Stop();
2019-11-25 17:40:18 -08:00
for(n = 0; n < 100; n++)
2019-11-24 20:45:15 -08:00
remap[n] = n;
CDAudio_GetAudioDiskInfo();
return;
}
2019-11-25 17:40:18 -08:00
if(q_strcasecmp(command, "remap") == 0)
2019-11-24 20:45:15 -08:00
{
ret = Cmd_Argc() - 2;
2019-11-25 17:40:18 -08:00
if(ret <= 0)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
for(n = 1; n < 100; n++)
if(remap[n] != n)
2019-11-25 17:29:41 -08:00
Con_Printf(" %" PRIu32 " -> %" PRIu32 "\n", n, remap[n]);
2019-11-24 20:45:15 -08:00
return;
}
2019-11-25 17:40:18 -08:00
for(n = 1; n <= ret; n++)
remap[n] = atoi(Cmd_Argv(n + 1));
2019-11-24 20:45:15 -08:00
return;
}
2019-11-25 17:40:18 -08:00
if(!cdValid)
2019-11-24 20:45:15 -08:00
{
CDAudio_GetAudioDiskInfo();
2019-11-25 17:40:18 -08:00
if(!cdValid)
2019-11-24 20:45:15 -08:00
{
Con_Printf("No CD in player.\n");
return;
}
}
2019-11-25 17:40:18 -08:00
if(q_strcasecmp(command, "play") == 0)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
n = atoi(Cmd_Argv(2));
if(n == 0)
2019-11-24 20:45:15 -08:00
n = 1;
CDAudio_Play((byte)n, false);
return;
}
2019-11-25 17:40:18 -08:00
if(q_strcasecmp(command, "loop") == 0)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
CDAudio_Play((byte)atoi(Cmd_Argv(2)), true);
2019-11-24 20:45:15 -08:00
return;
}
2019-11-25 17:40:18 -08:00
if(q_strcasecmp(command, "stop") == 0)
2019-11-24 20:45:15 -08:00
{
CDAudio_Stop();
return;
}
2019-11-25 17:40:18 -08:00
if(q_strcasecmp(command, "pause") == 0)
2019-11-24 20:45:15 -08:00
{
CDAudio_Pause();
return;
}
2019-11-25 17:40:18 -08:00
if(q_strcasecmp(command, "resume") == 0)
2019-11-24 20:45:15 -08:00
{
CDAudio_Resume();
return;
}
2019-11-25 17:40:18 -08:00
if(q_strcasecmp(command, "eject") == 0)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
if(playing)
2019-11-24 20:45:15 -08:00
CDAudio_Stop();
CDAudio_Eject();
cdValid = false;
return;
}
2019-11-25 17:40:18 -08:00
if(q_strcasecmp(command, "info") == 0)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
int32_t current_min, current_sec, current_frame;
int32_t length_min, length_sec, length_frame;
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
Con_Printf("%" PRIu32 " tracks\n", cd_handle->numtracks);
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
if(playing)
2019-11-25 17:29:41 -08:00
Con_Printf("Currently %s track %" PRIu32 "\n", playLooping ? "looping" : "playing", playTrack);
2019-11-25 17:40:18 -08:00
else if(wasPlaying)
2019-11-25 17:29:41 -08:00
Con_Printf("Paused %s track %" PRIu32 "\n", playLooping ? "looping" : "playing", playTrack);
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
if(playing || wasPlaying)
2019-11-24 20:45:15 -08:00
{
SDL_CDStatus(cd_handle);
FRAMES_TO_MSF(cd_handle->cur_frame, &current_min, &current_sec, &current_frame);
2019-11-25 17:40:18 -08:00
FRAMES_TO_MSF(cd_handle->track[playTrack - 1].length, &length_min, &length_sec, &length_frame);
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
Con_Printf("Current position: %" PRIi32 ":%02" PRIi32 ".%02" PRIi32 " (of %" PRIi32 ":%02" PRIi32 ".%02" PRIi32 ")\n",
current_min, current_sec, current_frame * 60 / CD_FPS,
length_min, length_sec, length_frame * 60 / CD_FPS);
2019-11-24 20:45:15 -08:00
}
Con_Printf("Volume is %f\n", bgmvolume.value);
return;
}
2019-11-25 17:40:18 -08:00
if(q_strcasecmp(command, "next") == 0)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
if(playTrack == cd_handle->numtracks)
2019-11-24 20:45:15 -08:00
playTrack = get_first_audiotrk() - 1;
CDAudio_Play(playTrack + 1, playLooping);
return;
}
2019-11-25 17:40:18 -08:00
if(q_strcasecmp(command, "prev") == 0)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
if(playTrack == get_first_audiotrk())
2019-11-24 20:45:15 -08:00
playTrack = cd_handle->numtracks + 1;
CDAudio_Play(playTrack - 1, playLooping);
return;
}
2019-11-25 17:40:18 -08:00
Con_Printf("cd: unknown command \"%s\"\n", command);
2019-11-24 20:45:15 -08:00
}
2019-11-25 17:40:18 -08:00
static bool CD_GetVolume(void *unused)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
/* FIXME: write proper code in here when SDL
supports cdrom volume control some day. */
2019-11-24 20:45:15 -08:00
return false;
}
2019-11-25 17:40:18 -08:00
static bool CD_SetVolume(void *unused)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
/* FIXME: write proper code in here when SDL
supports cdrom volume control some day. */
2019-11-24 20:45:15 -08:00
return false;
}
2019-11-25 17:40:18 -08:00
static bool CDAudio_SetVolume(float value)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
if(!cd_handle || !enabled)
2019-11-24 20:45:15 -08:00
return false;
old_cdvolume = value;
2019-11-25 17:40:18 -08:00
if(value == 0.0f)
CDAudio_Pause();
2019-11-24 20:45:15 -08:00
else
CDAudio_Resume();
2019-11-25 17:40:18 -08:00
if(!hw_vol_works)
2019-11-24 20:45:15 -08:00
{
return false;
}
else
{
2019-11-25 17:40:18 -08:00
/* FIXME: write proper code in here when SDL
supports cdrom volume control some day. */
return CD_SetVolume(NULL);
2019-11-24 20:45:15 -08:00
}
}
void CDAudio_Update(void)
{
2019-11-25 17:40:18 -08:00
CDstatus curstat;
/* static double lastchk;*/
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
if(!cd_handle || !enabled)
2019-11-24 20:45:15 -08:00
return;
2019-11-25 17:40:18 -08:00
if(old_cdvolume != bgmvolume.value)
CDAudio_SetVolume(bgmvolume.value);
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
/* if (playing && realtime > lastchk)*/
if(playing && realtime > endOfTrack)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
/* lastchk = realtime + 2;*/ /* two seconds between chks */
2019-11-24 20:45:15 -08:00
curstat = SDL_CDStatus(cd_handle);
2019-11-25 17:40:18 -08:00
if(curstat != CD_PLAYING && curstat != CD_PAUSED)
2019-11-24 20:45:15 -08:00
{
playing = false;
endOfTrack = -1.0;
2019-11-25 17:40:18 -08:00
if(playLooping)
2019-11-24 20:45:15 -08:00
CDAudio_Play(playTrack, true);
}
}
}
2019-11-25 17:40:18 -08:00
static const char *get_cddev_arg(const char *arg)
2019-11-24 20:45:15 -08:00
{
2019-12-02 04:24:20 -08:00
#if PLATFORM_IS(WINDOWS)
2019-11-25 17:40:18 -08:00
/* arg should be like "D:\", make sure it is so,
* but tolerate args like "D" or "D:", as well. */
2019-11-24 20:45:15 -08:00
static char drive[4];
2019-11-25 17:40:18 -08:00
if(!arg || ! *arg)
2019-11-24 20:45:15 -08:00
return NULL;
2019-11-25 17:40:18 -08:00
if(arg[1] != '\0')
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
if(arg[1] != ':')
2019-11-24 20:45:15 -08:00
return NULL;
2019-11-25 17:40:18 -08:00
if(arg[2] != '\0')
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
if(arg[2] != '\\' &&
arg[2] != '/')
2019-11-24 20:45:15 -08:00
return NULL;
2019-11-25 17:40:18 -08:00
if(arg[3] != '\0')
2019-11-24 20:45:15 -08:00
return NULL;
}
}
2019-11-25 17:40:18 -08:00
if(*arg >= 'A' && *arg <= 'Z')
2019-11-24 20:45:15 -08:00
{
drive[0] = *arg;
drive[1] = ':';
drive[2] = '\\';
drive[3] = '\0';
return drive;
}
2019-11-25 17:40:18 -08:00
else if(*arg >= 'a' && *arg <= 'z')
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
/* make it uppercase for SDL */
2019-11-24 20:45:15 -08:00
drive[0] = *arg - ('a' - 'A');
drive[1] = ':';
drive[2] = '\\';
drive[3] = '\0';
return drive;
}
return NULL;
#else
2019-11-25 17:40:18 -08:00
if(!arg || ! *arg)
2019-11-24 20:45:15 -08:00
return NULL;
return arg;
#endif
}
2019-11-25 17:40:18 -08:00
static void export_cddev_arg(void)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
/* Bad ugly hack to workaround SDL's cdrom device detection.
* not needed for windows due to the way SDL_cdrom works. */
2019-12-02 04:24:20 -08:00
#if !PLATFORM_IS(WINDOWS)
2019-11-25 16:49:58 -08:00
int32_t i = COM_CheckParm("-cddev");
2019-11-25 17:40:18 -08:00
if(i != 0 && i < com_argc - 1 && com_argv[i + 1][0] != '\0')
2019-11-24 20:45:15 -08:00
{
static char arg[64];
2019-11-25 17:40:18 -08:00
q_snprintf(arg, sizeof(arg), "SDL_CDROM=%s", com_argv[i + 1]);
2019-11-24 20:45:15 -08:00
putenv(arg);
}
#endif
}
2019-11-25 16:49:58 -08:00
int32_t CDAudio_Init(void)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
int32_t i, sdl_num_drives;
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
if(safemode || COM_CheckParm("-nocdaudio"))
2019-11-24 20:45:15 -08:00
return -1;
export_cddev_arg();
2019-11-25 17:40:18 -08:00
if(SDL_InitSubSystem(SDL_INIT_CDROM) < 0)
2019-11-24 20:45:15 -08:00
{
Con_Printf("Couldn't init SDL cdrom: %s\n", SDL_GetError());
return -1;
}
2019-11-25 17:40:18 -08:00
sdl_num_drives = SDL_CDNumDrives();
2019-12-02 07:01:47 -08:00
Con_Printf("SDL detected %" PRIi32 " CD-ROM drive(s)\n", sdl_num_drives);
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
if(sdl_num_drives < 1)
2019-11-24 20:45:15 -08:00
return -1;
2019-11-25 17:40:18 -08:00
if((i = COM_CheckParm("-cddev")) != 0 && i < com_argc - 1)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
const char *userdev = get_cddev_arg(com_argv[i + 1]);
if(!userdev)
2019-11-24 20:45:15 -08:00
{
Con_Printf("Invalid argument to -cddev\n");
return -1;
}
2019-11-25 17:40:18 -08:00
for(i = 0; i < sdl_num_drives; i++)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
if(!q_strcasecmp(SDL_CDName(i), userdev))
2019-11-24 20:45:15 -08:00
{
cd_dev = i;
break;
}
}
2019-11-25 17:40:18 -08:00
if(cd_dev == -1)
2019-11-24 20:45:15 -08:00
{
Con_Printf("SDL couldn't find cdrom device %s\n", userdev);
return -1;
}
}
2019-11-25 17:40:18 -08:00
if(cd_dev == -1)
cd_dev = 0; /* default drive */
2019-11-24 20:45:15 -08:00
cd_handle = SDL_CDOpen(cd_dev);
2019-11-25 17:40:18 -08:00
if(!cd_handle)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
Con_Printf("CDAudio_Init: Unable to open CD-ROM drive %s (%s)\n",
SDL_CDName(cd_dev), SDL_GetError());
2019-11-24 20:45:15 -08:00
return -1;
}
2019-11-25 17:40:18 -08:00
for(i = 0; i < 100; i++)
2019-11-24 20:45:15 -08:00
remap[i] = i;
enabled = true;
old_cdvolume = bgmvolume.value;
Con_Printf("CDAudio initialized (SDL, using %s)\n", SDL_CDName(cd_dev));
2019-11-25 17:40:18 -08:00
if(CDAudio_GetAudioDiskInfo())
2019-11-24 20:45:15 -08:00
{
Con_Printf("CDAudio_Init: No CD in drive\n");
cdValid = false;
}
2019-11-25 17:40:18 -08:00
Cmd_AddCommand("cd", CD_f);
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
hw_vol_works = CD_GetVolume(NULL); /* no SDL support at present. */
if(hw_vol_works)
hw_vol_works = CDAudio_SetVolume(bgmvolume.value);
2019-11-24 20:45:15 -08:00
return 0;
}
void CDAudio_Shutdown(void)
{
2019-11-25 17:40:18 -08:00
if(!cd_handle)
2019-11-24 20:45:15 -08:00
return;
CDAudio_Stop();
2019-11-25 17:40:18 -08:00
if(hw_vol_works)
CD_SetVolume(NULL); /* no SDL support at present. */
2019-12-02 04:24:20 -08:00
#if PLATFORM_IS(LINUX)
2019-11-25 17:40:18 -08:00
SDL_CDStop(cd_handle); /* see CDAudio_Stop() */
2019-11-24 20:45:15 -08:00
#endif
SDL_CDClose(cd_handle);
cd_handle = NULL;
cd_dev = -1;
SDL_QuitSubSystem(SDL_INIT_CDROM);
}
2019-11-24 22:41:23 -08:00
#endif /* defined(SDL_INIT_CDROM) */
2019-11-24 20:45:15 -08:00