Main Page   Compound List   File List   Compound Members   File Members   Related Pages  

util.h File Reference

#include <iostream.h>
#include <istream.h>
#include <string>
#include <cstdlib>
#include <fstream.h>
#include <vector.h>
#include <string.h>
#include <strstream.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>

Include dependency graph for util.h:

Include dependency graph

This graph shows which files directly or indirectly include this file:

Included by dependency graph

Go to the source code of this file.

Compounds

struct  globalsT

Defines

#define LINEAR   1
 
See also:
phrase::addWave().


#define EXPONENTIAL   2
 
See also:
phrase::addWave().


#define LOGARITHMIC   3
 
See also:
phrase::addWave().


#define SYLLABLE_BASED   4
 
See also:
phrase::addWave().



Typedefs

typedef unsigned int uint
 just a shortcut.


Enumerations

enum  CONTOUR_TYPE {
  straight,
  rise,
  fall
}
 contour types for intonation over syllable or phrase. More...


Functions

double mean (const vector<uint>& vec)
 returns artihmetic mean of <vec>. More...

void changeMean (vector<uint>& Vals, uint rate)
 sets elems of vec to the percentage of rate. More...

void smoothe (vector<uint>& Vals, uint winsize)
 a F0-smoothing function. More...

void changeContrast (vector<uint>& Vals, short rate, double mean)
 Expands or compresses valus around a mean value. More...

void interpolateLinear (vector<uint>&, uint start, uint end)
 changes elems of vec to the linear interpolated values between start and end. More...

vector<uintinterpolateLinear (uint length, uint start, uint end)
 returns vec with size length as the linear interpolated values between start and end. More...

double ST2Hz (uint freq, double semiTone)
 returns frequency, that is <semiTone> away from <freq>. More...

double Hz2ST (uint freq1, uint freq2)
 returns distance between freq1 and freq2 in Semitones. More...

double gradient2Hz (uint freq, uint time, double gradient)
 returns frequency, that is <gradient> (in ST/sec) away from <freq> after <time> (in msec) the following formula is used: ST(f1,f2) = 12/ln(2) * ln(f1/f2). More...

uint checkMaxF0 (uint freq)
 returns MaxF0 if <freq> > MaxF0, else <freq>. More...

uint checkMaxF1 (uint freq)
 returns MaxF1 if <freq> > MaxF1, else <freq>. More...

uint checkMaxF2 (uint freq)
 returns MaxF2 if <freq> > MaxF2, else <freq>. More...

uint checkMaxF3 (uint freq)
 returns MaxF3 if <freq> > MaxF3, else <freq>. More...

uint checkMaxF4 (uint freq)
 returns MaxF4 if <freq> > MaxF4, else <freq>. More...

uint checkMaxF5 (uint freq)
 returns MaxF5 if <freq> > MaxF5, else <freq>. More...

uint checkMinF0 (uint freq)
 returns MinF0 if <freq> < MinF0, else <freq>. More...

uint checkMinF1 (uint freq)
 returns MinF1 if <freq> < MinF1, else <freq>. More...

uint checkMinF2 (uint freq)
 returns MinF2 if <freq> < MinF2, else <freq>. More...

uint checkMinF3 (uint freq)
uint checkMinF4 (uint freq)
 returns MinF4 if <freq> < MinF4, else <freq>. More...

uint checkMinF5 (uint freq)
 returns MinF5 if <freq> < MinF5, else <freq>. More...

void addJitterVec (vector<uint>& vals, uint rate)
 All nonzero elements of vector get alternating subtracted or added their percentage with rate. More...

void error (string msg, int errNo)
 prints <msg> to stderr and exits program with <errNo>. More...

void warn (string msg)
 prints <msg> to stderr. More...

void printVec (vector<uint> vec)
 prints elems of vec to stdout, seperated by tabs. More...

void printVec (vector<int> vec)
 prints elems of vec to stdout, seperated by tabs. More...

vector<uintsubVec (vector<uint> vec, uint start, uint end)
 returns part of <vec> from index <start> to <end> (inclusive). More...

vector<uintmodelTrack (string name, uint valNum, vector<uint> f0ValVec, vector<uint> f0TimeVec)
 models F0-contour of phone name from mbrola-style f0-description. More...

vector<int> modelTrack (string name, uint valNum, vector<int> f0ValVec, vector<uint> f0TimeVec)
 models F0-contour of phone name from mbrola-style f0-description. More...

vector<int> change_valNum (string name, uint valNum, uint left, uint right, vector<int> orig)
 resizes vector orig (of ints) to length valNum. More...

vector<uintchange_valNum (string name, uint valNum, uint left, uint right, vector<uint> orig)
 resizes vector orig (of uints) to length valNum. More...

vector<uintchange_valNum_stop (string name, uint valNum, uint left, uint right, vector<uint> orig)
 resizes vector orig (of uints) to length valNum. More...

vector<string> string2vec (string buffer)
 returns substrings of buffer seperated by whitespace as vector. More...

