3D Audio GSoC:
authorJoerg Mueller <nexyon@gmail.com>
Wed, 13 Jul 2011 12:16:45 +0000 (12:16 +0000)
committerJoerg Mueller <nexyon@gmail.com>
Wed, 13 Jul 2011 12:16:45 +0000 (12:16 +0000)
* Fixed a warning in AUD_DoubleReader.cpp
* Removed some unneeded includes
* Fixed a bug resulting in a crash when stopping a sound
* Fixed a bug where a NaN resulted in a horrible memory error
* Fixed a typo bug which caused crackling in audio playback and export
* Added memory debugging code (ifdefed)

intern/audaspace/FX/AUD_DoubleReader.cpp
intern/audaspace/FX/AUD_LimiterReader.cpp
intern/audaspace/OpenAL/AUD_OpenALDevice.cpp
intern/audaspace/intern/AUD_ChannelMapperReader.cpp
intern/audaspace/intern/AUD_Mixer.cpp
intern/audaspace/intern/AUD_Reference.h
intern/audaspace/intern/AUD_SoftwareDevice.cpp

index fd2419a86e8d6b0a38e3ec23bba5cb012f3e260d..96352b0963ceb33cfa22f3fa1e3dea35ed7aa016 100644 (file)
@@ -33,9 +33,6 @@
 
 #include <cstring>
 
-static const char* specs_error = "AUD_DoubleReader: Both readers have to have "
-                                                                "the same specs.";
-
 AUD_DoubleReader::AUD_DoubleReader(AUD_Reference<AUD_IReader> reader1,
                                                                   AUD_Reference<AUD_IReader> reader2) :
                m_reader1(reader1), m_reader2(reader2), m_finished1(false)
index 92feac8a6a38291a7c4d2b675bc3b203f04f98a5..dc31477d2eb21f66ca69a22506cc85286de5d69d 100644 (file)
@@ -32,8 +32,6 @@
 #include "AUD_LimiterReader.h"
 #include "AUD_Buffer.h"
 
-#include <iostream>
-
 AUD_LimiterReader::AUD_LimiterReader(AUD_Reference<AUD_IReader> reader,
                                                                         float start, float end) :
                AUD_EffectReader(reader),
index 3b306d89d7b7d3dd063021061378d88e99dec8f8..65b1d3f3b6452365f7104c01c1c65b4e6b4ade1a 100644 (file)
@@ -178,10 +178,14 @@ bool AUD_OpenALDevice::AUD_OpenALHandle::stop()
 
        m_device->lock();
 
+       // AUD_XXX Create a reference of our own object so that it doesn't get
+       // deleted before the end of this function
+       AUD_Reference<AUD_OpenALHandle> This = this;
+
        if(m_status == AUD_STATUS_PLAYING)
-               m_device->m_playingSounds.remove(this);
+               m_device->m_playingSounds.remove(This);
        else
-               m_device->m_pausedSounds.remove(this);
+               m_device->m_pausedSounds.remove(This);
 
        m_device->unlock();
 
index 56c45da3fe4a18644107e82036e5097c09d17f98..dd6f5b4395304da0876932572784675ab59c76d2 100644 (file)
@@ -60,6 +60,8 @@ void AUD_ChannelMapperReader::setChannels(AUD_Channels channels)
 
 void AUD_ChannelMapperReader::setMonoAngle(float angle)
 {
+       if(std::isnan(angle))
+               angle = 0;
        m_mono_angle = angle;
        if(m_source_channels == AUD_CHANNELS_MONO)
                calculateMapping();
@@ -75,8 +77,6 @@ float AUD_ChannelMapperReader::angleDistance(float alpha, float beta)
        return alpha;
 }
 
