CODER.C
Upload User: meifeng08
Upload Date: 2013-06-18
Package Size: 5304k
Code Size: 4k
Category:

Voice Compress

Development Platform:

C/C++

  1. /* Version 3.3    Last modified: December 26, 1995 */
  2. /*
  3.    ITU-T G.729 Speech Coder     ANSI-C Source Code
  4.    Copyright (c) 1995, AT&T, France Telecom, NTT, Universite de Sherbrooke.
  5.    All rights reserved.
  6. */
  7. /*-------------------------------------------------------------------*
  8.  * Main program of the ITU-T G.729  8 kbit/s encoder.                *
  9.  *                                                                   *
  10.  *    Usage : coder speech_file  bitstream_file                      *
  11.  *-------------------------------------------------------------------*/
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include "typedef.h"
  15. #include "basic_op.h"
  16. #include "ld8k.h"
  17. int main(int argc, char *argv[] )
  18. {
  19.   FILE *f_speech;               /* File of speech data                   */
  20.   FILE *f_serial;               /* File of serial bits for transmission  */
  21.   extern Word16 *new_speech;     /* Pointer to new speech data            */
  22.   Word16 prm[PRM_SIZE];          /* Analysis parameters.                  */
  23.   Word16 serial[SERIAL_SIZE];    /* Output bitstream buffer               */
  24.   Word16 syn[L_FRAME];           /* Buffer for synthesis speech           */
  25.   Word16 i, frame;               /* frame counter */
  26.   printf("n");
  27.   printf("***********     ITU G.729 8 KBIT/S SPEECH CODER    ***********n");
  28.   printf("n");
  29.   printf("------------------- Fixed point C simulation -----------------n");
  30.   printf("n");
  31.   printf("-----------------          Version 3.3        ----------------n");
  32.   printf("n");
  33. /*--------------------------------------------------------------------------*
  34.  * Open speech file and result file (output serial bit stream)              *
  35.  *--------------------------------------------------------------------------*/
  36.   if ( argc != 3 )
  37.     {
  38.        printf("Usage : coder speech_file  bitstream_filen");
  39.        printf("n");
  40.        printf("Format for speech_file:n");
  41.        printf("  Speech is read from a binary file of 16 bits PCM data.n");
  42.        printf("n");
  43.        printf("Format for bitstream_file:n");
  44.        printf("  One (2-byte) synchronization word n");
  45.        printf("  One (2-byte) size word,n");
  46.        printf("  80 words (2-byte) containing 80 bits.n");
  47.        printf("n");
  48.        exit(1);
  49.     }
  50.   if ( (f_speech = fopen(argv[1], "rb")) == NULL) {
  51.      printf("%s - Error opening file  %s !!n", argv[0], argv[1]);
  52.      exit(0);
  53.   }
  54.   printf(" Input speech file    :  %sn", argv[1]);
  55.   if ( (f_serial = fopen(argv[2], "wb")) == NULL) {
  56.      printf("%s - Error opening file  %s !!n", argv[0], argv[2]);
  57.      exit(0);
  58.   }
  59.   printf(" Output bitstream file:  %sn", argv[2]);
  60. /*--------------------------------------------------------------------------*
  61.  * Initialization of the coder.                                             *
  62.  *--------------------------------------------------------------------------*/
  63.   Init_Pre_Process();
  64.   Init_Coder_ld8k();
  65.   for(i=0; i<PRM_SIZE; i++) prm[i] = (Word16)0;
  66.  /* To force the input and output to be time-aligned the variable SYNC
  67.     has to be defined. Note: the test vectors were generated with this option
  68.     disabled
  69.   */
  70. #ifdef SYNC
  71.   /* Read L_NEXT first speech data */
  72.   fread(&new_speech[-L_NEXT], sizeof(Word16), L_NEXT, f_speech);
  73. #ifdef HARDW
  74.     /* set 3 LSB's to zero */
  75.     for(i=0; i < L_NEXT; i++)
  76.       new_speech[-L_NEXT+i] = new_speech[-L_NEXT+i] & 0xFFF8;
  77. #endif
  78.   Pre_Process(&new_speech[-L_NEXT], L_NEXT);
  79. #endif
  80.   /* Loop for each "L_FRAME" speech data. */
  81.   frame =0;
  82.   while( fread(new_speech, sizeof(Word16), L_FRAME, f_speech) == L_FRAME)
  83.   {
  84. #ifdef HARDW
  85.     /* set 3 LSB's to zero */
  86.     for(i=0; i < L_FRAME; i++) new_speech[i] = new_speech[i] & 0xFFF8;
  87. #endif
  88.     Pre_Process(new_speech, L_FRAME);
  89.     Coder_ld8k(prm, syn);
  90.     prm2bits_ld8k( prm, serial);
  91.     if (fwrite(serial, sizeof(Word16), SERIAL_SIZE, f_serial) != SERIAL_SIZE)
  92.       printf("Write Error for frame %dn", frame);
  93.     frame++;
  94.     printf("Frame =%dr", frame);
  95.   }
  96.   return (0);
  97. }