Blender  V2.59
AUD_HighpassFactory.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: AUD_HighpassFactory.cpp 35141 2011-02-25 10:21:56Z jesterking $
00003  *
00004  * ***** BEGIN GPL LICENSE BLOCK *****
00005  *
00006  * Copyright 2009-2011 Jörg Hermann Müller
00007  *
00008  * This file is part of AudaSpace.
00009  *
00010  * Audaspace is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * AudaSpace is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with Audaspace; if not, write to the Free Software Foundation,
00022  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00023  *
00024  * ***** END GPL LICENSE BLOCK *****
00025  */
00026 
00032 #include "AUD_HighpassFactory.h"
00033 #include "AUD_IIRFilterReader.h"
00034 
00035 #include <cmath>
00036 
00037 #ifndef M_PI
00038 #define M_PI 3.14159265358979323846
00039 #endif
00040 
00041 AUD_HighpassFactory::AUD_HighpassFactory(AUD_IFactory* factory, float frequency,
00042                                                                                  float Q) :
00043                 AUD_EffectFactory(factory),
00044                 m_frequency(frequency),
00045                 m_Q(Q)
00046 {
00047 }
00048 
00049 AUD_IReader* AUD_HighpassFactory::createReader() const
00050 {
00051         AUD_IReader* reader = getReader();
00052 
00053         // calculate coefficients
00054         float w0 = 2 * M_PI * m_frequency / reader->getSpecs().rate;
00055         float alpha = sin(w0) / (2 * m_Q);
00056         float norm = 1 + alpha;
00057         float c = cos(w0);
00058         std::vector<float> a, b;
00059         a.push_back(1);
00060         a.push_back(-2 * c / norm);
00061         a.push_back((1 - alpha) / norm);
00062         b.push_back((1 + c) / (2 * norm));
00063         b.push_back((-1 - c) / norm);
00064         b.push_back(b[0]);
00065 
00066         return new AUD_IIRFilterReader(reader, b, a);
00067 }