|
CLAM-Development
1.3
|
00001 /* 00002 * Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG) 00003 * UNIVERSITAT POMPEU FABRA 00004 * 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 * 00020 */ 00021 00022 #include "SimpleOscillator.hxx" 00023 #include "ProcessingFactory.hxx" 00024 00025 namespace CLAM 00026 { 00027 00028 namespace Hidden 00029 { 00030 static const char * metadata[] = { 00031 "key", "SimpleOscillator", 00032 "category", "Generators", 00033 "description", "SimpleOscillator", 00034 0 00035 }; 00036 static FactoryRegistrator<ProcessingFactory, SimpleOscillator> reg = metadata; 00037 } 00038 00039 00040 // OscillatorConfig method definition 00041 void SimpleOscillatorConfig::DefaultInit(void) 00042 { 00043 AddFrequency(); 00044 AddAmplitude(); 00045 AddPhase(); 00046 AddSamplingRate(); 00047 00048 UpdateData(); 00049 00050 SetFrequency(440.0); 00051 SetAmplitude(1.0); 00052 SetPhase(0.0); 00053 SetSamplingRate( 44100 ); 00054 } 00055 00056 SimpleOscillator::SimpleOscillator( const SimpleOscillatorConfig& cfg ) 00057 : mOutput("Audio Output", this) 00058 , mFreqUpdated( false ) 00059 , mAmpUpdated( false ) 00060 , mFreqCtl( "Pitch", this, &SimpleOscillator::UpdateFreq ) 00061 , mAmpCtl( "Amplitude", this, &SimpleOscillator::UpdateAmp ) 00062 , mSamplesBetweenCallsCtl("SamplesBetweenCalls", this) 00063 { 00064 Configure( cfg ); 00065 } 00066 00067 SimpleOscillator::~SimpleOscillator() 00068 { 00069 } 00070 00071 bool SimpleOscillator::ConcreteConfigure( const ProcessingConfig& c ) 00072 { 00073 CopyAsConcreteConfig(mConfig, c); 00074 00075 00076 mAmp = mConfig.GetAmplitude(); 00077 mPhase = mConfig.GetPhase(); // TEMP HACK (See also constructor 00078 mSamplingRate = mConfig.GetSamplingRate(); 00079 mDeltaPhase = TData(2.*PI*mConfig.GetFrequency()/mSamplingRate); 00080 //xamat: kludge to convert this into an LFO, eventually separate into a different class 00081 mSamplesBetweenCallsCtl.DoControl(1); 00082 return true; 00083 } 00084 00085 bool SimpleOscillator::Do() 00086 { 00087 bool res = false; 00088 res = Do(mOutput.GetAudio()); 00089 mOutput.Produce(); 00090 return res; 00091 } 00092 00093 bool SimpleOscillator::Do( Audio& out ) 00094 { 00095 if( !AbleToExecute() ) return true; 00096 00097 ApplyFreqAndAmpControls(); 00098 00099 TData* ptr = out.GetBuffer().GetPtr(); 00100 for (int i=0;i<out.GetSize();i++) 00101 { 00102 (*ptr++) = mAmp * TData(sin(mPhase)); 00103 mPhase += mDeltaPhase; 00104 00105 if (mPhase>TData(2*PI)) 00106 mPhase-=TData(2*PI); 00107 } 00108 00109 return true; 00110 } 00111 00112 //xamat: kludge to convert this into an LFO, eventually separate into a different class 00113 bool SimpleOscillator::Do( TData& out ) 00114 { 00115 if( !AbleToExecute() ) return true; 00116 00117 ApplyFreqAndAmpControls(); 00118 00119 out = mAmp * TData(sin(mPhase)); 00120 mPhase += mDeltaPhase*mSamplesBetweenCallsCtl.GetLastValue(); 00121 00122 if (mPhase>TData(2*PI)) 00123 mPhase-=TData(2*PI); 00124 00125 return true; 00126 } 00127 00128 00129 void SimpleOscillator::UpdateFreq( TControlData value ) 00130 { 00131 mFreqUpdated = true; 00132 } 00133 00134 void SimpleOscillator::UpdateAmp( TControlData value ) 00135 { 00136 mAmpUpdated = true; 00137 } 00138 00139 } // namespace CLAM 00140
1.7.6.1