Fix for [#28916] 2.6 RC2 - Bake Sound to FCurve Crash
authorJoerg Mueller <nexyon@gmail.com>
Fri, 14 Oct 2011 16:58:21 +0000 (16:58 +0000)
committerJoerg Mueller <nexyon@gmail.com>
Fri, 14 Oct 2011 16:58:21 +0000 (16:58 +0000)
intern/audaspace/FX/AUD_DynamicIIRFilterReader.cpp
intern/audaspace/FX/AUD_IIRFilterReader.cpp
intern/audaspace/intern/AUD_C-API.cpp

index ed9b2d3..f1edccb 100644 (file)
@@ -32,7 +32,8 @@
 
 AUD_DynamicIIRFilterReader::AUD_DynamicIIRFilterReader(AUD_Reference<AUD_IReader> reader,
                                                                                                           AUD_Reference<AUD_DynamicIIRFilterFactory> factory) :
-       AUD_IIRFilterReader(reader, std::vector<float>(), std::vector<float>())
+       AUD_IIRFilterReader(reader, std::vector<float>(), std::vector<float>()),
+       m_factory(factory)
 {
        sampleRateChanged(reader->getSpecs().rate);
 }
index 1bfb9b9..90f7e1e 100644 (file)
@@ -36,11 +36,14 @@ AUD_IIRFilterReader::AUD_IIRFilterReader(AUD_Reference<AUD_IReader> reader,
                                                                                 const std::vector<float>& a) :
        AUD_BaseIIRFilterReader(reader, b.size(), a.size()), m_a(a), m_b(b)
 {
-       for(int i = 1; i < m_a.size(); i++)
-               m_a[i] /= m_a[0];
-       for(int i = 0; i < m_b.size(); i++)
-               m_b[i] /= m_a[0];
-       m_a[0] = 1;
+       if(m_a.size())
+       {
+               for(int i = 1; i < m_a.size(); i++)
+                       m_a[i] /= m_a[0];
+               for(int i = 0; i < m_b.size(); i++)
+                       m_b[i] /= m_a[0];
+               m_a[0] = 1;
+       }
 }
 
 sample_t AUD_IIRFilterReader::filter()
@@ -58,7 +61,7 @@ sample_t AUD_IIRFilterReader::filter()
 void AUD_IIRFilterReader::setCoefficients(const std::vector<float>& b,
                                                                                  const std::vector<float>& a)
 {
-       setLengths(m_b.size(), m_a.size());
+       setLengths(b.size(), a.size());
        m_a = a;
        m_b = b;
 }
index af053df..66e3a0e 100644 (file)
@@ -826,42 +826,51 @@ float* AUD_readSoundBuffer(const char* filename, float low, float high,
 
        AUD_Reference<AUD_IFactory> file = new AUD_FileFactory(filename);
 
-       AUD_Reference<AUD_IReader> reader = file->createReader();
-       AUD_SampleRate rate = reader->getSpecs().rate;
+       int position = 0;
 
-       sound = new AUD_ChannelMapperFactory(file, specs);
+       try
+       {
+               AUD_Reference<AUD_IReader> reader = file->createReader();
 
-       if(high < rate)
-               sound = new AUD_LowpassFactory(sound, high);
-       if(low > 0)
-               sound = new AUD_HighpassFactory(sound, low);
+               AUD_SampleRate rate = reader->getSpecs().rate;
 
-       sound = new AUD_EnvelopeFactory(sound, attack, release, threshold, 0.1f);
-       sound = new AUD_LinearResampleFactory(sound, specs);
+               sound = new AUD_ChannelMapperFactory(file, specs);
 
-       if(square)
-               sound = new AUD_SquareFactory(sound, sthreshold);
+               if(high < rate)
+                       sound = new AUD_LowpassFactory(sound, high);
+               if(low > 0)
+                       sound = new AUD_HighpassFactory(sound, low);
 
-       if(accumulate)
-               sound = new AUD_AccumulatorFactory(sound, additive);
-       else if(additive)
-               sound = new AUD_SumFactory(sound);
+               sound = new AUD_EnvelopeFactory(sound, attack, release, threshold, 0.1f);
+               sound = new AUD_LinearResampleFactory(sound, specs);
 
-       reader = sound->createReader();
+               if(square)
+                       sound = new AUD_SquareFactory(sound, sthreshold);
 
-       if(reader.isNull())
-               return NULL;
+               if(accumulate)
+                       sound = new AUD_AccumulatorFactory(sound, additive);
+               else if(additive)
+                       sound = new AUD_SumFactory(sound);
 
-       int len;
-       int position = 0;
-       bool eos;
-       do
+               reader = sound->createReader();
+
+               if(reader.isNull())
+                       return NULL;
+
+               int len;
+               bool eos;
+               do
+               {
+                       len = samplerate;
+                       buffer.resize((position + len) * sizeof(float), true);
+                       reader->read(len, eos, buffer.getBuffer() + position);
+                       position += len;
+               } while(!eos);
+       }
+       catch(AUD_Exception&)
        {
-               len = samplerate;
-               buffer.resize((position + len) * sizeof(float), true);
-               reader->read(len, eos, buffer.getBuffer() + position);
-               position += len;
-       } while(!eos);
+               return NULL;
+       }
 
        float* result = (float*)malloc(position * sizeof(float));
        memcpy(result, buffer.getBuffer(), position * sizeof(float));