Revision: 37716
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37716
Author:   nexyon
Date:     2011-06-21 20:35:09 +0000 (Tue, 21 Jun 2011)
Log Message:
-----------
3D Audio GSoC:
Adapting all readers to maximally support dynamic resampling/rechanneling, 
introducing a DynamicIIRFilter for example.

Modified Paths:
--------------
    branches/soc-2011-pepper/intern/audaspace/CMakeLists.txt
    branches/soc-2011-pepper/intern/audaspace/FX/AUD_BaseIIRFilterReader.cpp
    branches/soc-2011-pepper/intern/audaspace/FX/AUD_BaseIIRFilterReader.h
    branches/soc-2011-pepper/intern/audaspace/FX/AUD_ButterworthFactory.cpp
    branches/soc-2011-pepper/intern/audaspace/FX/AUD_ButterworthFactory.h
    branches/soc-2011-pepper/intern/audaspace/FX/AUD_DoubleReader.cpp
    branches/soc-2011-pepper/intern/audaspace/FX/AUD_HighpassFactory.cpp
    branches/soc-2011-pepper/intern/audaspace/FX/AUD_HighpassFactory.h
    branches/soc-2011-pepper/intern/audaspace/FX/AUD_IIRFilterReader.cpp
    branches/soc-2011-pepper/intern/audaspace/FX/AUD_IIRFilterReader.h
    branches/soc-2011-pepper/intern/audaspace/FX/AUD_LimiterReader.cpp
    branches/soc-2011-pepper/intern/audaspace/FX/AUD_LimiterReader.h
    branches/soc-2011-pepper/intern/audaspace/FX/AUD_LowpassFactory.cpp
    branches/soc-2011-pepper/intern/audaspace/FX/AUD_LowpassFactory.h
    branches/soc-2011-pepper/intern/audaspace/FX/AUD_SuperposeReader.cpp
    branches/soc-2011-pepper/intern/audaspace/intern/AUD_ConverterReader.cpp
    branches/soc-2011-pepper/intern/audaspace/intern/AUD_ConverterReader.h

Added Paths:
-----------
    branches/soc-2011-pepper/intern/audaspace/FX/AUD_DynamicIIRFilterFactory.cpp
    branches/soc-2011-pepper/intern/audaspace/FX/AUD_DynamicIIRFilterFactory.h
    branches/soc-2011-pepper/intern/audaspace/FX/AUD_DynamicIIRFilterReader.cpp
    branches/soc-2011-pepper/intern/audaspace/FX/AUD_DynamicIIRFilterReader.h

Modified: branches/soc-2011-pepper/intern/audaspace/CMakeLists.txt
===================================================================
--- branches/soc-2011-pepper/intern/audaspace/CMakeLists.txt    2011-06-21 
20:32:25 UTC (rev 37715)
+++ branches/soc-2011-pepper/intern/audaspace/CMakeLists.txt    2011-06-21 
20:35:09 UTC (rev 37716)
@@ -41,6 +41,8 @@
        FX/AUD_DelayReader.cpp
        FX/AUD_DoubleFactory.cpp
        FX/AUD_DoubleReader.cpp
+       FX/AUD_DynamicIIRFilterFactory.cpp
+       FX/AUD_DynamicIIRFilterReader.cpp
        FX/AUD_EffectFactory.cpp
        FX/AUD_EffectReader.cpp
        FX/AUD_EnvelopeFactory.cpp
@@ -133,6 +135,8 @@
        FX/AUD_DelayReader.h
        FX/AUD_DoubleFactory.h
        FX/AUD_DoubleReader.h
+       FX/AUD_DynamicIIRFilterFactory.h
+       FX/AUD_DynamicIIRFilterReader.h
        FX/AUD_EffectFactory.h
        FX/AUD_EffectReader.h
        FX/AUD_EnvelopeFactory.h

Modified: 
branches/soc-2011-pepper/intern/audaspace/FX/AUD_BaseIIRFilterReader.cpp
===================================================================
--- branches/soc-2011-pepper/intern/audaspace/FX/AUD_BaseIIRFilterReader.cpp    
2011-06-21 20:32:25 UTC (rev 37715)
+++ branches/soc-2011-pepper/intern/audaspace/FX/AUD_BaseIIRFilterReader.cpp    
2011-06-21 20:35:09 UTC (rev 37716)
@@ -33,20 +33,20 @@
 
 #include <cstring>
 
