From 69c35fae99f9e4906fb2945eb32dd43cb4459694 Mon Sep 17 00:00:00 2001 From: van Date: Wed, 17 Apr 2024 20:28:17 +0800 Subject: [PATCH] Add f0-synthesized algorithm. --- src/util/flux_util.c | 58 ++++++++++++++++++++++++++++++++++++++++++++ src/util/flux_util.h | 3 +++ 2 files changed, 61 insertions(+) diff --git a/src/util/flux_util.c b/src/util/flux_util.c index eec6ab8..d44157a 100644 --- a/src/util/flux_util.c +++ b/src/util/flux_util.c @@ -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