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 "FreqShift.hxx" 00023 #include "ProcessingFactory.hxx" 00024 00025 namespace CLAM 00026 { 00027 00028 namespace Hidden 00029 { 00030 static const char * metadata[] = { 00031 "key", "FreqShift", 00032 // "category", "Spectral Transformations", 00033 // "description", "FreqShift", 00034 0 00035 }; 00036 static FactoryRegistrator<ProcessingFactory, FreqShift> reg = metadata; 00037 } 00038 00039 00040 bool FreqShift::Do(const Spectrum& in, Spectrum& out) 00041 { 00042 00043 if ( !mConfig.GetPreserveOuts() ) 00044 { 00045 out = in; //TODO big cludge for streaming 00046 } 00047 00048 //xamat: todo, we just hope the spectrum is in mag/phase format 00049 DataArray& iMagArray = in.GetMagBuffer(); 00050 DataArray& iPhaseArray = in.GetPhaseBuffer(); 00051 TSize spectrumSize = in.GetSize(); 00052 //I need to keep a copy of the magnitude array to guarantee inplace processing is possible 00053 mOMagArray.Resize(spectrumSize); 00054 mOMagArray.SetSize(spectrumSize); 00055 mOPhaseArray.Resize(spectrumSize); 00056 mOPhaseArray.SetSize(spectrumSize); 00057 00058 //actually this is one over the spectral resolution, but it will be better for what I need afterwords 00059 TData spectralResolution = spectrumSize/in.GetSpectralRange(); 00060 int amount = Round(mShiftAmount.GetLastValue() * spectralResolution); 00061 00062 for(int i = 0; i<spectrumSize; i++) 00063 { 00064 if(i<amount) 00065 { 00066 mOMagArray[i] = 0; 00067 mOPhaseArray[i] = 0; 00068 } 00069 else if(i>spectrumSize+amount) 00070 { 00071 mOMagArray[i] = 0; 00072 mOPhaseArray[i] = 0; 00073 } 00074 else 00075 { 00076 mOMagArray[i] = iMagArray[i-amount]; 00077 mOPhaseArray[i] = iPhaseArray[i-amount]; 00078 } 00079 } 00080 out.SetMagBuffer(mOMagArray); 00081 out.SetPhaseBuffer(mOPhaseArray); 00082 return true; 00083 } 00084 00085 00086 } 00087