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

📄 gsm_hr_bak.htm

📁 这是Half rate speech(GSM 06.20)
💻 HTM
📖 第 1 页 / 共 2 页
字号:

  strcpy(decpath,"tmp.dec");
  reid(codpaths,decpath);

 /* In this section the *.dec files are decode and *.out files are created */

  pfileInFile1 = fopen(decpath, "rb");
  strcpy(outpath,"tmp.out");
  pfileInFile2 = fopen(outpath, "wb");

  if (pfileInFile1 == NULL)
  {
	printf("error: can not open file %s\n", decpath);
	exit(1);
  }
  if (pfileInFile2 == NULL)
  {
	printf("error: can not open file %s\n", outpath);
	exit(1);
  }

  puts("\n\n");
  puts("   ****************************************");
  puts("   *                                      *");
  puts("   *      GSM Half-Rate Speech Coder      *");
  puts("   *                                      *");
  puts("   *                                      *");
  printf("   *        %s            *\n", VERSION);
  printf("   *        %s            *\n", DATE);
  puts("   *                                      *");
  puts("   ****************************************");
  puts("\n");


  printf("option:       ");
  puts("dec (speech decoder)");

  if (giDTXon)
	printf("DTX mode:     enabled\n");
  else
	printf("DTX mode:     disabled\n");

  printf("input file:   %s\n", decpath);
  printf("output file:  %s\n\n", outpath);



								/* decode */

	  /* start the decoder and receive DTX in the home state */
	  /* --------------------------------------------------- */

	  resetDec();

	  /* decode:  synthesize speech */
	  /* -------------------------- */

	  for (giFrmCnt = 1, iDoneFrm = 0;
		   !iDoneFrm && giFrmCnt <= iMaxNumFrms;
		   giFrmCnt++)
	  {

#ifndef SILENT
		printf("decoding frame %d \r", giFrmCnt);
#endif

		if (decode(pfileInFile1, pfileInFile2))
		  iDoneFrm = 1;
	  }

	  if (iDoneFrm)
		giFrmCnt--;

	  printf(" %d speech frames decoded\n", giFrmCnt - 1);

  fclose(pfileInFile1);
  fclose(pfileInFile2);

  /* In this section the *.out file must change to the *.wav file */
/*The header first removed is added to the *.out file to make the *.wav file*/

  pfileInFile1 = fopen(inwavpath, "rb");
  if (pfileInFile1==NULL)
  {
	  printf("Cannot open %s as input file.\n",inwavpath);
	  exit(0);
  }
  pfileInFile2 = fopen(outpath, "rb");
  if (pfileInFile2==NULL)
  {
	  printf("Cannot open %s as input file.\n",outpath);
	  exit(0);
  }
  pfileOutFile = fopen(outwavpath, "wb");
  if (pfileOutFile==NULL)
  {
	  printf("Cannot open %s as output file.\n",outwavpath);
	  exit(0);
  }
  i=fseek(pfileInFile1,0L,0);
  if (i!=0)
  {
	  printf("Cannot fseek %s",inwavpath);
	  exit(0);
  }
  i=fseek(pfileInFile2,0L,0);
  if (i!=0)
  {
	  printf("Cannot fseek %s",outpath);
	  exit(0);
  }
  i=fread((char *) header, 1,NUM_HEADER, pfileInFile1);
  if (i!=NUM_HEADER)
  {
	  printf("Can not read the header of %s",inwavpath);
	  exit(0);
  }
  fwrite((char *) header, 1,NUM_HEADER, pfileOutFile);
  iNumRead1=NUM_SAMPLES;
  cntr_fr=0;
  while (iNumRead1==NUM_SAMPLES)
  {
	   i=fread((char *) pswSamplesRead2, sizeof (Shortword),
						NUM_SAMPLES, pfileInFile1);

	   iNumRead1 = fread((char *) pswSamplesRead1, sizeof (Shortword),
						NUM_SAMPLES, pfileInFile2);
	   if(iNumRead1==NUM_SAMPLES)
	   {
		   fwrite((char *) pswSamplesRead1, sizeof (Shortword),
						NUM_SAMPLES, pfileOutFile);
		   cntr_fr++;
	   }
	   else
		   fwrite((char *) pswSamplesRead2, sizeof (Shortword),
						i, pfileOutFile);

  }
  printf("Output file %s has %d frames.",outpath,cntr_fr);
  fclose(pfileInFile1);
  fclose(pfileInFile2);
  fclose(pfileOutFile);

  return (0);
}

