Revision: 21800
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21800
Author:   nexyon
Date:     2009-07-22 16:14:26 +0200 (Wed, 22 Jul 2009)

Log Message:
-----------
Added support for 3D audio and other GE stuff, like volume, pitch and ping pong 
looping.

Modified Paths:
--------------
    branches/soundsystem/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp
    branches/soundsystem/intern/audaspace/intern/AUD_C-API.cpp
    branches/soundsystem/intern/audaspace/intern/AUD_Space.h
    branches/soundsystem/source/blender/blenkernel/intern/sound.c
    branches/soundsystem/source/blender/blenloader/intern/readfile.c
    branches/soundsystem/source/gameengine/Converter/KX_ConvertActuators.cpp
    branches/soundsystem/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
    branches/soundsystem/source/gameengine/Ketsji/KX_SoundActuator.cpp
    branches/soundsystem/source/gameengine/Ketsji/KX_SoundActuator.h

Modified: branches/soundsystem/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp
===================================================================
--- branches/soundsystem/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp   
2009-07-22 13:35:02 UTC (rev 21799)
+++ branches/soundsystem/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp   
2009-07-22 14:14:26 UTC (rev 21800)
@@ -1097,7 +1097,7 @@
 {
        alListenerfv(AL_POSITION, (ALfloat*)data.position);
        alListenerfv(AL_VELOCITY, (ALfloat*)data.velocity);
-       alListenerfv(AL_ORIENTATION, (ALfloat*)data.orientation);
+       alListenerfv(AL_ORIENTATION, (ALfloat*)&(data.orientation[3]));
 }
 
 bool AUD_OpenALDevice::setSetting(AUD_3DSetting setting, float value)
@@ -1162,6 +1162,8 @@
        return std::numeric_limits<float>::quiet_NaN();
 }
 
+#include <stdio.h>
+
 bool AUD_OpenALDevice::updateSource(AUD_Handle* handle, AUD_3DData &data)
 {
        lock();
@@ -1171,7 +1173,7 @@
                int source = ((AUD_OpenALHandle*)handle)->source;
                alSourcefv(source, AL_POSITION, (ALfloat*)data.position);
                alSourcefv(source, AL_VELOCITY, (ALfloat*)data.velocity);
-               alSourcefv(source, AL_ORIENTATION, (ALfloat*)data.orientation);
+               alSourcefv(source, AL_DIRECTION, 
(ALfloat*)&(data.orientation[3]));
                unlock();
                return true;
        }

Modified: branches/soundsystem/intern/audaspace/intern/AUD_C-API.cpp
===================================================================
--- branches/soundsystem/intern/audaspace/intern/AUD_C-API.cpp  2009-07-22 
13:35:02 UTC (rev 21799)
+++ branches/soundsystem/intern/audaspace/intern/AUD_C-API.cpp  2009-07-22 
14:14:26 UTC (rev 21800)
@@ -35,6 +35,7 @@
 #include "AUD_PingPongFactory.h"
 #include "AUD_LoopFactory.h"
 #include "AUD_ReadDevice.h"