-#define CC m_channels + m_channel
+#define CC m_specs.channels + m_channel
 
 AUD_BaseIIRFilterReader::AUD_BaseIIRFilterReader(AUD_Reference<AUD_IReader> 
reader, int in,
                                                                                
                 int out) :
                AUD_EffectReader(reader),
-               m_channels(reader->getSpecs().channels),
+               m_specs(reader->getSpecs()),
                m_xlen(in), m_ylen(out),
                m_xpos(0), m_ypos(0), m_channel(0)
 {
-       m_x = new sample_t[in * m_channels];
-       m_y = new sample_t[out * m_channels];
+       m_x = new sample_t[m_xlen * m_specs.channels];
+       m_y = new sample_t[m_ylen * m_specs.channels];
 
-       memset(m_x, 0, sizeof(sample_t) * in * m_channels);
-       memset(m_y, 0, sizeof(sample_t) * out * m_channels);
+       memset(m_x, 0, sizeof(sample_t) * m_xlen * m_specs.channels);
+       memset(m_y, 0, sizeof(sample_t) * m_ylen * m_specs.channels);
 }
 
 AUD_BaseIIRFilterReader::~AUD_BaseIIRFilterReader()
@@ -55,11 +55,73 @@
        delete[] m_y;
 }
 
+void AUD_BaseIIRFilterReader::setLengths(int in, int out)
+{
+       if(in != m_xlen)
+       {
+               sample_t* xn = new sample_t[in * m_specs.channels];
+               memset(xn, 0, sizeof(sample_t) * in * m_specs.channels);
+
+               for(m_channel = 0; m_channel < m_specs.channels; m_channel++)
+               {
+                       for(int i = 1; i <= in && i <= m_xlen; i++)
+                       {
+                               xn[(in - i) * CC] = x(-i);
+                       }
+               }
+
+               delete[] m_x;
+               m_x = xn;
+               m_xpos = 0;
+               m_xlen = in;
+       }
+
+       if(out != m_ylen)
+       {
+               sample_t* yn = new sample_t[out * m_specs.channels];
+               memset(yn, 0, sizeof(sample_t) * out * m_specs.channels);
+
+               for(m_channel = 0; m_channel < m_specs.channels; m_channel++)
+               {
+                       for(int i = 1; i <= out && i <= m_ylen; i++)
+                       {
+                               yn[(out - i) * CC] = y(-i);
+                       }
+               }
+
+               delete[] m_y;
+               m_y = yn;
+               m_ypos = 0;
+               m_ylen = out;
+       }
+}
+
 void AUD_BaseIIRFilterReader::read(int& length, bool& eos, sample_t* buffer)
 {
+       AUD_Specs specs = m_reader->getSpecs();
+       if(specs.channels != m_specs.channels)
+       {
+               m_specs.channels = specs.channels;
+
+               delete[] m_x;
+               delete[] m_y;
+
+               m_x = new sample_t[m_xlen * m_specs.channels];
+               m_y = new sample_t[m_ylen * m_specs.channels];
+
+               memset(m_x, 0, sizeof(sample_t) * m_xlen * m_specs.channels);
+               memset(m_y, 0, sizeof(sample_t) * m_ylen * m_specs.channels);
+       }
+
+       if(specs.rate != m_specs.rate)
+       {
+               m_specs = specs;
+               sampleRateChanged(m_specs.rate);
+       }
+
        m_reader->read(length, eos, buffer);
 
-       for(m_channel = 0; m_channel < m_channels; m_channel++)
+       for(m_channel = 0; m_channel < m_specs.channels; m_channel++)
        {
                for(int i = 0; i < length; i++)
                {
@@ -71,3 +133,7 @@
                }
        }
 }
+
+void AUD_BaseIIRFilterReader::sampleRateChanged(AUD_SampleRate rate)
+{
+}

