1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-12 02:28:11 +02:00

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".
This commit is contained in:
phoebus118 2008-03-20 09:55:33 +00:00
parent 9c4cb94490
commit 3a279a7964
2 changed files with 24 additions and 6 deletions

View File

@ -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);
}

View File

@ -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
};