Fixed sound using streams.

This commit is contained in:
lotodore
2007-06-03 10:03:54 +00:00
parent 2623d43290
commit 03bffdbc76
3 changed files with 28 additions and 29 deletions
+3 -4
View File
@@ -1053,6 +1053,9 @@ void mainWindowImpl::refreshAction(int playerID, int playerAction) {
// paint action pixmap and raise // paint action pixmap and raise
actionLabelArray[playerID]->setPixmap(QPixmap(":/actions/resources/graphics/actions/action_"+actionArray[playerAction]+".png")); actionLabelArray[playerID]->setPixmap(QPixmap(":/actions/resources/graphics/actions/action_"+actionArray[playerAction]+".png"));
//play sounds if exist
mySDLPlayer->playSound(actionArray[playerAction].toStdString());
} }
if (playerAction == 1) { if (playerAction == 1) {
@@ -1063,10 +1066,6 @@ void mainWindowImpl::refreshAction(int playerID, int playerAction) {
holeCardsArray[playerID][1]->setPixmap(onePix, FALSE); holeCardsArray[playerID][1]->setPixmap(onePix, FALSE);
} }
} }
//play sounds if exist
mySDLPlayer->playSound(actionArray[playerAction].toStdString());
} }
} }
+24 -25
View File
@@ -15,16 +15,16 @@
using namespace std; using namespace std;
SDLPlayer::SDLPlayer():QObject() SDLPlayer::SDLPlayer()
: currentChannel(0), soundData(NULL)
{ {
currentChannel = 0;
initAudio(); initAudio();
} }
SDLPlayer::~SDLPlayer() SDLPlayer::~SDLPlayer()
{ {
closeAudio();
} }
void SDLPlayer::initAudio() { void SDLPlayer::initAudio() {
@@ -43,27 +43,26 @@ void SDLPlayer::initAudio() {
void SDLPlayer::playSound(string audioString) { void SDLPlayer::playSound(string audioString) {
// QFile myFile(":sounds/resources/sounds/"+QString::fromStdString(audioString)+".wav"); QFile myFile(":sounds/resources/sounds/"+QString::fromStdString(audioString)+".wav");
// if(myFile.open(QIODevice::ReadOnly)) {
// if(myFile.open(QIODevice::ReadOnly)) {
// audioDone();
// audioDone();
// QDataStream in(&myFile);
// Uint8 *myMem = new Uint8[(int)myFile.size()]; QDataStream in(&myFile);
// in.readRawData( (char*)myMem, (int)myFile.size() ); soundData = new Uint8[(int)myFile.size()];
// in.readRawData( (char*)soundData, (int)myFile.size() );
// sound = Mix_QuickLoad_WAV( myMem );
// sound = Mix_QuickLoad_WAV(soundData);
// currentChannel = Mix_PlayChannel(-1, sound,0);
// currentChannel = Mix_PlayChannel(-1, sound,0);
// delete[] myMem; }
// } else cout << "could not load " << audioString << ".wav" << endl;
// else cout << "could not load " << audioString << ".wav" << endl;
//test //test
audioDone(); // audioDone();
sound = Mix_LoadWAV( QString(QString::fromStdString(audioString)+QString(".wav")).toStdString().c_str() ); // sound = Mix_LoadWAV( QString(QString::fromStdString(audioString)+QString(".wav")).toStdString().c_str() );
currentChannel = Mix_PlayChannel(-1, sound,0); // currentChannel = Mix_PlayChannel(-1, sound,0);
} }
@@ -72,13 +71,13 @@ void SDLPlayer::audioDone() {
Mix_HaltChannel(currentChannel); Mix_HaltChannel(currentChannel);
Mix_FreeChunk(sound); Mix_FreeChunk(sound);
sound = NULL; sound = NULL;
delete[] soundData;
soundData = NULL;
} }
void SDLPlayer::closeAudio() { void SDLPlayer::closeAudio() {
Mix_HaltChannel(currentChannel); audioDone();
Mix_FreeChunk(sound);
sound = NULL;
Mix_CloseAudio(); Mix_CloseAudio();
SDL_Quit(); SDL_Quit();
} }
+1
View File
@@ -47,6 +47,7 @@ private:
int audio_channels; int audio_channels;
int audio_buffers; int audio_buffers;
Mix_Chunk *sound; Mix_Chunk *sound;
Uint8 *soundData;
int currentChannel; int currentChannel;
}; };