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

📄 resamp_main.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 & speaker verification program  main
//---------------------------------------------------------------------

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

static bool fixed=false,univ=false,fp=false,fast=false;
static double factor=0;
static float window=0,rollf=0,alpha=0;
static int inrate=0,outrate=0,length=0,steps=0,bufsize=0;
static char *infile="",*outfile="";

static bool ParseCommLine (int argc, char *argv[]) {

    while (argc>2) {
        if (strcmp(*argv,"-f")==0) {
           if (argc<3) return false;
           inrate = atoi(*(argv+1));
           outrate = atoi(*(argv+2));
           fixed=true;
           univ=false;
           argc-=3;
           argv+=3;
           continue;
        }
        if (strcmp(*argv,"-u")==0) {
           if (argc<3) return false;
           steps = atoi(*(argv+1));
           factor = atof(*(argv+2));
           fixed=false;
           univ=true;
           argc-=3;
           argv+=3;
           continue;
        }
        if(strcmp(*argv,"-w")==0) {
           if (argc<2) return false;
           window = (float)atof(*(argv+1));
           length = 0;
           argc-=2;
           argv+=2;
           continue;
        }
        if(strcmp(*argv,"-l")==0) {
           if (argc<2) return false;
           length = atoi(*(argv+1));
           window = 0;
           argc-=2;
           argv+=2;
           continue;
        }
        if(strcmp(*argv,"-a")==0) {
           if (argc<2) return false;
           alpha = (float)atof(*(argv+1));
           argc-=2;
           argv+=2;
           continue;
        }
        if(strcmp(*argv,"-b")==0) {
           if (argc<2) return false;
           bufsize = atoi(*(argv+1));
           argc-=2;
           argv+=2;
           continue;
        }
        if(strcmp(*argv,"-r")==0) {
           if (argc<2) return false;
           rollf = (float)atof(*(argv+1));
           argc-=2;
           argv+=2;
           continue;
        }
        if(strcmp(*argv,"-float")==0) {
           fp=true;
           argc-=1;
           argv+=1;
           continue;
        }
        if(strcmp(*argv,"-fast")==0) {
           fast=true;
           argc-=1;
           argv+=1;
           continue;
        }
    }

    if ((!fixed)&&(!univ)) univ=true;
    if (inrate<=0)      inrate=16000;
    if (outrate<=0)     outrate=11025;
    if (factor<=0)      factor=11025.0/16000.0;
    if ((window<=0)&&(length<=0)) window=64.0;
    if (window>=1024.0) window=1024.0f;
    if (length>=1024)   length=1024;
    if (steps<=0)       steps=256;
    if (steps>=4096)    steps=4096;
    if (alpha<=1.0)     alpha=9.0f;
    if (rollf<=0)       rollf=0.95f;
    if (rollf>1.0)      rollf=0.95f;
    if (bufsize<=0)     bufsize=4000;

    if (argc>1) {
       infile=*argv;
       argv++;
       outfile=*argv;
       return true;
    } else {
       return false;
    }

    return true;
}

int main(int argc, char *argv[]){

    Resample *res;
    const IppLibraryVersion *ver;

    ver = ippsGetLibVersion();
    printf("IPPS library used: %s  %d.%d.%d\n",ver->Name,
         ver->major,ver->minor,ver->majorBuild);
    ver = ippsrGetLibVersion();
    printf("IPPSR library used: %s  %d.%d.%d\n",ver->Name,
         ver->major,ver->minor,ver->majorBuild);

    if (!ParseCommLine (argc - 1, argv + 1)){
       fprintf (stderr, "\r\n   USAGE:\r\n");
       fprintf (stderr, "   %s (-f in out|-u steps factor) (-w window|-l length) [options] infile outfile\r\n", argv[0]);
       fprintf (stderr, "   %s (-f in out|-u factor) [options] infile outfile\r\n", argv[0]);
       fprintf (stderr, "     -f   in out  Fixed filter for input rate and output rate\r\n");
       fprintf (stderr, "     -u   factor  Universal filter with discretization steps per 1 andfactor\r\n");
       fprintf (stderr, "     -w   window  Ideal filter window size \r\n");
       fprintf (stderr, "     -l   length  Filter length\r\n");
       fprintf (stderr, "\r\n   OPTIONS:\r\n");
       fprintf (stderr, "     -r   rollf   Roll-off frequency\r\n");
       fprintf (stderr, "     -a   alpha   Kaiser window parameter\r\n");
       fprintf (stderr, "     -b   bufsize Data portion size in samples\r\n");
       fprintf (stderr, "     -fast        Fast calculations\r\n");
       fprintf (stderr, "     -float       Float point calculations\r\n");

    } else {
       res=new Resample(rollf,alpha,fast,fp);
       if (fixed) {
          if (length>0) {
             res->InitFix(inrate,outrate,length,bufsize);
          } else {
             res->InitFix(inrate,outrate,window,bufsize);
          }
       } else {
          if (length>0) {
             res->Init(factor,length,steps,bufsize);
          } else {
             res->Init(factor,window,steps,bufsize);
          }
       }
       if (res->Check()) {
          res->Do(infile,outfile);
       } else {
          printf ("Failed to resample\n");
       }

       delete res;
    }

    return 0;
}

⌨️ 快捷键说明

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