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

📄 decoder.c

📁 这是一个平台无关的标准C的AMR解码库
💻 C
字号:

/*************************************************************************
*
*      GSM AMR-NB speech codec   R98   Version 7.6.0   December 12, 2001
*                                R99   Version 3.3.0                
*                                REL-4 Version 4.1.0                
*
********************************************************************************
*
*      File             : decoder.c
*      Purpose          : Speech decoder main program.
*
********************************************************************************
*
*         Usage : decoder  bitstream_file  synth_file
*
*
*         Format for bitstream_file:
*             1 word (2-byte) for the frame type
*               (see frame.h for possible values)
*               Normally, the TX frame type is expected.
*               RX frame type can be forced with "-rxframetype"
*           244 words (2-byte) containing 244 bits.
*               Bit 0 = 0x0000 and Bit 1 = 0x0001
*             1 word (2-byte) for the mode indication
*               (see mode.h for possible values)
*             4 words for future use, currently unused
*
*         Format for synth_file:
*           Synthesis is written to a binary file of 16 bits data.
*
********************************************************************************
*/

/*
********************************************************************************
*                         INCLUDE FILES
********************************************************************************
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "n_proc.h"
#include "amr_dec.h"
#include "cnst.h"

/*
********************************************************************************
*                             MAIN PROGRAM 
********************************************************************************
*/

int main (int argc, char *argv[])
{
  char *progname = argv[0];
  char *fileName = NULL;
  char *serialFileName = NULL;
  int	filelen = 0;
  char *filedata = NULL;
  void *pAMRDEC = NULL;
  int	erro_Code = 0;
  int	frame = 0;
  short	synth[L_FRAME];
  int	synthlen = 0;
  
  FILE *file_syn, *file_serial;

   proc_head ("Decoder");

  /*----------------------------------------------------------------------*
   * check number of arguments                                            *
   *----------------------------------------------------------------------*/
  if (argc != 3)
  {
    fprintf (stderr,
      " Usage:\n\n"
      "   %s  bitstream_file synth_file\n\n",
             progname);
      exit (1);
  }
  
  serialFileName = argv[1];
  fileName = argv[2];

  /*----------------------------------------------------------------------*
   * Open serial bit stream and output speech file                        *
   *----------------------------------------------------------------------*/
  if (strcmp(serialFileName, "-") == 0) {
     file_serial = stdin;
  }
  else if ((file_serial = fopen (serialFileName, "rb")) == NULL)
  {
      fprintf (stderr, "Input file '%s' does not exist !!\n", serialFileName);
      exit (0);
  }
  fprintf (stderr, "Input bitstream file:   %s\n", serialFileName);

  if (strcmp(fileName, "-") == 0) {
     file_syn = stdout;
  }
  else if ((file_syn = fopen (fileName, "wb")) == NULL)
  {
      fprintf (stderr, "Cannot create output file '%s' !!\n", fileName);
      exit (0);
  }
  fprintf (stderr, "Synthesis speech file:  %s\n", fileName);

   /* read serial file */
  fseek(file_serial,0,SEEK_END);
  filelen = ftell(file_serial);
  fseek(file_serial,0,SEEK_SET);
  if (filelen>0) {
	  filedata = (char*)malloc(filelen);
  }
  else{
	  fprintf (stderr, "No memory!!");
	  exit(1);
  }
  fread(filedata, sizeof(char), filelen, file_serial);
  fclose(file_serial);

  /*-----------------------------------------------------------------------*
   * Initialization of decoder                                             *
   *-----------------------------------------------------------------------*/
  pAMRDEC = AMR_dec_Init(filedata,filelen,&erro_Code);
  if (!pAMRDEC)
      exit(-1);
    
  /*-----------------------------------------------------------------------*
   * process serial bitstream frame by frame                               *
   *-----------------------------------------------------------------------*/
  frame = 0;
  synthlen = AMR_dec_Decode(pAMRDEC,L_FRAME,synth);

  while (synthlen>0)
  {
     
     ++frame;
     if ( (frame%50) == 0) {
        fprintf (stderr, "\rframe=%d  ", frame);
     }

     /* write synthesized speech to file */
     if (fwrite (synth, sizeof (short), synthlen, file_syn) != L_FRAME) {
         fprintf(stderr, "\nerror writing output file: %s\n",
                 strerror(errno));
     };
     fflush(file_syn);

	 synthlen = AMR_dec_Decode(pAMRDEC,L_FRAME,synth);
  }
  fprintf (stderr, "\n%d frame(s) processed\n", frame);
  
  /*-----------------------------------------------------------------------*
   * Close down speech decoder                                             *
   *-----------------------------------------------------------------------*/
  AMR_dec_Close(pAMRDEC);
  fclose(file_syn);
  
  return 0;
}

⌨️ 快捷键说明

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