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

Joerg Mueller nexyon at gmail.com
Thu Aug 4 15:47:16 CEST 2011


Revision: 39019
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=39019
Author:   nexyon
Date:     2011-08-04 13:47:15 +0000 (Thu, 04 Aug 2011)
Log Message:
-----------
3D Audio GSoC:
Implementation of Julius O. Smith's resampling algorithm for high quality audio resampling.

The filter currently is a sinc filter with a 0.9 cutt-off and windowed by a kaiser window (beta = 10).
Also includes minor changes in the linear resampler.

Modified Paths:
--------------
    branches/soc-2011-pepper/intern/audaspace/CMakeLists.txt
    branches/soc-2011-pepper/intern/audaspace/intern/AUD_LinearResampleReader.cpp
    branches/soc-2011-pepper/intern/audaspace/intern/AUD_LinearResampleReader.h

Added Paths:
-----------
    branches/soc-2011-pepper/intern/audaspace/intern/AUD_JOSResampleFactory.cpp
    branches/soc-2011-pepper/intern/audaspace/intern/AUD_JOSResampleFactory.h
    branches/soc-2011-pepper/intern/audaspace/intern/AUD_JOSResampleReader.cpp
    branches/soc-2011-pepper/intern/audaspace/intern/AUD_JOSResampleReader.h

Modified: branches/soc-2011-pepper/intern/audaspace/CMakeLists.txt
===================================================================
--- branches/soc-2011-pepper/intern/audaspace/CMakeLists.txt	2011-08-04 13:22:38 UTC (rev 39018)
+++ branches/soc-2011-pepper/intern/audaspace/CMakeLists.txt	2011-08-04 13:47:15 UTC (rev 39019)
@@ -94,6 +94,10 @@
 	intern/AUD_IFactory.h
 	intern/AUD_IHandle.h
 	intern/AUD_IReader.h
+	intern/AUD_JOSResampleFactory.cpp
+	intern/AUD_JOSResampleFactory.h
+	intern/AUD_JOSResampleReader.cpp
+	intern/AUD_JOSResampleReader.h
 	intern/AUD_LinearResampleFactory.cpp
 	intern/AUD_LinearResampleFactory.h
 	intern/AUD_LinearResampleReader.cpp

Added: branches/soc-2011-pepper/intern/audaspace/intern/AUD_JOSResampleFactory.cpp
===================================================================
--- branches/soc-2011-pepper/intern/audaspace/intern/AUD_JOSResampleFactory.cpp	                        (rev 0)
+++ branches/soc-2011-pepper/intern/audaspace/intern/AUD_JOSResampleFactory.cpp	2011-08-04 13:47:15 UTC (rev 39019)
@@ -0,0 +1,44 @@
+/*
+ * $Id$
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * Copyright 2009-2011 Jörg Hermann Müller
+ *
+ * This file is part of AudaSpace.
+ *
+ * Audaspace is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * AudaSpace is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Audaspace; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file audaspace/intern/AUD_JOSResampleFactory.cpp
+ *  \ingroup audaspaceintern
+ */
+
+
+#include "AUD_JOSResampleFactory.h"
+#include "AUD_JOSResampleReader.h"
+
+AUD_JOSResampleFactory::AUD_JOSResampleFactory(AUD_Reference<AUD_IFactory> factory,
+													 AUD_DeviceSpecs specs) :
+		AUD_MixerFactory(factory, specs)
+{
+}
+
+AUD_Reference<AUD_IReader> AUD_JOSResampleFactory::createReader()
+{
+	return new AUD_JOSResampleReader(getReader(), m_specs.specs);
+}


Property changes on: branches/soc-2011-pepper/intern/audaspace/intern/AUD_JOSResampleFactory.cpp
___________________________________________________________________
Added: svn:keywords
   + Author Date Id Revision
Added: svn:eol-style
   + native

