3D Audio GSoC:
authorJoerg Mueller <nexyon@gmail.com>
Tue, 14 Jun 2011 12:13:19 +0000 (12:13 +0000)
committerJoerg Mueller <nexyon@gmail.com>
Tue, 14 Jun 2011 12:13:19 +0000 (12:13 +0000)
Changed Readers to top-down architecture instead of bottom-up.

48 files changed:
intern/audaspace/FX/AUD_BaseIIRFilterReader.cpp
intern/audaspace/FX/AUD_BaseIIRFilterReader.h
intern/audaspace/FX/AUD_DelayReader.cpp
intern/audaspace/FX/AUD_DelayReader.h
intern/audaspace/FX/AUD_DoubleReader.cpp
intern/audaspace/FX/AUD_DoubleReader.h
intern/audaspace/FX/AUD_EffectReader.cpp
intern/audaspace/FX/AUD_EffectReader.h
intern/audaspace/FX/AUD_FaderReader.cpp
intern/audaspace/FX/AUD_FaderReader.h
intern/audaspace/FX/AUD_LimiterReader.cpp
intern/audaspace/FX/AUD_LimiterReader.h
intern/audaspace/FX/AUD_LoopReader.cpp
intern/audaspace/FX/AUD_LoopReader.h
intern/audaspace/FX/AUD_ReverseReader.cpp
intern/audaspace/FX/AUD_ReverseReader.h
intern/audaspace/FX/AUD_SuperposeReader.cpp
intern/audaspace/FX/AUD_SuperposeReader.h
intern/audaspace/OpenAL/AUD_OpenALDevice.cpp
intern/audaspace/OpenAL/AUD_OpenALDevice.h
intern/audaspace/SRC/AUD_SRCResampleReader.cpp
intern/audaspace/SRC/AUD_SRCResampleReader.h
intern/audaspace/ffmpeg/AUD_FFMPEGReader.cpp
intern/audaspace/ffmpeg/AUD_FFMPEGReader.h
intern/audaspace/intern/AUD_BufferReader.cpp
intern/audaspace/intern/AUD_BufferReader.h
intern/audaspace/intern/AUD_C-API.cpp
intern/audaspace/intern/AUD_ChannelMapperReader.cpp
intern/audaspace/intern/AUD_ChannelMapperReader.h
intern/audaspace/intern/AUD_ConverterReader.cpp
intern/audaspace/intern/AUD_ConverterReader.h
intern/audaspace/intern/AUD_IReader.h
intern/audaspace/intern/AUD_LinearResampleReader.cpp
intern/audaspace/intern/AUD_LinearResampleReader.h
intern/audaspace/intern/AUD_Mixer.cpp
intern/audaspace/intern/AUD_Mixer.h
intern/audaspace/intern/AUD_SequencerReader.cpp
intern/audaspace/intern/AUD_SequencerReader.h
intern/audaspace/intern/AUD_SilenceReader.cpp
intern/audaspace/intern/AUD_SilenceReader.h
intern/audaspace/intern/AUD_SinusReader.cpp
intern/audaspace/intern/AUD_SinusReader.h
intern/audaspace/intern/AUD_SoftwareDevice.cpp
intern/audaspace/intern/AUD_SoftwareDevice.h
intern/audaspace/intern/AUD_StreamBufferFactory.cpp
intern/audaspace/jack/AUD_JackDevice.cpp
intern/audaspace/sndfile/AUD_SndFileReader.cpp
intern/audaspace/sndfile/AUD_SndFileReader.h

index 5ad5903141bfc5c0f124975e18c871f939b2ad20..9ddd8af019bd329714754e862f5801241dcdf950 100644 (file)
@@ -55,24 +55,15 @@ AUD_BaseIIRFilterReader::~AUD_BaseIIRFilterReader()
        delete[] m_y;
 }
 
