AudioWindowing.cxx
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "Segment.hxx"
00023 #include "Frame.hxx"
00024 #include "SpectrumConfig.hxx"
00025 #include "AudioWindowing.hxx"
00026 #include "ProcessingFactory.hxx"
00027
00028 namespace CLAM
00029 {
00030
00031 namespace Hidden
00032 {
00033 static const char* metadata[] = {
00034 "key", "AudioWindowing",
00035 "category", "Analysis",
00036 "description", "AudioWindowing",
00037 0
00038 };
00039 static FactoryRegistrator<ProcessingFactory, AudioWindowing> reg = metadata;
00040 }
00041
00042 AudioWindowing::~AudioWindowing()
00043 {
00044 }
00045
00046 bool AudioWindowing::ConcreteConfigure(const ProcessingConfig& cfg)
00047 {
00048 CopyAsConcreteConfig(mConfig,cfg);
00049
00050 if (! ConfigureChildren()) return false;
00051 ConfigureData();
00052 return true;
00053 }
00054
00055 bool AudioWindowing::ConfigureChildren()
00056 {
00057 int windowSize = mConfig.GetWindowSize();
00058 EWindowType windowType = mConfig.GetWindowType();
00059 if (not (windowSize&1))
00060 {
00061 AddConfigErrorMessage("FFT Restriction:");
00062 AddConfigErrorMessage("Window size should be odd.");
00063 return false;
00064 }
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074 if (not isPowerOfTwo(mConfig.GetFFTSize()))
00075 {
00076 AddConfigErrorMessage("FFT Restriction:");
00077 AddConfigErrorMessage("FFT Size should be a power of two.");
00078 return false;
00079 }
00080 WindowGeneratorConfig windowGeneratorConfig;
00081 windowGeneratorConfig.SetSize(windowSize);
00082 windowGeneratorConfig.SetType(windowType);
00083 if (! mWindowGenerator.Configure(windowGeneratorConfig) )
00084 {
00085 AddConfigErrorMessage("Window Generator configuration failed.");
00086 AddConfigErrorMessage(mWindowGenerator.GetConfigErrorMessage());
00087 return false;
00088 }
00089
00090 CircularShiftConfig circularShiftConfig;
00091 circularShiftConfig.SetAmount(-((windowSize-1)/TData(2)));
00092 if (! mCircularShift.Configure(circularShiftConfig) )
00093 {
00094 AddConfigErrorMessage("Circular Shift configuration failed.");
00095 AddConfigErrorMessage(mCircularShift.GetConfigErrorMessage());
00096 return false;
00097 }
00098
00099 return true;
00100 }
00101
00102 void AudioWindowing::ConfigureData()
00103 {
00104 mInput.SetSize(mConfig.GetWindowSize()-1);
00105 mInput.SetHop(mConfig.GetHopSize());
00106
00107 mWindow.SetSize(mConfig.GetWindowSize());
00108
00109
00110 mWindowGenerator.Do(mWindow);
00111
00112
00113 mWindow.SetSize(mWindow.GetSize()-1);
00114
00115
00116 mWindow.SetSize(mConfig.GetFFTSize());
00117 }
00118
00119 void AudioWindowing::AttachChildren()
00120 {
00121 mWindowGenerator.SetParent(this);
00122 mAudioProduct.SetParent(this);
00123 mCircularShift.SetParent(this);
00124 }
00125
00126 bool AudioWindowing::Do(void)
00127 {
00128 bool result = Do(mInput.GetAudio(),mOutput.GetData());
00129
00130 mInput.Consume();
00131 mOutput.Produce();
00132
00133 return result;
00134 }
00135
00136 bool AudioWindowing::Do(const Audio& in,Audio& out)
00137 {
00138 in.GetAudioChunk(0,in.GetSize() ,out,true );
00139 out.SetSampleRate(mConfig.GetSamplingRate());
00140
00141
00142 out.SetSize(mConfig.GetFFTSize());
00143
00144
00145 if (mConfig.GetWindowType()!=EWindowType::eNone )
00146 mAudioProduct.Do(out, mWindow, out);
00147
00148
00149 if (mConfig.GetDoHalfWindowShift())
00150 mCircularShift.Do(out,out);
00151
00152
00153 return true;
00154 }
00155
00156
00157
00158 }
00159