Added: branches/soc-2011-pepper/intern/audaspace/intern/AUD_JOSResampleFactory.h
===================================================================
--- branches/soc-2011-pepper/intern/audaspace/intern/AUD_JOSResampleFactory.h	                        (rev 0)
+++ branches/soc-2011-pepper/intern/audaspace/intern/AUD_JOSResampleFactory.h	2011-08-04 13:47:15 UTC (rev 39019)
@@ -0,0 +1,53 @@
+/*
+ * $Id$
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * Copyright 2009-2011 Jörg Hermann Müller
+ *
+ * This file is part of AudaSpace.
+ *
+ * Audaspace is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * AudaSpace is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Audaspace; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file audaspace/intern/AUD_JOSResampleFactory.h
+ *  \ingroup audaspaceintern
+ */
+
+
+#ifndef AUD_JOSRESAMPLEFACTORY
+#define AUD_JOSRESAMPLEFACTORY
+
+#include "AUD_MixerFactory.h"
+
+/**
+ * This factory creates a resampling reader that does Julius O. Smith's resampling algorithm.
+ */
+class AUD_JOSResampleFactory : public AUD_MixerFactory
+{
+private:
+	// hide copy constructor and operator=
+	AUD_JOSResampleFactory(const AUD_JOSResampleFactory&);
+	AUD_JOSResampleFactory& operator=(const AUD_JOSResampleFactory&);
+
+public:
+	AUD_JOSResampleFactory(AUD_Reference<AUD_IFactory> factory, AUD_DeviceSpecs specs);
+
+	virtual AUD_Reference<AUD_IReader> createReader();
+};
+
+#endif //AUD_JOSRESAMPLEFACTORY


Property changes on: branches/soc-2011-pepper/intern/audaspace/intern/AUD_JOSResampleFactory.h
___________________________________________________________________
Added: svn:keywords
   + Author Date Id Revision
Added: svn:eol-style
   + native

