home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Da Capo
/
da_capo_vol1.bin
/
programs
/
amiga
/
misc
/
mpegaudio
/
musicout.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-03-21
|
18KB
|
463 lines
/**********************************************************************
Copyright (c) 1991 MPEG/audio software simulation group, All Rights Reserved
musicout.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 *
* 3/06/91 Douglas Wong rename setup.h to dedef.h *
* removed extraneous variables *
* removed window_samples (now part of *
* filter_samples) *
* 3/07/91 Davis Pan changed output file to "codmusic" *
* 5/10/91 Vish (PRISM) Ported to Macintosh and Unix. *
* Incorporated new "out_fifo()" which *
* writes out last incomplete buffer. *
* Incorporated all AIFF routines which *
* are also compatible with SUN. *
* Incorporated user interface for *
* specifying sound file names. *
* Also incorporated user interface for *
* writing AIFF compatible sound files. *
* 27jun91 dpwe (Aware) Added musicout and &sample_frames as *
* args to out_fifo (were glob refs). *
* Used new 'frame_params' struct. *
* Clean,simplify, track clipped output *
* and total bits/frame received. *
* 7/10/91 Earle Jennings changed to floats to FLOAT *
*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 *
* Additions and revisions are marked *
* with "dhl" for clarity *
* 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. *
*19 aug 92 Soren H. Nielsen Changed MS-DOS file name extensions. *
* 8/27/93 Seymour Shlien, Fixes in Unix and MSDOS ports, *
* Daniel Lauzon, and *
* Bill Truerniet *
**********************************************************************/
#include "common.h"
#include "decoder.h"
#ifdef UNIX
#include <time.h>
#endif
/********************************************************************
/*
/* This part contains the MPEG I decoder for Layers I & II.
/*
/*********************************************************************/
/****************************************************************
/*
/* For MS-DOS user (Turbo c) change all instance of malloc
/* to _farmalloc and free to _farfree. Compiler model hugh
/* Also make sure all the pointer specified are changed to far.
/*
/*****************************************************************/
/*********************************************************************
/*
/* Core of the Layer II decoder. Default layer is Layer II.
/*
/*********************************************************************/
/* Global variable definitions for "musicout.c" */
char *programName;
/* Implementations */
main(argc, argv)
int argc;
char **argv;
{
typedef short PCM[2][3][SBLIMIT];
PCM FAR *pcm_sample;
typedef unsigned int SAM[2][3][SBLIMIT];
SAM FAR *sample;
typedef double FRA[2][3][SBLIMIT];
FRA FAR *fraction;
typedef double VE[2][HAN_SIZE];
VE FAR *w;
Bit_stream_struc bs;
frame_params fr_ps;
layer info;
FILE *musicout;
unsigned long sample_frames;
int i, j, k, stereo, done=FALSE, clip, sync;
int error_protection, crc_error_count, total_error_count;
unsigned int old_crc, new_crc;
unsigned int bit_alloc[2][SBLIMIT], scfsi[2][SBLIMIT],
scale_index[2][3][SBLIMIT];
unsigned long bitsPerSlot, samplesPerFrame, frameNum = 0;
unsigned long frameBits, gotBits = 0;
IFF_AIFF pcm_aiff_data;
char encoded_file_name[MAX_NAME_SIZE];
char decoded_file_name[MAX_NAME_SIZE];
char t[50];
int need_aiff;
int topSb = 0;
#ifdef UNIX
clock_t time_to_decode = clock();
#endif
#ifdef MACINTOSH
console_options.nrows = MAC_WINDOW_SIZE;
argc = ccommand(&argv);
#endif
/* Most large variables are declared dynamically to ensure
compatibility with smaller machines */
pcm_sample = (PCM FAR *) mem_alloc((long) sizeof(PCM), "PCM Samp");
sample = (SAM FAR *) mem_alloc((long) sizeof(SAM), "Sample");
fraction = (FRA FAR *) mem_alloc((long) sizeof(FRA), "fraction");
w = (VE FAR *) mem_alloc((long) sizeof(VE), "w");
fr_ps.header = &info;
fr_ps.tab_num = -1; /* no table loaded */
fr_ps.alloc = NULL;
for (i=0;i<HAN_SIZE;i++) for (j=0;j<2;j++) (*w)[j][i] = 0.0;
programName = argv[0];
if(argc==1) { /* no command line args -> interact */
do {
printf ("Enter encoded file name <required>: ");
gets (encoded_file_name);
if (encoded_file_name[0] == NULL_CHAR)
printf ("Encoded file name is required. \n");
} while (encoded_file_name[0] == NULL_CHAR);
printf (">>> Encoded file name is: %s \n", encoded_file_name);
#ifdef MS_DOS
printf ("Enter MPEG decoded file name <%s>: ",
new_ext(encoded_file_name, DFLT_OPEXT)); /* 92-08-19 shn */
#else
printf ("Enter MPEG decoded file name <%s%s>: ", encoded_file_name,
DFLT_OPEXT);
#endif
gets (decoded_file_name);
if (decoded_file_name[0] == NULL_CHAR) {
#ifdef MS_DOS
/* replace old extension with new one, 92-08-19 shn */
strcpy(decoded_file_name,new_ext(encoded_file_name, DFLT_OPEXT));
#else
strcat (strcpy(decoded_file_name, encoded_file_name), DFLT_OPEXT);
#endif
}
printf (">>> MPEG decoded file name is: %s \n", decoded_file_name);
printf(
"Do you wish to write an AIFF compatible sound file ? (y/<n>) : ");
gets(t);
if (*t == 'y' || *t == 'Y') need_aiff = TRUE;
else need_aiff = FALSE;
if (need_aiff)
printf(">>> An AIFF compatible sound file will be written\n");
else printf(">>> A non-headered PCM sound file will be written\n"