home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 13 / AACD13.ISO / AACD / Sound / LAME / src / amiga_mpega.c < prev    next >
C/C++ Source or Header  |  2000-07-06  |  3KB  |  113 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. #ifdef AMIGA_MPEGA
  9.  
  10. #include "lame.h"
  11. #include "util.h"
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #define __USE_SYSBASE
  15.  
  16. /* We need a small workaround here so GCC doesn't fail upon redefinition. :P */
  17. #define FLOAT _FLOAT
  18. #include <proto/exec.h>
  19. #include <proto/mpega.h>
  20. #undef _FLOAT
  21.  
  22. #ifndef __GNUC__
  23. #include <dos.h>
  24. #endif
  25.  
  26. struct Library  *MPEGABase=NULL;
  27. MPEGA_STREAM    *mstream=NULL;
  28. MPEGA_CTRL      mctrl;
  29.  
  30.  
  31. #ifndef __GNUC__
  32. static int break_cleanup(void)
  33. {
  34.     /* Dummy break function to make atexit() work. :P */
  35.     return 1;
  36. }
  37. #endif
  38.  
  39. static void exit_cleanup(void)
  40. {
  41.     if(mstream) {
  42.         MPEGA_close(mstream);
  43.         mstream = NULL;
  44.     }
  45.     if(MPEGABase) {
  46.         CloseLibrary(MPEGABase);
  47.         MPEGABase = NULL;
  48.     }
  49. }
  50.  
  51.  
  52. int lame_decode_initfile(const char *fullname, mp3data_struct *mp3data)
  53. {
  54.     mctrl.bs_access = NULL;
  55.  
  56.     mctrl.layer_1_2.mono.quality    = 2;
  57.     mctrl.layer_1_2.stereo.quality  = 2;
  58.     mctrl.layer_1_2.mono.freq_div   = 1;
  59.     mctrl.layer_1_2.stereo.freq_div = 1;
  60.     mctrl.layer_1_2.mono.freq_max   = 48000;
  61.     mctrl.layer_1_2.stereo.freq_max = 48000;
  62.     mctrl.layer_3.mono.quality      = 2;
  63.     mctrl.layer_3.stereo.quality    = 2;
  64.     mctrl.layer_3.mono.freq_div     = 1;
  65.     mctrl.layer_3.stereo.freq_div   = 1;
  66.     mctrl.layer_3.mono.freq_max     = 48000;
  67.     mctrl.layer_3.stereo.freq_max   = 48000;
  68.     mctrl.layer_1_2.force_mono      = 0;
  69.     mctrl.layer_3.force_mono        = 0;
  70.  
  71.     MPEGABase = OpenLibrary("mpega.library", 2);
  72.     if(!MPEGABase) {
  73.         fprintf(stderr, "Unable to open mpega.library v2\n");
  74.         exit(1);
  75.     }
  76. #ifndef __GNUC__
  77.     onbreak(break_cleanup);
  78. #endif
  79.     atexit(exit_cleanup);
  80.  
  81.     mstream=MPEGA_open(fullname, &mctrl);
  82.     if(!mstream) { return (-1); }
  83.  
  84.     mp3data->stereo     = mstream->dec_channels;
  85.     mp3data->samplerate = mstream->dec_frequency;
  86.     mp3data->bitrate    = mstream->bitrate;
  87.     mp3data->nsamp      = (FLOAT)mstream->ms_duration/1000 * mstream->dec_frequency;
  88.  
  89.     return 0;
  90. }
  91.  
  92. int lame_decode_fromfile(FILE *fd, short pcm_l[],short pcm_r[],mp3data_struct *mp3data)
  93. {
  94.     int outsize=0;
  95.     WORD *b[MPEGA_MAX_CHANNELS];
  96.  
  97.     b[0]=pcm_l;
  98.     b[1]=pcm_r;
  99.  
  100.     while ((outsize == 0) || (outsize == MPEGA_ERR_BADFRAME))    /* Skip bad frames */
  101.         outsize = MPEGA_decode_frame(mstream, b);
  102.  
  103.     mp3data->stereo     = mstream->dec_channels;
  104.     mp3data->samplerate = mstream->dec_frequency;
  105.     mp3data->bitrate    = mstream->bitrate;
  106.     mp3data->nsamp      = (FLOAT)mstream->ms_duration/1000 * mstream->dec_frequency;
  107.  
  108.     if (outsize < 0) { return (-1); }
  109.     else { return outsize; }
  110. }
  111.  
  112. #endif /* AMIGA_MPEGA */
  113.