- Fix issue 144 (Sound is either 0 or 100%), for PSP ONLY. The methods are now here for linux/windows, but only the music volume method will work currently, and it sets the volume globally. Patch by Yeshua with some cleanup by myself.
This commit is contained in:
wagic.the.homebrew@gmail.com
2009-12-12 15:10:32 +00:00
parent f6c4350b38
commit 74accec275
12 changed files with 348 additions and 360 deletions

View File

@@ -1,87 +1,88 @@
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
// //
// JGE is a hardware accelerated 2D game SDK for PSP/Windows. // JGE is a hardware accelerated 2D game SDK for PSP/Windows.
// //
// Licensed under the BSD license, see LICENSE in JGE root for details. // Licensed under the BSD license, see LICENSE in JGE root for details.
// //
// 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>
// Copyright (c) 2007 Cooleyes // Copyright (c) 2007 Cooleyes
// Copyright (c) 2007 Mr.Cheese // Copyright (c) 2007 Mr.Cheese
// //
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
#ifndef _JAUDIO_H_ #ifndef _JAUDIO_H_
#define _JAUDIO_H_ #define _JAUDIO_H_
#include <pspiofilemgr.h> #include <pspiofilemgr.h>
#include <pspaudiolib.h> #include <pspaudiolib.h>
#include <malloc.h> #include <malloc.h>
#include <string.h> #include <string.h>
/////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////
#define PW_REPLAY 0x00000001 // #define PW_REPLAY 0x00000001 //
#define PW_DELAY 0x00000010 // #define PW_DELAY 0x00000010 //
#define PW_FAST 0x00000100 // #define PW_FAST 0x00000100 //
#define PW_PAUSE 0x00001000 // #define PW_PAUSE 0x00001000 //
#define NUMBER_WAV_CHANNELS 3 #define NUMBER_WAV_CHANNELS 3
typedef struct _WAVDATA typedef struct _WAVDATA
{ {
char fullName[256]; // filename char fullName[256]; // filename
unsigned long fileSize; // size of file unsigned long fileSize; // size of file
short headSize; // size of head short headSize; // size of head
unsigned short format; // unsigned short format; //
unsigned short channelCount; // unsigned short channelCount; //
unsigned long samplePerSecond; // unsigned long samplePerSecond; //
unsigned long bytePerSecond; // unsigned long bytePerSecond; //
unsigned short bytePerSample; // unsigned short bytePerSample; //
unsigned long soundSize; // unsigned long soundSize; //
char* buffer; // sound data char* buffer; // sound data
SceUID fd; // file id for streaming SceUID fd; // file id for streaming
unsigned long bytePosition; // current read position unsigned long bytePosition; // current read position
char nSample; // progress rate char nSample; // progress rate
unsigned long sizeStep; // unsigned long sizeStep; //
unsigned long flag; // playback flag unsigned long flag; // playback flag
unsigned long delayTime; // delay time in (us) unsigned long delayTime; // delay time in (us)
} WAVDATA; } WAVDATA;
/////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////
char loadWaveData(WAVDATA* p_wav, char* fileName, char memLoad); char loadWaveData(WAVDATA* p_wav, char* fileName, char memLoad);
void releaseWaveData(WAVDATA* p_wav); void releaseWaveData(WAVDATA* p_wav);
void audioOutCallback(int channel, void* buf, unsigned int length); void audioOutCallback(int channel, void* buf, unsigned int length);
void audioOutCallback_0(void* buf, unsigned int length, void *userdata); void audioOutCallback_0(void* buf, unsigned int length, void *userdata);
void audioOutCallback_1(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_2(void* buf, unsigned int length, void *userdata);
//void audioOutCallback_3(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); char playWaveFile(int channel, char* fullName, unsigned long flag);
void stopWaveFile(int channel); void stopWaveFile(int channel);
int playWaveMem(WAVDATA* p_wav, unsigned long flag); int playWaveMem(WAVDATA* p_wav, unsigned long flag);
void stopWaveMem(int channel); void stopWaveMem(int channel);
void audioInit(); void audioInit();
void audioDestroy(); void audioDestroy();
void setChannelFlag(int channel, int flag); void setChannelFlag(int channel, int flag);
void setPspVolume(int volume);
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
#define DECODING_BUFFER_COUNT 2
#define SAMPLE_PER_FRAME 1152 #define DECODING_BUFFER_COUNT 2
#define MAX_MP3_FILE 2 #define SAMPLE_PER_FRAME 1152
#define MAX_MP3_FILE 2
class JMP3;
class JMP3;
void PlayMP3(JMP3 *mp3, bool looping = false);
void StopMP3(); void PlayMP3(JMP3 *mp3, bool looping = false);
void ResumeMP3(JMP3 *mp3); void StopMP3();
void ResumeMP3(JMP3 *mp3);
void ReleaseMP3Decoder();
void MP3AudioOutCallback(void* buf, unsigned int length, void *userdata); void ReleaseMP3Decoder();
int decodeThread2(SceSize args, void *argp); void MP3AudioOutCallback(void* buf, unsigned int length, void *userdata);
extern bool g_MP3DecoderOK; int decodeThread2(SceSize args, void *argp);
extern bool g_MP3DecoderOK;
#endif
#endif

View File

@@ -1,200 +1,205 @@
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
// //
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows. // JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
// //
// Licensed under the BSD license, see LICENSE in JGE root for details. // Licensed under the BSD license, see LICENSE in JGE root for details.
// //
// 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>
// //
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
#ifndef _JSOUNDSYSTEM_H_ #ifndef _JSOUNDSYSTEM_H_
#define _JSOUNDSYSTEM_H_ #define _JSOUNDSYSTEM_H_
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdarg.h> #include <stdarg.h>
#include "JTypes.h" #include "JTypes.h"
#ifdef WIN32 #ifdef WIN32
#include <windows.h> #include <windows.h>
#elif defined (LINUX) #elif defined (LINUX)
#else #else
#include <pspgu.h> #include <pspgu.h>
#include <pspkernel.h> #include <pspkernel.h>
#include <pspdisplay.h> #include <pspdisplay.h>
#include <pspdebug.h> #include <pspdebug.h>
#include <pspctrl.h> #include <pspctrl.h>
#include <time.h> #include <time.h>
#include <string.h> #include <string.h>
#include <pspaudiolib.h> #include <pspaudiolib.h>
#include <psprtc.h> #include <psprtc.h>
#include "JAudio.h" #include "JAudio.h"
#include "JMP3.h" #include "JMP3.h"
#endif #endif
//------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------
class JMusic class JMusic
{ {
public: public:
JMusic(); JMusic();
~JMusic(); ~JMusic();
void Update(); void Update();
int getPlayTime(); int getPlayTime();
#if defined (WIN32) || defined (LINUX) #if defined (WIN32) || defined (LINUX)
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
JMP3* mTrack; JMP3* mTrack;
#endif #endif
}; };
//------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------
class JSample class JSample
{ {
public: public:
JSample(); JSample();
~JSample(); ~JSample();
int mVoice; int mVoice;
#if defined (WIN32) || defined (LINUX) #if defined (WIN32) || defined (LINUX)
FSOUND_SAMPLE *mSample; FSOUND_SAMPLE *mSample;
#else #else
WAVDATA *mSample; WAVDATA *mSample;
#endif #endif
}; };
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
/// Sound engine for playing sound effects (WAV) and background /// Sound engine for playing sound effects (WAV) and background
/// music (MP3). /// music (MP3).
/// ///
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
class JSoundSystem class JSoundSystem
{ {
public: public:
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
/// Get the singleton instance /// Get the singleton instance
/// ///
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
static JSoundSystem* GetInstance(); static JSoundSystem* GetInstance();
static void Destroy(); static void Destroy();
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
/// Load music. /// Load music.
/// ///
/// @note MP3 is the only supported format for the moment. /// @note MP3 is the only supported format for the moment.
/// ///
/// @param filename - Name of the music file. /// @param filename - Name of the music file.
/// ///
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
JMusic *LoadMusic(const char *fileName); JMusic *LoadMusic(const char *fileName);
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
/// Delete music from memory. /// Delete music from memory.
/// ///
/// @param music - Music to be deleted. /// @param music - Music to be deleted.
/// ///
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
//void FreeMusic(JMusic *music); //void FreeMusic(JMusic *music);
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
/// Play music. /// Play music.
/// ///
/// @param music - Music to be played. /// @param music - Music to be played.
/// @param looping - Play the music in a loop. /// @param looping - Play the music in a loop.
/// ///
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
void PlayMusic(JMusic *music, bool looping = false); void PlayMusic(JMusic *music, bool looping = false);
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
/// Stop playing. /// Stop playing.
/// ///
/// @param music - Music to be stopped. /// @param music - Music to be stopped.
/// ///
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
void StopMusic(JMusic *music); void StopMusic(JMusic *music);
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
/// Resume playing. /// Resume playing.
/// ///
/// @param music - Music to be resumed. /// @param music - Music to be resumed.
/// ///
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
void ResumeMusic(JMusic *music); void ResumeMusic(JMusic *music);
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
/// Load sound effect. /// Load sound effect.
/// ///
/// @note WAV sound effect only. /// @note WAV sound effect only.
/// ///
/// @param fileName - Sound effect for loading. /// @param fileName - Sound effect for loading.
/// ///
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
JSample *LoadSample(const char *fileName); JSample *LoadSample(const char *fileName);
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
/// Delete sound effect from memory. /// Delete sound effect from memory.
/// ///
/// @param sample - Sound to be deleted. /// @param sample - Sound to be deleted.
/// ///
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
//void FreeSample(JSample *sample); //void FreeSample(JSample *sample);
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
/// Play sound effect. /// Play sound effect.
/// ///
/// @param sample - Sound for playing. /// @param sample - Sound for playing.
/// ///
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
void PlaySample(JSample *sample); void PlaySample(JSample *sample);
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
/// Set volume for audio playback. /// Set volume for audio playback.
/// ///
/// @param volume - New volume. /// @param volume - New volume.
/// ///
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
void SetVolume(int volume); void SetVolume(int volume);
int mChannel; void SetMusicVolume(int volume);
protected:
JSoundSystem(); void SetSfxVolume(int volume);
~JSoundSystem();
int mChannel;
void InitSoundSystem(); protected:
void DestroySoundSystem(); JSoundSystem();
~JSoundSystem();
private:
void InitSoundSystem();
#ifdef WIN32 void DestroySoundSystem();
JMusic *mCurrentMusic; private:
#endif #ifdef WIN32
int mVolume; JMusic *mCurrentMusic;
#endif
static JSoundSystem* mInstance;
int mVolume;
}; int mMusicVolume;
#endif
static JSoundSystem* mInstance;
};
#endif

Binary file not shown.

View File

@@ -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 char loadWaveData(WAVDATA* p_wav, char* fileName, char memLoad) // WAVE加载, memLoad-是否加载至内磥E
{ {

View File

@@ -145,9 +145,11 @@ JSample *JSoundSystem::LoadSample(const char *fileName)
void JSoundSystem::PlayMusic(JMusic *music, bool looping) void JSoundSystem::PlayMusic(JMusic *music, bool looping)
{ {
if (music->mTrack) if (music->mTrack)
PlayMP3(music->mTrack, looping); 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); 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; 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);
} }

View File

@@ -129,23 +129,6 @@ JMusic *JSoundSystem::LoadMusic(const char *fileName)
return music; 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) void JSoundSystem::PlayMusic(JMusic *music, bool looping)
{ {
// if (music && music->mTrack) // 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); FSOUND_SetSFXMasterVolume(volume);
mVolume = volume; mVolume = volume;
} }
void JSoundSystem::SetSfxVolume(int volume){
//TODO
}
JSample *JSoundSystem::LoadSample(const char *fileName) JSample *JSoundSystem::LoadSample(const char *fileName)

