[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [25544] trunk/blender/intern/audaspace: Added rectifying sound effect (will be used for sound -> f-curve later).

Joerg Mueller nexyon at gmail.com
Thu Dec 24 15:58:11 CET 2009


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

Log Message:
-----------
Added rectifying sound effect (will be used for sound -> f-curve later).

Modified Paths:
--------------
    trunk/blender/intern/audaspace/intern/AUD_C-API.cpp
    trunk/blender/intern/audaspace/intern/AUD_C-API.h
    trunk/blender/intern/audaspace/intern/AUD_ConverterFunctions.cpp
    trunk/blender/intern/audaspace/intern/AUD_ConverterFunctions.h

Added Paths:
-----------
    trunk/blender/intern/audaspace/FX/AUD_RectifyFactory.cpp
    trunk/blender/intern/audaspace/FX/AUD_RectifyFactory.h
    trunk/blender/intern/audaspace/FX/AUD_RectifyReader.cpp
    trunk/blender/intern/audaspace/FX/AUD_RectifyReader.h

Added: trunk/blender/intern/audaspace/FX/AUD_RectifyFactory.cpp
===================================================================
--- trunk/blender/intern/audaspace/FX/AUD_RectifyFactory.cpp	                        (rev 0)
+++ trunk/blender/intern/audaspace/FX/AUD_RectifyFactory.cpp	2009-12-24 14:58:11 UTC (rev 25544)
@@ -0,0 +1,45 @@
+/*
+ * $Id: AUD_VolumeFactory.cpp 22328 2009-08-09 23:23:19Z gsrb3d $
+ *
+ * ***** 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_RectifyFactory.h"
+#include "AUD_RectifyReader.h"
+
+AUD_RectifyFactory::AUD_RectifyFactory(AUD_IFactory* factory) :
+		AUD_EffectFactory(factory) {}
+
+AUD_RectifyFactory::AUD_RectifyFactory() :
+		AUD_EffectFactory(0) {}
+
+AUD_IReader* AUD_RectifyFactory::createReader()
+{
+	AUD_IReader* reader = getReader();
+
+	if(reader != 0)
+	{
+		reader = new AUD_RectifyReader(reader); AUD_NEW("reader")
+	}
+
+	return reader;
+}

Added: trunk/blender/intern/audaspace/FX/AUD_RectifyFactory.h
===================================================================
--- trunk/blender/intern/audaspace/FX/AUD_RectifyFactory.h	                        (rev 0)
+++ trunk/blender/intern/audaspace/FX/AUD_RectifyFactory.h	2009-12-24 14:58:11 UTC (rev 25544)
@@ -0,0 +1,51 @@
+/*
+ * $Id: AUD_VolumeFactory.h 22328 2009-08-09 23:23:19Z gsrb3d $
+ *
+ * ***** 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_RECTIFYFACTORY
+#define AUD_RECTIFYFACTORY
+
+#include "AUD_EffectFactory.h"
+
+/**
+ * This factory rectifies another factory.
+ */
+class AUD_RectifyFactory : public AUD_EffectFactory
+{
+public:
+	/**
+	 * Creates a new rectify factory.
+	 * \param factory The input factory.
+	 */
+	AUD_RectifyFactory(AUD_IFactory* factory = 0);
+
+	/**
+	 * Creates a new rectify factory.
+	 */
+	AUD_RectifyFactory();
+
+	virtual AUD_IReader* createReader();
+};
+
+#endif //AUD_RECTIFYFACTORY

Added: trunk/blender/intern/audaspace/FX/AUD_RectifyReader.cpp
===================================================================
--- trunk/blender/intern/audaspace/FX/AUD_RectifyReader.cpp	                        (rev 0)
+++ trunk/blender/intern/audaspace/FX/AUD_RectifyReader.cpp	2009-12-24 14:58:11 UTC (rev 25544)
@@ -0,0 +1,82 @@
+/*
+ * $Id: AUD_VolumeReader.cpp 22328 2009-08-09 23:23:19Z gsrb3d $
+ *
+ * ***** 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_RectifyReader.h"
+#include "AUD_Buffer.h"
+
+#include <cstring>
+
+AUD_RectifyReader::AUD_RectifyReader(AUD_IReader* reader) :
+		AUD_EffectReader(reader)
+{
+	int bigendian = 1;
+	bigendian = (((char*)&bigendian)[0]) ? 0: 1; // 1 if Big Endian
+
+	switch(m_reader->getSpecs().format)
+	{
+	case AUD_FORMAT_S16:
+		m_rectify = AUD_rectify<int16_t>;
+		break;
+	case AUD_FORMAT_S32:
+		m_rectify = AUD_rectify<int32_t>;
+		break;
+	case AUD_FORMAT_FLOAT32:
+		m_rectify = AUD_rectify<float>;
+		break;
+	case AUD_FORMAT_FLOAT64:
+		m_rectify = AUD_rectify<double>;
+		break;
+	case AUD_FORMAT_U8:
+		m_rectify = AUD_rectify_u8;
+		break;
+	case AUD_FORMAT_S24:
+		m_rectify = bigendian ? AUD_rectify_s24_be : AUD_rectify_s24_le;
+		break;
+	default:
+		delete m_reader;
+		AUD_THROW(AUD_ERROR_READER);
+	}
+
+	m_buffer = new AUD_Buffer(); AUD_NEW("buffer")
+}
+
+AUD_RectifyReader::~AUD_RectifyReader()
+{
+	delete m_buffer; AUD_DELETE("buffer")
+}
+
+void AUD_RectifyReader::read(int & length, sample_t* & buffer)
+{
+	sample_t* buf;
+	AUD_Specs specs = m_reader->getSpecs();
+
+	m_reader->read(length, buf);
+	if(m_buffer->getSize() < length*AUD_SAMPLE_SIZE(specs))
+		m_buffer->resize(length*AUD_SAMPLE_SIZE(specs));
+
+	buffer = m_buffer->getBuffer();
+
+	m_rectify(buffer, buf, length * specs.channels);
+}

Added: trunk/blender/intern/audaspace/FX/AUD_RectifyReader.h
===================================================================
--- trunk/blender/intern/audaspace/FX/AUD_RectifyReader.h	                        (rev 0)
+++ trunk/blender/intern/audaspace/FX/AUD_RectifyReader.h	2009-12-24 14:58:11 UTC (rev 25544)
@@ -0,0 +1,65 @@
+/*
+ * $Id: AUD_VolumeReader.h 22328 2009-08-09 23:23:19Z gsrb3d $
+ *
+ * ***** 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_RECTIFYREADER
+#define AUD_RECTIFYREADER
+
+#include "AUD_EffectReader.h"
+#include "AUD_ConverterFunctions.h"
+class AUD_Buffer;
+
+/**
+ * This class reads another reader and rectifies it.
+ */
+class AUD_RectifyReader : public AUD_EffectReader
+{
+private:
+	/**
+	 * The playback buffer.
+	 */
+	AUD_Buffer *m_buffer;
+
+	/**
+	 * Rectifying function.
+	 */
+	AUD_rectify_f m_rectify;
+
+public:
+	/**
+	 * Creates a new rectify reader.
+	 * \param reader The reader to read from.
+	 * \exception AUD_Exception Thrown if the reader specified is NULL.
+	 */
+	AUD_RectifyReader(AUD_IReader* reader);
+
+	/**
+	 * Destroys the reader.
+	 */
+	virtual ~AUD_RectifyReader();
+
+	virtual void read(int & length, sample_t* & buffer);
+};
+
+#endif //AUD_RECTIFYREADER

Modified: trunk/blender/intern/audaspace/intern/AUD_C-API.cpp
===================================================================
--- trunk/blender/intern/audaspace/intern/AUD_C-API.cpp	2009-12-24 14:01:22 UTC (rev 25543)
+++ trunk/blender/intern/audaspace/intern/AUD_C-API.cpp	2009-12-24 14:58:11 UTC (rev 25544)
@@ -31,6 +31,7 @@
 #include "AUD_LimiterFactory.h"
 #include "AUD_PingPongFactory.h"
 #include "AUD_LoopFactory.h"
+#include "AUD_RectifyFactory.h"
 #include "AUD_ReadDevice.h"
 #include "AUD_SourceCaps.h"
 #include "AUD_IReader.h"
@@ -285,6 +286,20 @@
 	return false;
 }
 
