music_flac.h
author Sam Lantinga <slouken@libsdl.org>
Wed, 17 Jun 2015 00:11:41 -0700
changeset 705 fe757163b8f7
parent 625 1d489d8ec2e0
child 711 f40c5ac95b12
permissions -rw-r--r--
Fixed bug 3018 - Loading MIDI music using FluidSynth leaks memory.

Philipp Wiesemann

There is a memory leak in fluidsynth.c and fluidsynth_loadsong_RW_internal(). The allocated temporary buffer is not deleted if fluid_player_add_mem() returns FLUID_OK.
slouken@382
     1
/*
slouken@518
     2
  SDL_mixer:  An audio mixer library based on the SDL library
slouken@601
     3
  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
slouken@382
     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@382
     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@382
    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@382
    20
slouken@518
    21
  Header to handle loading FLAC music files in SDL.
slouken@617
    22
    ~ Austen Dicken (admin@cvpcs.org)
slouken@382
    23
*/
slouken@382
    24
slouken@382
    25
/* $Id:  $ */
slouken@382
    26
slouken@382
    27
#ifdef FLAC_MUSIC
slouken@382
    28
slouken@382
    29
#include <FLAC/stream_decoder.h>
slouken@382
    30
slouken@382
    31
typedef struct {
slouken@617
    32
    FLAC__uint64 sample_size;
slouken@617
    33
    unsigned sample_rate;
slouken@617
    34
    unsigned channels;
slouken@617
    35
    unsigned bits_per_sample;
slouken@617
    36
    FLAC__uint64 total_samples;
slouken@382
    37
slouken@617
    38
    // the following are used to handle the callback nature of the writer
slouken@617
    39
    int max_to_read;
slouken@617
    40
    char *data;             // pointer to beginning of data array
slouken@617
    41
    int data_len;           // size of data array
slouken@617
    42
    int data_read;          // amount of data array used
slouken@617
    43
    char *overflow;         // pointer to beginning of overflow array
slouken@617
    44
    int overflow_len;       // size of overflow array
slouken@617
    45
    int overflow_read;      // amount of overflow array used
slouken@382
    46
} FLAC_Data;
slouken@382
    47
slouken@382
    48
typedef struct {
slouken@617
    49
    int playing;
slouken@617
    50
    int volume;
slouken@617
    51
    int section;
slouken@617
    52
    FLAC__StreamDecoder *flac_decoder;
slouken@617
    53
    FLAC_Data flac_data;
slouken@625
    54
    SDL_RWops *src;
slouken@625
    55
    int freesrc;
slouken@617
    56
    SDL_AudioCVT cvt;
slouken@617
    57
    int len_available;
slouken@617
    58
    Uint8 *snd_available;
slouken@382
    59
} FLAC_music;
slouken@382
    60
slouken@382
    61
/* Initialize the FLAC player, with the given mixer settings
slouken@382
    62
   This function returns 0, or -1 if there was an error.
slouken@382
    63
 */
slouken@382
    64
extern int FLAC_init(SDL_AudioSpec *mixer);
slouken@382
    65
slouken@382
    66
/* Set the volume for a FLAC stream */
slouken@382
    67
extern void FLAC_setvolume(FLAC_music *music, int volume);
slouken@382
    68
slouken@382
    69
/* Load an FLAC stream from an SDL_RWops object */
slouken@625
    70
extern FLAC_music *FLAC_new_RW(SDL_RWops *src, int freesrc);
slouken@382
    71
slouken@382
    72
/* Start playback of a given FLAC stream */
slouken@382
    73
extern void FLAC_play(FLAC_music *music);
slouken@382
    74
slouken@382
    75
/* Return non-zero if a stream is currently playing */
slouken@382
    76
extern int FLAC_playing(FLAC_music *music);
slouken@382
    77
slouken@382
    78
/* Play some of a stream previously started with FLAC_play() */
slouken@382
    79
extern int FLAC_playAudio(FLAC_music *music, Uint8 *stream, int len);
slouken@382
    80
slouken@382
    81
/* Stop playback of a stream previously started with FLAC_play() */
slouken@382
    82
extern void FLAC_stop(FLAC_music *music);
slouken@382
    83
slouken@382
    84
/* Close the given FLAC stream */
slouken@382
    85
extern void FLAC_delete(FLAC_music *music);
slouken@382
    86
slouken@382
    87
/* Jump (seek) to a given position (time is in seconds) */
slouken@382
    88
extern void FLAC_jump_to_time(FLAC_music *music, double time);
slouken@382
    89
slouken@382
    90
#endif /* FLAC_MUSIC */