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

📄 towave.c

📁 DSP c64优化 ACT spraa14 mp3优化实例 与其优化应用报告配套
💻 C
📖 第 1 页 / 共 2 页
字号:
/*____________________________________________________________________________
        
        FreeAmp - The Free MP3 Player

        MP3 Decoder originally Copyright (C) 1995-1997 Xing Technology
        Corp.  http://www.xingtech.com

        Portions Copyright (C) 1998-1999 EMusic.com

        This program is free software; you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
        the Free Software Foundation; either version 2 of the License, or
        (at your option) any later version.

        This program is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU General Public License for more details.

        You should have received a copy of the GNU General Public License
        along with this program; if not, write to the Free Software
        Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
        
____________________________________________________________________________*/

/* ------------------------------------------------------------------------

      NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE

        This file exists for reference only. It is not actually used
        in the FreeAmp project. There is no need to mess with this 
        file. There is no need to flatten the beavers, either.

      NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE

*---- towave.c --------------------------------------------
  32 bit version only

decode mpeg Layer I/II/III file using portable ANSI C decoder,
output to pcm wave file.

mod 8/19/98 decode 22 sf bands

mod 5/14/98  allow mpeg25 (dec8 not supported for mpeg25 samp rate)

mod 3/4/98 bs_trigger  bs_bufbytes  made signed, unsigned may 
            not terminate properly.  Also extra test in bs_fill.

mod 8/6/96 add 8 bit output to standard decoder

ver 1.4 mods 7/18/96 32 bit and add asm option

mods 6/29/95  allow MS wave file for u-law.  bugfix u-law table dec8.c

mods 2/95 add sample rate reduction, freq_limit and conversions.
          add _decode8 for 8Ks output, 16bit 8bit, u-law output.
          add additional control parameters to init.
          add _info function

mod 5/12/95 add quick window cwinq.c

mod 5/19/95 change from stream io to handle io

mod 11/16/95 add Layer I

mod 1/5/95   integer overflow mod iup.c

ver 1.3
mod 2/5/96   portability mods
             drop Tom and Gloria pcm file types

ver 2.0
mod 1/7/97   Layer 3 (float mpeg-1 only)
    2/6/97   Layer 3 MPEG-2

ver 3.01     Layer III bugfix crc problem 8/18/97
ver 3.02     Layer III fix wannabe.mp3 problem 10/9/97
ver 3.03     allow mpeg 2.5  5/14/98
  
Decoder functions for _decode8 are defined in dec8.c.  Useage
is same as regular decoder.

Towave illustrates use of decoder.  Towave converts
mpeg audio files to 16 bit (short) pcm.  Default pcm file
format is wave. Other formats can be accommodated by
adding alternative write_pcm_header and write_pcm_tailer
functions.  The functions kbhit and getch used in towave.c
may not port to other systems.

The decoder handles all mpeg1 and mpeg2 Layer I/II  bitstreams.  

For compatability with the asm decoder and future C versions,
source code users are discouraged from making modifications
to the decoder proper.  MS Windows applications can use wrapper
functions in a separate module if decoder functions need to
be exported.

NOTE additional control parameters.

mod 8/6/96 standard decoder adds 8 bit output

decode8 (8Ks output) convert_code:
   convert_code = 4*bit_code + chan_code
       bit_code:   1 = 16 bit linear pcm
                   2 =  8 bit (unsigned) linear pcm
                   3 = u-law (8 bits unsigned)
       chan_code:  0 = convert two chan to mono
                   1 = convert two chan to mono
                   2 = convert two chan to left chan
                   3 = convert two chan to right chan

decode (standard decoder) convert_code:
             0 = two chan output
             1 = convert two chan to mono
             2 = convert two chan to left chan
             3 = convert two chan to right chan
     or with 8 = 8 bit output 
          (other bits ignored)

decode (standard decoder) reduction_code:
             0 = full sample rate output
             1 = half rate
             2 = quarter rate

-----------------------------------------------------------*/
#include <stdlib.h>
#include <stdio.h>
#include <float.h>
#include <math.h>
#include <string.h>
#include "itype.h"

#include "mhead.h"                /* mpeg header structure, decode protos */

#define NEED_KBHIT

#include "port.h"

#define IN_FILE   "./hi_o_03e.mp2"

static char default_file[] = IN_FILE;
static char default_outfile[] = "none";

/*********  bitstream buffer */
#ifdef __TMS320C55X__ /* Put this in BSS instead of on the heap */
#define BS_BUFBYTES 8000U
static unsigned char bs_buffer[BS_BUFBYTES];
#else
#define BS_BUFBYTES 10000U
static unsigned char *bs_buffer = NULL;
#endif /* __TMS320C55X__ */

static unsigned char *bs_bufptr;
static int bs_trigger;
static int bs_bufbytes;
static FILE *handle = NULL;

/********************** */

/********  pcm buffer ********/
#ifdef __TMS320C55X__
#define PCM_BUFBYTES  8000U
static char pcm_buffer[PCM_BUFBYTES];
#else
#define PCM_BUFBYTES  10000U
static char *pcm_buffer;
#endif /* __TMS320C55X__ */

static unsigned int pcm_bufbytes;

/****************************/
static int bs_fill();

int frame_cnt = 0;

static int out_mpeg_info(MPEG_HEAD * h, INT32 bitrate_arg);
int ff_decode(char *filename,
              char *fileout,
              int reduction_code,
              int convert_code,
              int decode8_flag,
              int freq_limit,
              int integer_decode);
int cvt_to_wave_test();

/*------------------------------------------*/
main()
{
   int i, k;
   char *filename;
   char *fileout;
   int convert_code;
   int reduction_code;
   int freq_limit;
   int integer_decode;
   int decode8_flag;                /* decode to 8KHz */

   printf(
            "\n  file-file MPEG Layer I/II/III audio decode v3.04/32"
            "\n Copyright 1995-98 Xing Technology Corp."
            "\n"
      );

/****** process command line args */
   filename = default_file;
   fileout = default_outfile;
   convert_code = 0;
   reduction_code = 0;
   freq_limit = 24000;
   integer_decode = 1;
   decode8_flag = 0;                /* decode to 8KHz */

/******** decode *********/
   ff_decode(filename, fileout,
             reduction_code, convert_code, decode8_flag,
             freq_limit, integer_decode);
/*************************/

   printf("\nDone\n");
   return 0;
}

/*-------------------------------------------------------------*/
int ff_decode(char *filename, char *fileout,
              int reduction_code, int convert_code, int decode8_flag,
              int freq_limit, int integer)
{
   int framebytes;
   int u;
   MPEG_HEAD head;
   IN_OUT x;
   int in_bytes, out_bytes;
   DEC_INFO decinfo;
   INT32 bitrate;

/*------------------------------------------*/
   typedef struct
   {
      int (*decode_init) (MPEG_HEAD * h, int framebytes_arg,
                          int reduction_code, int transform_code,
                          int convert_code, int freq_limit);
      void (*decode_info) (DEC_INFO * info);
        IN_OUT(*decode) (unsigned char *bs, short *pcm);
   }
   AUDIO;
   static AUDIO audio;

   static AUDIO audio_table[2][2] =
   {
      {
         {NULL, NULL, NULL},
         {NULL, NULL, NULL},
      },
      {
         {i_audio_decode_init, i_audio_decode_info, i_audio_decode},
         {NULL, NULL, NULL},
      }
   };

/*------------------------------------------*/

⌨️ 快捷键说明

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