uint msec2frames (uint dur, globalsT glob)
 returns framenumbers from msec. More...

uint calcNewDur (uint dur, int rate, globalsT glob)
 returns framenumbers as fraction of dur determined by rate. More...

uint F12BW (uint f1)
 returns Bandwidth of F1 as parabolic function of F1. More...


Variables

const uint A_HIGH_INT = 100000
 used for initialization.

const uint maxVal = 10000
 used for error checking.

const uint MAX_DBVAL = 60
 all dB vals should be normaized to 60 dB.

const uint maxF0 = 5000
 max meaningful val for f0 in 10th of hertz.

const uint minF0 = 500
 min meaningful val for f0 in 10th of hertz.

const uint maxF1 = 1000
 max meaningful val for f1 in hertz.

const uint minF1 = 200
 min meaningful val for f1 in hertz.

const uint maxF2 = 2500
 max meaningful val for f2 in hertz.

const uint minF2 = 500
 min meaningful val for f2 in hertz.

const uint maxF3 = 3800
 max meaningful val for f3 in hertz.

const uint minF3 = 2100
 min meaningful val for f3 in hertz.

const uint maxF4 = 4500
 max meaningful val for f4 in hertz.

const uint minF4 = 3000
 min meaningful val for f4 in hertz.

const uint maxF5 = 5000
 max meaningful val for f5 in hertz.

const uint minF5 = 3500
 min meaningful val for f5 in hertz.

const uint jumpTolerance = 50
 value for warning if freq-jump while concatenating formant-tracks is higher.

const uint minOq = 10
 min meaningful oq.

const uint minB1 = 30
 min meaningful b1.

const uint minB2 = 30
 min meaningful b2.

const uint minB3 = 30
 min meaningful b3.

const uint minB4 = 40
 min meaningful b4.

const uint minB5 = 45
 min meaningful b5.

const uint minB6 = 50
 min meaningful b6.

const uint minBnp = 30
 min meaningful bnp.

const uint minBtp = 30
 min meaningful btp.

const uint MIN_SPEECHRATE = 70
 min meaningful change in speechrate.

const uint MAX_SPEECHRATE = 150
 max meaningful change in speechrate.


Define Documentation

#define EXPONENTIAL   2
 

See also:
phrase::addWave().

#define LINEAR   1
 

See also:
phrase::addWave().

#define LOGARITHMIC   3
 

See also:
phrase::addWave().

#define SYLLABLE_BASED   4
 

See also:
phrase::addWave().


Typedef Documentation

typedef unsigned int uint
 

just a shortcut.


Enumeration Type Documentation

enum CONTOUR_TYPE
 

contour types for intonation over syllable or phrase.

Enumeration values:
straight  
rise   0=straight.
fall   1=rise.
00118              {
00119   straight, 
00120   rise, 
00121   fall, 
00122 }


Function Documentation

uint F12BW ( uint f1 )
 

returns Bandwidth of F1 as parabolic function of F1.

It's implmented, but I didn't hear a difference. data comes from: author = {Fujimura, O. and Lindqvist, J. }, title = {Sweep-Tone Measurements of Vocal-Tract Characteristics}, journal = JASA, year = {1971}, volume = {49}, number = {2}, pages = {541-558},

Parameters:
uint   f1
Returns:
uint bw1
00567                     {
00568   // parameters of parabel describing BW1 as Function of F1
00569   double a=0.0004094,
00570     b=-0.44975,
00571     c=153.575;
00572   if (f1>maxF1 || f1<minF1) {
00573     cerr<<"WARNING: F12BW: unlikely F1 value: "<<f1<<" yields weired BW1 value\n";
00574   }
00575   return (uint) ((double)f1*(double)f1*a + (double)f1*b + c);
00576 }

double Hz2ST ( uint freq1,
uint freq2 )
 

returns distance between freq1 and freq2 in Semitones.

the following formula is used: ST(f1,f2) = 12/ln(2) * ln(f1/f2)

Parameters:
uint   freq1
uint   freq2
Returns:
double
00217                                       {
00218   double result;
00219   // ST(f1,f2) = 12/ln(2) * ln(f1/f2)
00220   const double _12_LN2 = 17.31234;
00221   result = _12_LN2 * log((double)freq1/(double)freq2);
00222   return result>0?result:-result;
00223 }

double ST2Hz ( uint freq,
double semiTone )
 

returns frequency, that is <semiTone> away from <freq>.

the following formula is used: ST(f1,f2) = 12/ln(2) * ln(f1/f2)

Parameters:
uint   freq
double   semitone
Returns:
double
00208                                           {
00209   // ST(f1,f2) = 12/ln(2) * ln(f1/f2)
00210   const double _12_LN2 = 17.31234;
00211   double Exp;
00212   Exp = semiTone/_12_LN2;
00213   return exp(Exp) * freq;
00214 }

void addJitterVec ( vector< uint >& vals,
uint rate )
 

