diff options
author | Joerg Mueller <nexyon@gmail.com> | 2011-06-22 00:13:27 +0400 |
---|---|---|
committer | Joerg Mueller <nexyon@gmail.com> | 2011-06-22 00:13:27 +0400 |
commit | 3d932ba4968d8caa3c936d9186439781e7cedca0 (patch) | |
tree | b6968fff93462e6e05caba6d89c58d80982325b8 | |
parent | f2ceca4eb05675f4058fc6666805de58cb10916f (diff) |
3D Audio GSoC:
Buffer.assureSize - a function that should long have been there.
-rw-r--r-- | intern/audaspace/FX/AUD_SuperposeReader.cpp | 3 | ||||
-rw-r--r-- | intern/audaspace/OpenAL/AUD_OpenALDevice.cpp | 9 | ||||
-rw-r--r-- | intern/audaspace/SRC/AUD_SRCResampleReader.cpp | 3 | ||||
-rw-r--r-- | intern/audaspace/fftw/AUD_BandPassReader.cpp | 3 | ||||
-rw-r--r-- | intern/audaspace/intern/AUD_Buffer.cpp | 6 | ||||
-rw-r--r-- | intern/audaspace/intern/AUD_Buffer.h | 10 | ||||
-rw-r--r-- | intern/audaspace/intern/AUD_ChannelMapperReader.cpp | 3 | ||||
-rw-r--r-- | intern/audaspace/intern/AUD_ConverterReader.cpp | 3 | ||||
-rw-r--r-- | intern/audaspace/intern/AUD_LinearResampleReader.cpp | 3 | ||||
-rw-r--r-- | intern/audaspace/intern/AUD_Mixer.cpp | 3 | ||||
-rw-r--r-- | intern/audaspace/intern/AUD_SequencerReader.cpp | 3 | ||||
-rw-r--r-- | intern/audaspace/intern/AUD_SoftwareDevice.cpp | 3 |
12 files changed, 28 insertions, 24 deletions
diff --git a/intern/audaspace/FX/AUD_SuperposeReader.cpp b/intern/audaspace/FX/AUD_SuperposeReader.cpp index 3ad2420fc91..49e29d2b0f9 100644 --- a/intern/audaspace/FX/AUD_SuperposeReader.cpp +++ b/intern/audaspace/FX/AUD_SuperposeReader.cpp @@ -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); diff --git a/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp b/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp index 2780f108cda..18c50d29225 100644 --- a/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp +++ b/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp @@ -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++) { diff --git a/intern/audaspace/SRC/AUD_SRCResampleReader.cpp b/intern/audaspace/SRC/AUD_SRCResampleReader.cpp index 42696a1caaa..85f935bab8e 100644 --- a/intern/audaspace/SRC/AUD_SRCResampleReader.cpp +++ b/intern/audaspace/SRC/AUD_SRCResampleReader.cpp @@ -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); diff --git a/intern/audaspace/fftw/AUD_BandPassReader.cpp b/intern/audaspace/fftw/AUD_BandPassReader.cpp index 06f0a2af0ad..22c65b18d76 100644 --- a/intern/audaspace/fftw/AUD_BandPassReader.cpp +++ b/intern/audaspace/fftw/AUD_BandPassReader.cpp @@ -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) { diff --git a/intern/audaspace/intern/AUD_Buffer.cpp b/intern/audaspace/intern/AUD_Buffer.cpp index 37c05fd1cc0..43955b54988 100644 --- a/intern/audaspace/intern/AUD_Buffer.cpp +++ b/intern/audaspace/intern/AUD_Buffer.cpp @@ -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); +} diff --git a/intern/audaspace/intern/AUD_Buffer.h b/intern/audaspace/intern/AUD_Buffer.h index 9b199d82fbb..4a37bc17464 100644 --- a/intern/audaspace/intern/AUD_Buffer.h +++ b/intern/audaspace/intern/AUD_Buffer.h @@ -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 diff --git a/intern/audaspace/intern/AUD_ChannelMapperReader.cpp b/intern/audaspace/intern/AUD_ChannelMapperReader.cpp index a70eebc192c..bfc5596bb21 100644 --- a/intern/audaspace/intern/AUD_ChannelMapperReader.cpp +++ b/intern/audaspace/intern/AUD_ChannelMapperReader.cpp @@ -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(); diff --git a/intern/audaspace/intern/AUD_ConverterReader.cpp b/intern/audaspace/intern/AUD_ConverterReader.cpp index 7e0246f5d62..4fed746c96b 100644 --- a/intern/audaspace/intern/AUD_ConverterReader.cpp +++ b/intern/audaspace/intern/AUD_ConverterReader.cpp @@ -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()); diff --git a/intern/audaspace/intern/AUD_LinearResampleReader.cpp b/intern/audaspace/intern/AUD_LinearResampleReader.cpp index 6cb1d946ea3..a8bd9749a2b 100644 --- a/intern/audaspace/intern/AUD_LinearResampleReader.cpp +++ b/intern/audaspace/intern/AUD_LinearResampleReader.cpp @@ -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; diff --git a/intern/audaspace/intern/AUD_Mixer.cpp b/intern/audaspace/intern/AUD_Mixer.cpp index 880e9d22e96..e6699811344 100644 --- a/intern/audaspace/intern/AUD_Mixer.cpp +++ b/intern/audaspace/intern/AUD_Mixer.cpp @@ -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; diff --git a/intern/audaspace/intern/AUD_SequencerReader.cpp b/intern/audaspace/intern/AUD_SequencerReader.cpp index 794a524c527..2cf9222673e 100644 --- a/intern/audaspace/intern/AUD_SequencerReader.cpp +++ b/intern/audaspace/intern/AUD_SequencerReader.cpp @@ -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); diff --git a/intern/audaspace/intern/AUD_SoftwareDevice.cpp b/intern/audaspace/intern/AUD_SoftwareDevice.cpp index ff744f74973..f80d3d12748 100644 --- a/intern/audaspace/intern/AUD_SoftwareDevice.cpp +++ b/intern/audaspace/intern/AUD_SoftwareDevice.cpp @@ -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(); |