~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
 
30
30
#include "AUD_ButterworthFactory.h"
31
31
#include "AUD_IIRFilterReader.h"
32
 
 
33
 
#include <cmath>
34
 
 
35
 
#ifndef M_PI
36
 
#define M_PI 3.14159265358979323846
37
 
#endif
38
 
 
39
 
#define BWPB41 0.76536686473
40
 
#define BWPB42 1.84775906502
41
 
 
42
 
AUD_ButterworthFactory::AUD_ButterworthFactory(AUD_Reference<AUD_IFactory> factory,
 
32
#include "AUD_ButterworthCalculator.h"
 
33
 
 
34
AUD_ButterworthFactory::AUD_ButterworthFactory(boost::shared_ptr<AUD_IFactory> factory,
43
35
                                                                                           float frequency) :
44
 
                AUD_DynamicIIRFilterFactory(factory),
45
 
                m_frequency(frequency)
 
36
                AUD_DynamicIIRFilterFactory(factory, boost::shared_ptr<AUD_IDynamicIIRFilterCalculator>(new AUD_ButterworthCalculator(frequency)))
46
37
{
47
38
}
48
39
 
49
 
void AUD_ButterworthFactory::recalculateCoefficients(AUD_SampleRate rate,
50
 
                                                                                                         std::vector<float> &b,
51
 
                                                                                                         std::vector<float> &a)
52
 
{
53
 
        float omega = 2 * tan(m_frequency * M_PI / rate);
54
 
        float o2 = omega * omega;
55
 
        float o4 = o2 * o2;
56
 
        float x1 = o2 + 2 * BWPB41 * omega + 4;
57
 
        float x2 = o2 + 2 * BWPB42 * omega + 4;
58
 
        float y1 = o2 - 2 * BWPB41 * omega + 4;
59
 
        float y2 = o2 - 2 * BWPB42 * omega + 4;
60
 
        float o228 = 2 * o2 - 8;
61
 
        float norm = x1 * x2;
62
 
        a.push_back(1);
63
 
        a.push_back((x1 + x2) * o228 / norm);
64
 
        a.push_back((x1 * y2 + x2 * y1 + o228 * o228) / norm);
65
 
        a.push_back((y1 + y2) * o228 / norm);
66
 
        a.push_back(y1 * y2 / norm);
67
 
        b.push_back(o4 / norm);
68
 
        b.push_back(4 * o4 / norm);
69
 
        b.push_back(6 * o4 / norm);
70
 
        b.push_back(b[1]);
71
 
        b.push_back(b[0]);
72
 
}