Пример #1
0
void PLC_init(G711_PLC_state *PLC)
{
  ippsZero_8u((void*)PLC, sizeof(G711_PLC_state));
  erasecnt = 0;
  pitchbufend = &pitchbuf[HISTORYLEN];
  ippsZero_16s(history, HISTORYLEN);
}
Пример #2
0
JERRCODE CJPEGDecoder::DecodeScanBaselineIN_RSTI(void)
{
  int rcount = 0;
  IppStatus status;
  JERRCODE  jerr;
#ifdef __TIMING__
  Ipp64u   c0;
  Ipp64u   c1;
#endif

#ifdef _OPENMP
  int j;
  for(j = 0; j < m_num_threads; j++)
    status = ippiDecodeHuffmanStateInit_JPEG_8u(m_state_t[j]);
#endif
  status = ippiDecodeHuffmanStateInit_JPEG_8u(m_state);

  if(ippStsNoErr != status)
  {
    return JPEG_ERR_INTERNAL;
  }

  m_marker = JM_NONE;

  // workaround for 8-bit qnt tables in 12-bit scans
  if(m_qntbl[0].m_initialized && m_qntbl[0].m_precision == 0 && m_jpeg_precision == 12)
    m_qntbl[0].ConvertToHighPrecision();

  if(m_qntbl[1].m_initialized && m_qntbl[1].m_precision == 0 && m_jpeg_precision == 12)
    m_qntbl[1].ConvertToHighPrecision();

  if(m_qntbl[2].m_initialized && m_qntbl[2].m_precision == 0 && m_jpeg_precision == 12)
    m_qntbl[2].ConvertToHighPrecision();

  if(m_qntbl[3].m_initialized && m_qntbl[3].m_precision == 0 && m_jpeg_precision == 12)
    m_qntbl[3].ConvertToHighPrecision();

  // workaround for 16-bit qnt tables in 8-bit scans
  if(m_qntbl[0].m_initialized && m_qntbl[0].m_precision == 1 && m_jpeg_precision == 8)
    m_qntbl[0].ConvertToLowPrecision();

  if(m_qntbl[1].m_initialized && m_qntbl[1].m_precision == 1 && m_jpeg_precision == 8)
    m_qntbl[1].ConvertToLowPrecision();

  if(m_qntbl[2].m_initialized && m_qntbl[2].m_precision == 1 && m_jpeg_precision == 8)
    m_qntbl[2].ConvertToLowPrecision();

  if(m_qntbl[3].m_initialized && m_qntbl[3].m_precision == 1 && m_jpeg_precision == 8)
    m_qntbl[3].ConvertToLowPrecision();

  if(m_dctbl[0].IsEmpty())
  {
    jerr = m_dctbl[0].Create();
    if(JPEG_OK != jerr)
      return jerr;

    jerr = m_dctbl[0].Init(0,0,(Ipp8u*)&DefaultLuminanceDCBits[0],(Ipp8u*)&DefaultLuminanceDCValues[0]);
    if(JPEG_OK != jerr)
      return jerr;
  }

  if(m_dctbl[1].IsEmpty())
  {
    jerr = m_dctbl[1].Create();
    if(JPEG_OK != jerr)
      return jerr;

    jerr = m_dctbl[1].Init(1,0,(Ipp8u*)&DefaultChrominanceDCBits[0],(Ipp8u*)&DefaultChrominanceDCValues[0]);
    if(JPEG_OK != jerr)
      return jerr;
  }

  if(m_actbl[0].IsEmpty())
  {
    jerr = m_actbl[0].Create();
    if(JPEG_OK != jerr)
      return jerr;

    jerr = m_actbl[0].Init(0,1,(Ipp8u*)&DefaultLuminanceACBits[0],(Ipp8u*)&DefaultLuminanceACValues[0]);
    if(JPEG_OK != jerr)
      return jerr;
  }

  if(m_actbl[1].IsEmpty())
  {
    jerr = m_actbl[1].Create();
    if(JPEG_OK != jerr)
      return jerr;

    jerr = m_actbl[1].Init(1,1,(Ipp8u*)&DefaultChrominanceACBits[0],(Ipp8u*)&DefaultChrominanceACValues[0]);
    if(JPEG_OK != jerr)
      return jerr;
  }

  m_rsti_offset[0] = m_BitStreamIn.GetStreamPos();

#ifdef _OPENMP
#pragma omp parallel shared(rcount) if(m_jpeg_sampling != JS_411)
#endif
  {
    int     i          = 0;
    int     rh         = 1;
    int     r          = 0;
    int     currMCURow = 0;
    int     idThread   = 0;
    Ipp16s* pMCUBuf    = 0;  // the pointer to Buffer for a current thread.

#ifdef _OPENMP
    idThread = omp_get_thread_num(); // the thread id of the calling thread.
#endif

    pMCUBuf = m_block_buffer + idThread * m_numxMCU * m_nblock * DCTSIZE2;

    while(i < m_num_rsti)
    {
#ifdef _OPENMP
#pragma omp critical
      {
#endif

        i = rcount;
        rcount++;

        if(i < m_num_rsti)
        {
          ParseNextRSTI(idThread,i+1);
        }

#ifdef _OPENMP
      }
#endif

      if(i < m_num_rsti)
      {
#ifdef _OPENMP

        currMCURow = m_rsti_height*i;

        m_BitStreamInT[idThread].SetDataLen(m_rsti_offset[i+1] - m_rsti_offset[i]);
        m_BitStreamInT[idThread].SetCurrPos(0);
#endif
        rh = IPP_MIN(m_rsti_height, m_numyMCU - currMCURow);

        for(r = 0; r < rh; r++)
        {
          ippsZero_16s(pMCUBuf,m_numxMCU * m_nblock * DCTSIZE2);

          jerr = DecodeHuffmanMCURowBL_RSTI(pMCUBuf, idThread);
          if(JPEG_OK != jerr)
            continue;

          jerr = ReconstructMCURowBL8x8(pMCUBuf, idThread);
          if(JPEG_OK != jerr)
            continue;

          jerr = UpSampling(currMCURow + r,idThread);
          if(JPEG_OK != jerr)
            continue;

          jerr = ColorConvert(currMCURow + r,idThread);
          if(JPEG_OK != jerr)
            continue;
        }

        if(m_jpeg_restart_interval)
        {
          jerr = ProcessRestart(idThread);
          if(JPEG_OK != jerr)
          {
            LOG0("Error: ProcessRestart() failed!");
          }
        }
      } // if
#ifndef _OPENMP
        i++;
#endif
    } // for m_numyMCU
  } // OMP

#ifdef _OPENMP
  /*for(j = 0; j < m_num_rsti; j++)
  {
    omp_destroy_lock(&locks[j]);
  }

  ippFree(locks);
  locks = 0;*/
#endif

  return JPEG_OK;
} // CJPEGDecoder::DecodeScanBaselineIN_RSTI()
Пример #3
0
Ipp32s WINAPI WinMain( HINSTANCE hinst, HINSTANCE xxx, LPWSTR lpCmdLine, Ipp32s yyy )
{
   Ipp8s line[WINCE_CMDLINE_SIZE];                     /* to copy command line */
   Ipp8s* argvv[WINCE_NCMD_PARAMS];
   Ipp8s** argv=argvv;

   wchar_t wexename[WINCE_EXENAME_SIZE];
   Ipp8s exename[WINCE_EXENAME_SIZE];
   Ipp8s cmdline[WINCE_CMDLINE_SIZE];

   /* simulate argc and argv parameters */
   Ipp32s argc;
#else /*Other OS*/
Ipp32s main(Ipp32s argc, Ipp8s *argv[])
{
#endif /*_WIN32_WCE*/
   CommandLineParams clParams;
   USC_EC_Params ecParams;
   USC_Status USCStatus;
   MeasureIt measure;
   FILE *fp_rin = NULL;
   FILE *fp_sin = NULL;
   FILE *fp_sout = NULL;
   FILE *f_log = NULL;
   vm_file *f_csv = NULL;        /* csv File    */
   Ipp8u *in1_buff_cur, *in2_buff_cur, *out_buff_cur;
   Ipp8u *in1_buff=NULL, *in2_buff=NULL, *out_buff=NULL;

   Ipp32s flen, in_len, lCallResult;
   Ipp32s i, frameNum, tailNum;
   Ipp32s usage=0, n_repeat=1;
   double speech_sec;
   Ipp32s delay=0;
   Ipp8s* appName=argv[0];
   Ipp8s pString[MAX_LEN_STRING];
   const  IppLibraryVersion *ver = NULL;
#if defined( _WIN32_WCE )

   GetModuleFileName( hinst, wexename, WINCE_EXENAME_SIZE );
   sprintf( exename, "%ls", wexename );
   sprintf( cmdline, "%ls", lpCmdLine );
   argc = parseCmndLine( exename, cmdline, line, WINCE_CMDLINE_SIZE, argv, WINCE_NCMD_PARAMS );

#endif

   ippStaticInit();

   SetCommandLineByDefault(&clParams);
   strcpy(clParams.csvFileName, "ec_speed.csv");

   usage = ReadCommandLine(&clParams, argc, argv);
   if(clParams.puttolog == 1) {
     if((f_log = fopen(clParams.logFileName, "a")) == NULL) return FOPEN_FAIL;
   } else f_log = NULL;
   if(usage) {
      if(clParams.enumerate == 1) {
         EnumerateStaticLinkedEC(f_log);
         if(f_log) fclose(f_log);
         return 0;
      } else {
        PrintUsage((const Ipp8s *)appName, f_log);
        return USAGE;
      }
   }

   lCallResult = LoadECByName((const Ipp8s *)clParams.ECName, &ecParams, f_log);
   if(lCallResult < 0) {
      sprintf(pString, "Cannot find %s echo canceller.\n", clParams.ECName);
      OutputInfoString(1, f_log, (const Ipp8s*)pString);
      if(f_log) fclose(f_log);
      return LOAD_EC_FAIL;
   }
   ecParams.pUSC_EC_Fxns->std.GetInfo((USC_Handle)NULL, &ecParams.pInfo);
   ecParams.objEC = NULL;
   ecParams.pBanks = NULL;
   ecParams.nBanks = 0;

   if((fp_rin = fopen(clParams.rinFileName,"rb")) == NULL)  {
      sprintf(pString, "echo canceller: File %s [r-in] could not be open.\n", clParams.rinFileName);
      OutputInfoString(1, f_log, (const Ipp8s*)pString);
      if(f_log) fclose(f_log);
      return FOPEN_FAIL;
   }
   if((fp_sin = fopen(clParams.sinFileName,"rb")) == NULL) {
      sprintf(pString, "echo canceller: File %s [s-in] could not be open.\n", clParams.sinFileName);
      OutputInfoString(1, f_log, (const Ipp8s*)pString);
      if(f_log) fclose(f_log);
      return FOPEN_FAIL;
   }
   if((fp_sout = fopen(clParams.soutFileName,"wb")) == NULL) {
      sprintf(pString, "echo canceller: File %s [s-out] could not be open.\n", clParams.soutFileName);
      OutputInfoString(1, f_log, (const Ipp8s*)pString);
      if(f_log) fclose(f_log);
      return FOPEN_FAIL;
   }
   if(clParams.puttocsv) { /* open the csv file */
      if((f_csv = vm_file_open(clParams.csvFileName, "a")) == NULL) {
         sprintf(pString, "\nFile %s could not be open.\n", clParams.csvFileName);
         OutputInfoString(1, f_log, (const Ipp8s*)pString);
         if(f_log) fclose(f_log);
         return FOPEN_FAIL;
      }
   }
    if(clParams.printSysInfo){
        OutputInfoString(0, f_log,"The Intel(R) echo canceller conformant to ITU G167 and G168,\n");
        ver = ippscGetLibVersion();
        sprintf(pString, "The Intel(R) IPPSC library used:  %d.%d.%d Build %d, name %s\n",
            ver->major,ver->minor,ver->majorBuild,ver->build,ver->Name);
        OutputInfoString(0, f_log, (const Ipp8s*)pString);
        ver = ippsGetLibVersion();
        sprintf(pString, "The Intel(R) IPPSP library used:  %d.%d.%d Build %d, name %s\n",
            ver->major,ver->minor,ver->majorBuild,ver->build,ver->Name);
        OutputInfoString(0, f_log, (const Ipp8s*)pString);
    }
    sprintf(pString, "Input  rin file: %s\n", clParams.rinFileName);
    OutputInfoString(1, f_log, (const Ipp8s*)pString);
    sprintf(pString, "Input  sin file: %s\n", clParams.sinFileName);
    OutputInfoString(1, f_log, (const Ipp8s*)pString);
    sprintf(pString, "Output sout file: %s\n", clParams.soutFileName);
    OutputInfoString(1, f_log, (const Ipp8s*)pString);
    switch(clParams.nlp) {
     case 0:
         sprintf(pString, "NLP disabled\n");
         break;
     case 1:
         sprintf(pString, "NLP type 1 enabled\n");
         break;
     default:
         sprintf(pString, "NLP  type 2 enabled\n");
    }

    switch(clParams.alg) {
     case EC_FULLBAND:
            ecParams.pInfo.params.algType = EC_FULLBAND;
            sprintf(pString, "mode : fullband \n");
            break;
     case EC_SUBBAND:
            ecParams.pInfo.params.algType = EC_SUBBAND;
            sprintf(pString, "mode : subband \n");
            break;
     case EC_AFFINESUBBAND:
         ecParams.pInfo.params.algType = EC_AFFINESUBBAND;
         sprintf(pString, "mode : subband affine projection \n");
         break;
     case EC_FASTSUBBAND:
            ecParams.pInfo.params.algType = EC_FASTSUBBAND;
            sprintf(pString, "mode : fast subband \n");
            break;
     default: return UNKNOWN_FORMAT;
   }
    OutputInfoString(1, f_log, (const Ipp8s*)pString);
    switch(clParams.adapt) {
        case 0:
            sprintf(pString, "adaptation : disable \n");
            ecParams.pInfo.params.modes.adapt = AD_OFF;
            break;
        case 2:
            sprintf(pString, "adaptation : lite \n");
            ecParams.pInfo.params.modes.adapt = AD_LITEADAPT;
            break;
        default:
            ecParams.pInfo.params.modes.adapt = AD_FULLADAPT;
            sprintf(pString, "adaptation : full \n");
    }
   OutputInfoString(1, f_log, (const Ipp8s*)pString);
   sprintf(pString, "echo tail length : %d\n", clParams.tail);
   OutputInfoString(1, f_log, (const Ipp8s*)pString);
   if(clParams.puttocsv) {
    if(clParams.printSysInfo){
        sysInfoToCSV(f_csv);
    }
   }
   ecParams.pInfo.params.pcmType.sample_frequency = clParams.freq;
   ecParams.pInfo.params.pcmType.bitPerSample = 16;
   ecParams.pInfo.params.echotail = clParams.tail;
   ecParams.pInfo.params.modes.zeroCoeff = 1;///???
   ecParams.pInfo.params.modes.nlp = clParams.nlp;
   ecParams.pInfo.params.modes.cng = clParams.cng;
   ecParams.pInfo.params.modes.td = 1;
   ecParams.pInfo.params.modes.ah = clParams.ah_mode;

   ecParams.pUSC_EC_Fxns->std.NumAlloc((const USC_EC_Option *)&ecParams.pInfo.params, &ecParams.nBanks);
   ecParams.pBanks = (USC_MemBank*)ippsMalloc_8u(sizeof(USC_MemBank)*ecParams.nBanks);
   if(!ecParams.pBanks) {
      sprintf(pString, "\nLow memory: %d bytes not allocated\n", (int)(sizeof(USC_MemBank)*ecParams.nBanks));
      OutputInfoString(1, f_log, (const Ipp8s*)pString);
      if(fp_rin) fclose(fp_rin);
      if(fp_sin) fclose(fp_sin);
      if(fp_sout) fclose(fp_sout);
      if(clParams.puttocsv) { if(f_csv) vm_file_fclose(f_csv); }
      if(f_log) fclose(f_log);
      return MEMORY_FAIL;
   }
   ecParams.pUSC_EC_Fxns->std.MemAlloc((const USC_EC_Option *)&ecParams.pInfo.params, ecParams.pBanks);
   for(i=0;i<ecParams.nBanks;i++) {
     ecParams.pBanks[i].pMem = (Ipp8s *)ippsMalloc_8u(ecParams.pBanks[i].nbytes);//375d60,377420
     if(!ecParams.pBanks[i].pMem) {
       sprintf(pString, "\nLow memory: %d bytes not allocated\n", ecParams.pBanks[i].nbytes);
       OutputInfoString(1, f_log, (const Ipp8s*)pString);
       if(ecParams.pBanks) ippsFree(ecParams.pBanks);
       if(fp_rin) fclose(fp_rin);
       if(fp_sin) fclose(fp_sin);
       if(fp_sout) fclose(fp_sout);
       if(clParams.puttocsv) { if(f_csv) vm_file_fclose(f_csv); }
       if(f_log) fclose(f_log);
       return MEMORY_FAIL;
     }
   }

   flen = PrepareInput(fp_rin, " receive-in input ", &in1_buff, f_log);
   in_len = PrepareInput(fp_sin, " send-in input ", &in2_buff, f_log);

   if(ecParams.pInfo.params.pcmType.sample_frequency == 8000){ /* 8 KHz */
      delay = (Ipp32s) (clParams.fdelay * 8000 * 2/1000);
   }else{ /* 16 KHz */
      delay = (Ipp32s) (clParams.fdelay * 16000 * 2/1000);
   }
   flen -= delay;
   if(flen < 0)  flen = 0;
   if (flen < in_len)
       in_len = flen;

   out_buff=(Ipp8u*)ippsMalloc_8u(in_len);/* allocate output buffer */
   if(!out_buff){ /* allocate output buffer */
      sprintf(pString, "\nNo memory for buffering of %d output bytes", in_len);
      OutputInfoString(1, f_log, (const Ipp8s*)pString);
      if(f_log) fclose(f_log);
      return MEMORY_FAIL;
   }

   /* time stamp prior to threads creation, creation and running time may overlap. */
   measure_start(&measure);

   n_repeat = clParams.nRepeat;
   while(n_repeat--) {
      USCStatus = ecParams.pUSC_EC_Fxns->std.Init((const USC_EC_Option *)&ecParams.pInfo.params, ecParams.pBanks, &ecParams.objEC);
      if(USCStatus!=USC_NoError) {
        OutputInfoString(1, f_log,"\nCan not initialize the EC object!");
        if(ecParams.pBanks) ippsFree(ecParams.pBanks);
        if(fp_rin) fclose(fp_rin);
        if(fp_sin) fclose(fp_sin);
        if(fp_sout) fclose(fp_sout);
        if(clParams.puttocsv) { if(f_csv) vm_file_fclose(f_csv); }
        if(f_log) fclose(f_log);
        return ERROR_INIT;
      }
      ecParams.pUSC_EC_Fxns->std.GetInfo(ecParams.objEC, (USC_EC_Info *)&ecParams.pInfo);
      frameNum = in_len/ecParams.pInfo.params.framesize;
      tailNum = (in_len/sizeof(Ipp16s)) - (ecParams.pInfo.params.framesize/sizeof(Ipp16s))*frameNum;

      out_buff_cur = out_buff;
      in1_buff_cur = in1_buff;
      in2_buff_cur = in2_buff+ delay; /* shift forward the sin at delay */

      for (i = 0; i < frameNum; i++) {
          ecParams.pUSC_EC_Fxns->CancelEcho(ecParams.objEC, (Ipp16s *)in2_buff_cur,
              (Ipp16s *)in1_buff_cur, (Ipp16s *)out_buff_cur);//4,6,9,11,14,19,21,26,29,31,34,36,39,41,44,46,49,51
          in1_buff_cur += ecParams.pInfo.params.framesize;
          in2_buff_cur += ecParams.pInfo.params.framesize;
          out_buff_cur += ecParams.pInfo.params.framesize;
      }
      for (i = 0; i < tailNum; i++) {
          ippsZero_16s((Ipp16s *)out_buff_cur, tailNum);
      }
   }

   measure_end(&measure);

   if (PostProcessPCMstream((Ipp8s *)out_buff, in_len)) {
       sprintf(pString, "No memory for load of %d bytes convert from linear PCM to special pack value.",in_len);
       OutputInfoString(1, f_log, (const Ipp8s*)pString);
       if(f_log) fclose(f_log);
       return MEMORY_FAIL;
   }
   /* Write output PCM to the output file */
   fwrite(out_buff, 1, in_len, fp_sout);

   for(i=0; i<ecParams.nBanks;i++){
     if(ecParams.pBanks[i].pMem) ippsFree(ecParams.pBanks[i].pMem);
     ecParams.pBanks[i].pMem = NULL;
   }
   if(ecParams.pBanks) { ippsFree(ecParams.pBanks); ecParams.pBanks = NULL; }
   ippsFree(out_buff);

   speech_sec = (in_len / 2 * clParams.nRepeat)/(double)ecParams.pInfo.params.pcmType.sample_frequency;
   measure_output(f_log, &measure, speech_sec);
   sprintf(pString, "Done %d samples of %d Hz PCM wave file (%g sec)\n",
       (in_len>>1) * clParams.nRepeat, ecParams.pInfo.params.pcmType.sample_frequency, speech_sec);
   OutputInfoString(1, f_log, (const Ipp8s*)pString);

   if(clParams.puttocsv) {
       Ipp8s* rinFile;
       Ipp8s* sinFile;
       if ((rinFile = strrchr(clParams.rinFileName, '/')) != NULL) {
           rinFile += 1;
       } else if ((rinFile = strrchr(clParams.rinFileName, '\\')) != NULL) {
           rinFile += 1;
       } else
           rinFile = clParams.rinFileName;
       if ((sinFile = strrchr(clParams.sinFileName, '/')) != NULL) {
           sinFile += 1;
       } else if ((sinFile = strrchr(clParams.sinFileName, '\\')) != NULL) {
           sinFile += 1;
       } else
           sinFile = clParams.sinFileName;
       i=sprintf(pString, clParams.ECName);
       i += sprintf(pString + i,",");
       switch(clParams.alg) {
            case EC_FULLBAND:
                i += sprintf(pString + i,"fullband,");
                break;
            case EC_SUBBAND:
                i += sprintf(pString + i,"subband,");
                break;
            case EC_FASTSUBBAND:
                i += sprintf(pString + i,"fast subband,");
                break;
            default:
                i += sprintf(pString + i,"subband,");
       }
       switch(clParams.adapt) {
            case 2:
                i += sprintf(pString + i,"lite,");
                break;
            default:
                i += sprintf(pString + i,"full,");
       }
       i += sprintf(pString + i,"%d,",clParams.tail);
       i += sprintf(pString + i,"%d,%s,%s,%4.2f,%4.2f",
            ecParams.pInfo.params.pcmType.sample_frequency, rinFile, sinFile, speech_sec,
            measure.speed_in_mhz);
       vm_string_fprintf(f_csv,VM_STRING("%s\n"),pString);
       vm_file_fclose(f_csv);
   }

   ippsFree(in1_buff);
   ippsFree(in2_buff);

   fclose(fp_rin);
   fclose(fp_sin);
   fclose(fp_sout);

   OutputInfoString(1, f_log,"Completed !\n");
   if(f_log) fclose(f_log);
   return 0;
}