amiga_mpega.c

Go to the documentation of this file.
00001 /* MPGLIB replacement using mpega.library (AmigaOS)
00002  * Written by Thomas Wenzel and Sigbjrn (CISC) Skj�et.
00003  *
00004  * Big thanks to St�hane Tavernard for mpega.library.
00005  *
00006  */
00007 
00008 /* $Id: amiga_mpega.c,v 1.3 2005/11/01 13:01:56 robert Exp $ */
00009 
00010 #ifdef HAVE_CONFIG_H
00011 #include <config.h>
00012 #endif
00013 
00014 #ifdef AMIGA_MPEGA
00015 
00016 #define __USE_SYSBASE
00017 #include "lame.h"
00018 #include <stdio.h>
00019 #include <stdlib.h>
00020 
00021 /* We need a small workaround here so GCC doesn't fail upon redefinition. :P */
00022 #define FLOAT _FLOAT
00023 #include <proto/exec.h>
00024 #include <proto/mpega.h>
00025 #undef _FLOAT
00026 
00027 #ifndef __GNUC__
00028 #include <dos.h>
00029 #endif
00030 
00031 struct Library *MPEGABase = NULL;
00032 MPEGA_STREAM *mstream = NULL;
00033 MPEGA_CTRL mctrl;
00034 
00035 static const int smpls[2][4] = {
00036 /* Layer x  I   II   III */
00037     {0, 384, 1152, 1152}, /* MPEG-1     */
00038     {0, 384, 1152, 576} /* MPEG-2(.5) */
00039 };
00040 
00041 
00042 #ifndef __GNUC__
00043 static int
00044 break_cleanup(void)
00045 {
00046     /* Dummy break function to make atexit() work. :P */
00047     return 1;
00048 }
00049 #endif
00050 
00051 static void
00052 exit_cleanup(void)
00053 {
00054     if (mstream) {
00055         MPEGA_close(mstream);
00056         mstream = NULL;
00057     }
00058     if (MPEGABase) {
00059         CloseLibrary(MPEGABase);
00060         MPEGABase = NULL;
00061     }
00062 }
00063 
00064 
00065 int
00066 lame_decode_initfile(const char *fullname, mp3data_struct * mp3data)
00067 {
00068     mctrl.bs_access = NULL;
00069 
00070     mctrl.layer_1_2.mono.quality = 2;
00071     mctrl.layer_1_2.stereo.quality = 2;
00072     mctrl.layer_1_2.mono.freq_div = 1;
00073     mctrl.layer_1_2.stereo.freq_div = 1;
00074     mctrl.layer_1_2.mono.freq_max = 48000;
00075     mctrl.layer_1_2.stereo.freq_max = 48000;
00076     mctrl.layer_3.mono.quality = 2;
00077     mctrl.layer_3.stereo.quality = 2;
00078     mctrl.layer_3.mono.freq_div = 1;
00079     mctrl.layer_3.stereo.freq_div = 1;
00080     mctrl.layer_3.mono.freq_max = 48000;
00081     mctrl.layer_3.stereo.freq_max = 48000;
00082     mctrl.layer_1_2.force_mono = 0;
00083     mctrl.layer_3.force_mono = 0;
00084 
00085     MPEGABase = OpenLibrary("mpega.library", 2);
00086     if (!MPEGABase) {
00087         error_printf("Unable to open mpega.library v2\n");
00088         exit(1);
00089     }
00090 #ifndef __GNUC__
00091     onbreak(break_cleanup);
00092 #endif
00093     atexit(exit_cleanup);
00094 
00095     mp3data->header_parsed = 0;
00096     mstream = MPEGA_open((char *) fullname, &mctrl);
00097     if (!mstream)
00098         return (-1);
00099 
00100     mp3data->header_parsed = 1;
00101     mp3data->stereo = mstream->dec_channels;
00102     mp3data->samplerate = mstream->dec_frequency;
00103     mp3data->bitrate = mstream->bitrate;
00104     mp3data->nsamp = (float) mstream->ms_duration / 1000 * mstream->dec_frequency;
00105     mp3data->mode = mstream->mode;
00106     mp3data->mode_ext = 0; /* mpega.library doesn't supply this info! :( */
00107     mp3data->framesize = smpls[mstream->norm - 1][mstream->layer];
00108 
00109     return 0;
00110 }
00111 
00112 int
00113 lame_decode_fromfile(FILE * fd, short pcm_l[], short pcm_r[], mp3data_struct * mp3data)
00114 {
00115     int     outsize = 0;
00116     WORD   *b[MPEGA_MAX_CHANNELS];
00117 
00118     b[0] = pcm_l;
00119     b[1] = pcm_r;
00120 
00121     mp3data->header_parsed = 0;
00122     while ((outsize == 0) || (outsize == MPEGA_ERR_BADFRAME)) /* Skip bad frames */
00123         outsize = MPEGA_decode_frame(mstream, b);
00124 
00125     if (outsize < 0)
00126         return (-1);
00127 
00128     mp3data->header_parsed = 1;
00129     mp3data->stereo = mstream->dec_channels;
00130     mp3data->samplerate = mstream->dec_frequency;
00131     mp3data->bitrate = mstream->bitrate;
00132     mp3data->mode = mstream->mode;
00133     mp3data->mode_ext = 0; /* mpega.library doesn't supply this info! :( */
00134     mp3data->framesize = smpls[mstream->norm - 1][mstream->layer];
00135 
00136     return outsize;
00137 }
00138 
00139 #endif /* AMIGA_MPEGA */

Generated on Sun Dec 2 11:34:17 2007 for LAME by  doxygen 1.5.2