From 35f84fe46489e117fab33d2598921cd34ef0c759 Mon Sep 17 00:00:00 2001 From: molivier Date: Thu, 15 Apr 2004 14:24:03 +0000 Subject: [PATCH] Fine-grained CD volume support for Linux. Note that it uses the CD player internal volume, not the system audio mixer. The BSD version should follow very soon; if someone knows how to do that on Win32, I would be glad to hear from him. git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@4108 d7cf8633-e32d-0410-b094-e92efae38249 --- cd_bsd.c | 13 +++++++++++++ cd_linux.c | 30 ++++++++++++++++++++++++++++++ cd_null.c | 11 +++++++++++ cd_shared.c | 16 ++++++++++++---- cd_win.c | 13 +++++++++++++ 5 files changed, 79 insertions(+), 4 deletions(-) diff --git a/cd_bsd.c b/cd_bsd.c index 41de20a1..6c8f9a81 100644 --- a/cd_bsd.c +++ b/cd_bsd.c @@ -81,6 +81,19 @@ int CDAudio_SysGetAudioDiskInfo (void) } +float CDAudio_SysGetVolume (void) +{ + // IMPLEMENTME + return -1.0f; +} + + +void CDAudio_SysSetVolume (float volume) +{ + // IMPLEMENTME +} + + int CDAudio_SysPlay (qbyte track) { struct ioc_read_toc_entry rte; diff --git a/cd_linux.c b/cd_linux.c index feaa5b3a..7877e83f 100644 --- a/cd_linux.c +++ b/cd_linux.c @@ -77,6 +77,36 @@ int CDAudio_SysGetAudioDiskInfo (void) } +float CDAudio_SysGetVolume (void) +{ + struct cdrom_volctrl vol; + + if (cdfile == -1) + return -1.0f; + + if (ioctl (cdfile, CDROMVOLREAD, &vol) == -1) + { + Con_DPrint("ioctl CDROMVOLREAD failed\n"); + return -1.0f; + } + + return (vol.channel0 + vol.channel1) / 2.0f / 255.0f; +} + + +void CDAudio_SysSetVolume (float volume) +{ + struct cdrom_volctrl vol; + + if (cdfile == -1) + return; + + vol.channel0 = vol.channel1 = volume * 255; + if (ioctl (cdfile, CDROMVOLCTRL, &vol) == -1) + Con_DPrint("ioctl CDROMVOLCTRL failed\n"); +} + + int CDAudio_SysPlay (qbyte track) { struct cdrom_tocentry entry; diff --git a/cd_null.c b/cd_null.c index 7bfe2f3e..300334a2 100644 --- a/cd_null.c +++ b/cd_null.c @@ -37,6 +37,17 @@ int CDAudio_SysGetAudioDiskInfo (void) } +float CDAudio_SysGetVolume (void) +{ + return -1.0f; +} + + +void CDAudio_SysSetVolume (float volume) +{ +} + + int CDAudio_SysPlay (qbyte track) { return -1; diff --git a/cd_shared.c b/cd_shared.c index 6f152570..d1106c37 100644 --- a/cd_shared.c +++ b/cd_shared.c @@ -26,6 +26,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. extern void CDAudio_SysEject (void); extern void CDAudio_SysCloseDoor (void); extern int CDAudio_SysGetAudioDiskInfo (void); +extern float CDAudio_SysGetVolume (void); +extern void CDAudio_SysSetVolume (float volume); extern int CDAudio_SysPlay (qbyte track); extern int CDAudio_SysStop (void); extern int CDAudio_SysPause (void); @@ -46,6 +48,8 @@ static qbyte remap[100]; static qbyte maxTrack; static int faketrack = -1; +static float saved_vol = 1.0f; + // exported variables qboolean cdValid = false; qboolean cdPlaying = false; @@ -323,10 +327,7 @@ void CDAudio_SetVolume (float newvol) if (faketrack != -1) S_SetChannelVolume (faketrack, newvol); - else - { - // TODO: add support for the "real CD" mixer - } + CDAudio_SysSetVolume (newvol); } cdvolume = newvol; @@ -377,6 +378,10 @@ int CDAudio_Startup (void) cdValid = false; } + saved_vol = CDAudio_SysGetVolume (); + if (saved_vol < 0.0f) + saved_vol = 1.0f; + initialized = true; Con_DPrint("CD Audio Initialized\n"); @@ -388,6 +393,9 @@ void CDAudio_Shutdown (void) { if (!initialized) return; + + CDAudio_SysSetVolume (saved_vol); + CDAudio_Stop(); CDAudio_SysShutdown(); initialized = false; diff --git a/cd_win.c b/cd_win.c index dee8ef63..b7c49173 100644 --- a/cd_win.c +++ b/cd_win.c @@ -81,6 +81,19 @@ int CDAudio_SysGetAudioDiskInfo(void) } +float CDAudio_SysGetVolume (void) +{ + // IMPLEMENTME + return -1.0f; +} + + +void CDAudio_SysSetVolume (float volume) +{ + // IMPLEMENTME +} + + int CDAudio_SysPlay (qbyte track) { DWORD dwReturn; -- 2.39.2