3D Audio GSoC:
authorJoerg Mueller <nexyon@gmail.com>
Tue, 21 Jun 2011 20:13:27 +0000 (20:13 +0000)
committerJoerg Mueller <nexyon@gmail.com>
Tue, 21 Jun 2011 20:13:27 +0000 (20:13 +0000)
Buffer.assureSize - a function that should long have been there.

12 files changed:
intern/audaspace/FX/AUD_SuperposeReader.cpp
intern/audaspace/OpenAL/AUD_OpenALDevice.cpp
intern/audaspace/SRC/AUD_SRCResampleReader.cpp
intern/audaspace/fftw/AUD_BandPassReader.cpp
intern/audaspace/intern/AUD_Buffer.cpp
intern/audaspace/intern/AUD_Buffer.h
intern/audaspace/intern/AUD_ChannelMapperReader.cpp
intern/audaspace/intern/AUD_ConverterReader.cpp
intern/audaspace/intern/AUD_LinearResampleReader.cpp
intern/audaspace/intern/AUD_Mixer.cpp
intern/audaspace/intern/AUD_SequencerReader.cpp
intern/audaspace/intern/AUD_SoftwareDevice.cpp

index 3ad2420fc9167f8a51c0ab9253a3de5225495384..49e29d2b0f9d3f951956a4ed128019c0eda2a5ef 100644 (file)
@@ -87,8 +87,7 @@ 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);
+       m_buffer.assureSize(length * samplesize);
 
        int len1 = length;
        m_reader1->read(len1, buffer);
index 2780f108cdabdb1ba47d9103d849a6942f4a5e07..18c50d292258cd1930bf22c354a02a7379396e9c 100644 (file)
@@ -160,8 +160,7 @@ 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));
+                                               m_buffer.assureSize(m_buffersize * AUD_DEVICE_SAMPLE_SIZE(specs));
 
                                                // for all empty buffers
                                                while(info--)
@@ -582,8 +581,7 @@ AUD_Handle* AUD_OpenALDevice::play(AUD_Reference<AUD_IReader> reader, bool keep)
 
                try
                {
-                       if(m_buffer.getSize() < m_buffersize * AUD_DEVICE_SAMPLE_SIZE(specs))
-                               m_buffer.resize(m_buffersize * AUD_DEVICE_SAMPLE_SIZE(specs));
+                       m_buffer.assureSize(m_buffersize * AUD_DEVICE_SAMPLE_SIZE(specs));
                        int length;
 
                        for(int i = 0; i < AUD_OPENAL_CYCLE_BUFFERS; i++)
@@ -884,8 +882,7 @@ bool AUD_OpenALDevice::seek(AUD_Handle* handle, float position)
                                        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));
+                                       m_buffer.assureSize(m_buffersize * AUD_DEVICE_SAMPLE_SIZE(specs));
 
                                        for(int i = 0; i < AUD_OPENAL_CYCLE_BUFFERS; i++)
                                        {
index 42696a1caaacd7e500c4091926d6b35289eeaa2e..85f935bab8ee5ef3a810119c8ed7d23426f993a9 100644 (file)
@@ -108,8 +108,7 @@ 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);
+       m_buffer.assureSize(size);
 
        length = src_callback_read(m_src, m_factor, length, buffer);
 
index 06f0a2af0adc0a11ff95e678aab5373f94b8d01b..22c65b18d7670f61932065d200f043881dbafd40 100644 (file)
@@ -71,8 +71,7 @@ void AUD_BandPassReader::read(int & length, sample_t* & buffer)
 
        if(length > 0)
        {
-               if(length * AUD_SAMPLE_SIZE(specs) > m_buffer->getSize())
-                       m_buffer->resize(length * AUD_SAMPLE_SIZE(specs));
+               m_buffer->assureSize(length * AUD_SAMPLE_SIZE(specs));
 
                if(length != m_length)
                {
index 37c05fd1cc03d3195b9f49ac16675b6a759fd911..43955b5498854eff706b5f749094f61e07f5fa68 100644 (file)
@@ -74,3 +74,9 @@ void AUD_Buffer::resize(int size, bool keep)
 
        m_size = size;
 }
+
+void AUD_Buffer::assureSize(int size, bool keep)
+{
+       if(m_size < size)
+               resize(size, keep);
+}
index 9b199d82fbb07b24b363764d31565dc137d9b74c..4a37bc1746421b3a7e9ced2c000830bff9c93560 100644 (file)
@@ -80,6 +80,16 @@ public:
         *        the data at the end will be lost.
         */
        void resize(int size, bool keep = false);
+
+       /**
+        * Makes sure the buffer has a minimum size.
+        * If size is >= current size, nothing will happen.
+        * Otherwise the buffer is resized with keep as parameter.
+        * \param size The new minimum size of the buffer, measured in bytes.
+        * \param keep Whether to keep the old data. If the new buffer is smaller,
+        *        the data at the end will be lost.
+        */
+       void assureSize(int size, bool keep = false);
 };
 
 #endif //AUD_BUFFER
