[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [37708] branches/soc-2011-pepper/intern/ audaspace: 3D Audio GSoC:

Joerg Mueller nexyon at gmail.com
Tue Jun 21 22:13:27 CEST 2011


Revision: 37708
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37708
Author:   nexyon
Date:     2011-06-21 20:13:27 +0000 (Tue, 21 Jun 2011)
Log Message:
-----------
3D Audio GSoC:
Buffer.assureSize - a function that should long have been there.

Modified Paths:
--------------
    branches/soc-2011-pepper/intern/audaspace/FX/AUD_SuperposeReader.cpp
    branches/soc-2011-pepper/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp
    branches/soc-2011-pepper/intern/audaspace/SRC/AUD_SRCResampleReader.cpp
    branches/soc-2011-pepper/intern/audaspace/fftw/AUD_BandPassReader.cpp
    branches/soc-2011-pepper/intern/audaspace/intern/AUD_Buffer.cpp
    branches/soc-2011-pepper/intern/audaspace/intern/AUD_Buffer.h
    branches/soc-2011-pepper/intern/audaspace/intern/AUD_ChannelMapperReader.cpp
    branches/soc-2011-pepper/intern/audaspace/intern/AUD_ConverterReader.cpp
    branches/soc-2011-pepper/intern/audaspace/intern/AUD_LinearResampleReader.cpp
    branches/soc-2011-pepper/intern/audaspace/intern/AUD_Mixer.cpp
    branches/soc-2011-pepper/intern/audaspace/intern/AUD_SequencerReader.cpp
    branches/soc-2011-pepper/intern/audaspace/intern/AUD_SoftwareDevice.cpp

Modified: branches/soc-2011-pepper/intern/audaspace/FX/AUD_SuperposeReader.cpp
===================================================================
--- branches/soc-2011-pepper/intern/audaspace/FX/AUD_SuperposeReader.cpp	2011-06-21 20:12:39 UTC (rev 37707)
+++ branches/soc-2011-pepper/intern/audaspace/FX/AUD_SuperposeReader.cpp	2011-06-21 20:13:27 UTC (rev 37708)
@@ -87,8 +87,7 @@
 	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);

Modified: branches/soc-2011-pepper/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp
===================================================================
--- branches/soc-2011-pepper/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp	2011-06-21 20:12:39 UTC (rev 37707)
+++ branches/soc-2011-pepper/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp	2011-06-21 20:13:27 UTC (rev 37708)
@@ -160,8 +160,7 @@
 					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 @@
 
 		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 @@
 					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++)
 					{

Modified: branches/soc-2011-pepper/intern/audaspace/SRC/AUD_SRCResampleReader.cpp
===================================================================
--- branches/soc-2011-pepper/intern/audaspace/SRC/AUD_SRCResampleReader.cpp	2011-06-21 20:12:39 UTC (rev 37707)
+++ branches/soc-2011-pepper/intern/audaspace/SRC/AUD_SRCResampleReader.cpp	2011-06-21 20:13:27 UTC (rev 37708)
@@ -108,8 +108,7 @@
 {
 	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);
 

Modified: branches/soc-2011-pepper/intern/audaspace/fftw/AUD_BandPassReader.cpp
===================================================================
--- branches/soc-2011-pepper/intern/audaspace/fftw/AUD_BandPassReader.cpp	2011-06-21 20:12:39 UTC (rev 37707)
+++ branches/soc-2011-pepper/intern/audaspace/fftw/AUD_BandPassReader.cpp	2011-06-21 20:13:27 UTC (rev 37708)
@@ -71,8 +71,7 @@
 
 	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)
 		{

Modified: branches/soc-2011-pepper/intern/audaspace/intern/AUD_Buffer.cpp
===================================================================
--- branches/soc-2011-pepper/intern/audaspace/intern/AUD_Buffer.cpp	2011-06-21 20:12:39 UTC (rev 37707)
+++ branches/soc-2011-pepper/intern/audaspace/intern/AUD_Buffer.cpp	2011-06-21 20:13:27 UTC (rev 37708)
@@ -74,3 +74,9 @@
 
 	m_size = size;
 }
