CLAM-Development  1.4.0
SimpleOscillator.cxx
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG)
3  * UNIVERSITAT POMPEU FABRA
4  *
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  */
21 
22 #include "SimpleOscillator.hxx"
23 #include "ProcessingFactory.hxx"
24 
25 namespace CLAM
26 {
27 
28 namespace Hidden
29 {
30  static const char * metadata[] = {
31  "key", "SimpleOscillator",
32  "category", "Generators",
33  "description", "SimpleOscillator",
34  0
35  };
36  static FactoryRegistrator<ProcessingFactory, SimpleOscillator> reg = metadata;
37 }
38 
39 
40 // OscillatorConfig method definition
42 {
43  AddFrequency();
44  AddAmplitude();
45  AddPhase();
46  AddSamplingRate();
47 
48  UpdateData();
49 
50  SetFrequency(440.0);
51  SetAmplitude(1.0);
52  SetPhase(0.0);
53  SetSamplingRate( 44100 );
54 }
55 
57  : mOutput("Audio Output", this)
58  , mFreqUpdated( false )
59  , mAmpUpdated( false )
60  , mFreqCtl( "Pitch", this, &SimpleOscillator::UpdateFreq )
61  , mAmpCtl( "Amplitude", this, &SimpleOscillator::UpdateAmp )
62  , mSamplesBetweenCallsCtl("SamplesBetweenCalls", this)
63 {
64  Configure( cfg );
65 }
66 
68 {
69 }
70 
72 {
74 
75 
76  mAmp = mConfig.GetAmplitude();
77  mPhase = mConfig.GetPhase(); // TEMP HACK (See also constructor
78  mSamplingRate = mConfig.GetSamplingRate();
79  mDeltaPhase = TData(2.*PI*mConfig.GetFrequency()/mSamplingRate);
80  //xamat: kludge to convert this into an LFO, eventually separate into a different class
82  return true;
83 }
84 
86 {
87  bool res = false;
88  res = Do(mOutput.GetAudio());
89  mOutput.Produce();
90  return res;
91 }
92 
94 {
95  if( !AbleToExecute() ) return true;
96 
98 
99  TData* ptr = out.GetBuffer().GetPtr();
100  for (int i=0;i<out.GetSize();i++)
101  {
102  (*ptr++) = mAmp * TData(sin(mPhase));
103  mPhase += mDeltaPhase;
104 
105  if (mPhase>TData(2*PI))
106  mPhase-=TData(2*PI);
107  }
108 
109  return true;
110 }
111 
112 //xamat: kludge to convert this into an LFO, eventually separate into a different class
114 {
115  if( !AbleToExecute() ) return true;
116 
118 
119  out = mAmp * TData(sin(mPhase));
121 
122  if (mPhase>TData(2*PI))
123  mPhase-=TData(2*PI);
124 
125  return true;
126 }
127 
128 
130 {
131  mFreqUpdated = true;
132 }
133 
135 {
136  mAmpUpdated = true;
137 }
138 
139 } // namespace CLAM
140