SMSGenderChange.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 "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
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
00059 TData maxSss = 200;
00060
00061
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
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