SpectralEnvelopeApply.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 "Complex.hxx"
00023 #include "SpectralEnvelopeApply.hxx"
00024
00025 #define CLASS "SpectralEnvelopeApply"
00026
00027 namespace CLAM {
00028
00029
00030
00031 SpectralEnvelopeApply::SpectralEnvelopeApply()
00032 {
00033 Configure(SpectralEnvelopeApplyConfig());
00034 }
00035
00036 SpectralEnvelopeApply::SpectralEnvelopeApply(const SpectralEnvelopeApplyConfig &c = SpectralEnvelopeApplyConfig())
00037 {
00038 Configure(c);
00039 }
00040
00041 SpectralEnvelopeApply::~SpectralEnvelopeApply()
00042 {}
00043
00044
00045
00046
00047 bool SpectralEnvelopeApply::ConcreteConfigure(const ProcessingConfig& c)
00048 {
00049
00050 CopyAsConcreteConfig(mConfig, c);
00051 return true;
00052 }
00053
00054
00055
00056 bool SpectralEnvelopeApply::SetPrototypes(const SpectralPeakArray& input,Spectrum& output)
00057 {
00058 return true;
00059 }
00060
00061 bool SpectralEnvelopeApply::SetPrototypes()
00062 {
00063 return true;
00064 }
00065
00066 bool SpectralEnvelopeApply::UnsetPrototypes()
00067 {
00068 return true;
00069 }
00070
00071
00072
00073 bool SpectralEnvelopeApply::Do(void)
00074 {
00075 CLAM_ASSERT(false,CLASS"::Do(): Supervised mode not implemented");
00076 return false;
00077 }
00078
00079
00080 bool SpectralEnvelopeApply::Do(const SpectralPeakArray& input, const Spectrum& spectralEnvelope, SpectralPeakArray& output)
00081 {
00082 output.SetScale(input.GetScale());
00083 CLAM_ASSERT(input.GetScale()==spectralEnvelope.GetScale(),"You are trying to apply an envelope that has a different scale");
00084
00085 TSize nPeaks=input.GetnPeaks();
00086
00087 DataArray& iphaseBuffer=input.GetPhaseBuffer();
00088 DataArray& ifreqBuffer=input.GetFreqBuffer();
00089
00090 if(output.GetnMaxPeaks()!=input.GetnMaxPeaks())
00091 output.SetnMaxPeaks(input.GetnMaxPeaks());
00092 if(output.GetnPeaks()!=input.GetnPeaks())
00093 output.SetnPeaks(input.GetnPeaks());
00094
00095 DataArray& omagBuffer=output.GetMagBuffer();
00096 DataArray& ophaseBuffer=output.GetPhaseBuffer();
00097 DataArray& ofreqBuffer=output.GetFreqBuffer();
00098
00099 int i;
00100
00101 BPF& env = spectralEnvelope.GetMagBPF();
00102 for(i=0;i<nPeaks;i++)
00103 {
00104 ophaseBuffer[i]=iphaseBuffer[i];
00105 omagBuffer[i]=env.GetValue(ifreqBuffer[i]);
00106 ofreqBuffer[i]=ifreqBuffer[i];
00107 }
00108
00109 return true;
00110 }
00111
00112
00113 bool SpectralEnvelopeApply::Do(const Spectrum& input, const Spectrum& spectralEnvelope, Spectrum& output)
00114 {
00115 output.SetScale(input.GetScale());
00116 CLAM_ASSERT(input.GetScale()==spectralEnvelope.GetScale(),"You are trying to apply an envelope that has a different scale");
00117
00118 output=input;
00119
00120 int spectrumSize=input.GetSize();
00121
00122 int i;
00123 TData delta = input.GetSpectralRange()/(spectrumSize-1);
00124 DataArray& outMag = output.GetMagBuffer();
00125 BPF& env = spectralEnvelope.GetMagBPF();
00126
00127 TData currentFreq = 0.;
00128 for(i=0;i<spectrumSize;i++, currentFreq+=delta)
00129
00130 {
00131
00132 outMag[i] = env.GetValue(currentFreq);
00133
00134
00135 }
00136
00137
00138 return true;
00139 }
00140
00141
00142 };
00143