index a70eebc192c4978fbe2f54a01900fa1521db564f..bfc5596bb21d676354ab49932a9e25394c81aded 100644 (file)
@@ -78,8 +78,7 @@ AUD_Specs AUD_ChannelMapperReader::getSpecs() const
 
 void AUD_ChannelMapperReader::read(int & length, sample_t* buffer)
 {
-       if(m_buffer.getSize() < length * m_rch * sizeof(sample_t))
-               m_buffer.resize(length * m_rch * sizeof(sample_t));
+       m_buffer.assureSize(length * m_rch * sizeof(sample_t));
 
        sample_t* in = m_buffer.getBuffer();
 
index 7e0246f5d621c4d25c6a52dc0fbc7d34953614b3..4fed746c96ba6b8488cd804e1a2ef9111fcda930 100644 (file)
@@ -79,8 +79,7 @@ void AUD_ConverterReader::read(int & length, sample_t* buffer)
 {
        int samplesize = AUD_SAMPLE_SIZE(m_reader->getSpecs());
 
-       if(m_buffer.getSize() < length * samplesize)
-               m_buffer.resize(length * samplesize);
+       m_buffer.assureSize(length * samplesize);
 
        m_reader->read(length, m_buffer.getBuffer());
 
index 6cb1d946ea386c23153c3cf2a27de391e511c1bc..a8bd9749a2b514debaa546dc0b69b8974f265f0b 100644 (file)
@@ -76,8 +76,7 @@ void AUD_LinearResampleReader::read(int & length, sample_t* buffer)
        int samplesize = AUD_SAMPLE_SIZE(m_tspecs);
        int size = length * AUD_SAMPLE_SIZE(m_sspecs);
 
-       if(m_buffer.getSize() < size)
-               m_buffer.resize(size);
+       m_buffer.assureSize(size);
 
        int need = ceil((m_position + length) / m_factor) + 1 - m_sposition;
        int len = need;
index 880e9d22e96e7f5721c64ac3e036932bf3206b09..e6699811344f4e8c7b9465b24907d6b8900ea46f 100644 (file)
@@ -75,8 +75,7 @@ AUD_DeviceSpecs AUD_Mixer::getSpecs() const
 
 void AUD_Mixer::clear(int length)
 {
-       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));
+       m_buffer.assureSize(length * m_specs.channels * AUD_SAMPLE_SIZE(m_specs));
 
        m_length = length;
 
index 794a524c5275d3daf83bfbbdab36f957697b65dc..2cf9222673e8aa262700f9729661c278cb091641 100644 (file)
@@ -120,8 +120,7 @@ void AUD_SequencerReader::read(int & length, sample_t* buffer)
 
        int start, end, current, skip, len;
        AUD_Reference<AUD_SequencerStrip> strip;
-       if(m_buffer.getSize() < length * AUD_SAMPLE_SIZE(specs))
-               m_buffer.resize(length * AUD_SAMPLE_SIZE(specs));
+       m_buffer.assureSize(length * AUD_SAMPLE_SIZE(specs));
 
        m_mixer->clear(length);
 
index ff744f74973d9c3de6972862b9dcdf3cbfd10b29..f80d3d12748a393dd6aa552910e8b8d0a887e83b 100644 (file)
@@ -104,8 +104,7 @@ 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));
+       m_buffer.assureSize(length * AUD_SAMPLE_SIZE(m_specs));
 
        lock();