View File

@@ -136,22 +136,6 @@ JMusic *JSoundSystem::LoadMusic(const char *fileName)
return music; 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) void JSoundSystem::PlayMusic(JMusic *music, bool looping)
{ {
@@ -171,22 +155,27 @@ void JSoundSystem::PlayMusic(JMusic *music, bool looping)
void JSoundSystem::StopMusic(JMusic *music) void JSoundSystem::StopMusic(JMusic *music)
{ {
// if (music && music->mTrack)
// FMUSIC_StopSong(music->mTrack);
FSOUND_StopSound(mChannel); FSOUND_StopSound(mChannel);
} }
void JSoundSystem::SetVolume(int volume) void JSoundSystem::SetVolume(int volume)
{ {
SetMusicVolume(volume);
SetSfxVolume(volume);
}
void JSoundSystem::SetMusicVolume(int volume)
{
//TODO This function needs to be redone
FSOUND_SetSFXMasterVolume(volume); FSOUND_SetSFXMasterVolume(volume);
mVolume = volume; mVolume = volume;
} }
void JSoundSystem::SetSfxVolume(int volume){
//TODO
}
JSample *JSoundSystem::LoadSample(const char *fileName) JSample *JSoundSystem::LoadSample(const char *fileName)
{ {

View File

@@ -116,7 +116,9 @@ void Credits::compute(Player * _p1, Player * _p2, GameApp * _app){
} }
if (unlocked && options[Options::SFXVOLUME].number > 0){ if (unlocked && options[Options::SFXVOLUME].number > 0){
JSample * sample = resources.RetrieveSample("bonus.wav"); JSample * sample = resources.RetrieveSample("bonus.wav");
if (sample) JSoundSystem::GetInstance()->PlaySample(sample); if (sample){
JSoundSystem::GetInstance()->PlaySample(sample);
}
} }
} }

View File

@@ -181,7 +181,9 @@ void GameApp::Create()
mCurrentState = NULL; mCurrentState = NULL;
mNextState = mGameStates[GAME_STATE_MENU]; 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]; char buf[512];
sprintf(buf, "size of MTGCard : %i\n" , sizeof(MTGCard)); sprintf(buf, "size of MTGCard : %i\n" , sizeof(MTGCard));
@@ -246,7 +248,7 @@ void GameApp::Update()
return; 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)){ if (mEngine->GetButtonState(PSP_CTRL_START) && mEngine->GetButtonState(PSP_CTRL_SQUARE)){
JRenderer::Destroy(); JRenderer::Destroy();
} }

