From 652aa2ce7c5ae0548ae0ed401a41669101848b25 Mon Sep 17 00:00:00 2001 From: doitux Date: Tue, 18 Dec 2012 15:49:19 +0100 Subject: [PATCH] basic android audio support (#156), support for bigger android screens (#160) --- pokerth_game.pro | 10 +- src/gui/qt/aboutpokerth/aboutpokerthimpl.cpp | 29 ++- .../qt/gui_800x480/settingsdialog_800x480.ui | 72 +++---- src/gui/qt/resources/pokerth_android.qrc | 14 ++ .../qt/settingsdialog/settingsdialogimpl.cpp | 5 +- src/gui/qt/sound/androidaudio.cpp | 181 ++++++++++++++++++ src/gui/qt/sound/androidaudio.h | 53 +++++ src/gui/qt/sound/androidsoundeffect.cpp | 115 +++++++++++ src/gui/qt/sound/androidsoundeffect.h | 37 ++++ src/gui/qt/sound/soundevents.cpp | 32 +++- src/gui/qt/sound/soundevents.h | 17 +- 11 files changed, 510 insertions(+), 55 deletions(-) create mode 100644 src/gui/qt/sound/androidaudio.cpp create mode 100644 src/gui/qt/sound/androidaudio.h create mode 100644 src/gui/qt/sound/androidsoundeffect.cpp create mode 100644 src/gui/qt/sound/androidsoundeffect.h diff --git a/pokerth_game.pro b/pokerth_game.pro index 6b459772..8722ab35 100644 --- a/pokerth_game.pro +++ b/pokerth_game.pro @@ -211,7 +211,9 @@ HEADERS += src/engine/game.h \ src/gui/qt/sound/soundevents.h \ src/gui/qt/mymessagebox/mymessagebox.h \ src/gui/qt/logfiledialog/logfiledialog.h \ - src/gui/qt/logfiledialog/callback.h + src/gui/qt/logfiledialog/callback.h \ + src/gui/qt/sound/androidaudio.h \ + src/gui/qt/sound/androidsoundeffect.h !gui_800x480 { FORMS += src/gui/qt/gametable.ui \ @@ -290,7 +292,9 @@ SOURCES += src/pokerth.cpp \ src/gui/qt/sound/soundevents.cpp \ src/gui/qt/mymessagebox/mymessagebox.cpp \ src/gui/qt/logfiledialog/logfiledialog.cpp \ - src/gui/qt/logfiledialog/callback.cpp + src/gui/qt/logfiledialog/callback.cpp \ + src/gui/qt/sound/androidaudio.cpp \ + src/gui/qt/sound/androidsoundeffect.cpp TRANSLATIONS = ts/pokerth_af.ts \ ts/pokerth_bg.ts \ ts/pokerth_zhcn.ts \ @@ -510,7 +514,7 @@ unix:!mac { LIBS += -ltinyxml LIBS += $$BOOST_LIBS LIBS += -lgsasl -lidn - LIBS += -lssl -lcrypto -lgcrypt -lgpg-error -lprotobuf-lite + LIBS += -lssl -lcrypto -lgcrypt -lgpg-error -lprotobuf-lite -lOpenSLES } TARGETDEPS += ./lib/libpokerth_lib.a \ ./lib/libpokerth_db.a \ diff --git a/src/gui/qt/aboutpokerth/aboutpokerthimpl.cpp b/src/gui/qt/aboutpokerth/aboutpokerthimpl.cpp index 85e8e138..e436979a 100755 --- a/src/gui/qt/aboutpokerth/aboutpokerthimpl.cpp +++ b/src/gui/qt/aboutpokerth/aboutpokerthimpl.cpp @@ -20,6 +20,10 @@ #include "game_defs.h" #include +#ifdef ANDROID + #include + #include +#endif aboutPokerthImpl::aboutPokerthImpl(QWidget *parent, ConfigFile *c) : QDialog(parent), myConfig(c) @@ -64,11 +68,29 @@ aboutPokerthImpl::aboutPokerthImpl(QWidget *parent, ConfigFile *c) label_logo->setPixmap(QPixmap(":/gfx/logoChip3D.png")); #ifdef GUI_800x480 - label_pokerthVersion->setStyleSheet("QLabel { font-size: 30px; font-weight: bold;}"); + label_pokerthVersion->setStyleSheet("QLabel { font-size: 30px; font-weight: bold;}"); #else label_pokerthVersion->setStyleSheet("QLabel { font-size: 16px; font-weight: bold;}"); #endif - label_pokerthVersion->setText(QString(tr("PokerTH %1").arg(POKERTH_BETA_RELEASE_STRING))); + +#ifdef ANDROID + JavaVM *currVM = (JavaVM *)QApplication::platformNativeInterface()->nativeResourceForWidget("JavaVM", 0); + JNIEnv* env; + int api = -2; + if (currVM->AttachCurrentThread(&env, NULL)<0) { + qCritical()<<"AttachCurrentThread failed"; + } + else { + jclass jclassApplicationClass = env->FindClass("android/os/Build$VERSION"); + if (jclassApplicationClass) { + api = env->GetStaticIntField(jclassApplicationClass, env->GetStaticFieldID(jclassApplicationClass,"SDK_INT", "I")); + } + currVM->DetachCurrentThread(); + } + label_pokerthVersion->setText(QString(tr("PokerTH %1 for Android (API%2)").arg(POKERTH_BETA_RELEASE_STRING).arg(api))); +#else + label_pokerthVersion->setText(QString(tr("PokerTH %1").arg(POKERTH_BETA_RELEASE_STRING))); +#endif this->setWindowTitle(QString(tr("About PokerTH %1").arg(POKERTH_BETA_RELEASE_STRING))); //add text to lables and textbrowsers @@ -93,7 +115,8 @@ aboutPokerthImpl::aboutPokerthImpl(QWidget *parent, ConfigFile *c) infoText.append(tr("- Changeable gui with online style gallery")+"\n"); infoText.append(tr("- Online ranking website with result tables")+"\n"); infoText.append("\n"); - infoText.append("(c)2006-2012, Felix Hammer, Florian Thauer, Lothar May"); + QString thisYear = QDate::currentDate().toString("yyyy"); + infoText.append("(c)2006-"+thisYear+", Felix Hammer, Florian Thauer, Lothar May"); label_infotext->setText(infoText); QString projectText; diff --git a/src/gui/qt/gui_800x480/settingsdialog_800x480.ui b/src/gui/qt/gui_800x480/settingsdialog_800x480.ui index 128a614e..4a9cb690 100644 --- a/src/gui/qt/gui_800x480/settingsdialog_800x480.ui +++ b/src/gui/qt/gui_800x480/settingsdialog_800x480.ui @@ -68,7 +68,7 @@ Interface - + :/gfx/preferences-desktop.png:/gfx/preferences-desktop.png @@ -77,7 +77,7 @@ Style - + :/gfx/fill-color.png:/gfx/fill-color.png @@ -86,7 +86,7 @@ Sound - + :/gfx/speaker.png:/gfx/speaker.png @@ -95,7 +95,7 @@ Local Game - + :/gfx/swbuttonlocalgame.png:/gfx/swbuttonlocalgame.png @@ -104,7 +104,7 @@ Network Game - + :/gfx/swbuttonjoinnetworkgame.png:/gfx/swbuttonjoinnetworkgame.png @@ -113,7 +113,7 @@ Internet Game - + :/gfx/swbuttoninternetgame.png:/gfx/swbuttoninternetgame.png @@ -122,7 +122,7 @@ Nicks/Avatars - + :/gfx/system_users.png:/gfx/system_users.png @@ -131,7 +131,7 @@ Log Messages - + :/gfx/utilities-log-viewer.png:/gfx/utilities-log-viewer.png @@ -140,7 +140,7 @@ Factory Settings - + :/gfx/document-revert.png:/gfx/document-revert.png @@ -250,19 +250,6 @@ - - - - Qt::Vertical - - - - 20 - 40 - - - - @@ -313,6 +300,19 @@ + + + + Qt::Vertical + + + + 20 + 40 + + + + @@ -750,7 +750,7 @@ p, li { white-space: pre-wrap; } - + :/gfx/document-open-folder.png:/gfx/document-open-folder.png @@ -836,7 +836,7 @@ p, li { white-space: pre-wrap; } 0 - + Sound Volume: @@ -1999,7 +1999,7 @@ p, li { white-space: pre-wrap; } Standard - + :/gfx/player_play.png:/gfx/player_play.png @@ -2008,7 +2008,7 @@ p, li { white-space: pre-wrap; } Registered players only - + :/gfx/registered.png:/gfx/registered.png @@ -2017,7 +2017,7 @@ p, li { white-space: pre-wrap; } Invited players only - + :/gfx/list_add_user.png:/gfx/list_add_user.png @@ -2026,7 +2026,7 @@ p, li { white-space: pre-wrap; } Ranking game - + :/gfx/cup.png:/gfx/cup.png @@ -2045,7 +2045,7 @@ p, li { white-space: pre-wrap; } Use password for private game: - + :/gfx/lock.png:/gfx/lock.png @@ -2110,7 +2110,7 @@ p, li { white-space: pre-wrap; } Remove Player - + :/gfx/list-remove.png:/gfx/list-remove.png @@ -3620,7 +3620,7 @@ p, li { white-space: pre-wrap; } - + :/gfx/document-open-folder.png:/gfx/document-open-folder.png @@ -3712,7 +3712,7 @@ p, li { white-space: pre-wrap; } Export as HTML - + :/gfx/text-html.png:/gfx/text-html.png @@ -3723,7 +3723,7 @@ p, li { white-space: pre-wrap; } Export as txt - + :/gfx/text-plain.png:/gfx/text-plain.png @@ -3734,7 +3734,7 @@ p, li { white-space: pre-wrap; } Save as ... - + :/gfx/filesave.png:/gfx/filesave.png @@ -3745,7 +3745,7 @@ p, li { white-space: pre-wrap; } Delete - + :/gfx/editdelete.png:/gfx/editdelete.png @@ -4040,7 +4040,7 @@ p, li { white-space: pre-wrap; } buttonBox - + diff --git a/src/gui/qt/resources/pokerth_android.qrc b/src/gui/qt/resources/pokerth_android.qrc index 6e165b0d..a55507d4 100644 --- a/src/gui/qt/resources/pokerth_android.qrc +++ b/src/gui/qt/resources/pokerth_android.qrc @@ -542,6 +542,20 @@ android-data/gfx/cards/default_800x480/51.png android-data/gfx/cards/default_800x480/defaultdeckstyle_800x480.xml android-data/gfx/cards/default_800x480/flipside.png + android-data/sounds/default/allin.wav + android-data/sounds/default/bet.wav + android-data/sounds/default/blinds_raises_level1.wav + android-data/sounds/default/blinds_raises_level2.wav + android-data/sounds/default/blinds_raises_level3.wav + android-data/sounds/default/call.wav + android-data/sounds/default/check.wav + android-data/sounds/default/dealtwocards.wav + android-data/sounds/default/fold.wav + android-data/sounds/default/lobbychatnotify.wav + android-data/sounds/default/onlinegameready.wav + android-data/sounds/default/playerconnected.wav + android-data/sounds/default/raise.wav + android-data/sounds/default/yourturn.wav emotes/face-angel.png diff --git a/src/gui/qt/settingsdialog/settingsdialogimpl.cpp b/src/gui/qt/settingsdialog/settingsdialogimpl.cpp index 872582b7..b4804d51 100644 --- a/src/gui/qt/settingsdialog/settingsdialogimpl.cpp +++ b/src/gui/qt/settingsdialog/settingsdialogimpl.cpp @@ -38,9 +38,10 @@ settingsDialogImpl::settingsDialogImpl(QWidget *parent, ConfigFile *c, selectAva #ifdef ANDROID stackedWidget->removeWidget(page_styles); - stackedWidget->removeWidget(page_sound); - listWidget->takeItem(1); listWidget->takeItem(1); + label_soundvol->hide(); + label_soundVolume->hide(); + horizontalSlider_soundVolume->hide(); #endif myManualBlindsOrderDialog = new manualBlindsOrderDialogImpl; diff --git a/src/gui/qt/sound/androidaudio.cpp b/src/gui/qt/sound/androidaudio.cpp new file mode 100644 index 00000000..1bd81fc7 --- /dev/null +++ b/src/gui/qt/sound/androidaudio.cpp @@ -0,0 +1,181 @@ +#include "androidaudio.h" +#include "androidsoundeffect.h" + +#include + +AndroidAudio::AndroidAudio(QObject *parent) : + QObject(parent), mEngineObject(NULL), mEngineEngine(NULL), mOutputMixObject(NULL), mSounds(), mSoundCount(0), mPlayerObject(NULL) +{ + createEngine(); + startSoundPlayer(); +} + +AndroidAudio::~AndroidAudio() +{ + destroyEngine(); + + for (int32_t i = 0; i < mSoundCount; ++i) { + qDeleteAll(mSounds); + + } +} + +// create the engine and output mix objects +void AndroidAudio::createEngine() +{ + SLresult result; + + // create engine + result = slCreateEngine(&mEngineObject, 0, NULL, 0, NULL, NULL); + Q_ASSERT(SL_RESULT_SUCCESS == result); + + // realize the engine + result = (*mEngineObject)->Realize(mEngineObject, SL_BOOLEAN_FALSE); + Q_ASSERT(SL_RESULT_SUCCESS == result); + + // get the engine interface, which is needed in order to create other objects + result = (*mEngineObject)->GetInterface(mEngineObject, SL_IID_ENGINE, &mEngineEngine); + Q_ASSERT(SL_RESULT_SUCCESS == result); + + // create output mix + const SLInterfaceID ids[] = {}; + const SLboolean req[] = {}; + result = (*mEngineEngine)->CreateOutputMix(mEngineEngine, &mOutputMixObject, 0, ids, req); + Q_ASSERT(SL_RESULT_SUCCESS == result); + + // realize the output mix + result = (*mOutputMixObject)->Realize(mOutputMixObject, SL_BOOLEAN_FALSE); + Q_ASSERT(SL_RESULT_SUCCESS == result); + + qDebug() << "Created Android Audio Engine"; +} + +void AndroidAudio::destroyEngine() +{ + if (mOutputMixObject != NULL) { + (*mOutputMixObject)->Destroy(mOutputMixObject); + } + + if (mEngineObject != NULL) { + (*mEngineObject)->Destroy(mEngineObject); + } + + if (mPlayerObject != NULL) { + (*mPlayerObject)->Destroy(mPlayerObject); + } + + for (int32_t i = 0; i < mSoundCount; ++i) { + mSounds.values().at(i)->unload(); + } + + qDebug() << "Destroyed Android Audio Engine"; +} + +void AndroidAudio::registerSound(const QString& path, const QString& name) +{ + qDebug() << "registerSound:" << path << name; + AndroidSoundEffect *lSound = new AndroidSoundEffect(path, this); + qDebug() << "registerSound:created"; + mSounds[name] = lSound; + + qDebug() << "registerSound:loading"; + lSound->load(); + qDebug() << "registerSound:loaded"; +} + +void AndroidAudio::startSoundPlayer() +{ + qDebug() << "Starting Sound Player"; + + SLresult lRes; + + //Configure the sound player input/output + SLDataLocator_AndroidSimpleBufferQueue lDataLocatorIn; + lDataLocatorIn.locatorType = SL_DATALOCATOR_BUFFERQUEUE; + lDataLocatorIn.numBuffers = 1; + + //Set the data format as mono-pcm-16bit-44100 + SLDataFormat_PCM lDataFormat; + lDataFormat.formatType = SL_DATAFORMAT_PCM; + lDataFormat.numChannels = 2; + lDataFormat.samplesPerSec = SL_SAMPLINGRATE_44_1; + lDataFormat.bitsPerSample = SL_PCMSAMPLEFORMAT_FIXED_16; + lDataFormat.containerSize = SL_PCMSAMPLEFORMAT_FIXED_16; + lDataFormat.channelMask = SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT; + lDataFormat.endianness = SL_BYTEORDER_LITTLEENDIAN; + + SLDataSource lDataSource; + lDataSource.pLocator = &lDataLocatorIn; + lDataSource.pFormat = &lDataFormat; + + SLDataLocator_OutputMix lDataLocatorOut; + lDataLocatorOut.locatorType = SL_DATALOCATOR_OUTPUTMIX; + lDataLocatorOut.outputMix = mOutputMixObject; + + SLDataSink lDataSink; + lDataSink.pLocator = &lDataLocatorOut; + lDataSink.pFormat = NULL; + + //Create the sound player + const SLuint32 lSoundPlayerIIDCount = 2; + const SLInterfaceID lSoundPlayerIIDs[] = { SL_IID_PLAY, SL_IID_BUFFERQUEUE }; + const SLboolean lSoundPlayerReqs[] = { SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE }; + + qDebug() << "Configured Sound Player"; + + lRes = (*mEngineEngine)->CreateAudioPlayer(mEngineEngine, &mPlayerObject, &lDataSource, &lDataSink, lSoundPlayerIIDCount, lSoundPlayerIIDs, lSoundPlayerReqs); + Q_ASSERT(SL_RESULT_SUCCESS == lRes); + + qDebug() << "Created Sound Player"; + + lRes = (*mPlayerObject)->Realize(mPlayerObject, SL_BOOLEAN_FALSE); + Q_ASSERT(SL_RESULT_SUCCESS == lRes); + + qDebug() << "Realised Sound Player"; + lRes = (*mPlayerObject)->GetInterface(mPlayerObject, SL_IID_PLAY, &mPlayerPlay); + Q_ASSERT(SL_RESULT_SUCCESS == lRes); + + lRes = (*mPlayerObject)->GetInterface(mPlayerObject, SL_IID_BUFFERQUEUE, &mPlayerQueue); + Q_ASSERT(SL_RESULT_SUCCESS == lRes); + + lRes = (*mPlayerPlay)->SetPlayState(mPlayerPlay, SL_PLAYSTATE_PLAYING); + Q_ASSERT(SL_RESULT_SUCCESS == lRes); + + qDebug() << "Created Buffer Player"; +} + +void AndroidAudio::playSound(const std::string& name, int i) { + + this->registerSound(QString(":/android/android-data/sounds/default/"+QString::fromStdString(name)+".wav"), QString::fromStdString(name)); + this->reallyPlaySound(QString::fromStdString(name)); +} + +void AndroidAudio::reallyPlaySound(const QString& name) +{ + SLresult lRes; + SLuint32 lPlayerState; + + AndroidSoundEffect* sound = mSounds[name]; + + if (!sound) { + qDebug() << "No such sound:" << name; + return; + } + //Get the current state of the player + (*mPlayerObject)->GetState(mPlayerObject, &lPlayerState); + + //If the player is realised + if (lPlayerState == SL_OBJECT_STATE_REALIZED) { + //Get the buffer and length of the effect + int16_t* lBuffer = (int16_t *)sound->mBuffer; + off_t lLength = sound->mLength; + + //Remove any sound from the queue + lRes = (*mPlayerQueue)->Clear(mPlayerQueue); + Q_ASSERT(SL_RESULT_SUCCESS == lRes); + + //Play the new sound + (*mPlayerQueue)->Enqueue(mPlayerQueue, lBuffer, lLength); + Q_ASSERT(SL_RESULT_SUCCESS == lRes); + } +} diff --git a/src/gui/qt/sound/androidaudio.h b/src/gui/qt/sound/androidaudio.h new file mode 100644 index 00000000..fdcb90fe --- /dev/null +++ b/src/gui/qt/sound/androidaudio.h @@ -0,0 +1,53 @@ +#ifndef ANDROIDAUDIO_H +#define ANDROIDAUDIO_H + +#include +#include + +#include "androidsoundeffect.h" + +// for native audio +#include +#include +#include +#include +#include + +class AndroidAudio : public QObject +{ + Q_OBJECT +public: + explicit AndroidAudio(QObject *parent = 0); + ~AndroidAudio(); + +signals: + +public slots: + + void registerSound(const QString& path, const QString &name); + void reallyPlaySound(const QString& name); + void playSound(const std::string& name, int i); + +private: + void createEngine(); + void destroyEngine(); + void startSoundPlayer(); + + // engine interfaces + SLObjectItf mEngineObject; + SLEngineItf mEngineEngine; + + // output mix interfaces + SLObjectItf mOutputMixObject; + + // buffer queue player interfaces - Effects + SLObjectItf mPlayerObject; + SLPlayItf mPlayerPlay; + SLBufferQueueItf mPlayerQueue; + + QMap mSounds; + int32_t mSoundCount; + +}; + +#endif // ANDROIDAUDIO_H diff --git a/src/gui/qt/sound/androidsoundeffect.cpp b/src/gui/qt/sound/androidsoundeffect.cpp new file mode 100644 index 00000000..3e8b9f73 --- /dev/null +++ b/src/gui/qt/sound/androidsoundeffect.cpp @@ -0,0 +1,115 @@ +#include // need this to get Q_OS_ANDROID #define, which we need before we include anything else! + +#if defined(Q_OS_ANDROID) + +#include "androidsoundeffect.h" +#include + +AndroidSoundEffect::AndroidSoundEffect(const QString& path, QObject *parent) : + QObject(parent), mBuffer(NULL), mLength(0), mPath(path) +{ +} + +AndroidSoundEffect::~AndroidSoundEffect() +{ + this->unload(); +} + +bool AndroidSoundEffect::load() +{ + QFile lSoundFile(mPath); + + qDebug() << "opening:" << mPath; + + if (!lSoundFile.open(QIODevice::ReadOnly)) { + qDebug() << "Could not open: " << mPath; + return false; + } + + // parse WAV file + qDebug() << " reading header:"; + + char id[4]; + lSoundFile.read(id, 4); + if( strncmp(id, "RIFF", 4) != 0 ) { + qDebug() << "not a WAV file - header not RIFF"; + lSoundFile.close(); + return false; + } + + int size = 0; + lSoundFile.read((char *)&size, 4); + qDebug() << " size:" << size; + + lSoundFile.read(id, 4); + if( strncmp(id, "WAVE", 4) != 0 ) { + qDebug() << "not a WAV file - header not WAVE"; + lSoundFile.close(); + return false; + } + + lSoundFile.read(id, 4); // "fmt " + + int format_length = 0; + lSoundFile.read((char *)&format_length, 4); + qDebug() << " format_length:" << format_length; + + short format_tag = 0; + lSoundFile.read((char *)&format_tag, 2); + + short n_channels = 0; + lSoundFile.read((char *)&n_channels, 2); + qDebug() << " n_channels:" << n_channels; + + int sample_rate = 0; + lSoundFile.read((char *)&sample_rate, 4); + qDebug() << " sample_rate:" << sample_rate; + + int avg_bytes_sec = 0; + lSoundFile.read((char *)&avg_bytes_sec, 4); + qDebug() << " avg_bytes_sec:" << avg_bytes_sec; + + short block_align = 0; + lSoundFile.read((char *)&block_align, 2); + + short bits_per_sample = 0; + lSoundFile.read((char *)&bits_per_sample, 2); + qDebug() << " bits_per_sample:" << bits_per_sample; + + lSoundFile.read(id, 4); + if( strncmp(id, "data", 4) != 0 ) { + qDebug() << "not a WAV file - didn't find data"; + lSoundFile.close(); + return false; + } + + lSoundFile.read((char *)&mLength, 4); + + qDebug() << " reading data:" << mLength; + + mBuffer = (char*)malloc((mLength)); + + int dataRead = lSoundFile.read(mBuffer, mLength); + if (dataRead != mLength) { + qDebug() << "didn't read correct amount of data' :" << mPath; + lSoundFile.close(); + delete [] mBuffer; + mBuffer = NULL; + return false; + } + + qDebug() << " closing:"; + lSoundFile.close(); + return true; +} + + +bool AndroidSoundEffect::unload() +{ + delete[] mBuffer; + mBuffer = NULL; + mLength = 0; + return true; +} + +#endif diff --git a/src/gui/qt/sound/androidsoundeffect.h b/src/gui/qt/sound/androidsoundeffect.h new file mode 100644 index 00000000..f1e3667a --- /dev/null +++ b/src/gui/qt/sound/androidsoundeffect.h @@ -0,0 +1,37 @@ +#ifndef ANDROIDSOUNDEFFECT_H +#define ANDROIDSOUNDEFFECT_H + +#include +#include +#include + +#include +#include +#include +#include + +class AndroidSoundEffect : public QObject +{ + Q_OBJECT +public: + explicit AndroidSoundEffect(const QString& pPath, QObject *parent = 0); + ~AndroidSoundEffect(); + + const char* getPath(); + bool load(); + bool unload(); + +signals: + +public slots: + +private: + char* mBuffer; + off_t mLength; + + QString mPath; + + friend class AndroidAudio; +}; + +#endif // ANDROIDSOUNDEFFECT_H diff --git a/src/gui/qt/sound/soundevents.cpp b/src/gui/qt/sound/soundevents.cpp index 7bb1e103..01c1c5d8 100644 --- a/src/gui/qt/sound/soundevents.cpp +++ b/src/gui/qt/sound/soundevents.cpp @@ -1,17 +1,33 @@ -#include "sdlplayer.h" +#include "soundevents.h" + +#ifdef ANDROID + #include "androidaudio.h" +#else + #include "sdlplayer.h" +#endif + + #include "configfile.h" #include "session.h" #include "game.h" -#include "soundevents.h" + +#include +#include SoundEvents::SoundEvents(ConfigFile *c): myConfig(c), lastSBValue(0), lastSBLevel(0), newGameNow(false) { - mySDLPlayer = new SDLPlayer(myConfig); + +#ifdef ANDROID + myPlayer = new AndroidAudio(); +#else + myPlayer = new SDLPlayer(myConfig); +#endif + } SoundEvents::~SoundEvents() { - mySDLPlayer->deleteLater(); + myPlayer->deleteLater(); } void SoundEvents::blindsWereSet(int sB) @@ -29,13 +45,13 @@ void SoundEvents::blindsWereSet(int sB) if(myConfig->readConfigInt("PlayBlindRaiseNotification")) { if(lastSBLevel == 1 || lastSBLevel == 2) { - mySDLPlayer->playSound("blinds_raises_level1", 0); + myPlayer->playSound("blinds_raises_level1", 0); } if(lastSBLevel == 3 || lastSBLevel == 4) { - mySDLPlayer->playSound("blinds_raises_level2", 0); + myPlayer->playSound("blinds_raises_level2", 0); } if(lastSBLevel >= 5) { - mySDLPlayer->playSound("blinds_raises_level3", 0); + myPlayer->playSound("blinds_raises_level3", 0); } } } @@ -49,5 +65,5 @@ void SoundEvents::newGameStarts() //HACK until playSound is done by events void SoundEvents::playSound(std::string audioString, int playerID) { - mySDLPlayer->playSound(audioString, playerID); + myPlayer->playSound(audioString, playerID); } diff --git a/src/gui/qt/sound/soundevents.h b/src/gui/qt/sound/soundevents.h index 24fd9dcc..15980e12 100644 --- a/src/gui/qt/sound/soundevents.h +++ b/src/gui/qt/sound/soundevents.h @@ -3,7 +3,14 @@ #include -class SDLPlayer; + +#ifdef ANDROID + class AndroidAudio; +#else + class SDLPlayer; +#endif + + class ConfigFile; class SoundEvents { @@ -21,9 +28,13 @@ protected: SoundEvents(const SoundEvents &); private: - SDLPlayer *mySDLPlayer; - ConfigFile *myConfig; +#ifdef ANDROID + AndroidAudio *myPlayer; +#else + SDLPlayer *myPlayer; +#endif + ConfigFile *myConfig; int lastSBValue; unsigned int lastSBLevel; bool newGameNow;