1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
|
/*
* Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG)
* UNIVERSITAT POMPEU FABRA
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "ProcessingComposite.hxx"
#include "FFT.hxx"
#include "IFFT.hxx"
#include "SpectrumProduct.hxx"
using namespace CLAM;
/** Big configuration class */
class BigConfiguration : public ProcessingConfig {
public:
DYNAMIC_TYPE_USING_INTERFACE (BigConfiguration, 2,ProcessingConfig);
DYN_ATTRIBUTE (0, public, std::string, Name);
DYN_ATTRIBUTE (1, public, int, AudioSize);
void DefaultInit();
};
/** This is the processing object class we are using to group several
* other processing objects.
*/
class BigProcessing : public ProcessingComposite {
// Configuration data
BigConfiguration mConfig;
// We define the internal data in our system.
Spectrum ImpulseResponse;
Spectrum SpectralInput;
Spectrum SpectralOutput;
// The internal Processing Objects
FFT mInputFFT;
SpectrumProduct mFilter;
IFFT mOutputIFFT;
// And the interfaces with the outside world.
/** Global input port */
AudioInPort InputAudio;
/** Global output port */
AudioInPort OutputAudio;
// Internal convenience methods.
void AdoptChildren();
void AttachChildren();
bool ConfigureChildren(int size);
void ConfigureData(int size);
// Processing Object compliance methods.
const char *GetClassName() const {return "BigProcessing";}
/** Configuration method */
bool ConcreteConfigure(const ProcessingConfig&);
public:
BigProcessing(BigConfiguration&);
BigProcessing();
const ProcessingConfig &GetConfig() const {return mConfig;}
/** Supervised mode execution */
bool Do(void);
/** Unsupervised mode execution */
bool Do(Audio& in, Audio &out);
};
void BigProcessing::AdoptChildren()
{
mInputFFT.SetParent(this);
mFilter.SetParent(this);
mOutputIFFT.SetParent(this);
}
BigProcessing::BigProcessing() :
InputAudio("Input Audio",this),
OutputAudio("Output Audio",this)
{
AdoptChildren();
Configure(BigConfiguration());
}
BigProcessing::BigProcessing(BigConfiguration& cfg) :
InputAudio("Input Audio",this),
OutputAudio("Output Audio",this)
{
AdoptChildren();
Configure(cfg);
}
bool BigProcessing::ConfigureChildren(int size)
{
FFTConfig cfg_fft;
cfg_fft.SetAudioSize(size);
if (!mInputFFT.Configure(cfg_fft))
return false;
IFFTConfig cfg_ifft;
cfg_ifft.SetAudioSize(size);
if (!mOutputIFFT.Configure(cfg_ifft))
return false;
// Note: mFilter has not config parameters.
return true;
}
void BigProcessing::ConfigureData(int audio_size)
{
int spectrum_size = audio_size / 2 + 1;
ImpulseResponse.SetSize(spectrum_size);
SpectralInput.SetSize(spectrum_size);
SpectralOutput.SetSize(spectrum_size);
}
bool BigProcessing::ConcreteConfigure(const ProcessingConfig& c)
{
CopyAsConcreteConfig(mConfig, c);
int size=0;
if (mConfig.HasAudioSize())
size = mConfig.GetAudioSize();
ConfigureChildren(size);
ConfigureData(size);
return true;
}
bool BigProcessing::Do()
{
return false;
}
bool BigProcessing::Do(Audio& in, Audio &out)
{
mInputFFT.Do(in,SpectralInput);
mFilter.Do(SpectralInput,ImpulseResponse,SpectralOutput);
mOutputIFFT.Do(SpectralOutput,out);
return true;
}
void BigConfiguration::DefaultInit()
{
AddName();
AddAudioSize();
UpdateData();
SetAudioSize(0);
}
int main()
{
try {
BigProcessing system;
BigConfiguration system_config;
Audio Input;
Audio Output;
Input.SetSize(1024);
Output.SetSize(1024);
system_config.SetAudioSize(1024);
system.Configure(system_config);
system.Start();
system.Do(Input,Output);
} catch(Err &e) {
e.Print();
}
return 0;
}
|