Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/intern
diff options
context:
space:
mode:
authorJoerg Mueller <nexyon@gmail.com>2009-12-24 17:58:11 +0300
committerJoerg Mueller <nexyon@gmail.com>2009-12-24 17:58:11 +0300
commit1d224ad692c8794500f4d6fd5257887db150a635 (patch)
treea375be4aacfec86a4c60d1231a97f7efc2ecc373 /intern
parenta2b0020e11e27c6d7ecdacf747a4543ab733867b (diff)
Added rectifying sound effect (will be used for sound -> f-curve later).
Diffstat (limited to 'intern')
-rw-r--r--intern/audaspace/FX/AUD_RectifyFactory.cpp45
-rw-r--r--intern/audaspace/FX/AUD_RectifyFactory.h51
-rw-r--r--intern/audaspace/FX/AUD_RectifyReader.cpp82
-rw-r--r--intern/audaspace/FX/AUD_RectifyReader.h65
-rw-r--r--intern/audaspace/intern/AUD_C-API.cpp15
-rw-r--r--intern/audaspace/intern/AUD_C-API.h7
-rw-r--r--intern/audaspace/intern/AUD_ConverterFunctions.cpp40
-rw-r--r--intern/audaspace/intern/AUD_ConverterFunctions.h17
8 files changed, 322 insertions, 0 deletions
diff --git a/intern/audaspace/FX/AUD_RectifyFactory.cpp b/intern/audaspace/FX/AUD_RectifyFactory.cpp
new file mode 100644
index 00000000000..21786aea133
--- /dev/null
+++ b/intern/audaspace/FX/AUD_RectifyFactory.cpp
@@ -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;
+}
diff --git a/intern/audaspace/FX/AUD_RectifyFactory.h b/intern/audaspace/FX/AUD_RectifyFactory.h
new file mode 100644
index 00000000000..bc84f111832
--- /dev/null
+++ b/intern/audaspace/FX/AUD_RectifyFactory.h
@@ -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
diff --git a/intern/audaspace/FX/AUD_RectifyReader.cpp b/intern/audaspace/FX/AUD_RectifyReader.cpp
new file mode 100644
index 00000000000..aeb5ee74cbd
--- /dev/null
+++ b/intern/audaspace/FX/AUD_RectifyReader.cpp
@@ -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);
+}
diff --git a/intern/audaspace/FX/AUD_RectifyReader.h b/intern/audaspace/FX/AUD_RectifyReader.h
new file mode 100644
index 00000000000..35817db636b
--- /dev/null
+++ b/intern/audaspace/FX/AUD_RectifyReader.h
@@ -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
diff --git a/intern/audaspace/intern/AUD_C-API.cpp b/intern/audaspace/intern/AUD_C-API.cpp
index 255d1d2f1f6..cd6b95b1d9e 100644
--- a/intern/audaspace/intern/AUD_C-API.cpp
+++ b/intern/audaspace/intern/AUD_C-API.cpp
@@ -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 @@ int AUD_stopLoop(AUD_Handle* handle)
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);
diff --git a/intern/audaspace/intern/AUD_C-API.h b/intern/audaspace/intern/AUD_C-API.h
index 66a5a5147b3..866f0248cb2 100644
--- a/intern/audaspace/intern/AUD_C-API.h
+++ b/intern/audaspace/intern/AUD_C-API.h
@@ -150,6 +150,13 @@ extern AUD_Sound* AUD_loopSound(AUD_Sound* sound);
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.
*/
diff --git a/intern/audaspace/intern/AUD_ConverterFunctions.cpp b/intern/audaspace/intern/AUD_ConverterFunctions.cpp
index b6d5dffa1a2..1b5d07bcc61 100644
--- a/intern/audaspace/intern/AUD_ConverterFunctions.cpp
+++ b/intern/audaspace/intern/AUD_ConverterFunctions.cpp
@@ -500,3 +500,43 @@ void AUD_volume_adjust_s24_be(sample_t* target, sample_t* source,
}
}
+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;
+
+ for(int i=0; i < count; i+=3)
+ {
+ value = source[i] << 16 | source[i+1] << 8 | source[i+2];
+ value |= (((value & 0x800000) >> 23) * 255) << 24;
+ if(value < 0)
+ value = -value;
+ target[i] = value >> 16;
+ target[i+1] = value >> 8;
+ target[i+2] = value;
+ }
+}
+
diff --git a/intern/audaspace/intern/AUD_ConverterFunctions.h b/intern/audaspace/intern/AUD_ConverterFunctions.h
index c1dd0f4a3a2..686e58704b7 100644
--- a/intern/audaspace/intern/AUD_ConverterFunctions.h
+++ b/intern/audaspace/intern/AUD_ConverterFunctions.h
@@ -46,6 +46,8 @@ typedef void (*AUD_convert_f)(sample_t* target, sample_t* source, int length);
typedef void (*AUD_volume_adjust_f)(sample_t* target, sample_t* source,
int count, float volume);
+typedef void (*AUD_rectify_f)(sample_t* target, sample_t* source, int count);
+
template <class T>
void AUD_convert_copy(sample_t* target, sample_t* source, int length)
{
@@ -153,4 +155,19 @@ void AUD_volume_adjust_s24_le(sample_t* target, sample_t* source,
void AUD_volume_adjust_s24_be(sample_t* target, sample_t* source,
int count, float volume);
+template <class T>
+void AUD_rectify(sample_t* target, sample_t* source, int count)
+{
+ T* t = (T*)target;
+ T* s = (T*)source;
+ for(int i=0; i < count; i++)
+ t[i] = s[i] < 0 ? -s[i] : s[i];
+}
+
+void AUD_rectify_u8(sample_t* target, sample_t* source, int count);
+
+void AUD_rectify_s24_le(sample_t* target, sample_t* source, int count);
+
+void AUD_rectify_s24_be(sample_t* target, sample_t* source, int count);
+
#endif //AUD_CONVERTERFUNCTIONS