SMSGenderChange.cxx

Go to the documentation of this file.
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 "SMSGenderChange.hxx"
00023 #include "ProcessingFactory.hxx"
00024 
00025 namespace CLAM
00026 {
00027 
00028 namespace Hidden
00029 {
00030         static const char * metadata[] = {
00031                 "key", "SMSGenderChange",
00032                 "category", "SMS Transformations",
00033                 "description", "SMSGenderChange",
00034                 0
00035         };
00036         static FactoryRegistrator<ProcessingFactory, SMSGenderChange> reg = metadata;
00037 }
00038 
00039 bool SMSGenderChange::Do(const SpectralPeakArray& inPeaks, 
00040                                 const Fundamental& inFund,
00041                                 const Spectrum& inSpectrum, 
00042                                 SpectralPeakArray& outPeaks,
00043                                 Fundamental& outFund,
00044                                 Spectrum& outSpectrum)
00045 {
00046 
00047         //we only transform voiced frames
00048         if(!inFund.GetFreq(0))
00049         {
00050                 outFund = inFund;
00051                 outSpectrum = inSpectrum;
00052                 outPeaks = inPeaks;
00053                 return true;
00054         }
00055         TData minPitch = 100;
00056         TData maxPitch = 800;
00057 
00058         //Maximum spectral shift
00059         TData maxSss = 200;
00060 
00061         //amount for spectral shape shift
00062         TData sssAmount;
00063 
00064         TData pitch = inFund.GetFreq(0);
00065 
00066         if(pitch<minPitch) sssAmount = 0;
00067         else if (pitch>maxPitch) sssAmount = maxSss;
00068         else sssAmount = (pitch-minPitch) / ( (maxPitch-minPitch)/maxSss);
00069         TData pitchTransposition=2;
00070 
00071         bool femaleToMale = mControl.GetLastValue()>0;
00072         if(femaleToMale)
00073         {
00074                 // Invert the transformations
00075                 sssAmount = -sssAmount;
00076                 pitchTransposition=1/pitchTransposition;
00077         }
00078 
00079         SendFloatToInControl(mSpectralShapeShift,"Shift Steps",sssAmount);
00080         SendFloatToInControl(mPitchShift,"PitchSteps",pitchTransposition);
00081 
00082         SpectralPeakArray tmpSpectralPeaks;
00083         mSpectralShapeShift.Do(inPeaks,tmpSpectralPeaks);
00084         mPitchShift.Do( tmpSpectralPeaks, inFund, inSpectrum, 
00085                         outPeaks, outFund, outSpectrum);
00086         return true;
00087 }
00088 
00089 bool SMSGenderChange::Do(const Frame& in, Frame& out)
00090 {
00091         return Do( in.GetSpectralPeakArray(),
00092                                 in.GetFundamental(), 
00093                                 in.GetResidualSpec(), 
00094                                 out.GetSpectralPeakArray(),
00095                                 out.GetFundamental(), 
00096                                 out.GetResidualSpec() 
00097                                 );
00098 
00099 }
00100 
00101 
00102 }
00103 
Generated by  doxygen 1.6.3