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 #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 }