2
* $Id: AUD_EnvelopeFactory.cpp 25643 2010-01-01 05:09:30Z nexyon $
4
* ***** BEGIN LGPL LICENSE BLOCK *****
6
* Copyright 2009 Jörg Hermann Müller
2
* ***** BEGIN GPL LICENSE BLOCK *****
4
* Copyright 2009-2011 Jörg Hermann Müller
8
6
* This file is part of AudaSpace.
10
* AudaSpace is free software: you can redistribute it and/or modify
11
* it under the terms of the GNU Lesser General Public License as published by
12
* the Free Software Foundation, either version 3 of the License, or
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
13
11
* (at your option) any later version.
15
13
* AudaSpace is distributed in the hope that it will be useful,
16
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU Lesser General Public License for more details.
20
* You should have received a copy of the GNU Lesser General Public License
21
* along with AudaSpace. If not, see <http://www.gnu.org/licenses/>.
23
* ***** END LGPL LICENSE BLOCK *****
16
* GNU General Public License for more details.
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.
22
* ***** END GPL LICENSE BLOCK *****
25
/** \file audaspace/FX/AUD_EnvelopeFactory.cpp
26
30
#include "AUD_EnvelopeFactory.h"
27
#include "AUD_EnvelopeReader.h"
29
AUD_EnvelopeFactory::AUD_EnvelopeFactory(AUD_IFactory* factory, float attack,
31
#include "AUD_CallbackIIRFilterReader.h"
35
struct EnvelopeParameters
43
sample_t AUD_EnvelopeFactory::envelopeFilter(AUD_CallbackIIRFilterReader* reader, EnvelopeParameters* param)
45
float in = fabs(reader->x(0));
46
float out = reader->y(-1);
47
if(in < param->threshold)
49
return (in > out ? param->attack : param->release) * (out - in) + in;
52
void AUD_EnvelopeFactory::endEnvelopeFilter(EnvelopeParameters* param)
57
AUD_EnvelopeFactory::AUD_EnvelopeFactory(AUD_Reference<AUD_IFactory> factory, float attack,
30
58
float release, float threshold,
31
59
float arthreshold) :
32
60
AUD_EffectFactory(factory),
34
62
m_release(release),
35
63
m_threshold(threshold),
36
m_arthreshold(arthreshold) {}
38
AUD_EnvelopeFactory::AUD_EnvelopeFactory(float attack, float release,
39
float threshold, float arthreshold) :
43
m_threshold(threshold),
44
m_arthreshold(arthreshold) {}
46
AUD_IReader* AUD_EnvelopeFactory::createReader()
48
AUD_IReader* reader = getReader();
52
reader = new AUD_EnvelopeReader(reader, m_attack, m_release,
53
m_threshold, m_arthreshold);
64
m_arthreshold(arthreshold)
68
AUD_Reference<AUD_IReader> AUD_EnvelopeFactory::createReader()
70
AUD_Reference<AUD_IReader> reader = getReader();
72
EnvelopeParameters* param = new EnvelopeParameters();
73
param->arthreshold = m_arthreshold;
74
param->attack = pow(m_arthreshold, 1.0f/(static_cast<float>(reader->getSpecs().rate) * m_attack));
75
param->release = pow(m_arthreshold, 1.0f/(static_cast<float>(reader->getSpecs().rate) * m_release));
76
param->threshold = m_threshold;
78
return new AUD_CallbackIIRFilterReader(reader, 1, 2,
79
(doFilterIIR) envelopeFilter,
80
(endFilterIIR) endEnvelopeFilter,