libAudioFlux / audioFlux

A library for audio and music analysis, feature extraction.
https://audioflux.top
MIT License
2.76k stars 118 forks source link

How can i extract logmel spec using audioFlux in total C++ code #26

Open SteveTanggithub opened 1 year ago

wtq2255 commented 1 year ago

@SteveTanggithub Hi, You can refer to the following code:

int main(int argc, char const *argv[]){
    SpectrogramObj spec=NULL;

    int status=0;

    int num=0;

    int samplate=32000;

    float lowFre=0;
    float highFre=16000;

    float *mDataArr=NULL;
    float *mDataArr2=NULL;

    int radix2Exp=12; // stft 4096
    WindowType windowType=Window_Hann;
    int slideLength=(1<<radix2Exp)/4;
    int isContinue=0;

    SpectralDataType dataType=SpectralData_Power;
    SpectralFilterBankScaleType filterBankType;
    SpectralFilterBankStyleType filterBankStyle;
    SpectralFilterBankNormalType filterNormalType;
    filterBankType=SpectralFilterBankScale_Mel;
    filterBankStyle=SpectralFilterBankStyle_Slaney;
    filterNormalType=SpectralFilterBankNormal_None;

    num=128;
    status=spectrogramObj_new(&spec,num,
                &samplate,&lowFre,&highFre,NULL,
                &radix2Exp,NULL,NULL,&isContinue,
                &dataType,&filterBankType,&filterBankStyle,&filterNormalType);

    timeLength=spectrogramObj_calTimeLength(spec,dataLength);
    mDataArr=__vnew(timeLength*num, NULL);
    mDataArr2=__vnew(timeLength*num, NULL);
    spectrogramObj_spectrogram(spec,dataArr,dataLength,mDataArr,NULL);
    util_powerToDB(mDataArr, timeLength*num, -80, mDataArr2);
}