music_mad.h
author Sam Lantinga <slouken@libsdl.org>
Sat, 28 Jan 2012 10:43:16 -0500
changeset 576 9026009cf370
parent 542 3de4970b36d4
child 601 05123263dab3
child 930 1f6c6389391a
permissions -rw-r--r--
Updated to version 1.2.13
slouken@357
     1
/*
slouken@518
     2
  SDL_mixer:  An audio mixer library based on the SDL library
slouken@518
     3
  Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
slouken@357
     4
slouken@518
     5
  This software is provided 'as-is', without any express or implied
slouken@518
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@518
     7
  arising from the use of this software.
slouken@357
     8
slouken@518
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@518
    10
  including commercial applications, and to alter it and redistribute it
slouken@518
    11
  freely, subject to the following restrictions:
slouken@357
    12
slouken@518
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@518
    14
     claim that you wrote the original software. If you use this software
slouken@518
    15
     in a product, an acknowledgment in the product documentation would be
slouken@518
    16
     appreciated but is not required.
slouken@518
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@518
    18
     misrepresented as being the original software.
slouken@518
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@357
    20
*/
slouken@357
    21
slouken@357
    22
#ifdef MP3_MAD_MUSIC
slouken@357
    23
slouken@357
    24
#include "mad.h"
slouken@357
    25
#include "SDL_rwops.h"
slouken@357
    26
#include "SDL_audio.h"
slouken@357
    27
#include "SDL_mixer.h"
slouken@357
    28
slouken@357
    29
#define MAD_INPUT_BUFFER_SIZE	(5*8192)
slouken@357
    30
#define MAD_OUTPUT_BUFFER_SIZE	8192
slouken@357
    31
slouken@357
    32
enum {
slouken@357
    33
  MS_input_eof    = 0x0001,
slouken@357
    34
  MS_input_error  = 0x0001,
slouken@357
    35
  MS_decode_eof   = 0x0002,
slouken@357
    36
  MS_decode_error = 0x0004,
slouken@357
    37
  MS_error_flags  = 0x000f,
slouken@357
    38
slouken@357
    39
  MS_playing      = 0x0100,
slouken@357
    40
  MS_cvt_decoded  = 0x0200,
slouken@357
    41
};
slouken@357
    42
slouken@357
    43
typedef struct {
slouken@357
    44
  SDL_RWops *rw;
slouken@521
    45
  int freerw;
slouken@357
    46
  struct mad_stream stream;
slouken@357
    47
  struct mad_frame frame;
slouken@357
    48
  struct mad_synth synth;
slouken@357
    49
  int frames_read;
slouken@357
    50
  mad_timer_t next_frame_start;
slouken@357
    51
  int volume;
slouken@357
    52
  int status;
slouken@357
    53
  int output_begin, output_end;
slouken@357
    54
  SDL_AudioSpec mixer;
slouken@357
    55
  SDL_AudioCVT cvt;
slouken@357
    56
slouken@357
    57
  unsigned char input_buffer[MAD_INPUT_BUFFER_SIZE + MAD_BUFFER_GUARD];
slouken@357
    58
  unsigned char output_buffer[MAD_OUTPUT_BUFFER_SIZE];
slouken@357
    59
} mad_data;
slouken@357
    60
slouken@521
    61
mad_data *mad_openFileRW(SDL_RWops *rw, SDL_AudioSpec *mixer, int freerw);
slouken@357
    62
void mad_closeFile(mad_data *mp3_mad);
slouken@357
    63
slouken@357
    64
void mad_start(mad_data *mp3_mad);
slouken@357
    65
void mad_stop(mad_data *mp3_mad);
slouken@357
    66
int mad_isPlaying(mad_data *mp3_mad);
slouken@357
    67
slouken@407
    68
int mad_getSamples(mad_data *mp3_mad, Uint8 *stream, int len);
slouken@357
    69
void mad_seek(mad_data *mp3_mad, double position);
slouken@357
    70
void mad_setVolume(mad_data *mp3_mad, int volume);
slouken@357
    71
slouken@357
    72
#endif