SMSPitchDiscretization.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 "SMSPitchDiscretization.hxx"
00023 #include "ProcessingFactory.hxx"
00024
00025
00026
00027 namespace CLAM
00028 {
00029
00030
00031 namespace Hidden
00032 {
00033 static const char * metadata[] = {
00034 "key", "SMSPitchDiscretization",
00035 "category", "SMS Transformations",
00036 "description", "SMSPitchDiscretization",
00037 0
00038 };
00039 static FactoryRegistrator<ProcessingFactory, SMSPitchDiscretization> reg = metadata;
00040 }
00041
00042 bool SMSPitchDiscretization::Do(const Frame& in, Frame& out)
00043 {
00044 return Do(in.GetSpectralPeakArray(),
00045 in.GetFundamental(),
00046 in.GetSpectrum(),
00047
00048 out.GetSpectralPeakArray(),
00049 out.GetFundamental(),
00050 out.GetSpectrum()
00051 );
00052 }
00053
00054 bool SMSPitchDiscretization::Do(const SpectralPeakArray& inPeaks,
00055 const Fundamental& inFund,
00056 const Spectrum& inSpectrum,
00057 SpectralPeakArray& outPeaks,
00058 Fundamental& outFund,
00059 Spectrum& outSpectrum
00060 )
00061 {
00062 outPeaks = inPeaks;
00063 outFund = inFund;
00064 outSpectrum = inSpectrum;
00065
00066 TData pitch = inFund.GetFreq();
00067
00068 if (pitch>0)
00069 {
00070 TData log2=0.69314718f;
00071
00072 int nst = Round(12*log(pitch/55)/log2);
00073 TData pow2_1_12=1.0594630f;
00074 TData discPitch=55*(CLAM_pow(pow2_1_12,nst));
00075
00076 TData amount=discPitch/pitch;
00077
00078 SendFloatToInControl(mPitchShift,"PitchSteps",amount);
00079 mPitchShift.Do( inPeaks,
00080 inFund,
00081 inSpectrum,
00082 outPeaks,
00083 outFund,
00084 outSpectrum);
00085
00086 Fundamental tmpFund;
00087 tmpFund.AddElem(discPitch);
00088 outFund = tmpFund;
00089 }
00090 return true;
00091 }
00092
00093
00094 }