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

📄 lfadec.c

📁 aac解码程序
💻 C
字号:
/****************************************************************************                  (c) copyright Coding Technologies (2007)                               All Rights Reserved This software module was developed by Coding Technologies (CT). This is company confidential information and the property of CT, and can not be reproduced or disclosed in any form without written authorization of CT. Those intending to use this software module for other purposes are advised that this infringe existing or pending patents. CT has no liability for use of this software module or derivatives thereof in any implementation. Copyright is not released for any means.  CT retains full right to use the code for its own purpose, assign or sell the code to a third party and to inhibit any user or third party from using the code. This copyright notice must be included in all copies or derivative works. REMARK: For convenience we are using an audio library whereas sound files and/or soundcard output can easily be handled. This audiolibrary is also included in the delivery to allow compilation and testing of this sample application program. $Id: lfadec.c,v 1.1.2.4 2007/01/12 14:47:51 boe Exp $*******************************************************************************//* ------------------------ includes --------------------------------------*/#include <stdio.h>#include <string.h>#include <stdlib.h>      /* atoi()                            */#include "liblfadec.h"   /* the aacPlus (LFA) decoder library */#include "au_channel.h"  /* the audio I/O library             *//*-------------------------------------------------------------------------*//***************************************************************************\ * *   functionname: main *   description : sample LFA decoder program * *   returns : * *   input   :     argc, argv *   output  : *\***************************************************************************/int main (int argc, char *argv[]){  int  err = 0;  int  lenAsf;  int  subchannelIndex;  unsigned char inputBuffer[8192];  /* this is a sufficient big buffer for max. bitrate ~170kbps */  unsigned int  inputBufferSize;  short         outputBuffer[2*6*960];  /* big enough for 6 stereo 960AAC-AU output samples */  int           asfSamples;  int           asfStatus;  FILE *lfaFile = NULL;  char outFile[512];  HANDLE_LFADECODER hDecoder = NULL;  /* the aacPlus (LFA) decoder handle */  LFADEC_ERROR      result;  char *versionInfo;  hAudioChannel audioOut = NULL;          /* the audio output handle         */  AuChanInfo    audioOutInfo;             /* info structure for audio output */  AuChanType    audioOutType;             /* type specifier to audio output  */  AuChanError   audioError = AU_CHAN_OK;  /* error code of the audio I/O lib */  /* copyright information */  fprintf(stderr,          "\n"          "--- Coding Technologies aacPlus decoder library ---\n"          "    sample application for the LFA transport\n"          "    Build Date:  "__DATE__"\n"          "    Copyright (c) Coding Technologies 2006\n"          "    Do not distribute!\n\n");  versionInfo = DABaacPlusDecGetVersionInfo();  if (*versionInfo)    fprintf(stderr, "Library %s\n\n", versionInfo);  /* check arguments, print usage */  if (argc != 2 && argc != 3) {    fprintf(stderr, "Usage: %s <inputfile> [<outputfile>]\n", argv [0]);    fprintf(stderr, "       for real time output drop the outputfilename\n\n");    err = 1;    goto cleanup;  }  outFile[0] = '\0';  if (argc == 3)    strcpy(outFile, argv[2]);  /* open input file */  lfaFile = fopen(argv[1], "rb");  if (lfaFile == NULL) {    fprintf(stderr, "Failed to open input file %s\n", argv[1]);    err = 1;    goto cleanup;  }  /* derive lenAsf and subchannelIndex from filename */  {    int   chbr;    char *pStr = strstr(argv[1], "chbr");    if (!pStr) {      fprintf(stderr, "Filename of input file (%s) does not indicate the sub-channel bitrate\n", argv[1]);      err = 1;      goto cleanup;    }    chbr            = atoi(pStr+4);    lenAsf          = chbr/8 * 110;    subchannelIndex = chbr/8;  }  /* open decoder */  result = DABaacPlusDecOpen(&hDecoder, subchannelIndex);  if (result != LFADEC_OK) {    fprintf(stderr, "DABaacPlusDecOpen() failed (%i)\n", result);    err = 1;    goto cleanup;  }  /* open audio device */  /* set audio output values */  audioOutInfo.valid             = 1;  audioOutInfo.fpScaleFactor     = 1.0;  audioOutInfo.nChannels         = 2;      /* for the LFA tests we know that we always have stereo output ... */  audioOutInfo.sampleRate        = 48000;  /* for the LFA tests we know that we always have 48 kHz output sampling rate ... */  audioOutInfo.bitsPerSample     = 16;  if (outFile[0] == '\0') {    /* real time output */    audioOutInfo.typeInfo.rt.level = 200;    audioOutType = TYPE_RT;  }  else {    audioOutType = TYPE_AUTODETECT;    /* TYPE_AUTODETECT means:       try to write an audio header as specified by the output name ending,       otherwise use default values */  }  audioError = AuChannelOpen(&audioOut, outFile, AU_CHAN_WRITE, &audioOutType, &audioOutInfo);  if (audioError) {    fprintf(stderr, "Failed to open audio device. Error: %d\n", audioError);    err = 1;    goto cleanup;  }  /*   * decoding loop   */  while (1) {    int wSamples;    /* read LFA audio super frame payload */    inputBufferSize = fread(inputBuffer, 1, lenAsf, lfaFile);    if (inputBufferSize != (unsigned int)lenAsf) {      if (feof(lfaFile)) {        fprintf(stderr, "\nEnd of input file reached\n");      }      else {        fprintf(stderr, "Failed to read from input file %s\n", argv[1]);        err = 1;      }      goto cleanup;    }    result = DABaacPlusDecDecodeSuperframe(hDecoder,                                           inputBuffer,                                           outputBuffer,                                           &asfSamples,                                           &asfStatus);    if (result != LFADEC_OK) {      fprintf(stderr, "DABaacPlusDecDecodeSuperframe() error (%i)\n", result);      err = 1;      goto cleanup;    }    /* write audio signal to wave file or audio device */    audioError = AuChannelWriteShort(audioOut,                                     outputBuffer,                                     asfSamples * 2,  /* (currently) only stereo output */                                     &wSamples);    if (audioError) {      fprintf(stderr, "Failed to write to audio device. Error: %d\n", audioError);      err = 1;      goto cleanup;    }  } cleanup:  if (lfaFile)    fclose(lfaFile);  if (audioOut)    AuChannelClose(audioOut);  if (hDecoder)    DABaacPlusDecClose(&hDecoder);  return err;}

⌨️ 快捷键说明

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