-void AUD_BaseIIRFilterReader::read(int & length, sample_t* buffer)
+void AUD_BaseIIRFilterReader::read(int & length, sample_t* buffer)
 {
-       sample_t* buf;
-
-       int samplesize = AUD_SAMPLE_SIZE(m_reader->getSpecs());
-
-       m_reader->read(length, buf);
-
-       if(m_buffer.getSize() < length * samplesize)
-               m_buffer.resize(length * samplesize);
-
-       buffer = m_buffer.getBuffer();
+       m_reader->read(length, buffer);
 
        for(m_channel = 0; m_channel < m_channels; m_channel++)
        {
                for(int i = 0; i < length; i++)
                {
-                       m_x[m_xpos * CC] = buf[i * CC];
+                       m_x[m_xpos * CC] = buffer[i * CC];
                        m_y[m_ypos * CC] = buffer[i * CC] = filter();
 
                        m_xpos = (m_xpos + 1) % m_xlen;
index 9f81e2d8a255b34f92ab5c0f1e62bce7977b2b66..2d1f21446a09dfdea1b38ccf98ee33cd586d84c2 100644 (file)
@@ -56,11 +56,6 @@ private:
         */
        const int m_ylen;
 
-       /**
-        * The playback buffer.
-        */
-       AUD_Buffer m_buffer;
-
        /**
         * The last in samples array.
         */
@@ -112,7 +107,7 @@ public:
 
        virtual ~AUD_BaseIIRFilterReader();
 
-       virtual void read(int & length, sample_t* buffer);
+       virtual void read(int & length, sample_t* buffer);
 
        virtual sample_t filter()=0;
 };
index a2224caf28802a09386af825d7954340c941a7aa..2e93184358eacc1884f4ed856391fcb6e4894a49 100644 (file)
@@ -36,8 +36,7 @@
 AUD_DelayReader::AUD_DelayReader(AUD_Reference<AUD_IReader> reader, float delay) :
                AUD_EffectReader(reader),
                m_delay(int(delay * reader->getSpecs().rate)),
-               m_remdelay(int(delay * reader->getSpecs().rate)),
-               m_empty(true)
+               m_remdelay(int(delay * reader->getSpecs().rate))
 {
 }
 
@@ -70,46 +69,28 @@ int AUD_DelayReader::getPosition() const
        return m_reader->getPosition() + m_delay;
 }
 
-void AUD_DelayReader::read(int & length, sample_t* buffer)
+void AUD_DelayReader::read(int & length, sample_t* buffer)
 {
        if(m_remdelay > 0)
        {
                AUD_Specs specs = m_reader->getSpecs();
                int samplesize = AUD_SAMPLE_SIZE(specs);
 
-               if(m_buffer.getSize() < length * samplesize)
-               {
-                       m_buffer.resize(length * samplesize);
-                       m_empty = false;
-               }
-
-               buffer = m_buffer.getBuffer();
-
                if(length > m_remdelay)
                {
-                       if(!m_empty)
-                               memset(buffer, 0, m_remdelay * samplesize);
+                       memset(buffer, 0, m_remdelay * samplesize);
 
                        int len = length - m_remdelay;
-                       sample_t* buf;
-                       m_reader->read(len, buf);
-
-                       memcpy(buffer + m_remdelay * specs.channels,
-                                  buf, len * samplesize);
+                       m_reader->read(len, buffer + m_remdelay * specs.channels);
 
                        if(len < length-m_remdelay)
                                length = m_remdelay + len;
 
                        m_remdelay = 0;
-                       m_empty = false;
                }
                else
                {
-                       if(!m_empty)
-                       {
-                               memset(buffer, 0, length * samplesize);
-                               m_empty = true;
-                       }
+                       memset(buffer, 0, length * samplesize);
                        m_remdelay -= length;
                }
        }
index 695003a8c43580b3f755d1c808c213744fef30de..cb0ec9bcd9d838f6a67d558c1cc31fc3dd7437e1 100644 (file)
 class AUD_DelayReader : public AUD_EffectReader
 {
 private:
-       /**
-        * The playback buffer.
-        */
-       AUD_Buffer m_buffer;
-
        /**
         * The delay level.
         */
@@ -56,11 +51,6 @@ private:
         */
        int m_remdelay;
 
-       /**
-        * Whether the buffer is currently filled with zeros.
-        */
-       bool m_empty;
-
        // hide copy constructor and operator=
        AUD_DelayReader(const AUD_DelayReader&);
        AUD_DelayReader& operator=(const AUD_DelayReader&);
@@ -76,7 +66,7 @@ public:
        virtual void seek(int position);
        virtual int getLength() const;
        virtual int getPosition() const;
-       virtual void read(int & length, sample_t* buffer);
+       virtual void read(int & length, sample_t* buffer);
 };
 
 #endif //AUD_DELAYREADER
index bf1c770a2ed01d30e1cc6dba2f66bbae859bf236..605c49066d2ba7a83d970e271786d85bc9a0f7fe 100644 (file)
@@ -89,7 +89,7 @@ AUD_Specs AUD_DoubleReader::getSpecs() const
        return m_reader1->getSpecs();
 }
 
-void AUD_DoubleReader::read(int & length, sample_t* buffer)
+void AUD_DoubleReader::read(int & length, sample_t* buffer)
 {
        if(!m_finished1)
        {
@@ -98,23 +98,12 @@ void AUD_DoubleReader::read(int & length, sample_t* & buffer)
 
                if(len < length)
                {
-                       AUD_Specs specs = m_reader1->getSpecs();
-                       int samplesize = AUD_SAMPLE_SIZE(specs);
-
-                       if(m_buffer.getSize() < length * samplesize)
-                               m_buffer.resize(length * samplesize);
-
-                       sample_t* buf = buffer;
-                       buffer = m_buffer.getBuffer();
-
-                       memcpy(buffer, buf, len * samplesize);
+                       const AUD_Specs specs = m_reader1->getSpecs();
 
                        len = length - len;
                        length -= len;
-                       m_reader2->read(len, buf);
 
-                       memcpy(buffer + length * specs.channels, buf,
-                                  len * samplesize);
+                       m_reader2->read(len, buffer + length * specs.channels);
 
                        length += len;
 
index 4f01c47d05226780f2c1941cde3d9b269f4aa35c..d68000fe81ae230fa7a32527fb24139aec286c02 100644 (file)
@@ -85,7 +85,7 @@ public:
        virtual int getLength() const;
        virtual int getPosition() const;
        virtual AUD_Specs getSpecs() const;
-       virtual void read(int & length, sample_t* buffer);
+       virtual void read(int & length, sample_t* buffer);
 };
 
 #endif //AUD_DOUBLEREADER
index d7c4eeb2ee1405272da6b9350c3057c34f8b5bad..aa8fe7a7f354de700e1d6d01302eb631c920d4cd 100644 (file)
@@ -65,7 +65,7 @@ AUD_Specs AUD_EffectReader::getSpecs() const
        return m_reader->getSpecs();
 }
 
-void AUD_EffectReader::read(int & length, sample_t* buffer)
+void AUD_EffectReader::read(int & length, sample_t* buffer)
 {
        m_reader->read(length, buffer);
 }
index 6aa185edcd04f96ff2595b44d7d28c6c4ded7acf..cfb8e5b6e77390f0a382f182cb4cef365c1f55e1 100644 (file)
@@ -69,7 +69,7 @@ public:
        virtual int getLength() const;
        virtual int getPosition() const;
        virtual AUD_Specs getSpecs() const;
-       virtual void read(int & length, sample_t* buffer);
+       virtual void read(int & length, sample_t* buffer);
 };
 
 #endif //AUD_EFFECTREADER
index e319e205e5f3c0f94d750289568e2790bfeb0bb4..7fe5c503c23f83d803688a7ef9e86e3e084acc33 100644 (file)
@@ -38,12 +38,11 @@ AUD_FaderReader::AUD_FaderReader(AUD_Reference<AUD_IReader> reader, AUD_FadeType
                AUD_EffectReader(reader),
                m_type(type),
                m_start(start),
-               m_length(length),
-               m_empty(true)
+               m_length(length)
 {
 }
 
-void AUD_FaderReader::read(int & length, sample_t* buffer)
+void AUD_FaderReader::read(int & length, sample_t* buffer)
 {
        int position = m_reader->getPosition();
        AUD_Specs specs = m_reader->getSpecs();
@@ -55,46 +54,18 @@ void AUD_FaderReader::read(int & length, sample_t* & buffer)
        {
                if(m_type != AUD_FADE_OUT)
                {
-                       if(m_buffer.getSize() < length * samplesize)
-                       {
-                               m_buffer.resize(length * samplesize);
-                               m_empty = false;
-                       }
-
-                       buffer = m_buffer.getBuffer();
-
-                       if(!m_empty)
-                       {
-                               memset(buffer, 0, length * samplesize);
-                               m_empty = true;
-                       }
+                       memset(buffer, 0, length * samplesize);
                }
        }
        else if(position / (float)specs.rate >= m_start+m_length)
        {
                if(m_type == AUD_FADE_OUT)
                {
-                       if(m_buffer.getSize() < length * samplesize)
-                       {
-                               m_buffer.resize(length * samplesize);
-                               m_empty = false;
-                       }
-
-                       buffer = m_buffer.getBuffer();
-
-                       if(!m_empty)
-                       {
-                               memset(buffer, 0, length * samplesize);
-                               m_empty = true;
-                       }
+                       memset(buffer, 0, length * samplesize);
                }
        }
        else
        {
-               if(m_buffer.getSize() < length * samplesize)
-                       m_buffer.resize(length * samplesize);
-
-               sample_t* buf = m_buffer.getBuffer();
                float volume = 1.0f;
 
                for(int i = 0; i < length * specs.channels; i++)
@@ -111,10 +82,7 @@ void AUD_FaderReader::read(int & length, sample_t* & buffer)
                                        volume = 1.0f - volume;
                        }
 
-                       buf[i] = buffer[i] * volume;
+                       buffer[i] = buffer[i] * volume;
                }
-
-               buffer = buf;
-               m_empty = false;
        }
 }
index b088477bce0d9f7184eab3c29b7d0aab3ce4a365..c0eb3d27d368cab0862099d81093b6a71c6fe3f4 100644 (file)
@@ -58,16 +58,6 @@ private:
         */
        const float m_length;
 
-       /**
-        * The playback buffer.
-        */
-       AUD_Buffer m_buffer;
-
-       /**
-        * Whether the buffer is empty.
-        */
-       bool m_empty;
-
        // hide copy constructor and operator=
        AUD_FaderReader(const AUD_FaderReader&);
        AUD_FaderReader& operator=(const AUD_FaderReader&);
@@ -82,7 +72,7 @@ public:
        AUD_FaderReader(AUD_Reference<AUD_IReader> reader, AUD_FadeType type,
                                        float start,float length);
 
-       virtual void read(int & length, sample_t* buffer);
+       virtual void read(int & length, sample_t* buffer);
 };
 
 #endif //AUD_FADERREADER
