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 "SegmentSMSHarmonizer.hxx" 00023 #include "ProcessingFactory.hxx" 00024 00025 namespace CLAM 00026 { 00027 00028 namespace Hidden 00029 { 00030 static const char * metadata[] = { 00031 "key", "SegmentSMSHarmonizer", 00032 // "category", "SMS Transformations", 00033 "description", "SegmentSMSHarmonizer", 00034 0 00035 }; 00036 static FactoryRegistrator<ProcessingFactory, SegmentSMSHarmonizer> reg = metadata; 00037 } 00038 00039 bool SegmentSMSHarmonizer::Do(const Frame& in, Frame& out) 00040 { 00041 BPF& voices=mConfig.GetBPF(); 00042 TSize nVoices=voices.Size(); 00043 00044 for(int i=0;i<nVoices;i++) 00045 { 00046 TData amount=voices.GetValueFromIndex(i); 00047 TData gain=voices.GetXValue(i); 00048 SendFloatToInControl(mPitchShift,"PitchSteps",amount); 00049 mPitchShift.Do(in,mTmpFrame); 00050 Gain(mTmpFrame,gain); 00051 AddFrame(mTmpFrame,out,out); 00052 } 00053 00054 //We set fundamental value of input to zero as it is inharmonic 00055 out.SetFundamental(mTmpFund); 00056 return true; 00057 } 00058 00059 void SegmentSMSHarmonizer::AddFrame(const Frame& in1, const Frame& in2, Frame& out) 00060 { 00061 if(mIgnoreResidualCtl.GetLastValue()<0.01) // is 0 00062 { 00063 mSpectrumAdder.Start(); 00064 mSpectrumAdder.Do(in1.GetResidualSpec(),in2.GetResidualSpec(),out.GetResidualSpec()); 00065 mSpectrumAdder.Stop(); 00066 } 00067 out.SetSpectralPeakArray(in1.GetSpectralPeakArray()+in2.GetSpectralPeakArray()); 00068 } 00069 00070 void SegmentSMSHarmonizer::Gain(Frame& inputFrame, TData gain) 00071 { 00072 SpectralPeakArray& peaks=inputFrame.GetSpectralPeakArray(); 00073 Spectrum& residual=inputFrame.GetResidualSpec(); 00074 DataArray& peakMag=peaks.GetMagBuffer(); 00075 int nPeaks=peaks.GetnPeaks(); 00076 int specSize=residual.GetSize(); 00077 //TODO check whether spectrum is in dB or not 00078 TData linGain=Lin(gain); 00079 00080 for(int i=0;i<nPeaks;i++) 00081 { 00082 peakMag[i]=std::min(peakMag[i]+gain,TData(0)); 00083 } 00084 if(mIgnoreResidualCtl.GetLastValue()<0.01) // is 0 00085 { 00086 DataArray& resMag = residual.GetMagBuffer(); 00087 for(int i=0;i<specSize;i++) 00088 { 00089 resMag[i] = resMag[i]*linGain; 00090 } 00091 } 00092 } 00093 00094 00095 } 00096