+#include "AUD_SourceCaps.h"
 
 /*
 #define WITH_SDL
@@ -106,7 +107,7 @@
                }
 
                if(AUD_device->checkCapability(AUD_CAPS_3D_DEVICE))
-                       AUD_3ddevice = (AUD_I3DDevice*) AUD_device;
+                       AUD_3ddevice = dynamic_cast<AUD_I3DDevice*>(AUD_device);
 
                return true;
        }
@@ -229,20 +230,21 @@
 
 int AUD_stopLoop(AUD_Handle* handle)
 {
-       assert(handle);
+       if(handle)
+       {
+               AUD_Message message;
+               message.type = AUD_MSG_LOOP;
+               message.loopcount = 0;
 
-       AUD_Message message;
-       message.type = AUD_MSG_LOOP;
-       message.loopcount = 0;
-
-       try
-       {
-               return AUD_device->sendMessage(handle, message);
+               try
+               {
+                       return AUD_device->sendMessage(handle, message);
+               }
+               catch(AUD_Exception e)
+               {
+               }
        }
-       catch(AUD_Exception e)
-       {
-               return false;
-       }
+       return false;
 }
 
 void AUD_unload(AUD_Sound* sound)
@@ -368,82 +370,98 @@
 
 int AUD_update3DSource(AUD_Handle* handle, AUD_3DData* data)
 {
-       assert(AUD_device);
-       assert(handle);
-       assert(data);
+       if(handle)
+       {
+               assert(AUD_device);
+               assert(data);
 
-       try
-       {
-               if(AUD_3ddevice)
-                       return AUD_3ddevice->updateSource(handle, *data);
+               try
+               {
+                       if(AUD_3ddevice)
+                               return AUD_3ddevice->updateSource(handle, 
*data);
+               }
+               catch(AUD_Exception e)
+               {
+               }
        }
-       catch(AUD_Exception e)
-       {
-       }
        return false;
 }
 
 int AUD_set3DSourceSetting(AUD_Handle* handle,
                                                   AUD_3DSourceSetting setting, 
float value)
 {
-       assert(AUD_device);
-       assert(handle);
+       if(handle)
+       {
+               assert(AUD_device);
 
-       try
-       {
-               if(AUD_3ddevice)
-                       return AUD_3ddevice->setSourceSetting(handle, setting, 
value);
+               try
+               {
+                       if(AUD_3ddevice)
+                               return AUD_3ddevice->setSourceSetting(handle, 
setting, value);
+               }
+               catch(AUD_Exception e)
+               {
+               }
        }
-       catch(AUD_Exception e)
-       {
-       }
        return false;
 }
 
 float AUD_get3DSourceSetting(AUD_Handle* handle, AUD_3DSourceSetting setting)
 {
-       assert(AUD_device);
-       assert(handle);
+       if(handle)
+       {
+               assert(AUD_device);
 
-       try
-       {
-               if(AUD_3ddevice)
-                       return AUD_3ddevice->getSourceSetting(handle, setting);
+               try
+               {
+                       if(AUD_3ddevice)
+                               return AUD_3ddevice->getSourceSetting(handle, 
setting);
+               }
+               catch(AUD_Exception e)
+               {
+               }
        }
-       catch(AUD_Exception e)
-       {
-       }
        return 0.0;
 }
 
 int AUD_setSoundVolume(AUD_Handle* handle, float volume)
 {
-       assert(AUD_device);
-       assert(handle);
+       if(handle)
+       {
+               assert(AUD_device);
+               AUD_SourceCaps caps;
+               caps.handle = handle;
+               caps.value = volume;
 
-       try
-       {
-               return AUD_device->setCapability(AUD_CAPS_SOURCE_VOLUME, 
&volume);
+               try
+               {
+                       return 
AUD_device->setCapability(AUD_CAPS_SOURCE_VOLUME, &caps);
+               }
+               catch(AUD_Exception e)
+               {
+                       return false;
+               }
        }
-       catch(AUD_Exception e)
-       {
-               return false;
-       }
 }
 
 int AUD_setSoundPitch(AUD_Handle* handle, float pitch)
 {
-       assert(AUD_device);
-       assert(handle);
+       if(handle)
+       {
+               assert(AUD_device);
+               AUD_SourceCaps caps;
+               caps.handle = handle;
+               caps.value = pitch;
 
-       try
-       {
-               return AUD_device->setCapability(AUD_CAPS_SOURCE_VOLUME, 
&pitch);
+               try
+               {
+                       return AUD_device->setCapability(AUD_CAPS_SOURCE_PITCH, 
&caps);
+               }
+               catch(AUD_Exception e)
+               {
+                       return false;
+               }
        }
-       catch(AUD_Exception e)
-       {
-               return false;
-       }
 }
 
 AUD_Device* AUD_openReadDevice(AUD_Specs specs)

Modified: branches/soundsystem/intern/audaspace/intern/AUD_Space.h
===================================================================
--- branches/soundsystem/intern/audaspace/intern/AUD_Space.h    2009-07-22 
13:35:02 UTC (rev 21799)
+++ branches/soundsystem/intern/audaspace/intern/AUD_Space.h    2009-07-22 
14:14:26 UTC (rev 21800)
@@ -288,7 +288,7 @@
        float velocity[3];
 
        /// 3x3 matrix telling the orientation of the object.
-       float orientation[3][3];
+       float orientation[9];
 } AUD_3DData;
 
 #endif //AUD_SPACE

Modified: branches/soundsystem/source/blender/blenkernel/intern/sound.c
===================================================================
--- branches/soundsystem/source/blender/blenkernel/intern/sound.c       
2009-07-22 13:35:02 UTC (rev 21799)
+++ branches/soundsystem/source/blender/blenkernel/intern/sound.c       
2009-07-22 14:14:26 UTC (rev 21800)
@@ -169,6 +169,24 @@
 
 void sound_load(struct bSound* sound)
 {
+       if(sound)
+       {
+               char fullpath[FILE_MAX];
+
+               /* load sound */
+               PackedFile* pf = sound->packedfile;
+
+               /* dont modify soundact->sound->name, only change a copy */
+               BLI_strncpy(fullpath, sound->name, sizeof(fullpath));
+               BLI_convertstringcode(fullpath, G.sce);
+
+               /* but we need a packed file then */
+               if (pf)
+                       sound->stream = AUD_loadBuffer((unsigned char*) 
pf->data, pf->size);
+               /* or else load it from disk */
+               else
+                       sound->stream = AUD_load(fullpath);
+       }
 }
 
 void sound_free(struct bSound* sound)
@@ -178,4 +196,10 @@
                freePackedFile(sound->packedfile);
                sound->packedfile = NULL;
        }
+
+       if(sound->stream)
+       {
+               AUD_unload(sound->stream);
+               sound->stream = NULL;
+       }
 }

