2001-02-19 21:15:25 +00:00
|
|
|
/*
|
|
|
|
cd_sdl.c
|
|
|
|
|
|
|
|
SDL CD audio routines
|
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
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:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
2001-09-28 06:26:31 +00:00
|
|
|
static const char rcsid[] =
|
|
|
|
"$Id$";
|
2001-05-20 20:52:27 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_WINDOWS_H
|
|
|
|
# include <windows.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <SDL.h>
|
|
|
|
|
2001-04-09 21:15:09 +00:00
|
|
|
#include "QF/cdaudio.h"
|
2001-03-27 23:36:02 +00:00
|
|
|
#include "QF/cmd.h"
|
2001-06-01 22:55:33 +00:00
|
|
|
#include "QF/cvar.h"
|
|
|
|
#include "QF/plugin.h"
|
2001-03-27 23:36:02 +00:00
|
|
|
#include "QF/qargs.h"
|
2001-04-09 21:15:09 +00:00
|
|
|
#include "QF/sound.h"
|
2001-09-21 04:22:46 +00:00
|
|
|
#include "QF/sys.h"
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-06-01 22:55:33 +00:00
|
|
|
#include "compat.h"
|
|
|
|
|
2001-08-31 00:16:31 +00:00
|
|
|
static plugin_t plugin_info;
|
|
|
|
static plugin_data_t plugin_info_data;
|
|
|
|
static plugin_funcs_t plugin_info_funcs;
|
|
|
|
static general_data_t plugin_info_general_data;
|
|
|
|
static general_funcs_t plugin_info_general_funcs;
|
|
|
|
//static cd_data_t plugin_info_cd_data;
|
|
|
|
static cd_funcs_t plugin_info_cd_funcs;
|
2001-06-01 22:55:33 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
static qboolean cdValid = false;
|
|
|
|
static qboolean initialized = false;
|
|
|
|
static qboolean enabled = true;
|
|
|
|
static qboolean playLooping = false;
|
|
|
|
|
2001-05-20 20:52:27 +00:00
|
|
|
static SDL_CD *cd_id;
|
2001-02-19 21:15:25 +00:00
|
|
|
static float cdvolume = 1.0;
|
|
|
|
|
2001-05-20 20:52:27 +00:00
|
|
|
|
2001-08-31 00:05:58 +00:00
|
|
|
static void
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_Eject (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
if (!cd_id || !enabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (SDL_CDEject (cd_id))
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_DPrintf ("Unable to eject CD-ROM tray.\n");
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-08-31 00:05:58 +00:00
|
|
|
static void
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_Pause (void)
|
|
|
|
{
|
|
|
|
if (!cd_id || !enabled)
|
|
|
|
return;
|
|
|
|
if (SDL_CDStatus (cd_id) != CD_PLAYING)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (SDL_CDPause (cd_id))
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_DPrintf ("CDAudio_Pause: Failed to pause track.\n");
|
2001-06-01 22:55:33 +00:00
|
|
|
}
|
|
|
|
|
2001-08-31 00:05:58 +00:00
|
|
|
static void
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_Stop (void)
|
|
|
|
{
|
|
|
|
int cdstate;
|
|
|
|
|
|
|
|
if (!cd_id || !enabled)
|
|
|
|
return;
|
|
|
|
cdstate = SDL_CDStatus (cd_id);
|
|
|
|
if ((cdstate != CD_PLAYING) && (cdstate != CD_PAUSED))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (SDL_CDStop (cd_id))
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_DPrintf ("CDAudio_Stop: Failed to stop track.\n");
|
2001-06-01 22:55:33 +00:00
|
|
|
}
|
|
|
|
|
2001-08-31 00:05:58 +00:00
|
|
|
static void
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_Play (byte track, qboolean looping)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
/* Initialize cd_stat to avoid warning */
|
|
|
|
/* XXX - Does this default value make sense? */
|
|
|
|
CDstatus cd_stat = CD_ERROR;
|
|
|
|
|
|
|
|
if (!cd_id || !enabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!cdValid) {
|
2001-08-27 01:00:03 +00:00
|
|
|
if (!CD_INDRIVE (cd_stat = SDL_CDStatus (cd_id)) ||
|
|
|
|
(!cd_id->numtracks))
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
cdValid = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((track < 1) || (track >= cd_id->numtracks)) {
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_Stop ();
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-06-01 22:55:33 +00:00
|
|
|
track--; // Convert track from person to SDL value
|
2001-02-19 21:15:25 +00:00
|
|
|
if (cd_stat == CD_PLAYING) {
|
|
|
|
if (cd_id->cur_track == track)
|
|
|
|
return;
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_Stop ();
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (SDL_CDPlay (cd_id, cd_id->track[track].offset,
|
|
|
|
cd_id->track[track].length)) {
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_DPrintf ("CDAudio_Play: Unable to play track: %d\n", track + 1);
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
playLooping = looping;
|
|
|
|
}
|
|
|
|
|
2001-08-31 00:05:58 +00:00
|
|
|
static void
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_Resume (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
if (!cd_id || !enabled)
|
|
|
|
return;
|
2001-06-01 22:55:33 +00:00
|
|
|
if (SDL_CDStatus (cd_id) != CD_PAUSED)
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
|
2001-06-01 22:55:33 +00:00
|
|
|
if (SDL_CDResume (cd_id))
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_DPrintf ("CDAudio_Resume: Failed tp resume track.\n");
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-08-31 00:05:58 +00:00
|
|
|
static void
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_Shutdown (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-06-01 22:55:33 +00:00
|
|
|
if (!cd_id)
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_Stop ();
|
|
|
|
SDL_CDClose (cd_id);
|
|
|
|
cd_id = NULL;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-08-31 00:05:58 +00:00
|
|
|
static void
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_Update (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
if (!cd_id || !enabled)
|
|
|
|
return;
|
|
|
|
if (bgmvolume->value != cdvolume) {
|
|
|
|
if (cdvolume) {
|
|
|
|
Cvar_SetValue (bgmvolume, 0.0);
|
|
|
|
CDAudio_Pause ();
|
|
|
|
} else {
|
|
|
|
Cvar_SetValue (bgmvolume, 1.0);
|
|
|
|
CDAudio_Resume ();
|
|
|
|
}
|
|
|
|
cdvolume = bgmvolume->value;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (playLooping && (SDL_CDStatus (cd_id) != CD_PLAYING)
|
|
|
|
&& (SDL_CDStatus (cd_id) != CD_PAUSED))
|
|
|
|
CDAudio_Play (cd_id->cur_track + 1, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CD_f_DEFINED
|
2001-05-20 20:52:27 +00:00
|
|
|
|
2001-08-31 00:05:58 +00:00
|
|
|
static void
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CD_f (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-07-15 07:04:17 +00:00
|
|
|
const char *command;
|
2001-05-20 20:52:27 +00:00
|
|
|
int cdstate;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (Cmd_Argc () < 2)
|
|
|
|
return;
|
|
|
|
|
|
|
|
command = Cmd_Argv (1);
|
2001-04-10 07:26:22 +00:00
|
|
|
if (strequal (command, "on")) {
|
2001-02-19 21:15:25 +00:00
|
|
|
enabled = true;
|
|
|
|
}
|
2001-04-10 07:26:22 +00:00
|
|
|
if (strequal (command, "off")) {
|
2001-02-19 21:15:25 +00:00
|
|
|
if (!cd_id)
|
|
|
|
return;
|
|
|
|
cdstate = SDL_CDStatus (cd_id);
|
|
|
|
if ((cdstate == CD_PLAYING) || (cdstate == CD_PAUSED))
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_Stop ();
|
2001-02-19 21:15:25 +00:00
|
|
|
enabled = false;
|
|
|
|
return;
|
|
|
|
}
|
2001-04-10 07:26:22 +00:00
|
|
|
if (strequal (command, "play")) {
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_Play (atoi (Cmd_Argv (2)), false);
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-04-10 07:26:22 +00:00
|
|
|
if (strequal (command, "loop")) {
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_Play (atoi (Cmd_Argv (2)), true);
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-04-10 07:26:22 +00:00
|
|
|
if (strequal (command, "stop")) {
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_Stop ();
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-04-10 07:26:22 +00:00
|
|
|
if (strequal (command, "pause")) {
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_Pause ();
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-04-10 07:26:22 +00:00
|
|
|
if (strequal (command, "resume")) {
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_Resume ();
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-04-10 07:26:22 +00:00
|
|
|
if (strequal (command, "eject")) {
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_Eject ();
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-04-10 07:26:22 +00:00
|
|
|
if (strequal (command, "info")) {
|
2001-02-19 21:15:25 +00:00
|
|
|
if (!cd_id)
|
|
|
|
return;
|
|
|
|
cdstate = SDL_CDStatus (cd_id);
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("%d tracks\n", cd_id->numtracks);
|
2001-02-19 21:15:25 +00:00
|
|
|
if (cdstate == CD_PLAYING)
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("Currently %s track %d\n",
|
2001-02-19 21:15:25 +00:00
|
|
|
playLooping ? "looping" : "playing",
|
|
|
|
cd_id->cur_track + 1);
|
|
|
|
else if (cdstate == CD_PAUSED)
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("Paused %s track %d\n",
|
2001-02-19 21:15:25 +00:00
|
|
|
playLooping ? "looping" : "playing",
|
|
|
|
cd_id->cur_track + 1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2001-06-01 22:55:33 +00:00
|
|
|
|
2001-08-31 00:05:58 +00:00
|
|
|
static void
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_Init (void)
|
|
|
|
{
|
|
|
|
if (SDL_Init (SDL_INIT_CDROM) < 0) {
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("Couldn't initialize SDL CD-AUDIO: %s\n", SDL_GetError ());
|
2001-06-01 22:55:33 +00:00
|
|
|
return; // was -1
|
|
|
|
}
|
|
|
|
cd_id = SDL_CDOpen (0);
|
|
|
|
if (!cd_id) {
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("CDAudio_Init: Unable to open default CD-ROM drive: %s\n",
|
2001-06-01 22:55:33 +00:00
|
|
|
SDL_GetError ());
|
|
|
|
return; // was -1
|
|
|
|
}
|
|
|
|
|
|
|
|
initialized = true;
|
|
|
|
enabled = true;
|
|
|
|
cdValid = true;
|
|
|
|
|
|
|
|
if (!CD_INDRIVE (SDL_CDStatus (cd_id))) {
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("CDAudio_Init: No CD in drive.\n");
|
2001-06-01 22:55:33 +00:00
|
|
|
cdValid = false;
|
|
|
|
}
|
|
|
|
if (!cd_id->numtracks) {
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("CDAudio_Init: CD contains no audio tracks.\n");
|
2001-06-01 22:55:33 +00:00
|
|
|
cdValid = false;
|
|
|
|
}
|
|
|
|
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("CD Audio Initialized.\n");
|
2001-06-01 22:55:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
plugin_t *
|
2001-08-31 00:05:58 +00:00
|
|
|
cd_sdl_PluginInfo (void)
|
2001-06-01 22:55:33 +00:00
|
|
|
{
|
|
|
|
plugin_info.type = qfp_cd;
|
|
|
|
plugin_info.api_version = QFPLUGIN_VERSION;
|
|
|
|
plugin_info.plugin_version = "0.1";
|
|
|
|
plugin_info.description = "Linux CD Audio output"
|
|
|
|
"Copyright (C) 2001 contributors of the QuakeForge project\n"
|
|
|
|
"Please see the file \"AUTHORS\" for a list of contributors\n";
|
|
|
|
plugin_info.functions = &plugin_info_funcs;
|
|
|
|
plugin_info.data = &plugin_info_data;
|
|
|
|
|
|
|
|
plugin_info_data.general = &plugin_info_general_data;
|
|
|
|
// plugin_info_data.cd = &plugin_info_cd_data;
|
|
|
|
plugin_info_data.input = NULL;
|
|
|
|
|
|
|
|
plugin_info_funcs.general = &plugin_info_general_funcs;
|
|
|
|
plugin_info_funcs.cd = &plugin_info_cd_funcs;
|
|
|
|
plugin_info_funcs.input = NULL;
|
|
|
|
|
|
|
|
plugin_info_general_funcs.p_Init = I_CDAudio_Init;
|
|
|
|
plugin_info_general_funcs.p_Shutdown = I_CDAudio_Shutdown;
|
|
|
|
|
|
|
|
plugin_info_cd_funcs.pCDAudio_Pause = I_CDAudio_Pause;
|
|
|
|
plugin_info_cd_funcs.pCDAudio_Play = I_CDAudio_Play;
|
|
|
|
plugin_info_cd_funcs.pCDAudio_Resume = I_CDAudio_Resume;
|
|
|
|
plugin_info_cd_funcs.pCDAudio_Update = I_CDAudio_Update;
|
|
|
|
plugin_info_cd_funcs.pCD_f = I_CD_f;
|
|
|
|
|
|
|
|
return &plugin_info;
|
|
|
|
}
|