From f1a6025aa2a8b6c99798e0738eaca4c844933c20 Mon Sep 17 00:00:00 2001 From: Jonathan Gray Date: Tue, 29 Jul 2003 12:34:46 +0000 Subject: turn d_sound.cpp into class BS2Sound svn-id: r9280 --- sword2/anims.cpp | 10 +-- sword2/controls.cpp | 82 +++++++++++------------ sword2/driver/d_sound.cpp | 165 +++++++++++++++++++++------------------------- sword2/driver/d_sound.h | 93 +++++++++++++++++++++++++- sword2/driver/driver96.h | 45 ------------- sword2/function.cpp | 3 +- sword2/mouse.cpp | 4 +- sword2/sound.cpp | 41 ++++++------ sword2/speech.cpp | 12 ++-- sword2/startup.cpp | 4 +- sword2/sword2.cpp | 6 +- sword2/sword2.h | 2 + 12 files changed, 249 insertions(+), 218 deletions(-) diff --git a/sword2/anims.cpp b/sword2/anims.cpp index 918a2ae54e..cd31e429fd 100644 --- a/sword2/anims.cpp +++ b/sword2/anims.cpp @@ -601,7 +601,7 @@ void CreateSequenceSpeech(_movieTextObject *sequenceText[]) // (James23may97) } //------------------------------ - wavSize = GetCompSpeechSize(speechFile, wavId); // returns size of decompressed wav, or 0 if wav not found + wavSize = g_bs2->_sound->GetCompSpeechSize(speechFile, wavId); // returns size of decompressed wav, or 0 if wav not found if (wavSize) // if we've got the wav { // allocate memory for speech buffer @@ -609,7 +609,7 @@ void CreateSequenceSpeech(_movieTextObject *sequenceText[]) // (James23may97) if (sequence_text_list[line].speech_mem) // if mem allocated ok (should be fine, but worth checking) { - if (PreFetchCompSpeech(speechFile, wavId, sequence_text_list[line].speech_mem->ad) == RD_OK) // Load speech & decompress to our buffer + if (g_bs2->_sound->PreFetchCompSpeech(speechFile, wavId, sequence_text_list[line].speech_mem->ad) == RD_OK) // Load speech & decompress to our buffer { Float_mem (sequence_text_list[line].speech_mem); // now float this buffer so we can make space for the next text sprites and/or speech samples speechRunning=1; // ok, we've got speech! @@ -722,7 +722,7 @@ int32 FN_smacker_lead_in(int32 *params) // James(21july97) //----------------------------------------- leadIn += sizeof(_standardHeader); - rv = PlayFx( 0, leadIn, 0, 0, RDSE_FXLEADIN ); // wav data gets copied to sound memory + rv = g_bs2->_sound->PlayFx( 0, leadIn, 0, 0, RDSE_FXLEADIN ); // wav data gets copied to sound memory //----------------------------------------- #ifdef _BS2_DEBUG @@ -840,7 +840,7 @@ int32 FN_play_sequence(int32 *params) // James(09apr97) // play the smacker FN_stop_music(NULL); // don't want to carry on streaming game music when smacker starts! - PauseFxForSequence(); // pause sfx during sequence, except the one used for lead-in music + g_bs2->_sound->PauseFxForSequence(); // pause sfx during sequence, except the one used for lead-in music if (sequenceTextLines) // if we have some text to accompany this sequence rv = PlaySmacker(filename, sequenceSpeechArray, leadOut); @@ -857,7 +857,7 @@ int32 FN_play_sequence(int32 *params) // James(09apr97) } */ - UnpauseFx(); // unpause sound fx again, in case we're staying in same location + g_bs2->_sound->UnpauseFx(); // unpause sound fx again, in case we're staying in same location //-------------------------------------- // close the lead-out music resource diff --git a/sword2/controls.cpp b/sword2/controls.cpp index 2745c7e560..3c004427ab 100644 --- a/sword2/controls.cpp +++ b/sword2/controls.cpp @@ -1929,12 +1929,12 @@ int32 ReadOptionSettings(void) //pete10Jun97 fclose(fp); - SetMusicVolume(buff[0]); - SetSpeechVolume(buff[1]); - SetFxVolume(buff[2]); - MuteMusic(buff[3]); - MuteSpeech(buff[4]); - MuteFx(buff[5]); + g_bs2->_sound->SetMusicVolume(buff[0]); + g_bs2->_sound->SetSpeechVolume(buff[1]); + g_bs2->_sound->SetFxVolume(buff[2]); + g_bs2->_sound->MuteMusic(buff[3]); + g_bs2->_sound->MuteSpeech(buff[4]); + g_bs2->_sound->MuteFx(buff[5]); UpdateGraphicsLevel(GetRenderType(), buff[6]); // (James13jun97) @@ -1944,7 +1944,7 @@ int32 ReadOptionSettings(void) //pete10Jun97 pointerTextSelected = buff[8]; if (buff[9] != stereoReversed) - ReverseStereo(); + g_bs2->_sound->ReverseStereo(); stereoReversed = buff[9]; @@ -1956,12 +1956,12 @@ int32 WriteOptionSettings(void) //pete10Jun97 uint8 buff[10]; FILE *fp; - buff[0] = GetMusicVolume(); - buff[1] = GetSpeechVolume(); - buff[2] = GetFxVolume(); - buff[3] = IsMusicMute(); - buff[4] = IsSpeechMute(); - buff[5] = IsFxMute(); + buff[0] = g_bs2->_sound->GetMusicVolume(); + buff[1] = g_bs2->_sound->GetSpeechVolume(); + buff[2] = g_bs2->_sound->GetFxVolume(); + buff[3] = g_bs2->_sound->IsMusicMute(); + buff[4] = g_bs2->_sound->IsSpeechMute(); + buff[5] = g_bs2->_sound->IsFxMute(); buff[6] = GetRenderType(); buff[7] = subtitles; buff[8] = pointerTextSelected; @@ -2094,9 +2094,9 @@ void Option_control(void) //Pete6Jun97 int title_len, subtitle_len, ok_len, cancel_len, left_align, test_len; // slider values - uint8 musicVolume = GetMusicVolume(); - uint8 speechVolume = GetSpeechVolume(); - uint8 fxVolume = GetFxVolume(); + uint8 musicVolume = g_bs2->_sound->GetMusicVolume(); + uint8 speechVolume = g_bs2->_sound->GetSpeechVolume(); + uint8 fxVolume = g_bs2->_sound->GetFxVolume(); uint8 grfxLevel = GetRenderType(); // safe slider values for restoring on cancel @@ -2197,9 +2197,9 @@ void Option_control(void) //Pete6Jun97 uint8 subtitle_state = subtitles; uint8 stereo_state = stereoReversed; - uint8 music_mute_state = IsMusicMute(); - uint8 speech_mute_state = IsSpeechMute(); - uint8 fx_mute_state = IsFxMute(); + uint8 music_mute_state = g_bs2->_sound->IsMusicMute(); + uint8 speech_mute_state = g_bs2->_sound->IsSpeechMute(); + uint8 fx_mute_state = g_bs2->_sound->IsFxMute(); //build the button surfaces surfaces @@ -2359,19 +2359,19 @@ void Option_control(void) //Pete6Jun97 } if (!music_mute_state) - SetMusicVolume(musicVolume); + g_bs2->_sound->SetMusicVolume(musicVolume); else - SetMusicVolume(0); + g_bs2->_sound->SetMusicVolume(0); if (!fx_mute_state) - SetFxVolume(fxVolume); + g_bs2->_sound->SetFxVolume(fxVolume); else - SetFxVolume(0); + g_bs2->_sound->SetFxVolume(0); if (!speech_mute_state) - SetSpeechVolume(speechVolume); + g_bs2->_sound->SetSpeechVolume(speechVolume); else - SetSpeechVolume(0); + g_bs2->_sound->SetSpeechVolume(0); //-------------------------------------------------- // Service windows @@ -2555,19 +2555,19 @@ void Option_control(void) //Pete6Jun97 { UpdateGraphicsLevel(safe_grfxLevel, grfxLevel); // (James13jun97) - MuteMusic(music_mute_state); // Ensure all the levels are recorded correctly (Pete21Aug97) - MuteSpeech(speech_mute_state); - MuteFx(fx_mute_state); - SetMusicVolume(music_target); - SetSpeechVolume(speech_target); - SetFxVolume(fx_target); + g_bs2->_sound->MuteMusic(music_mute_state); // Ensure all the levels are recorded correctly (Pete21Aug97) + g_bs2->_sound->MuteSpeech(speech_mute_state); + g_bs2->_sound->MuteFx(fx_mute_state); + g_bs2->_sound->SetMusicVolume(music_target); + g_bs2->_sound->SetSpeechVolume(speech_target); + g_bs2->_sound->SetFxVolume(fx_target); subtitles = subtitle_state; // Save object label and subtitle settings pointerTextSelected = object_state; speechSelected = !speech_mute_state; if (stereo_state != stereoReversed) - ReverseStereo(); + g_bs2->_sound->ReverseStereo(); stereoReversed = stereo_state; WriteOptionSettings(); @@ -2591,17 +2591,17 @@ void Option_control(void) //Pete6Jun97 if (touching_music_mute && dmusic_mute_state) { music_mute_state = dmusic_mute_state = 0; // if the button was in now let it out - MuteMusic(0); + g_bs2->_sound->MuteMusic(0); } if (touching_fx_mute && dfx_mute_state) { fx_mute_state = dfx_mute_state = 0; // if the button was in now let it out - MuteFx(0); + g_bs2->_sound->MuteFx(0); } if (touching_speech_mute && dspeech_mute_state) { speech_mute_state = dspeech_mute_state = 0; // if the button was in now let it out - MuteSpeech(0); + g_bs2->_sound->MuteSpeech(0); } // Stop tracking any sliders @@ -2649,7 +2649,7 @@ void Option_control(void) //Pete6Jun97 else { music_mute_state = 1; - MuteMusic(1); + g_bs2->_sound->MuteMusic(1); } } @@ -2660,7 +2660,7 @@ void Option_control(void) //Pete6Jun97 else { fx_mute_state=1; - MuteFx(1); + g_bs2->_sound->MuteFx(1); } } @@ -2671,7 +2671,7 @@ void Option_control(void) //Pete6Jun97 else { speech_mute_state=1; - MuteSpeech(1); + g_bs2->_sound->MuteSpeech(1); } } @@ -2680,7 +2680,7 @@ void Option_control(void) //Pete6Jun97 if (music_mute_state) { music_mute_state = 0; - MuteMusic(0); + g_bs2->_sound->MuteMusic(0); } if (mousex>(slab_sprite[0].x+SLIDER_W)) @@ -2707,7 +2707,7 @@ void Option_control(void) //Pete6Jun97 if (speech_mute_state) { speech_mute_state = 0; - MuteSpeech(0); + g_bs2->_sound->MuteSpeech(0); } if (mousex>(slab_sprite[1].x+SLIDER_W)) @@ -2734,7 +2734,7 @@ void Option_control(void) //Pete6Jun97 if (fx_mute_state) { fx_mute_state = 0; - MuteFx(0); + g_bs2->_sound->MuteFx(0); } if (mousex>(slab_sprite[2].x+SLIDER_W)) diff --git a/sword2/driver/d_sound.cpp b/sword2/driver/d_sound.cpp index cc88f6aac0..6fb8ac6274 100644 --- a/sword2/driver/d_sound.cpp +++ b/sword2/driver/d_sound.cpp @@ -358,6 +358,7 @@ #include "stdafx.h" #include "driver96.h" #include "rdwin.h" // for hwnd. +#include "d_sound.h" // Decompression macros #define MakeCompressedByte(shift,sign,amplitude) (((shift)<<4) + ((sign)<<3) + (amplitude)) @@ -366,6 +367,13 @@ #define GetCompressedAmplitude(byte) ((byte) & 7) #define GetdAPower(dA,power) for (power = 15;power>0 && !((dA) & (1<_sound->UpdateCompSampleStreaming(); // And wait for it to die GetDrawStatus (&ds); GetSoundStatus(&ss); diff --git a/sword2/mouse.cpp b/sword2/mouse.cpp index 4ace612770..e286872ba3 100644 --- a/sword2/mouse.cpp +++ b/sword2/mouse.cpp @@ -235,7 +235,7 @@ void System_menu(void) //Tony19Mar97 } //------------------------ - rv = PauseFx(); + rv = g_bs2->_sound->PauseFx(); if (rv != RD_OK) Zdebug("ERROR: PauseFx() returned %.8x in SystemMenu()", rv); //------------------------ @@ -309,7 +309,7 @@ void System_menu(void) //Tony19Mar97 this_screen.new_palette=1; //------------------------ - rv = UnpauseFx(); + rv = g_bs2->_sound->UnpauseFx(); if (rv != RD_OK) Zdebug("ERROR: UnpauseFx() returned %.8x in SystemMenu()", rv); //------------------------ diff --git a/sword2/sound.cpp b/sword2/sound.cpp index 2bf4b98d02..99ac8e0a5c 100644 --- a/sword2/sound.cpp +++ b/sword2/sound.cpp @@ -111,7 +111,7 @@ void Process_fx_queue(void) } else if (fxq[j].type == FX_SPOT2) { - if (IsFxOpen(j+1)) + if (g_bs2->_sound->IsFxOpen(j+1)) fxq[j].resource = 0; // Once the Fx has finished remove it from the queue. } } @@ -131,7 +131,7 @@ void Trigger_fx(uint8 j) // called from Process_fx_queue only { data = res_man.Res_open(fxq[j].resource); // load in the sample data += sizeof(_standardHeader); - rv = PlayFx( id, data, fxq[j].volume, fxq[j].pan, RDSE_FXSPOT ); // wav data gets copied to sound memory + rv = g_bs2->_sound->PlayFx( id, data, fxq[j].volume, fxq[j].pan, RDSE_FXSPOT ); // wav data gets copied to sound memory res_man.Res_close(fxq[j].resource); // release the sample // fxq[j].resource = 0; // clear spot fx from queue } @@ -139,9 +139,9 @@ void Trigger_fx(uint8 j) // called from Process_fx_queue only { // - to be referenced by 'j', so pass NULL data if (fxq[j].type == FX_RANDOM) - rv = PlayFx( id, NULL, fxq[j].volume, fxq[j].pan, RDSE_FXSPOT ); // not looped + rv = g_bs2->_sound->PlayFx( id, NULL, fxq[j].volume, fxq[j].pan, RDSE_FXSPOT ); // not looped else // FX_LOOP - rv = PlayFx( id, NULL, fxq[j].volume, fxq[j].pan, RDSE_FXLOOP ); // looped + rv = g_bs2->_sound->PlayFx( id, NULL, fxq[j].volume, fxq[j].pan, RDSE_FXLOOP ); // looped } #ifdef _BS2_DEBUG @@ -251,7 +251,7 @@ int32 FN_play_fx(int32 *params) // called from script only #endif data += sizeof(_standardHeader); - rv = OpenFx(id,data); // copy it to sound memory, using position in queue as 'id' + rv = g_bs2->_sound->OpenFx(id,data); // copy it to sound memory, using position in queue as 'id' #ifdef _BS2_DEBUG if (rv) @@ -289,7 +289,7 @@ int32 FN_set_fx_vol_and_pan(int32 *params) // 2 new pan (-16..16) // SetFxVolumePan(int32 id, uint8 vol, uint8 pan); - SetFxVolumePan(1+params[0], params[1], params[2]); // driver fx_id is 1+ + g_bs2->_sound->SetFxVolumePan(1+params[0], params[1], params[2]); // driver fx_id is 1+ // Zdebug("%d",params[2]); return (IR_CONT); @@ -302,7 +302,7 @@ int32 FN_set_fx_vol(int32 *params) // 1 new volume (0..16) // SetFxIdVolume(int32 id, uint8 vol); - SetFxIdVolume(1+params[0], params[1]); + g_bs2->_sound->SetFxIdVolume(1+params[0], params[1]); return (IR_CONT); } @@ -321,7 +321,7 @@ int32 FN_stop_fx(int32 *params) // called from script only if ((fxq[j].type == FX_RANDOM) || (fxq[j].type == FX_LOOP)) { id = (uint32)j+1; // because 0 is not a valid id - rv = CloseFx(id); // stop fx & remove sample from sound memory + rv = g_bs2->_sound->CloseFx(id); // stop fx & remove sample from sound memory #ifdef _BS2_DEBUG if (rv) @@ -350,7 +350,7 @@ int32 FN_stop_all_fx(int32 *params) // called from script only void Clear_fx_queue(void) { - ClearAllFx(); // stop all fx & remove the samples from sound memory + g_bs2->_sound->ClearAllFx(); // stop all fx & remove the samples from sound memory Init_fx_queue(); // clean out the queue } @@ -415,7 +415,7 @@ int32 FN_play_music(int32 *params) // updated by James on 10apr97 else sprintf(filename,"%sCLUSTERS\\MUSIC.CLU", res_man.GetCdPath()); - rv = StreamCompMusic(filename, params[0], loopFlag); + rv = g_bs2->_sound->StreamCompMusic(filename, params[0], loopFlag); #ifdef _BS2_DEBUG if (rv) @@ -435,25 +435,24 @@ int32 FN_stop_music(int32 *params) // called from script only looping_music_id=0; // clear the 'looping' flag - StopMusic(); + g_bs2->_sound->StopMusic(); if (params); return(IR_CONT); // continue script } //-------------------------------------------------------------------------------------- -extern void UpdateCompSampleStreaming(void); // used in Kill_music() //-------------------------------------------------------------------------------------- void Kill_music(void) // James22aug97 { uint8 count; looping_music_id=0; // clear the 'looping' flag - StopMusic(); + g_bs2->_sound->StopMusic(); // THIS BIT CAUSES THE MUSIC TO STOP INSTANTLY! for(count=0; count<16; count++) - UpdateCompSampleStreaming(); + g_bs2->_sound->UpdateCompSampleStreaming(); } //-------------------------------------------------------------------------------------- int32 FN_check_music_playing(int32 *params) // James (30july97) @@ -463,7 +462,7 @@ int32 FN_check_music_playing(int32 *params) // James (30july97) // sets result to no. of seconds of current tune remaining // or 0 if no music playing - RESULT = MusicTimeRemaining(); // in seconds, rounded up to the nearest second + RESULT = g_bs2->_sound->MusicTimeRemaining(); // in seconds, rounded up to the nearest second return(IR_CONT); // continue script } @@ -472,15 +471,15 @@ void PauseAllSound(void) // James25july97 { uint32 rv; // for drivers return value - rv = PauseMusic(); + rv = g_bs2->_sound->PauseMusic(); if (rv != RD_OK) Zdebug("ERROR: PauseMusic() returned %.8x in PauseAllSound()", rv); - rv = PauseSpeech(); + rv = g_bs2->_sound->PauseSpeech(); if (rv != RD_OK) Zdebug("ERROR: PauseSpeech() returned %.8x in PauseAllSound()", rv); - rv = PauseFx(); + rv = g_bs2->_sound->PauseFx(); if (rv != RD_OK) Zdebug("ERROR: PauseFx() returned %.8x in PauseAllSound()", rv); } @@ -489,15 +488,15 @@ void UnpauseAllSound(void) // James25july97 { uint32 rv; // for drivers return value - rv = UnpauseMusic(); + rv = g_bs2->_sound->UnpauseMusic(); if (rv != RD_OK) Zdebug("ERROR: UnpauseMusic() returned %.8x in UnpauseAllSound()", rv); - rv = UnpauseSpeech(); + rv = g_bs2->_sound->UnpauseSpeech(); if (rv != RD_OK) Zdebug("ERROR: UnpauseSpeech() returned %.8x in UnpauseAllSound()", rv); - rv = UnpauseFx(); + rv = g_bs2->_sound->UnpauseFx(); if (rv != RD_OK) Zdebug("ERROR: UnpauseFx() returned %.8x in UnpauseAllSound()", rv); } diff --git a/sword2/speech.cpp b/sword2/speech.cpp index abaf560955..b2196bcede 100644 --- a/sword2/speech.cpp +++ b/sword2/speech.cpp @@ -1373,7 +1373,7 @@ int32 FN_i_speak(int32 *params) //Tony18Oct96 (revamped by James01july97) // New fudge to wait for smacker samples to finish (James31july97) // since they can over-run into the game - if (GetSpeechStatus()!=RDSE_SAMPLEFINISHED) // has it finished? + if (g_bs2->_sound->GetSpeechStatus()!=RDSE_SAMPLEFINISHED) // has it finished? return (IR_REPEAT); //------------------------- @@ -1584,11 +1584,11 @@ int32 FN_i_speak(int32 *params) //Tony18Oct96 (revamped by James01july97) //------------------------------ - rv = PlayCompSpeech(speechFile, params[S_WAV], SPEECH_VOLUME, speech_pan); // Load speech but don't start playing yet + rv = g_bs2->_sound->PlayCompSpeech(speechFile, params[S_WAV], SPEECH_VOLUME, speech_pan); // Load speech but don't start playing yet if (rv == RD_OK) { speechRunning=1; // ok, we've got something to play (2 means not playing yet - see below) - UnpauseSpeech(); // set it playing now (we might want to do this next cycle, don't know yet) + g_bs2->_sound->UnpauseSpeech(); // set it playing now (we might want to do this next cycle, don't know yet) } #ifdef _BS2_DEBUG else @@ -1628,7 +1628,7 @@ int32 FN_i_speak(int32 *params) //Tony18Oct96 (revamped by James01july97) else if (speechRunning) // if playing a sample { if (!unpause_zone) - { if (AmISpeaking()==RDSE_QUIET) // if we're at a quiet bit + { if (g_bs2->_sound->AmISpeaking()==RDSE_QUIET) // if we're at a quiet bit ob_graphic->anim_pc=0; // restart from frame 0 ('closed mouth' frame) } } @@ -1655,7 +1655,7 @@ int32 FN_i_speak(int32 *params) //Tony18Oct96 (revamped by James01july97) if (speechRunning==1) // if playing a sample (note that value of '2' means about to play!) { if (!unpause_zone) - { if (GetSpeechStatus()==RDSE_SAMPLEFINISHED) // has it finished? + { if (g_bs2->_sound->GetSpeechStatus()==RDSE_SAMPLEFINISHED) // has it finished? speechFinished=1; // James25feb97 } else unpause_zone--; @@ -1704,7 +1704,7 @@ int32 FN_i_speak(int32 *params) //Tony18Oct96 (revamped by James01july97) if (speechRunning) // if speech sample playing { - StopSpeechBS2(); // halt the sample prematurely + g_bs2->_sound->StopSpeechBS2(); // halt the sample prematurely } } } diff --git a/sword2/startup.cpp b/sword2/startup.cpp index 5cb0d9bcf3..4524402deb 100644 --- a/sword2/startup.cpp +++ b/sword2/startup.cpp @@ -290,8 +290,8 @@ uint32 Con_start(uint8 *input) //Tony15Oct96 FN_stop_music(NULL); // fade out any music that is currently playing //--------------------------------------------- - UnpauseSpeech(); - StopSpeechBS2(); // halt the sample prematurely + g_bs2->_sound->UnpauseSpeech(); + g_bs2->_sound->StopSpeechBS2(); // halt the sample prematurely //-------------------------------------------------------------- // clean out all resources & flags, ready for a total restart (James24mar97) diff --git a/sword2/sword2.cpp b/sword2/sword2.cpp index e51aca86c4..288e7f85d0 100644 --- a/sword2/sword2.cpp +++ b/sword2/sword2.cpp @@ -165,7 +165,9 @@ int32 BS2State::InitialiseGame(void) Zdebug("CALLING: Init_event_system"); Init_event_system(); Zdebug("RETURNED."); - + + _sound = new BS2Sound; + Zdebug("CALLING: Init_fx_queue"); Init_fx_queue(); // initialise the sound fx queue Zdebug("RETURNED."); @@ -284,7 +286,7 @@ void BS2State::go() Zdebug("RETURNED."); Zdebug("CALLING: InitialiseSound"); - rv = InitialiseSound(22050, 2, 16); + rv = _sound->InitialiseSound(22050, 2, 16); Zdebug("RETURNED with rv = %.8x", rv); // don't care if this fails, because it should still work without sound cards // but it should set a global system flag so that we can avoid loading sound fx & streaming music diff --git a/sword2/sword2.h b/sword2/sword2.h index 2f13c7bb1c..3488d53b64 100644 --- a/sword2/sword2.h +++ b/sword2/sword2.h @@ -21,6 +21,7 @@ #define _SWORD2 //#include "src\driver96.h" +#include "driver/d_sound.h" #ifdef _PCF76 // Bodge for PCF76 version so that their demo CD can be labelled "PCF76" rather than "RBSII1" @@ -60,6 +61,7 @@ class BS2State : public Engine { GameDetector *_detector; uint32 _features; byte _gameId; + BS2Sound *_sound; private: bool _quit; }; -- cgit v1.2.3