index d5a46568b3ef32d0974d931802437a0e8c1e5ffe..0f87679410e5d4690a8af36ef453973524ab46a1 100644 (file)
@@ -48,14 +48,14 @@ AUD_LimiterReader::AUD_LimiterReader(AUD_Reference<AUD_IReader> reader,
                {
                        // skip first m_start samples by reading them
                        int length = AUD_DEFAULT_BUFFER_SIZE;
-                       sample_t* buffer;
+                       AUD_Buffer buffer(AUD_DEFAULT_BUFFER_SIZE * AUD_SAMPLE_SIZE(m_reader->getSpecs()));
                        for(int len = m_start;
                                length == AUD_DEFAULT_BUFFER_SIZE;
                                len -= AUD_DEFAULT_BUFFER_SIZE)
                        {
                                if(len < AUD_DEFAULT_BUFFER_SIZE)
                                        length = len;
-                               m_reader->read(length, buffer);
+                               m_reader->read(length, buffer.getBuffer());
                        }
                }
        }
@@ -80,7 +80,7 @@ int AUD_LimiterReader::getPosition() const
        return AUD_MIN(pos, m_end) - m_start;
 }
 
-void AUD_LimiterReader::read(int & length, sample_t* buffer)
+void AUD_LimiterReader::read(int & length, sample_t* buffer)
 {
        if(m_end >= 0)
        {
index f4502c33ae028a048cc06c013dd19cbd7aaf7c1a..660dc26b7a3f2fc99fb40e0a3f5e11747ffc4a69 100644 (file)
@@ -67,7 +67,7 @@ public:
        virtual void seek(int position);
        virtual int getLength() const;
        virtual int getPosition() const;
-       virtual void read(int & length, sample_t* buffer);
+       virtual void read(int & length, sample_t* buffer);
 };
 
 #endif //AUD_LIMITERREADER
index b7b8937abb83f75b8afefbb1a1a4a83f28554cf1..0efee5b55c0b47594fbe5fc86f637c6cd5bf1f0f 100644 (file)
@@ -68,10 +68,9 @@ int AUD_LoopReader::getPosition() const
        return m_reader->getPosition() * (m_count < 0 ? 1 : m_count);
 }
 
-void AUD_LoopReader::read(int & length, sample_t* buffer)
+void AUD_LoopReader::read(int & length, sample_t* buffer)
 {
        AUD_Specs specs = m_reader->getSpecs();
-       int samplesize = AUD_SAMPLE_SIZE(specs);
 
        int len = length;
 
@@ -81,13 +80,6 @@ void AUD_LoopReader::read(int & length, sample_t* & buffer)
        {
                int pos = 0;
 
-               if(m_buffer.getSize() < length * samplesize)
-                       m_buffer.resize(length * samplesize);
-
-               sample_t* buf = m_buffer.getBuffer();
-
-               memcpy(buf + pos * specs.channels, buffer, len * samplesize);
-
                pos += len;
 
                while(pos < length && m_left)
@@ -98,19 +90,16 @@ void AUD_LoopReader::read(int & length, sample_t* & buffer)
                        m_reader->seek(0);
 
                        len = length - pos;
-                       m_reader->read(len, buffer);
+                       m_reader->read(len, buffer + pos * specs.channels);
 
                        // prevent endless loop
                        if(!len)
                                break;
 
-                       memcpy(buf + pos * specs.channels, buffer, len * samplesize);
-
                        pos += len;
                }
 
                length = pos;
-               buffer = buf;
        }
        else
                length = len;
index 866d6f7885ff8c514f9bbb9a51e4aaf93234586a..d1338245df4168d99b3db6ebd7de19a64cf0d125 100644 (file)
 class AUD_LoopReader : public AUD_EffectReader
 {
 private:
-       /**
-        * The playback buffer.
-        */
-       AUD_Buffer m_buffer;
-
        /**
         * The loop count.
         */
@@ -73,7 +68,7 @@ public:
        virtual void seek(int position);
        virtual int getLength() const;
        virtual int getPosition() const;
-       virtual void read(int & length, sample_t* buffer);
+       virtual void read(int & length, sample_t* buffer);
 };
 
 #endif //AUD_LOOPREADER
index 8ca9f8609bb90bd543c5cca6cab8ac12625d9e43..030896d2eaec04a82394b5fe101bbd3529fd08a8 100644 (file)
@@ -60,7 +60,7 @@ int AUD_ReverseReader::getPosition() const
        return m_position;
 }
 
-void AUD_ReverseReader::read(int & length, sample_t* buffer)
+void AUD_ReverseReader::read(int & length, sample_t* buffer)
 {
        // first correct the length
        if(m_position + length > m_length)
@@ -72,36 +72,34 @@ void AUD_ReverseReader::read(int & length, sample_t* & buffer)
                return;
        }
 
-       AUD_Specs specs = getSpecs();
-       int samplesize = AUD_SAMPLE_SIZE(specs);
+       const AUD_Specs specs = getSpecs();
+       const int samplesize = AUD_SAMPLE_SIZE(specs);
 
-       // resize buffer if needed
-       if(m_buffer.getSize() < length * samplesize)
-               m_buffer.resize(length * samplesize);
+       sample_t temp[specs.channels];
 
-       buffer = m_buffer.getBuffer();
-
-       sample_t* buf;
        int len = length;
 
        // read from reader
        m_reader->seek(m_length - m_position - len);
-       m_reader->read(len, buf);
+       m_reader->read(len, buffer);
 
        // set null if reader didn't give enough data
        if(len < length)
-       {
                memset(buffer, 0, (length - len) * samplesize);
-               buffer += (length - len) * specs.channels;
-       }
 
        // copy the samples reverted
-       for(int i = 0; i < len; i++)
+       for(int i = 0; i < length / 2; i++)
+       {
+               memcpy(temp,
+                          buffer + (len - 1 - i) * specs.channels,
+                          samplesize);
+               memcpy(buffer + (len - 1 - i) * specs.channels,
+                          buffer + i * specs.channels,
+                          samplesize);
                memcpy(buffer + i * specs.channels,
-                          buf + (len - 1 - i) * specs.channels,
+                          temp,
                           samplesize);
+       }
 
        m_position += length;
-
-       buffer = m_buffer.getBuffer();
 }
index d8086e0853417e2bd3b2cab350beb8d74a1cd783..8525acaab36aaef4d3bc3f5103296c3d6a4a54e2 100644 (file)
@@ -52,11 +52,6 @@ private:
         */
        int m_position;
 
-       /**
-        * The playback buffer.
-        */
-       AUD_Buffer m_buffer;
-
        // hide copy constructor and operator=
        AUD_ReverseReader(const AUD_ReverseReader&);
        AUD_ReverseReader& operator=(const AUD_ReverseReader&);
@@ -73,7 +68,7 @@ public:
        virtual void seek(int position);
        virtual int getLength() const;
        virtual int getPosition() const;
-       virtual void read(int & length, sample_t* buffer);
+       virtual void read(int & length, sample_t* buffer);
 };
 
 #endif //AUD_REVERSEREADER
