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
diff options
context:
space:
mode:
authorJoerg Mueller <nexyon@gmail.com>2010-07-09 12:56:25 +0400
committerJoerg Mueller <nexyon@gmail.com>2010-07-09 12:56:25 +0400
commit5460994095345ff77da42868ccf8f3d90c1733f0 (patch)
treefb349ff9b88efc3e09e91de363f04aa4eb84deb3 /intern/audaspace/FX
parent3cef95cd93f69df8b3fdddecc8473079dba1c5c1 (diff)
Audaspace:
* Comment fix for PingPongFactory * Added 2 new factory types: Superpose and Double
Diffstat (limited to 'intern/audaspace/FX')
-rw-r--r--intern/audaspace/FX/AUD_DoubleFactory.cpp55
-rw-r--r--intern/audaspace/FX/AUD_DoubleFactory.h59
-rw-r--r--intern/audaspace/FX/AUD_PingPongFactory.h4
-rw-r--r--intern/audaspace/FX/AUD_SuperposeFactory.cpp55
-rw-r--r--intern/audaspace/FX/AUD_SuperposeFactory.h59
-rw-r--r--intern/audaspace/FX/AUD_SuperposeReader.cpp144
-rw-r--r--intern/audaspace/FX/AUD_SuperposeReader.h78
7 files changed, 450 insertions, 4 deletions
diff --git a/intern/audaspace/FX/AUD_DoubleFactory.cpp b/intern/audaspace/FX/AUD_DoubleFactory.cpp
new file mode 100644
index 00000000000..402d884be9f
--- /dev/null
+++ b/intern/audaspace/FX/AUD_DoubleFactory.cpp
@@ -0,0 +1,55 @@
+/*
+ * $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_DoubleFactory.h"
+#include "AUD_DoubleReader.h"
+
+AUD_DoubleFactory::AUD_DoubleFactory(AUD_IFactory* factory1, AUD_IFactory* factory2) :
+ m_factory1(factory1), m_factory2(factory2) {}
+
+AUD_IReader* AUD_DoubleFactory::createReader()
+{
+ AUD_IReader* reader1 = m_factory1->createReader();
+ if(!reader1)
+ return 0;
+ AUD_IReader* reader2;
+ try
+ {
+ reader2 = m_factory2->createReader();
+ if(!reader2)
+ {
+ delete reader1; AUD_DELETE("reader")
+ return 0;
+ }
+ }
+ catch(AUD_Exception&)
+ {
+ delete reader1; AUD_DELETE("reader")
+ throw;
+ }
+
+ AUD_IReader* reader = new AUD_DoubleReader(reader1, reader2);
+ return reader;
+}
diff --git a/intern/audaspace/FX/AUD_DoubleFactory.h b/intern/audaspace/FX/AUD_DoubleFactory.h
new file mode 100644
index 00000000000..03c7de19f06
--- /dev/null
+++ b/intern/audaspace/FX/AUD_DoubleFactory.h
@@ -0,0 +1,59 @@
+/*
+ * $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_DOUBLEFACTORY
+#define AUD_DOUBLEFACTORY
+
+#include "AUD_IFactory.h"
+
+/**
+ * This factory plays two other factories behind each other.
+ * \note Readers from the underlying factories must have the same sample rate and channel count.
+ */
+class AUD_DoubleFactory : public AUD_IFactory
+{
+private:
+ /**
+ * First played factory.
+ */
+ AUD_IFactory* m_factory1;
+
+ /**
+ * Second played factory.
+ */
+ AUD_IFactory* m_factory2;
+
+public:
+ /**
+ * Creates a new double factory.
+ * \param factory1 The first input factory.
+ * \param factory2 The second input factory.
+ */
+ AUD_DoubleFactory(AUD_IFactory* factory1, AUD_IFactory* factory2);
+
+ virtual AUD_IReader* createReader();
+};
+
+#endif //AUD_DOUBLEFACTORY
diff --git a/intern/audaspace/FX/AUD_PingPongFactory.h b/intern/audaspace/FX/AUD_PingPongFactory.h
index b8854da550a..1bf5d5e2508 100644
--- a/intern/audaspace/FX/AUD_PingPongFactory.h
+++ b/intern/audaspace/FX/AUD_PingPongFactory.h
@@ -41,10 +41,6 @@ public:
*/
AUD_PingPongFactory(AUD_IFactory* factory = 0);
- /**
- * Destroys the factory.
- */
-
virtual AUD_IReader* createReader();
};
diff --git a/intern/audaspace/FX/AUD_SuperposeFactory.cpp b/intern/audaspace/FX/AUD_SuperposeFactory.cpp
new file mode 100644
index 00000000000..afd1ec18efb
--- /dev/null
+++ b/intern/audaspace/FX/AUD_SuperposeFactory.cpp
@@ -0,0 +1,55 @@
+/*
+ * $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_SuperposeFactory.h"
+#include "AUD_SuperposeReader.h"
+
+AUD_SuperposeFactory::AUD_SuperposeFactory(AUD_IFactory* factory1, AUD_IFactory* factory2) :
+ m_factory1(factory1), m_factory2(factory2) {}
+
+AUD_IReader* AUD_SuperposeFactory::createReader()
+{
+ AUD_IReader* reader1 = m_factory1->createReader();
+ if(!reader1)
+ return 0;
+ AUD_IReader* reader2;
+ try
+ {
+ reader2 = m_factory2->createReader();
+ if(!reader2)
+ {
+ delete reader1; AUD_DELETE("reader")
+ return 0;
+ }
+ }
+ catch(AUD_Exception&)
+ {
+ delete reader1; AUD_DELETE("reader")
+ throw;
+ }
+
+ AUD_IReader* reader = new AUD_SuperposeReader(reader1, reader2);
+ return reader;
+}
diff --git a/intern/audaspace/FX/AUD_SuperposeFactory.h b/intern/audaspace/FX/AUD_SuperposeFactory.h
new file mode 100644
index 00000000000..44e79d76887
--- /dev/null
+++ b/intern/audaspace/FX/AUD_SuperposeFactory.h
@@ -0,0 +1,59 @@
+/*
+ * $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_SUPERPOSEFACTORY
+#define AUD_SUPERPOSEFACTORY
+
+#include "AUD_IFactory.h"
+
+/**
+ * This factory plays two other factories behind each other.
+ * \note Readers from the underlying factories must have the same sample rate and channel count.
+ */
+class AUD_SuperposeFactory : public AUD_IFactory
+{
+private:
+ /**
+ * First played factory.
+ */
+ AUD_IFactory* m_factory1;
+
+ /**
+ * Second played factory.
+ */
+ AUD_IFactory* m_factory2;
+
+public:
+ /**
+ * Creates a new superpose factory.
+ * \param factory1 The first input factory.
+ * \param factory2 The second input factory.
+ */
+ AUD_SuperposeFactory(AUD_IFactory* factory1, AUD_IFactory* factory2);
+
+ virtual AUD_IReader* createReader();
+};
+
+#endif //AUD_SUPERPOSEFACTORY
diff --git a/intern/audaspace/FX/AUD_SuperposeReader.cpp b/intern/audaspace/FX/AUD_SuperposeReader.cpp
new file mode 100644
index 00000000000..6519f272110
--- /dev/null
+++ b/intern/audaspace/FX/AUD_SuperposeReader.cpp
@@ -0,0 +1,144 @@
+/*
+ * $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_SuperposeReader.h"
+#include "AUD_Buffer.h"
+
+#include <cstring>
+
+AUD_SuperposeReader::AUD_SuperposeReader(AUD_IReader* reader1, AUD_IReader* reader2) :
+ m_reader1(reader1), m_reader2(reader2)
+{
+ try
+ {
+ if(!reader1)
+ AUD_THROW(AUD_ERROR_READER);
+
+ if(!reader2)
+ AUD_THROW(AUD_ERROR_READER);
+
+ AUD_Specs s1, s2;
+ s1 = reader1->getSpecs();
+ s2 = reader2->getSpecs();
+ if(memcmp(&s1, &s2, sizeof(AUD_Specs)) != 0)
+ AUD_THROW(AUD_ERROR_READER);
+ }
+
+ catch(AUD_Exception)
+ {
+ if(reader1)
+ {
+ delete reader1; AUD_DELETE("reader")
+ }
+ if(reader2)
+ {
+ delete reader2; AUD_DELETE("reader")
+ }
+
+ throw;
+ }
+
+ m_buffer = new AUD_Buffer(); AUD_NEW("buffer")
+}
+
+AUD_SuperposeReader::~AUD_SuperposeReader()
+{
+ delete m_reader1; AUD_DELETE("reader")
+ delete m_reader2; AUD_DELETE("reader")
+ delete m_buffer; AUD_DELETE("buffer")
+}
+
+bool AUD_SuperposeReader::isSeekable()
+{
+ return m_reader1->isSeekable() && m_reader2->isSeekable();
+}
+
+void AUD_SuperposeReader::seek(int position)
+{
+ m_reader1->seek(position);
+ m_reader2->seek(position);
+}
+
+int AUD_SuperposeReader::getLength()
+{
+ int len1 = m_reader1->getLength();
+ int len2 = m_reader2->getLength();
+ if((len1 < 0) || (len2 < 0))
+ return -1;
+ if(len1 < len2)
+ return len2;
+ return len1;
+}
+
+int AUD_SuperposeReader::getPosition()
+{
+ int pos1 = m_reader1->getPosition();
+ int pos2 = m_reader2->getPosition();
+ return AUD_MAX(pos1, pos2);
+}
+
+AUD_Specs AUD_SuperposeReader::getSpecs()
+{
+ return m_reader1->getSpecs();
+}
+
+AUD_ReaderType AUD_SuperposeReader::getType()
+{
+ if(m_reader1->getType() == AUD_TYPE_BUFFER &&
+ m_reader2->getType() == AUD_TYPE_BUFFER)
+ return AUD_TYPE_BUFFER;
+ return AUD_TYPE_STREAM;
+}
+
+bool AUD_SuperposeReader::notify(AUD_Message &message)
+{
+ return m_reader1->notify(message) | m_reader2->notify(message);
+}
+
+void AUD_SuperposeReader::read(int & length, sample_t* & buffer)
+{
+ AUD_Specs specs = m_reader1->getSpecs();
+ int samplesize = AUD_SAMPLE_SIZE(specs);
+
+ if(m_buffer->getSize() < length * samplesize)
+ m_buffer->resize(length * samplesize);
+ buffer = m_buffer->getBuffer();
+
+ int len1 = length;
+ sample_t* buf;
+ m_reader1->read(len1, buf);
+ memcpy(buffer, buf, len1 * samplesize);
+
+ if(len1 < length)
+ memset(buffer + len1 * specs.channels, 0, (length - len1) * samplesize);
+
+ int len2 = length;
+ m_reader2->read(len2, buf);
+
+ for(int i = 0; i < len2 * specs.channels; i++)
+ buffer[i] += buf[i];
+
+ length = AUD_MAX(len1, len2);
+}
diff --git a/intern/audaspace/FX/AUD_SuperposeReader.h b/intern/audaspace/FX/AUD_SuperposeReader.h
new file mode 100644
index 00000000000..71392b1133b
--- /dev/null
+++ b/intern/audaspace/FX/AUD_SuperposeReader.h
@@ -0,0 +1,78 @@
+/*
+ * $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_SUPERPOSEREADER
+#define AUD_SUPERPOSEREADER
+
+#include "AUD_IReader.h"
+class AUD_Buffer;
+
+/**
+ * This reader plays two readers with the same specs sequently.
+ */
+class AUD_SuperposeReader : public AUD_IReader
+{
+private:
+ /**
+ * The first reader.
+ */
+ AUD_IReader* m_reader1;
+
+ /**
+ * The second reader.
+ */
+ AUD_IReader* m_reader2;
+
+ /**
+ * The playback buffer for the intersecting part.
+ */
+ AUD_Buffer* m_buffer;
+
+public:
+ /**
+ * Creates a new superpose reader.
+ * \param reader1 The first reader to read from.
+ * \param reader2 The second reader to read from.
+ * \exception AUD_Exception Thrown if one of the reader specified is NULL
+ * or the specs from the readers differ.
+ */
+ AUD_SuperposeReader(AUD_IReader* reader1, AUD_IReader* reader2);
+
+ /**
+ * Destroys the reader.
+ */
+ virtual ~AUD_SuperposeReader();
+
+ virtual bool isSeekable();
+ virtual void seek(int position);
+ virtual int getLength();
+ virtual int getPosition();
+ virtual AUD_Specs getSpecs();
+ virtual AUD_ReaderType getType();
+ virtual bool notify(AUD_Message &message);
+ virtual void read(int & length, sample_t* & buffer);
+};
+
+#endif //AUD_SUPERPOSEREADER