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