index 6f39dcadf405ef022b38c8cc67b97b85fd6e9e3c..3ad2420fc9167f8a51c0ab9253a3de5225495384 100644 (file)
@@ -82,24 +82,22 @@ 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, sample_t* buffer)
 {
        AUD_Specs specs = m_reader1->getSpecs();
        int samplesize = AUD_SAMPLE_SIZE(specs);
 
        if(m_buffer.getSize() < length * samplesize)
                m_buffer.resize(length * samplesize);
-       buffer = m_buffer.getBuffer();
 
        int len1 = length;
-       sample_t* buf;
-       m_reader1->read(len1, buf);
-       memcpy(buffer, buf, len1 * samplesize);
+       m_reader1->read(len1, buffer);
 
        if(len1 < length)
                memset(buffer + len1 * specs.channels, 0, (length - len1) * samplesize);
 
        int len2 = length;
+       sample_t* buf = m_buffer.getBuffer();
        m_reader2->read(len2, buf);
 
        for(int i = 0; i < len2 * specs.channels; i++)
index 26e4b138dfac1c68729faf0abc3269071e6841b0..5a2a2a1d8d1d8431ac1934409eb5fece5392e163 100644 (file)
@@ -80,7 +80,7 @@ public:
        virtual int getLength() const;
        virtual int getPosition() const;
        virtual AUD_Specs getSpecs() const;
-       virtual void read(int & length, sample_t* buffer);
+       virtual void read(int & length, sample_t* buffer);
 };
 
 #endif //AUD_SUPERPOSEREADER
index a3b0bff316ed0f1ddbcf07bf992e1172d403e439..2780f108cdabdb1ba47d9103d849a6942f4a5e07 100644 (file)
@@ -130,7 +130,6 @@ void AUD_OpenALDevice::updateStreams()
        AUD_OpenALHandle* sound;
 
        int length;
-       sample_t* buffer;
 
        ALint info;
        AUD_DeviceSpecs specs = m_specs;
@@ -161,6 +160,8 @@ void AUD_OpenALDevice::updateStreams()
                                        if(info)
                                        {
                                                specs.specs = sound->reader->getSpecs();
+                                               if(m_buffer.getSize() < m_buffersize * AUD_DEVICE_SAMPLE_SIZE(specs))
+                                                       m_buffer.resize(m_buffersize * AUD_DEVICE_SAMPLE_SIZE(specs));
 
                                                // for all empty buffers
                                                while(info--)
@@ -170,7 +171,7 @@ void AUD_OpenALDevice::updateStreams()
                                                        {
                                                                // read data
                                                                length = m_buffersize;
-                                                               sound->reader->read(length, buffer);
+                                                               sound->reader->read(length, m_buffer.getBuffer());
 
                                                                // looping necessary?
                                                                if(length == 0 && sound->loopcount)
@@ -181,7 +182,7 @@ void AUD_OpenALDevice::updateStreams()
                                                                        sound->reader->seek(0);
 
                                                                        length = m_buffersize;
-                                                                       sound->reader->read(length, buffer);
+                                                                       sound->reader->read(length, m_buffer.getBuffer());
                                                                }
 
                                                                // read nothing?
@@ -204,7 +205,7 @@ void AUD_OpenALDevice::updateStreams()
                                                                // fill with new data
                                                                alBufferData(sound->buffers[sound->current],
                                                                                         sound->format,
-                                                                                        buffer, length *
+                                                                                        m_buffer.getBuffer(), length *
                                                                                         AUD_DEVICE_SAMPLE_SIZE(specs),
                                                                                         specs.rate);
 
@@ -581,14 +582,15 @@ AUD_Handle* AUD_OpenALDevice::play(AUD_Reference<AUD_IReader> reader, bool keep)
 
                try
                {
-                       sample_t* buf;
+                       if(m_buffer.getSize() < m_buffersize * AUD_DEVICE_SAMPLE_SIZE(specs))
+                               m_buffer.resize(m_buffersize * AUD_DEVICE_SAMPLE_SIZE(specs));
                        int length;
 
                        for(int i = 0; i < AUD_OPENAL_CYCLE_BUFFERS; i++)
                        {
                                length = m_buffersize;
-                               reader->read(length, buf);
-                               alBufferData(sound->buffers[i], sound->format, buf,
+                               reader->read(length, m_buffer.getBuffer());
+                               alBufferData(sound->buffers[i], sound->format, m_buffer.getBuffer(),
                                                         length * AUD_DEVICE_SAMPLE_SIZE(specs),
                                                         specs.rate);
                                if(alGetError() != AL_NO_ERROR)
@@ -879,17 +881,18 @@ bool AUD_OpenALDevice::seek(AUD_Handle* handle, float position)
                                ALenum err;
                                if((err = alGetError()) == AL_NO_ERROR)
                                {
-                                       sample_t* buf;
                                        int length;
                                        AUD_DeviceSpecs specs = m_specs;
                                        specs.specs = alhandle->reader->getSpecs();
+                                       if(m_buffer.getSize() < m_buffersize * AUD_DEVICE_SAMPLE_SIZE(specs))
+                                               m_buffer.resize(m_buffersize * AUD_DEVICE_SAMPLE_SIZE(specs));
 
                                        for(int i = 0; i < AUD_OPENAL_CYCLE_BUFFERS; i++)
                                        {
                                                length = m_buffersize;
-                                               alhandle->reader->read(length, buf);
+                                               alhandle->reader->read(length, m_buffer.getBuffer());
                                                alBufferData(alhandle->buffers[i], alhandle->format,
-                                                                        buf,
+                                                                        m_buffer.getBuffer(),
                                                                         length * AUD_DEVICE_SAMPLE_SIZE(specs),
                                                                         specs.rate);
 
index 3bca47f18052a9012f527aab30050a9ee15a1f3e..d5db5989fe779aef7030a158262ba5c121d56c72 100644 (file)
@@ -34,6 +34,7 @@
 
 #include "AUD_IDevice.h"
 #include "AUD_I3DDevice.h"
+#include "AUD_Buffer.h"
 struct AUD_OpenALHandle;
 struct AUD_OpenALBufferedFactory;
 
@@ -103,6 +104,11 @@ private:
         */
        int m_buffersize;
 
+       /**
+        * Device buffer.
+        */
+       AUD_Buffer m_buffer;
+
        /**
         * Starts the streaming thread.
         */
index e9a94418b6057e749bd93ecb9d880dae1af0624c..42696a1caaacd7e500c4091926d6b35289eeaa2e 100644 (file)
@@ -75,11 +75,10 @@ AUD_SRCResampleReader::~AUD_SRCResampleReader()
 long AUD_SRCResampleReader::doCallback(float** data)
 {
        int length = m_buffer.getSize() / AUD_SAMPLE_SIZE(m_tspecs);
-       sample_t* buffer;
 
-       m_reader->read(length, buffer);
+       *data = m_buffer.getBuffer();
+       m_reader->read(length, *data);
 
-       *data = buffer;
        return length;
 }
 
@@ -105,15 +104,13 @@ AUD_Specs AUD_SRCResampleReader::getSpecs() const
        return m_tspecs;
 }
 
-void AUD_SRCResampleReader::read(int & length, sample_t* buffer)
+void AUD_SRCResampleReader::read(int & length, sample_t* buffer)
 {
        int size = length * AUD_SAMPLE_SIZE(m_tspecs);
 
        if(m_buffer.getSize() < size)
                m_buffer.resize(size);
 
-       buffer = m_buffer.getBuffer();
-
        length = src_callback_read(m_src, m_factor, length, buffer);
 
        m_position += length;
index 21193661911a5418429152e446daa53c1c80d8cf..2d67e636bd70f7a1dfa472e2d47bb73663b781d7 100644 (file)
@@ -104,7 +104,7 @@ public:
        virtual int getLength() const;
        virtual int getPosition() const;
        virtual AUD_Specs getSpecs() const;
-       virtual void read(int & length, sample_t* buffer);
+       virtual void read(int & length, sample_t* buffer);
 };
 
 #endif //AUD_SRCRESAMPLEREADER
index ed6ca5d142ff04991a5aab3a7d7c5264dbb17c31..bacbbf2a725971f4a5d929d91a4ca8eaaa315486 100644 (file)
@@ -341,14 +341,14 @@ void AUD_FFMPEGReader::seek(int position)
                                                {
                                                        // read until we're at the right position
                                                        int length = AUD_DEFAULT_BUFFER_SIZE;
-                                                       sample_t* buffer;
+                                                       AUD_Buffer buffer(length * AUD_SAMPLE_SIZE(m_specs));
                                                        for(int len = position - m_position;
                                                                length == AUD_DEFAULT_BUFFER_SIZE;
                                                                len -= AUD_DEFAULT_BUFFER_SIZE)
                                                        {
                                                                if(len < AUD_DEFAULT_BUFFER_SIZE)
                                                                        length = len;
-                                                               read(length, buffer);
+                                                               read(length, buffer.getBuffer());
                                                        }
                                                }
                                        }
@@ -381,7 +381,7 @@ AUD_Specs AUD_FFMPEGReader::getSpecs() const
        return m_specs.specs;
 }
 
-void AUD_FFMPEGReader::read(int & length, sample_t* buffer)
+void AUD_FFMPEGReader::read(int & length, sample_t* buffer)
 {
        // read packages and decode them
        AVPacket packet;
@@ -390,11 +390,7 @@ void AUD_FFMPEGReader::read(int & length, sample_t* & buffer)
        int left = length;
        int sample_size = AUD_DEVICE_SAMPLE_SIZE(m_specs);
 
-       // resize output buffer if necessary
-       if(m_buffer.getSize() < length * AUD_SAMPLE_SIZE(m_specs))
-               m_buffer.resize(length * AUD_SAMPLE_SIZE(m_specs));
-
-       buffer = m_buffer.getBuffer();
+       sample_t* buf = buffer;
        pkgbuf_pos = m_pkgbuf_left;
        m_pkgbuf_left = 0;
 
@@ -402,9 +398,9 @@ void AUD_FFMPEGReader::read(int & length, sample_t* & buffer)
        if(pkgbuf_pos > 0)
        {
                data_size = AUD_MIN(pkgbuf_pos, left * sample_size);
-               m_convert((data_t*) buffer, (data_t*) m_pkgbuf.getBuffer(),
+               m_convert((data_t*) buf, (data_t*) m_pkgbuf.getBuffer(),
                                  data_size / AUD_FORMAT_SIZE(m_specs.format));
-               buffer += data_size / AUD_FORMAT_SIZE(m_specs.format);
+               buf += data_size / AUD_FORMAT_SIZE(m_specs.format);
                left -= data_size/sample_size;
        }
 
@@ -419,9 +415,9 @@ void AUD_FFMPEGReader::read(int & length, sample_t* & buffer)
 
                        // copy to output buffer
                        data_size = AUD_MIN(pkgbuf_pos, left * sample_size);
-                       m_convert((data_t*) buffer, (data_t*) m_pkgbuf.getBuffer(),
+                       m_convert((data_t*) buf, (data_t*) m_pkgbuf.getBuffer(),
                                          data_size / AUD_FORMAT_SIZE(m_specs.format));
-                       buffer += data_size / AUD_FORMAT_SIZE(m_specs.format);
+                       buf += data_size / AUD_FORMAT_SIZE(m_specs.format);
                        left -= data_size/sample_size;
                }
                av_free_packet(&packet);
@@ -435,8 +431,6 @@ void AUD_FFMPEGReader::read(int & length, sample_t* & buffer)
                                pkgbuf_pos-data_size);
        }
 
-       buffer = m_buffer.getBuffer();
-
        if(left > 0)
                length -= left;
        m_position += length;
index 26e66859451c92ba550bc283d890ac3116bf2d4d..c5bfd11dcbce40740a7aba7b91241b355818c091 100644 (file)
@@ -60,11 +60,6 @@ private:
         */
        int m_position;
 
-       /**
-        * The playback buffer.
-        */
-       AUD_Buffer m_buffer;
-
        /**
         * The specification of the audio data.
         */
@@ -167,7 +162,7 @@ public:
        virtual int getLength() const;
        virtual int getPosition() const;
        virtual AUD_Specs getSpecs() const;
-       virtual void read(int & length, sample_t* buffer);
+       virtual void read(int & length, sample_t* buffer);
 };
 
 #endif //AUD_FFMPEGREADER
index 0ac967b29b0d412984694c4302e4253731f04515..08ed52ea497aec12a6f4b987246da00a2e6bedd9 100644 (file)
@@ -33,6 +33,8 @@
 #include "AUD_Buffer.h"
 #include "AUD_Space.h"
 
+#include <cstring>
+
 AUD_BufferReader::AUD_BufferReader(AUD_Reference<AUD_Buffer> buffer,
                                                                   AUD_Specs specs) :
        m_position(0), m_buffer(buffer), m_specs(specs)
@@ -64,17 +66,22 @@ AUD_Specs AUD_BufferReader::getSpecs() const
        return m_specs;
 }
 
-void AUD_BufferReader::read(int & length, sample_t* buffer)
+void AUD_BufferReader::read(int & length, sample_t* buffer)
 {
        int sample_size = AUD_SAMPLE_SIZE(m_specs);
 
-       buffer = m_buffer->getBuffer() + m_position * m_specs.channels;
+       sample_t* buf = m_buffer->getBuffer() + m_position * m_specs.channels;
 
        // in case the end of the buffer is reached
        if(m_buffer->getSize() < (m_position + length) * sample_size)
                length = m_buffer->getSize() / sample_size - m_position;
 
        if(length < 0)
+       {
                length = 0;
+               return;
+       }
+
        m_position += length;
+       memcpy(buffer, buf, length * sample_size);
 }
index 3369672703c9a43fd240e03e337f2eae0aa075b7..16d7136ab63d0b04db40ad2e855e063afc35d52d 100644 (file)
@@ -76,7 +76,7 @@ public:
        virtual int getLength() const;
        virtual int getPosition() const;
        virtual AUD_Specs getSpecs() const;
-       virtual void read(int & length, sample_t* buffer);
+       virtual void read(int & length, sample_t* buffer);
 };
 
 #endif //AUD_BUFFERREADER
