home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 24 / AACD 24.iso / AACD / Sound / LAME / WarpOS / src / frontend / amiga_mpega.c next >
Encoding:
C/C++ Source or Header  |  2001-02-05  |  3.2 KB  |  134 lines

  1. /* MPGLIB replacement using mpega.library (AmigaOS)
  2.  * Written by Thomas Wenzel and Sigbjørn (CISC) Skjæret.
  3.  *
  4.  * Big thanks to Stéphane Tavernard for mpega.library.
  5.  *
  6.  */
  7.  
  8. /* $Id: amiga_mpega.c,v 1.2 2001/02/05 00:34:37 cisc Exp $ */
  9.  
  10. #ifdef HAVE_CONFIG_H
  11. #include <config.h>
  12. #endif
  13.  
  14. #ifdef AMIGA_MPEGA
  15.  
  16. #define __USE_SYSBASE
  17. #include "lame.h"
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20.  
  21. /* We need a small workaround here so GCC doesn't fail upon redefinition. :P */
  22. #define FLOAT _FLOAT
  23. #include <proto/exec.h>
  24. #include <proto/mpega.h>
  25. #undef _FLOAT
  26.  
  27. #ifndef __GNUC__
  28. #include <dos.h>
  29. #endif
  30.  
  31. struct Library  *MPEGABase=NULL;
  32. MPEGA_STREAM    *mstream=NULL;
  33. MPEGA_CTRL      mctrl;
  34.  
  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) */
  39. };
  40.  
  41.  
  42. #ifndef __GNUC__
  43. static int break_cleanup(void)
  44. {
  45.     /* Dummy break function to make atexit() work. :P */
  46.     return 1;
  47. }
  48. #endif
  49.  
  50. static void exit_cleanup(void)
  51. {
  52.     if(mstream) {
  53.         MPEGA_close(mstream);
  54.         mstream = NULL;
  55.     }
  56.     if(MPEGABase) {
  57.         CloseLibrary(MPEGABase);
  58.         MPEGABase = NULL;
  59.     }
  60. }
  61.  
  62.  
  63. int lame_decode_initfile(const char *fullname, mp3data_struct *mp3data)
  64. {
  65.     mctrl.bs_access = NULL;
  66.  
  67.     mctrl.layer_1_2.mono.quality    = 2;
  68.     mctrl.layer_1_2.stereo.quality  = 2;
  69.     mctrl.layer_1_2.mono.freq_div   = 1;
  70.     mctrl.layer_1_2.stereo.freq_div = 1;
  71.     mctrl.layer_1_2.mono.freq_max   = 48000;
  72.     mctrl.layer_1_2.stereo.freq_max = 48000;
  73.     mctrl.layer_3.mono.quality      = 2;
  74.     mctrl.layer_3.stereo.quality    = 2;
  75.     mctrl.layer_3.mono.freq_div     = 1;
  76.     mctrl.layer_3.stereo.freq_div   = 1;
  77.     mctrl.layer_3.mono.freq_max     = 48000;
  78.     mctrl.layer_3.stereo.freq_max   = 48000;
  79.     mctrl.layer_1_2.force_mono      = 0;
  80.     mctrl.layer_3.force_mono        = 0;
  81.  
  82.     MPEGABase = OpenLibrary("mpega.library", 2);
  83.     if(!MPEGABase) {
  84.         fprintf(stderr, "Unable to open mpega.library v2\n");
  85.         exit(1);
  86.     }
  87. #ifndef __GNUC__
  88.     onbreak(break_cleanup);
  89. #endif
  90.     atexit(exit_cleanup);
  91.  
  92.     mp3data->header_parsed = 0;
  93.     mstream=MPEGA_open((char *)fullname, &mctrl);
  94.     if(!mstream) return (-1);
  95.  
  96.     mp3data->header_parsed = 1;
  97.     mp3data->stereo        = mstream->dec_channels;
  98.     mp3data->samplerate    = mstream->dec_frequency;
  99.     mp3data->bitrate       = mstream->bitrate;
  100.     mp3data->nsamp         = (float)mstream->ms_duration/1000 * mstream->dec_frequency;
  101.     mp3data->mode          = mstream->mode;
  102.     mp3data->mode_ext      = 0;    /* mpega.library doesn't supply this info! :( */
  103.     mp3data->framesize     = smpls[mstream->norm-1][mstream->layer];
  104.  
  105.     return 0;
  106. }
  107.  
  108. int lame_decode_fromfile(FILE *fd, short pcm_l[], short pcm_r[], mp3data_struct *mp3data)
  109. {
  110.     int outsize=0;
  111.     WORD *b[MPEGA_MAX_CHANNELS];
  112.  
  113.     b[0]=pcm_l;
  114.     b[1]=pcm_r;
  115.  
  116.     mp3data->header_parsed = 0;
  117.     while ((outsize == 0) || (outsize == MPEGA_ERR_BADFRAME))    /* Skip bad frames */
  118.         outsize = MPEGA_decode_frame(mstream, b);
  119.  
  120.     if (outsize < 0) return (-1);
  121.  
  122.     mp3data->header_parsed = 1;
  123.     mp3data->stereo        = mstream->dec_channels;
  124.     mp3data->samplerate    = mstream->dec_frequency;
  125.     mp3data->bitrate       = mstream->bitrate;
  126.     mp3data->mode          = mstream->mode;
  127.     mp3data->mode_ext      = 0;    /* mpega.library doesn't supply this info! :( */
  128.     mp3data->framesize     = smpls[mstream->norm-1][mstream->layer];
  129.  
  130.     return outsize;
  131. }
  132.  
  133. #endif /* AMIGA_MPEGA */
  134.