All nonzero elements of vector get alternating subtracted or added their percentage with rate.

Used for Jitter simulation. However, there's a more sophisticated Jittersimulation already implmented in the klatt-formantsynthesizer (param FL (sensyn) or skew (s&i)).

Parameters:
vector   <uint>& vals
uint   rate
00125                                                  {
00126   for (uint i=0; i < vals.size(); i++) {
00127     if (vals[i] != 0) {
00128       if (i%2==0)
00129         vals[i] = checkMaxF0(vals[i] + (uint) (vals[i] * (rate/100.0)));
00130       else
00131         vals[i] = checkMinF0(vals[i] - (uint) (vals[i] * (rate/100.0)));
00132       // cout <<  (vals[i] * (rate/100.0)) << " ";
00133     }
00134   }
00135 }

uint calcNewDur ( uint dur,
int rate,
globalsT glob )
 

returns framenumbers as fraction of dur determined by rate.

framesize is taken from glob.ui.

Parameters:
uint   dur(in mesec)
uint   rate (in percent)
globalsT   glob
Returns:
uint framenumber
00552                                                    {
00553   uint newDur;
00554   
00555   newDur = dur*rate/100;
00556   uint middle = glob.ui/2+1;
00557 
00558   if (newDur % glob.ui==0)
00559     return newDur;
00560   else if (newDur % glob.ui < middle)
00561     return newDur - newDur % glob.ui;
00562   else 
00563     return newDur+(glob.ui - newDur % glob.ui);
00564 }

void changeContrast ( vector< uint >& Vals,
short rate,
double mean )
 

Expands or compresses valus around a mean value.

Depending whether elem of <Vals> is higher or lower then <mean> it gets added or subtracted the percentage of <rate> and distance to <mean>

Parameters:
vector<uint>   & Vals
short   rate
double   mean
00136                                                                  {
00137   uint newVal;
00138   double Rate = (rate-100) / 100.0;
00139   for (uint i=0; i < vals.size(); i++) {
00140     // distance between pitchVal and Mean in %
00141     if (vals[i] != 0) {
00142       double dist = (double)  vals[i]-mean;             // (vals[i] * 100.0 / mean - 100);
00143       if (Rate > 0) { // enhance range
00144         
00145         if (vals[i] > mean) {
00146           vals[i] = checkMaxF0(vals[i] + (uint)(dist * Rate));
00147         } else {
00148           vals[i] = checkMinF0(vals[i] + (uint)(dist * Rate));
00149         }
00150       } else {        // reduce range 
00151         if (vals[i] > mean) {
00152           if ((newVal = vals[i] + (uint)(dist * Rate)) < mean)
00153             vals[i] = (uint) mean;
00154           else
00155             vals[i] = newVal;
00156         } else {
00157           if ((newVal = vals[i] + (uint)(dist * Rate)) > mean)
00158             vals[i] = (uint) mean;
00159           else
00160             vals[i] = newVal;      
00161         }  
00162       }
00163     }
00164   }
00165 }

void changeMean ( vector< uint >& Vals,
uint rate )
 

sets elems of vec to the percentage of rate.

Parameters:
vec  
rate  
00098                                                {
00099   double changeFac = (double)rate/100.0;
00100   //cout << changeFac<<"\n";
00101   for (uint i=0; i < vals.size(); i++) {
00102     if (vals[i]!= 0) {
00103       //cout << vals[i]<<" ";
00104       vals[i] = checkMinF0(checkMaxF0( (uint) ((double)vals[i] * changeFac) ));
00105       // cout <<(double)vals[i] * changeFac <<" ";
00106     }
00107     //  cout << vals[i]<<" ";
00108   }
00109 }

vector< uint > change_valNum<uint> ( string name,
uint valNum,
uint left,
uint right,
vector< uint > orig )
 

resizes vector orig (of uints) to length valNum.

For shortening, frames are deleted around the middle between left and right. If those borders are overshot, a warning is delivered (containing name). For lengthening, the middle frame between left and right is repeated.

