Added Qt Multimedia support in order to replace Phonon. Currently does not work on Mac.
This commit is contained in:
@@ -23,28 +23,32 @@
|
||||
#include "SLES/OpenSLES_Android.h"
|
||||
|
||||
#elif defined USE_PHONON
|
||||
#include <phonon/AudioOutput>
|
||||
#include <phonon/MediaObject>
|
||||
#include <phonon/AudioOutput>
|
||||
#include <phonon/MediaObject>
|
||||
#elif defined WIN32
|
||||
#include <windows.h>
|
||||
#include <windows.h>
|
||||
#define WITH_FMOD
|
||||
#elif defined (PSP)
|
||||
#include <pspgu.h>
|
||||
#include <pspkernel.h>
|
||||
#include <pspdisplay.h>
|
||||
#include <pspdebug.h>
|
||||
#include <pspctrl.h>
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
#include <pspaudiolib.h>
|
||||
#include <psprtc.h>
|
||||
#include <pspgu.h>
|
||||
#include <pspkernel.h>
|
||||
#include <pspdisplay.h>
|
||||
#include <pspdebug.h>
|
||||
#include <pspctrl.h>
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
#include <pspaudiolib.h>
|
||||
#include <psprtc.h>
|
||||
|
||||
#include "JAudio.h"
|
||||
#include "JMP3.h"
|
||||
#include "JAudio.h"
|
||||
#include "JMP3.h"
|
||||
#elif defined QT_CONFIG
|
||||
#include "QMediaPlayer"
|
||||
#include "QMediaPlaylist"
|
||||
#include "QSoundEffect"
|
||||
#endif
|
||||
|
||||
#ifdef WITH_FMOD
|
||||
#include "../Dependencies/include/fmod.h"
|
||||
#include "../Dependencies/include/fmod.h"
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
@@ -67,7 +71,7 @@ public:
|
||||
#ifdef USE_PHONON
|
||||
Phonon::AudioOutput* mOutput;
|
||||
Phonon::MediaObject* mMediaObject;
|
||||
public slots:
|
||||
public slots:
|
||||
void seekAtTheBegining();
|
||||
#elif defined (PSP)
|
||||
JMP3* mTrack;
|
||||
@@ -82,6 +86,10 @@ public:
|
||||
SLPlayItf playInterface;
|
||||
SLSeekItf seekInterface;
|
||||
SLVolumeItf musicVolumeInterface;
|
||||
#elif defined QT_CONFIG
|
||||
QMediaPlaylist* playlist;
|
||||
QMediaPlayer* player;
|
||||
string fullpath;
|
||||
#else
|
||||
void* mTrack;
|
||||
#endif //WITH_FMOD
|
||||
@@ -92,13 +100,15 @@ public:
|
||||
//------------------------------------------------------------------------------------------------
|
||||
class JSample
|
||||
{
|
||||
public:
|
||||
public:
|
||||
JSample();
|
||||
~JSample();
|
||||
|
||||
unsigned long fileSize();
|
||||
|
||||
#if defined (PSP)
|
||||
#ifdef QT_CONFIG
|
||||
QSoundEffect effect;
|
||||
void* mSample;
|
||||
#elif defined (PSP)
|
||||
WAVDATA *mSample;
|
||||
#elif defined (IOS)
|
||||
std::string filename;
|
||||
@@ -133,126 +143,128 @@ class JSoundSystem
|
||||
|
||||
public:
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get the singleton instance
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
static JSoundSystem* GetInstance();
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Get the singleton instance
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
static JSoundSystem* GetInstance();
|
||||
|
||||
static void Destroy();
|
||||
static void Destroy();
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Load music.
|
||||
///
|
||||
/// @note MP3 is the only supported format for the moment.
|
||||
///
|
||||
/// @param filename - Name of the music file.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JMusic *LoadMusic(const char *fileName);
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Load music.
|
||||
///
|
||||
/// @note MP3 is the only supported format for the moment.
|
||||
///
|
||||
/// @param filename - Name of the music file.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JMusic *LoadMusic(const char *fileName);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Delete music from memory.
|
||||
///
|
||||
/// @param music - Music to be deleted.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//void FreeMusic(JMusic *music);
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Delete music from memory.
|
||||
///
|
||||
/// @param music - Music to be deleted.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//void FreeMusic(JMusic *music);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Play music.
|
||||
///
|
||||
/// @param music - Music to be played.
|
||||
/// @param looping - Play the music in a loop.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void PlayMusic(JMusic *music, bool looping = false);
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Play music.
|
||||
///
|
||||
/// @param music - Music to be played.
|
||||
/// @param looping - Play the music in a loop.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void PlayMusic(JMusic *music, bool looping = false);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Stop playing.
|
||||
///
|
||||
/// @param music - Music to be stopped.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void StopMusic(JMusic *music);
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Stop playing.
|
||||
///
|
||||
/// @param music - Music to be stopped.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void StopMusic(JMusic *music);
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Resume playing.
|
||||
///
|
||||
/// @param music - Music to be resumed.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void ResumeMusic(JMusic *music);
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Resume playing.
|
||||
///
|
||||
/// @param music - Music to be resumed.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void ResumeMusic(JMusic *music);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Pause playing.
|
||||
///
|
||||
/// @param music - Music to be paused.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void PauseMusic(JMusic *music);
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Pause playing.
|
||||
///
|
||||
/// @param music - Music to be paused.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void PauseMusic(JMusic *music);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Load sound effect.
|
||||
///
|
||||
/// @note WAV sound effect only.
|
||||
///
|
||||
/// @param fileName - Sound effect for loading.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JSample *LoadSample(const char *fileName);
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Load sound effect.
|
||||
///
|
||||
/// @note WAV sound effect only.
|
||||
///
|
||||
/// @param fileName - Sound effect for loading.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JSample *LoadSample(const char *fileName);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Delete sound effect from memory.
|
||||
///
|
||||
/// @param sample - Sound to be deleted.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//void FreeSample(JSample *sample);
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Delete sound effect from memory.
|
||||
///
|
||||
/// @param sample - Sound to be deleted.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//void FreeSample(JSample *sample);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Play sound effect.
|
||||
///
|
||||
/// @param sample - Sound for playing.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void PlaySample(JSample *sample);
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Play sound effect.
|
||||
///
|
||||
/// @param sample - Sound for playing.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void PlaySample(JSample *sample);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set volume for audio playback.
|
||||
///
|
||||
/// @param volume - New volume.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetVolume(int volume);
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/// Set volume for audio playback.
|
||||
///
|
||||
/// @param volume - New volume.
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void SetVolume(int volume);
|
||||
|
||||
void SetMusicVolume(int volume);
|
||||
void SetMusicVolume(int volume);
|
||||
|
||||
void SetSfxVolume(int volume);
|
||||
void SetSfxVolume(int volume);
|
||||
|
||||
int mChannel;
|
||||
int mChannel;
|
||||
protected:
|
||||
JSoundSystem();
|
||||
~JSoundSystem();
|
||||
JSoundSystem();
|
||||
~JSoundSystem();
|
||||
|
||||
void InitSoundSystem();
|
||||
void DestroySoundSystem();
|
||||
void InitSoundSystem();
|
||||
void DestroySoundSystem();
|
||||
|
||||
private:
|
||||
|
||||
JMusic *mCurrentMusic;
|
||||
#ifdef PSP
|
||||
JMusic *mCurrentMusic;
|
||||
JSample *mCurrentSample;
|
||||
#endif
|
||||
|
||||
int mVolume;
|
||||
int mMusicVolume;
|
||||
int mSampleVolume;
|
||||
int mVolume;
|
||||
int mMusicVolume;
|
||||
int mSampleVolume;
|
||||
|
||||
|
||||
static JSoundSystem* mInstance;
|
||||
static JSoundSystem* mInstance;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
JMusic::JMusic()
|
||||
#ifdef USE_PHONON
|
||||
: mOutput(0), mMediaObject(0)
|
||||
#elif defined QT_CONFIG
|
||||
: playlist(0), player(0)
|
||||
#endif
|
||||
{
|
||||
}
|
||||
@@ -40,7 +42,12 @@ int JMusic::getPlayTime(){
|
||||
|
||||
JMusic::~JMusic()
|
||||
{
|
||||
#ifdef USE_PHONON
|
||||
#ifdef QT_CONFIG
|
||||
if(player)
|
||||
delete player;
|
||||
if(playlist)
|
||||
delete playlist;
|
||||
#elif defined USE_PHONON
|
||||
if(mOutput)
|
||||
delete mOutput;
|
||||
if(mMediaObject)
|
||||
@@ -144,65 +151,88 @@ void JSoundSystem::DestroySoundSystem()
|
||||
|
||||
JMusic *JSoundSystem::LoadMusic(const char *fileName)
|
||||
{
|
||||
#ifdef USE_PHONON
|
||||
JMusic* music = new JMusic();
|
||||
if (music)
|
||||
{
|
||||
music->mOutput = new Phonon::AudioOutput(Phonon::GameCategory, 0);
|
||||
music->mMediaObject = new Phonon::MediaObject(0);
|
||||
string fullpath = JFileSystem::GetInstance()->GetResourceFile(fileName);
|
||||
music->mMediaObject->setCurrentSource(QString(fullpath.c_str()));
|
||||
Phonon::Path mediapath = Phonon::createPath(music->mMediaObject, music->mOutput);
|
||||
Q_ASSERT(mediapath.isValid());
|
||||
}
|
||||
return music;
|
||||
#elif (defined WITH_FMOD)
|
||||
JMusic* music = new JMusic();
|
||||
if (music)
|
||||
JMusic* music = NULL;
|
||||
#ifdef QT_CONFIG
|
||||
music = new JMusic();
|
||||
if (music)
|
||||
{
|
||||
JFileSystem* fileSystem = JFileSystem::GetInstance();
|
||||
if (fileSystem->OpenFile(fileName))
|
||||
{
|
||||
int size = fileSystem->GetFileSize();
|
||||
char *buffer = new char[size];
|
||||
fileSystem->ReadFile(buffer, size);
|
||||
music->mTrack = FSOUND_Sample_Load(FSOUND_UNMANAGED, buffer, FSOUND_LOADMEMORY, 0, size);
|
||||
|
||||
delete[] buffer;
|
||||
fileSystem->CloseFile();
|
||||
}
|
||||
music->player = new QMediaPlayer;
|
||||
music->player->setVolume(100);
|
||||
music->playlist = new QMediaPlaylist;
|
||||
music->fullpath = JFileSystem::GetInstance()->GetResourceFile(fileName);
|
||||
music->playlist->addMedia(QUrl(music->fullpath.c_str()));
|
||||
music->playlist->setCurrentIndex(0);
|
||||
}
|
||||
#elif defined USE_PHONON
|
||||
music = new JMusic();
|
||||
if (music)
|
||||
{
|
||||
music->mOutput = new Phonon::AudioOutput(Phonon::GameCategory, 0);
|
||||
music->mMediaObject = new Phonon::MediaObject(0);
|
||||
string fullpath = JFileSystem::GetInstance()->GetResourceFile(fileName);
|
||||
music->mMediaObject->setCurrentSource(QString(fullpath.c_str()));
|
||||
Phonon::Path mediapath = Phonon::createPath(music->mMediaObject, music->mOutput);
|
||||
Q_ASSERT(mediapath.isValid());
|
||||
}
|
||||
#elif (defined WITH_FMOD)
|
||||
music = new JMusic();
|
||||
if (music)
|
||||
{
|
||||
JFileSystem* fileSystem = JFileSystem::GetInstance();
|
||||
if (fileSystem->OpenFile(fileName))
|
||||
{
|
||||
int size = fileSystem->GetFileSize();
|
||||
char *buffer = new char[size];
|
||||
fileSystem->ReadFile(buffer, size);
|
||||
music->mTrack = FSOUND_Sample_Load(FSOUND_UNMANAGED, buffer, FSOUND_LOADMEMORY, 0, size);
|
||||
|
||||
delete[] buffer;
|
||||
fileSystem->CloseFile();
|
||||
}
|
||||
}
|
||||
return music;
|
||||
#else
|
||||
cerr << fileName << endl;
|
||||
return NULL;
|
||||
#endif
|
||||
return music;
|
||||
}
|
||||
|
||||
|
||||
void JSoundSystem::PlayMusic(JMusic *music, bool looping)
|
||||
{
|
||||
#ifdef USE_PHONON
|
||||
if (music && music->mMediaObject && music->mOutput)
|
||||
{
|
||||
if(looping)
|
||||
#ifdef QT_CONFIG
|
||||
if(music && music->player && music->playlist)
|
||||
{
|
||||
music->mMediaObject->connect(music->mMediaObject, SIGNAL(aboutToFinish()), music, SLOT(seekAtTheBegining()));
|
||||
if(looping)
|
||||
music->playlist->setPlaybackMode(QMediaPlaylist::Loop);
|
||||
|
||||
// music->player->setPlaylist(music->playlist);
|
||||
music->player->setMedia(QUrl(music->fullpath.c_str()));
|
||||
music->player->play();
|
||||
stringstream stream;
|
||||
stream << "Player state : " << music->player->state();
|
||||
DebugTrace(stream.str());
|
||||
}
|
||||
music->mOutput->setVolume((qreal)mVolume*0.01);
|
||||
music->mMediaObject->play();
|
||||
|
||||
}
|
||||
#elif (defined WITH_FMOD)
|
||||
if (music && music->mTrack)
|
||||
#elif USE_PHONON
|
||||
if (music && music->mMediaObject && music->mOutput)
|
||||
{
|
||||
mChannel = FSOUND_PlaySound(mChannel, music->mTrack);
|
||||
SetMusicVolume(mVolume);
|
||||
if(looping)
|
||||
{
|
||||
music->mMediaObject->connect(music->mMediaObject, SIGNAL(aboutToFinish()), music, SLOT(seekAtTheBegining()));
|
||||
}
|
||||
music->mOutput->setVolume((qreal)mVolume*0.01);
|
||||
music->mMediaObject->play();
|
||||
|
||||
if (looping)
|
||||
FSOUND_SetLoopMode(mChannel, FSOUND_LOOP_NORMAL);
|
||||
else
|
||||
FSOUND_SetLoopMode(mChannel, FSOUND_LOOP_OFF);
|
||||
}
|
||||
#elif (defined WITH_FMOD)
|
||||
if (music && music->mTrack)
|
||||
{
|
||||
mChannel = FSOUND_PlaySound(mChannel, music->mTrack);
|
||||
SetMusicVolume(mVolume);
|
||||
|
||||
if (looping)
|
||||
FSOUND_SetLoopMode(mChannel, FSOUND_LOOP_NORMAL);
|
||||
else
|
||||
FSOUND_SetLoopMode(mChannel, FSOUND_LOOP_OFF);
|
||||
}
|
||||
#else
|
||||
music = 0;
|
||||
@@ -213,7 +243,12 @@ void JSoundSystem::PlayMusic(JMusic *music, bool looping)
|
||||
|
||||
void JSoundSystem::StopMusic(JMusic *music)
|
||||
{
|
||||
#ifdef USE_PHONON
|
||||
#ifdef QT_CONFIG
|
||||
if (music && music->player && music->playlist)
|
||||
{
|
||||
music->player->stop();
|
||||
}
|
||||
#elif defined USE_PHONON
|
||||
if (music && music->mMediaObject && music->mOutput)
|
||||
{
|
||||
music->mMediaObject->stop();
|
||||
@@ -264,47 +299,61 @@ void JSoundSystem::SetSfxVolume(int volume){
|
||||
|
||||
JSample *JSoundSystem::LoadSample(const char *fileName)
|
||||
{
|
||||
#if (defined USE_PHONON)
|
||||
JSample* sample = new JSample();
|
||||
if (sample)
|
||||
{
|
||||
sample->mOutput = new Phonon::AudioOutput(Phonon::GameCategory, 0);
|
||||
sample->mMediaObject = new Phonon::MediaObject(0);
|
||||
string fullpath = JFileSystem::GetInstance()->GetResourceFile(fileName);
|
||||
sample->mMediaObject->setCurrentSource(QString(fullpath.c_str()));
|
||||
Phonon::Path mediapath = Phonon::createPath(sample->mMediaObject, sample->mOutput);
|
||||
Q_ASSERT(mediapath.isValid());
|
||||
}
|
||||
return sample;
|
||||
#elif (defined WITH_FMOD)
|
||||
JSample* sample = new JSample();
|
||||
if (sample)
|
||||
JSample* sample = NULL;
|
||||
#ifdef QT_CONFIG
|
||||
sample = new JSample();
|
||||
if (sample)
|
||||
{
|
||||
JFileSystem* fileSystem = JFileSystem::GetInstance();
|
||||
if (fileSystem->OpenFile(fileName))
|
||||
{
|
||||
int size = fileSystem->GetFileSize();
|
||||
char *buffer = new char[size];
|
||||
fileSystem->ReadFile(buffer, size);
|
||||
sample->mSample = FSOUND_Sample_Load(FSOUND_UNMANAGED, buffer, FSOUND_LOADMEMORY, 0, size);
|
||||
string fullpath = JFileSystem::GetInstance()->GetResourceFile(fileName);
|
||||
sample->effect.setSource(QUrl::fromLocalFile(fullpath.c_str()));
|
||||
sample->effect.setLoopCount(0);
|
||||
sample->effect.setVolume(1);
|
||||
sample->mSample = &(sample->effect);
|
||||
}
|
||||
#elif (defined USE_PHONON)
|
||||
sample = new JSample();
|
||||
if (sample)
|
||||
{
|
||||
sample->mOutput = new Phonon::AudioOutput(Phonon::GameCategory, 0);
|
||||
sample->mMediaObject = new Phonon::MediaObject(0);
|
||||
string fullpath = JFileSystem::GetInstance()->GetResourceFile(fileName);
|
||||
sample->mMediaObject->setCurrentSource(QString(fullpath.c_str()));
|
||||
Phonon::Path mediapath = Phonon::createPath(sample->mMediaObject, sample->mOutput);
|
||||
Q_ASSERT(mediapath.isValid());
|
||||
}
|
||||
#elif (defined WITH_FMOD)
|
||||
sample = new JSample();
|
||||
if (sample)
|
||||
{
|
||||
JFileSystem* fileSystem = JFileSystem::GetInstance();
|
||||
if (fileSystem->OpenFile(fileName))
|
||||
{
|
||||
int size = fileSystem->GetFileSize();
|
||||
char *buffer = new char[size];
|
||||
fileSystem->ReadFile(buffer, size);
|
||||
sample->mSample = FSOUND_Sample_Load(FSOUND_UNMANAGED, buffer, FSOUND_LOADMEMORY, 0, size);
|
||||
|
||||
delete[] buffer;
|
||||
fileSystem->CloseFile();
|
||||
}else
|
||||
sample->mSample = NULL;
|
||||
delete[] buffer;
|
||||
fileSystem->CloseFile();
|
||||
}else
|
||||
sample->mSample = NULL;
|
||||
|
||||
}
|
||||
return sample;
|
||||
#else
|
||||
cerr << fileName << endl;
|
||||
return NULL;
|
||||
#endif
|
||||
return sample;
|
||||
}
|
||||
|
||||
|
||||
void JSoundSystem::PlaySample(JSample *sample)
|
||||
{
|
||||
#ifdef USE_PHONON
|
||||
#ifdef QT_CONFIG
|
||||
if(sample)
|
||||
{
|
||||
sample->effect.play();
|
||||
}
|
||||
#elif defined USE_PHONON
|
||||
if (sample && sample->mMediaObject && sample->mOutput)
|
||||
{
|
||||
sample->mOutput->setVolume((qreal)mSampleVolume*0.01);
|
||||
|
||||
Reference in New Issue
Block a user