diff options
author | Simon Howard | 2013-10-06 14:58:44 +0000 |
---|---|---|
committer | Simon Howard | 2013-10-06 14:58:44 +0000 |
commit | 6ec6095cb127421fc648781d0820d23d6e7a58a4 (patch) | |
tree | eafd74cee78d87112b726c59d4e2f9576fb2370a /src/hexen/s_sound.c | |
parent | 9a4f30c23a7b87e5f5bf3e4e4039c845cba38d66 (diff) | |
download | chocolate-doom-6ec6095cb127421fc648781d0820d23d6e7a58a4.tar.gz chocolate-doom-6ec6095cb127421fc648781d0820d23d6e7a58a4.tar.bz2 chocolate-doom-6ec6095cb127421fc648781d0820d23d6e7a58a4.zip |
Finish implementation of Hexen CD audio music mode.
Subversion-branch: /branches/v2-branch
Subversion-revision: 2694
Diffstat (limited to 'src/hexen/s_sound.c')
-rw-r--r-- | src/hexen/s_sound.c | 194 |
1 files changed, 131 insertions, 63 deletions
diff --git a/src/hexen/s_sound.c b/src/hexen/s_sound.c index 45890300..de770bab 100644 --- a/src/hexen/s_sound.c +++ b/src/hexen/s_sound.c @@ -27,6 +27,7 @@ #include "i_cdmus.h" #include "i_sound.h" #include "i_system.h" +#include "i_timer.h" #include "m_argv.h" #include "m_misc.h" #include "r_local.h" @@ -41,11 +42,20 @@ void S_ShutDown(void); -boolean i_CDMusic; -int i_CDTrack; -int i_CDCurrentTrack; -int i_CDMusicLength; -int oldTic; +// If true, CD music playback is enabled (snd_musicdevice == SNDDEVICE_CD +// and CD initialization succeeded). +boolean cdmusic; + +// Track number of a track to play explicitly chosen by the +// player using cheats. A value of zero means no track chosen: +static int cd_custom_track = 0; + +// Currently playing track: +static int cd_current_track = 0; + +// Time (MS) at which the currently-playing CD track will finish playing +// and should be looped. Zero if we are not currently playing a track: +static int cd_track_end_time = 0; /* =============================================================================== @@ -93,6 +103,52 @@ void S_Start(void) //========================================================================== // +// Returns true if we are playing a looping CD track and it is time to +// restart it. +// +//========================================================================== + +static boolean ShouldRestartCDTrack(void) +{ + return cd_track_end_time != 0 && I_GetTimeMS() > cd_track_end_time; +} + +//========================================================================== +// +// Start playing a CD track. Returns true for success. +// +//========================================================================== + +static boolean StartCDTrack(int track, boolean loop) +{ + // Already playing? If so, don't bother. + + if (track == cd_current_track && !ShouldRestartCDTrack()) + { + return true; + } + + if (I_CDMusPlay(track)) + { + return false; + } + + cd_current_track = track; + + if (loop) + { + cd_track_end_time = I_GetTimeMS() + 1000 * I_CDMusTrackLength(track); + } + else + { + cd_track_end_time = 0; + } + + return true; +} + +//========================================================================== +// // S_StartSong // //========================================================================== @@ -104,33 +160,20 @@ void S_StartSong(int song, boolean loop) int length; int track; - if (i_CDMusic) - { // Play a CD track, instead - if (i_CDTrack) - { // Default to the player-chosen track - track = i_CDTrack; + // If we're in CD music mode, play a CD track, instead: + if (cdmusic) + { + // Default to the player-chosen track + if (cd_custom_track != 0) + { + track = cd_custom_track; } else { track = P_GetMapCDTrack(gamemap); } - if (track == i_CDCurrentTrack && i_CDMusicLength > 0) - { - return; - } - if (!I_CDMusPlay(track)) - { - if (loop) - { - i_CDMusicLength = 35 * I_CDMusTrackLength(track); - oldTic = gametic; - } - else - { - i_CDMusicLength = -1; - } - i_CDCurrentTrack = track; - } + + StartCDTrack(track, loop); } else { @@ -164,6 +207,44 @@ void S_StartSong(int song, boolean loop) //========================================================================== // +// Play a custom-chosen music track selected by the player. +// +// Returns true for success. +// +//========================================================================== + +boolean S_StartCustomCDTrack(int tracknum) +{ + boolean result; + + result = StartCDTrack(tracknum, true); + + if (result) + { + cd_custom_track = tracknum; + } + + return result; +} + +//========================================================================== +// +// Get the currently-playing CD track; returns -1 if not playing. +// +//========================================================================== + +int S_GetCurrentCDTrack(void) +{ + if (!cdmusic || cd_current_track == 0) + { + return -1; + } + + return cd_current_track; +} + +//========================================================================== +// // S_StartSongName // //========================================================================== @@ -178,7 +259,7 @@ void S_StartSongName(char *songLump, boolean loop) { return; } - if (i_CDMusic) + if (cdmusic) { cdTrack = 0; @@ -198,7 +279,7 @@ void S_StartSongName(char *songLump, boolean loop) { cdTrack = P_GetCDEnd2Track(); } - else if (!strcmp(songLump, "chess") && !i_CDTrack) + else if (!strcmp(songLump, "chess") && cd_custom_track == 0) { cdTrack = P_GetCDEnd3Track(); } @@ -208,23 +289,10 @@ void S_StartSongName(char *songLump, boolean loop) cdTrack = P_GetCDStartTrack(); } */ - if (!cdTrack || (cdTrack == i_CDCurrentTrack && i_CDMusicLength > 0)) + if (!cdTrack) { - return; - } - if (!I_CDMusPlay(cdTrack)) - { - if (loop) - { - i_CDMusicLength = 35 * I_CDMusTrackLength(cdTrack); - oldTic = gametic; - } - else - { - i_CDMusicLength = -1; - } - i_CDCurrentTrack = cdTrack; - i_CDTrack = false; + cd_custom_track = 0; + StartCDTrack(cdTrack, loop); } } else @@ -595,7 +663,7 @@ void S_SoundLink(mobj_t * oldactor, mobj_t * newactor) void S_PauseSound(void) { - if (i_CDMusic) + if (cdmusic) { I_CDMusStop(); } @@ -613,7 +681,7 @@ void S_PauseSound(void) void S_ResumeSound(void) { - if (i_CDMusic) + if (cdmusic) { I_CDMusResume(); } @@ -638,12 +706,13 @@ void S_UpdateSounds(mobj_t * listener) int absx; int absy; -#ifdef CDMUSIC - if (i_CDMusic) + // If we are looping a CD track, we need to check if it has + // finished playing and needs to restart. + if (cdmusic && ShouldRestartCDTrack()) { - I_UpdateCDMusic(); + StartCDTrack(cd_current_track, true); } -#endif + if (snd_MaxVolume == 0) { return; @@ -739,21 +808,21 @@ void S_Init(void) I_PrecacheSounds(S_sfx, NUMSFX); -#ifdef CDMUSIC -//TODO // Attempt to setup CD music - if (snd_MusicDevice == snd_CDMUSIC) + if (snd_musicdevice == SNDDEVICE_CD) { ST_Message(" Attempting to initialize CD Music: "); if (!cdrom) { - i_CDMusic = (I_CDMusInit() != -1); + cdmusic = (I_CDMusInit() != -1); } else - { // The user is trying to use the cdrom for both game and music - i_CDMusic = false; + { + // The user is trying to use the cdrom for both game and music + cdmusic = false; } - if (i_CDMusic) + + if (cdmusic) { ST_Message("initialized.\n"); } @@ -762,7 +831,6 @@ void S_Init(void) ST_Message("failed.\n"); } } -#endif } //========================================================================== @@ -830,7 +898,7 @@ boolean S_GetSoundPlayingInfo(mobj_t * mobj, int sound_id) void S_SetMusicVolume(void) { - if (i_CDMusic) + if (cdmusic) { I_CDMusSetVolume(snd_MusicVolume * 16); // 0-255 } @@ -840,7 +908,7 @@ void S_SetMusicVolume(void) } if (snd_MusicVolume == 0) { - if (!i_CDMusic) + if (!cdmusic) { I_PauseSong(); } @@ -848,7 +916,7 @@ void S_SetMusicVolume(void) } else if (MusicPaused) { - if (!i_CDMusic) + if (!cdmusic) { I_ResumeSong(); } @@ -867,7 +935,7 @@ void S_ShutDown(void) I_StopSong(); I_UnRegisterSong(RegisteredSong); I_ShutdownSound(); - if (i_CDMusic) + if (cdmusic) { I_CDMusStop(); } |