+AUD_Sound* AUD_rectifySound(AUD_Sound* sound)
+{
+	assert(sound);
+
+	try
+	{
+		return new AUD_RectifyFactory(sound);
+	}
+	catch(AUD_Exception)
+	{
+		return NULL;
+	}
+}
+
 void AUD_unload(AUD_Sound* sound)
 {
 	assert(sound);

Modified: trunk/blender/intern/audaspace/intern/AUD_C-API.h
===================================================================
--- trunk/blender/intern/audaspace/intern/AUD_C-API.h	2009-12-24 14:01:22 UTC (rev 25543)
+++ trunk/blender/intern/audaspace/intern/AUD_C-API.h	2009-12-24 14:58:11 UTC (rev 25544)
@@ -150,6 +150,13 @@
 extern int AUD_stopLoop(AUD_Handle* handle);
 
 /**
+ * Rectifies a sound.
+ * \param sound The sound to rectify.
+ * \return A handle of the rectified sound.
+ */
+extern AUD_Sound* AUD_rectifySound(AUD_Sound* sound);
+
+/**
  * Unloads a sound of any type.
  * \param sound The handle of the sound.
  */

Modified: trunk/blender/intern/audaspace/intern/AUD_ConverterFunctions.cpp
===================================================================
--- trunk/blender/intern/audaspace/intern/AUD_ConverterFunctions.cpp	2009-12-24 14:01:22 UTC (rev 25543)
+++ trunk/blender/intern/audaspace/intern/AUD_ConverterFunctions.cpp	2009-12-24 14:58:11 UTC (rev 25544)
@@ -500,3 +500,43 @@
 	}
 }
 
+void AUD_rectify_u8(sample_t* target, sample_t* source, int count)
+{
+	for(int i=0; i<count; i++)
+		target[i] = source[i] < 0x80 ? 0x0100 - source[i] : source[i];
+}
+
+void AUD_rectify_s24_le(sample_t* target, sample_t* source, int count)
+{
+	count *= 3;
+	int value;
+
+	for(int i=0; i<count; i+=3)
+	{
+		value = source[i+2] << 16 | source[i+1] << 8 | source[i];
+		value |= (((value & 0x800000) >> 23) * 255) << 24;
+		if(value < 0)
+			value = -value;
+		target[i+2] = value >> 16;
+		target[i+1] = value >> 8;
+		target[i] = value;
+	}
+}
+
+void AUD_rectify_s24_be(sample_t* target, sample_t* source, int count)
+{
+	count *= 3;
+	int value;
+

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list