7aabdb775f6ccf2090187846e3d47a04de16d3d5
[blender.git] / intern / audaspace / FX / AUD_SquareFactory.cpp
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * Copyright 2009-2011 Jörg Hermann Müller
5  *
6  * This file is part of AudaSpace.
7  *
8  * Audaspace is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * AudaSpace is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with Audaspace; if not, write to the Free Software Foundation,
20  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  *
22  * ***** END GPL LICENSE BLOCK *****
23  */
24
25 /** \file audaspace/FX/AUD_SquareFactory.cpp
26  *  \ingroup audfx
27  */
28
29
30 #include "AUD_SquareFactory.h"
31 #include "AUD_CallbackIIRFilterReader.h"
32
33 sample_t AUD_SquareFactory::squareFilter(AUD_CallbackIIRFilterReader* reader, float* threshold)
34 {
35         float in = reader->x(0);
36         if(in >= *threshold)
37                 return 1;
38         else if(in <= -*threshold)
39                 return -1;
40         else
41                 return 0;
42 }
43
44 void AUD_SquareFactory::endSquareFilter(float* threshold)
45 {
46         delete threshold;
47 }
48
49 AUD_SquareFactory::AUD_SquareFactory(AUD_Reference<AUD_IFactory> factory, float threshold) :
50                 AUD_EffectFactory(factory),
51                 m_threshold(threshold)
52 {
53 }
54
55 float AUD_SquareFactory::getThreshold() const
56 {
57         return m_threshold;
58 }
59
60 AUD_Reference<AUD_IReader> AUD_SquareFactory::createReader()
61 {
62         return new AUD_CallbackIIRFilterReader(getReader(), 1, 1,
63                                                                                    (doFilterIIR) squareFilter,
64                                                                                    (endFilterIIR) endSquareFilter,
65                                                                                    new float(m_threshold));
66 }