Fixed Phonon sound support.

This commit is contained in:
Xawotihs
2011-07-19 21:28:46 +00:00
parent 262c31b708
commit e09fe7570e
2 changed files with 28 additions and 53 deletions

View File

@@ -18,7 +18,6 @@
#include "JTypes.h" #include "JTypes.h"
#ifdef USE_PHONON #ifdef USE_PHONON
#include <phonon/AudioOutput> #include <phonon/AudioOutput>
#include <phonon/MediaObject> #include <phonon/MediaObject>
@@ -68,20 +67,14 @@ public:
public slots: public slots:
void seekAtTheBegining(); void seekAtTheBegining();
#else #elif defined (PSP)
#if defined (PSP)
JMP3* mTrack; JMP3* mTrack;
#else #elif defined WITH_FMOD
#ifdef WITH_FMOD
FSOUND_SAMPLE* mTrack; // MP3 needed to be of "sample" type for FMOD, FMUSIC_MODULE is for MODs FSOUND_SAMPLE* mTrack; // MP3 needed to be of "sample" type for FMOD, FMUSIC_MODULE is for MODs
#else #else
void* mTrack; void* mTrack;
#endif //WITH_FMOD #endif //WITH_FMOD
#endif //PSP
#endif //USE_PHONON
}; };
@@ -92,23 +85,17 @@ class JSample
JSample(); JSample();
~JSample(); ~JSample();
int mVoice;
unsigned long fileSize(); unsigned long fileSize();
#if defined (PSP) #if defined (PSP)
WAVDATA *mSample; WAVDATA *mSample;
#else #elif defined (WITH_FMOD)
#ifdef WITH_FMOD
FSOUND_SAMPLE *mSample; FSOUND_SAMPLE *mSample;
#else #elif defined (USE_PHONON)
#ifdef USE_PHONON
Phonon::AudioOutput* mOutput; Phonon::AudioOutput* mOutput;
Phonon::MediaObject* mMediaObject; Phonon::MediaObject* mMediaObject;
#endif //USE_PHONON #endif
void* mSample; void* mSample;
#endif //WITH_FMOD
#endif //PSP
}; };

View File

@@ -7,6 +7,7 @@
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com> // Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
// //
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
#include "DebugRoutines.h"
#ifdef WITH_FMOD #ifdef WITH_FMOD
#include "../../Dependencies/include/fmod.h" #include "../../Dependencies/include/fmod.h"
@@ -17,7 +18,6 @@
#include "../../include/JSoundSystem.h" #include "../../include/JSoundSystem.h"
#include "../../include/JFileSystem.h" #include "../../include/JFileSystem.h"
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
JMusic::JMusic() JMusic::JMusic()
#ifdef USE_PHONON #ifdef USE_PHONON
@@ -45,12 +45,10 @@ JMusic::~JMusic()
delete mOutput; delete mOutput;
if(mMediaObject) if(mMediaObject)
delete mMediaObject; delete mMediaObject;
#else #elif defined WITH_FMOD
#ifdef WITH_FMOD
JSoundSystem::GetInstance()->StopMusic(this); JSoundSystem::GetInstance()->StopMusic(this);
if (mTrack) FSOUND_Sample_Free(mTrack); if (mTrack) FSOUND_Sample_Free(mTrack);
#endif #endif
#endif
} }
#ifdef USE_PHONON #ifdef USE_PHONON
@@ -76,11 +74,9 @@ JSample::~JSample()
delete mOutput; delete mOutput;
if(mMediaObject) if(mMediaObject)
delete mMediaObject; delete mMediaObject;
#else #elif (defined WITH_FMOD)
#ifdef WITH_FMOD
if (mSample) FSOUND_Sample_Free(mSample); if (mSample) FSOUND_Sample_Free(mSample);
#endif #endif
#endif
} }
unsigned long JSample::fileSize() unsigned long JSample::fileSize()
@@ -154,15 +150,13 @@ JMusic *JSoundSystem::LoadMusic(const char *fileName)
{ {
music->mOutput = new Phonon::AudioOutput(Phonon::GameCategory, 0); music->mOutput = new Phonon::AudioOutput(Phonon::GameCategory, 0);
music->mMediaObject = new Phonon::MediaObject(0); music->mMediaObject = new Phonon::MediaObject(0);
music->mMediaObject->setCurrentSource("Res/" + QString(fileName)); string fullpath = JFileSystem::GetInstance()->GetResourceFile(fileName);
Phonon::Path path = Phonon::createPath(music->mMediaObject, music->mOutput); music->mMediaObject->setCurrentSource(QString(fullpath.c_str()));
Q_ASSERT(path.isValid()); Phonon::Path mediapath = Phonon::createPath(music->mMediaObject, music->mOutput);
Q_ASSERT(mediapath.isValid());
} }
return music; return music;
#else #elif (defined WITH_FMOD)
#ifndef WITH_FMOD
return NULL;
#else
JMusic* music = new JMusic(); JMusic* music = new JMusic();
if (music) if (music)
{ {
@@ -179,7 +173,8 @@ JMusic *JSoundSystem::LoadMusic(const char *fileName)
} }
} }
return music; return music;
#endif #else
return NULL;
#endif #endif
} }
@@ -197,8 +192,7 @@ void JSoundSystem::PlayMusic(JMusic *music, bool looping)
music->mMediaObject->play(); music->mMediaObject->play();
} }
#else #elif (defined WITH_FMOD)
#ifdef WITH_FMOD
if (music && music->mTrack) if (music && music->mTrack)
{ {
mChannel = FSOUND_PlaySound(mChannel, music->mTrack); mChannel = FSOUND_PlaySound(mChannel, music->mTrack);
@@ -210,7 +204,6 @@ void JSoundSystem::PlayMusic(JMusic *music, bool looping)
FSOUND_SetLoopMode(mChannel, FSOUND_LOOP_OFF); FSOUND_SetLoopMode(mChannel, FSOUND_LOOP_OFF);
} }
#endif #endif
#endif
} }
@@ -221,11 +214,9 @@ void JSoundSystem::StopMusic(JMusic *music)
{ {
music->mMediaObject->stop(); music->mMediaObject->stop();
} }
#else #elif (defined WITH_FMOD)
#ifdef WITH_FMOD
FSOUND_StopSound(mChannel); FSOUND_StopSound(mChannel);
#endif #endif
#endif
} }
@@ -255,21 +246,19 @@ void JSoundSystem::SetSfxVolume(int volume){
JSample *JSoundSystem::LoadSample(const char *fileName) JSample *JSoundSystem::LoadSample(const char *fileName)
{ {
#ifdef USE_PHONON #if (defined USE_PHONON)
JSample* sample = new JSample(); JSample* sample = new JSample();
if (sample) if (sample)
{ {
sample->mOutput = new Phonon::AudioOutput(Phonon::GameCategory, 0); sample->mOutput = new Phonon::AudioOutput(Phonon::GameCategory, 0);
sample->mMediaObject = new Phonon::MediaObject(0); sample->mMediaObject = new Phonon::MediaObject(0);
sample->mMediaObject->setCurrentSource("Res/" + QString(fileName)); string fullpath = JFileSystem::GetInstance()->GetResourceFile(fileName);
Phonon::Path path = Phonon::createPath(sample->mMediaObject, sample->mOutput); sample->mMediaObject->setCurrentSource(QString(fullpath.c_str()));
Q_ASSERT(path.isValid()); Phonon::Path mediapath = Phonon::createPath(sample->mMediaObject, sample->mOutput);
Q_ASSERT(mediapath.isValid());
} }
return sample; return sample;
#else #elif (defined WITH_FMOD)
#ifndef WITH_FMOD
return NULL;
#else
JSample* sample = new JSample(); JSample* sample = new JSample();
if (sample) if (sample)
{ {
@@ -288,7 +277,8 @@ JSample *JSoundSystem::LoadSample(const char *fileName)
} }
return sample; return sample;
#endif #else
return NULL;
#endif #endif
} }
@@ -301,13 +291,11 @@ void JSoundSystem::PlaySample(JSample *sample)
sample->mOutput->setVolume((qreal)mSampleVolume*0.01); sample->mOutput->setVolume((qreal)mSampleVolume*0.01);
sample->mMediaObject->play(); sample->mMediaObject->play();
} }
#else #elif (defined WITH_FMOD)
#ifdef WITH_FMOD
if (sample && sample->mSample){ if (sample && sample->mSample){
int channel = FSOUND_PlaySound(FSOUND_FREE, sample->mSample); int channel = FSOUND_PlaySound(FSOUND_FREE, sample->mSample);
FSOUND_SetVolumeAbsolute(channel, static_cast<int>(mSampleVolume * 2.55)); FSOUND_SetVolumeAbsolute(channel, static_cast<int>(mSampleVolume * 2.55));
} }
#endif #endif
#endif
} }