Parameters:
string   name
uint   valNum
uint   leftBorder
uint   reightBorder
vector   <uint> origVec
Returns:
vector<uint>
00439                                                                                                               { 
00440   int frameDiffNum;
00441   uint midFrame;
00442   vector<uint> returnVec(0);
00443   
00444   frameDiffNum = origVec.size() - valNum;
00445   //  cout <<   origVec.size() << "\n";
00446   // cout << name<<" "<< origVec.size() <<" "<<valNum<<" "<<frameDiffNum<< "\n";
00447   if (frameDiffNum>(int)(rightBorder-leftBorder)) {
00448     warn("dur change of phone "+name+" extends steady-state, ignoring borders!\n");
00449     midFrame =  origVec.size()/ 2;
00450   } else
00451     midFrame = rightBorder - (uint) rint((rightBorder-leftBorder) / 2);
00452   
00453   
00454   if (frameDiffNum > 0) { // delete Frames
00455     
00456     if (frameDiffNum%2==0)
00457       for (uint frame=0; frame < midFrame - (int) frameDiffNum/2; frame++) 
00458         returnVec.push_back(origVec[frame]);
00459     else
00460       for (uint frame=0; frame < midFrame - (int) frameDiffNum/2-1; frame++) 
00461         returnVec.push_back(origVec[frame]);      
00462     for (uint frame=midFrame + (int) frameDiffNum/2; 
00463          frame < origVec.size(); frame++) 
00464       returnVec.push_back(origVec[frame]);
00465 
00466   } else if  (frameDiffNum < 0) { // insert Frames
00467 
00468     for (uint frame=0; frame < midFrame; frame++) 
00469       returnVec.push_back(origVec[frame]);
00470     for (uint frame=0; frame < (uint) -frameDiffNum; frame++) 
00471       returnVec.push_back(origVec[midFrame]);
00472     for (uint frame=midFrame; frame < origVec.size(); frame++) 
00473       returnVec.push_back(origVec[frame]);
00474 
00475   } else { // no change
00476     return origVec;  
00477   }
00478   // cout << name << " "<<  origVec.size() <<" "<<valNum<<" "<<returnVec.size() << "\t";
00479   // cout <<name<<" lB:"<<leftBorder<<" rB:"<<rightBorder<< " midFr:"<<midFrame<<" frDiffNum:"<<(int) frameDiffNum<< " orgSize:"<<  origVec.size() <<" newSize:"<<valNum<<" actSize:"<<returnVec.size() <<"\n";
00480 
00481   if (returnVec.size() != valNum)
00482     error("something went wrong in change_valNum (uint) at phone: "+name+"\n", -3);
00483   return returnVec;
00484 }

vector< int > change_valNum<int> ( string name,
uint valNum,
uint left,
uint right,
vector< int > orig )
 

resizes vector orig (of ints) to length valNum.

For shortening, frames are deleted around the middle between left and right. If those borders are overshot, a warning is delivered (containing name). For lengthening, the middle frame between left and right is repeated.

Parameters:
string   name
uint   valNum
uint   leftBorder
uint   reightBorder
vector   <int> origVec
Returns:
vector<int>
00397                                                                                                             { 
00398   int frameDiffNum;
00399   uint midFrame;
00400   vector<int> returnVec(0);
00401   
00402   frameDiffNum = origVec.size() - valNum;
00403   //  cout <<   origVec.size() << "\n";
00404   // cout << name << " "<<  origVec.size() <<" "<<valNum<<" "<<frameDiffNum<< "\t";
00405   if (frameDiffNum > (int) (rightBorder-leftBorder)) {
00406     warn("dur change of phone "+name+" extends steady-state, ignoring borders!\n");
00407     midFrame =  origVec.size()/ 2;
00408   } else
00409     midFrame = rightBorder - (uint) rint((rightBorder-leftBorder) / 2);
00410   
00411   //  cout <<" "<<leftBorder<<" "<<rightBorder<< " "<<midFrame<<"\n";
00412   
00413   if (frameDiffNum > 0) { // delete Frames
00414     if (frameDiffNum%2==0)
00415       for (uint frame=0; frame < midFrame - (int) frameDiffNum/2; frame++) 
00416         returnVec.push_back(origVec[frame]);
00417     else
00418       for (uint frame=0; frame < midFrame - (int) frameDiffNum/2-1; frame++) 
00419         returnVec.push_back(origVec[frame]);      
00420     for (uint frame=midFrame + (int) frameDiffNum/2; 
00421          frame < origVec.size(); frame++) 
00422       returnVec.push_back(origVec[frame]);
00423     
00424   } else if  (frameDiffNum < 0) { // insert Frames
00425     for (uint frame=0; frame < midFrame; frame++) 
00426       returnVec.push_back(origVec[frame]);
00427     for (uint frame=0; frame < (uint) -frameDiffNum; frame++) 
00428       returnVec.push_back(origVec[midFrame]);
00429     for (uint frame=midFrame; frame < origVec.size(); frame++) 
00430       returnVec.push_back(origVec[frame]);
00431   } else { // no change
00432     return origVec;  
00433   }
00434   if (returnVec.size() != valNum)
00435     error("something went wrong in change_valNum (int) at phone: "+name+"\n", -3);
00436   return returnVec;
00437 }

vector< uint > change_valNum_stop<uint> ( string name,
uint valNum,
uint left,
uint right,
vector< uint > orig )
 

resizes vector orig (of uints) to length valNum.

This could be changed if stops should be dealt with differently than other phones. It's not used currently.

For shortening, frames are deleted around the middle between left and right. If those borders are overshot, a warning is delivered (containing name). For lengthening, the middle frame between left and right is repeated.

