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