EnvelopeModulator.cxx

Go to the documentation of this file.
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 "EnvelopeModulator.hxx"
00023 #include "CLAM_Math.hxx"
00024 
00025 
00026 namespace CLAM {
00027 
00028         void EnvModulatorConfig::DefaultInit()
00029         {
00030                 AddAll();
00031                 UpdateData();
00032                 SetSampleRate(44100);
00033                 SetFrameSize(512);
00034                 SetEnvelopeCompression(true);
00035         }
00036 
00037 
00038         EnvelopeModulator::EnvelopeModulator(const EnvModulatorConfig& c)
00039                 : InputEnvelope("Input Envelope",this),
00040                   InputAudio("Input Audio",this),
00041                   Output("Output Audio",this)
00042         {
00043                 Configure(c);
00044         }
00045 
00046         bool EnvelopeModulator::ConcreteConfigure(const ProcessingConfig& c)
00047         {
00048                 CopyAsConcreteConfig(mConfig, c);
00049 
00050                 mDeltaX = 1000.0/((TTime)mConfig.GetSampleRate());
00051 
00052                 mCompress = mConfig.GetEnvelopeCompression();
00053 
00054                 InputAudio.SetSize(mConfig.GetFrameSize());
00055                 Output.SetSize(mConfig.GetFrameSize());
00056                 return true;
00057         }
00058 
00059         TData EnvelopeModulator::Compress(TData x)
00060         {
00061                 if (x>=0)
00062                         return 1.0 - exp(-x);
00063                 else
00064                         return - (1.0 - exp(x));
00065         }
00066 
00067 
00068         bool EnvelopeModulator::Do()
00069         {
00070                 bool res = Do(InputEnvelope.GetData(),
00071                                           InputAudio.GetData(),
00072                                           Output.GetData());
00073                 InputEnvelope.Consume();
00074                 InputAudio.Consume();
00075                 Output.Produce();         
00076                 return res;
00077         }
00078 
00079         bool EnvelopeModulator::Do(const Envelope& env, const Audio& inp, Audio& out) 
00080         {
00081                 Array<TData> &inputArray = inp.GetBuffer();
00082                 Array<TData> &outputArray = out.GetBuffer();
00083                 BPFTmpl<TTime,TData> &amplitudeBpf = env.GetAmplitudeBPF();
00084                 TTime pos = 0.0;
00085                 const int size = std::min(inp.GetSize(), out.GetSize());
00086                 if (mCompress)
00087                         for (int i=0;i<size;i++) {
00088                                 outputArray[i]=inputArray[i]*amplitudeBpf.GetValue(pos);
00089                                 pos += mDeltaX;
00090                         }
00091                 else
00092                         for (int i=0;i<size;i++) {
00093                                 outputArray[i]=inputArray[i]*Compress(amplitudeBpf.GetValue(pos));
00094                                 pos += mDeltaX;
00095                         }
00096                 return true;
00097         }
00098 
00099 
00100 }
00101 
Generated by  doxygen 1.6.3