annotate decoders/flac.c @ 312:498240aa76f1

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