diff options
author | Joerg Mueller <nexyon@gmail.com> | 2009-12-24 17:58:11 +0300 |
---|---|---|
committer | Joerg Mueller <nexyon@gmail.com> | 2009-12-24 17:58:11 +0300 |
commit | 1d224ad692c8794500f4d6fd5257887db150a635 (patch) | |
tree | a375be4aacfec86a4c60d1231a97f7efc2ecc373 /intern/audaspace/FX | |
parent | a2b0020e11e27c6d7ecdacf747a4543ab733867b (diff) |
Added rectifying sound effect (will be used for sound -> f-curve later).
Diffstat (limited to 'intern/audaspace/FX')
-rw-r--r-- | intern/audaspace/FX/AUD_RectifyFactory.cpp | 45 | ||||
-rw-r--r-- | intern/audaspace/FX/AUD_RectifyFactory.h | 51 | ||||
-rw-r--r-- | intern/audaspace/FX/AUD_RectifyReader.cpp | 82 | ||||
-rw-r--r-- | intern/audaspace/FX/AUD_RectifyReader.h | 65 |
4 files changed, 243 insertions, 0 deletions
diff --git a/intern/audaspace/FX/AUD_RectifyFactory.cpp b/intern/audaspace/FX/AUD_RectifyFactory.cpp new file mode 100644 index 00000000000..21786aea133 --- /dev/null +++ b/intern/audaspace/FX/AUD_RectifyFactory.cpp @@ -0,0 +1,45 @@ +/* + * $Id: AUD_VolumeFactory.cpp 22328 2009-08-09 23:23:19Z gsrb3d $ + * + * ***** BEGIN LGPL LICENSE BLOCK ***** + * + * Copyright 2009 Jörg Hermann Müller + * + * This file is part of AudaSpace. + * + * AudaSpace is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * AudaSpace is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with AudaSpace. If not, see <http://www.gnu.org/licenses/>. + * + * ***** END LGPL LICENSE BLOCK ***** + */ + +#include "AUD_RectifyFactory.h" +#include "AUD_RectifyReader.h" + +AUD_RectifyFactory::AUD_RectifyFactory(AUD_IFactory* factory) : + AUD_EffectFactory(factory) {} + +AUD_RectifyFactory::AUD_RectifyFactory() : + AUD_EffectFactory(0) {} + +AUD_IReader* AUD_RectifyFactory::createReader() +{ + AUD_IReader* reader = getReader(); + + if(reader != 0) + { + reader = new AUD_RectifyReader(reader); AUD_NEW("reader") + } + + return reader; +} diff --git a/intern/audaspace/FX/AUD_RectifyFactory.h b/intern/audaspace/FX/AUD_RectifyFactory.h new file mode 100644 index 00000000000..bc84f111832 --- /dev/null +++ b/intern/audaspace/FX/AUD_RectifyFactory.h @@ -0,0 +1,51 @@ +/* + * $Id: AUD_VolumeFactory.h 22328 2009-08-09 23:23:19Z gsrb3d $ + * + * ***** BEGIN LGPL LICENSE BLOCK ***** + * + * Copyright 2009 Jörg Hermann Müller + * + * This file is part of AudaSpace. + * + * AudaSpace is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * AudaSpace is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with AudaSpace. If not, see <http://www.gnu.org/licenses/>. + * + * ***** END LGPL LICENSE BLOCK ***** + */ + +#ifndef AUD_RECTIFYFACTORY +#define AUD_RECTIFYFACTORY + +#include "AUD_EffectFactory.h" + +/** + * This factory rectifies another factory. + */ +class AUD_RectifyFactory : public AUD_EffectFactory +{ +public: + /** + * Creates a new rectify factory. + * \param factory The input factory. + */ + AUD_RectifyFactory(AUD_IFactory* factory = 0); + + /** + * Creates a new rectify factory. + */ + AUD_RectifyFactory(); + + virtual AUD_IReader* createReader(); +}; + +#endif //AUD_RECTIFYFACTORY diff --git a/intern/audaspace/FX/AUD_RectifyReader.cpp b/intern/audaspace/FX/AUD_RectifyReader.cpp new file mode 100644 index 00000000000..aeb5ee74cbd --- /dev/null +++ b/intern/audaspace/FX/AUD_RectifyReader.cpp @@ -0,0 +1,82 @@ +/* + * $Id: AUD_VolumeReader.cpp 22328 2009-08-09 23:23:19Z gsrb3d $ + * + * ***** BEGIN LGPL LICENSE BLOCK ***** + * + * Copyright 2009 Jörg Hermann Müller + * + * This file is part of AudaSpace. + * + * AudaSpace is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * AudaSpace is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with AudaSpace. If not, see <http://www.gnu.org/licenses/>. + * + * ***** END LGPL LICENSE BLOCK ***** + */ + +#include "AUD_RectifyReader.h" +#include "AUD_Buffer.h" + +#include <cstring> + +AUD_RectifyReader::AUD_RectifyReader(AUD_IReader* reader) : + AUD_EffectReader(reader) +{ + int bigendian = 1; + bigendian = (((char*)&bigendian)[0]) ? 0: 1; // 1 if Big Endian + + switch(m_reader->getSpecs().format) + { + case AUD_FORMAT_S16: + m_rectify = AUD_rectify<int16_t>; + break; + case AUD_FORMAT_S32: + m_rectify = AUD_rectify<int32_t>; + break; + case AUD_FORMAT_FLOAT32: + m_rectify = AUD_rectify<float>; + break; + case AUD_FORMAT_FLOAT64: + m_rectify = AUD_rectify<double>; + break; + case AUD_FORMAT_U8: + m_rectify = AUD_rectify_u8; + break; + case AUD_FORMAT_S24: + m_rectify = bigendian ? AUD_rectify_s24_be : AUD_rectify_s24_le; + break; + default: + delete m_reader; + AUD_THROW(AUD_ERROR_READER); + } + + m_buffer = new AUD_Buffer(); AUD_NEW("buffer") +} + +AUD_RectifyReader::~AUD_RectifyReader() +{ + delete m_buffer; AUD_DELETE("buffer") +} + +void AUD_RectifyReader::read(int & length, sample_t* & buffer) +{ + sample_t* buf; + AUD_Specs specs = m_reader->getSpecs(); + + m_reader->read(length, buf); + if(m_buffer->getSize() < length*AUD_SAMPLE_SIZE(specs)) + m_buffer->resize(length*AUD_SAMPLE_SIZE(specs)); + + buffer = m_buffer->getBuffer(); + + m_rectify(buffer, buf, length * specs.channels); +} diff --git a/intern/audaspace/FX/AUD_RectifyReader.h b/intern/audaspace/FX/AUD_RectifyReader.h new file mode 100644 index 00000000000..35817db636b --- /dev/null +++ b/intern/audaspace/FX/AUD_RectifyReader.h @@ -0,0 +1,65 @@ +/* + * $Id: AUD_VolumeReader.h 22328 2009-08-09 23:23:19Z gsrb3d $ + * + * ***** BEGIN LGPL LICENSE BLOCK ***** + * + * Copyright 2009 Jörg Hermann Müller + * + * This file is part of AudaSpace. + * + * AudaSpace is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * AudaSpace is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with AudaSpace. If not, see <http://www.gnu.org/licenses/>. + * + * ***** END LGPL LICENSE BLOCK ***** + */ + +#ifndef AUD_RECTIFYREADER +#define AUD_RECTIFYREADER + +#include "AUD_EffectReader.h" +#include "AUD_ConverterFunctions.h" +class AUD_Buffer; + +/** + * This class reads another reader and rectifies it. + */ +class AUD_RectifyReader : public AUD_EffectReader +{ +private: + /** + * The playback buffer. + */ + AUD_Buffer *m_buffer; + + /** + * Rectifying function. + */ + AUD_rectify_f m_rectify; + +public: + /** + * Creates a new rectify reader. + * \param reader The reader to read from. + * \exception AUD_Exception Thrown if the reader specified is NULL. + */ + AUD_RectifyReader(AUD_IReader* reader); + + /** + * Destroys the reader. + */ + virtual ~AUD_RectifyReader(); + + virtual void read(int & length, sample_t* & buffer); +}; + +#endif //AUD_RECTIFYREADER |