亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? gmm.cpp

?? Intel開發的IPP庫的應用實例
?? CPP
字號:
/*
//
//                  INTEL CORPORATION PROPRIETARY INFORMATION
//     This software is supplied under the terms of a license agreement or
//     nondisclosure agreement with Intel Corporation and may not be copied
//     or disclosed except in accordance with the terms of that agreement.
//          Copyright(c) 1999-2006 Intel Corporation. All Rights Reserved.
//
//     Intel(R) Integrated Performance Primitives Speech Processing Sample for Windows*
//
//  By downloading and installing this sample, you hereby agree that the
//  accompanying Materials are being provided to you under the terms and
//  conditions of the End User License Agreement for the Intel(R) Integrated
//  Performance Primitives product previously accepted by you. Please refer
//  to the file ippEULA.rtf located in the root directory of your Intel(R) IPP
//  product installation for more information.
//
*/

//---------------------------------------------------------------------
//                  GMM training class
//---------------------------------------------------------------------

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ipps.h>
#include <ippsr.h>
#include "gmm.h"

#define TRAINCYCLES 3

class MFCC{
public:
    static void readMFCC(char *infile,float **mfccs,int *size,int *step,int *frameNum,int cutEnergy);
};

void MFCC::readMFCC(char *infile,float **mfccs,int *size,int *step,int *frameNum,int cutEnergy){
struct  _MFCChead{
       int   frameNum;
       int   h_framePeriod;
       short frameSize;
       short h_mfccKind;
   } head;
    FILE *fin;
    float *mfcc;
    int   i,step4;
    fin = fopen(infile,"rb");
    if(!fin){
        printf("\n Unable to open file %s \n",infile);
        exit(3);
    }
    if(1!=fread(&head,sizeof(_MFCChead),1,fin)){
        printf("\n Unexpected feature file end \n");
        fclose(fin); exit(3);
    }
    if(cutEnergy) *size = (head.frameSize>>2)-1;
    else          *size = head.frameSize>>2;
    step4 = (*size+3)&(~3);// 16-byte align
    mfcc = ippsMalloc_32f(head.frameNum*step4+4);
    for (i=0;i<head.frameNum;++i){
        if(1!=fread(&mfcc[i*step4],head.frameSize,1,fin)){
            printf("\n Unexpected feature file end \n");
            fclose(fin); exit(3);
        }
    }
    *mfccs = mfcc;
    *step = step4;
    *frameNum = head.frameNum;
    fclose(fin);
    return;
}

typedef struct  {
       short gaussNum;
       short frameSize;
       short cutEnergy;
   }_mixHead;

void GMM::EvalDet(){
  int        j;
    for (j=0;j<gaussianNum;++j){
        ippsUpdateGConst_32f(&cvar[step*j], width,&det[j]);//len*ln(2*p)-sum(ln(cvar[j][i]))
    }
    ippsOutProbPreCalc_32f_I(weight,det,gaussianNum);
}

void GMM::ReadMix(char *infile){
  FILE  *fin;
  _mixHead mhead;
    fin = fopen(infile,"rb");
    if(!fin) printf("Unable to open file %s\n",infile);
    if(1!= fread(&mhead,sizeof(_mixHead),1,fin)){
        printf("\n Unexpected feature file end \n");
        fclose(fin); exit(3);
    }
    width = mhead.frameSize;
    gaussianNum  = mhead.gaussNum;
    cutEnergy = mhead.cutEnergy;
    step = (width+3)&(~3);// 16-byte align

    InitArays(step,gaussianNum);
    if((int)fread(mean,sizeof(float)*step,gaussianNum,fin)<gaussianNum){
        printf("\n Unexpected mixture file end \n");
        fclose(fin); exit(3);
    }
    if((int)fread(cvar,sizeof(float)*step,gaussianNum,fin)<gaussianNum){
        printf("\n Unexpected mixture file end \n");
        fclose(fin); exit(3);
    }
    if((int)fread(weight,sizeof(float),gaussianNum,fin)<gaussianNum){
        printf("\n Unexpected mixture file end \n");
        fclose(fin); exit(3);
    }
    fclose(fin);
    EvalDet();
}

void GMM::WriteMix(char *outfile){
  FILE  *fin;
    _mixHead mhead;
    fin = fopen(outfile,"wb");
    if(!fin) printf("Unable to open file %s\n",outfile);
    mhead.frameSize = width;
    mhead.gaussNum  = gaussianNum;
    mhead.cutEnergy = cutEnergy;
    if( (int)fwrite(&mhead,sizeof(_mixHead),1,fin)<1){
        printf("\n Unexpected mixture file end \n");
        fclose(fin); exit(3);
    }
    if( (int)fwrite(mean,sizeof(float)*step,gaussianNum,fin)<gaussianNum){
        printf("\n Unexpected mixture file end \n");
        fclose(fin); exit(3);
    }
    if( (int)fwrite(cvar,sizeof(float)*step,gaussianNum,fin)<gaussianNum ){
        printf("\n Unexpected mixture file end \n");
        fclose(fin); exit(3);
    }
    if( (int)fwrite(weight,sizeof(float),gaussianNum,fin)<gaussianNum){
        printf("\n Unexpected mixture file end \n");
        fclose(fin); exit(3);
    }
    fclose(fin);
}

void GMM::InitArays(int step,int gaussianNum){
    cvar = ippsMalloc_32f(step*gaussianNum);
    mean = ippsMalloc_32f(step*gaussianNum);
    det  = ippsMalloc_32f(gaussianNum);
    weight = ippsMalloc_32f(gaussianNum);
}

void GMM::InitMixWithCDBK(char *trainf,int maxMixSize,bool CutEnergy){
  float    **featureClass,*tmpBuf,*tmpMean,*tmpVar;
  int        k,i,j,clusters,frames;
  int       *pIndx;
  IppsCdbkState_32f *pCdbk;

    gaussianNum = maxMixSize;
    cutEnergy = CutEnergy;
    MFCC::readMFCC(trainf,&mfccs,&width,&step,&frameNum,cutEnergy);//read train data
    InitArays(step,gaussianNum);
    tmpBuf =ippsMalloc_32f(step*3);
    tmpMean=tmpBuf+step;
    tmpVar =tmpMean+step;
    featureClass=(float**)ippsMalloc_32f(frameNum);
    pIndx = ippsMalloc_32s(frameNum);

    // calculate and invert grand variance
    ippsMeanVarColumn_32f_D2(mfccs,frameNum,step,tmpMean,tmpBuf,width);
    ippsSet_32f(1,tmpVar,width);
    ippsDiv_32f_I(tmpBuf,tmpVar,width);
    // build codebook using Mahalanobis distance with grand variance
    ippsCdbkInitAlloc_WgtL2_32f(&pCdbk,mfccs,tmpVar,width,step,frameNum,gaussianNum,
       IPP_CDBK_KMEANS_LONG);
    // get real number of clusters
    ippsGetCdbkSize_32f(pCdbk,&gaussianNum);
    // quantify training frames
    ippsVQ_32f(mfccs,step,pIndx,frameNum,pCdbk);
    ippsCdbkFree_32f(pCdbk);

    // initialize Gaussian means with non-empty cluster centroids
    // and  Gaussian variances with non-empty cluster variances
    for(clusters=frames=k=0;k<gaussianNum;++k){
        for(j=i=0;i<frameNum;++i){
            if(k==pIndx[i]){
                featureClass[j++]=&mfccs[i*step];
            }
        }
        if (j>1){
            ippsMeanVarColumn_32f_D2L((const float**)featureClass,j,
               &mean[clusters*step],&cvar[clusters*step],width);
            ippsSet_32f(1.0f,tmpBuf,width);
            // invert variances for likelihood calculation, prevent NANs
            if (ippsDiv_32f(&cvar[clusters*step],tmpBuf,&cvar[clusters*step],
               width)==ippStsNoErr) {
               weight[clusters++] = (float)j;
               frames+=j;
            }
        }
    }
    if (clusters<=0) {
       printf("\n Could not initialize mixture \n");
       exit(4);
    } else {
       gaussianNum = clusters;
    }
    // initialize Gaussian weights with cluster sharesm
    ippsDivC_32f_I((float)frames,weight,gaussianNum);
    // log for likelihood calculation
    ippsLn_32f_I(weight,gaussianNum);
    //calculate constants for likelihood calculation
    EvalDet();

    ippsFree(featureClass);
    ippsFree(pIndx);
}

void GMM::TrainMix(int trainCycles){
  float   **postProb,*grad,*tmpWgt,*tmpVar;
  float     max,sum;
  int       j,t,cycles,i,gaussianNum4;
    gaussianNum4 = (gaussianNum+3)&(~3);//16-byte align
    grad     = ippsMalloc_32f(gaussianNum4);
    tmpWgt   = ippsMalloc_32f(frameNum);
    tmpVar   = ippsMalloc_32f(step);
    postProb = (float **)ippsMalloc_32f(frameNum);
    postProb[0] = ippsMalloc_32f(frameNum*gaussianNum4);
    for (i=1;i<frameNum;++i){
        postProb[i] = postProb[0]+gaussianNum4*i;
    }
    for(cycles=0; cycles<trainCycles;++cycles){//training cycle beginning
        for (t=0;t<frameNum;++t){// find posterior probabilities postProb[][]
            // additive term for log likelihood
            ippsCopy_32f(det,postProb[t],gaussianNum);
            // component log likelihoods for frame t
            ippsLogGaussMultiMix_32f_D2(mean,cvar,step,&mfccs[t*step],width,
                postProb[t],gaussianNum);
            // subtract maximum for better exponent
            ippsMax_32f(postProb[t],gaussianNum,&max);
            ippsSubC_32f_I(max,postProb[t],gaussianNum);
            // component likelihoods for frame t - numerators of h[j,t]
            ippsExp_32f_I(postProb[t],gaussianNum);
            // denomerators of h[j,t]
            ippsSum_32f(postProb[t],gaussianNum,&sum,ippAlgHintNone);
            // h[j,t]
            ippsDivC_32f_I(sum,postProb[t],gaussianNum);
        }
        // update weights
        ippsSumColumn_32f_D2((const float*)postProb[0],gaussianNum4,frameNum,grad,
            gaussianNum);
        ippsDivC_32f(grad,(float)frameNum,weight,gaussianNum);
        // log for likelihood calculation
        ippsLn_32f_I(weight,gaussianNum);

        ippsSet_32f(1,cvar,gaussianNum*step);
        for (j=0;j<gaussianNum;++j){
            //transpose column
            for (t=0;t<frameNum;++t)
                tmpWgt[t] = postProb[t][j];
            ippsDivC_32f_I(grad[j],tmpWgt,frameNum);
            //  update mixture mean and variance
            ippsWeightedMeanVarColumn_32f_D2(mfccs,step,tmpWgt,frameNum,&mean[j*step],
               tmpVar,width);
            //inverse for likelihood calculation
            ippsDiv_32f_I(tmpVar,&cvar[j*step],width);
        }
        //calculate constants for likelihood calculation
        EvalDet();
    }//training cycle end
    ippsFree(postProb[0]);
    ippsFree(postProb);
    ippsFree(grad);
    ippsFree(tmpVar);
    ippsFree(tmpWgt);
}

float GMM::LogLHPerFrame(char *TestFile){
  int    j,frames,twidth,step;
  float *testMFCC;
  float  logLH=0,res;
  MFCC::readMFCC(TestFile,&testMFCC,&twidth,&step,&frames,cutEnergy);
    if(twidth!=width || step!=step){
        printf("\nIncompatible feature %s \n",TestFile);
        exit(3);
    }

    for (j=0; j<frames; j++) {
       ippsLogGaussMixture_32f_D2(testMFCC+j*step,mean,cvar,gaussianNum,step,width,det,&res);
       logLH+=res;
    }

    ippsFree(testMFCC);
    return logLH/frames;
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产精品美女一区二区三区| 中文字幕综合网| 国产精品久久免费看| 一区二区在线看| 高清在线成人网| 精品剧情在线观看| 亚洲尤物在线视频观看| 岛国一区二区在线观看| 91精品国产综合久久久久久漫画| 亚洲欧洲制服丝袜| 成人激情综合网站| 精品美女一区二区| 日本sm残虐另类| 欧美裸体bbwbbwbbw| 中文字幕亚洲区| 成人性生交大合| 久久久久久久久久久99999| 欧美aaaaa成人免费观看视频| 欧美性三三影院| 亚洲国产精品一区二区久久恐怖片 | 欧美一区二区三区免费| 一区在线观看免费| 成人激情综合网站| 日本一区二区三级电影在线观看| 麻豆精品一二三| 日韩一二三区视频| 免费在线观看一区二区三区| 欧美日韩亚洲综合一区二区三区| 亚洲人123区| 在线视频观看一区| 一区二区三区欧美日| 在线中文字幕一区| 午夜精品久久久久久久| 欧美日韩成人激情| 日韩极品在线观看| 欧美精品18+| 日本欧美久久久久免费播放网| 制服丝袜亚洲播放| 美腿丝袜亚洲三区| 精品福利视频一区二区三区| 韩国成人在线视频| 国产精品午夜春色av| 91丨porny丨国产| 亚洲一区二区三区自拍| 欧美军同video69gay| 久久精品免费看| 中文字幕免费在线观看视频一区| 成人黄色大片在线观看| 亚洲影院在线观看| 欧美大片在线观看一区| 成人开心网精品视频| 一区二区三区丝袜| 日韩欧美电影一二三| 国产成人久久精品77777最新版本 国产成人鲁色资源国产91色综 | 在线免费观看不卡av| 亚洲国产一区在线观看| 91麻豆精品国产91久久久久| 亚洲国产日韩综合久久精品| 国产成人午夜精品影院观看视频| 国产亚洲一二三区| 成人av免费观看| 偷拍日韩校园综合在线| 欧美精品一区二区三区视频| 成人av免费在线播放| 午夜精品久久久| 国产日韩一级二级三级| 欧美天堂一区二区三区| 国产一区二区不卡老阿姨| 亚洲精品视频在线观看免费| 日韩一区二区三免费高清| 国产suv精品一区二区三区| 亚洲成人av一区| 国产亚洲污的网站| 欧美日本一区二区| 成人免费视频播放| 日韩电影在线免费观看| 中文字幕在线不卡一区二区三区| 91精品国产综合久久蜜臀| 99re这里都是精品| 精品一区二区三区在线观看国产 | 一区二区在线电影| 精品国产免费一区二区三区香蕉| 7777精品伊人久久久大香线蕉 | 国产成人免费9x9x人网站视频| 一区二区三区四区高清精品免费观看 | 美日韩一区二区| 一区二区三区日韩欧美精品| 亚洲国产高清不卡| 3751色影院一区二区三区| 91国产免费观看| 国产不卡视频在线播放| 免费成人在线网站| 三级欧美韩日大片在线看| 1区2区3区欧美| 日本一区二区成人| 2021中文字幕一区亚洲| 51午夜精品国产| 在线观看免费亚洲| jlzzjlzz国产精品久久| 国产成人免费视频一区| 蜜臀va亚洲va欧美va天堂| 亚洲mv大片欧洲mv大片精品| 亚洲女同女同女同女同女同69| 国产视频一区二区在线观看| 日韩美一区二区三区| 欧美一区二区三区人| 欧美另类变人与禽xxxxx| 精品污污网站免费看| 日本伦理一区二区| 欧美性生活影院| 色噜噜夜夜夜综合网| 色婷婷综合久色| 欧美专区亚洲专区| 在线观看亚洲a| 欧美日韩一级黄| 欧美精品久久一区| 337p亚洲精品色噜噜噜| 欧美久久久久中文字幕| 欧美理论在线播放| 欧美mv日韩mv亚洲| 久久网这里都是精品| 亚洲精品一区二区三区蜜桃下载| 精品少妇一区二区三区免费观看| 欧美videos中文字幕| 精品福利在线导航| 国产精品久久三| 亚洲欧美一区二区三区极速播放| 一区二区三区中文字幕| 香蕉av福利精品导航| 日韩电影一区二区三区四区| 久久99久久99| 成人免费毛片aaaaa**| 91亚洲永久精品| 91麻豆精品久久久久蜜臀| 久久综合色播五月| 亚洲视频一二区| 性做久久久久久久免费看| 日韩1区2区3区| 成人午夜又粗又硬又大| 日本丶国产丶欧美色综合| 91精品在线观看入口| 久久久久国色av免费看影院| 亚洲欧美激情插| 美女网站一区二区| 不卡一二三区首页| 在线不卡欧美精品一区二区三区| 久久蜜桃香蕉精品一区二区三区| 国产精品久久国产精麻豆99网站| 亚洲一区二区三区美女| 九一久久久久久| 91一区二区在线观看| 日韩三级.com| 亚洲手机成人高清视频| 美女视频黄 久久| 在线观看一区二区精品视频| 日韩写真欧美这视频| 亚洲视频一区在线| 精品一区二区三区久久| 色天使色偷偷av一区二区| 精品三级在线看| 亚洲电影第三页| 99综合影院在线| 2021中文字幕一区亚洲| 亚洲永久免费视频| 成人av集中营| 久久亚洲综合色| 免费观看成人av| 欧美日韩一区二区不卡| 亚洲视频在线观看一区| 国产精品主播直播| 日韩网站在线看片你懂的| 亚洲一区二区三区不卡国产欧美| 成人一区二区三区视频| 精品国产成人在线影院| 日韩国产欧美在线播放| 色婷婷一区二区三区四区| 国产午夜精品理论片a级大结局| 日韩av一区二区在线影视| 91欧美激情一区二区三区成人| 久久精品人人爽人人爽| 加勒比av一区二区| 欧美一区二区三区精品| 午夜成人在线视频| 欧洲日韩一区二区三区| 亚洲美女在线国产| 成人av网在线| 国产精品高潮呻吟| 成人性生交大片免费| 国产女人18水真多18精品一级做| 麻豆精品新av中文字幕| 欧美成人bangbros| 日本欧美加勒比视频| 欧美一级在线视频| 青青草国产成人99久久| 欧美一区二区久久| 免费高清成人在线| 亚洲精品在线一区二区| 国模娜娜一区二区三区| 久久精品在这里| 波多野结衣欧美|