Parameters:
string   name
uint   valNum
uint   leftBorder
uint   reightBorder
vector   <uint> origVec
Returns:
vector<uint>
00486                                                                                                                    { 
00487   int frameDiffNum;
00488   uint midFrame;
00489   vector<uint> returnVec(0);
00490   
00491   frameDiffNum = origVec.size() - valNum;
00492   //  cout <<   origVec.size() << "\n";
00493   // cout << name<<" "<< origVec.size() <<" "<<valNum<<" "<<frameDiffNum<< "\n";
00494   if (frameDiffNum>(int)(rightBorder-leftBorder)) {
00495     warn("dur change of phone "+name+" extends steady-state, ignoring borders!\n");
00496     midFrame =  origVec.size()/ 2;
00497   } else
00498     midFrame = rightBorder - (uint) rint((rightBorder-leftBorder) / 2);
00499   
00500   
00501   if (frameDiffNum > 0) { // delete Frames
00502     
00503     if (frameDiffNum%2==0)
00504       for (uint frame=0; frame < midFrame - (int) frameDiffNum/2; frame++) 
00505         returnVec.push_back(origVec[frame]);
00506     else
00507       for (uint frame=0; frame < midFrame - (int) frameDiffNum/2-1; frame++) 
00508         returnVec.push_back(origVec[frame]);      
00509     for (uint frame=midFrame + (int) frameDiffNum/2; 
00510          frame < origVec.size(); frame++) 
00511       returnVec.push_back(origVec[frame]);
00512 
00513   } else if  (frameDiffNum < 0) { // insert Frames
00514 
00515     for (uint frame=0; frame < midFrame; frame++) 
00516       returnVec.push_back(origVec[frame]);
00517     for (uint frame=0; frame < (uint) -frameDiffNum; frame++) 
00518       returnVec.push_back(origVec[midFrame]);
00519     for (uint frame=midFrame; frame < origVec.size(); frame++) 
00520       returnVec.push_back(origVec[frame]);
00521 
00522   } else { // no change
00523     return origVec;  
00524   }
00525   //  cout << name << " "<<  origVec.size() <<" "<<valNum<<" "<<returnVec.size() << "\t";
00526   // cout <<name<<" lB:"<<leftBorder<<" rB:"<<rightBorder<< " midFr:"<<midFrame<<" frDiffNum:"<<(int) frameDiffNum<< " orgSize:"<<  origVec.size() <<" newSize:"<<valNum<<" actSize:"<<returnVec.size() <<"\n";
00527 
00528   if (returnVec.size() != valNum)
00529     error("something went wrong in change_valNum at phone: "+name+"\n", -3);
00530   return returnVec;
00531 }

uint checkMaxF0 ( uint freq )
 

returns MaxF0 if <freq> > MaxF0, else <freq>.

Copyright (C) 2000 Felix Burkhardt

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

author's contact: felixbur@gmx.de

00025                            { 
00026   if (freq > maxF0)
00027     return maxF0;
00028   return freq;
00029 }

uint checkMaxF1 ( uint freq )
 

returns MaxF1 if <freq> > MaxF1, else <freq>.

Parameters:
uint   freq
Returns:
uint
00030                            { 
00031   if (freq > maxF1)
00032     return maxF1;
00033   return freq;
00034 }

uint checkMaxF2 ( uint freq )
 

returns MaxF2 if <freq> > MaxF2, else <freq>.

Parameters:
uint   freq
Returns:
uint
00035                            { 
00036   if (freq > maxF2)
00037     return maxF2;
00038   return freq;
00039 }

uint checkMaxF3 ( uint freq )
 

returns MaxF3 if <freq> > MaxF3, else <freq>.

Parameters:
uint   freq
Returns:
uint
00040                            { 
00041   if (freq > maxF3)
00042     return maxF3;
00043   return freq;
00044 }

uint checkMaxF4 ( uint freq )
 

returns MaxF4 if <freq> > MaxF4, else <freq>.

Parameters:
uint   freq
Returns:
uint
00045                            { 
00046   if (freq > maxF4)
00047     return maxF4;
00048   return freq;
00049 }

uint checkMaxF5 ( uint freq )
 

returns MaxF5 if <freq> > MaxF5, else <freq>.

Parameters:
uint   freq
Returns:
uint
00050                            { 
00051   if (freq > maxF5)
00052     return maxF5;
00053   return freq;
00054 }

uint checkMinF0 ( uint freq )
 

returns MinF0 if <freq> < MinF0, else <freq>.

Parameters:
uint   freq
Returns:
uint
00056                            {
00057   if (freq < minF0)
00058     return minF0;
00059   return freq;
00060 }

uint checkMinF1 ( uint freq )
 

returns MinF1 if <freq> < MinF1, else <freq>.

Parameters:
uint   freq
Returns:
uint
00061                            {
00062   if (freq < minF1)
00063     return minF1;
00064   return freq;
00065 }

uint checkMinF2 ( uint freq )
 

returns MinF2 if <freq> < MinF2, else <freq>.

Parameters:
uint   freq
Returns:
uint
00066                            {
00067   if (freq < minF2)
00068     return minF2;
00069   return freq;
00070 }

