Mercurial > SDL_sound_CoreAudio
comparison decoders/flac.c @ 515:c5f184b4b2cd stable-1.0
Updated to libFLAC 1.1.3 API.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Sat, 28 Oct 2006 00:53:45 +0000 |
parents | 30f96c853462 |
children | 45ee760a6f5a |
comparison
equal
deleted
inserted
replaced
512:ef0d98d55865 | 515:c5f184b4b2cd |
---|---|
42 #include "SDL_sound.h" | 42 #include "SDL_sound.h" |
43 | 43 |
44 #define __SDL_SOUND_INTERNAL__ | 44 #define __SDL_SOUND_INTERNAL__ |
45 #include "SDL_sound_internal.h" | 45 #include "SDL_sound_internal.h" |
46 | 46 |
47 #include <FLAC/export.h> | |
48 | |
49 /* FLAC 1.1.3 has FLAC_API_VERSION_CURRENT == 8 */ | |
50 #if !defined(FLAC_API_VERSION_CURRENT) || FLAC_API_VERSION_CURRENT < 8 | |
51 #define LEGACY_FLAC | |
52 #else | |
53 #undef LEGACY_FLAC | |
54 #endif | |
55 | |
56 #ifdef LEGACY_FLAC | |
47 #include <FLAC/seekable_stream_decoder.h> | 57 #include <FLAC/seekable_stream_decoder.h> |
48 | 58 |
49 #define D_END_OF_STREAM FLAC__SEEKABLE_STREAM_DECODER_END_OF_STREAM | 59 #define D_END_OF_STREAM FLAC__SEEKABLE_STREAM_DECODER_END_OF_STREAM |
50 | 60 |
51 #define d_new() FLAC__seekable_stream_decoder_new() | 61 #define d_new() FLAC__seekable_stream_decoder_new() |
78 #define d_seek_absolute(x, y) FLAC__seekable_stream_decoder_seek_absolute(x, y) | 88 #define d_seek_absolute(x, y) FLAC__seekable_stream_decoder_seek_absolute(x, y) |
79 | 89 |
80 typedef FLAC__SeekableStreamDecoderSeekStatus d_seek_status_t; | 90 typedef FLAC__SeekableStreamDecoderSeekStatus d_seek_status_t; |
81 typedef FLAC__SeekableStreamDecoderTellStatus d_tell_status_t; | 91 typedef FLAC__SeekableStreamDecoderTellStatus d_tell_status_t; |
82 typedef FLAC__SeekableStreamDecoderLengthStatus d_length_status_t; | 92 typedef FLAC__SeekableStreamDecoderLengthStatus d_length_status_t; |
93 #else | |
94 #include <FLAC/stream_decoder.h> | |
95 | |
96 #define D_END_OF_STREAM FLAC__STREAM_DECODER_END_OF_STREAM | |
97 | |
98 #define d_new() FLAC__stream_decoder_new() | |
99 #define d_process_metadata(x) FLAC__stream_decoder_process_until_end_of_metadata(x) | |
100 #define d_process_one_frame(x) FLAC__stream_decoder_process_single(x) | |
101 #define d_get_state(x) FLAC__stream_decoder_get_state(x) | |
102 #define d_finish(x) FLAC__stream_decoder_finish(x) | |
103 #define d_delete(x) FLAC__stream_decoder_delete(x) | |
104 | |
105 typedef FLAC__StreamDecoder decoder_t; | |
106 typedef FLAC__StreamDecoderReadStatus d_read_status_t; | |
107 | |
108 #define D_SEEK_STATUS_OK FLAC__STREAM_DECODER_SEEK_STATUS_OK | |
109 #define D_SEEK_STATUS_ERROR FLAC__STREAM_DECODER_SEEK_STATUS_ERROR | |
110 #define D_TELL_STATUS_OK FLAC__STREAM_DECODER_TELL_STATUS_OK | |
111 #define D_TELL_STATUS_ERROR FLAC__STREAM_DECODER_TELL_STATUS_ERROR | |
112 #define D_LENGTH_STATUS_OK FLAC__STREAM_DECODER_LENGTH_STATUS_OK | |
113 #define D_LENGTH_STATUS_ERROR FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR | |
114 | |
115 #define d_seek_absolute(x, y) FLAC__stream_decoder_seek_absolute(x, y) | |
116 | |
117 typedef FLAC__StreamDecoderSeekStatus d_seek_status_t; | |
118 typedef FLAC__StreamDecoderTellStatus d_tell_status_t; | |
119 typedef FLAC__StreamDecoderLengthStatus d_length_status_t; | |
120 #endif | |
83 | 121 |
84 #define D_WRITE_CONTINUE FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE | 122 #define D_WRITE_CONTINUE FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE |
85 #define D_READ_END_OF_STREAM FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM | 123 #define D_READ_END_OF_STREAM FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM |
86 #define D_READ_ABORT FLAC__STREAM_DECODER_READ_STATUS_ABORT | 124 #define D_READ_ABORT FLAC__STREAM_DECODER_READ_STATUS_ABORT |
87 #define D_READ_CONTINUE FLAC__STREAM_DECODER_READ_STATUS_CONTINUE | 125 #define D_READ_CONTINUE FLAC__STREAM_DECODER_READ_STATUS_CONTINUE |
139 d_delete(f->decoder); | 177 d_delete(f->decoder); |
140 free(f); | 178 free(f); |
141 } /* free_flac */ | 179 } /* free_flac */ |
142 | 180 |
143 | 181 |
182 #ifdef LEGACY_FLAC | |
144 static d_read_status_t read_callback( | 183 static d_read_status_t read_callback( |
145 const decoder_t *decoder, FLAC__byte buffer[], | 184 const decoder_t *decoder, FLAC__byte buffer[], |
146 unsigned int *bytes, void *client_data) | 185 unsigned int *bytes, void *client_data) |
186 #else | |
187 static d_read_status_t read_callback( | |
188 const decoder_t *decoder, FLAC__byte buffer[], | |
189 size_t *bytes, void *client_data) | |
190 #endif | |
147 { | 191 { |
148 flac_t *f = (flac_t *) client_data; | 192 flac_t *f = (flac_t *) client_data; |
149 Uint32 retval; | 193 Uint32 retval; |
150 | 194 |
151 retval = SDL_RWread(f->rw, (Uint8 *) buffer, 1, *bytes); | 195 retval = SDL_RWread(f->rw, (Uint8 *) buffer, 1, *bytes); |
398 { | 442 { |
399 free(f); | 443 free(f); |
400 BAIL_MACRO(ERR_OUT_OF_MEMORY, 0); | 444 BAIL_MACRO(ERR_OUT_OF_MEMORY, 0); |
401 } /* if */ | 445 } /* if */ |
402 | 446 |
447 #ifdef LEGACY_FLAC | |
403 d_set_read_callback(decoder, read_callback); | 448 d_set_read_callback(decoder, read_callback); |
404 d_set_write_callback(decoder, write_callback); | 449 d_set_write_callback(decoder, write_callback); |
405 d_set_metadata_callback(decoder, metadata_callback); | 450 d_set_metadata_callback(decoder, metadata_callback); |
406 d_set_error_callback(decoder, error_callback); | 451 d_set_error_callback(decoder, error_callback); |
407 d_set_seek_callback(decoder, seek_callback); | 452 d_set_seek_callback(decoder, seek_callback); |
408 d_set_tell_callback(decoder, tell_callback); | 453 d_set_tell_callback(decoder, tell_callback); |
409 d_set_length_callback(decoder, length_callback); | 454 d_set_length_callback(decoder, length_callback); |
410 d_set_eof_callback(decoder, eof_callback); | 455 d_set_eof_callback(decoder, eof_callback); |
411 | 456 |
412 d_set_client_data(decoder, f); | 457 d_set_client_data(decoder, f); |
458 #endif | |
413 | 459 |
414 f->rw = internal->rw; | 460 f->rw = internal->rw; |
415 f->sample = sample; | 461 f->sample = sample; |
416 f->decoder = decoder; | 462 f->decoder = decoder; |
417 f->sample->actual.format = 0; | 463 f->sample->actual.format = 0; |
418 f->is_flac = 0 /* !!! FIXME: should be "has_extension", not "0". */; | 464 f->is_flac = 0 /* !!! FIXME: should be "has_extension", not "0". */; |
419 | 465 |
420 internal->decoder_private = f; | 466 internal->decoder_private = f; |
467 /* really should check the init return value here: */ | |
468 #ifdef LEGACY_FLAC | |
421 d_init(decoder); | 469 d_init(decoder); |
470 #else | |
471 FLAC__stream_decoder_init_stream(decoder, read_callback, seek_callback, | |
472 tell_callback, length_callback, | |
473 eof_callback, write_callback, | |
474 metadata_callback, error_callback, f); | |
475 #endif | |
422 | 476 |
423 sample->flags = SOUND_SAMPLEFLAG_NONE; | 477 sample->flags = SOUND_SAMPLEFLAG_NONE; |
424 | 478 |
425 pos = SDL_RWtell(f->rw); | 479 pos = SDL_RWtell(f->rw); |
426 if (SDL_RWseek(f->rw, 0, SEEK_END) > 0) | 480 if (SDL_RWseek(f->rw, 0, SEEK_END) > 0) |