Modified: branches/soc-2011-pepper/intern/audaspace/FX/AUD_BaseIIRFilterReader.h
===================================================================
--- branches/soc-2011-pepper/intern/audaspace/FX/AUD_BaseIIRFilterReader.h      
2011-06-21 20:32:25 UTC (rev 37715)
+++ branches/soc-2011-pepper/intern/audaspace/FX/AUD_BaseIIRFilterReader.h      
2011-06-21 20:35:09 UTC (rev 37716)
@@ -42,19 +42,19 @@
 {
 private:
        /**
-        * Channel count.
+        * Specs.
         */
-       const int m_channels;
+       AUD_Specs m_specs;
 
        /**
         * Length of input samples needed.
         */
-       const int m_xlen;
+       int m_xlen;
 
        /**
         * Length of output samples needed.
         */
-       const int m_ylen;
+       int m_ylen;
 
        /**
         * The last in samples array.
@@ -94,15 +94,17 @@
         */
        AUD_BaseIIRFilterReader(AUD_Reference<AUD_IReader> reader, int in, int 
out);
 
+       void setLengths(int in, int out);
+
 public:
        inline sample_t x(int pos)
        {
-               return m_x[(m_xpos + pos + m_xlen) % m_xlen * m_channels + 
m_channel];
+               return m_x[(m_xpos + pos + m_xlen) % m_xlen * m_specs.channels 
+ m_channel];
        }
 
        inline sample_t y(int pos)
        {
-               return m_y[(m_ypos + pos + m_ylen) % m_ylen * m_channels + 
m_channel];
+               return m_y[(m_ypos + pos + m_ylen) % m_ylen * m_specs.channels 
+ m_channel];
        }
 
        virtual ~AUD_BaseIIRFilterReader();
@@ -110,6 +112,7 @@
        virtual void read(int& length, bool& eos, sample_t* buffer);
 
        virtual sample_t filter()=0;
+       virtual void sampleRateChanged(AUD_SampleRate rate);
 };
 
 #endif //AUD_BASEIIRFILTERREADER

Modified: 
branches/soc-2011-pepper/intern/audaspace/FX/AUD_ButterworthFactory.cpp
===================================================================
--- branches/soc-2011-pepper/intern/audaspace/FX/AUD_ButterworthFactory.cpp     
2011-06-21 20:32:25 UTC (rev 37715)
+++ branches/soc-2011-pepper/intern/audaspace/FX/AUD_ButterworthFactory.cpp     
2011-06-21 20:35:09 UTC (rev 37716)
@@ -43,17 +43,16 @@
 
 AUD_ButterworthFactory::AUD_ButterworthFactory(AUD_Reference<AUD_IFactory> 
factory,
                                                                                
           float frequency) :
-               AUD_EffectFactory(factory),
+               AUD_DynamicIIRFilterFactory(factory),
                m_frequency(frequency)
 {
 }
 
-AUD_Reference<AUD_IReader> AUD_ButterworthFactory::createReader()
+void AUD_ButterworthFactory::recalculateCoefficients(AUD_SampleRate rate,
+                                                                               
                         std::vector<float> &b,
+                                                                               
                         std::vector<float> &a)
 {
-       AUD_Reference<AUD_IReader> reader = getReader();
-
-       // calculate coefficients
-       float omega = 2 * tan(m_frequency * M_PI / reader->getSpecs().rate);
+       float omega = 2 * tan(m_frequency * M_PI / rate);
        float o2 = omega * omega;
        float o4 = o2 * o2;
        float x1 = o2 + 2 * BWPB41 * omega + 4;
@@ -62,7 +61,6 @@
        float y2 = o2 - 2 * BWPB42 * omega + 4;
        float o228 = 2 * o2 - 8;
        float norm = x1 * x2;
-       std::vector<float> a, b;
        a.push_back(1);
        a.push_back((x1 + x2) * o228 / norm);
        a.push_back((x1 * y2 + x2 * y1 + o228 * o228) / norm);
@@ -73,6 +71,4 @@
        b.push_back(6 * o4 / norm);
        b.push_back(b[1]);
        b.push_back(b[0]);
-
-       return new AUD_IIRFilterReader(reader, b, a);
 }

