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
actionLabelArray[playerID]->setPixmap(QPixmap(":/actions/resources/graphics/actions/action_"+actionArray[playerAction]+".png"));
//play sounds if exist
mySDLPlayer->playSound(actionArray[playerAction].toStdString());
}
if (playerAction == 1) {
@@ -1063,10 +1066,6 @@ void mainWindowImpl::refreshAction(int playerID, int playerAction) {
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;
SDLPlayer::SDLPlayer():QObject()
SDLPlayer::SDLPlayer()
: currentChannel(0), soundData(NULL)
{
currentChannel = 0;
initAudio();
}
SDLPlayer::~SDLPlayer()
{
closeAudio();
}
void SDLPlayer::initAudio() {
@@ -43,27 +43,26 @@ void SDLPlayer::initAudio() {
void SDLPlayer::playSound(string audioString) {
// QFile myFile(":sounds/resources/sounds/"+QString::fromStdString(audioString)+".wav");
// if(myFile.open(QIODevice::ReadOnly)) {
//
// audioDone();
//
// QDataStream in(&myFile);
// Uint8 *myMem = new Uint8[(int)myFile.size()];
// in.readRawData( (char*)myMem, (int)myFile.size() );
//
// sound = Mix_QuickLoad_WAV( myMem );
//
// currentChannel = Mix_PlayChannel(-1, sound,0);
//
// delete[] myMem;
// }
// else cout << "could not load " << audioString << ".wav" << endl;
QFile myFile(":sounds/resources/sounds/"+QString::fromStdString(audioString)+".wav");
if(myFile.open(QIODevice::ReadOnly)) {
audioDone();
QDataStream in(&myFile);
soundData = new Uint8[(int)myFile.size()];
in.readRawData( (char*)soundData, (int)myFile.size() );
sound = Mix_QuickLoad_WAV(soundData);
currentChannel = Mix_PlayChannel(-1, sound,0);
}
else cout << "could not load " << audioString << ".wav" << endl;
//test
audioDone();
sound = Mix_LoadWAV( QString(QString::fromStdString(audioString)+QString(".wav")).toStdString().c_str() );
currentChannel = Mix_PlayChannel(-1, sound,0);
// audioDone();
// sound = Mix_LoadWAV( QString(QString::fromStdString(audioString)+QString(".wav")).toStdString().c_str() );
// currentChannel = Mix_PlayChannel(-1, sound,0);
}
@@ -72,13 +71,13 @@ void SDLPlayer::audioDone() {
Mix_HaltChannel(currentChannel);
Mix_FreeChunk(sound);
sound = NULL;
delete[] soundData;
soundData = NULL;
}
void SDLPlayer::closeAudio() {
Mix_HaltChannel(currentChannel);
Mix_FreeChunk(sound);
sound = NULL;
audioDone();
Mix_CloseAudio();
SDL_Quit();
}
+1
View File
@@ -47,6 +47,7 @@ private:
int audio_channels;
int audio_buffers;
Mix_Chunk *sound;
Uint8 *soundData;
int currentChannel;
};