music_mad.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. SDL_mixer: An audio mixer library based on the SDL library
  3. Copyright (C) 1997-2013 Sam Lantinga <[email protected]>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. #ifdef MP3_MAD_MUSIC
  19. #include "mad.h"
  20. #include "SDL_rwops.h"
  21. #include "SDL_audio.h"
  22. #include "SDL_mixer.h"
  23. #define MAD_INPUT_BUFFER_SIZE (5*8192)
  24. #define MAD_OUTPUT_BUFFER_SIZE 8192
  25. enum {
  26. MS_input_eof = 0x0001,
  27. MS_input_error = 0x0001,
  28. MS_decode_eof = 0x0002,
  29. MS_decode_error = 0x0004,
  30. MS_error_flags = 0x000f,
  31. MS_playing = 0x0100,
  32. MS_cvt_decoded = 0x0200,
  33. };
  34. typedef struct {
  35. SDL_RWops *src;
  36. int freesrc;
  37. struct mad_stream stream;
  38. struct mad_frame frame;
  39. struct mad_synth synth;
  40. int frames_read;
  41. mad_timer_t next_frame_start;
  42. int volume;
  43. int status;
  44. int output_begin, output_end;
  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_openFileRW(SDL_RWops *src, SDL_AudioSpec *mixer, int freesrc);
  51. void mad_closeFile(mad_data *mp3_mad);
  52. void mad_start(mad_data *mp3_mad);
  53. void mad_stop(mad_data *mp3_mad);
  54. int mad_isPlaying(mad_data *mp3_mad);
  55. int mad_getSamples(mad_data *mp3_mad, Uint8 *stream, int len);
  56. void mad_seek(mad_data *mp3_mad, double position);
  57. void mad_setVolume(mad_data *mp3_mad, int volume);
  58. #endif