Skip to content

Latest commit

 

History

History
528 lines (425 loc) · 16 KB

flac.c

File metadata and controls

528 lines (425 loc) · 16 KB
 
Nov 9, 2001
Nov 9, 2001
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/*
* SDL_sound -- An abstract sound format decoding API.
* Copyright (C) 2001 Ryan C. Gordon.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* FLAC decoder for SDL_sound.
*
* This driver handles FLAC audio, that is to say the Free Lossless Audio
* Codec. It depends on libFLAC for decoding, which can be grabbed from:
* http://flac.sourceforge.net
*
Dec 26, 2001
Dec 26, 2001
27
* Please see the file COPYING in the source's root directory.
Nov 9, 2001
Nov 9, 2001
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
*
* This file written by Torbjörn Andersson. (d91tan@Update.UU.SE)
*/
#if HAVE_CONFIG_H
# include <config.h>
#endif
#ifdef SOUND_SUPPORTS_FLAC
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "SDL_sound.h"
#define __SDL_SOUND_INTERNAL__
#include "SDL_sound_internal.h"
Jan 31, 2003
Jan 31, 2003
47
#include <FLAC/seekable_stream_decoder.h>
Apr 24, 2002
Apr 24, 2002
48
49
50
51
52
#define D_END_OF_STREAM FLAC__SEEKABLE_STREAM_DECODER_END_OF_STREAM
#define d_new() FLAC__seekable_stream_decoder_new()
#define d_init(x) FLAC__seekable_stream_decoder_init(x)
Sep 30, 2002
Sep 30, 2002
53
54
#define d_process_metadata(x) FLAC__seekable_stream_decoder_process_until_end_of_metadata(x)
#define d_process_one_frame(x) FLAC__seekable_stream_decoder_process_single(x)
Apr 24, 2002
Apr 24, 2002
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#define d_get_state(x) FLAC__seekable_stream_decoder_get_state(x)
#define d_finish(x) FLAC__seekable_stream_decoder_finish(x)
#define d_delete(x) FLAC__seekable_stream_decoder_delete(x)
#define d_set_read_callback(x, y) FLAC__seekable_stream_decoder_set_read_callback(x, y)
#define d_set_write_callback(x, y) FLAC__seekable_stream_decoder_set_write_callback(x, y)
#define d_set_metadata_callback(x, y) FLAC__seekable_stream_decoder_set_metadata_callback(x, y)
#define d_set_error_callback(x, y) FLAC__seekable_stream_decoder_set_error_callback(x, y)
#define d_set_client_data(x, y) FLAC__seekable_stream_decoder_set_client_data(x, y)
typedef FLAC__SeekableStreamDecoder decoder_t;
typedef FLAC__SeekableStreamDecoderReadStatus d_read_status_t;
#define D_SEEK_STATUS_OK FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_OK
#define D_SEEK_STATUS_ERROR FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_ERROR
#define D_TELL_STATUS_OK FLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_OK
#define D_TELL_STATUS_ERROR FLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_ERROR
#define D_LENGTH_STATUS_OK FLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_OK
#define D_LENGTH_STATUS_ERROR FLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_ERROR
#define d_set_seek_callback(x, y) FLAC__seekable_stream_decoder_set_seek_callback(x, y)
#define d_set_tell_callback(x, y) FLAC__seekable_stream_decoder_set_tell_callback(x, y)
#define d_set_length_callback(x, y) FLAC__seekable_stream_decoder_set_length_callback(x, y)
#define d_set_eof_callback(x, y) FLAC__seekable_stream_decoder_set_eof_callback(x, y)
#define d_seek_absolute(x, y) FLAC__seekable_stream_decoder_seek_absolute(x, y)
typedef FLAC__SeekableStreamDecoderSeekStatus d_seek_status_t;
typedef FLAC__SeekableStreamDecoderTellStatus d_tell_status_t;
typedef FLAC__SeekableStreamDecoderLengthStatus d_length_status_t;
Jul 11, 2002
Jul 11, 2002
84
85
86
87
#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_ABORT FLAC__STREAM_DECODER_READ_STATUS_ABORT
#define D_READ_CONTINUE FLAC__STREAM_DECODER_READ_STATUS_CONTINUE
Apr 24, 2002
Apr 24, 2002
88
89
90
91
#define d_error_status_string FLAC__StreamDecoderErrorStatusString
typedef FLAC__StreamDecoderErrorStatus d_error_status_t;
Jul 11, 2002
Jul 11, 2002
92
93
typedef FLAC__StreamMetadata d_metadata_t;
typedef FLAC__StreamDecoderWriteStatus d_write_status_t;
Apr 24, 2002
Apr 24, 2002
94
Nov 9, 2001
Nov 9, 2001
95
96
97
98
99
100
static int FLAC_init(void);
static void FLAC_quit(void);
static int FLAC_open(Sound_Sample *sample, const char *ext);
static void FLAC_close(Sound_Sample *sample);
static Uint32 FLAC_read(Sound_Sample *sample);
Jan 17, 2002
Jan 17, 2002
101
static int FLAC_rewind(Sound_Sample *sample);
Apr 21, 2002
Apr 21, 2002
102
static int FLAC_seek(Sound_Sample *sample, Uint32 ms);
Nov 9, 2001
Nov 9, 2001
103
104
105
106
107
108
109
110
111
112
113
114
static const char *extensions_flac[] = { "FLAC", "FLA", NULL };
const Sound_DecoderFunctions __Sound_DecoderFunctions_FLAC =
{
{
extensions_flac,
"Free Lossless Audio Codec",
"Torbjörn Andersson <d91tan@Update.UU.SE>",
"http://flac.sourceforge.net/"
},
Jan 17, 2002
Jan 17, 2002
115
116
117
118
119
FLAC_init, /* init() method */
FLAC_quit, /* quit() method */
FLAC_open, /* open() method */
FLAC_close, /* close() method */
FLAC_read, /* read() method */
Apr 21, 2002
Apr 21, 2002
120
121
FLAC_rewind, /* rewind() method */
FLAC_seek /* seek() method */
Nov 9, 2001
Nov 9, 2001
122
123
124
125
126
};
/* This is what we store in our internal->decoder_private field. */
typedef struct
{
Apr 24, 2002
Apr 24, 2002
127
decoder_t *decoder;
Nov 9, 2001
Nov 9, 2001
128
129
130
SDL_RWops *rw;
Sound_Sample *sample;
Uint32 frame_size;
Nov 26, 2001
Nov 26, 2001
131
Uint8 is_flac;
Apr 24, 2002
Apr 24, 2002
132
Uint32 stream_length;
Nov 9, 2001
Nov 9, 2001
133
134
135
} flac_t;
Nov 26, 2001
Nov 26, 2001
136
137
static void free_flac(flac_t *f)
{
Apr 24, 2002
Apr 24, 2002
138
139
d_finish(f->decoder);
d_delete(f->decoder);
Nov 26, 2001
Nov 26, 2001
140
141
142
143
free(f);
} /* free_flac */
Apr 24, 2002
Apr 24, 2002
144
145
static d_read_status_t read_callback(
const decoder_t *decoder, FLAC__byte buffer[],
Nov 9, 2001
Nov 9, 2001
146
147
148
149
150
151
152
153
154
155
156
unsigned int *bytes, void *client_data)
{
flac_t *f = (flac_t *) client_data;
Uint32 retval;
retval = SDL_RWread(f->rw, (Uint8 *) buffer, 1, *bytes);
if (retval == 0)
{
*bytes = 0;
f->sample->flags |= SOUND_SAMPLEFLAG_EOF;
Apr 24, 2002
Apr 24, 2002
157
return(D_READ_END_OF_STREAM);
Nov 9, 2001
Nov 9, 2001
158
159
160
161
162
163
} /* if */
if (retval == -1)
{
*bytes = 0;
f->sample->flags |= SOUND_SAMPLEFLAG_ERROR;
Apr 24, 2002
Apr 24, 2002
164
return(D_READ_ABORT);
Nov 9, 2001
Nov 9, 2001
165
166
167
168
169
170
171
172
} /* if */
if (retval < *bytes)
{
*bytes = retval;
f->sample->flags |= SOUND_SAMPLEFLAG_EAGAIN;
} /* if */
Apr 24, 2002
Apr 24, 2002
173
174
return(D_READ_CONTINUE);
} /* read_callback */
Nov 9, 2001
Nov 9, 2001
175
176
Apr 24, 2002
Apr 24, 2002
177
178
static d_write_status_t write_callback(
const decoder_t *decoder, const FLAC__Frame *frame,
Jul 11, 2002
Jul 11, 2002
179
180
const FLAC__int32 * const buffer[],
void *client_data)
Nov 9, 2001
Nov 9, 2001
181
182
183
{
flac_t *f = (flac_t *) client_data;
Uint32 i, j;
Nov 26, 2001
Nov 26, 2001
184
Uint32 sample;
Nov 9, 2001
Nov 9, 2001
185
186
187
188
189
190
191
192
193
194
Uint8 *dst;
f->frame_size = frame->header.channels * frame->header.blocksize
* frame->header.bits_per_sample / 8;
if (f->frame_size > f->sample->buffer_size)
Sound_SetBufferSize(f->sample, f->frame_size);
dst = f->sample->buffer;
Nov 26, 2001
Nov 26, 2001
195
196
197
198
199
200
/* If the sample is neither exactly 8-bit nor 16-bit, it will have to
* be converted. Unfortunately the buffer is read-only, so we either
* have to check for each sample, or make a copy of the buffer. I'm
* not sure which way is best, so I've arbitrarily picked the former.
*/
if (f->sample->actual.format == AUDIO_S8)
Nov 9, 2001
Nov 9, 2001
201
202
203
{
for (i = 0; i < frame->header.blocksize; i++)
for (j = 0; j < frame->header.channels; j++)
Nov 26, 2001
Nov 26, 2001
204
205
206
207
208
209
{
sample = buffer[j][i];
if (frame->header.bits_per_sample < 8)
sample <<= (8 - frame->header.bits_per_sample);
*dst++ = sample & 0x00ff;
} /* for */
Nov 9, 2001
Nov 9, 2001
210
211
212
213
214
215
} /* if */
else
{
for (i = 0; i < frame->header.blocksize; i++)
for (j = 0; j < frame->header.channels; j++)
{
Nov 26, 2001
Nov 26, 2001
216
217
218
219
220
221
222
sample = buffer[j][i];
if (frame->header.bits_per_sample < 16)
sample <<= (16 - frame->header.bits_per_sample);
else if (frame->header.bits_per_sample > 16)
sample >>= (frame->header.bits_per_sample - 16);
*dst++ = (sample & 0xff00) >> 8;
*dst++ = sample & 0x00ff;
Nov 9, 2001
Nov 9, 2001
223
224
225
} /* for */
} /* else */
Apr 24, 2002
Apr 24, 2002
226
227
return(D_WRITE_CONTINUE);
} /* write_callback */
Nov 9, 2001
Nov 9, 2001
228
229
Apr 24, 2002
Apr 24, 2002
230
231
232
static void metadata_callback(
const decoder_t *decoder,
const d_metadata_t *metadata,
Nov 9, 2001
Nov 9, 2001
233
234
235
void *client_data)
{
flac_t *f = (flac_t *) client_data;
May 12, 2004
May 12, 2004
236
237
Sound_Sample *sample = f->sample;
Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
Apr 24, 2002
Apr 24, 2002
238
Nov 9, 2001
Nov 9, 2001
239
240
SNDDBG(("FLAC: Metadata callback.\n"));
Nov 26, 2001
Nov 26, 2001
241
242
243
/* There are several kinds of metadata, but STREAMINFO is the only
* one that always has to be there.
*/
Nov 9, 2001
Nov 9, 2001
244
245
246
if (metadata->type == FLAC__METADATA_TYPE_STREAMINFO)
{
SNDDBG(("FLAC: Metadata is streaminfo.\n"));
Nov 26, 2001
Nov 26, 2001
247
248
f->is_flac = 1;
May 12, 2004
May 12, 2004
249
250
sample->actual.channels = metadata->data.stream_info.channels;
sample->actual.rate = metadata->data.stream_info.sample_rate;
Nov 9, 2001
Nov 9, 2001
251
May 12, 2004
May 12, 2004
252
if (metadata->data.stream_info.sample_rate == 0 ||
May 8, 2004
May 8, 2004
253
metadata->data.stream_info.total_samples == 0)
May 12, 2004
May 12, 2004
254
255
256
257
258
259
{
internal->total_time = -1;
} /* if */
else
{
internal->total_time = (metadata->data.stream_info.total_samples)
May 8, 2004
May 8, 2004
260
/ metadata->data.stream_info.sample_rate * 1000;
May 12, 2004
May 12, 2004
261
internal->total_time += (metadata->data.stream_info.total_samples
May 8, 2004
May 8, 2004
262
263
% metadata->data.stream_info.sample_rate) * 1000
/ metadata->data.stream_info.sample_rate;
May 12, 2004
May 12, 2004
264
} /* else */
May 8, 2004
May 8, 2004
265
Nov 26, 2001
Nov 26, 2001
266
if (metadata->data.stream_info.bits_per_sample > 8)
May 12, 2004
May 12, 2004
267
sample->actual.format = AUDIO_S16MSB;
Nov 26, 2001
Nov 26, 2001
268
else
May 12, 2004
May 12, 2004
269
sample->actual.format = AUDIO_S8;
Nov 9, 2001
Nov 9, 2001
270
} /* if */
Apr 24, 2002
Apr 24, 2002
271
} /* metadata_callback */
Nov 9, 2001
Nov 9, 2001
272
273
Apr 24, 2002
Apr 24, 2002
274
275
276
static void error_callback(
const decoder_t *decoder,
d_error_status_t status,
Nov 9, 2001
Nov 9, 2001
277
278
279
void *client_data)
{
flac_t *f = (flac_t *) client_data;
Nov 19, 2001
Nov 19, 2001
280
Jul 5, 2002
Jul 5, 2002
281
__Sound_SetError(d_error_status_string[status]);
Nov 9, 2001
Nov 9, 2001
282
f->sample->flags |= SOUND_SAMPLEFLAG_ERROR;
Apr 24, 2002
Apr 24, 2002
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
} /* error_callback */
static d_seek_status_t seek_callback(
const decoder_t *decoder,
FLAC__uint64 absolute_byte_offset,
void *client_data)
{
flac_t *f = (flac_t *) client_data;
if (SDL_RWseek(f->rw, absolute_byte_offset, SEEK_SET) >= 0)
{
return(D_SEEK_STATUS_OK);
} /* if */
return(D_SEEK_STATUS_ERROR);
} /* seek_callback*/
static d_tell_status_t tell_callback(
const decoder_t *decoder,
FLAC__uint64 *absolute_byte_offset,
void *client_data)
{
flac_t *f = (flac_t *) client_data;
Jul 11, 2002
Jul 11, 2002
308
int pos;
Apr 24, 2002
Apr 24, 2002
309
310
pos = SDL_RWtell(f->rw);
Nov 9, 2001
Nov 9, 2001
311
Apr 24, 2002
Apr 24, 2002
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
if (pos < 0)
{
return(D_TELL_STATUS_ERROR);
} /* if */
*absolute_byte_offset = pos;
return(D_TELL_STATUS_OK);
} /* tell_callback */
static d_length_status_t length_callback(
const decoder_t *decoder,
FLAC__uint64 *stream_length,
void *client_data)
{
flac_t *f = (flac_t *) client_data;
if (f->sample->flags & SOUND_SAMPLEFLAG_CANSEEK)
{
*stream_length = f->stream_length;
return(D_LENGTH_STATUS_OK);
} /* if */
return(D_LENGTH_STATUS_ERROR);
} /* length_callback */
static FLAC__bool eof_callback(
const decoder_t *decoder,
void *client_data)
{
flac_t *f = (flac_t *) client_data;
Jul 11, 2002
Jul 11, 2002
344
int pos;
Apr 24, 2002
Apr 24, 2002
345
346
347
348
349
350
351
352
353
354
355
356
/* Maybe we could check for SOUND_SAMPLEFLAG_EOF here instead? */
pos = SDL_RWtell(f->rw);
if (pos >= 0 && pos >= f->stream_length)
{
return(true);
} /* if */
return(false);
} /* eof_callback */
Nov 9, 2001
Nov 9, 2001
357
358
359
360
361
362
363
364
365
366
367
368
369
static int FLAC_init(void)
{
return(1); /* always succeeds. */
} /* FLAC_init */
static void FLAC_quit(void)
{
/* it's a no-op. */
} /* FLAC_quit */
Dec 17, 2001
Dec 17, 2001
370
371
#define FLAC_MAGIC 0x43614C66 /* "fLaC" in ASCII. */
Nov 9, 2001
Nov 9, 2001
372
373
374
375
static int FLAC_open(Sound_Sample *sample, const char *ext)
{
Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
SDL_RWops *rw = internal->rw;
Apr 24, 2002
Apr 24, 2002
376
decoder_t *decoder;
Nov 9, 2001
Nov 9, 2001
377
flac_t *f;
Nov 26, 2001
Nov 26, 2001
378
int i;
Dec 17, 2001
Dec 17, 2001
379
int has_extension = 0;
Apr 24, 2002
Apr 24, 2002
380
Uint32 pos;
Dec 17, 2001
Dec 17, 2001
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
/*
* If the extension is "flac", we'll believe that this is really meant
* to be a FLAC stream, and will try to grok it from existing metadata.
* metadata searching can be a very expensive operation, however, so
* unless the user swears that it is a FLAC stream through the extension,
* we decide what to do based on the existance of a 32-bit magic number.
*/
for (i = 0; extensions_flac[i] != NULL; i++)
{
if (__Sound_strcasecmp(ext, extensions_flac[i]) == 0)
{
has_extension = 1;
break;
} /* if */
} /* for */
if (!has_extension)
{
int rc;
Uint32 flac_magic = SDL_ReadLE32(rw);
BAIL_IF_MACRO(flac_magic != FLAC_MAGIC, "FLAC: Not a FLAC stream.", 0);
/* move back over magic number for metadata scan... */
rc = SDL_RWseek(internal->rw, -sizeof (flac_magic), SEEK_CUR);
BAIL_IF_MACRO(rc < 0, ERR_IO_ERROR, 0);
} /* if */
Nov 9, 2001
Nov 9, 2001
408
409
410
411
f = (flac_t *) malloc(sizeof (flac_t));
BAIL_IF_MACRO(f == NULL, ERR_OUT_OF_MEMORY, 0);
Apr 24, 2002
Apr 24, 2002
412
decoder = d_new();
Nov 9, 2001
Nov 9, 2001
413
414
415
if (decoder == NULL)
{
free(f);
Jul 5, 2002
Jul 5, 2002
416
BAIL_MACRO(ERR_OUT_OF_MEMORY, 0);
Nov 9, 2001
Nov 9, 2001
417
418
} /* if */
Apr 24, 2002
Apr 24, 2002
419
420
421
422
423
424
425
426
d_set_read_callback(decoder, read_callback);
d_set_write_callback(decoder, write_callback);
d_set_metadata_callback(decoder, metadata_callback);
d_set_error_callback(decoder, error_callback);
d_set_seek_callback(decoder, seek_callback);
d_set_tell_callback(decoder, tell_callback);
d_set_length_callback(decoder, length_callback);
d_set_eof_callback(decoder, eof_callback);
Sep 30, 2002
Sep 30, 2002
427
Apr 24, 2002
Apr 24, 2002
428
d_set_client_data(decoder, f);
Nov 9, 2001
Nov 9, 2001
429
430
431
432
f->rw = internal->rw;
f->sample = sample;
f->decoder = decoder;
Nov 19, 2001
Nov 19, 2001
433
f->sample->actual.format = 0;
Dec 17, 2001
Dec 17, 2001
434
f->is_flac = 0 /* !!! FIXME: should be "has_extension", not "0". */;
Nov 26, 2001
Nov 26, 2001
435
436
internal->decoder_private = f;
Apr 24, 2002
Apr 24, 2002
437
d_init(decoder);
Nov 26, 2001
Nov 26, 2001
438
Apr 24, 2002
Apr 24, 2002
439
440
441
sample->flags = SOUND_SAMPLEFLAG_NONE;
pos = SDL_RWtell(f->rw);
Jul 11, 2002
Jul 11, 2002
442
if (SDL_RWseek(f->rw, 0, SEEK_END) > 0)
Apr 24, 2002
Apr 24, 2002
443
444
{
f->stream_length = SDL_RWtell(f->rw);
Jul 11, 2002
Jul 11, 2002
445
446
447
448
449
if (SDL_RWseek(f->rw, pos, SEEK_SET) == -1)
{
free_flac(f);
BAIL_MACRO(ERR_IO_ERROR, 0);
} /* if */
Apr 24, 2002
Apr 24, 2002
450
451
sample->flags = SOUND_SAMPLEFLAG_CANSEEK;
} /* if */
Jul 11, 2002
Jul 11, 2002
452
Dec 17, 2001
Dec 17, 2001
453
454
/*
* If we are not sure this is a FLAC stream, check for the STREAMINFO
Nov 26, 2001
Nov 26, 2001
455
* metadata block. If not, we'd have to peek at the first audio frame
Dec 17, 2001
Dec 17, 2001
456
457
* and get the sound format from there, but that is not yet
* implemented.
Nov 26, 2001
Nov 26, 2001
458
459
*/
if (!f->is_flac)
Nov 9, 2001
Nov 9, 2001
460
{
Apr 24, 2002
Apr 24, 2002
461
d_process_metadata(decoder);
Nov 26, 2001
Nov 26, 2001
462
463
464
465
466
/* Still not FLAC? Give up. */
if (!f->is_flac)
{
free_flac(f);
Jul 5, 2002
Jul 5, 2002
467
BAIL_MACRO("FLAC: No metadata found. Not a FLAC stream?", 0);
Nov 26, 2001
Nov 26, 2001
468
} /* if */
Nov 9, 2001
Nov 9, 2001
469
470
} /* if */
Nov 19, 2001
Nov 19, 2001
471
SNDDBG(("FLAC: Accepting data stream.\n"));
Nov 9, 2001
Nov 9, 2001
472
473
474
475
476
477
478
479
480
return(1);
} /* FLAC_open */
static void FLAC_close(Sound_Sample *sample)
{
Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
flac_t *f = (flac_t *) internal->decoder_private;
Nov 26, 2001
Nov 26, 2001
481
free_flac(f);
Nov 9, 2001
Nov 9, 2001
482
483
484
485
486
487
488
489
490
} /* FLAC_close */
static Uint32 FLAC_read(Sound_Sample *sample)
{
Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
flac_t *f = (flac_t *) internal->decoder_private;
Uint32 len;
Apr 24, 2002
Apr 24, 2002
491
if (!d_process_one_frame(f->decoder))
Nov 9, 2001
Nov 9, 2001
492
{
Jan 19, 2002
Jan 19, 2002
493
sample->flags |= SOUND_SAMPLEFLAG_ERROR;
Jul 5, 2002
Jul 5, 2002
494
BAIL_MACRO("FLAC: Couldn't decode frame.", 0);
Nov 9, 2001
Nov 9, 2001
495
496
} /* if */
Apr 24, 2002
Apr 24, 2002
497
if (d_get_state(f->decoder) == D_END_OF_STREAM)
Nov 9, 2001
Nov 9, 2001
498
{
Jan 19, 2002
Jan 19, 2002
499
sample->flags |= SOUND_SAMPLEFLAG_EOF;
Nov 9, 2001
Nov 9, 2001
500
501
502
return(0);
} /* if */
Nov 19, 2001
Nov 19, 2001
503
504
505
/* An error may have been signalled through the error callback. */
if (sample->flags & SOUND_SAMPLEFLAG_ERROR)
return(0);
Jan 19, 2002
Jan 19, 2002
506
Nov 9, 2001
Nov 9, 2001
507
508
509
return(f->frame_size);
} /* FLAC_read */
Jan 17, 2002
Jan 17, 2002
510
511
512
static int FLAC_rewind(Sound_Sample *sample)
{
Apr 24, 2002
Apr 24, 2002
513
return FLAC_seek(sample, 0);
Jan 17, 2002
Jan 17, 2002
514
515
} /* FLAC_rewind */
Apr 21, 2002
Apr 21, 2002
516
517
518
static int FLAC_seek(Sound_Sample *sample, Uint32 ms)
{
Apr 24, 2002
Apr 24, 2002
519
520
521
522
523
Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
flac_t *f = (flac_t *) internal->decoder_private;
d_seek_absolute(f->decoder, (ms * sample->actual.rate) / 1000);
return(1);
Apr 21, 2002
Apr 21, 2002
524
525
} /* FLAC_seek */
Nov 9, 2001
Nov 9, 2001
526
527
528
#endif /* SOUND_SUPPORTS_FLAC */
/* end of flac.c ... */