1 /* MPGLIB replacement using mpega.library (AmigaOS)
2 * Written by Thomas Wenzel and Sigbjrn (CISC) Skj�et.
4 * Big thanks to St�hane Tavernard for mpega.library.
8 /* $Id: amiga_mpega.c,v 1.3 2005/11/01 13:01:56 robert Exp $ */
21 /* We need a small workaround here so GCC doesn't fail upon redefinition. :P */
23 #include <proto/exec.h>
24 #include <proto/mpega.h>
31 struct Library *MPEGABase = NULL;
32 MPEGA_STREAM *mstream = NULL;
35 static const int smpls[2][4] = {
36 /* Layer x I II III */
37 {0, 384, 1152, 1152}, /* MPEG-1 */
38 {0, 384, 1152, 576} /* MPEG-2(.5) */
46 /* Dummy break function to make atexit() work. :P */
59 CloseLibrary(MPEGABase);
66 lame_decode_initfile(const char *fullname, mp3data_struct * mp3data)
68 mctrl.bs_access = NULL;
70 mctrl.layer_1_2.mono.quality = 2;
71 mctrl.layer_1_2.stereo.quality = 2;
72 mctrl.layer_1_2.mono.freq_div = 1;
73 mctrl.layer_1_2.stereo.freq_div = 1;
74 mctrl.layer_1_2.mono.freq_max = 48000;
75 mctrl.layer_1_2.stereo.freq_max = 48000;
76 mctrl.layer_3.mono.quality = 2;
77 mctrl.layer_3.stereo.quality = 2;
78 mctrl.layer_3.mono.freq_div = 1;
79 mctrl.layer_3.stereo.freq_div = 1;
80 mctrl.layer_3.mono.freq_max = 48000;
81 mctrl.layer_3.stereo.freq_max = 48000;
82 mctrl.layer_1_2.force_mono = 0;
83 mctrl.layer_3.force_mono = 0;
85 MPEGABase = OpenLibrary("mpega.library", 2);
87 error_printf("Unable to open mpega.library v2\n");
91 onbreak(break_cleanup);
95 mp3data->header_parsed = 0;
96 mstream = MPEGA_open((char *) fullname, &mctrl);
100 mp3data->header_parsed = 1;
101 mp3data->stereo = mstream->dec_channels;
102 mp3data->samplerate = mstream->dec_frequency;
103 mp3data->bitrate = mstream->bitrate;
104 mp3data->nsamp = (float) mstream->ms_duration / 1000 * mstream->dec_frequency;
105 mp3data->mode = mstream->mode;
106 mp3data->mode_ext = 0; /* mpega.library doesn't supply this info! :( */
107 mp3data->framesize = smpls[mstream->norm - 1][mstream->layer];
113 lame_decode_fromfile(FILE * fd, short pcm_l[], short pcm_r[], mp3data_struct * mp3data)
116 WORD *b[MPEGA_MAX_CHANNELS];
121 mp3data->header_parsed = 0;
122 while ((outsize == 0) || (outsize == MPEGA_ERR_BADFRAME)) /* Skip bad frames */
123 outsize = MPEGA_decode_frame(mstream, b);
128 mp3data->header_parsed = 1;
129 mp3data->stereo = mstream->dec_channels;
130 mp3data->samplerate = mstream->dec_frequency;
131 mp3data->bitrate = mstream->bitrate;
132 mp3data->mode = mstream->mode;
133 mp3data->mode_ext = 0; /* mpega.library doesn't supply this info! :( */
134 mp3data->framesize = smpls[mstream->norm - 1][mstream->layer];
139 #endif /* AMIGA_MPEGA */