~ubuntu-branches/ubuntu/precise/lmms/precise-updates

« back to all changes in this revision

Viewing changes to plugins/peak_controller_effect/peak_controller_effect.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Артём Попов
  • Date: 2011-02-14 20:58:36 UTC
  • mfrom: (1.1.10 upstream) (3.1.9 sid)
  • Revision ID: james.westby@ubuntu.com-20110214205836-2u41xus1d2mj8nfz
Tags: 0.4.10-1ubuntu1
* Merge from debian unstable (LP: #718801).  Remaining changes:
  - Replace build-dep on libwine-dev with wine1.2-dev to build
    against the newer Wine.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 * peak_controller_effect.cpp - PeakController effect plugin
3
3
 *
4
4
 * Copyright (c) 2008 Paul Giblock <drfaygo/at/gmail/dot/com>
5
 
 * 
 
5
 * Copyright (c) 2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
 
6
 *
6
7
 * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
7
8
 *
8
9
 * This program is free software; you can redistribute it and/or
39
40
        STRINGIFY( PLUGIN_NAME ),
40
41
        "Peak Controller",
41
42
        QT_TRANSLATE_NOOP( "pluginBrowser",
42
 
                                "Plugin for controlling knobs with sound peaks" ),
 
43
                        "Plugin for controlling knobs with sound peaks" ),
43
44
        "Paul Giblock <drfaygo/at/gmail.com>",
44
45
        0x0100,
45
46
        Plugin::Effect,
61
62
                        const Descriptor::SubPluginFeatures::Key * _key ) :
62
63
        Effect( &peakcontrollereffect_plugin_descriptor, _parent, _key ),
63
64
        m_peakControls( this ),
 
65
        m_lastSample( 0 ),
 
66
        m_lastRMS( -1 ),
64
67
        m_autoController( NULL )
65
68
{
66
69
        m_autoController = new PeakController( engine::getSong(), this );
91
94
        // audio with this effect       
92
95
        if( !isEnabled() || !isRunning() )
93
96
        {
94
 
                return( FALSE );
 
97
                return false;
95
98
        }
96
99
 
97
 
 
98
100
        // RMS:
99
101
        double sum = 0;
100
102
        for( int i = 0; i < _frames; ++i )
110
112
                }
111
113
        }
112
114
 
113
 
        m_lastSample = c.m_baseModel.value() + c.m_amountModel.value() *
114
 
                                                        sqrtf( sum / _frames );
 
115
        float curRMS = sqrtf( sum / _frames );
 
116
        const float origRMS = curRMS;
 
117
        if( m_lastRMS < 0 )
 
118
        {
 
119
                m_lastRMS = curRMS;
 
120
        }
 
121
        const float v = ( curRMS >= m_lastRMS ) ?
 
122
                                c.m_attackModel.value() :
 
123
                                        c.m_decayModel.value();
 
124
        const float a = sqrtf( sqrtf( v ) );
 
125
        curRMS = (1-a)*curRMS + a*m_lastRMS;
 
126
 
 
127
        m_lastSample = c.m_baseModel.value() + c.m_amountModel.value()*curRMS;
 
128
        m_lastRMS = curRMS;
 
129
 
 
130
        // on greater buffer sizes our LP is updated less frequently, therfore
 
131
        // replay a certain number of passes so the LP state is as if it was
 
132
        // updated N times with buffer-size 1/N
 
133
        const int timeOversamp = (4*_frames) / DEFAULT_BUFFER_SIZE-1;
 
134
        for( int i = 0; i < timeOversamp; ++i )
 
135
        {
 
136
                m_lastRMS = (1-a)*origRMS + a*m_lastRMS;
 
137
        }
115
138
 
116
139
        //checkGate( out_sum / _frames );
117
140
 
118
 
        return( isRunning() );
 
141
        return isRunning();
119
142
}
120
143
 
121
144
 
128
151
Plugin * PLUGIN_EXPORT lmms_plugin_main( Model * _parent, void * _data )
129
152
{
130
153
        return new PeakControllerEffect( _parent,
131
 
                static_cast<const Plugin::Descriptor::SubPluginFeatures::Key *>(
132
 
                                                                _data ) );
 
154
                static_cast<const Plugin::Descriptor::SubPluginFeatures::Key *>( _data ) );
133
155
}
134
156
 
135
157
}