Skip to content

Commit

Permalink
Update flux_util.
Browse files Browse the repository at this point in the history
  • Loading branch information
liufeigit committed Dec 11, 2023
1 parent 1b10379 commit 2290dd4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/util/flux_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,41 @@ void util_log10Compress(float *vArr1,float *gamma,int length,float *vArr2){
__vlog10_compress(vArr1, gamma,NULL, length, vArr2);
}

// temproal, return maxDb, percent is < -base
float util_temproal(float *dataArr,int length,float base,float *avgValue,float *percentValue){
float max=-100;

int count=0;
float value=0;
float total=0;

if(!dataArr||!length){
return 0;
}

for(int i=0;i<length;i++){
value=20*log10f(fabsf(dataArr[i])+1e-8);
if(value<-36){
value=-36;
}

if(max<value){
max=value;
}

total+=value;

if(value>-base){
count++;
}
}

*avgValue=total/length;
*percentValue=1.0*(length-count)/length;

return max;
}

/***
x=1 1
0<x<1
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 @@ -54,6 +54,9 @@ void util_magToAbsDB(float *pArr,int length,int fftLength,int isNorm,float min,f
void util_logCompress(float *vArr1,float *gamma,int length,float *vArr2);
void util_log10Compress(float *vArr1,float *gamma,int length,float *vArr2);

// temproal, return maxDb, percent is < -base
float util_temproal(float *dataArr,int length,float base,float *avgDb,float *percent);

// gamma eps=1e-5
float util_gamma(float x,float *eps);
long double util_gammal(long double x,long double *eps);
Expand Down

0 comments on commit 2290dd4

Please sign in to comment.