[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [25591] trunk/blender/intern/audaspace: Sound:

Joerg Mueller nexyon at gmail.com
Mon Dec 28 11:15:35 CET 2009


Revision: 25591
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=25591
Author:   nexyon
Date:     2009-12-28 11:15:35 +0100 (Mon, 28 Dec 2009)

Log Message:
-----------
Sound:

* Fixed minor errors in AUD_BufferReader.cpp and AUD_LoopFactory.h
* Added a first version of a bandpass filter using fftw3

Modified Paths:
--------------
    trunk/blender/intern/audaspace/CMakeLists.txt
    trunk/blender/intern/audaspace/FX/AUD_LoopFactory.h
    trunk/blender/intern/audaspace/SConscript
    trunk/blender/intern/audaspace/intern/AUD_BufferReader.cpp

Added Paths:
-----------
    trunk/blender/intern/audaspace/fftw/
    trunk/blender/intern/audaspace/fftw/AUD_BandPassFactory.cpp
    trunk/blender/intern/audaspace/fftw/AUD_BandPassFactory.h
    trunk/blender/intern/audaspace/fftw/AUD_BandPassReader.cpp
    trunk/blender/intern/audaspace/fftw/AUD_BandPassReader.h

Modified: trunk/blender/intern/audaspace/CMakeLists.txt
===================================================================
--- trunk/blender/intern/audaspace/CMakeLists.txt	2009-12-28 10:00:04 UTC (rev 25590)
+++ trunk/blender/intern/audaspace/CMakeLists.txt	2009-12-28 10:15:35 UTC (rev 25591)
@@ -40,11 +40,6 @@
 	SET(INC ${INC} OpenAL ${OPENAL_INCLUDE_DIR})
 	FILE(GLOB OPENALSRC OpenAL/*.cpp)
 	ADD_DEFINITIONS(-DWITH_OPENAL)
-
-	STRING(REGEX MATCH ".*ramework.*" FRAMEWORK ${OPENAL_INCLUDE_DIR})
-	IF(FRAMEWORK)
-		ADD_DEFINITIONS(-DAPPLE_FRAMEWORK_FIX)
-	ENDIF(FRAMEWORK)
 ENDIF(WITH_OPENAL)
 
 IF(WITH_JACK)
@@ -59,6 +54,12 @@
 	ADD_DEFINITIONS(-DWITH_SNDFILE)
 ENDIF(WITH_SNDFILE)
 
-SET(SRC ${SRC} ${FFMPEGSRC} ${SNDFILESRC} ${SDLSRC} ${OPENALSRC} ${JACKSRC})
+IF(WITH_FFTW3)
+	SET(INC ${INC} fftw ${FFTW3_INC})
+	FILE(GLOB FFTW3SRC fftw/*.cpp)
+	ADD_DEFINITIONS(-DWITH_FFTW3)
+ENDIF(WITH_FFTW3)
 
+SET(SRC ${SRC} ${FFMPEGSRC} ${SNDFILESRC} ${FFTW3SRC} ${SDLSRC} ${OPENALSRC} ${JACKSRC})
+
 BLENDERLIB(bf_audaspace "${SRC}" "${INC}")

Modified: trunk/blender/intern/audaspace/FX/AUD_LoopFactory.h
===================================================================
--- trunk/blender/intern/audaspace/FX/AUD_LoopFactory.h	2009-12-28 10:00:04 UTC (rev 25590)
+++ trunk/blender/intern/audaspace/FX/AUD_LoopFactory.h	2009-12-28 10:15:35 UTC (rev 25591)
@@ -38,7 +38,7 @@
 	/**
 	 * The loop count.
 	 */
-	float m_loop;
+	int m_loop;
 
 public:
 	/**

Modified: trunk/blender/intern/audaspace/SConscript
===================================================================
--- trunk/blender/intern/audaspace/SConscript	2009-12-28 10:00:04 UTC (rev 25590)
+++ trunk/blender/intern/audaspace/SConscript	2009-12-28 10:15:35 UTC (rev 25591)
@@ -31,4 +31,9 @@
 	incs += ' sndfile ' + env['BF_SNDFILE_INC']
 	defs.append('WITH_SNDFILE')
 
+if env['WITH_BF_FFTW3']:
+	sources += env.Glob('fftw/*.cpp')
+	incs += ' fftw ' + env['BF_FFTW3_INC']
+	defs.append('WITH_FFTW3')
+
 env.BlenderLib ('bf_audaspace', sources, Split(incs), defs, libtype=['intern','player'], priority = [25,215] )

Added: trunk/blender/intern/audaspace/fftw/AUD_BandPassFactory.cpp
===================================================================
--- trunk/blender/intern/audaspace/fftw/AUD_BandPassFactory.cpp	                        (rev 0)
+++ trunk/blender/intern/audaspace/fftw/AUD_BandPassFactory.cpp	2009-12-28 10:15:35 UTC (rev 25591)
@@ -0,0 +1,79 @@
+/*
+ * $Id$
+ *
+ * ***** BEGIN LGPL LICENSE BLOCK *****
+ *
+ * Copyright 2009 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 Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with AudaSpace.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * ***** END LGPL LICENSE BLOCK *****
+ */
+
+#include "AUD_BandPassFactory.h"
+#include "AUD_BandPassReader.h"
+
+AUD_BandPassFactory::AUD_BandPassFactory(AUD_IFactory* factory, float low,
+										 float high) :
+		AUD_EffectFactory(factory),
+		m_low(low),
+		m_high(high) {}
+
+AUD_BandPassFactory::AUD_BandPassFactory(float low, float high) :
+		AUD_EffectFactory(0),
+		m_low(low),
+		m_high(high) {}
+
+float AUD_BandPassFactory::getLow()
+{
+	return m_low;
+}
+
+float AUD_BandPassFactory::getHigh()
+{
+	return m_high;
+}
+
+void AUD_BandPassFactory::setLow(float low)
+{
+	m_low = low;
+}
+
+void AUD_BandPassFactory::setHigh(float high)
+{
+	m_high = high;
+}
+
+AUD_IReader* AUD_BandPassFactory::createReader()
+{
+	AUD_IReader* reader = getReader();
+
+	if(reader != 0)
+	{
+		if(reader->getSpecs().format == AUD_FORMAT_FLOAT32)
+		{
+			reader = new AUD_BandPassReader(reader, m_low, m_high);
+			AUD_NEW("reader")
+		}
+		else
+		{
+			delete reader; AUD_DELETE("reader")
+			return 0;
+		}
+	}
+
+	return reader;
+}


Property changes on: trunk/blender/intern/audaspace/fftw/AUD_BandPassFactory.cpp
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: trunk/blender/intern/audaspace/fftw/AUD_BandPassFactory.h
===================================================================
--- trunk/blender/intern/audaspace/fftw/AUD_BandPassFactory.h	                        (rev 0)
+++ trunk/blender/intern/audaspace/fftw/AUD_BandPassFactory.h	2009-12-28 10:15:35 UTC (rev 25591)
@@ -0,0 +1,88 @@
+/*
+ * $Id$
+ *
+ * ***** BEGIN LGPL LICENSE BLOCK *****
+ *
+ * Copyright 2009 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 Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with AudaSpace.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * ***** END LGPL LICENSE BLOCK *****
+ */
+
+#ifndef AUD_BANDPASSFACTORY
+#define AUD_BANDPASSFACTORY
+
+#include "AUD_EffectFactory.h"
+
+/**
+ * This factory creates a band pass filter for a sound wave.
+ */
+class AUD_BandPassFactory : public AUD_EffectFactory
+{
+private:
+	/**
+	 * The lowest frequency to be passed.
+	 */
+	float m_low;
+
+	/**
+	 * The highest frequency to be passed.
+	 */
+	float m_high;
+
+public:
+	/**
+	 * Creates a new band pass factory.
+	 * \param factory The input factory.
+	 * \param low The lowest passed frequency.
+	 * \param high The highest passed frequency.
+	 */
+	AUD_BandPassFactory(AUD_IFactory* factory, float low, float high);
+
+	/**
+	 * Creates a new band pass factory.
+	 * \param low The lowest passed frequency.
+	 * \param high The highest passed frequency.
+	 */
+	AUD_BandPassFactory(float low, float high);
+
+	/**
+	 * Returns the lowest passed frequency.
+	 */
+	float getLow();
+
+	/**
+	 * Returns the highest passed frequency.
+	 */
+	float getHigh();
+
+	/**
+	 * Sets the lowest passed frequency.
+	 * \param low The lowest passed frequency.
+	 */
+	void setLow(float low);
+
+	/**
+	 * Sets the highest passed frequency.
+	 * \param high The highest passed frequency.
+	 */
+	void setHigh(float hight);
+
+	virtual AUD_IReader* createReader();
+};
+
+#endif //AUD_BANDPASSFACTORY


Property changes on: trunk/blender/intern/audaspace/fftw/AUD_BandPassFactory.h
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: trunk/blender/intern/audaspace/fftw/AUD_BandPassReader.cpp
===================================================================
--- trunk/blender/intern/audaspace/fftw/AUD_BandPassReader.cpp	                        (rev 0)
+++ trunk/blender/intern/audaspace/fftw/AUD_BandPassReader.cpp	2009-12-28 10:15:35 UTC (rev 25591)
@@ -0,0 +1,126 @@
+/*
+ * $Id$
+ *
+ * ***** BEGIN LGPL LICENSE BLOCK *****
+ *
+ * Copyright 2009 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 Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with AudaSpace.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * ***** END LGPL LICENSE BLOCK *****
+ */
+
+#include "AUD_BandPassReader.h"
+#include "AUD_Buffer.h"
+
+#include <cstring>
+#include <stdio.h>
+
+AUD_BandPassReader::AUD_BandPassReader(AUD_IReader* reader, float low,
+									   float high) :
+		AUD_EffectReader(reader), m_low(low), m_high(high)
+{
+	m_buffer = new AUD_Buffer(); AUD_NEW("buffer")
+	m_in = new AUD_Buffer(); AUD_NEW("buffer")
+	m_out = new AUD_Buffer(); AUD_NEW("buffer")
+	m_length = 0;
+}
+
+AUD_BandPassReader::~AUD_BandPassReader()
+{
+	if(m_length != 0)
+	{
+		fftw_destroy_plan(m_forward);
+		fftw_destroy_plan(m_backward);
+	}
+
+	delete m_buffer; AUD_DELETE("buffer")
+	delete m_in; AUD_DELETE("buffer")
+	delete m_out; AUD_DELETE("buffer")
+}
+
+AUD_ReaderType AUD_BandPassReader::getType()
+{
+	return m_reader->getType();
+}
+
+void AUD_BandPassReader::read(int & length, sample_t* & buffer)
+{
+	AUD_Specs specs = m_reader->getSpecs();
+
+	m_reader->read(length, buffer);
+
+	if(length > 0)
+	{
+		if(length * AUD_SAMPLE_SIZE(specs) > m_buffer->getSize())
+			m_buffer->resize(length * AUD_SAMPLE_SIZE(specs));
+
+		if(length != m_length)
+		{
+			if(m_length != 0)
+			{
+				fftw_destroy_plan(m_forward);
+				fftw_destroy_plan(m_backward);
+			}
+
+			m_length = length;
+			printf("WINDOW: %d\n", m_length);
+
+			if(m_length * sizeof(double) > m_in->getSize())
+			{
+				m_in->resize(m_length * sizeof(double));
+				m_out->resize((m_length / 2 + 1) * sizeof(fftw_complex));
+			}
+
+			m_forward = fftw_plan_dft_r2c_1d(m_length,
+											 (double*)m_in->getBuffer(),
+											 (fftw_complex*)m_out->getBuffer(),
+											 FFTW_ESTIMATE);
+			m_backward = fftw_plan_dft_c2r_1d(m_length,
+											  (fftw_complex*)m_out->getBuffer(),
+											  (double*)m_in->getBuffer(),
+											  FFTW_ESTIMATE);
+		}
+
+		float* source = (float*) buffer;
+		double* target = (double*) m_in->getBuffer();
+		float* target2 = (float*) m_buffer->getBuffer();
+		fftw_complex* complex = (fftw_complex*) m_out->getBuffer();
+		float frequency;
+
+		for(int channel = 0; channel < specs.channels; channel++)
+		{
+			for(int i = 0; i < m_length; i++)

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list