music_mad.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. struct mad_stream stream;
  35. struct mad_frame frame;
  36. struct mad_synth synth;
  37. int frames_read;
  38. mad_timer_t next_frame_start;
  39. int volume;
  40. int status;
  41. int output_begin, output_end;
  42. SDL_AudioSpec mixer;
  43. SDL_AudioCVT cvt;
  44. unsigned char input_buffer[MAD_INPUT_BUFFER_SIZE + MAD_BUFFER_GUARD];
  45. unsigned char output_buffer[MAD_OUTPUT_BUFFER_SIZE];
  46. } mad_data;
  47. mad_data *mad_openFile(const char *filename, SDL_AudioSpec *mixer);
  48. mad_data *mad_openFileRW(SDL_RWops *rw, SDL_AudioSpec *mixer);
  49. void mad_closeFile(mad_data *mp3_mad);
  50. void mad_start(mad_data *mp3_mad);
  51. void mad_stop(mad_data *mp3_mad);
  52. int mad_isPlaying(mad_data *mp3_mad);
  53. void mad_getSamples(mad_data *mp3_mad, Uint8 *stream, int len);
  54. void mad_seek(mad_data *mp3_mad, double position);
  55. void mad_setVolume(mad_data *mp3_mad, int volume);