CLAM-Development
1.1
|
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 #ifndef _AudioAmplifier_ 00023 #define _AudioAmplifier_ 00024 00025 #include "Processing.hxx" 00026 #include "ProcessingConfig.hxx" 00027 #include "Audio.hxx" 00028 #include "AudioInPort.hxx" 00029 #include "AudioOutPort.hxx" 00030 #include "InControl.hxx" 00031 00032 namespace CLAM{ 00033 00037 class AudioAmplifierConfig : public ProcessingConfig 00038 { 00039 public: 00040 DYNAMIC_TYPE_USING_INTERFACE( AudioAmplifierConfig, 1, ProcessingConfig ); 00041 DYN_ATTRIBUTE( 0, public, double, MaxGain ); 00042 00043 protected: 00044 void DefaultInit(); 00045 }; 00046 00047 00053 class AudioAmplifier: public Processing 00054 { 00058 const char *GetClassName() const { return "AudioAmplifier"; } 00059 00061 AudioInPort mInputAudio; 00062 AudioOutPort mOutputAudio; 00063 00065 InControl mInputControl; 00066 00067 00068 public: 00069 00070 AudioAmplifier() 00071 : 00072 mInputAudio("Input Audio",this ), 00073 mOutputAudio("Audio Output",this), 00074 00075 mInputControl("Gain", this) 00076 { 00077 Configure( mConfig ); 00078 } 00079 00080 ~AudioAmplifier() {} 00081 00082 bool Do() 00083 { 00084 bool result = Do( mInputAudio.GetAudio(), mOutputAudio.GetAudio() ); 00085 00086 mInputAudio.Consume(); 00087 mOutputAudio.Produce(); 00088 00089 return result; 00090 } 00091 00092 bool Do(const Audio& in, Audio& out) 00093 { 00094 int size = in.GetSize(); 00095 00096 TData gain = mInputControl.GetLastValue(); 00097 00098 const DataArray& inb = in.GetBuffer(); 00099 DataArray& outb = out.GetBuffer(); 00100 00101 for (int i=0;i<size;i++) 00102 { 00103 outb[i] = inb[i]*gain; 00104 } 00105 00106 return true; 00107 } 00108 00109 typedef AudioAmplifierConfig Config; 00110 00111 00112 protected: 00113 00114 const ProcessingConfig& GetConfig() const { return mConfig; } 00115 00116 bool ConcreteConfigure(const ProcessingConfig& config) { 00117 00118 CopyAsConcreteConfig( mConfig, config ); 00119 00120 double max_gain = mConfig.GetMaxGain(); 00121 mInputControl.SetBounds(0.,max_gain); 00122 mInputControl.SetDefaultValue(1.); 00123 mInputControl.DoControl(1.); 00124 return true; 00125 } 00126 00127 00128 private: 00129 00131 Config mConfig; 00132 }; 00133 00134 };//namespace CLAM 00135 00136 #endif // _AudioAmplifier_ 00137