decoder.c

来自「这是G.723和G.729的音频编解码的源代码」· C语言 代码 · 共 170 行

C
170
字号
/* Version 2.0    Last modified: 6/30/95 */

/*
   ITU-T G.729 Speech Coder     ANSI-C Source Code
   Copyright (c) 1995, AT&T, France Telecom, NTT, Universite de Sherbrooke.
   All rights reserved.
*/

/*-----------------------------------------------------------------*
 * Main program of the ITU-T G.729  8 kbit/s decoder.              *
 *                                                                 *
 *    Usage : decoder  bitstream_file  synth_file                  *
 *                                                                 *
 *-----------------------------------------------------------------*/

#include <stdlib.h>
#include <stdio.h>

#include "typedef.h"
#include "basic_op.h"
#include "count.h"
#include "ld8k.h"

 Word16 bad_lsf;        /* bad LSF indicator   */

/*
   This variable should be always set to zero unless transmission errors
   in LSP indices are detected.
   This variable is useful if the channel coding designer decides to
   perform error checking on these important parameters. If an error is
   detected on the  LSP indices, the corresponding flag is
   set to 1 signalling to the decoder to perform parameter substitution.
   (The flags should be set back to 0 for correct transmission).
*/

/*-----------------------------------------------------------------*
 *            Main decoder routine                                 *
 *-----------------------------------------------------------------*/

int main(int argc, char *argv[] )
{
  Word16  synth_buf[L_FRAME+M], *synth; /* Synthesis                   */
  Word16  parm[PRM_SIZE+1];             /* Synthesis parameters        */
  Word16  serial[SERIAL_SIZE];          /* Serial stream               */
  Word16  Az_dec[MP1*2], *ptr_Az;       /* Decoded Az for post-filter  */
  Word16  T0_first;                     /* Pitch lag in 1st subframe   */
  Word16  pst_out[L_FRAME];             /* Postfilter output           */
  Word16  *ptr_out;                     /* pointer on output array     */

  Word16  voicing;                      /* voicing from previous frame */
  Word16  sf_voic;                      /* voicing for subframe        */

  Word16  PARITY;                       /* Disable Parity              */
  Word16  i;
  FILE   *f_syn, *f_serial;

  printf("\n");
  printf("***********     ITU G.729 8 KBIT/S SPEECH CODER    ***********\n");
  printf("\n");
  printf("------------------- Fixed point C simulation -----------------\n");
  printf("\n");
  printf("-----------------          Version 2.0        ----------------\n");
  printf("\n");

   /* Passed arguments */

   if ( argc < 3 || argc > 4)
     {
        printf("Usage :%s bitstream_file  outputspeech_file\n",argv[0]);
        printf("\n");
        printf("Format for bitstream_file:\n");
        printf("  One word (2-byte) to indicate erasure,\n");
        printf("  One word (2-byte) to indicate size,\n");
        printf("  80 words (2-byte) containing 80 bits.\n");
        printf("\n");
        printf("Format for outputspeech_file:\n");
        printf("  Synthesis is written to a binary file of 16 bits data.\n");
        exit( 1 );
     }

   /* Open file for synthesis and packed serial stream */

   if( (f_serial = fopen(argv[1],"rb") ) == NULL )
     {
        printf("%s - Error opening file  %s !!\n", argv[0], argv[1]);
        exit(0);
     }

   if( (f_syn = fopen(argv[2], "wb") ) == NULL )
     {
        printf("%s - Error opening file  %s !!\n", argv[0], argv[2]);
        exit(0);
     }
   /* This allows disabling of the parity check */
   if (argc == 4)
     PARITY = (Word16)atoi(argv[3]);
   else
     PARITY = 1;                /* default is parity on */

   printf("Input bitstream file  :   %s\n",argv[1]);
   printf("Synthesis speech file :   %s\n",argv[2]);
   if (PARITY == 0)
     printf("WARNING: Parity is disabled\n\n");

/*-----------------------------------------------------------------*
 *           Initialization of decoder                             *
 *-----------------------------------------------------------------*/

  for (i=0; i<M; i++) synth_buf[i] = 0;
  synth = synth_buf + M;

  bad_lsf = 0;          /* Initialize bad LSF indicator */
  Init_Decod_ld8k();
  Init_Post_Filter();
  Init_Post_Process();
  Init_WMOPS_counter();
  voicing = 60;


/*-----------------------------------------------------------------*
 *            Loop for each "L_FRAME" speech data                  *
 *-----------------------------------------------------------------*/

  while( fread(serial, sizeof(Word16), SERIAL_SIZE, f_serial) == SERIAL_SIZE)
  {
    Reset_WMOPS_counter();      /* reset WMOPS counter for the new frame */

    bits2prm_ld8k( &serial[2], &parm[1]);

    if (serial[0] == SYNC_WORD) {
       parm[0] = 0;           /* No frame erasure */
    } else {
       parm[0] = 1;           /* frame erased     */
    }

    /* check parity and put 1 in parm[4] if parity error */

    if(PARITY == 1)
      parm[4] = Check_Parity_Pitch(parm[3], parm[4]);
    else
      parm[4] = 0;

    Decod_ld8k(parm, voicing, synth, Az_dec, &T0_first);

    fwc();  /* Decoder functions worst case */


    /* Postfilter */

    voicing = 0;
    ptr_Az = Az_dec;
    for(i=0; i<L_FRAME; i+=L_SUBFR) {
       Post(T0_first, &synth[i], ptr_Az, &pst_out[i], &sf_voic);
       test();
       if (sf_voic != 0) { voicing = sf_voic; move16();}
       ptr_Az += MP1; move16();
    }
    Copy(&synth_buf[L_FRAME], &synth_buf[0], M);
    ptr_out = pst_out;

    Post_Process(pst_out, L_FRAME);

    fwc();                      /* Postfilter functions worst case       */
    WMOPS_output();             /* output WMOPS values for current frame */

    fwrite(ptr_out, sizeof(short), L_FRAME, f_syn);
  }
  return(0);
}

⌨️ 快捷键说明

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