Added: branches/soc-2011-pepper/intern/audaspace/intern/AUD_JOSResampleReader.cpp
===================================================================
--- branches/soc-2011-pepper/intern/audaspace/intern/AUD_JOSResampleReader.cpp	                        (rev 0)
+++ branches/soc-2011-pepper/intern/audaspace/intern/AUD_JOSResampleReader.cpp	2011-08-04 13:47:15 UTC (rev 39019)
@@ -0,0 +1,3596 @@
+/*
+ * $Id$
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * Copyright 2009-2011 Jörg Hermann Müller
+ *
+ * This file is part of AudaSpace.
+ *
+ * Audaspace is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * AudaSpace is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Audaspace; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file audaspace/intern/AUD_JOSResampleReader.cpp
+ *  \ingroup audaspaceintern
+ */
+
+#include "AUD_JOSResampleReader.h"
+
+#include <cmath>
+#include <cstring>
+
+#define CC m_channels + channel
+
+#define AUD_RATE_MAX 10
+
+AUD_JOSResampleReader::AUD_JOSResampleReader(AUD_Reference<AUD_IReader> reader,
+												   AUD_Specs specs) :
+	AUD_ResampleReader(reader, specs.rate),
+	m_channels(reader->getSpecs().channels),
+	m_n(0),
+	m_P(0),
+	m_cache_valid(0)
+{
+}
+
+void AUD_JOSResampleReader::reset()
+{
+	m_cache_valid = 0;
+	m_n = 0;
+	m_P = 0;
+}
+
+void AUD_JOSResampleReader::updateBuffer(int size, float factor, int samplesize)
+{
+	unsigned int len;
+	// first calculate what length we need right now
+	if(factor >= 1)
+		len = m_Nz;
+	else
+		len = (unsigned int)(ceil(m_Nz / factor));
+
+	// then check if afterwards the length is enough for the maximum rate
+	if(len + size < m_Nz * AUD_RATE_MAX)
+		len = size - m_Nz * AUD_RATE_MAX;
+
+	if(m_n > len)
+	{
+		sample_t* buf = m_buffer.getBuffer();
+		len = m_n - len;
+		memmove(buf, buf + len * m_channels, (m_cache_valid - len) * samplesize);
+		m_n -= len;
+		m_cache_valid -= len;
+	}
+
+	m_buffer.assureSize((m_cache_valid + size) * samplesize, true);
+}
+
+void AUD_JOSResampleReader::seek(int position)
+{
+	position = floor(position * double(m_reader->getSpecs().rate) / double(m_rate));
+	m_reader->seek(position);
+	reset();
+}
+
+int AUD_JOSResampleReader::getLength() const
+{
+	return floor(m_reader->getLength() * double(m_rate) / double(m_reader->getSpecs().rate));
+}
+
+int AUD_JOSResampleReader::getPosition() const
+{
+	return floor((m_reader->getPosition() + double(m_P) / 4294967296.0) // 2^32
+				 * m_rate / m_reader->getSpecs().rate);
+}
+
+AUD_Specs AUD_JOSResampleReader::getSpecs() const
+{
+	AUD_Specs specs = m_reader->getSpecs();
+	specs.rate = m_rate;
+	return specs;
+}
+
+void AUD_JOSResampleReader::read(int& length, bool& eos, sample_t* buffer)
+{
+	if(length == 0)
+		return;
+
+	AUD_Specs specs = m_reader->getSpecs();
+
+	int samplesize = AUD_SAMPLE_SIZE(specs);
+	float factor = float(m_rate) / float(m_reader->getSpecs().rate);
+	eos = false;
+	int len;
+	sample_t* buf;
+
+	// check for channels changed
+
+	if(specs.channels != m_channels)
+	{
+		m_channels = specs.channels;
+		reset();
+	}
+
+	if(factor == 1 && (m_P == 1))
+	{
+		// can read directly!
+
+		len = length - (m_cache_valid - m_n);
+
+		updateBuffer(len, factor, samplesize);
+		buf = m_buffer.getBuffer();
+
+		m_reader->read(len, eos, buf + m_cache_valid * m_channels);
+		m_cache_valid += len;
+
+		length = m_cache_valid - m_n;
+
+		if(length > 0)
+		{
+			memcpy(buffer, buf + m_n * m_channels, length * samplesize);
+			m_n += length;
+		}
+
+		return;
+	}
+
+
+	if(factor >= 1)
+		len = (m_n - m_cache_valid) + int(ceil(length / factor)) + m_Nz;
+	else
+		len = (m_n - m_cache_valid) + int(ceil(length / factor) + ceil(m_Nz / factor));
+
+	if(len > 0)
+	{
+		int should = len;
+
+		updateBuffer(len, factor, samplesize);
+		buf = m_buffer.getBuffer();
+
+		m_reader->read(len, eos, buf + m_cache_valid * m_channels);
+		m_cache_valid += len;
+
+		if(len < should)
+		{
+			if(eos)
+			{
+				// end of stream, let's check how many more samples we can produce
+				if(factor >= 1)
+					len = floor((len - (m_n - m_cache_valid)) * factor);
+				else
+					len = floor((len - (m_n - m_cache_valid)) * factor);
+				if(len < length)
+					length = len;
+			}
+			else
+			{
+				// not enough data available yet, so we recalculate how many samples we can calculate
+				if(factor >= 1)
+					len = floor((len - m_Nz - (m_n - m_cache_valid)) * factor);
+				else
+					len = floor((len - m_Nz * factor - (m_n - m_cache_valid)) * factor);
+			}
+		}
+	}
+
+	memset(buffer, 0, length * samplesize);
+
+	unsigned int n_increment = (unsigned int)(floor(1 / factor));
+	unsigned int P_increment = (unsigned int)(round(4294967296.0 * fmod(1 / factor, 1)));
+
+	unsigned int P, L, l, end_i;
+	float eta, v;
+
+	if(factor >= 1)
+	{
+		L = m_L;
+
+		for(unsigned int t = 0; t < length; t++)
+		{
+			P = m_P;
+
+			end_i = m_Nz - 1;
+			if(m_n + 1 < end_i)
+				end_i = m_n + 1;
+
+			l = (unsigned int)(floor(float(P) / float(m_NN)));
+			eta = fmod(P, m_NN) / m_NN;
+
+			for(unsigned int i = 0; i < end_i; i++)

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list