View File

@@ -327,7 +327,7 @@ void GameStateDuel::Update(float dt)
if (MusicExist(musictrack)){ if (MusicExist(musictrack)){
GameApp::music = resources.ssLoadMusic(musictrack.c_str()); GameApp::music = resources.ssLoadMusic(musictrack.c_str());
JSoundSystem::GetInstance()->PlayMusic(GameApp::music, true); JSoundSystem::GetInstance()->PlayMusic(GameApp::music, true);
} }
} }
//end of music code //end of music code

View File

@@ -195,6 +195,9 @@ void GameStateOptions::ButtonPressed(int controllerId, int controlId)
switch (controlId){ switch (controlId){
case 1: case 1:
optionsTabs->save(); optionsTabs->save();
//Set Audio volume
JSoundSystem::GetInstance()->SetSfxVolume(options[Options::SFXVOLUME].number);
JSoundSystem::GetInstance()->SetMusicVolume(options[Options::MUSICVOLUME].number);
case 2: case 2:
mParent->SetNextState(GAME_STATE_MENU); mParent->SetNextState(GAME_STATE_MENU);
break; break;

View File

@@ -1090,31 +1090,6 @@ void WGuiMenu::Add(WGuiBase * it){
items.push_back(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){ void WGuiMenu::Update(float dt){
@@ -1238,7 +1213,7 @@ void WGuiTabMenu::Render(){
void WGuiTabMenu::save(){ void WGuiTabMenu::save(){
confirmChange(true); confirmChange(true);
setData(); setData();
::options.save(); ::options.save();
} }