Modified: branches/soc-2011-pepper/intern/audaspace/FX/AUD_ButterworthFactory.h
===================================================================
--- branches/soc-2011-pepper/intern/audaspace/FX/AUD_ButterworthFactory.h       
2011-06-21 20:32:25 UTC (rev 37715)
+++ branches/soc-2011-pepper/intern/audaspace/FX/AUD_ButterworthFactory.h       
2011-06-21 20:35:09 UTC (rev 37716)
@@ -32,12 +32,12 @@
 #ifndef AUD_BUTTERWORTHFACTORY
 #define AUD_BUTTERWORTHFACTORY
 
-#include "AUD_EffectFactory.h"
+#include "AUD_DynamicIIRFilterFactory.h"
 
 /**
  * This factory creates a butterworth filter reader.
  */
-class AUD_ButterworthFactory : public AUD_EffectFactory
+class AUD_ButterworthFactory : public AUD_DynamicIIRFilterFactory
 {
 private:
        /**
@@ -57,7 +57,9 @@
         */
        AUD_ButterworthFactory(AUD_Reference<AUD_IFactory> factory, float 
frequency);
 
-       virtual AUD_Reference<AUD_IReader> createReader();
+       virtual void recalculateCoefficients(AUD_SampleRate rate,
+                                                                               
 std::vector<float>& b,
+                                                                               
 std::vector<float>& a);
 };
 
 #endif //AUD_BUTTERWORTHFACTORY

Modified: branches/soc-2011-pepper/intern/audaspace/FX/AUD_DoubleReader.cpp
===================================================================
--- branches/soc-2011-pepper/intern/audaspace/FX/AUD_DoubleReader.cpp   
2011-06-21 20:32:25 UTC (rev 37715)
+++ branches/soc-2011-pepper/intern/audaspace/FX/AUD_DoubleReader.cpp   
2011-06-21 20:35:09 UTC (rev 37716)
@@ -43,10 +43,6 @@
        AUD_Specs s1, s2;
        s1 = reader1->getSpecs();
        s2 = reader2->getSpecs();
-       if(memcmp(&s1, &s2, sizeof(AUD_Specs)) != 0)
-       {
-               AUD_THROW(AUD_ERROR_SPECS, specs_error);
-       }
 }
 
 AUD_DoubleReader::~AUD_DoubleReader()
@@ -86,7 +82,7 @@
 
 AUD_Specs AUD_DoubleReader::getSpecs() const
 {
-       return m_reader1->getSpecs();
+       return m_finished1 ? m_reader1->getSpecs() : m_reader2->getSpecs();
 }
 
 void AUD_DoubleReader::read(int& length, bool& eos, sample_t* buffer)
@@ -95,20 +91,7 @@
 
        if(!m_finished1)
        {
-               int len = length;
-               m_reader1->read(len, m_finished1, buffer);
-
-               if(m_finished1)
-               {
-                       const AUD_Specs specs = m_reader1->getSpecs();
-
-                       len = length - len;
-                       length -= len;
-
-                       m_reader2->read(len, eos, buffer + length * 
specs.channels);
-
-                       length += len;
-               }
+               m_reader1->read(length, m_finished1, buffer);
        }
        else
        {

Added: 
branches/soc-2011-pepper/intern/audaspace/FX/AUD_DynamicIIRFilterFactory.cpp
===================================================================
--- 
branches/soc-2011-pepper/intern/audaspace/FX/AUD_DynamicIIRFilterFactory.cpp    
                            (rev 0)
+++ 
branches/soc-2011-pepper/intern/audaspace/FX/AUD_DynamicIIRFilterFactory.cpp    
    2011-06-21 20:35:09 UTC (rev 37716)
@@ -0,0 +1,42 @@
+/*
+ * $Id$
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * Copyright 2009-2011 Jörg Hermann Müller
+ *
+ * This file is part of AudaSpace.
+ *
+ * Audaspace is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * AudaSpace is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Audaspace; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file audaspace/FX/AUD_DynamicIIRFilterFactory.cpp
+ *  \ingroup audfx
+ */
+

@@ 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