~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to intern/audaspace/FX/AUD_EnvelopeFactory.cpp

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2012-07-23 08:54:18 UTC
  • mfrom: (14.2.16 sid)
  • mto: (14.2.19 sid)
  • mto: This revision was merged to the branch mainline in revision 42.
  • Revision ID: package-import@ubuntu.com-20120723085418-9foz30v6afaf5ffs
Tags: 2.63a-2
* debian/: Cycles support added (Closes: #658075)
  For now, this top feature has been enabled only
  on [any-amd64 any-i386] architectures because
  of OpenImageIO failing on all others
* debian/: scripts installation path changed
  from /usr/lib to /usr/share:
  + debian/patches/: patchset re-worked for path changing
  + debian/control: "Breaks" field added on yafaray-exporter

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * $Id: AUD_EnvelopeFactory.cpp 25643 2010-01-01 05:09:30Z nexyon $
3
 
 *
4
 
 * ***** BEGIN LGPL LICENSE BLOCK *****
5
 
 *
6
 
 * Copyright 2009 Jörg Hermann Müller
 
2
 * ***** BEGIN GPL LICENSE BLOCK *****
 
3
 *
 
4
 * Copyright 2009-2011 Jörg Hermann Müller
7
5
 *
8
6
 * This file is part of AudaSpace.
9
7
 *
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.
14
12
 *
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.
19
 
 *
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/>.
22
 
 *
23
 
 * ***** END LGPL LICENSE BLOCK *****
24
 
 */
 
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_EnvelopeFactory.cpp
 
26
 *  \ingroup audfx
 
27
 */
 
28
 
25
29
 
26
30
#include "AUD_EnvelopeFactory.h"
27
 
#include "AUD_EnvelopeReader.h"
28
 
 
29
 
AUD_EnvelopeFactory::AUD_EnvelopeFactory(AUD_IFactory* factory, float attack,
 
31
#include "AUD_CallbackIIRFilterReader.h"
 
32
 
 
33
#include <cmath>
 
34
 
 
35
struct EnvelopeParameters
 
36
{
 
37
        float attack;
 
38
        float release;
 
39
        float threshold;
 
40
        float arthreshold;
 
41
};
 
42
 
 
43
sample_t AUD_EnvelopeFactory::envelopeFilter(AUD_CallbackIIRFilterReader* reader, EnvelopeParameters* param)
 
44
{
 
45
        float in = fabs(reader->x(0));
 
46
        float out = reader->y(-1);
 
47
        if(in < param->threshold)
 
48
                in = 0.0f;
 
49
        return (in > out ? param->attack : param->release) * (out - in) + in;
 
50
}
 
51
 
 
52
void AUD_EnvelopeFactory::endEnvelopeFilter(EnvelopeParameters* param)
 
53
{
 
54
        delete param;
 
55
}
 
56
 
 
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),
33
61
                m_attack(attack),
34
62
                m_release(release),
35
63
                m_threshold(threshold),
36
 
                m_arthreshold(arthreshold) {}
37
 
 
38
 
AUD_EnvelopeFactory::AUD_EnvelopeFactory(float attack, float release,
39
 
                                                                                 float threshold, float arthreshold) :
40
 
                AUD_EffectFactory(0),
41
 
                m_attack(attack),
42
 
                m_release(release),
43
 
                m_threshold(threshold),
44
 
                m_arthreshold(arthreshold) {}
45
 
 
46
 
AUD_IReader* AUD_EnvelopeFactory::createReader()
47
 
{
48
 
        AUD_IReader* reader = getReader();
49
 
 
50
 
        if(reader != 0)
51
 
        {
52
 
                reader = new AUD_EnvelopeReader(reader, m_attack, m_release,
53
 
                                                                                m_threshold, m_arthreshold);
54
 
                AUD_NEW("reader")
55
 
        }
56
 
 
57
 
        return reader;
 
64
                m_arthreshold(arthreshold)
 
65
{
 
66
}
 
67
 
 
68
AUD_Reference<AUD_IReader> AUD_EnvelopeFactory::createReader()
 
69
{
 
70
        AUD_Reference<AUD_IReader> reader = getReader();
 
71
 
 
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;
 
77
 
 
78
        return new AUD_CallbackIIRFilterReader(reader, 1, 2,
 
79
                                                                                   (doFilterIIR) envelopeFilter,
 
80
                                                                                   (endFilterIIR) endEnvelopeFilter,
 
81
                                                                                   param);
58
82
}