sdl audio fix
small gui fixes
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
using namespace std;
|
||||
|
||||
SDLPlayer::SDLPlayer()
|
||||
: soundData(NULL), currentChannel(0)
|
||||
: soundData(NULL), currentChannel(0) , audioEnabled(0)
|
||||
{
|
||||
initAudio();
|
||||
}
|
||||
@@ -37,47 +37,56 @@ void SDLPlayer::initAudio() {
|
||||
|
||||
SDL_Init(SDL_INIT_AUDIO);
|
||||
|
||||
if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers) == 0)
|
||||
if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers) == 0) {
|
||||
Mix_QuerySpec(&audio_rate, &audio_format, &audio_channels);
|
||||
audioEnabled = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void SDLPlayer::playSound(string audioString) {
|
||||
|
||||
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);
|
||||
if(audioEnabled) {
|
||||
|
||||
currentChannel = Mix_PlayChannel(-1, sound,0);
|
||||
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);
|
||||
|
||||
}
|
||||
// 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);
|
||||
|
||||
}
|
||||
|
||||
void SDLPlayer::audioDone() {
|
||||
|
||||
Mix_HaltChannel(currentChannel);
|
||||
Mix_FreeChunk(sound);
|
||||
sound = NULL;
|
||||
delete[] soundData;
|
||||
soundData = NULL;
|
||||
if(audioEnabled) {
|
||||
Mix_HaltChannel(currentChannel);
|
||||
Mix_FreeChunk(sound);
|
||||
sound = NULL;
|
||||
delete[] soundData;
|
||||
soundData = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void SDLPlayer::closeAudio() {
|
||||
|
||||
audioDone();
|
||||
Mix_CloseAudio();
|
||||
SDL_Quit();
|
||||
|
||||
if(audioEnabled) {
|
||||
audioDone();
|
||||
Mix_CloseAudio();
|
||||
SDL_Quit();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,6 +50,8 @@ private:
|
||||
Uint8 *soundData;
|
||||
int currentChannel;
|
||||
|
||||
bool audioEnabled;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user