-#include <iostream>
-
 void AUD_ChannelMapperReader::calculateMapping()
 {
        if(m_map_size < m_source_channels * m_target_channels)
@@ -127,6 +127,8 @@ void AUD_ChannelMapperReader::calculateMapping()
 
                for(int j = 0; j < m_target_channels; j++)
                {
+                       if(j == lfe)
+                               continue;
                        angle = angleDistance(source_angles[i], target_angles[j]);
                        if(angle < angle_min1)
                        {
index cfdf2b0e60a657f568c71236f3d61f10df9cdce0..74ff180627a22471a17c3a3a5a194cba18db018e 100644 (file)
@@ -92,7 +92,7 @@ void AUD_Mixer::mix(sample_t* buffer, int start, int length, float volume)
        sample_t* out = m_buffer.getBuffer();
 
        length = (AUD_MIN(m_length, length + start) - start) * m_specs.channels;
-       start += m_specs.channels;
+       start *= m_specs.channels;
 
        for(int i = 0; i < length; i++)
                out[i + start] += buffer[i] * volume;
index f9716b76fe2b85ca2cc14b69af4e47006e697290..3ddeab2eff15524668ae3e06ca8fec1d3ca95b11 100644 (file)
 
 #include <map>
 
+#ifdef MEM_DEBUG
+#include <iostream>
+#include <typeinfo>
+#endif
+
 class AUD_ReferenceHandler
 {
 private:
@@ -88,6 +93,10 @@ public:
        {
                m_original = m_reference = reference;
                AUD_ReferenceHandler::incref(reference);
+#ifdef MEM_DEBUG
+               if(m_reference != 0)
+                       std::cerr << "+" << typeid(*m_reference).name() << std::endl;
+#endif
        }
 
        /**
@@ -98,6 +107,10 @@ public:
        {
                m_original = m_reference = ref.m_reference;
                AUD_ReferenceHandler::incref(m_reference);
+#ifdef MEM_DEBUG
+               if(m_reference != 0)
+                       std::cerr << "+" << typeid(*m_reference).name() << std::endl;
+#endif
        }
 
        template <class U>
@@ -106,6 +119,10 @@ public:
                m_original = ref.get();
                m_reference = dynamic_cast<T*>(ref.get());
                AUD_ReferenceHandler::incref(m_original);
+#ifdef MEM_DEBUG
+               if(m_reference != 0)
+                       std::cerr << "+" << typeid(*m_reference).name() << std::endl;
+#endif
        }
 
        /**
@@ -114,6 +131,10 @@ public:
         */
        ~AUD_Reference()
        {
+#ifdef MEM_DEBUG
+               if(m_reference != 0)
+                       std::cerr << "-" << typeid(*m_reference).name() << std::endl;
+#endif
                if(AUD_ReferenceHandler::decref(m_original))
                        delete m_reference;
        }
@@ -127,12 +148,20 @@ public:
                if(&ref == this)
                        return *this;
 
+#ifdef MEM_DEBUG
+               if(m_reference != 0)
+                       std::cerr << "-" << typeid(*m_reference).name() << std::endl;
+#endif
                if(AUD_ReferenceHandler::decref(m_original))
                        delete m_reference;
 
                m_original = ref.m_original;
                m_reference = ref.m_reference;
                AUD_ReferenceHandler::incref(m_original);
+#ifdef MEM_DEBUG
+               if(m_reference != 0)
+                       std::cerr << "+" << typeid(*m_reference).name() << std::endl;
+#endif
 
                return *this;
        }
index c19f65afc6de18bb4daccd88f529c2111d7197d4..5e4308607045e70609d4c6a0abfb32050549c7bc 100644 (file)
@@ -65,8 +65,6 @@ AUD_SoftwareDevice::AUD_SoftwareHandle::AUD_SoftwareHandle(AUD_SoftwareDevice* d
 {
 }
 
-#include <iostream>
-
 void AUD_SoftwareDevice::AUD_SoftwareHandle::update()
 {
        int flags = 0;
@@ -170,7 +168,7 @@ void AUD_SoftwareDevice::AUD_SoftwareHandle::update()
                {
                        AUD_Vector3 SZ = m_orientation.getLookAt();
 
-                       float phi = acos(SZ * SL / (SZ.length() * SL.length()));
+                       float phi = acos(float(SZ * SL / (SZ.length() * SL.length())));
                        float t = (phi - m_cone_angle_inner)/(m_cone_angle_outer - m_cone_angle_inner);
 
                        if(t > 0)
@@ -202,7 +200,7 @@ void AUD_SoftwareDevice::AUD_SoftwareHandle::update()
 
        if(Asquare > 0)
        {
-               float phi = acos(Z * A/ (Z.length() * sqrt(Asquare)));
+               float phi = acos(float(Z * A / (Z.length() * sqrt(Asquare))));
                if(N.cross(Z) * A > 0)
                        phi = -phi;
 
@@ -268,15 +266,19 @@ bool AUD_SoftwareDevice::AUD_SoftwareHandle::stop()
 
        m_device->lock();
 
+       // AUD_XXX Create a reference of our own object so that it doesn't get
+       // deleted before the end of this function
+       AUD_Reference<AUD_SoftwareHandle> This = this;
+
        if(m_status == AUD_STATUS_PLAYING)
        {
-               m_device->m_playingSounds.remove(this);
+               m_device->m_playingSounds.remove(This);
 
                if(m_device->m_playingSounds.empty())
                        m_device->playing(m_device->m_playback = false);
        }
        else
-               m_device->m_pausedSounds.remove(this);
+               m_device->m_pausedSounds.remove(This);
 
        m_device->unlock();
        m_status = AUD_STATUS_INVALID;