From 6543298e6bc0842e0d5a971cbbe39572423657d2 Mon Sep 17 00:00:00 2001 From: danij Date: Sun, 12 Jan 2014 21:26:38 +0000 Subject: [PATCH] WinMM|Windows: Fixed build (missing header), cleanup --- doomsday/plugins/winmm/include/dswinmm.h | 121 +++++++++------ doomsday/plugins/winmm/src/cdaudio.cpp | 182 ++++++++--------------- 2 files changed, 131 insertions(+), 172 deletions(-) diff --git a/doomsday/plugins/winmm/include/dswinmm.h b/doomsday/plugins/winmm/include/dswinmm.h index 4af68e28e7..ac372b08c5 100644 --- a/doomsday/plugins/winmm/include/dswinmm.h +++ b/doomsday/plugins/winmm/include/dswinmm.h @@ -1,29 +1,21 @@ -/**\file - *\section License - * License: GPL - * Online License Link: http://www.gnu.org/licenses/gpl.html +/** @file dswinmm.h Windows Multimedia audio driver. * - *\author Copyright © 2003-2013 Jaakko Keränen - *\author Copyright © 2007-2009 Daniel Swanson + * @authors Copyright © 2003-2013 Jaakko Keränen + * @authors Copyright © 2007-2013 Daniel Swanson * - * 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. + * @par License + * GPL: http://www.gnu.org/licenses/gpl.html * - * 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 St, Fifth Floor, - * Boston, MA 02110-1301 USA - */ - -/** - * dswinmm.h: Windows Multimedia, Win32 audio driver. + * 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 St, Fifth Floor, Boston, MA + * 02110-1301 USA */ #ifndef __DSWINMM_H__ @@ -62,28 +54,61 @@ enum { MIX_VOLUME // 0-255 }; -int mixer4i(int device, int action, int control, int parm); - -// Public music interface. -int DM_Music_Init(void); -void DM_Music_Shutdown(void); -void DM_Music_Reset(void); -void DM_Music_Update(void); -void DM_Music_Set(int prop, float value); -int DM_Music_Get(int prop, void* ptr); -void DM_Music_Pause(int pause); -void DM_Music_Stop(void); -void* DM_Music_SongBuffer(unsigned int length); -int DM_Music_Play(int looped); - -// CD Audio interface: -int DM_CDAudio_Init(void); -void DM_CDAudio_Shutdown(void); -void DM_CDAudio_Update(void); -void DM_CDAudio_Set(int prop, float value); -int DM_CDAudio_Get(int prop, void* ptr); -void DM_CDAudio_Pause(int pause); -void DM_CDAudio_Stop(void); -int DM_CDAudio_Play(int track, int looped); - -#endif +int mixer4i(int device, int action, int control, int parm); + +/// Public music interface ----------------------------------------------------- + +int DM_Music_Init(); +void DM_Music_Shutdown(); +void DM_Music_Reset(); +void DM_Music_Update(); +void DM_Music_Set(int prop, float value); +int DM_Music_Get(int prop, void *ptr); +void DM_Music_Pause(int pause); +void DM_Music_Stop(); +void *DM_Music_SongBuffer(unsigned int length); +int DM_Music_Play(int looped); + +/// CD Audio interface --------------------------------------------------------- + +/** + * Initialize the CDAudio-interface. + */ +int DM_CDAudio_Init(); + +/** + * Shutdown the CDAudio-interface, we do nothing whilst offline. + */ +void DM_CDAudio_Shutdown(); + +/** + * Do any necessary update tasks. Called every frame by the engine. + */ +void DM_CDAudio_Update(); + +/** + * Assign the value of a CDAudio-interface property. + */ +void DM_CDAudio_Set(int prop, float value); + +/** + * Retrieve the value of a CDAudio-interface property. + */ +int DM_CDAudio_Get(int prop, void *ptr); + +/** + * Pauses playback of the currently playing audio track. + */ +void DM_CDAudio_Pause(int pause); + +/** + * Stops playback of the currently playing audio track. + */ +void DM_CDAudio_Stop(); + +/** + * Begin playback of a specifc audio track, possibly looped. + */ +int DM_CDAudio_Play(int track, int looped); + +#endif // __DSWINMM_H__ diff --git a/doomsday/plugins/winmm/src/cdaudio.cpp b/doomsday/plugins/winmm/src/cdaudio.cpp index 862794e8ef..9a058ee681 100644 --- a/doomsday/plugins/winmm/src/cdaudio.cpp +++ b/doomsday/plugins/winmm/src/cdaudio.cpp @@ -1,58 +1,32 @@ -/**\file cdaudio.cpp - *\section License - * License: GPL - * Online License Link: http://www.gnu.org/licenses/gpl.html +/** @file cdaudio.cpp Compact Disc-Digital Audio (CD-DA) / "Redbook" playback. * - *\author Copyright © 2003-2013 Jaakko Keränen - *\author Copyright © 2006-2013 Daniel Swanson + * Uses the Windows API MCI interface. * - * 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. + * @authors Copyright © 2003-2013 Jaakko Keränen + * @authors Copyright © 2006-2013 Daniel Swanson * - * 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. + * @par License + * GPL: http://www.gnu.org/licenses/gpl.html * - * 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 St, Fifth Floor, - * Boston, MA 02110-1301 USA + * 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 St, Fifth Floor, Boston, MA + * 02110-1301 USA */ -/** - * Compact Disc-Digital Audio (CD-DA) / "Redbook". - * - * Uses the Windows API MCI interface. - */ - -// HEADER FILES ------------------------------------------------------------ - -#include -#include -#include - #include "dswinmm.h" +#include +#include +#include +#include -// MACROS ------------------------------------------------------------------ - -#define DEVICEID "mycd" - -// TYPES ------------------------------------------------------------------- - -// EXTERNAL FUNCTION PROTOTYPES -------------------------------------------- - -// PUBLIC FUNCTION PROTOTYPES ---------------------------------------------- - -// PRIVATE FUNCTION PROTOTYPES --------------------------------------------- - -// EXTERNAL DATA DECLARATIONS ---------------------------------------------- - -// PUBLIC DATA DEFINITIONS ------------------------------------------------- - -// PRIVATE DATA DEFINITIONS ------------------------------------------------ +#define DEVICEID "mycd" static int cdInited = false; @@ -61,29 +35,24 @@ static int cdCurrentTrack = 0; static dd_bool cdLooping; static double cdStartTime, cdPauseTime, cdTrackLength; -// CODE -------------------------------------------------------------------- - /** * Execute an MCI command string. * - * @return @c true, if successful. + * Returns @c true iff successful. */ -static int sendMCICmd(char* returnInfo, int returnLength, - const char *format, ...) +static int sendMCICmd(char *returnInfo, int returnLength, char const *format, ...) { - char buf[300]; - va_list args; - MCIERROR error; + char buf[300]; + va_list args; va_start(args, format); dd_vsnprintf(buf, sizeof(buf), format, args); va_end(args); - if((error = mciSendStringA(buf, returnInfo, returnLength, NULL))) + if(MCIERROR error = mciSendStringA(buf, returnInfo, returnLength, NULL)) { mciGetErrorStringA(error, buf, 300); App_Log(DE2_AUDIO_ERROR, "[WinMM] CD playback error: %s", buf); - return false; } @@ -91,24 +60,24 @@ static int sendMCICmd(char* returnInfo, int returnLength, } /** - * @return Length of the track in seconds. + * @return Length of the track in seconds. */ static int getTrackLength(int track) { - char lenString[80]; - int min, sec; + char lenString[80]; if(!sendMCICmd(lenString, 80, "status " DEVICEID " length track %i", track)) return 0; - sscanf(lenString, "%i:%i", &min, &sec); - return min * 60 + sec; + int minutes, seconds; + sscanf(lenString, "%i:%i", &minutes, &seconds); + return minutes * 60 + seconds; } -static int isPlaying(void) +static int isPlaying() { - char lenString[80]; + char lenString[80]; if(!sendMCICmd(lenString, 80, "status " DEVICEID " mode wait")) return false; @@ -119,39 +88,27 @@ static int isPlaying(void) return false; } -/** - * Assign the value of a CDAudio-interface property. - */ void DM_CDAudio_Set(int prop, float value) { - if(!cdInited) - return; + if(!cdInited) return; switch(prop) { - case MUSIP_VOLUME: - { - int val = MINMAX_OF(0, (byte) (value * 255 + .5f), 255); - + case MUSIP_VOLUME: { // Straighten the volume curve. + int val = MINMAX_OF(0, int(value * 255 + .5f), 255); val <<= 8; // Make it a word. val = (int) (255.9980469 * sqrt(value)); mixer4i(MIX_CDAUDIO, MIX_SET, MIX_VOLUME, val); - break; - } + break; } - default: - break; + default: break; } } -/** - * Retrieve the value of a CDAudio-interface property. - */ -int DM_CDAudio_Get(int prop, void* ptr) +int DM_CDAudio_Get(int prop, void *ptr) { - if(!cdInited) - return false; + if(!cdInited) return false; switch(prop) { @@ -166,20 +123,15 @@ int DM_CDAudio_Get(int prop, void* ptr) case MUSIP_PLAYING: return (cdInited && isPlaying()? true : false); - default: - break; + default: break; } return false; } -/** - * Initialize the CDAudio-interface. - */ -int DM_CDAudio_Init(void) +int DM_CDAudio_Init() { - if(cdInited) - return true; + if(cdInited) return true; if(!sendMCICmd(0, 0, "open cdaudio alias " DEVICEID)) return false; @@ -195,13 +147,9 @@ int DM_CDAudio_Init(void) return cdInited = true; } -/** - * Shutdown the CDAudio-interface, we do nothing whilst offline. - */ -void DM_CDAudio_Shutdown(void) +void DM_CDAudio_Shutdown() { - if(!cdInited) - return; + if(!cdInited) return; DM_CDAudio_Stop(); sendMCICmd(0, 0, "close " DEVICEID); @@ -209,13 +157,9 @@ void DM_CDAudio_Shutdown(void) cdInited = false; } -/** - * Do any necessary update tasks. Called every frame by the engine. - */ -void DM_CDAudio_Update(void) +void DM_CDAudio_Update() { - if(!cdInited) - return; + if(!cdInited) return; // Check for looping. if(cdCurrentTrack && cdLooping && @@ -226,20 +170,14 @@ void DM_CDAudio_Update(void) } } -/** - * Begin playback of a specifc audio track, possibly looped. - */ int DM_CDAudio_Play(int track, int looped) { - int len; - - if(!cdInited) - return false; + if(!cdInited) return false; // Get the length of the track. - cdTrackLength = len = getTrackLength(track); - if(!len) - return false; // Hmm?! + int len = getTrackLength(track); + cdTrackLength = len; + if(!len) return false; // Hmm?! // Play it! if(!sendMCICmd(0, 0, "play " DEVICEID " from %i to %i", track, @@ -252,28 +190,24 @@ int DM_CDAudio_Play(int track, int looped) return cdCurrentTrack = track; } -/** - * Pauses playback of the currently playing audio track. - */ void DM_CDAudio_Pause(int pause) { - if(!cdInited) - return; + if(!cdInited) return; sendMCICmd(0, 0, "%s " DEVICEID, pause ? "pause" : "play"); if(pause) + { cdPauseTime = Timer_Seconds(); + } else + { cdStartTime += Timer_Seconds() - cdPauseTime; + } } -/** - * Stops playback of the currently playing audio track. - */ -void DM_CDAudio_Stop(void) +void DM_CDAudio_Stop() { - if(!cdInited || !cdCurrentTrack) - return; + if(!cdInited || !cdCurrentTrack) return; cdCurrentTrack = 0; sendMCICmd(0, 0, "stop " DEVICEID);