index 08fb55f760581466dbe7aa45229108fe7bc22179..b0050abe7aca26a7c875adda067dca7f28679349 100644 (file)
@@ -778,13 +778,11 @@ float* AUD_readSoundBuffer(const char* filename, float low, float high,
 
        int len;
        int position = 0;
-       sample_t* readbuffer;
        do
        {
                len = samplerate;
                buffer.resize((position + len) * sizeof(float), true);
-               reader->read(len, readbuffer);
-               memcpy(buffer.getBuffer() + position, readbuffer, len * sizeof(float));
+               reader->read(len, buffer.getBuffer() + position);
                position += len;
        } while(len != 0);
 
@@ -868,6 +866,7 @@ int AUD_readSound(AUD_Sound* sound, sample_t* buffer, int length)
 {
        AUD_DeviceSpecs specs;
        sample_t* buf;
+       AUD_Buffer aBuffer;
 
        specs.rate = AUD_RATE_INVALID;
        specs.channels = AUD_CHANNELS_MONO;
@@ -882,6 +881,13 @@ int AUD_readSound(AUD_Sound* sound, sample_t* buffer, int length)
        for(int i = 0; i < length; i++)
        {
                len = floor(samplejump * (i+1)) - floor(samplejump * i);
+
+               if(aBuffer.getSize() < len * AUD_SAMPLE_SIZE(reader->getSpecs()))
+               {
+                       aBuffer.resize(len * AUD_SAMPLE_SIZE(reader->getSpecs()));
+                       buf = aBuffer.getBuffer();
+               }
+
                reader->read(len, buf);
 
                if(len < 1)
index 3079d31c9e9d76f729e03adc008d1f38ca08242d..a70eebc192c4978fbe2f54a01900fa1521db564f 100644 (file)
@@ -76,16 +76,15 @@ AUD_Specs AUD_ChannelMapperReader::getSpecs() const
        return m_specs;
 }
 
-void AUD_ChannelMapperReader::read(int & length, sample_t* buffer)
+void AUD_ChannelMapperReader::read(int & length, sample_t* buffer)
 {
-       sample_t* in = buffer;
+       if(m_buffer.getSize() < length * m_rch * sizeof(sample_t))
+               m_buffer.resize(length * m_rch * sizeof(sample_t));
 
-       m_reader->read(length, in);
+       sample_t* in = m_buffer.getBuffer();
 
-       if(m_buffer.getSize() < length * AUD_SAMPLE_SIZE(m_specs))
-               m_buffer.resize(length * AUD_SAMPLE_SIZE(m_specs));
+       m_reader->read(length, in);
 
-       buffer = m_buffer.getBuffer();
        sample_t sum;
 
        for(int i = 0; i < length; i++)
index 1c7dba1df7c851a68647ec87c05e0066694e20d6..31c22b8cf5aaf7e4d7cf25438505db04914be772 100644 (file)
@@ -43,7 +43,7 @@ class AUD_ChannelMapperReader : public AUD_EffectReader
 {
 private:
        /**
-        * The sound output buffer.
+        * The sound reading buffer.
         */
        AUD_Buffer m_buffer;
 
@@ -80,7 +80,7 @@ public:
        ~AUD_ChannelMapperReader();
 
        virtual AUD_Specs getSpecs() const;
-       virtual void read(int & length, sample_t* buffer);
+       virtual void read(int & length, sample_t* buffer);
 };
 
 #endif //AUD_CHANNELMAPPERREADER
index 6927f3e969c339b20de0afd2e3bc8e2cfee68c15..7e0246f5d621c4d25c6a52dc0fbc7d34953614b3 100644 (file)
@@ -75,17 +75,15 @@ AUD_Specs AUD_ConverterReader::getSpecs() const
        return m_specs.specs;
 }
 
-void AUD_ConverterReader::read(int & length, sample_t* buffer)
+void AUD_ConverterReader::read(int & length, sample_t* buffer)
 {
-       m_reader->read(length, buffer);
-
-       int samplesize = AUD_SAMPLE_SIZE(m_specs);
+       int samplesize = AUD_SAMPLE_SIZE(m_reader->getSpecs());
 
        if(m_buffer.getSize() < length * samplesize)
                m_buffer.resize(length * samplesize);
 
-       m_convert((data_t*)m_buffer.getBuffer(), (data_t*)buffer,
-                         length * m_specs.channels);
+       m_reader->read(length, m_buffer.getBuffer());
 
-       buffer = m_buffer.getBuffer();
+       m_convert((data_t*)buffer, (data_t*)m_buffer.getBuffer(),
+                         length * m_specs.channels);
 }
index 6f252b5f9f921cba328d89926a96de7bc2c99013..958fe6d1897ce24276bebdbd231355c45538b0ae 100644 (file)
@@ -70,7 +70,7 @@ public:
        AUD_ConverterReader(AUD_Reference<AUD_IReader> reader, AUD_DeviceSpecs specs);
 
        virtual AUD_Specs getSpecs() const;
-       virtual void read(int & length, sample_t* buffer);
+       virtual void read(int & length, sample_t* buffer);
 };
 
 #endif //AUD_CONVERTERREADER
index 7c31c5939644c9df467c8f333fb71d89a9ff8ba8..01baf13f540427b1f7d2dd4706a156ec60553876 100644 (file)
@@ -100,7 +100,7 @@ public:
         *                A smaller value also indicates the end of the reader.
         * \param[out] buffer The pointer to the buffer with the samples.
         */
-       virtual void read(int & length, sample_t* buffer)=0;
+       virtual void read(int & length, sample_t* buffer)=0;
 };
 
 #endif //AUD_IREADER
