From: molivier Date: Mon, 15 Dec 2003 07:48:43 +0000 (+0000) Subject: Audio CD support for NetBSD; it also compiles on OpenBSD, but I can't test it for... X-Git-Tag: xonotic-v0.1.0preview~6210 X-Git-Url: https://git.xonotic.org/?a=commitdiff_plain;h=4373c092bf0fd4af24faa72d3fd83b7adc8a408e;p=xonotic%2Fdarkplaces.git Audio CD support for NetBSD; it also compiles on OpenBSD, but I can't test it for now. Plus some diff noise reduction and a minor bug fix in cd_linux.c (the case when the user changes track without using the "cd" command should now be handled correctly) git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@3725 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/cd_bsd.c b/cd_bsd.c new file mode 100644 index 00000000..14bb3172 --- /dev/null +++ b/cd_bsd.c @@ -0,0 +1,234 @@ +/* +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 the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ +// Quake is a trademark of Id Software, Inc., (c) 1996 Id Software, Inc. All +// rights reserved. + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "quakedef.h" + + +static int cdfile = -1; +static char cd_dev[64] = _PATH_DEV "cd0"; + + +void CDAudio_SysEject (void) +{ + if (cdfile == -1) + return; + + ioctl(cdfile, CDIOCALLOW); + if (ioctl(cdfile, CDIOCEJECT) == -1) + Con_DPrintf("ioctl CDIOCEJECT failed\n"); +} + + +void CDAudio_SysCloseDoor (void) +{ + if (cdfile == -1) + return; + + ioctl(cdfile, CDIOCALLOW); + if (ioctl(cdfile, CDIOCCLOSE) == -1) + Con_DPrintf("ioctl CDIOCCLOSE failed\n"); +} + +int CDAudio_SysGetAudioDiskInfo (void) +{ + struct ioc_toc_header tochdr; + + if (ioctl(cdfile, CDIOREADTOCHEADER, &tochdr) == -1) + { + Con_DPrintf("ioctl CDIOREADTOCHEADER failed\n"); + return -1; + } + + if (tochdr.starting_track < 1) + { + Con_DPrintf("CDAudio: no music tracks\n"); + return -1; + } + + return tochdr.ending_track; +} + + +int CDAudio_SysPlay (qbyte track) +{ + struct ioc_read_toc_entry rte; + struct cd_toc_entry entry; + struct ioc_play_track ti; + + if (cdfile == -1) + return -1; + + // don't try to play a non-audio track + rte.address_format = CD_MSF_FORMAT; + rte.starting_track = track; + rte.data_len = sizeof(entry); + rte.data = &entry; + if (ioctl(cdfile, CDIOREADTOCENTRYS, &rte) == -1) + { + Con_DPrintf("ioctl CDIOREADTOCENTRYS failed\n"); + return -1; + } + if (entry.control & 4) // if it's a data track + { + Con_Printf("CDAudio: track %i is not audio\n", track); + return -1; + } + + if (cdPlaying) + CDAudio_Stop(); + + ti.start_track = track; + ti.end_track = track; + ti.start_index = 1; + ti.end_index = 99; + + if (ioctl(cdfile, CDIOCPLAYTRACKS, &ti) == -1) + { + Con_DPrintf("ioctl CDIOCPLAYTRACKS failed\n"); + return -1; + } + + if (ioctl(cdfile, CDIOCRESUME) == -1) + { + Con_DPrintf("ioctl CDIOCRESUME failed\n"); + return -1; + } + + return 0; +} + + +int CDAudio_SysStop (void) +{ + if (cdfile == -1) + return -1; + + if (ioctl(cdfile, CDIOCSTOP) == -1) + { + Con_DPrintf("ioctl CDIOCSTOP failed (%d)\n", errno); + return -1; + } + ioctl(cdfile, CDIOCALLOW); + + return 0; +} + +int CDAudio_SysPause (void) +{ + if (cdfile == -1) + return -1; + + if (ioctl(cdfile, CDIOCPAUSE) == -1) + { + Con_DPrintf("ioctl CDIOCPAUSE failed\n"); + return -1; + } + + return 0; +} + + +int CDAudio_SysResume (void) +{ + if (cdfile == -1) + return -1; + + if (ioctl(cdfile, CDIOCRESUME) == -1) + Con_DPrintf("ioctl CDIOCRESUME failed\n"); + + return 0; +} + +int CDAudio_SysUpdate (void) +{ + static time_t lastchk = 0; + struct ioc_read_subchannel subchnl; + struct cd_sub_channel_info data; + + if (cdPlaying && lastchk < time(NULL)) + { + lastchk = time(NULL) + 2; //two seconds between chks + + bzero(&subchnl, sizeof(subchnl)); + subchnl.data = &data; + subchnl.data_len = sizeof(data); + subchnl.address_format = CD_MSF_FORMAT; + subchnl.data_format = CD_CURRENT_POSITION; + + if (ioctl(cdfile, CDIOCREADSUBCHANNEL, &subchnl) == -1) + { + Con_DPrintf("ioctl CDIOCREADSUBCHANNEL failed\n"); + cdPlaying = false; + return -1; + } + if (data.header.audio_status != CD_AS_PLAY_IN_PROGRESS && + data.header.audio_status != CD_AS_PLAY_PAUSED) + { + cdPlaying = false; + if (cdPlayLooping) + CDAudio_Play(cdPlayTrack, true); + } + else + cdPlayTrack = data.what.position.track_number; + } + + return 0; +} + +void CDAudio_SysInit (void) +{ + int i; + + if ((i = COM_CheckParm("-cddev")) != 0 && i < com_argc - 1) + strlcpy(cd_dev, com_argv[i + 1], sizeof(cd_dev)); +} + +int CDAudio_SysStartup (void) +{ + char buff [80]; + + if ((cdfile = opendisk(cd_dev, O_RDONLY, buff, sizeof(buff), 0)) == -1) + { + Con_DPrintf("CDAudio_SysStartup: open of \"%s\" failed (%i)\n", + cd_dev, errno); + cdfile = -1; + return -1; + } + + return 0; +} + +void CDAudio_SysShutdown (void) +{ + close(cdfile); + cdfile = -1; +} diff --git a/cd_linux.c b/cd_linux.c index 29a4bb06..32c0c3f0 100644 --- a/cd_linux.c +++ b/cd_linux.c @@ -34,13 +34,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. static int cdfile = -1; static char cd_dev[64] = "/dev/cdrom"; + void CDAudio_SysEject (void) { if (cdfile == -1) return; if (ioctl(cdfile, CDROMEJECT) == -1) - Con_DPrintf("ioctl cdromeject failed\n"); + Con_DPrintf("ioctl CDROMEJECT failed\n"); } @@ -50,7 +51,7 @@ void CDAudio_SysCloseDoor (void) return; if (ioctl(cdfile, CDROMCLOSETRAY) == -1) - Con_DPrintf("ioctl cdromclosetray failed\n"); + Con_DPrintf("ioctl CDROMCLOSETRAY failed\n"); } int CDAudio_SysGetAudioDiskInfo (void) @@ -59,7 +60,7 @@ int CDAudio_SysGetAudioDiskInfo (void) if (ioctl(cdfile, CDROMREADTOCHDR, &tochdr) == -1) { - Con_DPrintf("ioctl cdromreadtochdr failed\n"); + Con_DPrintf("ioctl CDROMREADTOCHDR failed\n"); return -1; } @@ -86,7 +87,7 @@ int CDAudio_SysPlay (qbyte track) entry.cdte_format = CDROM_MSF; if (ioctl(cdfile, CDROMREADTOCENTRY, &entry) == -1) { - Con_DPrintf("ioctl cdromreadtocentry failed\n"); + Con_DPrintf("ioctl CDROMREADTOCENTRY failed\n"); return -1; } if (entry.cdte_ctrl == CDROM_DATA_TRACK) @@ -105,13 +106,13 @@ int CDAudio_SysPlay (qbyte track) if (ioctl(cdfile, CDROMPLAYTRKIND, &ti) == -1) { - Con_DPrintf("ioctl cdromplaytrkind failed\n"); + Con_DPrintf("ioctl CDROMPLAYTRKIND failed\n"); return -1; } if (ioctl(cdfile, CDROMRESUME) == -1) { - Con_DPrintf("ioctl cdromresume failed\n"); + Con_DPrintf("ioctl CDROMRESUME failed\n"); return -1; } @@ -126,10 +127,10 @@ int CDAudio_SysStop (void) if (ioctl(cdfile, CDROMSTOP) == -1) { - Con_DPrintf("ioctl cdromstop failed (%d)\n", errno); + Con_DPrintf("ioctl CDROMSTOP failed (%d)\n", errno); return -1; } - + return 0; } @@ -140,10 +141,10 @@ int CDAudio_SysPause (void) if (ioctl(cdfile, CDROMPAUSE) == -1) { - Con_DPrintf("ioctl cdrompause failed\n"); + Con_DPrintf("ioctl CDROMPAUSE failed\n"); return -1; } - + return 0; } @@ -154,7 +155,7 @@ int CDAudio_SysResume (void) return -1; if (ioctl(cdfile, CDROMRESUME) == -1) - Con_DPrintf("ioctl cdromresume failed\n"); + Con_DPrintf("ioctl CDROMRESUME failed\n"); return 0; } @@ -164,22 +165,27 @@ int CDAudio_SysUpdate (void) struct cdrom_subchnl subchnl; static time_t lastchk = 0; - if (cdPlaying && lastchk < time(NULL)) { + if (cdPlaying && lastchk < time(NULL)) + { lastchk = time(NULL) + 2; //two seconds between chks subchnl.cdsc_format = CDROM_MSF; - if (ioctl(cdfile, CDROMSUBCHNL, &subchnl) == -1 ) { - Con_DPrintf("ioctl cdromsubchnl failed\n"); + if (ioctl(cdfile, CDROMSUBCHNL, &subchnl) == -1) + { + Con_DPrintf("ioctl CDROMSUBCHNL failed\n"); cdPlaying = false; return -1; } if (subchnl.cdsc_audiostatus != CDROM_AUDIO_PLAY && - subchnl.cdsc_audiostatus != CDROM_AUDIO_PAUSED) { + subchnl.cdsc_audiostatus != CDROM_AUDIO_PAUSED) + { cdPlaying = false; if (cdPlayLooping) CDAudio_Play(cdPlayTrack, true); } + else + cdPlayTrack = subchnl.cdsc_trk; } - + return 0; } @@ -188,14 +194,15 @@ void CDAudio_SysInit (void) int i; if ((i = COM_CheckParm("-cddev")) != 0 && i < com_argc - 1) - strlcpy (cd_dev, com_argv[i + 1], sizeof (cd_dev)); + strlcpy(cd_dev, com_argv[i + 1], sizeof(cd_dev)); } int CDAudio_SysStartup (void) { if ((cdfile = open(cd_dev, O_RDONLY)) == -1) { - Con_DPrintf("CDAudio_SysStartup: open of \"%s\" failed (%i)\n", cd_dev, errno); + Con_DPrintf("CDAudio_SysStartup: open of \"%s\" failed (%i)\n", + cd_dev, errno); cdfile = -1; return -1; } diff --git a/makefile.bsd b/makefile.bsd index 95bf677a..faa17cb5 100644 --- a/makefile.bsd +++ b/makefile.bsd @@ -5,15 +5,13 @@ CC=gcc MAKE:=$(MAKE) -f makefile.bsd -#recommended for: anyone not using ALSA 0.5 -#OBJ_BSDSOUND=snd_oss.o snd_dma.o snd_mix.o snd_mem.o OBJ_BSDSOUND=snd_null.o BSDSOUNDLIB= -#if you want CD sound in Linux -#OBJ_BSDCD=cd_bsd.o +#if you want CD sound in BSD +OBJ_BSDCD=cd_shared.o cd_bsd.o #if you want no CD audio -OBJ_BSDCD=cd_null.o +#OBJ_BSDCD=cd_null.o #K6/athlon optimizations #CPUOPTIMIZATIONS=-march=k6 @@ -72,7 +70,7 @@ DO_CC=$(CC) $(CFLAGS) -c $< -o $@ # Link # LordHavoc note: I have been informed that system libraries must come last # on the linker line, and that -lm must always be last -LDFLAGS_GLX=-lm +LDFLAGS_GLX=-lm -lutil LDFLAGS_DED=-lm LDFLAGS_DEBUG=-g -ggdb LDFLAGS_PROFILE=-g -pg