music_flac.h
author Sam Lantinga <slouken@libsdl.org>
Wed, 04 Jan 2012 00:16:03 -0500
changeset 542 3de4970b36d4
parent 521 565549e046b0
child 601 05123263dab3
permissions -rw-r--r--
Fixed bug 1252 - Added Mix_LoadMUSType_RW() so you can tell SDL_mixer what type the music is

This involved a complete refactoring of the music loading so it's entirely rwops based and has improved music type detection code.
     1 /*
     2   SDL_mixer:  An audio mixer library based on the SDL library
     3   Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
     4 
     5   This software is provided 'as-is', without any express or implied
     6   warranty.  In no event will the authors be held liable for any damages
     7   arising from the use of this software.
     8 
     9   Permission is granted to anyone to use this software for any purpose,
    10   including commercial applications, and to alter it and redistribute it
    11   freely, subject to the following restrictions:
    12 
    13   1. The origin of this software must not be misrepresented; you must not
    14      claim that you wrote the original software. If you use this software
    15      in a product, an acknowledgment in the product documentation would be
    16      appreciated but is not required.
    17   2. Altered source versions must be plainly marked as such, and must not be
    18      misrepresented as being the original software.
    19   3. This notice may not be removed or altered from any source distribution.
    20 
    21   Header to handle loading FLAC music files in SDL.
    22 	~ Austen Dicken (admin@cvpcs.org)
    23 */
    24 
    25 /* $Id:  $ */
    26 
    27 #ifdef FLAC_MUSIC
    28 
    29 #include <FLAC/stream_decoder.h>
    30 
    31 typedef struct {
    32 	FLAC__uint64 sample_size;
    33 	unsigned sample_rate;
    34 	unsigned channels;
    35 	unsigned bits_per_sample;
    36 	FLAC__uint64 total_samples;
    37 
    38 	// the following are used to handle the callback nature of the writer
    39 	int max_to_read;
    40 	char *data;				// pointer to beginning of data array
    41 	int data_len;			// size of data array
    42 	int data_read;			// amount of data array used
    43 	char *overflow;			// pointer to beginning of overflow array
    44 	int overflow_len;		// size of overflow array
    45 	int overflow_read;		// amount of overflow array used
    46 } FLAC_Data;
    47 
    48 typedef struct {
    49 	int playing;
    50 	int volume;
    51 	int section;
    52 	FLAC__StreamDecoder *flac_decoder;
    53 	FLAC_Data flac_data;
    54 	SDL_RWops *rwops;
    55 	int freerw;
    56 	SDL_AudioCVT cvt;
    57 	int len_available;
    58 	Uint8 *snd_available;
    59 } FLAC_music;
    60 
    61 /* Initialize the FLAC player, with the given mixer settings
    62    This function returns 0, or -1 if there was an error.
    63  */
    64 extern int FLAC_init(SDL_AudioSpec *mixer);
    65 
    66 /* Set the volume for a FLAC stream */
    67 extern void FLAC_setvolume(FLAC_music *music, int volume);
    68 
    69 /* Load an FLAC stream from an SDL_RWops object */
    70 extern FLAC_music *FLAC_new_RW(SDL_RWops *rw, int freerw);
    71 
    72 /* Start playback of a given FLAC stream */
    73 extern void FLAC_play(FLAC_music *music);
    74 
    75 /* Return non-zero if a stream is currently playing */
    76 extern int FLAC_playing(FLAC_music *music);
    77 
    78 /* Play some of a stream previously started with FLAC_play() */
    79 extern int FLAC_playAudio(FLAC_music *music, Uint8 *stream, int len);
    80 
    81 /* Stop playback of a stream previously started with FLAC_play() */
    82 extern void FLAC_stop(FLAC_music *music);
    83 
    84 /* Close the given FLAC stream */
    85 extern void FLAC_delete(FLAC_music *music);
    86 
    87 /* Jump (seek) to a given position (time is in seconds) */
    88 extern void FLAC_jump_to_time(FLAC_music *music, double time);
    89 
    90 #endif /* FLAC_MUSIC */