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

📄 decoder_main.c

📁 Intel开发的IPP库的应用实例
💻 C
字号:
/*
//
//                  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) 2003-2006 Intel Corporation. All Rights Reserved.
//
//     Intel(R) Integrated Performance Primitives Advanced Aurora 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.
//
//   ES 202 050 v1.1.1 is the international standard promoted by ETSI
//   and other organizations. Implementations of these standards, or the standard
//   enabled platforms may require licenses from various entities, including
//   Intel Corporation.
//
*/

#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

#include "decoderapi.h"

#define BOOLEAN int
#define FALSE 0
#define TRUE (!FALSE)

int n_repeat;
AuroraDataType DecoderIn;

FILE *fpIn = NULL;
FILE *fpOut1 = NULL;
FILE *fpOut2 = NULL;
FILE *fpVAD = NULL;            /* Input & output vad file */

AuroraRate SFrequency = r16KHz; /* SamplingFrequency */
int SamplingFrequency = 16000;  /* SamplingFrequency */
int puttocsv = 0;
int stepTest=100;

typedef struct{
    long SamplesNumber;
    long SamplePeriod;
    short SampleSize;
    short SampleKind;
}
HTKHeader;

void WriteHTKHeader (FILE * out, int SamplesNumber){
    long tmpl[2];
    short tmps[2];
    fseek (out, 0L, SEEK_SET);
    tmpl[0] = SamplesNumber; tmpl[1] = 100000;
    tmps[0] = (short)(NUM_CEP_COEFF + 1 )*4; tmps[1] = 8262;

    fwrite (tmpl, sizeof (long), 2, out);
    fwrite (tmps, sizeof (short), 2, out);
}

static BOOLEAN
ParseCommLine (int argc, char *argv[])
{
    char st[256];
    int rep;
    n_repeat = 1;
    DecoderIn = QUANTIZED;

    if (argc < 2) return FALSE;
    while (argc-2)
    {
        if(strcmp(*argv,"-step")==0){
            rep = atoi(*(argv+1));
            if(0 == rep) rep=1;
            stepTest=rep;
            argc-=2;
            argv+=2;
            continue;
        }
        else if(strcmp(*argv,"-s")==0){
            rep = atoi(*(argv+1));
            if(0 == rep) rep=1;
            if(rep > n_repeat) n_repeat=rep;
            argc-=2;
            argv+=2;
            continue;
        }
        if(strcmp(*argv,"-i")==0){
            if(strcmp(*(argv+1),"q")==0)
               DecoderIn = QUANTIZED;
            else if(strcmp(*(argv+1),"m")==0)
               DecoderIn = MULTIFRAME;
            argc-=2;
            argv+=2;
            continue;
        }
        else if(strcmp(*argv,"-vad")==0){
           if ( (fpVAD = fopen(*(argv+1), "wb")) == NULL) {
              printf("File %s could not be open.\n", *argv);
              return FALSE;
           }
           fseek(fpVAD,0L,SEEK_SET);
           argc-=2;
           argv+=2;
           continue;
        }
        else if (strcmp (*argv, "-f") == 0)
        {
            SamplingFrequency = 1000 * atoi (*(argv+1));
            switch(SamplingFrequency){
            case 16000: SFrequency = r16KHz;break;
            case 11000: SFrequency = r16KHz;break;
            case 8000: SFrequency = r8KHz;break;
            default:
                 printf("WARNING:unrecognised frequancy %s \n",*(argv+1));
                 return FALSE;
            }

            argc-=2;
            argv+=2;
            continue;
        }
        else if (strcmp (*argv, "-c") == 0)
        {
            puttocsv = 1;
            argc--;
            argv++;
            continue;
        }
        printf("WARNING:unrecognised parameter %s \n",*argv);
        argc--;
        argv++;
        return FALSE;
    }
    if ( (fpIn = fopen(*argv, "rb")) == NULL) {
        printf("File %s could not be open.\n", *argv);
         return FALSE;
    }
    argv++; argc--;
    if ( (fpOut1 = fopen(*argv, "wb")) == NULL) {
       printf("File %s could not be open.\n", *argv);
       return FALSE;
    }
    sprintf(st,"%s.calc",*argv);
    if ( (fpOut2 = fopen(st, "wb")) == NULL) {
       printf("File %s could not be open.\n", st);
       return FALSE;
    }

    argv++; argc--;

    return TRUE;
}



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

    long  FrameCounter = 0,SizeBuffer,countFrameCalc;
    const IppLibraryVersion *ver;
    float *FeatBuff32f;
    unsigned char *Buffer,*workBuffer,*pVadBuff;
    float *pDst;
    AuroraDecoder *pCodec;
    int i,NumberFrame,sizeFrame;
    int repeat;
    FILE *f_csv;
    int countFrame,stepFrame;
    int size;
    int cbeg;
    int end;
    short sync = 0x784d;
    clock_t time_start;
    clock_t time_finish;
    double rt_time;
