From 637873deb0952bdd64d4fb461145685379191210 Mon Sep 17 00:00:00 2001 From: Joerg Mueller Date: Fri, 1 Jan 2010 18:45:21 +0000 Subject: Added another three effects that you can use with the Sound to F-Curve modifier, have fun! --- intern/audaspace/FX/AUD_AccumulatorFactory.cpp | 49 +++++++++++++ intern/audaspace/FX/AUD_AccumulatorFactory.h | 59 +++++++++++++++ intern/audaspace/FX/AUD_AccumulatorReader.cpp | 99 ++++++++++++++++++++++++++ intern/audaspace/FX/AUD_AccumulatorReader.h | 75 +++++++++++++++++++ intern/audaspace/FX/AUD_SquareFactory.cpp | 57 +++++++++++++++ intern/audaspace/FX/AUD_SquareFactory.h | 70 ++++++++++++++++++ intern/audaspace/FX/AUD_SquareReader.cpp | 63 ++++++++++++++++ intern/audaspace/FX/AUD_SquareReader.h | 65 +++++++++++++++++ intern/audaspace/FX/AUD_SumFactory.cpp | 43 +++++++++++ intern/audaspace/FX/AUD_SumFactory.h | 46 ++++++++++++ intern/audaspace/FX/AUD_SumReader.cpp | 68 ++++++++++++++++++ intern/audaspace/FX/AUD_SumReader.h | 64 +++++++++++++++++ 12 files changed, 758 insertions(+) create mode 100644 intern/audaspace/FX/AUD_AccumulatorFactory.cpp create mode 100644 intern/audaspace/FX/AUD_AccumulatorFactory.h create mode 100644 intern/audaspace/FX/AUD_AccumulatorReader.cpp create mode 100644 intern/audaspace/FX/AUD_AccumulatorReader.h create mode 100644 intern/audaspace/FX/AUD_SquareFactory.cpp create mode 100644 intern/audaspace/FX/AUD_SquareFactory.h create mode 100644 intern/audaspace/FX/AUD_SquareReader.cpp create mode 100644 intern/audaspace/FX/AUD_SquareReader.h create mode 100644 intern/audaspace/FX/AUD_SumFactory.cpp create mode 100644 intern/audaspace/FX/AUD_SumFactory.h create mode 100644 intern/audaspace/FX/AUD_SumReader.cpp create mode 100644 intern/audaspace/FX/AUD_SumReader.h (limited to 'intern/audaspace/FX') diff --git a/intern/audaspace/FX/AUD_AccumulatorFactory.cpp b/intern/audaspace/FX/AUD_AccumulatorFactory.cpp new file mode 100644 index 00000000000..20709c57ee5 --- /dev/null +++ b/intern/audaspace/FX/AUD_AccumulatorFactory.cpp @@ -0,0 +1,49 @@ +/* + * $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 . + * + * ***** END LGPL LICENSE BLOCK ***** + */ + +#include "AUD_AccumulatorFactory.h" +#include "AUD_AccumulatorReader.h" + +AUD_AccumulatorFactory::AUD_AccumulatorFactory(AUD_IFactory* factory, + bool additive) : + AUD_EffectFactory(factory), + m_additive(additive) {} + +AUD_AccumulatorFactory::AUD_AccumulatorFactory(bool additive) : + AUD_EffectFactory(0), + m_additive(additive) {} + +AUD_IReader* AUD_AccumulatorFactory::createReader() +{ + AUD_IReader* reader = getReader(); + + if(reader != 0) + { + reader = new AUD_AccumulatorReader(reader, m_additive); + AUD_NEW("reader") + } + + return reader; +} diff --git a/intern/audaspace/FX/AUD_AccumulatorFactory.h b/intern/audaspace/FX/AUD_AccumulatorFactory.h new file mode 100644 index 00000000000..e475a19ccf6 --- /dev/null +++ b/intern/audaspace/FX/AUD_AccumulatorFactory.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 . + * + * ***** END LGPL LICENSE BLOCK ***** + */ + +#ifndef AUD_ACCUMULATORFACTORY +#define AUD_ACCUMULATORFACTORY + +#include "AUD_EffectFactory.h" + +/** + * This factory creates an accumulator reader. + */ +class AUD_AccumulatorFactory : public AUD_EffectFactory +{ +private: + /** + * Whether the accumulator is additive. + */ + bool m_additive; + +public: + /** + * Creates a new accumulator factory. + * \param factory The input factory. + * \param additive Whether the accumulator is additive. + */ + AUD_AccumulatorFactory(AUD_IFactory* factory, bool additive = false); + + /** + * Creates a new accumulator factory. + * \param additive Whether the accumulator is additive. + */ + AUD_AccumulatorFactory(bool additive = false); + + virtual AUD_IReader* createReader(); +}; + +#endif //AUD_ACCUMULATORFACTORY diff --git a/intern/audaspace/FX/AUD_AccumulatorReader.cpp b/intern/audaspace/FX/AUD_AccumulatorReader.cpp new file mode 100644 index 00000000000..67ab4157f9c --- /dev/null +++ b/intern/audaspace/FX/AUD_AccumulatorReader.cpp @@ -0,0 +1,99 @@ +/* + * $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 . + * + * ***** END LGPL LICENSE BLOCK ***** + */ + +#include "AUD_AccumulatorReader.h" +#include "AUD_Buffer.h" + +#include + +#define CC specs.channels + channel + +AUD_AccumulatorReader::AUD_AccumulatorReader(AUD_IReader* reader, + bool additive) : + AUD_EffectReader(reader), + m_additive(additive) +{ + AUD_Specs specs = reader->getSpecs(); + int samplesize = AUD_SAMPLE_SIZE(specs); + + m_buffer = new AUD_Buffer(); AUD_NEW("buffer") + + m_sums = new AUD_Buffer(samplesize); AUD_NEW("buffer") + memset(m_sums->getBuffer(), 0, samplesize); + + m_prevs = new AUD_Buffer(samplesize); AUD_NEW("buffer") + memset(m_prevs->getBuffer(), 0, samplesize); +} + +AUD_AccumulatorReader::~AUD_AccumulatorReader() +{ + delete m_buffer; AUD_DELETE("buffer") + delete m_sums; AUD_DELETE("buffer") + delete m_prevs; AUD_DELETE("buffer") +} + +void AUD_AccumulatorReader::read(int & length, sample_t* & buffer) +{ + sample_t* buf; + sample_t* sums; + sample_t* prevs; + sums = m_sums->getBuffer(); + prevs = m_prevs->getBuffer(); + + 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(); + + if(m_additive) + { + for(int channel = 0; channel < specs.channels; channel++) + { + for(int i = 0; i < length; i++) + { + if(buf[i * CC] > prevs[channel]) + sums[channel] += buf[i * CC] - prevs[channel]; + buffer[i * CC] = sums[channel] + buf[i * CC]; + prevs[channel] = buf[i * CC]; + } + } + } + else + { + for(int channel = 0; channel < specs.channels; channel++) + { + for(int i = 0; i < length * specs.channels; i++) + { + if(buf[i * CC] > prevs[channel]) + sums[channel] += buf[i * CC] - prevs[channel]; + buffer[i * CC] = sums[channel]; + prevs[channel] = buf[i * CC]; + } + } + } +} diff --git a/intern/audaspace/FX/AUD_AccumulatorReader.h b/intern/audaspace/FX/AUD_AccumulatorReader.h new file mode 100644 index 00000000000..8ad1dda30f6 --- /dev/null +++ b/intern/audaspace/FX/AUD_AccumulatorReader.h @@ -0,0 +1,75 @@ +/* + * $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 . + * + * ***** END LGPL LICENSE BLOCK ***** + */ + +#ifndef AUD_ACCUMULATORREADER +#define AUD_ACCUMULATORREADER + +#include "AUD_EffectReader.h" +class AUD_Buffer; + +/** + * This class represents an accumulator. + */ +class AUD_AccumulatorReader : public AUD_EffectReader +{ +private: + /** + * The playback buffer. + */ + AUD_Buffer *m_buffer; + + /** + * The sums of the specific channels. + */ + AUD_Buffer *m_sums; + + /** + * The previous results of the specific channels. + */ + AUD_Buffer *m_prevs; + + /** + * Whether the accumulator is additive. + */ + bool m_additive; + +public: + /** + * Creates a new accumulator reader. + * \param reader The reader to read from. + * \param additive Whether the accumulator is additive. + * \exception AUD_Exception Thrown if the reader specified is NULL. + */ + AUD_AccumulatorReader(AUD_IReader* reader, bool additive); + + /** + * Destroys the reader. + */ + virtual ~AUD_AccumulatorReader(); + + virtual void read(int & length, sample_t* & buffer); +}; + +#endif //AUD_ACCUMULATORREADER diff --git a/intern/audaspace/FX/AUD_SquareFactory.cpp b/intern/audaspace/FX/AUD_SquareFactory.cpp new file mode 100644 index 00000000000..638acaa9a32 --- /dev/null +++ b/intern/audaspace/FX/AUD_SquareFactory.cpp @@ -0,0 +1,57 @@ +/* + * $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 . + * + * ***** END LGPL LICENSE BLOCK ***** + */ + +#include "AUD_SquareFactory.h" +#include "AUD_SquareReader.h" + +AUD_SquareFactory::AUD_SquareFactory(AUD_IFactory* factory, float threshold) : + AUD_EffectFactory(factory), + m_threshold(threshold) {} + +AUD_SquareFactory::AUD_SquareFactory(float threshold) : + AUD_EffectFactory(0), + m_threshold(threshold) {} + +float AUD_SquareFactory::getThreshold() +{ + return m_threshold; +} + +void AUD_SquareFactory::setThreshold(float threshold) +{ + m_threshold = threshold; +} + +AUD_IReader* AUD_SquareFactory::createReader() +{ + AUD_IReader* reader = getReader(); + + if(reader != 0) + { + reader = new AUD_SquareReader(reader, m_threshold); AUD_NEW("reader") + } + + return reader; +} diff --git a/intern/audaspace/FX/AUD_SquareFactory.h b/intern/audaspace/FX/AUD_SquareFactory.h new file mode 100644 index 00000000000..dfbe5ae2887 --- /dev/null +++ b/intern/audaspace/FX/AUD_SquareFactory.h @@ -0,0 +1,70 @@ +/* + * $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 . + * + * ***** END LGPL LICENSE BLOCK ***** + */ + +#ifndef AUD_SQUAREFACTORY +#define AUD_SQUAREFACTORY + +#include "AUD_EffectFactory.h" + +/** + * This factory Transforms any signal to a square signal. + */ +class AUD_SquareFactory : public AUD_EffectFactory +{ +private: + /** + * The threshold. + */ + float m_threshold; + +public: + /** + * Creates a new square factory. + * \param factory The input factory. + * \param threshold The threshold. + */ + AUD_SquareFactory(AUD_IFactory* factory = 0, float threshold = 0.0f); + + /** + * Creates a new square factory. + * \param threshold The threshold. + */ + AUD_SquareFactory(float threshold); + + /** + * Returns the threshold. + */ + float getThreshold(); + + /** + * Sets the threshold. + * \param threshold The new threshold value. Should be between 0.0 and 1.0. + */ + void setThreshold(float threshold); + + virtual AUD_IReader* createReader(); +}; + +#endif //AUD_SQUAREFACTORY diff --git a/intern/audaspace/FX/AUD_SquareReader.cpp b/intern/audaspace/FX/AUD_SquareReader.cpp new file mode 100644 index 00000000000..2d4dc52fe27 --- /dev/null +++ b/intern/audaspace/FX/AUD_SquareReader.cpp @@ -0,0 +1,63 @@ +/* + * $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 . + * + * ***** END LGPL LICENSE BLOCK ***** + */ + +#include "AUD_SquareReader.h" +#include "AUD_Buffer.h" + +#include + +AUD_SquareReader::AUD_SquareReader(AUD_IReader* reader, float threshold) : + AUD_EffectReader(reader), + m_threshold(threshold) +{ + m_buffer = new AUD_Buffer(); AUD_NEW("buffer") +} + +AUD_SquareReader::~AUD_SquareReader() +{ + delete m_buffer; AUD_DELETE("buffer") +} + +void AUD_SquareReader::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(); + + for(int i = 0; i < length * specs.channels; i++) + { + if(buf[i] >= m_threshold) + buffer[i] = 1.0f; + else if(buf[i] <= -m_threshold) + buffer[i] = -1.0f; + else + buffer[i] = 0.0f; + } +} diff --git a/intern/audaspace/FX/AUD_SquareReader.h b/intern/audaspace/FX/AUD_SquareReader.h new file mode 100644 index 00000000000..63dda351445 --- /dev/null +++ b/intern/audaspace/FX/AUD_SquareReader.h @@ -0,0 +1,65 @@ +/* + * $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 . + * + * ***** END LGPL LICENSE BLOCK ***** + */ + +#ifndef AUD_SQUAREREADER +#define AUD_SQUAREREADER + +#include "AUD_EffectReader.h" +class AUD_Buffer; + +/** + * This class changes another signal into a square signal. + */ +class AUD_SquareReader : public AUD_EffectReader +{ +private: + /** + * The playback buffer. + */ + AUD_Buffer *m_buffer; + + /** + * The threshold level. + */ + float m_threshold; + +public: + /** + * Creates a new square reader. + * \param reader The reader to read from. + * \param threshold The size of the buffer. + * \exception AUD_Exception Thrown if the reader specified is NULL. + */ + AUD_SquareReader(AUD_IReader* reader, float threshold); + + /** + * Destroys the reader. + */ + virtual ~AUD_SquareReader(); + + virtual void read(int & length, sample_t* & buffer); +}; + +#endif //AUD_SQUAREREADER diff --git a/intern/audaspace/FX/AUD_SumFactory.cpp b/intern/audaspace/FX/AUD_SumFactory.cpp new file mode 100644 index 00000000000..f7990aab8a1 --- /dev/null +++ b/intern/audaspace/FX/AUD_SumFactory.cpp @@ -0,0 +1,43 @@ +/* + * $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 . + * + * ***** END LGPL LICENSE BLOCK ***** + */ + +#include "AUD_SumFactory.h" +#include "AUD_SumReader.h" + +AUD_SumFactory::AUD_SumFactory(AUD_IFactory* factory) : + AUD_EffectFactory(factory) {} + +AUD_IReader* AUD_SumFactory::createReader() +{ + AUD_IReader* reader = getReader(); + + if(reader != 0) + { + reader = new AUD_SumReader(reader); + AUD_NEW("reader") + } + + return reader; +} diff --git a/intern/audaspace/FX/AUD_SumFactory.h b/intern/audaspace/FX/AUD_SumFactory.h new file mode 100644 index 00000000000..5cb48e26b10 --- /dev/null +++ b/intern/audaspace/FX/AUD_SumFactory.h @@ -0,0 +1,46 @@ +/* + * $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 . + * + * ***** END LGPL LICENSE BLOCK ***** + */ + +#ifndef AUD_SUMFACTORY +#define AUD_SUMFACTORY + +#include "AUD_EffectFactory.h" + +/** + * This factory creates a sum reader. + */ +class AUD_SumFactory : public AUD_EffectFactory +{ +public: + /** + * Creates a new sum factory. + * \param factory The input factory. + */ + AUD_SumFactory(AUD_IFactory* factory = 0); + + virtual AUD_IReader* createReader(); +}; + +#endif //AUD_SUMFACTORY diff --git a/intern/audaspace/FX/AUD_SumReader.cpp b/intern/audaspace/FX/AUD_SumReader.cpp new file mode 100644 index 00000000000..08747790fc9 --- /dev/null +++ b/intern/audaspace/FX/AUD_SumReader.cpp @@ -0,0 +1,68 @@ +/* + * $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 . + * + * ***** END LGPL LICENSE BLOCK ***** + */ + +#include "AUD_SumReader.h" +#include "AUD_Buffer.h" + +#include + +#define CC specs.channels + channel + +AUD_SumReader::AUD_SumReader(AUD_IReader* reader) : + AUD_EffectReader(reader) +{ + AUD_Specs specs = reader->getSpecs(); + int samplesize = AUD_SAMPLE_SIZE(specs); + + m_buffer = new AUD_Buffer(); AUD_NEW("buffer") + + m_sums = new AUD_Buffer(samplesize); AUD_NEW("buffer") + memset(m_sums->getBuffer(), 0, samplesize); +} + +AUD_SumReader::~AUD_SumReader() +{ + delete m_buffer; AUD_DELETE("buffer") + delete m_sums; AUD_DELETE("buffer") +} + +void AUD_SumReader::read(int & length, sample_t* & buffer) +{ + sample_t* buf; + sample_t* sums; + sums = m_sums->getBuffer(); + + 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(); + + for(int channel = 0; channel < specs.channels; channel++) + for(int i = 0; i < length * specs.channels; i++) + buffer[i * CC] = sums[channel] = sums[channel] + buf[i * CC]; +} diff --git a/intern/audaspace/FX/AUD_SumReader.h b/intern/audaspace/FX/AUD_SumReader.h new file mode 100644 index 00000000000..76ccf2f863a --- /dev/null +++ b/intern/audaspace/FX/AUD_SumReader.h @@ -0,0 +1,64 @@ +/* + * $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 . + * + * ***** END LGPL LICENSE BLOCK ***** + */ + +#ifndef AUD_SUMREADER +#define AUD_SUMREADER + +#include "AUD_EffectReader.h" +class AUD_Buffer; + +/** + * This class represents an summer. + */ +class AUD_SumReader : public AUD_EffectReader +{ +private: + /** + * The playback buffer. + */ + AUD_Buffer *m_buffer; + + /** + * The sums of the specific channels. + */ + AUD_Buffer *m_sums; + +public: + /** + * Creates a new sum reader. + * \param reader The reader to read from. + * \exception AUD_Exception Thrown if the reader specified is NULL. + */ + AUD_SumReader(AUD_IReader* reader); + + /** + * Destroys the reader. + */ + virtual ~AUD_SumReader(); + + virtual void read(int & length, sample_t* & buffer); +}; + +#endif //AUD_SUMREADER -- cgit v1.2.3