~ubuntu-branches/ubuntu/hoary/kdemultimedia/hoary

« back to all changes in this revision

Viewing changes to arts/modules/synth_fx_cflanger_impl.cc

  • Committer: Bazaar Package Importer
  • Author(s): Martin Schulze
  • Date: 2003-01-22 15:00:51 UTC
  • Revision ID: james.westby@ubuntu.com-20030122150051-uihwkdoxf15mi1tn
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
    /*
 
2
 
 
3
    Copyright (C) 2000 Jeff Tranter
 
4
                       tranter@pobox.com
 
5
                       Stefan Westerfeld
 
6
                       stefan@space.twc.de
 
7
    
 
8
    This library is free software; you can redistribute it and/or
 
9
    modify it under the terms of the GNU Library General Public
 
10
    License as published by the Free Software Foundation; either
 
11
    version 2 of the License, or (at your option) any later version.
 
12
  
 
13
    This library is distributed in the hope that it will be useful,
 
14
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
16
    Library General Public License for more details.
 
17
   
 
18
    You should have received a copy of the GNU Library General Public License
 
19
    along with this library; see the file COPYING.LIB.  If not, write to
 
20
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
21
    Boston, MA 02111-1307, USA.
 
22
 
 
23
    */
 
24
 
 
25
#include <math.h>
 
26
#include "artsmodules.h"
 
27
#include "stdsynthmodule.h"
 
28
 
 
29
using namespace Arts;
 
30
 
 
31
class Synth_FX_CFLANGER_impl : virtual public Synth_FX_CFLANGER_skel,
 
32
                                                        virtual public StdSynthModule
 
33
{
 
34
protected:
 
35
        float _mintime;
 
36
        float _maxtime;
 
37
        static const int SAMPLINGRATE = 44100;
 
38
        static const int MAXDELAY = SAMPLINGRATE;
 
39
        float *dbuffer;
 
40
        unsigned long dbpos;
 
41
        float center;
 
42
        float range;
 
43
 
 
44
public:
 
45
        Synth_FX_CFLANGER_impl()
 
46
        {
 
47
                dbuffer=new float[MAXDELAY];
 
48
        }
 
49
        ~Synth_FX_CFLANGER_impl()
 
50
        {
 
51
                delete [] dbuffer;
 
52
        }
 
53
 
 
54
        float mintime() { return _mintime; }
 
55
 
 
56
        void mintime(float newMintime) { _mintime = newMintime; }
 
57
 
 
58
        float maxtime() { return _maxtime; }
 
59
 
 
60
        void maxtime(float newMaxtime) { _maxtime = newMaxtime; }
 
61
 
 
62
        void streamInit()
 
63
        {
 
64
                center = (_maxtime + _mintime) / 2;
 
65
                range = _maxtime - center;
 
66
                for (int i=0; i<MAXDELAY; i++)
 
67
                        dbuffer[i] = 0;
 
68
                dbpos = 0;
 
69
        }
 
70
 
 
71
        void calculateBlock(unsigned long samples)
 
72
        {
 
73
                unsigned long i;
 
74
                float delay, floor_delay;
 
75
                long start_pos, end_pos;
 
76
                float start_val, end_val;
 
77
 
 
78
                for(i=0; i<samples; i++)
 
79
                {
 
80
                        dbuffer[dbpos] = invalue[i];
 
81
                        // Delaytime i.e. = 35ms + (+/- LFO[-1 bis 1] * 15ms) / 1000 * 44100
 
82
                        delay = ((center + (lfo[i] * range)) / 1000.0) * (float) SAMPLINGRATE;
 
83
                        floor_delay = floor(delay);
 
84
                        start_pos = dbpos - (long)(floor_delay);
 
85
                        end_pos = start_pos-1;
 
86
                        if (start_pos < 0) start_pos += MAXDELAY; // wrapping exception
 
87
                        if (end_pos < 0) end_pos += MAXDELAY;
 
88
                        start_val = dbuffer[start_pos];
 
89
                        end_val = dbuffer[end_pos];
 
90
                        outvalue[i] = start_val + ((delay - floor_delay) * (end_val - start_val));
 
91
                        dbpos++;
 
92
                        if (dbpos == MAXDELAY) dbpos = 0;
 
93
                }
 
94
        }
 
95
};
 
96
 
 
97
REGISTER_IMPLEMENTATION(Synth_FX_CFLANGER_impl);