index 6217826eeec942d886c293988338b831f06df4c5..6cb1d946ea386c23153c3cf2a27de391e511c1bc 100644 (file)
@@ -71,18 +71,17 @@ AUD_Specs AUD_LinearResampleReader::getSpecs() const
        return m_tspecs;
 }
 
-void AUD_LinearResampleReader::read(int & length, sample_t* buffer)
+void AUD_LinearResampleReader::read(int & length, sample_t* buffer)
 {
        int samplesize = AUD_SAMPLE_SIZE(m_tspecs);
-       int size = length * samplesize;
+       int size = length * AUD_SAMPLE_SIZE(m_sspecs);
 
        if(m_buffer.getSize() < size)
                m_buffer.resize(size);
 
        int need = ceil((m_position + length) / m_factor) + 1 - m_sposition;
        int len = need;
-       sample_t* buf;
-       buffer = m_buffer.getBuffer();
+       sample_t* buf = m_buffer.getBuffer();
 
        m_reader->read(len, buf);
 
index fdf7858f97f7b43e852cbc99f5e89ca06b8a6df9..f673cd0ee661c90041a7745a6ab74aa3e9eb9fdd 100644 (file)
@@ -92,7 +92,7 @@ public:
        virtual int getLength() const;
        virtual int getPosition() const;
        virtual AUD_Specs getSpecs() const;
-       virtual void read(int & length, sample_t* buffer);
+       virtual void read(int & length, sample_t* buffer);
 };
 
 #endif //AUD_LINEARRESAMPLEREADER
index 03488ac46b1a7eedb77a53824b5dc1d21db8613c..880e9d22e96e7f5721c64ac3e036932bf3206b09 100644 (file)
@@ -73,43 +73,33 @@ AUD_DeviceSpecs AUD_Mixer::getSpecs() const
        return m_specs;
 }
 
-void AUD_Mixer::add(sample_t* buffer, int start, int length, float volume)
+void AUD_Mixer::clear(int length)
 {
-       AUD_MixerBuffer buf;
-       buf.buffer = buffer;
-       buf.start = start;
-       buf.length = length;
-       buf.volume = volume;
-       m_buffers.push_back(buf);
-}
-
-void AUD_Mixer::superpose(data_t* buffer, int length, float volume)
-{
-       AUD_MixerBuffer buf;
+       if(m_buffer.getSize() < length * m_specs.channels * AUD_SAMPLE_SIZE(m_specs))
+               m_buffer.resize(length * m_specs.channels * AUD_SAMPLE_SIZE(m_specs));
 
-       int channels = m_specs.channels;
+       m_length = length;
 
-       if(m_buffer.getSize() < length * channels * 4)
-               m_buffer.resize(length * channels * 4);
+       memset(m_buffer.getBuffer(), 0, length * m_specs.channels * AUD_SAMPLE_SIZE(m_specs));
+}
 
+void AUD_Mixer::mix(sample_t* buffer, int start, int length, float volume)
+{
        sample_t* out = m_buffer.getBuffer();
-       sample_t* in;
-
-       memset(out, 0, length * channels * 4);
 
-       int end;
+       length = (AUD_MIN(m_length, length + start) - start) * m_specs.channels;
+       start += m_specs.channels;
 
-       while(!m_buffers.empty())
-       {
-               buf = m_buffers.front();
-               m_buffers.pop_front();
+       for(int i = 0; i < length; i++)
+               out[i + start] += buffer[i] * volume;
+}
 
-               end = buf.length * channels;
-               in = buf.buffer;
+void AUD_Mixer::read(data_t* buffer, float volume)
+{
+       sample_t* out = m_buffer.getBuffer();
 
-               for(int i = 0; i < end; i++)
-                       out[i + buf.start * channels] += in[i] * buf.volume * volume;
-       }
+       for(int i = 0; i < m_length * m_specs.channels; i++)
+               out[i] *= volume;
 
-       m_convert(buffer, (data_t*) out, length * channels);
+       m_convert(buffer, (data_t*) out, m_length * m_specs.channels);
 }
