This commit is contained in:
+7
-3
@@ -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 \
|
||||
|
||||
@@ -20,6 +20,10 @@
|
||||
#include "game_defs.h"
|
||||
#include <QtCore>
|
||||
|
||||
#ifdef ANDROID
|
||||
#include <QPlatformNativeInterface>
|
||||
#include <jni.h>
|
||||
#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;
|
||||
|
||||
@@ -68,7 +68,7 @@
|
||||
<string>Interface</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources/pokerth_android.qrc">
|
||||
<iconset resource="../resources/pokerth.qrc">
|
||||
<normaloff>:/gfx/preferences-desktop.png</normaloff>:/gfx/preferences-desktop.png</iconset>
|
||||
</property>
|
||||
</item>
|
||||
@@ -77,7 +77,7 @@
|
||||
<string>Style</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources/pokerth_android.qrc">
|
||||
<iconset resource="../resources/pokerth.qrc">
|
||||
<normaloff>:/gfx/fill-color.png</normaloff>:/gfx/fill-color.png</iconset>
|
||||
</property>
|
||||
</item>
|
||||
@@ -86,7 +86,7 @@
|
||||
<string>Sound</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources/pokerth_android.qrc">
|
||||
<iconset resource="../resources/pokerth.qrc">
|
||||
<normaloff>:/gfx/speaker.png</normaloff>:/gfx/speaker.png</iconset>
|
||||
</property>
|
||||
</item>
|
||||
@@ -95,7 +95,7 @@
|
||||
<string>Local Game</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources/pokerth_android.qrc">
|
||||
<iconset resource="../resources/pokerth.qrc">
|
||||
<normaloff>:/gfx/swbuttonlocalgame.png</normaloff>:/gfx/swbuttonlocalgame.png</iconset>
|
||||
</property>
|
||||
</item>
|
||||
@@ -104,7 +104,7 @@
|
||||
<string>Network Game</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources/pokerth_android.qrc">
|
||||
<iconset resource="../resources/pokerth.qrc">
|
||||
<normaloff>:/gfx/swbuttonjoinnetworkgame.png</normaloff>:/gfx/swbuttonjoinnetworkgame.png</iconset>
|
||||
</property>
|
||||
</item>
|
||||
@@ -113,7 +113,7 @@
|
||||
<string>Internet Game</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources/pokerth_android.qrc">
|
||||
<iconset resource="../resources/pokerth.qrc">
|
||||
<normaloff>:/gfx/swbuttoninternetgame.png</normaloff>:/gfx/swbuttoninternetgame.png</iconset>
|
||||
</property>
|
||||
</item>
|
||||
@@ -122,7 +122,7 @@
|
||||
<string>Nicks/Avatars</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources/pokerth_android.qrc">
|
||||
<iconset resource="../resources/pokerth.qrc">
|
||||
<normaloff>:/gfx/system_users.png</normaloff>:/gfx/system_users.png</iconset>
|
||||
</property>
|
||||
</item>
|
||||
@@ -131,7 +131,7 @@
|
||||
<string>Log Messages</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources/pokerth_android.qrc">
|
||||
<iconset resource="../resources/pokerth.qrc">
|
||||
<normaloff>:/gfx/utilities-log-viewer.png</normaloff>:/gfx/utilities-log-viewer.png</iconset>
|
||||
</property>
|
||||
</item>
|
||||
@@ -140,7 +140,7 @@
|
||||
<string>Factory Settings</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources/pokerth_android.qrc">
|
||||
<iconset resource="../resources/pokerth.qrc">
|
||||
<normaloff>:/gfx/document-revert.png</normaloff>:/gfx/document-revert.png</iconset>
|
||||
</property>
|
||||
</item>
|
||||
@@ -250,19 +250,6 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="0">
|
||||
<spacer name="verticalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
@@ -313,6 +300,19 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<spacer name="verticalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="page_styles">
|
||||
@@ -750,7 +750,7 @@ p, li { white-space: pre-wrap; }
|
||||
</size>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources/pokerth_android.qrc">
|
||||
<iconset resource="../resources/pokerth.qrc">
|
||||
<normaloff>:/gfx/document-open-folder.png</normaloff>:/gfx/document-open-folder.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
@@ -836,7 +836,7 @@ p, li { white-space: pre-wrap; }
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_25">
|
||||
<widget class="QLabel" name="label_soundvol">
|
||||
<property name="text">
|
||||
<string>Sound Volume:</string>
|
||||
</property>
|
||||
@@ -1999,7 +1999,7 @@ p, li { white-space: pre-wrap; }
|
||||
<string>Standard</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources/pokerth_android.qrc">
|
||||
<iconset resource="../resources/pokerth.qrc">
|
||||
<normaloff>:/gfx/player_play.png</normaloff>:/gfx/player_play.png</iconset>
|
||||
</property>
|
||||
</item>
|
||||
@@ -2008,7 +2008,7 @@ p, li { white-space: pre-wrap; }
|
||||
<string>Registered players only</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources/pokerth_android.qrc">
|
||||
<iconset resource="../resources/pokerth.qrc">
|
||||
<normaloff>:/gfx/registered.png</normaloff>:/gfx/registered.png</iconset>
|
||||
</property>
|
||||
</item>
|
||||
@@ -2017,7 +2017,7 @@ p, li { white-space: pre-wrap; }
|
||||
<string>Invited players only</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources/pokerth_android.qrc">
|
||||
<iconset resource="../resources/pokerth.qrc">
|
||||
<normaloff>:/gfx/list_add_user.png</normaloff>:/gfx/list_add_user.png</iconset>
|
||||
</property>
|
||||
</item>
|
||||
@@ -2026,7 +2026,7 @@ p, li { white-space: pre-wrap; }
|
||||
<string>Ranking game</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources/pokerth_android.qrc">
|
||||
<iconset resource="../resources/pokerth.qrc">
|
||||
<normaloff>:/gfx/cup.png</normaloff>:/gfx/cup.png</iconset>
|
||||
</property>
|
||||
</item>
|
||||
@@ -2045,7 +2045,7 @@ p, li { white-space: pre-wrap; }
|
||||
<string>Use password for private game:</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources/pokerth_android.qrc">
|
||||
<iconset resource="../resources/pokerth.qrc">
|
||||
<normaloff>:/gfx/lock.png</normaloff>:/gfx/lock.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
@@ -2110,7 +2110,7 @@ p, li { white-space: pre-wrap; }
|
||||
<string>Remove Player</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources/pokerth_android.qrc">
|
||||
<iconset resource="../resources/pokerth.qrc">
|
||||
<normaloff>:/gfx/list-remove.png</normaloff>:/gfx/list-remove.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
@@ -3620,7 +3620,7 @@ p, li { white-space: pre-wrap; }
|
||||
</size>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources/pokerth_android.qrc">
|
||||
<iconset resource="../resources/pokerth.qrc">
|
||||
<normaloff>:/gfx/document-open-folder.png</normaloff>:/gfx/document-open-folder.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
@@ -3712,7 +3712,7 @@ p, li { white-space: pre-wrap; }
|
||||
<string>Export as HTML</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources/pokerth_android.qrc">
|
||||
<iconset resource="../resources/pokerth.qrc">
|
||||
<normaloff>:/gfx/text-html.png</normaloff>:/gfx/text-html.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
@@ -3723,7 +3723,7 @@ p, li { white-space: pre-wrap; }
|
||||
<string>Export as txt</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources/pokerth_android.qrc">
|
||||
<iconset resource="../resources/pokerth.qrc">
|
||||
<normaloff>:/gfx/text-plain.png</normaloff>:/gfx/text-plain.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
@@ -3734,7 +3734,7 @@ p, li { white-space: pre-wrap; }
|
||||
<string>Save as ...</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources/pokerth_android.qrc">
|
||||
<iconset resource="../resources/pokerth.qrc">
|
||||
<normaloff>:/gfx/filesave.png</normaloff>:/gfx/filesave.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
@@ -3745,7 +3745,7 @@ p, li { white-space: pre-wrap; }
|
||||
<string>Delete</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources/pokerth_android.qrc">
|
||||
<iconset resource="../resources/pokerth.qrc">
|
||||
<normaloff>:/gfx/editdelete.png</normaloff>:/gfx/editdelete.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
@@ -4040,7 +4040,7 @@ p, li { white-space: pre-wrap; }
|
||||
<tabstop>buttonBox</tabstop>
|
||||
</tabstops>
|
||||
<resources>
|
||||
<include location="../resources/pokerth_android.qrc"/>
|
||||
<include location="../resources/pokerth.qrc"/>
|
||||
</resources>
|
||||
<connections>
|
||||
<connection>
|
||||
|
||||
@@ -542,6 +542,20 @@
|
||||
<file>android-data/gfx/cards/default_800x480/51.png</file>
|
||||
<file>android-data/gfx/cards/default_800x480/defaultdeckstyle_800x480.xml</file>
|
||||
<file>android-data/gfx/cards/default_800x480/flipside.png</file>
|
||||
<file>android-data/sounds/default/allin.wav</file>
|
||||
<file>android-data/sounds/default/bet.wav</file>
|
||||
<file>android-data/sounds/default/blinds_raises_level1.wav</file>
|
||||
<file>android-data/sounds/default/blinds_raises_level2.wav</file>
|
||||
<file>android-data/sounds/default/blinds_raises_level3.wav</file>
|
||||
<file>android-data/sounds/default/call.wav</file>
|
||||
<file>android-data/sounds/default/check.wav</file>
|
||||
<file>android-data/sounds/default/dealtwocards.wav</file>
|
||||
<file>android-data/sounds/default/fold.wav</file>
|
||||
<file>android-data/sounds/default/lobbychatnotify.wav</file>
|
||||
<file>android-data/sounds/default/onlinegameready.wav</file>
|
||||
<file>android-data/sounds/default/playerconnected.wav</file>
|
||||
<file>android-data/sounds/default/raise.wav</file>
|
||||
<file>android-data/sounds/default/yourturn.wav</file>
|
||||
</qresource>
|
||||
<qresource prefix="/emotes">
|
||||
<file>emotes/face-angel.png</file>
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -0,0 +1,181 @@
|
||||
#include "androidaudio.h"
|
||||
#include "androidsoundeffect.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
#ifndef ANDROIDAUDIO_H
|
||||
#define ANDROIDAUDIO_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QMap>
|
||||
|
||||
#include "androidsoundeffect.h"
|
||||
|
||||
// for native audio
|
||||
#include <jni.h>
|
||||
#include <SLES/OpenSLES.h>
|
||||
#include <SLES/OpenSLES_Android.h>
|
||||
#include <android/asset_manager.h>
|
||||
#include <android/asset_manager_jni.h>
|
||||
|
||||
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<QString, AndroidSoundEffect*> mSounds;
|
||||
int32_t mSoundCount;
|
||||
|
||||
};
|
||||
|
||||
#endif // ANDROIDAUDIO_H
|
||||
@@ -0,0 +1,115 @@
|
||||
#include <QtGlobal> // 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 <QFile>
|
||||
|
||||
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
|
||||
@@ -0,0 +1,37 @@
|
||||
#ifndef ANDROIDSOUNDEFFECT_H
|
||||
#define ANDROIDSOUNDEFFECT_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QDebug>
|
||||
#include <QString>
|
||||
|
||||
#include <SLES/OpenSLES.h>
|
||||
#include <SLES/OpenSLES_Android.h>
|
||||
#include <android/asset_manager.h>
|
||||
#include <android/asset_manager_jni.h>
|
||||
|
||||
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
|
||||
@@ -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 <QtCore>
|
||||
#include <QtGui>
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,14 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user