diff options
author | Maarten Gribnau <mail@maartengribnau.com> | 2002-11-05 00:50:33 +0300 |
---|---|---|
committer | Maarten Gribnau <mail@maartengribnau.com> | 2002-11-05 00:50:33 +0300 |
commit | bd39a84c8b22c69017cfd05bf7c0d063b8a62ff1 (patch) | |
tree | 841705fa0cb2c7c4cfeb06226db637114b7ef066 /intern/SoundSystem | |
parent | c458cc73102e920e54bc1f997fc8d3f16c9eb34d (diff) |
Added fmod sound for OSX and fixed some endian problems in
gameengine/SoundSystem to get it to work.
Maarten (mail@maartengribnau.com)
Diffstat (limited to 'intern/SoundSystem')
-rw-r--r-- | intern/SoundSystem/Makefile | 3 | ||||
-rw-r--r-- | intern/SoundSystem/SND_DependKludge.h | 27 | ||||
-rw-r--r-- | intern/SoundSystem/fmod/SND_FmodDevice.cpp | 44 | ||||
-rw-r--r-- | intern/SoundSystem/intern/SND_Scene.cpp | 2 | ||||
-rw-r--r-- | intern/SoundSystem/intern/SND_Utils.cpp | 58 |
5 files changed, 114 insertions, 20 deletions
diff --git a/intern/SoundSystem/Makefile b/intern/SoundSystem/Makefile index e7f9760cc3c..97a65fe9215 100644 --- a/intern/SoundSystem/Makefile +++ b/intern/SoundSystem/Makefile @@ -42,6 +42,9 @@ ifeq ($(OS),windows) DIRS += fmod DIRS += openal endif +ifeq ($(OS),darwin) + DIRS += fmod +endif ifeq ($(OS),freebsd) DIRS += openal endif diff --git a/intern/SoundSystem/SND_DependKludge.h b/intern/SoundSystem/SND_DependKludge.h index de4c1212c7e..545f7f45b9a 100644 --- a/intern/SoundSystem/SND_DependKludge.h +++ b/intern/SoundSystem/SND_DependKludge.h @@ -37,21 +37,20 @@ #if defined (_WIN32) #define USE_FMOD +#elif defined (__linux__) +# if defined (__i386__) +# define USE_OPENAL +# endif +#elif defined (__FreeBSD__) +# define USE_OPENAL +#elif defined (__APPLE__) +# define USE_FMOD #else -# if defined (__linux__) -# if defined (__i386__) -# define USE_OPENAL -# endif -# else -# if defined (__FreeBSD__) -# define USE_OPENAL -# endif -# ifdef USE_OPENAL -# undef USE_OPENAL -# endif -# ifdef USE_FMOD -# undef USE_FMOD -# endif +# ifdef USE_OPENAL +# undef USE_OPENAL +# endif +# ifdef USE_FMOD +# undef USE_FMOD # endif #endif diff --git a/intern/SoundSystem/fmod/SND_FmodDevice.cpp b/intern/SoundSystem/fmod/SND_FmodDevice.cpp index 862703d0d59..cc01b864428 100644 --- a/intern/SoundSystem/fmod/SND_FmodDevice.cpp +++ b/intern/SoundSystem/fmod/SND_FmodDevice.cpp @@ -366,19 +366,31 @@ void SND_FmodDevice::SetObjectLoop(int id, unsigned int loopmode) const { case SND_LOOP_OFF: { +#ifndef __APPLE__ char result = FSOUND_Sample_SetLoopMode(m_sources[id], FSOUND_LOOP_OFF); +#else + char result = FSOUND_SetLoopMode(m_sources[id], FSOUND_LOOP_OFF); +#endif // char result = FSOUND_SetLoopMode(m_channels[id], FSOUND_LOOP_OFF); break; } case SND_LOOP_NORMAL: { +#ifndef __APPLE__ char result = FSOUND_Sample_SetLoopMode(m_sources[id], FSOUND_LOOP_NORMAL); +#else + char result = FSOUND_SetLoopMode(m_sources[id], FSOUND_LOOP_NORMAL); +#endif // char result = FSOUND_SetLoopMode(m_channels[id], FSOUND_LOOP_NORMAL); break; } case SND_LOOP_BIDIRECTIONAL: { +#ifndef __APPLE__ char result = FSOUND_Sample_SetLoopMode(m_sources[id], FSOUND_LOOP_BIDI); +#else + char result = FSOUND_SetLoopMode(m_sources[id], FSOUND_LOOP_BIDI); +#endif // char result = FSOUND_SetLoopMode(m_channels[id], FSOUND_LOOP_NORMAL); break; } @@ -460,10 +472,14 @@ void SND_FmodDevice::SetObjectTransform(int id, void SND_FmodDevice::PlayCD(int track) const { +#ifndef __APPLE__ signed char result = FSOUND_CD_Play(track); +#else + signed char result = FSOUND_CD_Play(0, track); +#endif #ifdef ONTKEVER - printf("play track %d, result: %c\n", track, result); + printf("SND_FmodDevice::PlayCD(): track=%d, result=%d\n", track, (int)result); #endif } @@ -471,10 +487,14 @@ void SND_FmodDevice::PlayCD(int track) const void SND_FmodDevice::PauseCD(bool pause) const { +#ifndef __APPLE__ signed char result = FSOUND_CD_SetPaused(pause); +#else + signed char result = FSOUND_CD_SetPaused(0, pause); +#endif #ifdef ONTKEVER - printf("pause cd: %d, result: %c\n", pause, result); + printf("SND_FmodDevice::PauseCD(): pause=%d, result=%d\n", pause, (int)result); #endif } @@ -488,10 +508,14 @@ void SND_FmodDevice::StopCD() const { if (pCD->GetUsed()) { +#ifndef __APPLE__ signed char result = FSOUND_CD_Stop(); +#else + signed char result = FSOUND_CD_Stop(0); +#endif #ifdef ONTKEVER - printf("stop cd, result: %c\n", result); + printf("SND_FmodDevice::StopCD(): result=%d\n", (int)result); #endif } } @@ -501,7 +525,15 @@ void SND_FmodDevice::StopCD() const void SND_FmodDevice::SetCDPlaymode(int playmode) const { +#ifndef __APPLE__ FSOUND_CD_SetPlayMode(playmode); +#else + FSOUND_CD_SetPlayMode(0, playmode); +#endif + +#ifdef ONTKEVER + printf("SND_FmodDevice::SetCDPlaymode(): playmode=%d,\n", playmode); +#endif } @@ -509,10 +541,14 @@ void SND_FmodDevice::SetCDPlaymode(int playmode) const void SND_FmodDevice::SetCDGain(MT_Scalar gain) const { int volume = gain * 255; +#ifndef __APPLE__ signed char result = FSOUND_CD_SetVolume(volume); +#else + signed char result = FSOUND_CD_SetVolume(0, volume); +#endif #ifdef ONTKEVER - printf("gain: %f, volume: %d, result: %c\n", gain, volume, result); + printf("SND_FmodDevice::SetCDGain(): gain=%f, volume=%d, result=%d\n", gain, volume, (int)result); #endif } diff --git a/intern/SoundSystem/intern/SND_Scene.cpp b/intern/SoundSystem/intern/SND_Scene.cpp index 5bc65f02359..4417dfbcfc9 100644 --- a/intern/SoundSystem/intern/SND_Scene.cpp +++ b/intern/SoundSystem/intern/SND_Scene.cpp @@ -408,7 +408,7 @@ void SND_Scene::UpdateActiveObects() #endif // if ((playstate == SND_STOPPED && (!juststartedplaying) && !pObject->GetLoopMode() && pObject->IsRunning()) -#ifdef WIN32 +#if defined(WIN32) || defined(__APPLE__) if ((playstate == SND_STOPPED) && !pObject->GetLoopMode()) #else if (!pObject->GetLoopMode()) diff --git a/intern/SoundSystem/intern/SND_Utils.cpp b/intern/SoundSystem/intern/SND_Utils.cpp index 3965c534cd3..543251e431f 100644 --- a/intern/SoundSystem/intern/SND_Utils.cpp +++ b/intern/SoundSystem/intern/SND_Utils.cpp @@ -59,6 +59,44 @@ extern "C" { #define BUFFERSIZE 32 + +/***************************************************************************** + * Begin of temporary Endian stuff. + * I think there should be a central place to handle endian conversion but for + * the time being it suffices. Note that the defines come from the Blender + * source. + *****************************************************************************/ +typedef enum +{ + SND_endianBig = 0, + SND_endianLittle +} SND_TEndian; + +#ifdef __APPLE__ +const SND_TEndian SND_fEndian = SND_endianBig; +#else +const SND_TEndian SND_fEndian = SND_endianLittle; +#endif + +/* This one swaps the bytes in a short */ +#define SWITCH_SHORT(a) { \ + char s_i, *p_i; \ + p_i= (char *)&(a); \ + s_i=p_i[0]; \ + p_i[0] = p_i[1]; \ + p_i[1] = s_i; } + +/* This one rotates the bytes in an int */ +#define SWITCH_INT(a) { \ + char s_i, *p_i; \ + p_i= (char *)&(a); \ + s_i=p_i[0]; p_i[0]=p_i[3]; p_i[3]=s_i; \ + s_i=p_i[1]; p_i[1]=p_i[2]; p_i[2]=s_i; } +/***************************************************************************** + * End of temporary Endian stuff. + *****************************************************************************/ + + /* loads a file */ void* SND_LoadSample(char *filename) { @@ -120,7 +158,10 @@ bool SND_IsSampleValid(const STR_String& name, void* memlocation) if(!(memcmp(buffer, "RIFF", 4) && memcmp(&(buffer[8]), "WAVEfmt ", 8))) { - int shortbuf = * ((short *) &buffer[20]); + /* This was endian unsafe. See top of the file for the define. */ + short shortbuf = *((short *) &buffer[20]); + if (SND_fEndian == SND_endianBig) SWITCH_SHORT(shortbuf); + if (shortbuf == SND_WAVE_FORMAT_PCM) result = true; @@ -199,6 +240,8 @@ unsigned int SND_GetSampleFormat(void* sample) { memcpy(&sampletype, ((char*)sample) + 20, 2); } + /* This was endian unsafe. See top of the file for the define. */ + if (SND_fEndian == SND_endianBig) SWITCH_SHORT(sampletype); return (unsigned int)sampletype; } @@ -214,6 +257,8 @@ unsigned int SND_GetNumberOfChannels(void* sample) { memcpy(&numberofchannels, ((char*)sample) + 22, 2); } + /* This was endian unsafe. See top of the file for the define. */ + if (SND_fEndian == SND_endianBig) SWITCH_SHORT(numberofchannels); return (unsigned int)numberofchannels; } @@ -229,6 +274,8 @@ unsigned int SND_GetSampleRate(void* sample) { memcpy(&samplerate, ((char*)sample) + 24, 4); } + /* This was endian unsafe. See top of the file for the define. */ + if (SND_fEndian == SND_endianBig) SWITCH_INT(samplerate); return samplerate; } @@ -244,6 +291,8 @@ unsigned int SND_GetBitRate(void* sample) { memcpy(&bitrate, ((char*)sample) + 34, 2); } + /* This was endian unsafe. See top of the file for the define. */ + if (SND_fEndian == SND_endianBig) SWITCH_SHORT(bitrate); return (unsigned int)bitrate; } @@ -259,9 +308,13 @@ unsigned int SND_GetNumberOfSamples(void* sample) if (CheckSample(sample)) { memcpy(&chunklength, ((char*)sample) + offset, 4); + /* This was endian unsafe. See top of the file for the define. */ + if (SND_fEndian == SND_endianBig) SWITCH_INT(chunklength); + offset = offset + chunklength + 4; memcpy(data, ((char*)sample) + offset, 4); + /* This seems very unsafe, what if data is never found (f.i. corrupt file)... */ // lets find "data" while (memcmp(data, "data", 4)) { @@ -270,6 +323,9 @@ unsigned int SND_GetNumberOfSamples(void* sample) } offset += 4; memcpy(&length, ((char*)sample) + offset, 4); + + /* This was endian unsafe. See top of the file for the define. */ + if (SND_fEndian == SND_endianBig) SWITCH_INT(length); } return length; |