J :
* This update has Wagic compile and work under Darwin 64-bits.
- Linux 64-bits is expected to compile and work from now on, but
was not tested. As with before, Linux 64 bits can still run
the 32 bits version.
- Darwin version is not using Carbon but X emulation.
- 64-bits versions have no sound because there is no 64-bits
version of fmod.
- Windows 64-bits probably does not compile. Windows 64-bits can
still run the 32 bits version.
- Darwin 32-bits probably does not work at the moment because the
libfmod requires another name to work on Macs, but as 64-bits
disables it it works.
- Other unix flavors are expected to work as long as they have
a working OpenGL library, X11, and *either* 64-bits *or* a
working fmod. Thus in the practice Tru64, Irix and the like
probably work, as should FreeBSD and other BSDs in 64 bits
versions, but 32 bits versions will search for a non-existing
fmod. All of this is pure conjecture and none was tested.
- All 64-bits versions have no sound.
- The mac version does not display the particles at the moment.
This is not critical, but the cause is unknown yet. I would
like to know if other 64 bits unices share the same bug or if
it is mac-specific.
* Test is needed in particular to see whether the program still
compiles and works in Linux and PSP. Windows is probably all
right, but compiling PSP in windows may be broken by this
update.
This commit is contained in:
@@ -8,8 +8,12 @@
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#include "../../Dependencies/include/png.h"
|
||||
|
||||
#ifdef WITH_FMOD
|
||||
#include "../../Dependencies/include/fmod.h"
|
||||
#else
|
||||
#define FSOUND_FREE 0
|
||||
#endif
|
||||
|
||||
#include "../../include/JSoundSystem.h"
|
||||
#include "../../include/JFileSystem.h"
|
||||
@@ -25,16 +29,19 @@ void JMusic::Update(){
|
||||
}
|
||||
|
||||
int JMusic::getPlayTime(){
|
||||
#ifdef WITH_FMOD
|
||||
return FSOUND_GetCurrentPosition(JSoundSystem::GetInstance()->mChannel)/44.1; //todo more generic, here it's only 44kHz
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
JMusic::~JMusic()
|
||||
{
|
||||
JSoundSystem::GetInstance()->StopMusic(this);
|
||||
//JSoundSystem::GetInstance()->FreeMusic(this);
|
||||
|
||||
if (mTrack)
|
||||
FSOUND_Sample_Free(mTrack);
|
||||
#ifdef WITH_FMOD
|
||||
JSoundSystem::GetInstance()->StopMusic(this);
|
||||
if (mTrack) FSOUND_Sample_Free(mTrack);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -46,162 +53,172 @@ JSample::JSample()
|
||||
|
||||
JSample::~JSample()
|
||||
{
|
||||
//JSoundSystem::GetInstance()->FreeSample(this);
|
||||
if (mSample)
|
||||
FSOUND_Sample_Free(mSample);
|
||||
#ifdef WITH_FMOD
|
||||
if (mSample) FSOUND_Sample_Free(mSample);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JSoundSystem* JSoundSystem::mInstance = NULL;
|
||||
|
||||
|
||||
JSoundSystem* JSoundSystem::GetInstance()
|
||||
{
|
||||
if (mInstance == NULL)
|
||||
{
|
||||
mInstance = new JSoundSystem();
|
||||
mInstance->InitSoundSystem();
|
||||
}
|
||||
|
||||
return mInstance;
|
||||
if (mInstance == NULL)
|
||||
{
|
||||
mInstance = new JSoundSystem();
|
||||
mInstance->InitSoundSystem();
|
||||
}
|
||||
return mInstance;
|
||||
}
|
||||
|
||||
|
||||
void JSoundSystem::Destroy()
|
||||
{
|
||||
if (mInstance)
|
||||
{
|
||||
mInstance->DestroySoundSystem();
|
||||
delete mInstance;
|
||||
mInstance = NULL;
|
||||
}
|
||||
if (mInstance)
|
||||
{
|
||||
mInstance->DestroySoundSystem();
|
||||
delete mInstance;
|
||||
mInstance = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
JSoundSystem::JSoundSystem()
|
||||
{
|
||||
mVolume = 0;
|
||||
mVolume = 0;
|
||||
mSampleVolume = 0;
|
||||
mChannel = FSOUND_FREE;
|
||||
}
|
||||
|
||||
|
||||
JSoundSystem::~JSoundSystem()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void JSoundSystem::InitSoundSystem()
|
||||
{
|
||||
FSOUND_Init(44100, 32, 0);
|
||||
#ifdef WITH_FMOD
|
||||
FSOUND_Init(44100, 32, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void JSoundSystem::DestroySoundSystem()
|
||||
{
|
||||
FSOUND_Close();
|
||||
|
||||
#ifdef WITH_FMOD
|
||||
FSOUND_Close();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
JMusic *JSoundSystem::LoadMusic(const char *fileName)
|
||||
{
|
||||
JMusic* music = new JMusic();
|
||||
if (music)
|
||||
#ifndef WITH_FMOD
|
||||
return NULL;
|
||||
#elif
|
||||
JMusic* music = new JMusic();
|
||||
if (music)
|
||||
{
|
||||
JFileSystem* fileSystem = JFileSystem::GetInstance();
|
||||
if (fileSystem->OpenFile(fileName))
|
||||
{
|
||||
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);
|
||||
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();
|
||||
}
|
||||
|
||||
delete[] buffer;
|
||||
fileSystem->CloseFile();
|
||||
}
|
||||
|
||||
return music;
|
||||
}
|
||||
return music;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void JSoundSystem::PlayMusic(JMusic *music, bool looping)
|
||||
{
|
||||
|
||||
if (music && music->mTrack)
|
||||
{
|
||||
mChannel = FSOUND_PlaySound(mChannel, music->mTrack);
|
||||
SetMusicVolume(mVolume);
|
||||
#ifdef 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);
|
||||
|
||||
}
|
||||
if (looping)
|
||||
FSOUND_SetLoopMode(mChannel, FSOUND_LOOP_NORMAL);
|
||||
else
|
||||
FSOUND_SetLoopMode(mChannel, FSOUND_LOOP_OFF);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void JSoundSystem::StopMusic(JMusic *music)
|
||||
{
|
||||
FSOUND_StopSound(mChannel);
|
||||
#ifdef WITH_FMOD
|
||||
FSOUND_StopSound(mChannel);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void JSoundSystem::SetVolume(int volume)
|
||||
{
|
||||
SetMusicVolume(volume);
|
||||
SetSfxVolume(volume);
|
||||
SetMusicVolume(volume);
|
||||
SetSfxVolume(volume);
|
||||
}
|
||||
|
||||
void JSoundSystem::SetMusicVolume(int volume)
|
||||
{
|
||||
if (mChannel != FSOUND_FREE) FSOUND_SetVolumeAbsolute(mChannel,volume * 2.55);
|
||||
mVolume = volume;
|
||||
#ifdef WITH_FMOD
|
||||
if (mChannel != FSOUND_FREE) FSOUND_SetVolumeAbsolute(mChannel,volume * 2.55);
|
||||
#endif
|
||||
mVolume = volume;
|
||||
}
|
||||
|
||||
void JSoundSystem::SetSfxVolume(int volume){
|
||||
//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);
|
||||
//that's a bit dirty but it works
|
||||
#ifdef WITH_FMOD
|
||||
FSOUND_SetVolumeAbsolute(FSOUND_ALL, volume * 2.55);
|
||||
#endif
|
||||
mSampleVolume = volume;
|
||||
SetMusicVolume(mVolume);
|
||||
}
|
||||
|
||||
JSample *JSoundSystem::LoadSample(const char *fileName)
|
||||
{
|
||||
JSample* sample = new JSample();
|
||||
if (sample)
|
||||
#ifndef WITH_FMOD
|
||||
return NULL;
|
||||
#else
|
||||
JSample* sample = new JSample();
|
||||
if (sample)
|
||||
{
|
||||
JFileSystem* fileSystem = JFileSystem::GetInstance();
|
||||
if (fileSystem->OpenFile(fileName))
|
||||
{
|
||||
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;
|
||||
|
||||
}
|
||||
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);
|
||||
|
||||
return sample;
|
||||
delete[] buffer;
|
||||
fileSystem->CloseFile();
|
||||
}else
|
||||
sample->mSample = NULL;
|
||||
|
||||
}
|
||||
return sample;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void JSoundSystem::PlaySample(JSample *sample)
|
||||
{
|
||||
#ifdef WITH_FMOD
|
||||
if (sample && sample->mSample){
|
||||
int channel = FSOUND_PlaySound(FSOUND_FREE, sample->mSample);
|
||||
int channel = FSOUND_PlaySound(FSOUND_FREE, sample->mSample);
|
||||
FSOUND_SetVolumeAbsolute(channel,mSampleVolume * 2.55);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user