Created
December 28, 2018 10:55
-
-
Save mazzzystar/784920637a6b2ef2110fc9fac68ab605 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* smooth and normalize the input pitch vector */ | |
void SProcessQuery(float* fPitchArray,int& Len){ | |
int i; | |
float MeanVal; | |
for (i=1;i<Len-1;i++){ | |
if (fPitchArray[i-1]<2 && fPitchArray[i]>2 && fPitchArray[i+1]<2) | |
fPitchArray[i]=0; | |
} | |
int nCountFrm=0; | |
for (i=0;i<Len-5;i++){ | |
if (i%5==0){ | |
fPitchArray[i/5]=GetMean(fPitchArray+i,5); | |
nCountFrm++; | |
} | |
} | |
Len=nCountFrm; | |
float LastVal=0.0; | |
for (i=1;i<Len-1;i++){ | |
if (fPitchArray[i-1]<2 && fabs(fPitchArray[i]-LastVal)>0.3*LastVal && fPitchArray[i+1]<2) | |
fPitchArray[i]=0; | |
if (fPitchArray[i]>2) | |
LastVal=fPitchArray[i]; | |
} | |
/* remove the silence frame*/ | |
float temppitch=0; | |
int vadCount=0; | |
int nStartTag=0; | |
int nStart=0; | |
for (i=0;i<Len;i++){ | |
if(nStartTag==0){ | |
if(fPitchArray[i]<2) | |
nStart=i; | |
else | |
nStartTag=1; | |
} | |
if (fPitchArray[i]>2){ | |
fPitchArray[i]=(float)(log10(fPitchArray[i])/log10(2.0f)); | |
if(i>3) | |
temppitch=GetMean(fPitchArray+i-3,3); | |
else | |
temppitch=fPitchArray[i]; | |
vadCount=0; | |
}else{ | |
vadCount++; | |
if (temppitch>0) | |
fPitchArray[i]=temppitch; | |
} | |
} | |
for(i=0;i<Len-nStart-1;i++){ | |
fPitchArray[i]=fPitchArray[i+nStart+1]; | |
} | |
Len-=(nStart+1); | |
MeanVal=0; | |
int VadSize=0; | |
for (i=0;i<Len;i++){ | |
if (fPitchArray[i]>6.3){ | |
MeanVal+=fPitchArray[i]; | |
VadSize++; | |
} | |
} | |
float me=0.0f; | |
if(VadSize<1){ | |
Len=0; | |
return ; | |
} | |
else | |
me=MeanVal/VadSize; | |
for (i=0; i<Len; i++){ | |
fPitchArray[i]=fPitchArray[i]-me+PITCH_NORMALIZE_VALUE; | |
if (fPitchArray[i]>8) | |
fPitchArray[i]=fPitchArray[i]-1; | |
if (fPitchArray[i]<6.35) | |
fPitchArray[i]=fPitchArray[i]+1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment