⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gauss_main.cpp

📁 Intel开发的IPP库的应用实例
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*
//
//                  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 Gaussian Mixture 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.
//
//
//     Test of Vector Gaussian Mixture Calculation
//
//
*/


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ipps.h>
#include <ippsr.h>
#include <ippcore.h>

#include "len_stat.h"
#include "fake_decoder.h"
#include "prob_cache.h"
#include "prob_calc.h"
#include "feat_calc.h"

static int frequency = 500;
static int TypeTest  = 0;
static int meanSc    = 9;
static int varSc     = 9;
static int probSc    = 16;

static int num_err   = 0;

#if defined( _WIN32 ) || defined( _WIN64 )
  #define IPP_MAX_64U  ( 0xffffffffffffffffL ) //18446744073709551615
#else
  #define IPP_MAX_64U  ( 0xffffffffffffffffLL ) //18446744073709551615
#endif


float getUSec(Ipp64u s, Ipp64u e) { // returns (CPU_Frequency * time_in_sec)
#if defined __ICL
   Ipp64f b=((s<e)?(e-s):((IPP_MAX_64U-s)+e))/1000000.0;
#else  // MSVC 6.0 could not divide int64 by double
   Ipp64u a=(s<e)?(e-s):((IPP_MAX_64U-s)+e);
   Ipp64f b=((Ipp32u)(a>>32)*((Ipp64f)IPP_MAX_32U+1.0)+(Ipp32u)(a&IPP_MAX_32U))/1000000.0;
#endif
   return (float)b;
}

static bool ParseCommLine (int argc, char *argv[])
{
    if (argc < 2) return false;
    while (argc>=2)
    {
        if (strcmp(*argv,"-f")==0) {
            frequency = atoi(*(argv+1));
            if(0 == frequency) frequency=500;
            argc-=2;
            argv+=2;
            continue;
        }
        if (strcmp(*argv,"-mf")==0) {
            meanSc = atoi(*(argv+1));
            argc-=2;
            argv+=2;
            continue;
        }
        if (strcmp(*argv,"-vf")==0) {
            varSc = atoi(*(argv+1));
            argc-=2;
            argv+=2;
            continue;
        }
        if (strcmp(*argv,"-pf")==0) {
            probSc = atoi(*(argv+1));
            argc-=2;
            argv+=2;
            continue;
        }
        if (strcmp(*argv,"-t")==0) {
            TypeTest = atoi(*(argv+1));
            argc-=2;
            argv+=2;
            continue;
        }
        printf("WARNING:unrecognised parameter %s \n",*argv);
        argc--;
        argv++;
    }
    return true;
}

char* Fake_Decoder_Test
  (Calc_Hint hint,            // probability calculation method:
                              // calcNone   -  no calculations
                              // calcVect   -  LogGauss & LogAdd calculations
                              // calcVecM   -  LogGauss & LogMax calculations
                              // calcMix    -  LogGaussMixture calculations
   char   *paramfile,         // mixture param file name or "" for fake model
   char   *featfile,          // HTK feature file name or "" for fake features
   int     mixnum,            // state (mixture) number for fake model
   int     gaussnum,          // Gaussian number per mixture for fake model
   int     dimension,         // feature space dimension for fake model or features
   int     calcmax,           // maximal probability vector length for calculator
   int     calcmin,           // minimal probability vector length (except end)
   int     framenum,          // frame number for fake features
   int     delay,             // maximal portion of features
   int     cachelen,          // cache length (frames)
   int     veclen,            // probability vector length in cache
   int     actlen,            // maximal state activity interval
   int     avrmix,            // average active states per frame
   char   *problogfile,       // probability log file name or "" for fake features
   char   *featlogfile,       // HTK feature file name or "" for fake features
   int     meanScale,         // scale factor for mean values
   int     varScale,          // scale factor for var values
   int     probScale)         // scale factor for probability values
{
   int t,num,avl;
   Ipp64u m_clocks;
   double sec_time;
   double speech_sec;
   float freq=(float)frequency;
   int model=0;

   Len_Stat stat_dec;
   Len_Stat stat_cache;

   Prob_Calc *calc= new Prob_Calc(meanScale,varScale,probScale,hint);
   if (paramfile[0]==0) {
       if (calc->Init_Calc(mixnum,gaussnum,dimension,calcmax,calcmin)<0){
           num_err++;
           return "ERROR! Could not create fake mixture calculator\n";
       }
       model=0;
   } else  {
       if (calc->Init_Calc(paramfile,calcmax,calcmin)<0){
           num_err++;
           return "ERROR! Could not create SDT mixture calculator\n";
       }
       model=1;
       mixnum=calc->State_Number();
       dimension=calc->Feature_Length();
       gaussnum=calc->Max_Gauss();
   }
   if (calc->Init_LogFile(featlogfile)<0){
       num_err++;
       return "ERROR! Could not open feature log file\n";
   }

   Feat_Calc *feat= new Feat_Calc(meanScale,dimension,delay);
   if (featfile[0]==0) {
       if (feat->Init_Feat(framenum)<0){
           num_err++;
           return "ERROR! Could not create fake feature producer\n";
       }
   } else {
       if (feat->Init_Feat(featfile)<0){
           num_err++;
           return "Could not create HTK file feature producer\n";
       }
   }
   if (!calc->Attach_Feat(feat)){
       num_err++;
       return "Could not attach feature producer\n";
   }

   Prob_Cache *cache= new Prob_Cache(mixnum,veclen,cachelen);
   if (cache->Init_Cache()<0){
       num_err++;
       return "ERROR! Could not create probabilities cache\n";
   }
   if (!cache->Attach_Calc(calc)){
       num_err++;
       return "ERROR! Could not attach mixture calculator\n";
   }

   Fake_Decoder *dec = new Fake_Decoder(mixnum,actlen);
   if (dec->Init_Decoder()<0){
       num_err++;
       return "ERROR! Could not create fake decoder\n";
   }
   if (!dec->Attach_Cache(cache)){
       num_err++;
       return "Could not attach probabilities cache\n";
   }
   if (dec->Init_LogFile(problogfile)<0){
       num_err++;
       return "ERROR! Could not open probability log file\n";
   }

   stat_dec.len=256;
   stat_dec.nums=(int*)calloc(sizeof(int),256);

   stat_cache.len=veclen;
   stat_cache.nums=(int*)calloc(sizeof(int),veclen);

   m_clocks=ippGetCpuClocks();
   framenum=1;
   while (dec->Decode_Frame(avrmix)) {
      framenum++;
   }
   sec_time = getUSec(m_clocks,ippGetCpuClocks());
   speech_sec = (framenum+1)/100.0;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -