diff --git a/JGE/include/JAudio.h b/JGE/include/JAudio.h index 4530b0c62..ebbb89d77 100644 --- a/JGE/include/JAudio.h +++ b/JGE/include/JAudio.h @@ -1,87 +1,88 @@ -//------------------------------------------------------------------------------------- -// -// JGE is a hardware accelerated 2D game SDK for PSP/Windows. -// -// Licensed under the BSD license, see LICENSE in JGE root for details. -// -// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) -// Copyright (c) 2007 Cooleyes -// Copyright (c) 2007 Mr.Cheese -// -//------------------------------------------------------------------------------------- - -#ifndef _JAUDIO_H_ -#define _JAUDIO_H_ - - -#include -#include -#include -#include - - -/////////////////////////////////////////////////////////////////// -#define PW_REPLAY 0x00000001 // -#define PW_DELAY 0x00000010 // -#define PW_FAST 0x00000100 // -#define PW_PAUSE 0x00001000 // - -#define NUMBER_WAV_CHANNELS 3 - -typedef struct _WAVDATA -{ - char fullName[256]; // filename - unsigned long fileSize; // size of file - short headSize; // size of head - unsigned short format; // - unsigned short channelCount; // - unsigned long samplePerSecond; // - unsigned long bytePerSecond; // - unsigned short bytePerSample; // - unsigned long soundSize; // - char* buffer; // sound data - SceUID fd; // file id for streaming - unsigned long bytePosition; // current read position - char nSample; // progress rate - unsigned long sizeStep; // - unsigned long flag; // playback flag - unsigned long delayTime; // delay time in (us) - -} WAVDATA; - - -/////////////////////////////////////////////////////////////////// -char loadWaveData(WAVDATA* p_wav, char* fileName, char memLoad); -void releaseWaveData(WAVDATA* p_wav); -void audioOutCallback(int channel, void* buf, unsigned int length); -void audioOutCallback_0(void* buf, unsigned int length, void *userdata); -void audioOutCallback_1(void* buf, unsigned int length, void *userdata); -void audioOutCallback_2(void* buf, unsigned int length, void *userdata); -//void audioOutCallback_3(void* buf, unsigned int length, void *userdata); -char playWaveFile(int channel, char* fullName, unsigned long flag); -void stopWaveFile(int channel); -int playWaveMem(WAVDATA* p_wav, unsigned long flag); -void stopWaveMem(int channel); -void audioInit(); -void audioDestroy(); -void setChannelFlag(int channel, int flag); - -////////////////////////////////////////////////////////////////////////// - - -#define DECODING_BUFFER_COUNT 2 -#define SAMPLE_PER_FRAME 1152 -#define MAX_MP3_FILE 2 - -class JMP3; - -void PlayMP3(JMP3 *mp3, bool looping = false); -void StopMP3(); -void ResumeMP3(JMP3 *mp3); - -void ReleaseMP3Decoder(); -void MP3AudioOutCallback(void* buf, unsigned int length, void *userdata); -int decodeThread2(SceSize args, void *argp); -extern bool g_MP3DecoderOK; - -#endif +//------------------------------------------------------------------------------------- +// +// JGE is a hardware accelerated 2D game SDK for PSP/Windows. +// +// Licensed under the BSD license, see LICENSE in JGE root for details. +// +// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) +// Copyright (c) 2007 Cooleyes +// Copyright (c) 2007 Mr.Cheese +// +//------------------------------------------------------------------------------------- + +#ifndef _JAUDIO_H_ +#define _JAUDIO_H_ + + +#include +#include +#include +#include + + +/////////////////////////////////////////////////////////////////// +#define PW_REPLAY 0x00000001 // +#define PW_DELAY 0x00000010 // +#define PW_FAST 0x00000100 // +#define PW_PAUSE 0x00001000 // + +#define NUMBER_WAV_CHANNELS 3 + +typedef struct _WAVDATA +{ + char fullName[256]; // filename + unsigned long fileSize; // size of file + short headSize; // size of head + unsigned short format; // + unsigned short channelCount; // + unsigned long samplePerSecond; // + unsigned long bytePerSecond; // + unsigned short bytePerSample; // + unsigned long soundSize; // + char* buffer; // sound data + SceUID fd; // file id for streaming + unsigned long bytePosition; // current read position + char nSample; // progress rate + unsigned long sizeStep; // + unsigned long flag; // playback flag + unsigned long delayTime; // delay time in (us) + +} WAVDATA; + + +/////////////////////////////////////////////////////////////////// +char loadWaveData(WAVDATA* p_wav, char* fileName, char memLoad); +void releaseWaveData(WAVDATA* p_wav); +void audioOutCallback(int channel, void* buf, unsigned int length); +void audioOutCallback_0(void* buf, unsigned int length, void *userdata); +void audioOutCallback_1(void* buf, unsigned int length, void *userdata); +void audioOutCallback_2(void* buf, unsigned int length, void *userdata); +//void audioOutCallback_3(void* buf, unsigned int length, void *userdata); +char playWaveFile(int channel, char* fullName, unsigned long flag); +void stopWaveFile(int channel); +int playWaveMem(WAVDATA* p_wav, unsigned long flag); +void stopWaveMem(int channel); +void audioInit(); +void audioDestroy(); +void setChannelFlag(int channel, int flag); +void setPspVolume(int volume); + +////////////////////////////////////////////////////////////////////////// + + +#define DECODING_BUFFER_COUNT 2 +#define SAMPLE_PER_FRAME 1152 +#define MAX_MP3_FILE 2 + +class JMP3; + +void PlayMP3(JMP3 *mp3, bool looping = false); +void StopMP3(); +void ResumeMP3(JMP3 *mp3); + +void ReleaseMP3Decoder(); +void MP3AudioOutCallback(void* buf, unsigned int length, void *userdata); +int decodeThread2(SceSize args, void *argp); +extern bool g_MP3DecoderOK; + +#endif diff --git a/JGE/include/JSoundSystem.h b/JGE/include/JSoundSystem.h index 5167132c7..1f522c14a 100644 --- a/JGE/include/JSoundSystem.h +++ b/JGE/include/JSoundSystem.h @@ -1,200 +1,205 @@ -//------------------------------------------------------------------------------------- -// -// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows. -// -// Licensed under the BSD license, see LICENSE in JGE root for details. -// -// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) -// -//------------------------------------------------------------------------------------- - -#ifndef _JSOUNDSYSTEM_H_ -#define _JSOUNDSYSTEM_H_ - -#include -#include -#include -#include - -#include "JTypes.h" - - -#ifdef WIN32 - - #include -#elif defined (LINUX) -#else - - #include - #include - #include - #include - #include - #include - #include - #include - #include - - #include "JAudio.h" - #include "JMP3.h" - -#endif - - -//------------------------------------------------------------------------------------------------ -class JMusic -{ -public: - JMusic(); - ~JMusic(); - void Update(); - int getPlayTime(); - -#if defined (WIN32) || defined (LINUX) - FSOUND_SAMPLE *mTrack; // MP3 needed to be of "sample" type for FMOD, FMUSIC_MODULE is for MODs -#else - JMP3* mTrack; -#endif - -}; - - -//------------------------------------------------------------------------------------------------ -class JSample -{ -public: - JSample(); - ~JSample(); - - int mVoice; - -#if defined (WIN32) || defined (LINUX) - FSOUND_SAMPLE *mSample; -#else - WAVDATA *mSample; -#endif -}; - - -////////////////////////////////////////////////////////////////////////// -/// Sound engine for playing sound effects (WAV) and background -/// music (MP3). -/// -////////////////////////////////////////////////////////////////////////// -class JSoundSystem -{ - -public: - - ////////////////////////////////////////////////////////////////////////// - /// Get the singleton instance - /// - ////////////////////////////////////////////////////////////////////////// - static JSoundSystem* GetInstance(); - - 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); - - ////////////////////////////////////////////////////////////////////////// - /// 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); - - ////////////////////////////////////////////////////////////////////////// - /// Stop playing. - /// - /// @param music - Music to be stopped. - /// - ////////////////////////////////////////////////////////////////////////// - void StopMusic(JMusic *music); - - - ////////////////////////////////////////////////////////////////////////// - /// Resume playing. - /// - /// @param music - Music to be resumed. - /// - ////////////////////////////////////////////////////////////////////////// - void ResumeMusic(JMusic *music); - - ////////////////////////////////////////////////////////////////////////// - /// 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); - - ////////////////////////////////////////////////////////////////////////// - /// 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); - - int mChannel; -protected: - JSoundSystem(); - ~JSoundSystem(); - - void InitSoundSystem(); - void DestroySoundSystem(); - -private: - -#ifdef WIN32 - - JMusic *mCurrentMusic; - -#endif - - int mVolume; - - - static JSoundSystem* mInstance; - -}; - -#endif +//------------------------------------------------------------------------------------- +// +// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows. +// +// Licensed under the BSD license, see LICENSE in JGE root for details. +// +// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) +// +//------------------------------------------------------------------------------------- + +#ifndef _JSOUNDSYSTEM_H_ +#define _JSOUNDSYSTEM_H_ + +#include +#include +#include +#include + +#include "JTypes.h" + + +#ifdef WIN32 + + #include +#elif defined (LINUX) +#else + + #include + #include + #include + #include + #include + #include + #include + #include + #include + + #include "JAudio.h" + #include "JMP3.h" + +#endif + + +//------------------------------------------------------------------------------------------------ +class JMusic +{ +public: + JMusic(); + ~JMusic(); + void Update(); + int getPlayTime(); + +#if defined (WIN32) || defined (LINUX) + FSOUND_SAMPLE *mTrack; // MP3 needed to be of "sample" type for FMOD, FMUSIC_MODULE is for MODs +#else + JMP3* mTrack; +#endif + +}; + + +//------------------------------------------------------------------------------------------------ +class JSample +{ +public: + JSample(); + ~JSample(); + + int mVoice; + +#if defined (WIN32) || defined (LINUX) + FSOUND_SAMPLE *mSample; +#else + WAVDATA *mSample; +#endif +}; + + +////////////////////////////////////////////////////////////////////////// +/// Sound engine for playing sound effects (WAV) and background +/// music (MP3). +/// +////////////////////////////////////////////////////////////////////////// +class JSoundSystem +{ + +public: + + ////////////////////////////////////////////////////////////////////////// + /// Get the singleton instance + /// + ////////////////////////////////////////////////////////////////////////// + static JSoundSystem* GetInstance(); + + 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); + + ////////////////////////////////////////////////////////////////////////// + /// 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); + + ////////////////////////////////////////////////////////////////////////// + /// Stop playing. + /// + /// @param music - Music to be stopped. + /// + ////////////////////////////////////////////////////////////////////////// + void StopMusic(JMusic *music); + + + ////////////////////////////////////////////////////////////////////////// + /// Resume playing. + /// + /// @param music - Music to be resumed. + /// + ////////////////////////////////////////////////////////////////////////// + void ResumeMusic(JMusic *music); + + ////////////////////////////////////////////////////////////////////////// + /// 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); + + ////////////////////////////////////////////////////////////////////////// + /// 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); + + void SetMusicVolume(int volume); + + void SetSfxVolume(int volume); + + int mChannel; +protected: + JSoundSystem(); + ~JSoundSystem(); + + void InitSoundSystem(); + void DestroySoundSystem(); + +private: + +#ifdef WIN32 + + JMusic *mCurrentMusic; + +#endif + + int mVolume; + int mMusicVolume; + + + static JSoundSystem* mInstance; + +}; + +#endif diff --git a/JGE/lib/win/jge.lib b/JGE/lib/win/jge.lib index 4f101ef23..98c6d66ea 100644 Binary files a/JGE/lib/win/jge.lib and b/JGE/lib/win/jge.lib differ diff --git a/JGE/src/JAudio.cpp b/JGE/src/JAudio.cpp index dbd7c52f2..234afdeed 100644 --- a/JGE/src/JAudio.cpp +++ b/JGE/src/JAudio.cpp @@ -38,6 +38,13 @@ WAVDATA currentWav[NUMBER_WAV_CHANNELS]; // 各通道当前的播放 /////////////////////////////////////////////////////////////////// +void setPspVolume(int volume) +{ + pspAudioSetVolume(0, volume, volume); + pspAudioSetVolume(1, volume, volume); + pspAudioSetVolume(2, volume, volume); +} + char loadWaveData(WAVDATA* p_wav, char* fileName, char memLoad) // WAVE加载, memLoad-是否加载至内磥E { diff --git a/JGE/src/JSfx.cpp b/JGE/src/JSfx.cpp index c7f9bfddf..7df04b5b6 100644 --- a/JGE/src/JSfx.cpp +++ b/JGE/src/JSfx.cpp @@ -145,9 +145,11 @@ JSample *JSoundSystem::LoadSample(const char *fileName) void JSoundSystem::PlayMusic(JMusic *music, bool looping) { - if (music->mTrack) PlayMP3(music->mTrack, looping); + JMP3 * mp3 = JMP3::mInstance; + if (mp3) mp3->setVolume((mMusicVolume * .01) *0x8000); + } @@ -157,11 +159,22 @@ void JSoundSystem::PlaySample(JSample *sample) playWaveMem(sample->mSample, 0); } +void JSoundSystem::SetVolume(int volume){ + SetMusicVolume(volume); + SetSfxVolume(volume); +} -void JSoundSystem::SetVolume(int volume) +void JSoundSystem::SetMusicVolume(int volume) { + mMusicVolume = volume; JMP3 * mp3 = JMP3::mInstance; - if (mp3) mp3->setVolume(volume); + if (mp3) mp3->setVolume((mMusicVolume * .01) *0x8000); +} + +void JSoundSystem::SetSfxVolume(int volume) +{ + setPspVolume((volume * .01) *0x8000); + } diff --git a/JGE/src/linux/JSfx.cpp b/JGE/src/linux/JSfx.cpp index 8d88deb37..06b47d161 100644 --- a/JGE/src/linux/JSfx.cpp +++ b/JGE/src/linux/JSfx.cpp @@ -129,23 +129,6 @@ JMusic *JSoundSystem::LoadMusic(const char *fileName) return music; } -// void JSoundSystem::FreeMusic(JMusic *music) -// { -// if (music) -// { -// // if (music->mTrack) -// // FMUSIC_FreeSong(music->mTrack); -// // delete music; -// // music = NULL; -// -// if (music->mTrack) -// FSOUND_Sample_Free(music->mTrack); -// -// //delete music; -// //music = NULL; -// } -// } - void JSoundSystem::PlayMusic(JMusic *music, bool looping) { // if (music && music->mTrack) @@ -176,14 +159,22 @@ void JSoundSystem::StopMusic(JMusic *music __attribute__((unused))) } -void JSoundSystem::SetVolume(int volume) +void JSoundSystem::SetVolume(int volume){ + SetMusicVolume(volume); + SetSfxVolume(volume); +} + +void JSoundSystem::SetMusicVolume(int volume) { + //TODO Fix to affect only mp3 playback... FSOUND_SetSFXMasterVolume(volume); mVolume = volume; } - +void JSoundSystem::SetSfxVolume(int volume){ + //TODO +} JSample *JSoundSystem::LoadSample(const char *fileName) diff --git a/JGE/src/win/JSoundSystem_Win.cpp b/JGE/src/win/JSoundSystem_Win.cpp index a7c01a2e6..4e5b2131b 100644 --- a/JGE/src/win/JSoundSystem_Win.cpp +++ b/JGE/src/win/JSoundSystem_Win.cpp @@ -136,22 +136,6 @@ JMusic *JSoundSystem::LoadMusic(const char *fileName) return music; } -// void JSoundSystem::FreeMusic(JMusic *music) -// { -// if (music) -// { -// // if (music->mTrack) -// // FMUSIC_FreeSong(music->mTrack); -// // delete music; -// // music = NULL; -// -// if (music->mTrack) -// FSOUND_Sample_Free(music->mTrack); -// -// //delete music; -// //music = NULL; -// } -// } void JSoundSystem::PlayMusic(JMusic *music, bool looping) { @@ -171,22 +155,27 @@ void JSoundSystem::PlayMusic(JMusic *music, bool looping) void JSoundSystem::StopMusic(JMusic *music) { - // if (music && music->mTrack) - // FMUSIC_StopSong(music->mTrack); - FSOUND_StopSound(mChannel); } void JSoundSystem::SetVolume(int volume) { + SetMusicVolume(volume); + SetSfxVolume(volume); +} + +void JSoundSystem::SetMusicVolume(int volume) +{ + //TODO This function needs to be redone FSOUND_SetSFXMasterVolume(volume); mVolume = volume; } - - +void JSoundSystem::SetSfxVolume(int volume){ + //TODO +} JSample *JSoundSystem::LoadSample(const char *fileName) { diff --git a/projects/mtg/src/Credits.cpp b/projects/mtg/src/Credits.cpp index e0b9a8cb7..187777974 100644 --- a/projects/mtg/src/Credits.cpp +++ b/projects/mtg/src/Credits.cpp @@ -116,7 +116,9 @@ void Credits::compute(Player * _p1, Player * _p2, GameApp * _app){ } if (unlocked && options[Options::SFXVOLUME].number > 0){ JSample * sample = resources.RetrieveSample("bonus.wav"); - if (sample) JSoundSystem::GetInstance()->PlaySample(sample); + if (sample){ + JSoundSystem::GetInstance()->PlaySample(sample); + } } } diff --git a/projects/mtg/src/GameApp.cpp b/projects/mtg/src/GameApp.cpp index f38fcab0a..98dd44cc6 100644 --- a/projects/mtg/src/GameApp.cpp +++ b/projects/mtg/src/GameApp.cpp @@ -181,7 +181,9 @@ void GameApp::Create() mCurrentState = NULL; mNextState = mGameStates[GAME_STATE_MENU]; - // effect = NEW CardEffect(); + //Set Audio volume + JSoundSystem::GetInstance()->SetSfxVolume(options[Options::SFXVOLUME].number); + JSoundSystem::GetInstance()->SetMusicVolume(options[Options::MUSICVOLUME].number); char buf[512]; sprintf(buf, "size of MTGCard : %i\n" , sizeof(MTGCard)); @@ -246,7 +248,7 @@ void GameApp::Update() return; } - //Restart Rendering engine when START and TRIANGLE ARE PRESSED SIMULTANEOUSLY + //Restart Rendering engine when START and SQUARE ARE PRESSED SIMULTANEOUSLY if (mEngine->GetButtonState(PSP_CTRL_START) && mEngine->GetButtonState(PSP_CTRL_SQUARE)){ JRenderer::Destroy(); } diff --git a/projects/mtg/src/GameStateDuel.cpp b/projects/mtg/src/GameStateDuel.cpp index 76b5aa172..11d46f824 100644 --- a/projects/mtg/src/GameStateDuel.cpp +++ b/projects/mtg/src/GameStateDuel.cpp @@ -327,7 +327,7 @@ void GameStateDuel::Update(float dt) if (MusicExist(musictrack)){ GameApp::music = resources.ssLoadMusic(musictrack.c_str()); - JSoundSystem::GetInstance()->PlayMusic(GameApp::music, true); + JSoundSystem::GetInstance()->PlayMusic(GameApp::music, true); } } //end of music code diff --git a/projects/mtg/src/GameStateOptions.cpp b/projects/mtg/src/GameStateOptions.cpp index 185272f3a..f0ea6b4c2 100644 --- a/projects/mtg/src/GameStateOptions.cpp +++ b/projects/mtg/src/GameStateOptions.cpp @@ -195,6 +195,9 @@ void GameStateOptions::ButtonPressed(int controllerId, int controlId) switch (controlId){ case 1: optionsTabs->save(); + //Set Audio volume + JSoundSystem::GetInstance()->SetSfxVolume(options[Options::SFXVOLUME].number); + JSoundSystem::GetInstance()->SetMusicVolume(options[Options::MUSICVOLUME].number); case 2: mParent->SetNextState(GAME_STATE_MENU); break; diff --git a/projects/mtg/src/OptionItem.cpp b/projects/mtg/src/OptionItem.cpp index f560e8392..304b7451e 100644 --- a/projects/mtg/src/OptionItem.cpp +++ b/projects/mtg/src/OptionItem.cpp @@ -1090,31 +1090,6 @@ void WGuiMenu::Add(WGuiBase * it){ items.push_back(it); } -//WGuiMenu -/* -void WGuiMenu::Update(float dt){ - JGE * mEngine = JGE::GetInstance(); - - WGuiBase * c = Current(); - if(c && !c->isModal()){ - if (mEngine->GetButtonClick(buttonPrev)){ - if (currentItem > 0 && c->Leaving(buttonPrev)){ - currentItem--; - c = Current(); - c->Entering(buttonPrev); - } - } - else if (mEngine->GetButtonClick(buttonNext)){ - if (currentItem < (int)items.size()-1 && c->Leaving(buttonNext)){ - currentItem++; - c = Current(); - c->Entering(buttonNext); - } - } - } - if(c) - c->Update(dt); -}*/ void WGuiMenu::Update(float dt){ @@ -1238,7 +1213,7 @@ void WGuiTabMenu::Render(){ void WGuiTabMenu::save(){ confirmChange(true); - setData(); + setData(); ::options.save(); }