/*-----------------------*/
    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:");
        fprintf (stderr, "   %s [options] <infile> <HTK_outfile>\r\n", argv[0]);
        fprintf (stderr, "\r\n    OPTIONS:\r\n");
        fprintf (stderr, "     -f   freq      Sampling frequency in kHz (8,16)        16\r\n");
        fprintf (stderr, "     -c             Write performance line \r\n");
        fprintf (stderr, "     -s   XX        Number of repeat                         1\r\n");
        fprintf (stderr, "     -i q           Run quantised                           q \r\n");
        fprintf (stderr, "        m           Run multiframe                            \r\n");
        fprintf (stderr, "     -step XX       Step for testing                       100\r\n");
        fprintf (stderr, "     -vad filename  VAD file \r\n");
        fprintf (stderr, "     -help          Help \r\n");

    }
    else{

       /*-------------------   DECODER -----------------------------*/
           /*   Init Codec    */
           if (InitAuroraDecoder(&pCodec,SFrequency,DecoderIn)==-1)return -1;

           /*   Read file   */
           fseek(fpIn,0L,SEEK_END);
           SizeBuffer = ftell(fpIn);
           fseek(fpIn,0L,SEEK_SET);
           Buffer=ippsMalloc_8u(SizeBuffer);


           fread(Buffer, sizeof(unsigned char),SizeBuffer, fpIn);

           /* Allocate buffer for output feature  */
           if (DecoderIn ==QUANTIZED){
               NumberFrame = (SizeBuffer)/8;
               FeatBuff32f = ippsMalloc_32f (NumberFrame*(NUM_CEP_COEFF+2));
               ippsZero_32f(FeatBuff32f,NumberFrame*(NUM_CEP_COEFF+2));
               sizeFrame = 8;
           }

           if (DecoderIn ==MULTIFRAME){
               NumberFrame = SizeBuffer/144;
               FeatBuff32f = ippsMalloc_32f (NumberFrame*24*(NUM_CEP_COEFF+1));
               ippsZero_32f(FeatBuff32f,NumberFrame*24*(NUM_CEP_COEFF+1));
               sizeFrame = NUM_MULTI_BYTE;
           }

           pVadBuff = ippsMalloc_8u(NumberFrame*24);
           pDst = ippsMalloc_32f(NumberFrame*24*40);

           /*   Main loop for timing  */
           time_start = clock();
           repeat = n_repeat;
           while(n_repeat--){
               stepFrame = stepTest;
               workBuffer = Buffer;
               countFrame = 0;
               end = 0;
               for (i=0; i<NumberFrame;i+=stepFrame){
                   if (NumberFrame-i <= stepFrame ){ size = NumberFrame-i;
                   end = 1;
                   }
                   else size = stepFrame;
                   if (DecoderIn ==QUANTIZED)
                     countFrame+=ApplyAuroraDecoder_QF(pCodec,(unsigned char*)workBuffer,size,
                         FeatBuff32f,pVadBuff,end);
                   if (DecoderIn ==MULTIFRAME)
                     countFrame+=ApplyAuroraDecoder_MF(pCodec,(unsigned char*)workBuffer,size,
                         FeatBuff32f,pVadBuff,end);
                   workBuffer+=stepFrame*sizeFrame;

               }
               countFrameCalc = ApplyAuroraDecoder_DerCal(pCodec,FeatBuff32f,pVadBuff,countFrame,pDst);
           }
           time_finish = clock();
           rt_time = (double)(time_finish-time_start)/CLOCKS_PER_SEC/repeat*1000;
           /* Write Feature file */
           WriteHTKHeader (fpOut1, countFrame);

           fwrite (FeatBuff32f, sizeof (float), countFrame * (NUM_CEP_COEFF+1), fpOut1);
           if(fpVAD)fwrite (pVadBuff, sizeof(char), countFrame, fpVAD);

           /* Write Feature file 2*/
           WriteHTKHeader (fpOut2, countFrameCalc);

           fwrite (pDst, sizeof (float), countFrameCalc * 40, fpOut2);

           if(FeatBuff32f) ippsFree(FeatBuff32f);
           if(pVadBuff) ippsFree(pVadBuff);
           if(pDst) ippsFree(pDst);
           if(Buffer) ippsFree(Buffer);
           /*  Release memory */
           ReleaseAuroraDecoder(pCodec);

       /* end if decoder */

       /*-----------  Output statistics  --------------------   */
       printf(" %d frames\n",countFrame);
       printf(" Speed %g (ms)\n",rt_time);
       if (puttocsv) {
          if ( (f_csv = fopen("decoderspeed.csv", "r")) == NULL)cbeg=1;else cbeg=0;
          if ( (f_csv = fopen("decoderspeed.csv", "a")) == NULL) {
             printf("\nFile codecspeed.csv could not be open.\n");
          exit(5);
          }
          if (cbeg)fprintf(f_csv,"\nTypeApplication, Type DecoderIn, Time(ms), Sample,Frame");
          if ((DecoderIn == QUANTIZED) )
              fprintf(f_csv,"\nDecoder, QUANTIZED, %f, %d, %d",rt_time,
              NumberFrame,countFrame);
          if ((DecoderIn == MULTIFRAME) )
              fprintf(f_csv,"\nDecoder, MULTIFRAME, %f, %d, %d",rt_time,
              NumberFrame,countFrame);



          fclose(f_csv);
       }


       /* Close input and output files */
       if (fpIn)fclose (fpIn);
       if (fpOut1)fclose (fpOut1);
       if (fpOut2)fclose (fpOut2);
       if (fpVAD)fclose (fpVAD);

    }/*else*/


   return 0;
}

⌨️ 快捷键说明

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