Merging with trunk up to r38631.
[blender.git] / intern / audaspace / FX / AUD_SuperposeReader.cpp
index 6f39dcadf405ef022b38c8cc67b97b85fd6e9e3c..a0dc12fea96e161b783b0f020199edc5e953a1a4 100644 (file)
@@ -39,11 +39,6 @@ static const char* specs_error = "AUD_SuperposeReader: Both readers have to "
 AUD_SuperposeReader::AUD_SuperposeReader(AUD_Reference<AUD_IReader> reader1, AUD_Reference<AUD_IReader> reader2) :
        m_reader1(reader1), m_reader2(reader2)
 {
-       AUD_Specs s1, s2;
-       s1 = reader1->getSpecs();
-       s2 = reader2->getSpecs();
-       if(memcmp(&s1, &s2, sizeof(AUD_Specs)))
-               AUD_THROW(AUD_ERROR_SPECS, specs_error);
 }
 
 AUD_SuperposeReader::~AUD_SuperposeReader()
@@ -82,28 +77,31 @@ AUD_Specs AUD_SuperposeReader::getSpecs() const
        return m_reader1->getSpecs();
 }
 
-void AUD_SuperposeReader::read(int & length, sample_t* & buffer)
+void AUD_SuperposeReader::read(int& length, bool& eos, sample_t* buffer)
 {
        AUD_Specs specs = m_reader1->getSpecs();
+       AUD_Specs s2 = m_reader2->getSpecs();
+       if(memcmp(&specs, &s2, sizeof(AUD_Specs)))
+               AUD_THROW(AUD_ERROR_SPECS, specs_error);
+
        int samplesize = AUD_SAMPLE_SIZE(specs);
 
-       if(m_buffer.getSize() < length * samplesize)
-               m_buffer.resize(length * samplesize);
-       buffer = m_buffer.getBuffer();
+       m_buffer.assureSize(length * samplesize);
 
        int len1 = length;
-       sample_t* buf;
-       m_reader1->read(len1, buf);
-       memcpy(buffer, buf, len1 * samplesize);
+       m_reader1->read(len1, eos, buffer);
 
        if(len1 < length)
                memset(buffer + len1 * specs.channels, 0, (length - len1) * samplesize);
 
        int len2 = length;
-       m_reader2->read(len2, buf);
+       bool eos2;
+       sample_t* buf = m_buffer.getBuffer();
+       m_reader2->read(len2, eos2, buf);
 
        for(int i = 0; i < len2 * specs.channels; i++)
                buffer[i] += buf[i];
 
        length = AUD_MAX(len1, len2);
+       eos &= eos2;
 }