Skip to content

Commit

Permalink
Add f0-synthesized algorithm.
Browse files Browse the repository at this point in the history
  • Loading branch information
liufeigit committed Apr 17, 2024
1 parent 4d91906 commit 69c35fa
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
58 changes: 58 additions & 0 deletions src/util/flux_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,64 @@ void util_preEmphasis(float *vArr1,int length,float coef,float *vArr2){
}
}

// synthesized f0; length1=floor(time*fs), ampArr can NULL, default is 1
float *util_synthF0(float *timeArr,float *freArr,int length,int samplate,float *ampArr){
float *fArr=NULL;
float *tArr=NULL;

float *fArr1=NULL;
float *tArr1=NULL;
float *aArr1=NULL;

float *dataArr=NULL;

int length1=0;

float cum=0;

length1=floorf(timeArr[length-1]*samplate);

fArr=__vnew(length, NULL);
tArr=__vnew(length, NULL);

__vmul_value(timeArr, samplate, length, tArr);
__vmul_value(freArr, 2*M_PI/samplate, length, fArr);

fArr1=__vnew(length1, NULL);
__varange(0, length1, 1, &tArr1);

__vinterp_linear(tArr,fArr,length,tArr1,length1,fArr1);

aArr1=__vnew(length1, NULL);
if(ampArr){
__vinterp_linear(tArr,ampArr,length,tArr1,length1,aArr1);
}
else{
for(int i=0;i<length1;i++){
aArr1[i]=1;
}
}

// synth wave
dataArr=__vnew(length1, NULL);
for(int i=0;i<length1;i++){
cum+=fArr1[i];
dataArr[i]=cum;
}

__vsin(dataArr, length1, NULL);
__vmul(dataArr, aArr1, length1, NULL);

free(fArr);
free(tArr);

free(fArr1);
free(tArr1);
free(aArr1);

return dataArr;
}

int util_readWave(char *name,float **dataArr){
int status=0;
WaveReadObj waveRead=NULL;
Expand Down
3 changes: 3 additions & 0 deletions src/util/flux_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ void util_delta(float *dataArr1,int length,int order,float *dataArr2);
// pre_emphasis; coef 0.97
void util_preEmphasis(float *vArr1,int length,float coef,float *vArr2);

// synthesized f0; length1=floor(time*fs), ampArr can NULL, default is 1
float *util_synthF0(float *timeArr,float *freArr,int samplate,int length,float *ampArr);

// wave
int util_readWave(char *name,float **dataArr);
void util_writeWave(char *name,float *dataArr,int length);
Expand Down

0 comments on commit 69c35fa

Please sign in to comment.