music_mad.h
author Sam Lantinga <slouken@libsdl.org>
Sun, 08 Nov 2009 18:40:07 +0000
changeset 474 a2c238c0c4b2
parent 407 73a92ea2c061
child 518 8bc9b5fd2aae
permissions -rw-r--r--
Don't break binary compatibility!
slouken@357
     1
/*
slouken@357
     2
    SDL_mixer:  An audio mixer library based on the SDL library
slouken@386
     3
    Copyright (C) 1997-2009 Sam Lantinga
slouken@357
     4
slouken@357
     5
    This library is free software; you can redistribute it and/or
slouken@357
     6
    modify it under the terms of the GNU Library General Public
slouken@357
     7
    License as published by the Free Software Foundation; either
slouken@357
     8
    version 2 of the License, or (at your option) any later version.
slouken@357
     9
slouken@357
    10
    This library is distributed in the hope that it will be useful,
slouken@357
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@357
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@357
    13
    Library General Public License for more details.
slouken@357
    14
slouken@357
    15
    You should have received a copy of the GNU Library General Public
slouken@357
    16
    License along with this library; if not, write to the Free
slouken@357
    17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
slouken@357
    18
slouken@357
    19
    Sam Lantinga
slouken@357
    20
    slouken@libsdl.org
slouken@357
    21
*/
slouken@357
    22
slouken@357
    23
#ifdef MP3_MAD_MUSIC
slouken@357
    24
slouken@357
    25
#include "mad.h"
slouken@357
    26
#include "SDL_rwops.h"
slouken@357
    27
#include "SDL_audio.h"
slouken@357
    28
#include "SDL_mixer.h"
slouken@357
    29
slouken@357
    30
#define MAD_INPUT_BUFFER_SIZE	(5*8192)
slouken@357
    31
#define MAD_OUTPUT_BUFFER_SIZE	8192
slouken@357
    32
slouken@357
    33
enum {
slouken@357
    34
  MS_input_eof    = 0x0001,
slouken@357
    35
  MS_input_error  = 0x0001,
slouken@357
    36
  MS_decode_eof   = 0x0002,
slouken@357
    37
  MS_decode_error = 0x0004,
slouken@357
    38
  MS_error_flags  = 0x000f,
slouken@357
    39
slouken@357
    40
  MS_playing      = 0x0100,
slouken@357
    41
  MS_cvt_decoded  = 0x0200,
slouken@357
    42
};
slouken@357
    43
slouken@357
    44
typedef struct {
slouken@357
    45
  SDL_RWops *rw;
slouken@380
    46
  SDL_bool freerw;
slouken@357
    47
  struct mad_stream stream;
slouken@357
    48
  struct mad_frame frame;
slouken@357
    49
  struct mad_synth synth;
slouken@357
    50
  int frames_read;
slouken@357
    51
  mad_timer_t next_frame_start;
slouken@357
    52
  int volume;
slouken@357
    53
  int status;
slouken@357
    54
  int output_begin, output_end;
slouken@357
    55
  SDL_AudioSpec mixer;
slouken@357
    56
  SDL_AudioCVT cvt;
slouken@357
    57
slouken@357
    58
  unsigned char input_buffer[MAD_INPUT_BUFFER_SIZE + MAD_BUFFER_GUARD];
slouken@357
    59
  unsigned char output_buffer[MAD_OUTPUT_BUFFER_SIZE];
slouken@357
    60
} mad_data;
slouken@357
    61
slouken@357
    62
mad_data *mad_openFile(const char *filename, SDL_AudioSpec *mixer);
slouken@357
    63
mad_data *mad_openFileRW(SDL_RWops *rw, SDL_AudioSpec *mixer);
slouken@357
    64
void mad_closeFile(mad_data *mp3_mad);
slouken@357
    65
slouken@357
    66
void mad_start(mad_data *mp3_mad);
slouken@357
    67
void mad_stop(mad_data *mp3_mad);
slouken@357
    68
int mad_isPlaying(mad_data *mp3_mad);
slouken@357
    69
slouken@407
    70
int mad_getSamples(mad_data *mp3_mad, Uint8 *stream, int len);
slouken@357
    71
void mad_seek(mad_data *mp3_mad, double position);
slouken@357
    72
void mad_setVolume(mad_data *mp3_mad, int volume);
slouken@357
    73
slouken@357
    74
#endif