index d8c4dde26856e5f57f5bc7b2d79bd3d155a0e3af..9e2be46145290cdf339512853194b1164f3894ad 100644 (file)
 #include "AUD_Buffer.h"
 #include "AUD_Reference.h"
 class AUD_IReader;
-#include <list>
-
-struct AUD_MixerBuffer
-{
-       sample_t* buffer;
-       int start;
-       int length;
-       float volume;
-};
 
 /**
  * This abstract class is able to mix audiosignals of different channel count
@@ -54,17 +45,17 @@ class AUD_Mixer
 {
 protected:
        /**
-        * The list of buffers to superpose.
+        * The output specification.
         */
-       std::list<AUD_MixerBuffer> m_buffers;
+       const AUD_DeviceSpecs m_specs;
 
        /**
-        * The output specification.
+        * The length of the mixing buffer.
         */
-       const AUD_DeviceSpecs m_specs;
+       int m_length;
 
        /**
-        * The temporary mixing buffer.
+        * The mixing buffer.
         */
        AUD_Buffer m_buffer;
 
@@ -98,21 +89,26 @@ public:
        virtual AUD_Reference<AUD_IReader> prepare(AUD_Reference<AUD_IReader> reader)=0;
 
        /**
-        * Adds a buffer for superposition.
+        * Mixes a buffer.
         * \param buffer The buffer to superpose.
         * \param start The start sample of the buffer.
         * \param length The length of the buffer in samples.
         * \param volume The mixing volume. Must be a value between 0.0 and 1.0.
         */
-       virtual void add(sample_t* buffer, int start, int length, float volume);
+       virtual void mix(sample_t* buffer, int start, int length, float volume);
 
        /**
-        * Superposes all added buffers into an output buffer.
+        * Writes the mixing buffer into an output buffer.
         * \param buffer The target buffer for superposing.
-        * \param length The length of the buffer in samples.
         * \param volume The mixing volume. Must be a value between 0.0 and 1.0.
         */
-       virtual void superpose(data_t* buffer, int length, float volume);
+       virtual void read(data_t* buffer, float volume);
+
+       /**
+        * Clears the mixing buffer.
+        * \param length The length of the buffer in samples.
+        */
+       virtual void clear(int length);
 };
 
 #endif //AUD_MIXER
index b7cbdda544e980832f6de804998e74d73f6fb220..794a524c5275d3daf83bfbbdab36f957697b65dc 100644 (file)
@@ -113,21 +113,17 @@ AUD_Specs AUD_SequencerReader::getSpecs() const
        return m_mixer->getSpecs().specs;
 }
 
-void AUD_SequencerReader::read(int & length, sample_t* buffer)
+void AUD_SequencerReader::read(int & length, sample_t* buffer)
 {
        AUD_DeviceSpecs specs = m_mixer->getSpecs();
-       int samplesize = AUD_SAMPLE_SIZE(specs);
        int rate = specs.rate;
 
-       int size = length * samplesize;
-
        int start, end, current, skip, len;
        AUD_Reference<AUD_SequencerStrip> strip;
-       sample_t* buf;
+       if(m_buffer.getSize() < length * AUD_SAMPLE_SIZE(specs))
+               m_buffer.resize(length * AUD_SAMPLE_SIZE(specs));
 
-       if(m_buffer.getSize() < size)
-               m_buffer.resize(size);
-       buffer = m_buffer.getBuffer();
+       m_mixer->clear(length);
 
        if(!m_factory->getMute())
        {
@@ -176,8 +172,8 @@ void AUD_SequencerReader::read(int & length, sample_t* & buffer)
                                                        len -= skip;
                                                        if(strip->reader->getPosition() != current)
                                                                strip->reader->seek(current);
-                                                       strip->reader->read(len, buf);
-                                                       m_mixer->add(buf, skip, len, m_volume(m_data, strip->entry->data, (float)m_position / (float)rate));
+                                                       strip->reader->read(len, m_buffer.getBuffer());
+                                                       m_mixer->mix(m_buffer.getBuffer(), skip, len, m_volume(m_data, strip->entry->data, (float)m_position / (float)rate));
                                                }
                                        }
                                }
@@ -185,7 +181,7 @@ void AUD_SequencerReader::read(int & length, sample_t* & buffer)
                }
        }
 
-       m_mixer->superpose((data_t*)buffer, length, 1.0f);
+       m_mixer->read((data_t*)buffer, 1.0f);
 
        m_position += length;
 }
index 2efb94aa1fbafcd8b4dd593c529d047a6b5545bc..8b90c27ed9e80a9267ecadc03b98307b792099a6 100644 (file)
@@ -56,7 +56,7 @@ private:
        int m_position;
 
        /**
-        * The sound output buffer.
+        * The reading buffer.
         */
        AUD_Buffer m_buffer;
 
@@ -100,7 +100,7 @@ public:
        virtual int getLength() const;
        virtual int getPosition() const;
        virtual AUD_Specs getSpecs() const;
-       virtual void read(int & length, sample_t* buffer);
+       virtual void read(int & length, sample_t* buffer);
 };
 
 #endif //AUD_SEQUENCERREADER
index bdff4fe75a63486d149e92690f20d8e84f6e6807..cd109c2352cf65631af646174e346169f043f2bd 100644 (file)
@@ -66,15 +66,8 @@ AUD_Specs AUD_SilenceReader::getSpecs() const
        return specs;
 }
 
-void AUD_SilenceReader::read(int & length, sample_t* buffer)
+void AUD_SilenceReader::read(int & length, sample_t* buffer)
 {
-       // resize if necessary
-       if(m_buffer.getSize() < length * sizeof(sample_t))
-       {
-               m_buffer.resize(length * sizeof(sample_t));
-               memset(m_buffer.getBuffer(), 0, m_buffer.getSize());
-       }
-
-       buffer = m_buffer.getBuffer();
+       memset(buffer, 0, length * sizeof(sample_t));
        m_position += length;
 }
index b35b4cfab42f450a7d2b210cc846379798dca4ab..753cda896be48ed1301ec142834cad1eadcc97bb 100644 (file)
@@ -51,11 +51,6 @@ private:
         */
        int m_position;
 
-       /**
-        * The playback buffer.
-        */
-       AUD_Buffer m_buffer;
-
        // hide copy constructor and operator=
        AUD_SilenceReader(const AUD_SilenceReader&);
        AUD_SilenceReader& operator=(const AUD_SilenceReader&);
@@ -71,7 +66,7 @@ public:
        virtual int getLength() const;
        virtual int getPosition() const;
        virtual AUD_Specs getSpecs() const;
-       virtual void read(int & length, sample_t* buffer);
+       virtual void read(int & length, sample_t* buffer);
 };
 
 #endif //AUD_SILENCEREADER
index f32464f067a5d5d27906e0601eb6090bab6575ea..d8acd0f1a8f684874431b3c5bc7699232951717f 100644 (file)
@@ -72,14 +72,9 @@ AUD_Specs AUD_SinusReader::getSpecs() const
        return specs;
 }
 
