home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Da Capo
/
da_capo_vol1.bin
/
programs
/
amiga
/
misc
/
mpegaudio
/
decode.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-03-21
|
24KB
|
678 lines
/**********************************************************************
Copyright (c) 1991 MPEG/audio software simulation group, All Rights Reserved
decode.c
**********************************************************************/
/**********************************************************************
* MPEG/audio coding/decoding software, work in progress *
* NOT for public distribution until verified and approved by the *
* MPEG/audio committee. For further information, please contact *
* Davis Pan, 508-493-2241, e-mail: pan@3d.enet.dec.com *
* *
* VERSION 3.9 *
* changes made since last update: *
* date programmers comment *
* 2/25/91 Douglas Wong, start of version 1.0 records *
* Davis Pan *
* 3/06/91 Douglas Wong rename: setup.h to dedef.h *
* dfilter to defilter *
* dwindow to dewindow *
* integrated "quantizer", "scalefactor" *
* combined window_samples routine into *
* filter samples *
* 3/31/91 Bill Aspromonte replaced read_filter by *
* create_syn_filter and introduced a *
* new Sub-Band Synthesis routine called *
* SubBandSynthesis() *
* 5/10/91 Vish (PRISM) Ported to Macintosh and Unix. *
* Changed "out_fifo()" so that last *
* unfilled block is also written out. *
* "create_syn_filter()" was modified so *
* that calculation precision is same as *
* in specification tables. *
* Changed "decode_scale()" to reflect *
* specifications. *
* Removed all routines used by *
* "synchronize_buffer()". This is now *
* replaced by "seek_sync()". *
* Incorporated Jean-Georges Fritsch's *
* "bitstream.c" package. *
* Deleted "reconstruct_sample()". *
* 27jun91 dpwe (Aware) Passed outFile and &sampFrames as *
* args to out_fifo() - were global. *
* Moved "alloc_*" reader to common.c. *
* alloc, sblimit, stereo passed via new *
* 'frame_params struct (were globals). *
* Added JOINT STEREO decoding, lyrs I&II*
* Affects: decode_bitalloc,buffer_samps *
* Plus a few other cleanups. *
* 6/10/91 Earle Jennings conditional expansion added in *
* II_dequantize_sample to handle range *
* problems in MSDOS version *
* 8/8/91 Jens Spille Change for MS-C6.00 *
*10/1/91 S.I. Sudharsanan, Ported to IBM AIX platform. *
* Don H. Lee, *
* Peter W. Farrett *
*10/3/91 Don H. Lee implemented CRC-16 error protection *
* newly introduced functions are *
* buffer_CRC and recover_CRC_error. *
* 2/11/92 W. Joseph Carter Ported new code to Macintosh. Most *
* important fixes involved changing *
* 16-bit ints to long or unsigned in *
* bit alloc routines for quant of 65535 *
* and passing proper function args. *
* Removed "Other Joint Stereo" option *
* and made bitrate be total channel *
* bitrate, irrespective of the mode. *
* Fixed many small bugs & reorganized. *
* 7/27/92 Juan Pineda Bug fix in SubBandSynthesis() *
**********************************************************************/
#include "common.h"
#include "decoder.h"
/***************************************************************
/*
/* This module contains the core of the decoder ie all the
/* computational routines. (Layer I and II only)
/* Functions are common to both layer unless
/* otherwise specified.
/*
/***************************************************************/
/*****************************************************************
/*
/* The following routines decode the system information
/*
/****************************************************************/
/************ Layer I, Layer II & Layer III ******************/
void decode_info(bs, fr_ps)
Bit_stream_struc *bs;
frame_params *fr_ps;
{
layer *hdr = fr_ps->header;
hdr->version = get1bit(bs);
hdr->lay = 4-getbits(bs,2);
hdr->error_protection = !get1bit(bs); /* error protect. TRUE/FALSE */
hdr->bitrate_index = getbits(bs,4);
hdr->sampling_frequency = getbits(bs,2);
hdr->padding = get1bit(bs);
hdr->extension = get1bit(bs);
hdr->mode = getbits(bs,2);
hdr->mode_ext = getbits(bs,2);
hdr->copyright = get1bit(bs);
hdr->original = get1bit(bs);
hdr->emphasis = getbits(bs,2);
}
/*******************************************************************
/*
/* The bit allocation information is decoded. Layer I
/* has 4 bit per subband whereas Layer II is Ws and bit rate
/* dependent.
/*
/********************************************************************/
/**************************** Layer II *************/
void II_decode_bitalloc(bs, bit_alloc, fr_ps)
Bit_stream_struc *bs;
unsigned int bit_alloc[2][SBLIMIT];
frame_params *fr_ps;
{
int i,j;
int stereo = fr_ps->stereo;
int sblimit = fr_ps->sblimit;
int jsbound = fr_ps->jsbound;
al_table *alloc = fr_ps->alloc;
for (i=0;i<jsbound;i++) for (j=0;j<stereo;j++)
bit_alloc[j][i] = (char) getbits(bs,(*alloc)[i][0].bits);
for (i=jsbound;i<sblimit;i++) /* expand to 2 channels */
bit_alloc[0][i] = bit_alloc[1][i] =
(char) getbits(bs,(*alloc)[i][0].bits);
for (i=sblimit;i<SBLIMIT;i++) for (j=0;j<stereo;j++)
bit_alloc[j][i] = 0;
}
/**************************** Layer I *************/
void I_decode_bitalloc(bs, bit_alloc, fr_ps)
Bit_stream_struc *bs;
unsigned int bit_alloc[2][SBLIMIT];
frame_params *fr_ps;
{
int i,j;
int stereo = fr_ps->stereo;
int sblimit = fr_ps->sblimit;
int jsbound = fr_ps->jsbound;
int b;
for (i=0;i<jsbound;i++) for (j=0;j<stereo;j++)
bit_alloc[j][i] = getbits(bs,4);
for (i=jsbound;i<SBLIMIT;i++) {
b = getbits(bs,4);
for (j=0;j<stereo;j++)
bit_alloc[j][i] = b;
}
}
/*****************************************************************
/*
/* The following two functions implement the layer I and II
/* format of scale factor extraction. Layer I involves reading
/* 6 bit per subband as scale factor. Layer II requires reading
/* first the scfsi which in turn indicate the number of scale factors
/* transmitted.
/* Layer I : I_decode_scale
/* Layer II : II_decode_scale
/*
/****************************************************************/
/************************** Layer I stuff ************************/
void I_decode_scale(bs, bit_alloc, scale_index, fr_ps)
Bit_stream_struc *bs;
unsigned int bit_alloc[2][S