From d2e6e2a67e272563535e7b673ed4747b3cfc7744 Mon Sep 17 00:00:00 2001 From: Joseph Eagar Date: Wed, 13 Jan 2010 08:16:14 +0000 Subject: [PATCH] more files --- .../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 +++++++++++ .../audaspace/FX/AUD_ButterworthFactory.cpp | 49 +++++++ intern/audaspace/FX/AUD_ButterworthFactory.h | 59 +++++++++ intern/audaspace/FX/AUD_ButterworthReader.cpp | 124 ++++++++++++++++++ intern/audaspace/FX/AUD_ButterworthReader.h | 83 ++++++++++++ intern/audaspace/FX/AUD_EnvelopeFactory.cpp | 58 ++++++++ intern/audaspace/FX/AUD_EnvelopeFactory.h | 82 ++++++++++++ intern/audaspace/FX/AUD_EnvelopeReader.cpp | 86 ++++++++++++ intern/audaspace/FX/AUD_EnvelopeReader.h | 84 ++++++++++++ intern/audaspace/FX/AUD_HighpassFactory.cpp | 51 +++++++ intern/audaspace/FX/AUD_HighpassFactory.h | 66 ++++++++++ intern/audaspace/FX/AUD_HighpassReader.cpp | 116 ++++++++++++++++ intern/audaspace/FX/AUD_HighpassReader.h | 83 ++++++++++++ intern/audaspace/FX/AUD_LowpassFactory.cpp | 51 +++++++ intern/audaspace/FX/AUD_LowpassFactory.h | 66 ++++++++++ intern/audaspace/FX/AUD_LowpassReader.cpp | 115 ++++++++++++++++ intern/audaspace/FX/AUD_LowpassReader.h | 83 ++++++++++++ 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 +++++++++ 28 files changed, 2014 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_ButterworthFactory.cpp create mode 100644 intern/audaspace/FX/AUD_ButterworthFactory.h create mode 100644 intern/audaspace/FX/AUD_ButterworthReader.cpp create mode 100644 intern/audaspace/FX/AUD_ButterworthReader.h create mode 100644 intern/audaspace/FX/AUD_EnvelopeFactory.cpp create mode 100644 intern/audaspace/FX/AUD_EnvelopeFactory.h create mode 100644 intern/audaspace/FX/AUD_EnvelopeReader.cpp create mode 100644 intern/audaspace/FX/AUD_EnvelopeReader.h create mode 100644 intern/audaspace/FX/AUD_HighpassFactory.cpp create mode 100644 intern/audaspace/FX/AUD_HighpassFactory.h create mode 100644 intern/audaspace/FX/AUD_HighpassReader.cpp create mode 100644 intern/audaspace/FX/AUD_HighpassReader.h create mode 100644 intern/audaspace/FX/AUD_LowpassFactory.cpp create mode 100644 intern/audaspace/FX/AUD_LowpassFactory.h create mode 100644 intern/audaspace/FX/AUD_LowpassReader.cpp create mode 100644 intern/audaspace/FX/AUD_LowpassReader.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 diff --git a/intern/audaspace/FX/AUD_AccumulatorFactory.cpp b/intern/audaspace/FX/AUD_AccumulatorFactory.cpp new file mode 100644 index 00000000000..62d3fba818e --- /dev/null +++ b/intern/audaspace/FX/AUD_AccumulatorFactory.cpp @@ -0,0 +1,49 @@ +/* + * $Id: AUD_AccumulatorFactory.cpp 25656 2010-01-01 18:45:21Z nexyon $ + * + * ***** 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..ea7b25d6171 --- /dev/null +++ b/intern/audaspace/FX/AUD_AccumulatorFactory.h @@ -0,0 +1,59 @@ +/* + * $Id: AUD_AccumulatorFactory.h 25656 2010-01-01 18:45:21Z nexyon $ + * + * ***** 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..a5aeb72cca5 --- /dev/null +++ b/intern/audaspace/FX/AUD_AccumulatorReader.cpp @@ -0,0 +1,99 @@ +/* + * $Id: AUD_AccumulatorReader.cpp 25656 2010-01-01 18:45:21Z nexyon $ + * + * ***** 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..45cc0cf36c9 --- /dev/null +++ b/intern/audaspace/FX/AUD_AccumulatorReader.h @@ -0,0 +1,75 @@ +/* + * $Id: AUD_AccumulatorReader.h 25656 2010-01-01 18:45:21Z nexyon $ + * + * ***** 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_ButterworthFactory.cpp b/intern/audaspace/FX/AUD_ButterworthFactory.cpp new file mode 100644 index 00000000000..f75790e4ad2 --- /dev/null +++ b/intern/audaspace/FX/AUD_ButterworthFactory.cpp @@ -0,0 +1,49 @@ +/* + * $Id: AUD_ButterworthFactory.cpp 25643 2010-01-01 05:09:30Z nexyon $ + * + * ***** 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_ButterworthFactory.h" +#include "AUD_ButterworthReader.h" + +AUD_ButterworthFactory::AUD_ButterworthFactory(AUD_IFactory* factory, + float frequency) : + AUD_EffectFactory(factory), + m_frequency(frequency) {} + +AUD_ButterworthFactory::AUD_ButterworthFactory(float frequency) : + AUD_EffectFactory(0), + m_frequency(frequency) {} + +AUD_IReader* AUD_ButterworthFactory::createReader() +{ + AUD_IReader* reader = getReader(); + + if(reader != 0) + { + reader = new AUD_ButterworthReader(reader, m_frequency); + AUD_NEW("reader") + } + + return reader; +} diff --git a/intern/audaspace/FX/AUD_ButterworthFactory.h b/intern/audaspace/FX/AUD_ButterworthFactory.h new file mode 100644 index 00000000000..7854927e76d --- /dev/null +++ b/intern/audaspace/FX/AUD_ButterworthFactory.h @@ -0,0 +1,59 @@ +/* + * $Id: AUD_ButterworthFactory.h 25643 2010-01-01 05:09:30Z nexyon $ + * + * ***** 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_BUTTERWORTHFACTORY +#define AUD_BUTTERWORTHFACTORY + +#include "AUD_EffectFactory.h" + +/** + * This factory creates a butterworth filter reader. + */ +class AUD_ButterworthFactory : public AUD_EffectFactory +{ +private: + /** + * The attack value in seconds. + */ + float m_frequency; + +public: + /** + * Creates a new butterworth factory. + * \param factory The input factory. + * \param frequency The cutoff frequency. + */ + AUD_ButterworthFactory(AUD_IFactory* factory, float frequency); + + /** + * Creates a new butterworth factory. + * \param frequency The cutoff frequency. + */ + AUD_ButterworthFactory(float frequency); + + virtual AUD_IReader* createReader(); +}; + +#endif //AUD_BUTTERWORTHFACTORY diff --git a/intern/audaspace/FX/AUD_ButterworthReader.cpp b/intern/audaspace/FX/AUD_ButterworthReader.cpp new file mode 100644 index 00000000000..1c2d7426a40 --- /dev/null +++ b/intern/audaspace/FX/AUD_ButterworthReader.cpp @@ -0,0 +1,124 @@ +/* + * $Id: AUD_ButterworthReader.cpp 25645 2010-01-01 11:40:48Z nexyon $ + * + * ***** 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_ButterworthReader.h" +#include "AUD_Buffer.h" + +#include +#include + +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif + +#define BWPB41 0.76536686473 +#define BWPB42 1.84775906502 +#define CC channels + channel + +AUD_ButterworthReader::AUD_ButterworthReader(AUD_IReader* reader, + float frequency) : + AUD_EffectReader(reader) +{ + AUD_Specs specs = reader->getSpecs(); + int samplesize = AUD_SAMPLE_SIZE(specs); + + m_buffer = new AUD_Buffer(); AUD_NEW("buffer") + + m_outvalues = new AUD_Buffer(samplesize * 5); AUD_NEW("buffer") + memset(m_outvalues->getBuffer(), 0, samplesize * 5); + + m_invalues = new AUD_Buffer(samplesize * 5); AUD_NEW("buffer") + memset(m_invalues->getBuffer(), 0, samplesize * 5); + + m_position = 0; + + // calculate coefficients + float omega = 2 * tan(frequency * M_PI / specs.rate); + float o2 = omega * omega; + float o4 = o2 * o2; + float x1 = o2 + 2 * BWPB41 * omega + 4; + float x2 = o2 + 2 * BWPB42 * omega + 4; + float y1 = o2 - 2 * BWPB41 * omega + 4; + float y2 = o2 - 2 * BWPB42 * omega + 4; + float o228 = 2 * o2 - 8; + float norm = x1 * x2; + m_coeff[0][0] = 0; + m_coeff[0][1] = (x1 + x2) * o228 / norm; + m_coeff[0][2] = (x1 * y2 + x2 * y1 + o228 * o228) / norm; + m_coeff[0][3] = (y1 + y2) * o228 / norm; + m_coeff[0][4] = y1 * y2 / norm; + m_coeff[1][4] = m_coeff[1][0] = o4 / norm; + m_coeff[1][3] = m_coeff[1][1] = 4 * o4 / norm; + m_coeff[1][2] = 6 * o4 / norm; +} + +AUD_ButterworthReader::~AUD_ButterworthReader() +{ + delete m_buffer; AUD_DELETE("buffer") + + delete m_outvalues; AUD_DELETE("buffer") + delete m_invalues; AUD_DELETE("buffer"); +} + +void AUD_ButterworthReader::read(int & length, sample_t* & buffer) +{ + sample_t* buf; + sample_t* outvalues; + sample_t* invalues; + + outvalues = m_outvalues->getBuffer(); + invalues = m_invalues->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(); + int channels = specs.channels; + + for(int channel = 0; channel < channels; channel++) + { + for(int i = 0; i < length; i++) + { + invalues[m_position * CC] = buf[i * CC]; + outvalues[m_position * CC] = 0; + + for(int j = 0; j < 4; j++) + { + outvalues[m_position * CC] += m_coeff[1][j] * + invalues[((m_position + j) % 5) * CC] - + m_coeff[0][j] * + outvalues[((m_position + j) % 5) * CC]; + } + + buffer[i * CC] = outvalues[m_position * CC]; + + m_position = (m_position + 4) % 5; + } + } +} diff --git a/intern/audaspace/FX/AUD_ButterworthReader.h b/intern/audaspace/FX/AUD_ButterworthReader.h new file mode 100644 index 00000000000..b93b1f355c5 --- /dev/null +++ b/intern/audaspace/FX/AUD_ButterworthReader.h @@ -0,0 +1,83 @@ +/* + * $Id: AUD_ButterworthReader.h 25643 2010-01-01 05:09:30Z nexyon $ + * + * ***** 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_BUTTERWORTHREADER +#define AUD_BUTTERWORTHREADER + +#include "AUD_EffectReader.h" +class AUD_Buffer; + +/** + * This class represents a butterworth filter. + */ +class AUD_ButterworthReader : public AUD_EffectReader +{ +private: + /** + * The playback buffer. + */ + AUD_Buffer *m_buffer; + + /** + * The last out values buffer. + */ + AUD_Buffer *m_outvalues; + + /** + * The last in values buffer. + */ + AUD_Buffer *m_invalues; + + /** + * The position for buffer cycling. + */ + int m_position; + + /** + * Filter coefficients. + */ + float m_coeff[2][5]; + +public: + /** + * Creates a new butterworth reader. + * \param reader The reader to read from. + * \param attack The attack value in seconds. + * \param release The release value in seconds. + * \param threshold The threshold value. + * \param arthreshold The attack/release threshold value. + * \exception AUD_Exception Thrown if the reader specified is NULL. + */ + AUD_ButterworthReader(AUD_IReader* reader, float frequency); + + /** + * Destroys the reader. + */ + virtual ~AUD_ButterworthReader(); + + virtual void read(int & length, sample_t* & buffer); +}; + +#endif //AUD_BUTTERWORTHREADER diff --git a/intern/audaspace/FX/AUD_EnvelopeFactory.cpp b/intern/audaspace/FX/AUD_EnvelopeFactory.cpp new file mode 100644 index 00000000000..ff9cb9ad757 --- /dev/null +++ b/intern/audaspace/FX/AUD_EnvelopeFactory.cpp @@ -0,0 +1,58 @@ +/* + * $Id: AUD_EnvelopeFactory.cpp 25643 2010-01-01 05:09:30Z nexyon $ + * + * ***** 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_EnvelopeFactory.h" +#include "AUD_EnvelopeReader.h" + +AUD_EnvelopeFactory::AUD_EnvelopeFactory(AUD_IFactory* factory, float attack, + float release, float threshold, + float arthreshold) : + AUD_EffectFactory(factory), + m_attack(attack), + m_release(release), + m_threshold(threshold), + m_arthreshold(arthreshold) {} + +AUD_EnvelopeFactory::AUD_EnvelopeFactory(float attack, float release, + float threshold, float arthreshold) : + AUD_EffectFactory(0), + m_attack(attack), + m_release(release), + m_threshold(threshold), + m_arthreshold(arthreshold) {} + +AUD_IReader* AUD_EnvelopeFactory::createReader() +{ + AUD_IReader* reader = getReader(); + + if(reader != 0) + { + reader = new AUD_EnvelopeReader(reader, m_attack, m_release, + m_threshold, m_arthreshold); + AUD_NEW("reader") + } + + return reader; +} diff --git a/intern/audaspace/FX/AUD_EnvelopeFactory.h b/intern/audaspace/FX/AUD_EnvelopeFactory.h new file mode 100644 index 00000000000..948c53b46e4 --- /dev/null +++ b/intern/audaspace/FX/AUD_EnvelopeFactory.h @@ -0,0 +1,82 @@ +/* + * $Id: AUD_EnvelopeFactory.h 25643 2010-01-01 05:09:30Z nexyon $ + * + * ***** 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_ENVELOPEFACTORY +#define AUD_ENVELOPEFACTORY + +#include "AUD_EffectFactory.h" + +/** + * This factory creates an envelope follower reader. + */ +class AUD_EnvelopeFactory : public AUD_EffectFactory +{ +private: + /** + * The attack value in seconds. + */ + float m_attack; + + /** + * The release value in seconds. + */ + float m_release; + + /** + * The threshold value. + */ + float m_threshold; + + /** + * The attack/release threshold value. + */ + float m_arthreshold; + +public: + /** + * Creates a new envelope factory. + * \param factory The input factory. + * \param attack The attack value in seconds. + * \param release The release value in seconds. + * \param threshold The threshold value. + * \param arthreshold The attack/release threshold value. + */ + AUD_EnvelopeFactory(AUD_IFactory* factory, float attack, float release, + float threshold, float arthreshold); + + /** + * Creates a new envelope factory. + * \param attack The attack value in seconds. + * \param release The release value in seconds. + * \param threshold The threshold value. + * \param arthreshold The attack/release threshold value. + */ + AUD_EnvelopeFactory(float attack, float release, float threshold, + float arthreshold); + + virtual AUD_IReader* createReader(); +}; + +#endif //AUD_ENVELOPEFACTORY diff --git a/intern/audaspace/FX/AUD_EnvelopeReader.cpp b/intern/audaspace/FX/AUD_EnvelopeReader.cpp new file mode 100644 index 00000000000..ea8136cda22 --- /dev/null +++ b/intern/audaspace/FX/AUD_EnvelopeReader.cpp @@ -0,0 +1,86 @@ +/* + * $Id: AUD_EnvelopeReader.cpp 25646 2010-01-01 11:55:56Z nexyon $ + * + * ***** 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_EnvelopeReader.h" +#include "AUD_Buffer.h" + +#include +#include + +AUD_EnvelopeReader::AUD_EnvelopeReader(AUD_IReader* reader, float attack, + float release, float threshold, + float arthreshold) : + AUD_EffectReader(reader), + m_threshold(threshold) +{ + AUD_Specs specs = reader->getSpecs(); + int samplesize = AUD_SAMPLE_SIZE(specs); + + m_buffer = new AUD_Buffer(); AUD_NEW("buffer") + + m_envelopes = new AUD_Buffer(samplesize); + AUD_NEW("buffer") + memset(m_envelopes->getBuffer(), 0, samplesize); + + m_bAttack = pow(arthreshold, 1.0f/(specs.rate * attack)); + m_bRelease = pow(arthreshold, 1.0f/(specs.rate * release)); +} + +AUD_EnvelopeReader::~AUD_EnvelopeReader() +{ + delete m_buffer; AUD_DELETE("buffer") + delete m_envelopes; AUD_DELETE("buffer") +} + +void AUD_EnvelopeReader::read(int & length, sample_t* & buffer) +{ + sample_t* buf; + sample_t* envelopes; + envelopes = m_envelopes->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(); + + sample_t value; + + for(int channel = 0; channel < specs.channels; channel++) + { + for(int i = 0; i < length; i++) + { + value = fabs(buf[i * specs.channels + channel]); + if(value < m_threshold) + value = 0.0f; + + buffer[i * specs.channels + channel] = envelopes[channel] = + ((value > envelopes[channel]) ? m_bAttack : m_bRelease) * + (envelopes[channel] - value) + value; + } + } +} diff --git a/intern/audaspace/FX/AUD_EnvelopeReader.h b/intern/audaspace/FX/AUD_EnvelopeReader.h new file mode 100644 index 00000000000..5bdc16734a9 --- /dev/null +++ b/intern/audaspace/FX/AUD_EnvelopeReader.h @@ -0,0 +1,84 @@ +/* + * $Id: AUD_EnvelopeReader.h 25643 2010-01-01 05:09:30Z nexyon $ + * + * ***** 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_ENVELOPEREADER +#define AUD_ENVELOPEREADER + +#include "AUD_EffectReader.h" +class AUD_Buffer; + +/** + * This class represents an envelope follower. + */ +class AUD_EnvelopeReader : public AUD_EffectReader +{ +private: + /** + * The playback buffer. + */ + AUD_Buffer *m_buffer; + + /** + * The last envelopes buffer. + */ + AUD_Buffer *m_envelopes; + + /** + * Attack b value. + */ + float m_bAttack; + + /** + * Release b value. + */ + float m_bRelease; + + /** + * Threshold value. + */ + float m_threshold; + +public: + /** + * Creates a new envelope reader. + * \param reader The reader to read from. + * \param attack The attack value in seconds. + * \param release The release value in seconds. + * \param threshold The threshold value. + * \param arthreshold The attack/release threshold value. + * \exception AUD_Exception Thrown if the reader specified is NULL. + */ + AUD_EnvelopeReader(AUD_IReader* reader, float attack, float release, + float threshold, float arthreshold); + + /** + * Destroys the reader. + */ + virtual ~AUD_EnvelopeReader(); + + virtual void read(int & length, sample_t* & buffer); +}; + +#endif //AUD_ENVELOPEREADER diff --git a/intern/audaspace/FX/AUD_HighpassFactory.cpp b/intern/audaspace/FX/AUD_HighpassFactory.cpp new file mode 100644 index 00000000000..7b5eb96d28f --- /dev/null +++ b/intern/audaspace/FX/AUD_HighpassFactory.cpp @@ -0,0 +1,51 @@ +/* + * $Id: AUD_HighpassFactory.cpp 25643 2010-01-01 05:09:30Z nexyon $ + * + * ***** 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_HighpassFactory.h" +#include "AUD_HighpassReader.h" + +AUD_HighpassFactory::AUD_HighpassFactory(AUD_IFactory* factory, float frequency, + float Q) : + AUD_EffectFactory(factory), + m_frequency(frequency), + m_Q(Q) {} + +AUD_HighpassFactory::AUD_HighpassFactory(float frequency, float Q) : + AUD_EffectFactory(0), + m_frequency(frequency), + m_Q(Q) {} + +AUD_IReader* AUD_HighpassFactory::createReader() +{ + AUD_IReader* reader = getReader(); + + if(reader != 0) + { + reader = new AUD_HighpassReader(reader, m_frequency, m_Q); + AUD_NEW("reader") + } + + return reader; +} diff --git a/intern/audaspace/FX/AUD_HighpassFactory.h b/intern/audaspace/FX/AUD_HighpassFactory.h new file mode 100644 index 00000000000..59cf921b0fe --- /dev/null +++ b/intern/audaspace/FX/AUD_HighpassFactory.h @@ -0,0 +1,66 @@ +/* + * $Id: AUD_HighpassFactory.h 25646 2010-01-01 11:55:56Z nexyon $ + * + * ***** 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_HIGHPASSFACTORY +#define AUD_HIGHPASSFACTORY + +#include "AUD_EffectFactory.h" + +/** + * This factory creates a highpass filter reader. + */ +class AUD_HighpassFactory : public AUD_EffectFactory +{ +private: + /** + * The attack value in seconds. + */ + float m_frequency; + + /** + * The Q factor. + */ + float m_Q; + +public: + /** + * Creates a new highpass factory. + * \param factory The input factory. + * \param frequency The cutoff frequency. + * \param Q The Q factor. + */ + AUD_HighpassFactory(AUD_IFactory* factory, float frequency, float Q = 1.0f); + + /** + * Creates a new highpass factory. + * \param frequency The cutoff frequency. + * \param Q The Q factor. + */ + AUD_HighpassFactory(float frequency, float Q = 1.0f); + + virtual AUD_IReader* createReader(); +}; + +#endif //AUD_HIGHPASSFACTORY diff --git a/intern/audaspace/FX/AUD_HighpassReader.cpp b/intern/audaspace/FX/AUD_HighpassReader.cpp new file mode 100644 index 00000000000..24bda0f1aa1 --- /dev/null +++ b/intern/audaspace/FX/AUD_HighpassReader.cpp @@ -0,0 +1,116 @@ +/* + * $Id: AUD_HighpassReader.cpp 25646 2010-01-01 11:55:56Z nexyon $ + * + * ***** 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_HighpassReader.h" +#include "AUD_Buffer.h" + +#include +#include + +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif + +#define CC channels + channel + +AUD_HighpassReader::AUD_HighpassReader(AUD_IReader* reader, float frequency, + float Q) : + AUD_EffectReader(reader) +{ + AUD_Specs specs = reader->getSpecs(); + int samplesize = AUD_SAMPLE_SIZE(specs); + + m_buffer = new AUD_Buffer(); AUD_NEW("buffer") + + m_outvalues = new AUD_Buffer(samplesize * AUD_HIGHPASS_ORDER); + AUD_NEW("buffer") + memset(m_outvalues->getBuffer(), 0, samplesize * AUD_HIGHPASS_ORDER); + + m_invalues = new AUD_Buffer(samplesize * AUD_HIGHPASS_ORDER); + AUD_NEW("buffer") + memset(m_invalues->getBuffer(), 0, samplesize * AUD_HIGHPASS_ORDER); + + m_position = 0; + + // calculate coefficients + float w0 = 2 * M_PI * frequency / specs.rate; + float alpha = sin(w0) / (2 * Q); + float norm = 1 + alpha; + m_coeff[0][0] = 0; + m_coeff[0][1] = -2 * cos(w0) / norm; + m_coeff[0][2] = (1 - alpha) / norm; + m_coeff[1][2] = m_coeff[1][0] = (1 + cos(w0)) / (2 * norm); + m_coeff[1][1] = (-1 - cos(w0)) / norm; +} + +AUD_HighpassReader::~AUD_HighpassReader() +{ + delete m_buffer; AUD_DELETE("buffer") + + delete m_outvalues; AUD_DELETE("buffer") + delete m_invalues; AUD_DELETE("buffer"); +} + +void AUD_HighpassReader::read(int & length, sample_t* & buffer) +{ + sample_t* buf; + sample_t* outvalues; + sample_t* invalues; + + outvalues = m_outvalues->getBuffer(); + invalues = m_invalues->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(); + int channels = specs.channels; + + for(int channel = 0; channel < channels; channel++) + { + for(int i = 0; i < length; i++) + { + invalues[m_position * CC] = buf[i * CC]; + outvalues[m_position * CC] = 0; + + for(int j = 0; j < AUD_HIGHPASS_ORDER; j++) + { + outvalues[m_position * CC] += m_coeff[1][j] * + invalues[((m_position + j) % AUD_HIGHPASS_ORDER) * CC] - + m_coeff[0][j] * + outvalues[((m_position + j) % AUD_HIGHPASS_ORDER) * CC]; + } + + buffer[i * CC] = outvalues[m_position * CC]; + + m_position = (m_position + AUD_HIGHPASS_ORDER-1) % + AUD_HIGHPASS_ORDER; + } + } +} diff --git a/intern/audaspace/FX/AUD_HighpassReader.h b/intern/audaspace/FX/AUD_HighpassReader.h new file mode 100644 index 00000000000..7080de9f8c7 --- /dev/null +++ b/intern/audaspace/FX/AUD_HighpassReader.h @@ -0,0 +1,83 @@ +/* + * $Id: AUD_HighpassReader.h 25643 2010-01-01 05:09:30Z nexyon $ + * + * ***** 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_HIGHPASSREADER +#define AUD_HIGHPASSREADER + +#include "AUD_EffectReader.h" +class AUD_Buffer; + +#define AUD_HIGHPASS_ORDER 3 + +/** + * This class represents a highpass filter. + */ +class AUD_HighpassReader : public AUD_EffectReader +{ +private: + /** + * The playback buffer. + */ + AUD_Buffer *m_buffer; + + /** + * The last out values buffer. + */ + AUD_Buffer *m_outvalues; + + /** + * The last in values buffer. + */ + AUD_Buffer *m_invalues; + + /** + * The position for buffer cycling. + */ + int m_position; + + /** + * Filter coefficients. + */ + float m_coeff[2][AUD_HIGHPASS_ORDER]; + +public: + /** + * Creates a new highpass reader. + * \param reader The reader to read from. + * \param frequency The cutoff frequency. + * \param Q The Q factor. + * \exception AUD_Exception Thrown if the reader specified is NULL. + */ + AUD_HighpassReader(AUD_IReader* reader, float frequency, float Q); + + /** + * Destroys the reader. + */ + virtual ~AUD_HighpassReader(); + + virtual void read(int & length, sample_t* & buffer); +}; + +#endif //AUD_HIGHPASSREADER diff --git a/intern/audaspace/FX/AUD_LowpassFactory.cpp b/intern/audaspace/FX/AUD_LowpassFactory.cpp new file mode 100644 index 00000000000..b8cfd493814 --- /dev/null +++ b/intern/audaspace/FX/AUD_LowpassFactory.cpp @@ -0,0 +1,51 @@ +/* + * $Id: AUD_LowpassFactory.cpp 25643 2010-01-01 05:09:30Z nexyon $ + * + * ***** 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_LowpassFactory.h" +#include "AUD_LowpassReader.h" + +AUD_LowpassFactory::AUD_LowpassFactory(AUD_IFactory* factory, float frequency, + float Q) : + AUD_EffectFactory(factory), + m_frequency(frequency), + m_Q(Q) {} + +AUD_LowpassFactory::AUD_LowpassFactory(float frequency, float Q) : + AUD_EffectFactory(0), + m_frequency(frequency), + m_Q(Q) {} + +AUD_IReader* AUD_LowpassFactory::createReader() +{ + AUD_IReader* reader = getReader(); + + if(reader != 0) + { + reader = new AUD_LowpassReader(reader, m_frequency, m_Q); + AUD_NEW("reader") + } + + return reader; +} diff --git a/intern/audaspace/FX/AUD_LowpassFactory.h b/intern/audaspace/FX/AUD_LowpassFactory.h new file mode 100644 index 00000000000..5dce13837dc --- /dev/null +++ b/intern/audaspace/FX/AUD_LowpassFactory.h @@ -0,0 +1,66 @@ +/* + * $Id: AUD_LowpassFactory.h 25646 2010-01-01 11:55:56Z nexyon $ + * + * ***** 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_LOWPASSFACTORY +#define AUD_LOWPASSFACTORY + +#include "AUD_EffectFactory.h" + +/** + * This factory creates a lowpass filter reader. + */ +class AUD_LowpassFactory : public AUD_EffectFactory +{ +private: + /** + * The attack value in seconds. + */ + float m_frequency; + + /** + * The Q factor. + */ + float m_Q; + +public: + /** + * Creates a new lowpass factory. + * \param factory The input factory. + * \param frequency The cutoff frequency. + * \param Q The Q factor. + */ + AUD_LowpassFactory(AUD_IFactory* factory, float frequency, float Q = 1.0f); + + /** + * Creates a new lowpass factory. + * \param frequency The cutoff frequency. + * \param Q The Q factor. + */ + AUD_LowpassFactory(float frequency, float Q = 1.0f); + + virtual AUD_IReader* createReader(); +}; + +#endif //AUD_LOWPASSFACTORY diff --git a/intern/audaspace/FX/AUD_LowpassReader.cpp b/intern/audaspace/FX/AUD_LowpassReader.cpp new file mode 100644 index 00000000000..135db4372af --- /dev/null +++ b/intern/audaspace/FX/AUD_LowpassReader.cpp @@ -0,0 +1,115 @@ +/* + * $Id: AUD_LowpassReader.cpp 25646 2010-01-01 11:55:56Z nexyon $ + * + * ***** 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_LowpassReader.h" +#include "AUD_Buffer.h" + +#include +#include + +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif + +#define CC channels + channel + +AUD_LowpassReader::AUD_LowpassReader(AUD_IReader* reader, float frequency, + float Q) : + AUD_EffectReader(reader) +{ + AUD_Specs specs = reader->getSpecs(); + int samplesize = AUD_SAMPLE_SIZE(specs); + + m_buffer = new AUD_Buffer(); AUD_NEW("buffer") + + m_outvalues = new AUD_Buffer(samplesize * AUD_LOWPASS_ORDER); + AUD_NEW("buffer") + memset(m_outvalues->getBuffer(), 0, samplesize * AUD_LOWPASS_ORDER); + + m_invalues = new AUD_Buffer(samplesize * AUD_LOWPASS_ORDER); + AUD_NEW("buffer") + memset(m_invalues->getBuffer(), 0, samplesize * AUD_LOWPASS_ORDER); + + m_position = 0; + + // calculate coefficients + float w0 = 2 * M_PI * frequency / specs.rate; + float alpha = sin(w0) / (2 * Q); + float norm = 1 + alpha; + m_coeff[0][0] = 0; + m_coeff[0][1] = -2 * cos(w0) / norm; + m_coeff[0][2] = (1 - alpha) / norm; + m_coeff[1][2] = m_coeff[1][0] = (1 - cos(w0)) / (2 * norm); + m_coeff[1][1] = (1 - cos(w0)) / norm; +} + +AUD_LowpassReader::~AUD_LowpassReader() +{ + delete m_buffer; AUD_DELETE("buffer") + + delete m_outvalues; AUD_DELETE("buffer") + delete m_invalues; AUD_DELETE("buffer"); +} + +void AUD_LowpassReader::read(int & length, sample_t* & buffer) +{ + sample_t* buf; + sample_t* outvalues; + sample_t* invalues; + + outvalues = m_outvalues->getBuffer(); + invalues = m_invalues->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(); + int channels = specs.channels; + + for(int channel = 0; channel < channels; channel++) + { + for(int i = 0; i < length; i++) + { + invalues[m_position * CC] = buf[i * CC]; + outvalues[m_position * CC] = 0; + + for(int j = 0; j < AUD_LOWPASS_ORDER; j++) + { + outvalues[m_position * CC] += m_coeff[1][j] * + invalues[((m_position + j) % AUD_LOWPASS_ORDER) * CC] - + m_coeff[0][j] * + outvalues[((m_position + j) % AUD_LOWPASS_ORDER) * CC]; + } + + buffer[i * CC] = outvalues[m_position * CC]; + + m_position = (m_position + AUD_LOWPASS_ORDER-1) % AUD_LOWPASS_ORDER; + } + } +} diff --git a/intern/audaspace/FX/AUD_LowpassReader.h b/intern/audaspace/FX/AUD_LowpassReader.h new file mode 100644 index 00000000000..a76e1de5e76 --- /dev/null +++ b/intern/audaspace/FX/AUD_LowpassReader.h @@ -0,0 +1,83 @@ +/* + * $Id: AUD_LowpassReader.h 25643 2010-01-01 05:09:30Z nexyon $ + * + * ***** 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_LOWPASSREADER +#define AUD_LOWPASSREADER + +#include "AUD_EffectReader.h" +class AUD_Buffer; + +#define AUD_LOWPASS_ORDER 3 + +/** + * This class represents a lowpass filter. + */ +class AUD_LowpassReader : public AUD_EffectReader +{ +private: + /** + * The playback buffer. + */ + AUD_Buffer *m_buffer; + + /** + * The last out values buffer. + */ + AUD_Buffer *m_outvalues; + + /** + * The last in values buffer. + */ + AUD_Buffer *m_invalues; + + /** + * The position for buffer cycling. + */ + int m_position; + + /** + * Filter coefficients. + */ + float m_coeff[2][AUD_LOWPASS_ORDER]; + +public: + /** + * Creates a new lowpass reader. + * \param reader The reader to read from. + * \param frequency The cutoff frequency. + * \param Q The Q factor. + * \exception AUD_Exception Thrown if the reader specified is NULL. + */ + AUD_LowpassReader(AUD_IReader* reader, float frequency, float Q); + + /** + * Destroys the reader. + */ + virtual ~AUD_LowpassReader(); + + virtual void read(int & length, sample_t* & buffer); +}; + +#endif //AUD_LOWPASSREADER diff --git a/intern/audaspace/FX/AUD_SquareFactory.cpp b/intern/audaspace/FX/AUD_SquareFactory.cpp new file mode 100644 index 00000000000..d16bc84780b --- /dev/null +++ b/intern/audaspace/FX/AUD_SquareFactory.cpp @@ -0,0 +1,57 @@ +/* + * $Id: AUD_SquareFactory.cpp 25656 2010-01-01 18:45:21Z nexyon $ + * + * ***** 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..2c0562ade8e --- /dev/null +++ b/intern/audaspace/FX/AUD_SquareFactory.h @@ -0,0 +1,70 @@ +/* + * $Id: AUD_SquareFactory.h 25656 2010-01-01 18:45:21Z nexyon $ + * + * ***** 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..c6bfc749f14 --- /dev/null +++ b/intern/audaspace/FX/AUD_SquareReader.cpp @@ -0,0 +1,63 @@ +/* + * $Id: AUD_SquareReader.cpp 25656 2010-01-01 18:45:21Z nexyon $ + * + * ***** 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..d3d99317a09 --- /dev/null +++ b/intern/audaspace/FX/AUD_SquareReader.h @@ -0,0 +1,65 @@ +/* + * $Id: AUD_SquareReader.h 25656 2010-01-01 18:45:21Z nexyon $ + * + * ***** 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..e00a2e78b7b --- /dev/null +++ b/intern/audaspace/FX/AUD_SumFactory.cpp @@ -0,0 +1,43 @@ +/* + * $Id: AUD_SumFactory.cpp 25656 2010-01-01 18:45:21Z nexyon $ + * + * ***** 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..d5bb2fa8270 --- /dev/null +++ b/intern/audaspace/FX/AUD_SumFactory.h @@ -0,0 +1,46 @@ +/* + * $Id: AUD_SumFactory.h 25656 2010-01-01 18:45:21Z nexyon $ + * + * ***** 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..5147661bf24 --- /dev/null +++ b/intern/audaspace/FX/AUD_SumReader.cpp @@ -0,0 +1,68 @@ +/* + * $Id: AUD_SumReader.cpp 25656 2010-01-01 18:45:21Z nexyon $ + * + * ***** 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..fb59a39faa8 --- /dev/null +++ b/intern/audaspace/FX/AUD_SumReader.h @@ -0,0 +1,64 @@ +/* + * $Id: AUD_SumReader.h 25656 2010-01-01 18:45:21Z nexyon $ + * + * ***** 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