From da310386aebe60dd8d70a640df035829a9f17d94 Mon Sep 17 00:00:00 2001 From: Justin Marshall Date: Tue, 2 Jun 2020 13:23:07 -0700 Subject: [PATCH] OpenAL music works at latest. --- REDALERT/AUDIOMIX.H | 4 +++- REDALERT/AUDMIX.CPP | 33 ++++++++++++++++++++++++++++++++ REDALERT/THEME.CPP | 46 ++++++++++++++++----------------------------- REDALERT/THEME.H | 2 ++ 4 files changed, 54 insertions(+), 31 deletions(-) diff --git a/REDALERT/AUDIOMIX.H b/REDALERT/AUDIOMIX.H index 4ef1f57..a45322b 100644 --- a/REDALERT/AUDIOMIX.H +++ b/REDALERT/AUDIOMIX.H @@ -5,4 +5,6 @@ #pragma once void AudMix_Init(void); -const char* GetEffectFileName(int index); \ No newline at end of file +const char* GetEffectFileName(int index); +const char* GetThemeMusicFileName(int index); +void AudMix_PlayMusic(int musicId); \ No newline at end of file diff --git a/REDALERT/AUDMIX.CPP b/REDALERT/AUDMIX.CPP index c407435..0920541 100644 --- a/REDALERT/AUDMIX.CPP +++ b/REDALERT/AUDMIX.CPP @@ -34,6 +34,9 @@ enum AudioBufferType_t { #define MAX_PRECACHE_AUDIO 512 AudioBuffer_t precacheAudioTable[AUDIO_BUFFER_NUMTYPES][MAX_PRECACHE_AUDIO]; +AudioBuffer_t musicPrecacheAudioTable[MAX_PRECACHE_AUDIO]; + +int currentMusicPlaying = -1; struct RIFF_Header { char chunkID[4]; @@ -154,6 +157,22 @@ bool AudMix_IsEnabled(void) { return device != NULL && context != NULL; } +/* +============= +AudMix_PlayMusic +============= +*/ +void AudMix_PlayMusic(int musicId) { + if (currentMusicPlaying != -1) { + alSourcei(musicPrecacheAudioTable[currentMusicPlaying].sourceId, AL_LOOPING, 0); + alSourceStop(musicPrecacheAudioTable[currentMusicPlaying].sourceId); + } + + alSourcei(musicPrecacheAudioTable[musicId].sourceId, AL_LOOPING, 1); + alSourcePlay(musicPrecacheAudioTable[musicId].sourceId); + currentMusicPlaying = musicId; +} + /* ============= AudMix_Init @@ -191,6 +210,16 @@ void AudMix_Init(void) { } } + // Precache the music. + for (int i = 0; i < THEME_COUNT; i++) { + char expandedFilePath[512]; + + sprintf(expandedFilePath, "sound/music/%s.wav", GetThemeMusicFileName(i)); + if (!loadWavFile(expandedFilePath, musicPrecacheAudioTable[i])) { + //assert(!"failed to load music!"); + } + } + alListener3f(AL_POSITION, 0.0f, 0.0f, 0.0f); } @@ -210,6 +239,10 @@ void On_Sound_Effect(int sound_index, int variation, COORDINATE coord, int house // void On_Speech(int speech_index) // MBL 02.06.2020 void On_Speech(int speech_index, HouseClass* house) { + if (house == NULL) { + alSourcePlay(precacheAudioTable[AUDIO_BUFFER_HOUSE_NONE][speech_index].sourceId); + } + // DLLExportClass::On_Speech(PlayerPtr, speech_index); // MBL 02.06.2020 //if (house == NULL) { // DLLExportClass::On_Speech(PlayerPtr, speech_index); diff --git a/REDALERT/THEME.CPP b/REDALERT/THEME.CPP index 5bc3a4a..7417a13 100644 --- a/REDALERT/THEME.CPP +++ b/REDALERT/THEME.CPP @@ -49,6 +49,7 @@ #include "function.h" #include "theme.h" +#include "AUDIOMIX.H" #ifndef WIN32 extern short StreamLowImpact; @@ -102,6 +103,9 @@ ThemeClass::ThemeControl ThemeClass::_themes[THEME_COUNT] = { #endif }; +const char* GetThemeMusicFileName(int index) { + return ThemeClass::_themes[index].Name; +} /*********************************************************************************************** * ThemeClass::Base_Name -- Fetches the base filename for the theme specified. * @@ -282,33 +286,13 @@ ThemeType ThemeClass::Next_Song(ThemeType theme) const *=============================================================================================*/ void ThemeClass::Queue_Song(ThemeType theme) { - /* - ** If there is no score file present, then abort. - */ - if (!ScoresPresent) return; - - /* - ** If there is no sound driver or sounds have been specifically - ** turned off, then abort. - */ - if (SampleType == 0 || Debug_Quiet) return; - /* ** If the current score volumne is set to silent, then there is no need to play the ** specified theme. */ if (Options.ScoreVolume == 0) return; - /* - ** If the pending theme is available to be set and the specified theme is valid, then - ** set the queued theme accordingly. - */ - if (Pending == THEME_NONE || Pending == THEME_PICK_ANOTHER || theme == THEME_NONE || theme == THEME_QUIET) { - Pending = theme; - if (Still_Playing()) { - Fade_Sample(Current, THEME_DELAY); - } - } + AudMix_PlayMusic(theme); } @@ -330,15 +314,17 @@ void ThemeClass::Queue_Song(ThemeType theme) *=============================================================================================*/ int ThemeClass::Play_Song(ThemeType theme) { - if (ScoresPresent && SampleType && !Debug_Quiet && Options.ScoreVolume != 0) { - Stop(); - Score = theme; - if (theme != THEME_NONE && theme != THEME_QUIET) { - //PG StreamLowImpact = true; - Current = File_Stream_Sample_Vol(Theme_File_Name(theme), 0xFF, true); - //PG StreamLowImpact = false; - } - } + AudMix_PlayMusic(theme); + + //if (ScoresPresent && SampleType && !Debug_Quiet && Options.ScoreVolume != 0) { + // Stop(); + // Score = theme; + // if (theme != THEME_NONE && theme != THEME_QUIET) { + // //PG StreamLowImpact = true; + // Current = File_Stream_Sample_Vol(Theme_File_Name(theme), 0xFF, true); + // //PG StreamLowImpact = false; + // } + //} return(Current); } diff --git a/REDALERT/THEME.H b/REDALERT/THEME.H index b46c34e..5c76520 100644 --- a/REDALERT/THEME.H +++ b/REDALERT/THEME.H @@ -37,6 +37,8 @@ class ThemeClass { + friend const char* GetThemeMusicFileName(int index); + private: static char const * Theme_File_Name(ThemeType theme);