From 6ec6095cb127421fc648781d0820d23d6e7a58a4 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Sun, 6 Oct 2013 14:58:44 +0000 Subject: Finish implementation of Hexen CD audio music mode. Subversion-branch: /branches/v2-branch Subversion-revision: 2694 --- src/hexen/p_setup.c | 18 ++--- src/hexen/s_sound.c | 194 +++++++++++++++++++++++++++++++++++----------------- src/hexen/s_sound.h | 3 + src/hexen/sb_bar.c | 45 ++++-------- src/i_cdmus.c | 19 ++++- src/setup/sound.c | 1 + 6 files changed, 170 insertions(+), 110 deletions(-) (limited to 'src') diff --git a/src/hexen/p_setup.c b/src/hexen/p_setup.c index 57c4ab8c..bf4c5359 100644 --- a/src/hexen/p_setup.c +++ b/src/hexen/p_setup.c @@ -671,11 +671,6 @@ void P_GroupLines(void) ================= */ -// haleyjd FIXME: CDMUSIC -#ifdef __WATCOMC__ -extern boolean i_CDMusic; -#endif - void P_SetupLevel(int episode, int map, int playermask, skill_t skill) { int i; @@ -690,15 +685,14 @@ void P_SetupLevel(int episode, int map, int playermask, skill_t skill) = players[i].itemcount = 0; } players[consoleplayer].viewz = 1; // will be set by player think - - - // haleyjd FIXME: CDMUSIC -#ifdef __WATCOMC__ - if (i_CDMusic == false) + + // Waiting-for-level-load song; not played if playing music from CD + // (the seek time will be so long it will just make loading take + // longer) + if (!cdmusic) { - S_StartSongName("chess", true); // Waiting-for-level-load song + S_StartSongName("chess", true); } -#endif Z_FreeTags(PU_LEVEL, PU_PURGELEVEL - 1); 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; /* =============================================================================== @@ -91,6 +101,52 @@ void S_Start(void) S_StartSong(gamemap, true); } +//========================================================================== +// +// 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 { @@ -162,6 +205,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(); } diff --git a/src/hexen/s_sound.h b/src/hexen/s_sound.h index b66a513e..f9f2ac5c 100644 --- a/src/hexen/s_sound.h +++ b/src/hexen/s_sound.h @@ -79,6 +79,7 @@ typedef struct extern int snd_MaxVolume; extern int snd_MusicVolume; extern int snd_Channels; +extern boolean cdmusic; void S_Start(void); void S_StartSound(mobj_t * origin, int sound_id); @@ -95,5 +96,7 @@ void S_Init(void); void S_GetChannelInfo(SoundInfo_t * s); void S_SetMusicVolume(void); boolean S_GetSoundPlayingInfo(mobj_t * mobj, int sound_id); +boolean S_StartCustomCDTrack(int tracknum); +int S_GetCurrentCDTrack(void); #endif diff --git a/src/hexen/sb_bar.c b/src/hexen/sb_bar.c index bcaa40be..a77e3a3b 100644 --- a/src/hexen/sb_bar.c +++ b/src/hexen/sb_bar.c @@ -26,6 +26,7 @@ // HEADER FILES ------------------------------------------------------------ #include "h2def.h" +#include "i_cdmus.h" #include "i_video.h" #include "m_bbox.h" #include "m_cheat.h" @@ -34,8 +35,6 @@ #include "s_sound.h" #include "v_video.h" -#include "i_sound.h" // For CD stuff - // TYPES ------------------------------------------------------------------- typedef struct Cheat_s @@ -96,15 +95,6 @@ static void CheatTrackFunc2(player_t * player, Cheat_t * cheat); extern int ArmorIncrement[NUMCLASSES][NUMARMOR]; extern int AutoArmorSave[NUMCLASSES]; -// haleyjd FIXME: CDMUSIC -#ifdef __WATCOMC__ -extern boolean i_CDMusic; -extern int i_CDMusicLength; -extern int i_CDTrack; -extern int i_CDCurrentTrack; -extern int oldTic; -#endif - // PUBLIC DATA DECLARATIONS ------------------------------------------------ boolean DebugSound; // Debug flag for displaying sound info @@ -113,11 +103,6 @@ int curpos; int inv_ptr; int ArtifactFlash; -// haleyjd FIXME: CDMUSIC -#ifndef __WATCOMC__ -boolean i_CDMusic; // in Watcom, defined in i_ibm -#endif - // PRIVATE DATA DEFINITIONS ------------------------------------------------ static int DisplayTicker = 0; @@ -1517,7 +1502,7 @@ static boolean HandleCheats(byte key) else if (netgame) { // change CD track is the only cheat available in deathmatch eat = false; - if (i_CDMusic) + if (cdmusic) { if (CheatAddKey(&Cheats[0], key, &eat)) { @@ -1931,22 +1916,21 @@ static void CheatRevealFunc(player_t * player, Cheat_t * cheat) static void CheatTrackFunc1(player_t * player, Cheat_t * cheat) { - // haleyjd FIXME: CDMUSIC -#ifdef __WATCOMC__ char buffer[80]; - if (!i_CDMusic) + if (!cdmusic) { return; } + if (I_CDMusInit() == -1) { P_SetMessage(player, "ERROR INITIALIZING CD", true); } + sprintf(buffer, "ENTER DESIRED CD TRACK (%.2d - %.2d):\n", I_CDMusFirstTrack(), I_CDMusLastTrack()); P_SetMessage(player, buffer, true); -#endif } //=========================================================================== @@ -1957,41 +1941,38 @@ static void CheatTrackFunc1(player_t * player, Cheat_t * cheat) static void CheatTrackFunc2(player_t * player, Cheat_t * cheat) { - // haleyjd FIXME: CDMUSIC -#ifdef __WATCOMC__ char buffer[80]; int track; char args[2]; cht_GetParam(cheat->seq, args); - if (!i_CDMusic) + if (!cdmusic) { return; } + track = (args[0] - '0') * 10 + (args[1] - '0'); if (track < I_CDMusFirstTrack() || track > I_CDMusLastTrack()) { P_SetMessage(player, "INVALID TRACK NUMBER\n", true); return; } - if (track == i_CDCurrentTrack) + + if (track == S_GetCurrentCDTrack()) { return; } - if (I_CDMusPlay(track)) + + if (!S_StartCustomCDTrack(track)) { sprintf(buffer, "ERROR WHILE TRYING TO PLAY CD TRACK: %.2d\n", track); P_SetMessage(player, buffer, true); } else - { // No error encountered while attempting to play the track + { + // No error encountered while attempting to play the track sprintf(buffer, "PLAYING TRACK: %.2d\n", track); P_SetMessage(player, buffer, true); - i_CDMusicLength = 35 * I_CDMusTrackLength(track); - oldTic = gametic; - i_CDTrack = track; - i_CDCurrentTrack = track; } -#endif } diff --git a/src/i_cdmus.c b/src/i_cdmus.c index 94ac47c6..d05b5bd1 100644 --- a/src/i_cdmus.c +++ b/src/i_cdmus.c @@ -42,8 +42,20 @@ int I_CDMusInit(void) { int drive_num = 0; + // The initialize function is re-invoked when the CD track play cheat + // is used, so use the opportunity to call SDL_CDStatus() to update + // the status of the drive. + // TODO: Check this actually works. + + if (cd_handle != NULL) + { + SDL_CDStatus(cd_handle); + cd_Error = 0; + return 0; + } + // TODO: config variable to control CDROM to use. - + cd_handle = SDL_CDOpen(drive_num); if (cd_handle == NULL) @@ -53,6 +65,8 @@ int I_CDMusInit(void) return -1; } + printf("I_CDMusInit: Using CD-ROM drive: %s\n", SDL_CDName(drive_num)); + if (!CD_INDRIVE(cd_handle->status)) { fprintf(stderr, "I_CDMusInit: '%s': no CD in drive.\n", @@ -139,8 +153,7 @@ int I_CDMusFirstTrack(void) } } - /* Don't know? */ - + // Don't know? cd_Error = 1; return -1; diff --git a/src/setup/sound.c b/src/setup/sound.c index cd625efd..f601d5ff 100644 --- a/src/setup/sound.c +++ b/src/setup/sound.c @@ -131,6 +131,7 @@ static void UpdateSndDevices(TXT_UNCAST_ARG(widget), TXT_UNCAST_ARG(data)) snd_musicdevice = SNDDEVICE_GUS; break; case MUSICMODE_CD: + snd_musicdevice = SNDDEVICE_CD; break; } } -- cgit v1.2.3