From 6e2e3512397774e789f4fe5258a5d805ae8d4c23 Mon Sep 17 00:00:00 2001 From: "wagic.the.homebrew@gmail.com" Date: Thu, 7 Jan 2010 13:56:57 +0000 Subject: [PATCH] Erwan -fix issue 144 --- JGE/include/JSoundSystem.h | 1 + JGE/src/linux/JSfx.cpp | 52 ++++++++++---------------------- JGE/src/win/JSoundSystem_Win.cpp | 32 +++++++++----------- 3 files changed, 32 insertions(+), 53 deletions(-) diff --git a/JGE/include/JSoundSystem.h b/JGE/include/JSoundSystem.h index 1f522c14a..5751818b9 100644 --- a/JGE/include/JSoundSystem.h +++ b/JGE/include/JSoundSystem.h @@ -196,6 +196,7 @@ private: int mVolume; int mMusicVolume; + int mSampleVolume; static JSoundSystem* mInstance; diff --git a/JGE/src/linux/JSfx.cpp b/JGE/src/linux/JSfx.cpp index 06b47d161..eb78c0869 100644 --- a/JGE/src/linux/JSfx.cpp +++ b/JGE/src/linux/JSfx.cpp @@ -74,7 +74,9 @@ void JSoundSystem::Destroy() JSoundSystem::JSoundSystem() { - + mVolume = 0; + mSampleVolume = 0; + mChannel = FSOUND_FREE; } @@ -106,15 +108,6 @@ JMusic *JSoundSystem::LoadMusic(const char *fileName) if (fileSystem->OpenFile(fileName)) { - // FMUSIC is for MOD... - // int size = fileSystem->GetFileSize(); - // char *buffer = new char[size]; - // fileSystem->ReadFile(buffer, size); - // music->mTrack = FMUSIC_LoadSongEx(buffer, 0, size, FSOUND_LOADMEMORY, NULL, 0); - // - // delete[] buffer; - // fileSystem->CloseFile(); - int size = fileSystem->GetFileSize(); char *buffer = new char[size]; fileSystem->ReadFile(buffer, size); @@ -131,15 +124,12 @@ JMusic *JSoundSystem::LoadMusic(const char *fileName) void JSoundSystem::PlayMusic(JMusic *music, bool looping) { - // if (music && music->mTrack) - // { - // FMUSIC_SetLooping(music->mTrack, (looping?1:0)); - // FMUSIC_PlaySong(music->mTrack); - // } + if (music && music->mTrack) { - mChannel = FSOUND_PlaySound(FSOUND_FREE, music->mTrack); + mChannel = FSOUND_PlaySound(mChannel, music->mTrack); + SetMusicVolume(mVolume); if (looping) FSOUND_SetLoopMode(mChannel, FSOUND_LOOP_NORMAL); @@ -166,14 +156,16 @@ void JSoundSystem::SetVolume(int volume){ void JSoundSystem::SetMusicVolume(int volume) { - //TODO Fix to affect only mp3 playback... - FSOUND_SetSFXMasterVolume(volume); - + if (mChannel != FSOUND_FREE) FSOUND_SetVolumeAbsolute(mChannel,volume * 2.55); mVolume = volume; } void JSoundSystem::SetSfxVolume(int volume){ - //TODO + //this sets the volume to all channels then reverts back the volume for music.. + //that's a bit dirty but it works + FSOUND_SetVolumeAbsolute(FSOUND_ALL,volume * 2.55); + mSampleVolume = volume; + SetMusicVolume(mVolume); } @@ -202,23 +194,11 @@ JSample *JSoundSystem::LoadSample(const char *fileName) } -// void JSoundSystem::FreeSample(JSample *sample) -// { -// if (sample) -// { -// if (sample->mSample) -// FSOUND_Sample_Free(sample->mSample); -// -// //delete sample; -// //sample = NULL; -// } -// -// } - - void JSoundSystem::PlaySample(JSample *sample) { - if (sample && sample->mSample) - FSOUND_PlaySound(FSOUND_FREE, sample->mSample); + if (sample && sample->mSample){ + int channel = FSOUND_PlaySound(FSOUND_FREE, sample->mSample); + FSOUND_SetVolumeAbsolute(channel,mSampleVolume * 2.55); + } } diff --git a/JGE/src/win/JSoundSystem_Win.cpp b/JGE/src/win/JSoundSystem_Win.cpp index 4e5b2131b..cd7483276 100644 --- a/JGE/src/win/JSoundSystem_Win.cpp +++ b/JGE/src/win/JSoundSystem_Win.cpp @@ -81,7 +81,9 @@ void JSoundSystem::Destroy() JSoundSystem::JSoundSystem() { - + mVolume = 0; + mSampleVolume = 0; + mChannel = FSOUND_FREE; } @@ -113,15 +115,6 @@ JMusic *JSoundSystem::LoadMusic(const char *fileName) if (fileSystem->OpenFile(fileName)) { - // FMUSIC is for MOD... - // int size = fileSystem->GetFileSize(); - // char *buffer = new char[size]; - // fileSystem->ReadFile(buffer, size); - // music->mTrack = FMUSIC_LoadSongEx(buffer, 0, size, FSOUND_LOADMEMORY, NULL, 0); - // - // delete[] buffer; - // fileSystem->CloseFile(); - int size = fileSystem->GetFileSize(); char *buffer = new char[size]; fileSystem->ReadFile(buffer, size); @@ -142,7 +135,8 @@ void JSoundSystem::PlayMusic(JMusic *music, bool looping) if (music && music->mTrack) { - mChannel = FSOUND_PlaySound(FSOUND_FREE, music->mTrack); + mChannel = FSOUND_PlaySound(mChannel, music->mTrack); + SetMusicVolume(mVolume); if (looping) FSOUND_SetLoopMode(mChannel, FSOUND_LOOP_NORMAL); @@ -167,14 +161,16 @@ void JSoundSystem::SetVolume(int volume) void JSoundSystem::SetMusicVolume(int volume) { - //TODO This function needs to be redone - FSOUND_SetSFXMasterVolume(volume); - + if (mChannel != FSOUND_FREE) FSOUND_SetVolumeAbsolute(mChannel,volume * 2.55); mVolume = volume; } void JSoundSystem::SetSfxVolume(int volume){ - //TODO + //this sets the volume to all channels then reverts back the volume for music.. + //that's a bit dirty but it works + FSOUND_SetVolumeAbsolute(FSOUND_ALL,volume * 2.55); + mSampleVolume = volume; + SetMusicVolume(mVolume); } JSample *JSoundSystem::LoadSample(const char *fileName) @@ -203,7 +199,9 @@ JSample *JSoundSystem::LoadSample(const char *fileName) void JSoundSystem::PlaySample(JSample *sample) { - if (sample && sample->mSample) - FSOUND_PlaySound(FSOUND_FREE, sample->mSample); + if (sample && sample->mSample){ + int channel = FSOUND_PlaySound(FSOUND_FREE, sample->mSample); + FSOUND_SetVolumeAbsolute(channel,mSampleVolume * 2.55); + } }