/**************************************************************************
 *
 *   FUNCTION NAME:  decode
 *
 *   PURPOSE:
 *      Reads in one frame of speech parameters and outputs one frame of
 *      synthesized speech.  Resets the decoder to the home state if the
 *      Decoder Homing Frame pattern is detected.
 *
 *   INPUT:
 *      pfileDec        speech parameter input file.
 *
 *   OUTPUT:
 *      pfileSpeechOut  synthesized speech file
 *
 *   RETURN:
 *      0               successfully synthesized a complete frame of speech
 *      1               failed to synthesize a complete frame of speech
 *
 *   REFERENCES: Sub-clause 4.2 of GSM Recomendation 06.20
 *
 *   KEYWORDS:
 *      pfileDec, pfileSpeechOut
 **************************************************************************/

int    decode(FILE *pfileDec, FILE *pfileSpeechOut) /*OK*/
{

/*_________________________________________________________________________
 |                                                                         |
 |                            Local Constants                              |
 |_________________________________________________________________________|
*/

/* These constants define the number of consecutive */
/* parameters that decoderHomingFrameTest checks.   */
/* -------------------------------------------------*/

#define  WHOLE_FRAME  18
#define  TO_FIRST_SUBFRAME  9

/*_________________________________________________________________________
 |                                                                         |
 |                            Static Variables                             |
 |_________________________________________________________________________|
*/
  static Shortword pswSpeechPara[22],
         pswDecodedSpeechFrame[F_LEN];

  static int reset_flag_decoder_old = 1;

/*_________________________________________________________________________
 |                                                                         |
 |                            Automatic Variables                          |
 |_________________________________________________________________________|
*/
  int    i,
         reset_flag_decoder;

/*_________________________________________________________________________
 |                                                                         |
 |                              Executable Code                            |
 |_________________________________________________________________________|
*/

  if (readDecfile(pfileDec, pswSpeechPara))
    return (1);

  if(reset_flag_decoder_old)
    reset_flag_decoder=decoderHomingFrameTest(pswSpeechPara,
					      TO_FIRST_SUBFRAME);
  else
    reset_flag_decoder=0;

  if (reset_flag_decoder && reset_flag_decoder_old)
  {
    /* force the output to be the encoder homing frame pattern */

    for (i = 0; i < F_LEN; i++)
      pswDecodedSpeechFrame[i] = EHF_MASK;
  }
  else
  {
    speechDecoder(pswSpeechPara, pswDecodedSpeechFrame);
  }

  speechDecoderHostInterface(pswDecodedSpeechFrame, pfileSpeechOut);

  if(!reset_flag_decoder_old)
    reset_flag_decoder=decoderHomingFrameTest(pswSpeechPara, WHOLE_FRAME);

  if (reset_flag_decoder)
    resetDec();                        /* bring the decoder and receive DTX
                                        * to the home state */

  reset_flag_decoder_old = reset_flag_decoder;

  return (0);
}

/**************************************************************************
 *
 *   FUNCTION NAME:  encode
 *
 *   PURPOSE:
 *      Reads in one frame of speech samples and outputs one frame of
 *      speech parameters.  Resets the encoder to the home state if the
 *      Encoder Homing Frame pattern is detected.
 *
 *   INPUT:
 *      pfileSpeechIn   speech file
 *
 *   OUTPUT:
 *      pfileEnc        speech, encoded paramater data
 *
 *   RETURN:
 *      0                successfully wrote a complete frame of data
 *      1                failed to write a complete frame of data
 *
 *   REFERENCES: Sub-clause 4.1 of GSM Recomendation 06.20
 *
 *   KEYWORDS:
 *      pfileSpeechIn, pfileEnc
 **************************************************************************/

int    encode(FILE *pfileSpeechIn, FILE *pfileEnc)
{

/*_________________________________________________________________________
 |                                                                         |
 |                            Static Variables                             |
 |_________________________________________________________________________|
*/
  static Shortword pswSpeechPara[20];
  static Shortword pswSpeechBuff[F_LEN];

/*_________________________________________________________________________
 |                                                                         |
 |                            Automatic Variables                          |
 |_________________________________________________________________________|
*/
  int    iNumRead,i,
		 reset_flag;

/*_________________________________________________________________________
 |                                                                         |
 |                              Executable Code                            |
 |_________________________________________________________________________|
*/

  iNumRead = hostEncoderInterface(pfileSpeechIn, F_LEN, &pswSpeechBuff[0]);

/*  for (i=0;i<iNumRead;i++)
	  printf("%d  ",pswSpeechBuff[i]);*/

  if (iNumRead < F_LEN)
	return (1);

  reset_flag = encoderHomingFrameTest(&pswSpeechBuff[0]);

  speechEncoder(&pswSpeechBuff[0], pswSpeechPara);
/*  printf("\n");
  for (i=0;i<20;i++)
  {
	   printf("%X\n",pswSpeechPara[i]);
	   getch();
  }*/
  if (writeEncfile(pswSpeechPara, pfileEnc) != 20)
	return (1);

  if (reset_flag)
	resetEnc();                        /* Bring the encoder, VAD, and DTX to
										* the home state */

  return (0);
}
</PRE></BODY></HTML>

⌨️ 快捷键说明

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