From 3a279a7964823f66b95f62c7de19fb9394925060 Mon Sep 17 00:00:00 2001 From: phoebus118 Date: Thu, 20 Mar 2008 09:55:33 +0000 Subject: [PATCH] Interface added: CMusicHandler::playLodSnd(std::string name). We can play wav data of Heroes3.snd through CMusicHandler::playLodSnd(std::string name) now, where name can be "BASLDFND.wav" or "BASLKILL.wav". --- hch/CMusicHandler.cpp | 24 +++++++++++++++++++++--- hch/CMusicHandler.h | 6 +++--- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/hch/CMusicHandler.cpp b/hch/CMusicHandler.cpp index c605440d9..a962d810e 100644 --- a/hch/CMusicHandler.cpp +++ b/hch/CMusicHandler.cpp @@ -56,7 +56,7 @@ void CMusicHandler::initMusics() click = Mix_LoadWAV("MP3\\snd1.wav"); click->volume = 30; - this->sndPlayer = new CSndPlayer(); + this->sndh = new CSndHandler(std::string("Data\\Heroes3.snd")); } void CMusicHandler::playClick() @@ -69,7 +69,25 @@ void CMusicHandler::playClick() } } -bool CMusicHandler::playLodSnd(std::string sndname) +void CMusicHandler::playLodSnd(std::string sndname) { - return this->sndPlayer->playLodSnd(sndname); + int size; + unsigned char *data; + SDL_RWops *ops; + Mix_Chunk *chunk; + int channel; + + if ((data = sndh->extract(sndname, size)) == NULL) + return; + + ops = SDL_RWFromConstMem(data, size); + chunk = Mix_LoadWAV_RW(ops, 1); + + channel = Mix_PlayChannel(-1, chunk, 0); + if(channel == -1) + { + fprintf(stderr, "Unable to play WAV file(Data\\Heroes3.wav::%s): %s\n", + sndname.c_str(),Mix_GetError()); + } + ops->close(ops); } \ No newline at end of file diff --git a/hch/CMusicHandler.h b/hch/CMusicHandler.h index 56db4ad41..f095d983a 100644 --- a/hch/CMusicHandler.h +++ b/hch/CMusicHandler.h @@ -2,18 +2,18 @@ #define CMUSICHANDLER_H #include "SDL_mixer.h" -#include "CSndPlayer.h" +#include "CSndHandler.h" class CMusicHandler { protected: - CSndPlayer *sndPlayer; + CSndHandler *sndh; public: Mix_Music *AITheme0, *AITheme1, *AITheme2, *combat1, *combat2, *combat3, *combat4, *castleTown, *defendCastle, *dirt, *dungeon, *elemTown, *evilTheme, *fortressTown, *goodTheme, *grass, *infernoTown, *lava, *loopLepr, *loseCampain, *loseCastle, *loseCombat, *mainMenu, *mainMenuWoG, *necroTown, *neutralTheme, *rampart, *retreatBattle, *rough, *sand, *secretTheme, *snow, *stronghold, *surrenderBattle, *swamp, *towerTown, *ultimateLose, *underground, *water, *winScenario, *winBattle; Mix_Chunk * buildTown, *click; void initMusics(); void playClick(); //plays click music ;] - bool playLodSnd(std::string sndname); // plays sound wavs from Heroes3.snd + void playLodSnd(std::string sndname); // plays sound wavs from Heroes3.snd };