CLAM-Development  1.4.0
SMSGenderChange.cxx
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG)
3  * UNIVERSITAT POMPEU FABRA
4  *
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  */
21 
22 #include "SMSGenderChange.hxx"
23 #include "ProcessingFactory.hxx"
24 
25 namespace CLAM
26 {
27 
28 namespace Hidden
29 {
30  static const char * metadata[] = {
31  "key", "SMSGenderChange",
32  "category", "SMS Transformations",
33  "description", "SMSGenderChange",
34  0
35  };
36  static FactoryRegistrator<ProcessingFactory, SMSGenderChange> reg = metadata;
37 }
38 
40  const Fundamental& inFund,
41  const Spectrum& inSpectrum,
42  SpectralPeakArray& outPeaks,
43  Fundamental& outFund,
44  Spectrum& outSpectrum)
45 {
46 
47  //we only transform voiced frames
48  if(!inFund.GetFreq(0))
49  {
50  outFund = inFund;
51  outSpectrum = inSpectrum;
52  outPeaks = inPeaks;
53  return true;
54  }
55  TData minPitch = 100;
56  TData maxPitch = 800;
57 
58  //Maximum spectral shift
59  TData maxSss = 200;
60 
61  //amount for spectral shape shift
62  TData sssAmount;
63 
64  TData pitch = inFund.GetFreq(0);
65 
66  if(pitch<minPitch) sssAmount = 0;
67  else if (pitch>maxPitch) sssAmount = maxSss;
68  else sssAmount = (pitch-minPitch) / ( (maxPitch-minPitch)/maxSss);
69  TData pitchTransposition=2;
70 
71  bool femaleToMale = mControl.GetLastValue()>0;
72  if(femaleToMale)
73  {
74  // Invert the transformations
75  sssAmount = -sssAmount;
76  pitchTransposition=1/pitchTransposition;
77  }
78 
79  SendFloatToInControl(mSpectralShapeShift,"Shift Steps",sssAmount);
80  SendFloatToInControl(mPitchShift,"PitchSteps",pitchTransposition);
81 
82  SpectralPeakArray tmpSpectralPeaks;
83  mSpectralShapeShift.Do(inPeaks,tmpSpectralPeaks);
84  mPitchShift.Do( tmpSpectralPeaks, inFund, inSpectrum,
85  outPeaks, outFund, outSpectrum);
86  return true;
87 }
88 
89 bool SMSGenderChange::Do(const Frame& in, Frame& out)
90 {
91  return Do( in.GetSpectralPeakArray(),
92  in.GetFundamental(),
93  in.GetResidualSpec(),
94  out.GetSpectralPeakArray(),
95  out.GetFundamental(),
96  out.GetResidualSpec()
97  );
98 
99 }
100 
101 
102 }
103