Modified: branches/soundsystem/source/blender/blenloader/intern/readfile.c
===================================================================
--- branches/soundsystem/source/blender/blenloader/intern/readfile.c    
2009-07-22 13:35:02 UTC (rev 21799)
+++ branches/soundsystem/source/blender/blenloader/intern/readfile.c    
2009-07-22 14:14:26 UTC (rev 21800)
@@ -147,6 +147,9 @@
 #include "BKE_utildefines.h" // SWITCH_INT DATA ENDB DNA1 O_BINARY GLOB USER 
TEST REND
 #include "BKE_idprop.h"
 
+// AUD_XXX
+#include "BKE_sound.h"
+
 //XXX #include "BIF_butspace.h" // badlevel, for do_versions, patching event 
codes
 //XXX #include "BIF_filelist.h" // badlevel too, where to move this? - elubie
 //XXX #include "BIF_previewrender.h" // bedlelvel, for struct RenderInfo
@@ -4971,7 +4974,7 @@
                if(sound->id.flag & LIB_NEEDLINK) {
                        sound->id.flag -= LIB_NEEDLINK;
                        sound->ipo= newlibadr_us(fd, sound->id.lib, 
sound->ipo); // XXX depreceated - old animation system
-                       sound->stream = 0;
+// AUD_XXX                     sound->stream = 0;
                }
                sound= sound->id.next;
        }
@@ -9229,6 +9232,7 @@
                                sound->packedfile = sound->newpackedfile;
                                sound->newpackedfile = NULL;
                        }
+                       sound_load(sound);
                }
 
                for(ob = main->object.first; ob; ob = ob->id.next) {

Modified: 
branches/soundsystem/source/gameengine/Converter/KX_ConvertActuators.cpp
===================================================================
--- branches/soundsystem/source/gameengine/Converter/KX_ConvertActuators.cpp    
2009-07-22 13:35:02 UTC (rev 21799)
+++ branches/soundsystem/source/gameengine/Converter/KX_ConvertActuators.cpp    
2009-07-22 14:14:26 UTC (rev 21800)
@@ -480,27 +480,8 @@
                                                }
                                        }
 #else
-                                       AUD_Sound* sound = NULL;
-                                       if (soundact->sound) {
-                                               /* Need to convert the 
samplename into absolute path
-                                                * before checking if its 
loaded */
-                                               char fullpath[FILE_MAX];
+                                       bSound* sound = soundact->sound;
 
-                                               /* dont modify 
soundact->sound->name, only change a copy */
-                                               BLI_strncpy(fullpath, 
soundact->sound->name, sizeof(fullpath));
-                                               BLI_convertstringcode(fullpath, 
maggiename);
-                                               samplename = fullpath;
-
-                                               /* load sound */
-                                               PackedFile* pf = 
soundact->sound->packedfile;
-
-                                               /* but we need a packed file 
then */
-                                               if (pf)
-                                                       sound = 
AUD_loadBuffer((unsigned char*) pf->data, pf->size);
-                                               /* or else load it from disk */
-                                               else
-                                                       sound = 
AUD_load(samplename);
-                                       }
                                        if(!sound)
                                        {
                                                std::cout <<    "WARNING: Sound 
actuator \"" << bact->name <<

Modified: branches/soundsystem/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
===================================================================
--- branches/soundsystem/source/gameengine/Ketsji/KX_KetsjiEngine.cpp   
2009-07-22 13:35:02 UTC (rev 21799)
+++ branches/soundsystem/source/gameengine/Ketsji/KX_KetsjiEngine.cpp   
2009-07-22 14:14:26 UTC (rev 21800)
@@ -62,6 +62,7 @@
 #include "PHY_IPhysicsEnvironment.h"
 
 // AUD_XXX
+#include "AUD_C-API.h"
 //#include "SND_Scene.h"
 //#include "SND_IAudioDevice.h"
 
@@ -985,6 +986,41 @@
                listenerorientation);
 
        soundscene->Proceed();
+#else
+       {
+               AUD_3DData data;
+               float f;
+
+               listenerorientation.getValue3x3(data.orientation);
+               listenerposition.getValue(data.position);
+               listenervelocity.getValue(data.velocity);
+
+               f = data.position[1];
+               data.position[1] = data.position[2];
+               data.position[2] = -f;
+
+               f = data.velocity[1];
+               data.velocity[1] = data.velocity[2];
+               data.velocity[2] = -f;
+
+               f = data.orientation[1];
+               data.orientation[1] = data.orientation[2];
+               data.orientation[2] = -f;
+
+               f = data.orientation[3];
+               data.orientation[3] = -data.orientation[6];
+               data.orientation[6] = f;
+
+               f = data.orientation[4];
+               data.orientation[4] = -data.orientation[8];
+               data.orientation[8] = -f;
+
+               f = data.orientation[5];
+               data.orientation[5] = data.orientation[7];
+               data.orientation[7] = f;
+
+               AUD_updateListener(&data);
+       }
 #endif
 }
 

Modified: branches/soundsystem/source/gameengine/Ketsji/KX_SoundActuator.cpp

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to