enable openal support for os x and linux-powerpc
authorStefan Gartner <stefang@aon.at>
Wed, 14 Apr 2004 13:00:36 +0000 (13:00 +0000)
committerStefan Gartner <stefang@aon.at>
Wed, 14 Apr 2004 13:00:36 +0000 (13:00 +0000)
as there is a conflict between openal and sdl (when compiled with cdrom
support), i had to disable support for cd playing using sdl on os x
for the time being.

intern/SoundSystem/Makefile
intern/SoundSystem/SND_DependKludge.h
intern/SoundSystem/intern/SND_Utils.cpp
intern/SoundSystem/openal/SND_OpenALDevice.cpp
intern/SoundSystem/openal/SND_OpenALDevice.h
source/Makefile
source/nan_link.mk

index 9714e49da36cf4138364190e35315e0432ea5f49..20e37c26a334e62d7dfecef7b001bd5a5a701686 100644 (file)
@@ -44,16 +44,14 @@ ifneq ($(NAN_NO_OPENAL),true)
       DIRS += fmod 
       DIRS += openal sdl
   endif
-  #ifeq ($(OS),darwin)
-  #    DIRS += fmod 
-  #endif
+  ifeq ($(OS),darwin)
+      DIRS += openal
+  endif
   ifeq ($(OS),freebsd)
     DIRS += openal
   endif
   ifeq ($(OS),$(findstring $(OS), "linux"))
-    ifeq ($(CPU),i386)
-      DIRS += openal sdl
-    endif
+    DIRS += openal sdl
   endif
 else
   CPPFLAGS += -DNO_SOUND
index d5d8dd27972f035ac428b3783c2e92c3bb77df0b..15db3da9cd29200a4b63b061d36a1e748e0ec76a 100644 (file)
 
 #ifndef NO_SOUND
 
-#  if defined (_WIN32) && !defined(FREE_WINDOWS)
-#define USE_OPENAL
-#elif defined (__linux__)
-#      if defined (__i386__)
-#              define USE_OPENAL
-#      endif
-#elif defined (__FreeBSD__)
+#if defined (_WIN32) && !defined(FREE_WINDOWS)
+#   define USE_OPENAL
+#elif defined (__linux__) || (__FreeBSD__) || defined(__APPLE__)
 #      define USE_OPENAL
-/*
-#elif defined (__APPLE__)
-#      define USE_FMOD
-*/
 #else
 #      ifdef USE_OPENAL
 #              undef USE_OPENAL
index 1048e7016113354ddee0e945d43ba1573ed4bcd6..a919ffad609483ab45341d7213c934f0ffe51199 100644 (file)
@@ -73,7 +73,7 @@ typedef enum
        SND_endianLittle
 } SND_TEndian;
 
-#ifdef __APPLE__
+#ifdef __BIG_ENDIAN__
 const SND_TEndian SND_fEndian = SND_endianBig;
 #else
 const SND_TEndian SND_fEndian = SND_endianLittle;
@@ -339,6 +339,8 @@ unsigned int SND_GetHeaderSize(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);
 
@@ -392,10 +394,11 @@ void SND_GetSampleInfo(signed char* sample, SND_WaveSlot* waveslot)
        if (CheckSample(sample))
        {
                memcpy(&fileheader, sample, sizeof(WavFileHeader));
+               fileheader.size = SND_GetHeaderSize(sample);
                sample += sizeof(WavFileHeader);
                fileheader.size = ((fileheader.size+1) & ~1) - 4;
 
-               while ((fileheader.size != 0) && (memcpy(&chunkheader, sample, sizeof(WavChunkHeader))))
+               while ((fileheader.size > 0) && (memcpy(&chunkheader, sample, sizeof(WavChunkHeader))))
                {
                        sample += sizeof(WavChunkHeader);
                        if (!memcmp(chunkheader.id, "fmt ", 4))
index 6016b1b2355f4fbd0a9ece9cb658990001af3837..199e791dd64421cd17b16bd731ca7a01d5cc6a4e 100644 (file)
@@ -40,7 +40,9 @@
 #endif //WIN32
 
 #include "SND_OpenALDevice.h"
+#ifndef __APPLE__
 #include "SND_SDLCDDevice.h"
+#endif
 #include "SoundDefines.h"
 
 #include "SND_Utils.h"
@@ -276,8 +278,9 @@ SND_OpenALDevice::SND_OpenALDevice()
        {
                m_wavecache = new SND_WaveCache();
        }
-       
+#ifndef __APPLE__      
        m_cdrom = new SND_SDLCDDevice();
+#endif
 }
 
 void SND_OpenALDevice::UseCD(void) const
@@ -316,9 +319,10 @@ SND_OpenALDevice::~SND_OpenALDevice()
                this->StopCD();
                SND_CDObject::DisposeSystem();
        }
-       
+#ifndef __APPLE__
        if (m_cdrom)
                delete m_cdrom;
+#endif
 }
 
 
@@ -366,7 +370,7 @@ SND_WaveSlot* SND_OpenALDevice::LoadSample(const STR_String& name,
                                        bitrate = SND_GetBitRate(memlocation);
                                        
                                        /* load the sample into openal */
-#ifdef OUDE_OPENAL
+#if defined(OUDE_OPENAL) || defined (__APPLE__)
                                        alutLoadWAVMemory((char*)memlocation, &sampleformat, &data, &numberofsamples, &samplerate);                             //      openal_2.12
 #else
                                        alutLoadWAVMemory((signed char*)memlocation, &sampleformat, &data, &numberofsamples, &samplerate, &loop);//     openal_2.14+
@@ -377,7 +381,9 @@ SND_WaveSlot* SND_OpenALDevice::LoadSample(const STR_String& name,
                                /* or from file? */
                                else
                                {
-#ifdef WIN32
+#ifdef __APPLE__
+                                       alutLoadWAVFile((signed char*)samplename.Ptr(), &sampleformat, &data, &numberofsamples, &samplerate);
+#elif defined(WIN32)
                                        alutLoadWAVFile((signed char*)samplename.Ptr(), &sampleformat, &data, &numberofsamples, &samplerate, &loop);
 #else
                                        alutLoadWAV((char*)samplename.Ptr(), &data,
@@ -456,7 +462,9 @@ void SND_OpenALDevice::SetListenerRollOffFactor(MT_Scalar rollofffactor) const
 void SND_OpenALDevice::NextFrame() const
 {
        // CD
+#ifndef __APPLE__
        m_cdrom->NextFrame();
+#endif
        // not needed by openal
 }
 
@@ -509,8 +517,12 @@ int SND_OpenALDevice::GetPlayState(int id)
     int alstate = 0;
        int result = 0;
 
+#ifdef __APPLE__
+       alGetSourcei(m_sources[id], AL_SOURCE_STATE, &alstate);
+#else
     alGetSourceiv(m_sources[id], AL_SOURCE_STATE, &alstate);
-
+#endif
+       
        switch(alstate)
        {
        case AL_INITIAL:
@@ -690,31 +702,41 @@ void SND_OpenALDevice::SetObjectTransform(int id,
 
 void SND_OpenALDevice::PlayCD(int track) const
 {
+#ifndef __APPLE__
        m_cdrom->PlayCD(track);
+#endif
 }
 
 
 void SND_OpenALDevice::PauseCD(bool pause) const
 {
+#ifndef __APPLE__
        m_cdrom->PauseCD(pause);
+#endif
 }
 
 void SND_OpenALDevice::StopCD() const
 {
+#ifndef __APPLE__
        SND_CDObject* pCD = SND_CDObject::Instance();
 
        if (pCD && pCD->GetUsed())
        {
                m_cdrom->StopCD();
        }
+#endif
 }
 
 void SND_OpenALDevice::SetCDPlaymode(int playmode) const
 {
+#ifndef __APPLE__
        m_cdrom->SetCDPlaymode(playmode);
+#endif
 }
 
 void SND_OpenALDevice::SetCDGain(MT_Scalar gain) const
 {
+#ifndef __APPLE__
        m_cdrom->SetCDGain(gain);
+#endif
 }
index f204d2d03718ed2b1bd3e8e77650c065308e09e3..4f20580c2f34049aee462ad7e43bce2d62a74eca 100644 (file)
@@ -100,8 +100,9 @@ private:
        unsigned int    m_sources[NUM_SOURCES];
        bool                    m_buffersinitialized;
        bool                    m_sourcesinitialized;
-       
+#ifndef __APPLE__
        class SND_SDLCDDevice*  m_cdrom;
+#endif
 };
 
 #endif //SND_OPENALDEVICE
index 3fb82d4033eab87cf8a56d12d791a51bbb9d9cc9..20322946ab708a5561a27bc16dd7406540188349 100644 (file)
@@ -376,7 +376,7 @@ ifeq ($(NAN_NO_OPENAL), true)
     NAN_SND_LIBS += $(SOUNDSYSTEM)
 else
   ifeq ($(OS),$(findstring $(OS), "freebsd linux windows"))
-    ifeq ($(CPU),i386)
+    ifeq ($(CPU),$(findstring $(CPU), "i386 powerpc"))
       ifeq ($(OS),freebsd)
         NAN_SND_LIBS =  $(SOUNDSYSTEM)
         NAN_SND_LIBS += $(DUMMYSOUND)
@@ -410,6 +410,8 @@ else
     ifeq ($(OS),darwin)
       NAN_SND_LIBS =  $(SOUNDSYSTEM)
       NAN_SND_LIBS += $(DUMMYSOUND)
+      NAN_SND_LIBS += $(OPENALSOUND)
+      NAN_SND_LIBS += $(NAN_OPENAL)/lib/libopenal.a
       NAN_SND_LIBS += $(SOUNDSYSTEM)
     else
       NAN_SND_LIBS =  $(SOUNDSYSTEM)
index fd117f6e4f7d869589e61af5345d375a6227b00d..7f741ffad20d7cdbc4a0cd9c5155bf596a9e405d 100644 (file)
@@ -58,7 +58,8 @@ endif
 ifeq ($(OS),darwin)
     LLIBS    += -lGLU -lGL
     LLIBS    += -lz -framework Carbon -framework AGL 
-       LLIBS    += -framework QuickTime
+    LLIBS    += -framework QuickTime -framework CoreAudio
+    LLIBS    += -framework AudioUnit -framework AudioToolbox
     LDFLAGS += -L/System/Library/Frameworks/OpenGL.framework/Libraries
     DBG_LDFLAGS += -L/System/Library/Frameworks/OpenGL.framework/Libraries
 endif