uint checkMinF3 ( uint freq )
 

00071                            {
00072   if (freq < minF3)
00073     return minF3;
00074   return freq;
00075 }

uint checkMinF4 ( uint freq )
 

returns MinF4 if <freq> < MinF4, else <freq>.

Parameters:
uint   freq
Returns:
uint
00076                            {
00077   if (freq < minF4)
00078     return minF4;
00079   return freq;
00080 }

uint checkMinF5 ( uint freq )
 

returns MinF5 if <freq> < MinF5, else <freq>.

Parameters:
uint   freq
Returns:
uint
00081                            {
00082   if (freq < minF5)
00083     return minF5;
00084   return freq;
00085 }

void error ( string msg,
int errNo )
 

prints <msg> to stderr and exits program with <errNo>.

Parameters:
string   msg
int   errNo
00234                                    {
00235   cerr << endl << "ERROR: " << msg << endl;
00236   exit(errNo);
00237 }

double gradient2Hz ( uint freq,
uint time,
double gradient )
 

returns frequency, that is <gradient> (in ST/sec) away from <freq> after <time> (in msec) the following formula is used: ST(f1,f2) = 12/ln(2) * ln(f1/f2).

Parameters:
uint   freq
uint   time
uint   gradient
Returns:
double
00226                                                            {
00227   const double _12_LN2 = 17.31234;
00228   double Exp;
00229   double semiTone = (time*0.001)*gradient;
00230   Exp = semiTone/_12_LN2;
00231   return exp(Exp) * freq;
00232 }

vector< uint > interpolateLinear<uint> ( uint length,
uint start,
uint end )
 

returns vec with size length as the linear interpolated values between start and end.

Returns:
vector<uint>& resultVec
Parameters:
uint   length
uint   start
uint   end
00188                                                                    {
00189   double step;
00190   vector <uint> resultVec(0);
00191   
00192   if (start < end) {
00193     step = (double)(end-start) / (double) length;
00194     for (uint i=0; i < length; i++) {
00195       resultVec.push_back(start + (uint) (i * step));
00196     }
00197   } else if (start > end) {
00198     step = (double)(start-end) / (double) length;
00199     for (uint i=0; i < length; i++)
00200       resultVec.push_back(start - (uint)(i * step));
00201   } else
00202     for (uint i=0; i < length; i++)
00203       resultVec.push_back(start);
00204   return resultVec;
00205 }

void interpolateLinear ( vector< uint >& vec,
uint start,
uint end )
 

changes elems of vec to the linear interpolated values between start and end.

Parameters:
vector   <uint>& resultVec
uint   start
uint   end
00166                                                                 {
00167   double step;
00168   short length = vec.size();
00169  
00170   if (start < end) {
00171     step = (double)(end-start) / (double) length;
00172     for (short i=0; i < length; i++) {
00173       if (vec[i] != 0) {
00174         vec[i] = checkMaxF0(start + (uint) (i * step));
00175         // cout << vec[i]<<" "<<step<<"\n";
00176       }
00177     }
00178   } else if (start > end) {
00179     step = (double)(start-end) / (double) length;
00180     for (short i=0; i < length; i++)
00181       if (vec[i] != 0)
00182         vec[i] = checkMinF0(start - (uint)(i * step));
00183   } else
00184     for (short i=0; i < length; i++)
00185       if (vec[i] != 0)
00186         vec[i] = start;
00187 }

double mean ( const vector< uint >& vec )
 

returns artihmetic mean of <vec>.

Parameters:
const   vector<uint>& vec
Returns:
double
00087                                      {
00088   uint sum=0;
00089   
00090   for (uint i=0; i < vec.size(); i++) {
00091     sum += vec[i];
00092   }
00093   if (vec.size()>0)
00094     return sum/vec.size();
00095   else
00096     return 0;
00097 }

vector< int > modelTrack<int> ( string name,
uint valNum,
vector< int > f0ValVec,
vector< uint > f0TimeVec )
 

models F0-contour of phone name from mbrola-style f0-description.

returns f0vector as an interpolated version of f0ValVec and f0TimeVec.