-void AUD_SinusReader::read(int & length, sample_t* buffer)
+void AUD_SinusReader::read(int & length, sample_t* buffer)
 {
-       // resize if necessary
-       if(m_buffer.getSize() < length * sizeof(sample_t))
-               m_buffer.resize(length * sizeof(sample_t));
-
        // fill with sine data
-       buffer = m_buffer.getBuffer();
        for(int i = 0; i < length; i++)
        {
                buffer[i] = sin((m_position + i) * 2 * M_PI * m_frequency /
index e807f03226d5ab7a747266ac217164d4078b7977..dca00c156377927573f00529d1d4b2fb156479d9 100644 (file)
@@ -56,11 +56,6 @@ private:
         */
        int m_position;
 
-       /**
-        * The playback buffer.
-        */
-       AUD_Buffer m_buffer;
-
        /**
         * The sample rate for the output.
         */
@@ -83,7 +78,7 @@ public:
        virtual int getLength() const;
        virtual int getPosition() const;
        virtual AUD_Specs getSpecs() const;
-       virtual void read(int & length, sample_t* buffer);
+       virtual void read(int & length, sample_t* buffer);
 };
 
 #endif //AUD_SINUSREADER
index 82bb584158014c29ab84a349601b9486ffb8f6f3..ff744f74973d9c3de6972862b9dcdf3cbfd10b29 100644 (file)
@@ -104,17 +104,19 @@ void AUD_SoftwareDevice::destroy()
 
 void AUD_SoftwareDevice::mix(data_t* buffer, int length)
 {
+       if(m_buffer.getSize() < length * AUD_SAMPLE_SIZE(m_specs))
+               m_buffer.resize(length * AUD_SAMPLE_SIZE(m_specs));
+
        lock();
 
        {
                AUD_SoftwareHandle* sound;
                int len;
                int pos;
-               sample_t* buf;
                std::list<AUD_SoftwareHandle*> stopSounds;
-               std::list<AUD_Buffer*> tempBufs;
-               AUD_Buffer* tempbuf;
-               int samplesize = AUD_SAMPLE_SIZE(m_specs);
+               sample_t* buf = m_buffer.getBuffer();
+
+               m_mixer->clear(length);
 
                // for all sounds
                AUD_HandleIterator it = m_playingSounds.begin();
@@ -128,15 +130,13 @@ void AUD_SoftwareDevice::mix(data_t* buffer, int length)
                        // get the buffer from the source
                        pos = 0;
                        len = length;
+
                        sound->reader->read(len, buf);
 
                        // in case of looping
                        while(pos + len < length && sound->loopcount)
                        {
-                               tempbuf = new AUD_Buffer(len * samplesize);
-                               memcpy(tempbuf->getBuffer(), buf, len * samplesize);
-                               tempBufs.push_back(tempbuf);
-                               m_mixer->add(tempbuf->getBuffer(), pos, len, sound->volume);
+                               m_mixer->mix(buf, pos, len, sound->volume);
 
                                pos += len;
 
@@ -153,7 +153,7 @@ void AUD_SoftwareDevice::mix(data_t* buffer, int length)
                                        break;
                        }
 
-                       m_mixer->add(buf, pos, len, sound->volume);
+                       m_mixer->mix(buf, pos, len, sound->volume);
                        pos += len;
 
                        // in case the end of the sound is reached
@@ -170,7 +170,7 @@ void AUD_SoftwareDevice::mix(data_t* buffer, int length)
                }
 
                // superpose
-               m_mixer->superpose(buffer, length, m_volume);
+               m_mixer->read(buffer, m_volume);
 
                // cleanup
                while(!stopSounds.empty())
@@ -179,13 +179,6 @@ void AUD_SoftwareDevice::mix(data_t* buffer, int length)
                        stopSounds.pop_front();
                        stop(sound);
                }
-
-               while(!tempBufs.empty())
-               {
-                       tempbuf = tempBufs.front();
-                       tempBufs.pop_front();
-                       delete tempbuf;
-               }
        }
 
        unlock();
index 6cbc6e3ddc66a057754662de9b8fc6a7bb3c05b5..6518afe6737e5140c58272551c1217d2ce941f1d 100644 (file)
@@ -34,8 +34,8 @@
 
 #include "AUD_IDevice.h"
 #include "AUD_Mixer.h"
+#include "AUD_Buffer.h"
 struct AUD_SoftwareHandle;
-class AUD_Buffer;
 
 #include <list>
 #include <pthread.h>
@@ -85,6 +85,11 @@ protected:
        virtual void playing(bool playing)=0;
 
 private:
+       /**
+        * The reading buffer.
+        */
+       AUD_Buffer m_buffer;
+
        /**
         * The list of sounds that are currently playing.
         */
index 5c4e024917be1a46141ea822249777c6d42ea44b..1b96c97742bfdafecdd26cdc275dd1754c070bda 100644 (file)
@@ -45,7 +45,6 @@ AUD_StreamBufferFactory::AUD_StreamBufferFactory(AUD_Reference<AUD_IFactory> fac
        int sample_size = AUD_SAMPLE_SIZE(m_specs);
        int length;
        int index = 0;
-       sample_t* buffer;
 
        // get an approximated size if possible
        int size = reader->getLength();
@@ -63,10 +62,7 @@ AUD_StreamBufferFactory::AUD_StreamBufferFactory(AUD_Reference<AUD_IFactory> fac
 
                // read more
                length = size-index;
-               reader->read(length, buffer);
-               memcpy(m_buffer->getBuffer() + index * m_specs.channels,
-                          buffer,
-                          length * sample_size);
+               reader->read(length, m_buffer->getBuffer() + index * m_specs.channels);
                size += AUD_BUFFER_RESIZE_BYTES / sample_size;
                index += length;
        }
index 03a740f5fbf78c28f4531465e3592c5cd61714b1..a8b2625b848b8c4dfa08a30ff4a926d8d80457fe 100644 (file)
@@ -28,8 +28,6 @@
  *  \ingroup audjack
  */
 
-
-#include "AUD_Mixer.h"
 #include "AUD_JackDevice.h"
 #include "AUD_IReader.h"
 
index 7b5fd7b0f4564bcdbe3d1ff365aa9a3e8fee420f..cfe42b0725d71df4987f4cd47f2faa3596dbc3ad 100644 (file)
@@ -161,16 +161,8 @@ AUD_Specs AUD_SndFileReader::getSpecs() const
        return m_specs;
 }
 
-void AUD_SndFileReader::read(int & length, sample_t* buffer)
+void AUD_SndFileReader::read(int & length, sample_t* buffer)
 {
-       int sample_size = AUD_SAMPLE_SIZE(m_specs);
-
-       // resize output buffer if necessary
-       if(m_buffer.getSize() < length*sample_size)
-               m_buffer.resize(length*sample_size);
-
-       buffer = m_buffer.getBuffer();
-
        length = sf_readf_float(m_sndfile, buffer, length);
 
        m_position += length;
index af095819c0ed94777caef81831537888aa60d369..54ab05c63dad6912bfc38bef0aed14363d29552e 100644 (file)
@@ -67,11 +67,6 @@ private:
         */
        AUD_Specs m_specs;
 
-       /**
-        * The playback buffer.
-        */
-       AUD_Buffer m_buffer;
-
        /**
         * The sndfile.
         */
@@ -129,7 +124,7 @@ public:
        virtual int getLength() const;
        virtual int getPosition() const;
        virtual AUD_Specs getSpecs() const;
-       virtual void read(int & length, sample_t* buffer);
+       virtual void read(int & length, sample_t* buffer);
 };
 
 #endif //AUD_SNDFILEREADER