music_mad.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. SDL_mixer: An audio mixer library based on the SDL library
  3. Copyright (C) 1997-2004 Sam Lantinga
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public
  6. License as published by the Free Software Foundation; either
  7. version 2 of the License, or (at your option) any later version.
  8. This library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Library General Public License for more details.
  12. You should have received a copy of the GNU Library General Public
  13. License along with this library; if not, write to the Free
  14. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  15. Sam Lantinga
  16. slouken@libsdl.org
  17. */
  18. #include "mad.h"
  19. #include "SDL_rwops.h"
  20. #include "SDL_audio.h"
  21. #define MAD_INPUT_BUFFER_SIZE (5*8192)
  22. #define MAD_OUTPUT_BUFFER_SIZE 8192
  23. enum {
  24. MS_input_eof = 0x0001,
  25. MS_input_error = 0x0001,
  26. MS_decode_eof = 0x0002,
  27. MS_decode_error = 0x0004,
  28. MS_error_flags = 0x000f,
  29. MS_playing = 0x0100,
  30. MS_cvt_decoded = 0x0200,
  31. };
  32. typedef struct {
  33. SDL_RWops *rw;
  34. void *resampler[2]; /* SDLPAL: Avoid to use SDL's stupid resampler */
  35. struct mad_stream stream;
  36. struct mad_frame frame;
  37. struct mad_synth synth;
  38. int frames_read;
  39. mad_timer_t next_frame_start;
  40. int volume;
  41. int status;
  42. int output_begin, output_end;
  43. int upsample; /* SDLPAL: Is upsample or downsample */
  44. int resampler_quality; /* SDLPAL:resampler quality */
  45. SDL_AudioSpec mixer;
  46. SDL_AudioCVT cvt;
  47. unsigned char input_buffer[MAD_INPUT_BUFFER_SIZE + MAD_BUFFER_GUARD];
  48. unsigned char output_buffer[MAD_OUTPUT_BUFFER_SIZE];
  49. } mad_data;
  50. mad_data *mad_openFile(const char *filename, SDL_AudioSpec *mixer, int resampler_quality);
  51. mad_data *mad_openFileRW(SDL_RWops *rw, SDL_AudioSpec *mixer, int resampler_quality);
  52. void mad_closeFile(mad_data *mp3_mad);
  53. void mad_start(mad_data *mp3_mad);
  54. void mad_stop(mad_data *mp3_mad);
  55. int mad_isPlaying(mad_data *mp3_mad);
  56. void mad_getSamples(mad_data *mp3_mad, Uint8 *stream, int len);
  57. void mad_seek(mad_data *mp3_mad, double position);
  58. void mad_setVolume(mad_data *mp3_mad, int volume);