Parameters:
string   name
uint   valNum
vector   <int> f0ValVec
vector   <uint> f0TimeVec
Returns:
vector<int>
00330                                                                                                {
00331   vector<int> returnVec, tmpF0TimeVec, tmpF0ValVec ; // vector with new f0Vals
00332 
00333   uint actTargetVal, nextTargetVal, start, end;
00334   double step;
00335 
00336   if (f0ValVec.size()>0 && f0TimeVec.size()>0) {
00337     if (f0TimeVec[0]!=0) {
00338       tmpF0TimeVec.push_back(0);
00339       tmpF0ValVec.push_back(f0ValVec[0]);
00340     }
00341     for (uint i=0; i< f0ValVec.size(); i++) {
00342       tmpF0TimeVec.push_back(f0TimeVec[i]);
00343       tmpF0ValVec.push_back(f0ValVec[i]);    
00344     }
00345     if (f0TimeVec[f0TimeVec.size()-1]!=100) {
00346       tmpF0TimeVec.push_back(100);
00347       tmpF0ValVec.push_back(f0ValVec[f0ValVec.size()-1]);
00348     }
00349 
00350     for (uint i=0; i<tmpF0TimeVec.size()-1; i++) {
00351       actTargetVal = (uint) rint(tmpF0TimeVec[i] * valNum * 0.01);
00352       nextTargetVal = (uint) rint(tmpF0TimeVec[i+1] * valNum * 0.01);
00353       start  = tmpF0ValVec[i];
00354       end  = tmpF0ValVec[i+1];
00355       
00356       if (actTargetVal > nextTargetVal) {
00357         error("wrong intonation description at phone:"+name+"\n", -3);
00358       }
00359       else if (actTargetVal == nextTargetVal) {
00360       } else {
00361         if (start == end) {
00362           
00363           for (uint j=actTargetVal; j < nextTargetVal; j++)
00364             returnVec.push_back(end);
00365           
00366         }
00367         else {
00368           uint len = nextTargetVal-actTargetVal;
00369           if (len==1) {
00370             returnVec.push_back(start);
00371           } else {
00372             if (start < end) {
00373               step = (end-start) / len;
00374               for (uint j=1; j <= len; j++)
00375                 returnVec.push_back(start + (uint) rint(j * step));
00376             } else if (start > end) {
00377               step = (start-end) / len;
00378               for (uint j=1; j <= len; j++)
00379                 returnVec.push_back(start - (uint) rint(j * step));
00380             }
00381           }
00382         }
00383       }
00384     }
00385   } else { // no intonation-description -> set f0Vals to zero
00386     for (uint j=0; j < valNum; j++)
00387       returnVec.push_back(0);
00388   }
00389   
00390   if (returnVec.size()!=valNum)
00391     error ("modelIntonation: uncorrect number of f0-vals at phone: "+name+"\n", -1);
00392   
00393   return returnVec;
00394   
00395 }

vector< uint > modelTrack<uint> ( string name,
uint valNum,
vector< uint > f0ValVec,
vector< uint > f0TimeVec )
 

models F0-contour of phone name from mbrola-style f0-description.

returns f0vector as an interpolated version of f0ValVec and f0TimeVec.

Parameters:
string   name
uint   valNum
vector   <uint> f0ValVec
vector   <uint> f0TimeVec
Returns:
vector<uint>
00264                                                                                                  {
00265   vector<uint> returnVec, tmpF0TimeVec, tmpF0ValVec ; // vector with new f0Vals
00266 
00267   uint actTargetVal, nextTargetVal, start, end;
00268   double step;
00269 
00270   if (f0ValVec.size()>0 && f0TimeVec.size()>0) {
00271     if (f0TimeVec[0]!=0) {
00272       tmpF0TimeVec.push_back(0);
00273       tmpF0ValVec.push_back(f0ValVec[0]);
00274     }
00275     for (uint i=0; i< f0ValVec.size(); i++) {
00276       tmpF0TimeVec.push_back(f0TimeVec[i]);
00277       tmpF0ValVec.push_back(f0ValVec[i]);    
00278     }
00279     if (f0TimeVec[f0TimeVec.size()-1]!=100) {
00280       tmpF0TimeVec.push_back(100);
00281       tmpF0ValVec.push_back(f0ValVec[f0ValVec.size()-1]);
00282     }
00283 
00284     for (uint i=0; i<tmpF0TimeVec.size()-1; i++) {
00285       actTargetVal = (uint) rint(tmpF0TimeVec[i] * valNum * 0.01);
00286       nextTargetVal = (uint) rint(tmpF0TimeVec[i+1] * valNum * 0.01);
00287       start  = tmpF0ValVec[i];
00288       end  = tmpF0ValVec[i+1];
00289       
00290       if (actTargetVal > nextTargetVal) {
00291         error("wrong intonation description at phone:"+name+"\n", -3);
00292       }
00293       else if (actTargetVal == nextTargetVal) {
00294       } else {
00295         if (start == end) {
00296           
00297           for (uint j=actTargetVal; j < nextTargetVal; j++)
00298             returnVec.push_back(end);
00299           
00300         }
00301         else {
00302           uint len = nextTargetVal-actTargetVal;
00303           if (len==1) {
00304             returnVec.push_back(start);
00305           } else {
00306             if (start < end) {
00307               step = (end-start) / len;
00308               for (uint j=1; j <= len; j++)
00309                 returnVec.push_back(start + (uint) rint(j * step));
00310             } else if (start > end) {
00311               step = (start-end) / len;
00312               for (uint j=1; j <= len; j++)
00313                 returnVec.push_back(start - (uint) rint(j * step));
00314             }
00315           }
00316         }
00317       }
00318     }
00319   } else { // no intonation-description -> set f0Vals to zero
00320     for (uint j=0; j < valNum; j++)
00321       returnVec.push_back(0);
00322   }
00323   
00324   if (returnVec.size()!=valNum)
00325     error ("modelIntonation: uncorrect number of f0-vals at phone: "+name+"\n", -1);
00326   
00327   return returnVec;
00328   
00329 }

