www.pudn.com > g729_audio_encode.rar > coder.c


/* 
   ITU-T G.729 Speech Coder with Annex B    ANSI-C Source Code 
   Version 1.4    Last modified: November 2000 
 
   Copyright (c) 1996, 
   AT&T, France Telecom, NTT, Universite de Sherbrooke, Lucent Technologies, 
   Rockwell International 
   All rights reserved. 
*/ 
 
 
/*-------------------------------------------------------------------* 
 * Main program of the ITU-T G.729  8 kbit/s encoder.                * 
 *                                                                   * 
 *    Usage : coder speech_file  bitstream_file                      * 
 *-------------------------------------------------------------------*/ 
 
#include  
#include  
 
#include "typedef.h" 
#include "basic_op.h" 
#include "ld8k.h" 
#include "dtx.h" 
#include "octet.h" 
 
int main(int argc, char *argv[] ) 
{ 
  FILE *f_speech;               /* File of speech data                   */ 
  FILE *f_serial;               /* File of serial bits for transmission  */ 
 
  extern Word16 *new_speech;     /* Pointer to new speech data            */ 
 
  Word16 prm[PRM_SIZE+1];        /* Analysis parameters.                  */ 
  Word16 serial[SERIAL_SIZE];    /* Output bitstream buffer               */ 
  Word16 syn[L_FRAME];           /* Buffer for synthesis speech           */ 
 
  Word16 i, frame;               /* frame counter */ 
  Word32 count_frame; 
 
  /* For G.729B */ 
  Word16 nb_words; 
  Word16 vad_enable; 
   
  printf("\n"); 
  printf("***********     ITU G.729 8 KBIT/S SPEECH CODER    ***********\n"); 
  printf("                        (WITH ANNEX B)                        \n"); 
  printf("\n"); 
  printf("------------------- Fixed point C simulation -----------------\n"); 
  printf("\n"); 
  printf("------------------        Version 1.4         ----------------\n"); 
  printf("\n"); 
 
 
/*--------------------------------------------------------------------------* 
 * Open speech file and result file (output serial bit stream)              * 
 *--------------------------------------------------------------------------*/ 
 
  if ( argc != 4 ) 
    { 
       printf("Usage :%s speech_file  bitstream_file  VAD_flag\n",argv[0]); 
       printf("\n"); 
       printf("Format for speech_file:\n"); 
       printf("  Speech is read from a binary file of 16 bits PCM data.\n"); 
       printf("\n"); 
       printf("Format for bitstream_file:\n"); 
       printf("  One (2-byte) synchronization word \n"); 
       printf("  One (2-byte) size word,\n"); 
       printf("  80 words (2-byte) containing 80 bits.\n"); 
       printf("\n"); 
       printf("VAD flag:\n"); 
       printf("  0 to disable the VAD\n"); 
       printf("  1 to enable the VAD\n"); 
       exit(1); 
    } 
 
  if ( (f_speech = fopen(argv[1], "rb")) == NULL) { 
     printf("%s - Error opening file  %s !!\n", argv[0], argv[1]); 
     exit(0); 
  } 
  printf(" Input speech file    :  %s\n", argv[1]); 
 
  if ( (f_serial = fopen(argv[2], "wb")) == NULL) { 
     printf("%s - Error opening file  %s !!\n", argv[0], argv[2]); 
     exit(0); 
  } 
  printf(" Output bitstream file:  %s\n", argv[2]); 
 
  vad_enable = (Word16)atoi(argv[3]); 
  if (vad_enable == 1) 
    printf(" VAD enabled\n"); 
  else 
    printf(" VAD disabled\n"); 
 
#ifndef OCTET_TX_MODE 
  printf(" OCTET TRANSMISSION MODE is disabled\n"); 
#endif 
 
/*--------------------------------------------------------------------------* 
 * Initialization of the coder.                                             * 
 *--------------------------------------------------------------------------*/ 
 
  Init_Pre_Process(); 
  Init_Coder_ld8k(); 
  for(i=0; i