+
+void AUD_Buffer::assureSize(int size, bool keep)
+{
+	if(m_size < size)
+		resize(size, keep);
+}

Modified: branches/soc-2011-pepper/intern/audaspace/intern/AUD_Buffer.h
===================================================================
--- branches/soc-2011-pepper/intern/audaspace/intern/AUD_Buffer.h	2011-06-21 20:12:39 UTC (rev 37707)
+++ branches/soc-2011-pepper/intern/audaspace/intern/AUD_Buffer.h	2011-06-21 20:13:27 UTC (rev 37708)
@@ -80,6 +80,16 @@
 	 *        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

Modified: branches/soc-2011-pepper/intern/audaspace/intern/AUD_ChannelMapperReader.cpp
===================================================================
--- branches/soc-2011-pepper/intern/audaspace/intern/AUD_ChannelMapperReader.cpp	2011-06-21 20:12:39 UTC (rev 37707)
+++ branches/soc-2011-pepper/intern/audaspace/intern/AUD_ChannelMapperReader.cpp	2011-06-21 20:13:27 UTC (rev 37708)
@@ -78,8 +78,7 @@
 
 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();
 

Modified: branches/soc-2011-pepper/intern/audaspace/intern/AUD_ConverterReader.cpp
===================================================================
--- branches/soc-2011-pepper/intern/audaspace/intern/AUD_ConverterReader.cpp	2011-06-21 20:12:39 UTC (rev 37707)
+++ branches/soc-2011-pepper/intern/audaspace/intern/AUD_ConverterReader.cpp	2011-06-21 20:13:27 UTC (rev 37708)
@@ -79,8 +79,7 @@
 {
 	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());
 

Modified: branches/soc-2011-pepper/intern/audaspace/intern/AUD_LinearResampleReader.cpp
===================================================================
--- branches/soc-2011-pepper/intern/audaspace/intern/AUD_LinearResampleReader.cpp	2011-06-21 20:12:39 UTC (rev 37707)
+++ branches/soc-2011-pepper/intern/audaspace/intern/AUD_LinearResampleReader.cpp	2011-06-21 20:13:27 UTC (rev 37708)
@@ -76,8 +76,7 @@
 	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;

Modified: branches/soc-2011-pepper/intern/audaspace/intern/AUD_Mixer.cpp
===================================================================
--- branches/soc-2011-pepper/intern/audaspace/intern/AUD_Mixer.cpp	2011-06-21 20:12:39 UTC (rev 37707)
+++ branches/soc-2011-pepper/intern/audaspace/intern/AUD_Mixer.cpp	2011-06-21 20:13:27 UTC (rev 37708)
@@ -75,8 +75,7 @@
 
 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;
 

Modified: branches/soc-2011-pepper/intern/audaspace/intern/AUD_SequencerReader.cpp
===================================================================
--- branches/soc-2011-pepper/intern/audaspace/intern/AUD_SequencerReader.cpp	2011-06-21 20:12:39 UTC (rev 37707)
+++ branches/soc-2011-pepper/intern/audaspace/intern/AUD_SequencerReader.cpp	2011-06-21 20:13:27 UTC (rev 37708)
@@ -120,8 +120,7 @@
 
 	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);
 

Modified: branches/soc-2011-pepper/intern/audaspace/intern/AUD_SoftwareDevice.cpp
===================================================================
--- branches/soc-2011-pepper/intern/audaspace/intern/AUD_SoftwareDevice.cpp	2011-06-21 20:12:39 UTC (rev 37707)
+++ branches/soc-2011-pepper/intern/audaspace/intern/AUD_SoftwareDevice.cpp	2011-06-21 20:13:27 UTC (rev 37708)
@@ -104,8 +104,7 @@
 
 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();
 




More information about the Bf-blender-cvs mailing list