uint msec2frames ( uint dur,
globalsT glob )
 

returns framenumbers from msec.

framesize is taken from glob.ui.

Parameters:
uint   dur(in mesec)
globalsT   glob
Returns:
uint framenumber
00544                                           {
00545   return (uint) rint(dur/glob.ui);
00546 }

void printVec ( vector< int > vec )
 

prints elems of vec to stdout, seperated by tabs.

Parameters:
vector   <int>& vals
00248                                {
00249   for (uint i=0; i<vec.size(); i++)
00250     cout << vec[i] << "\t";
00251   cout << "\n";
00252 }

void printVec ( vector< uint > vec )
 

prints elems of vec to stdout, seperated by tabs.

Parameters:
vector   <uint>& vals
00243                                 {
00244   for (uint i=0; i<vec.size(); i++)
00245     cout << vec[i] << "\t";
00246   cout << "\n";
00247 }

void smoothe ( vector< uint >& Vals,
uint winsize )
 

a F0-smoothing function.

filters vector by replacing each elem by mean of +-winsize surrounding elems.

Parameters:
vec  
winsize  
00110                                                {
00111   uint sum;
00112   uint denom = 2*winsize+1;
00113   if (vals.size()>winsize+2)
00114     for (uint i=winsize; i < vals.size()-winsize; i++) {
00115       sum = 0;
00116       for (uint j=1; j<=winsize; j++) {
00117         sum += vals[i-j];
00118         sum += vals[i+j];
00119       }
00120       sum += vals[i];
00121       vals[i] = sum/denom;
00122     }
00123 }

vector< string > string2vec<string> ( string buffer )
 

returns substrings of buffer seperated by whitespace as vector.

Parameters:
string   buffer
Returns:
vector<string>
00533                                          {
00534   vector<string> returnVec;
00535   string token;
00536 
00537   istrstream ist(buffer.c_str());
00538   while (ist >> token)
00539     returnVec.push_back(token);
00540   
00541   return returnVec;
00542 }

vector< uint > subVec<uint> ( vector< uint > vec,
uint start,
uint end )
 

returns part of <vec> from index <start> to <end> (inclusive).

Parameters:
vector   <uint>& vals
uint   start
uint   end
Returns:
vector<uint>& vals
00254                                                             {
00255   vector<uint> returnVec;
00256   if (start<0 || start>end || end>=vec.size())
00257     error("subVec(): borders ot of range", -3);
00258   for (uint i=start; i<=end; i++)
00259     returnVec.push_back(vec[i]);
00260   return returnVec;
00261 }

void warn ( string msg )
 

prints <msg> to stderr.

Parameters:
string   msg
00239                        {
00240   cerr << "WARNING: " << msg;
00241 }


Variable Documentation

const uint A_HIGH_INT = 100000
 

used for initialization.

const uint MAX_DBVAL = 60
 

all dB vals should be normaized to 60 dB.

const uint MAX_SPEECHRATE = 150
 

max meaningful change in speechrate.

const uint MIN_SPEECHRATE = 70
 

min meaningful change in speechrate.

const uint jumpTolerance = 50
 

value for warning if freq-jump while concatenating formant-tracks is higher.

const uint maxF0 = 5000
 

max meaningful val for f0 in 10th of hertz.

const uint maxF1 = 1000
 

max meaningful val for f1 in hertz.

const uint maxF2 = 2500
 

max meaningful val for f2 in hertz.

const uint maxF3 = 3800
 

max meaningful val for f3 in hertz.

const uint maxF4 = 4500
 

max meaningful val for f4 in hertz.

const uint maxF5 = 5000
 

max meaningful val for f5 in hertz.

const uint maxVal = 10000
 

used for error checking.

const uint minB1 = 30
 

min meaningful b1.

const uint minB2 = 30
 

min meaningful b2.

const uint minB3 = 30
 

min meaningful b3.

const uint minB4 = 40
 

min meaningful b4.

const uint minB5 = 45
 

min meaningful b5.

const uint minB6 = 50
 

min meaningful b6.

const uint minBnp = 30
 

min meaningful bnp.

const uint minBtp = 30
 

min meaningful btp.

const uint minF0 = 500
 

min meaningful val for f0 in 10th of hertz.

const uint minF1 = 200
 

min meaningful val for f1 in hertz.

const uint minF2 = 500
 

min meaningful val for f2 in hertz.

const uint minF3 = 2100
 

min meaningful val for f3 in hertz.

const uint minF4 = 3000
 

min meaningful val for f4 in hertz.

const uint minF5 = 3500
 

min meaningful val for f5 in hertz.

const uint minOq = 10
 

min meaningful oq.

generated by doxygen