|
|
#define __SDL_SOUND_INTERNAL__ | #define __SDL_SOUND_INTERNAL__ |
#include "SDL_sound_internal.h" | #include "SDL_sound_internal.h" |
| |
|
#include <FLAC/export.h> |
|
|
|
/* FLAC 1.1.3 has FLAC_API_VERSION_CURRENT == 8 */ |
|
#if !defined(FLAC_API_VERSION_CURRENT) || FLAC_API_VERSION_CURRENT < 8 |
|
#define LEGACY_FLAC |
|
#else |
|
#undef LEGACY_FLAC |
|
#endif |
|
|
|
#ifdef LEGACY_FLAC |
#include <FLAC/seekable_stream_decoder.h> | #include <FLAC/seekable_stream_decoder.h> |
| |
#define D_END_OF_STREAM FLAC__SEEKABLE_STREAM_DECODER_END_OF_STREAM | #define D_END_OF_STREAM FLAC__SEEKABLE_STREAM_DECODER_END_OF_STREAM |
|
|
typedef FLAC__SeekableStreamDecoderSeekStatus d_seek_status_t; | typedef FLAC__SeekableStreamDecoderSeekStatus d_seek_status_t; |
typedef FLAC__SeekableStreamDecoderTellStatus d_tell_status_t; | typedef FLAC__SeekableStreamDecoderTellStatus d_tell_status_t; |
typedef FLAC__SeekableStreamDecoderLengthStatus d_length_status_t; | typedef FLAC__SeekableStreamDecoderLengthStatus d_length_status_t; |
|
#else |
|
#include <FLAC/stream_decoder.h> |
|
|
|
#define D_END_OF_STREAM FLAC__STREAM_DECODER_END_OF_STREAM |
|
|
|
#define d_new() FLAC__stream_decoder_new() |
|
#define d_process_metadata(x) FLAC__stream_decoder_process_until_end_of_metadata(x) |
|
#define d_process_one_frame(x) FLAC__stream_decoder_process_single(x) |
|
#define d_get_state(x) FLAC__stream_decoder_get_state(x) |
|
#define d_finish(x) FLAC__stream_decoder_finish(x) |
|
#define d_delete(x) FLAC__stream_decoder_delete(x) |
|
|
|
typedef FLAC__StreamDecoder decoder_t; |
|
typedef FLAC__StreamDecoderReadStatus d_read_status_t; |
|
|
|
#define D_SEEK_STATUS_OK FLAC__STREAM_DECODER_SEEK_STATUS_OK |
|
#define D_SEEK_STATUS_ERROR FLAC__STREAM_DECODER_SEEK_STATUS_ERROR |
|
#define D_TELL_STATUS_OK FLAC__STREAM_DECODER_TELL_STATUS_OK |
|
#define D_TELL_STATUS_ERROR FLAC__STREAM_DECODER_TELL_STATUS_ERROR |
|
#define D_LENGTH_STATUS_OK FLAC__STREAM_DECODER_LENGTH_STATUS_OK |
|
#define D_LENGTH_STATUS_ERROR FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR |
|
|
|
#define d_seek_absolute(x, y) FLAC__stream_decoder_seek_absolute(x, y) |
|
|
|
typedef FLAC__StreamDecoderSeekStatus d_seek_status_t; |
|
typedef FLAC__StreamDecoderTellStatus d_tell_status_t; |
|
typedef FLAC__StreamDecoderLengthStatus d_length_status_t; |
|
#endif |
| |
#define D_WRITE_CONTINUE FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE | #define D_WRITE_CONTINUE FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE |
#define D_READ_END_OF_STREAM FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM | #define D_READ_END_OF_STREAM FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM |
|
|
} /* free_flac */ | } /* free_flac */ |
| |
| |
|
#ifdef LEGACY_FLAC |
static d_read_status_t read_callback( | static d_read_status_t read_callback( |
const decoder_t *decoder, FLAC__byte buffer[], | const decoder_t *decoder, FLAC__byte buffer[], |
unsigned int *bytes, void *client_data) | unsigned int *bytes, void *client_data) |
|
#else |
|
static d_read_status_t read_callback( |
|
const decoder_t *decoder, FLAC__byte buffer[], |
|
size_t *bytes, void *client_data) |
|
#endif |
{ | { |
flac_t *f = (flac_t *) client_data; | flac_t *f = (flac_t *) client_data; |
Uint32 retval; | Uint32 retval; |
|
|
BAIL_MACRO(ERR_OUT_OF_MEMORY, 0); | BAIL_MACRO(ERR_OUT_OF_MEMORY, 0); |
} /* if */ | } /* if */ |
| |
|
#ifdef LEGACY_FLAC |
d_set_read_callback(decoder, read_callback); | d_set_read_callback(decoder, read_callback); |
d_set_write_callback(decoder, write_callback); | d_set_write_callback(decoder, write_callback); |
d_set_metadata_callback(decoder, metadata_callback); | d_set_metadata_callback(decoder, metadata_callback); |
|
|
d_set_eof_callback(decoder, eof_callback); | d_set_eof_callback(decoder, eof_callback); |
| |
d_set_client_data(decoder, f); | d_set_client_data(decoder, f); |
|
#endif |
| |
f->rw = internal->rw; | f->rw = internal->rw; |
f->sample = sample; | f->sample = sample; |
|
|
f->is_flac = 0 /* !!! FIXME: should be "has_extension", not "0". */; | f->is_flac = 0 /* !!! FIXME: should be "has_extension", not "0". */; |
| |
internal->decoder_private = f; | internal->decoder_private = f; |
|
/* really should check the init return value here: */ |
|
#ifdef LEGACY_FLAC |
d_init(decoder); | d_init(decoder); |
|
#else |
|
FLAC__stream_decoder_init_stream(decoder, read_callback, seek_callback, tell_callback, length_callback, eof_callback, write_callback, metadata_callback, error_callback, f); |
|
#endif |
| |
sample->flags = SOUND_SAMPLEFLAG_NONE; | sample->flags = SOUND_SAMPLEFLAG_NONE; |
| |