Lines 34-46
Link Here
|
34 |
#import <Cynthiune/Format.h> |
34 |
#import <Cynthiune/Format.h> |
35 |
#import <Cynthiune/utils.h> |
35 |
#import <Cynthiune/utils.h> |
36 |
|
36 |
|
|
|
37 |
/* FLAC 1.1.3 has FLAC_API_VERSION_CURRENT == 8 */ |
38 |
#if !defined(FLAC_API_VERSION_CURRENT) || FLAC_API_VERSION_CURRENT < 8 |
39 |
#define LEGACY_FLAC |
40 |
#else |
41 |
#undef LEGACY_FLAC |
42 |
#endif |
43 |
|
37 |
#import "FLAC.h" |
44 |
#import "FLAC.h" |
38 |
|
45 |
|
39 |
#define LOCALIZED(X) _b ([FLAC class], X) |
46 |
#define LOCALIZED(X) _b ([FLAC class], X) |
40 |
|
47 |
|
41 |
static FLAC__StreamDecoderWriteStatus |
48 |
static FLAC__StreamDecoderWriteStatus |
|
|
49 |
#ifdef LEGACY_FLAC |
42 |
writeCallback (const FLAC__FileDecoder *fileDecoder, const FLAC__Frame *frame, |
50 |
writeCallback (const FLAC__FileDecoder *fileDecoder, const FLAC__Frame *frame, |
43 |
const FLAC__int32 * const buffer[], void *clientData) |
51 |
const FLAC__int32 * const buffer[], void *clientData) |
|
|
52 |
#else |
53 |
writeCallback (const FLAC__StreamDecoder *fileDecoder, const FLAC__Frame *frame, |
54 |
const FLAC__int32 * const buffer[], void *clientData) |
55 |
#endif |
44 |
{ |
56 |
{ |
45 |
CFLAC *cStream; |
57 |
CFLAC *cStream; |
46 |
unsigned int sample, channel; |
58 |
unsigned int sample, channel; |
Lines 70-78
Link Here
|
70 |
} |
82 |
} |
71 |
|
83 |
|
72 |
static void |
84 |
static void |
|
|
85 |
#ifdef LEGACY_FLAC |
73 |
metadataCallback (const FLAC__FileDecoder *fileDecoder, |
86 |
metadataCallback (const FLAC__FileDecoder *fileDecoder, |
74 |
const FLAC__StreamMetadata *metadata, |
87 |
const FLAC__StreamMetadata *metadata, |
75 |
void *clientData) |
88 |
void *clientData) |
|
|
89 |
#else |
90 |
metadataCallback (const FLAC__StreamDecoder *fileDecoder, |
91 |
const FLAC__StreamMetadata *metadata, |
92 |
void *clientData) |
93 |
#endif |
76 |
{ |
94 |
{ |
77 |
CFLAC *cStream; |
95 |
CFLAC *cStream; |
78 |
|
96 |
|
Lines 88-96
Link Here
|
88 |
} |
106 |
} |
89 |
|
107 |
|
90 |
static void |
108 |
static void |
|
|
109 |
#ifdef LEGACY_FLAC |
91 |
errorCallback (const FLAC__FileDecoder *fileDecoder, |
110 |
errorCallback (const FLAC__FileDecoder *fileDecoder, |
92 |
FLAC__StreamDecoderErrorStatus status, |
111 |
FLAC__StreamDecoderErrorStatus status, |
93 |
void *clientData) |
112 |
void *clientData) |
|
|
113 |
#else |
114 |
errorCallback (const FLAC__StreamDecoder *fileDecoder, |
115 |
FLAC__StreamDecoderErrorStatus status, |
116 |
void *clientData) |
117 |
#endif |
94 |
{ |
118 |
{ |
95 |
NSLog (@"FLAC: received error with status %d", status); |
119 |
NSLog (@"FLAC: received error with status %d", status); |
96 |
} |
120 |
} |
Lines 161-166
Link Here
|
161 |
|
185 |
|
162 |
- (BOOL) _initializeFileDecoderWithFilename: (NSString *) fileName |
186 |
- (BOOL) _initializeFileDecoderWithFilename: (NSString *) fileName |
163 |
{ |
187 |
{ |
|
|
188 |
#ifdef LEGACY_FLAC |
164 |
FLAC__file_decoder_set_metadata_ignore_all (fileDecoder); |
189 |
FLAC__file_decoder_set_metadata_ignore_all (fileDecoder); |
165 |
FLAC__file_decoder_set_metadata_respond (fileDecoder, |
190 |
FLAC__file_decoder_set_metadata_respond (fileDecoder, |
166 |
FLAC__METADATA_TYPE_STREAMINFO); |
191 |
FLAC__METADATA_TYPE_STREAMINFO); |
Lines 173-185
Link Here
|
173 |
return (FLAC__file_decoder_set_filename (fileDecoder, [fileName cString]) |
198 |
return (FLAC__file_decoder_set_filename (fileDecoder, [fileName cString]) |
174 |
&& (FLAC__file_decoder_init (fileDecoder) == FLAC__FILE_DECODER_OK) |
199 |
&& (FLAC__file_decoder_init (fileDecoder) == FLAC__FILE_DECODER_OK) |
175 |
&& FLAC__file_decoder_process_until_end_of_metadata (fileDecoder)); |
200 |
&& FLAC__file_decoder_process_until_end_of_metadata (fileDecoder)); |
|
|
201 |
#else |
202 |
FLAC__stream_decoder_set_metadata_ignore_all (fileDecoder); |
203 |
FLAC__stream_decoder_set_metadata_respond (fileDecoder, |
204 |
FLAC__METADATA_TYPE_STREAMINFO); |
205 |
return ((FLAC__stream_decoder_init_file (fileDecoder, [fileName cString], |
206 |
writeCallback, metadataCallback, errorCallback, self) == FLAC__STREAM_DECODER_INIT_STATUS_OK) |
207 |
&& FLAC__stream_decoder_process_until_end_of_metadata (fileDecoder)); |
208 |
#endif |
176 |
} |
209 |
} |
177 |
|
210 |
|
178 |
- (BOOL) streamOpen: (NSString *) fileName |
211 |
- (BOOL) streamOpen: (NSString *) fileName |
179 |
{ |
212 |
{ |
180 |
BOOL result; |
213 |
BOOL result; |
181 |
|
214 |
|
|
|
215 |
#ifdef LEGACY_FLAC |
182 |
fileDecoder = FLAC__file_decoder_new(); |
216 |
fileDecoder = FLAC__file_decoder_new(); |
|
|
217 |
#else |
218 |
fileDecoder = FLAC__stream_decoder_new(); |
219 |
#endif |
183 |
|
220 |
|
184 |
if (fileDecoder) |
221 |
if (fileDecoder) |
185 |
{ |
222 |
{ |
Lines 187-193
Link Here
|
187 |
result = YES; |
224 |
result = YES; |
188 |
else |
225 |
else |
189 |
{ |
226 |
{ |
|
|
227 |
#ifdef LEGACY_FLAC |
190 |
FLAC__file_decoder_delete (fileDecoder); |
228 |
FLAC__file_decoder_delete (fileDecoder); |
|
|
229 |
#else |
230 |
FLAC__stream_decoder_delete (fileDecoder); |
231 |
#endif |
191 |
fileDecoder = NULL; |
232 |
fileDecoder = NULL; |
192 |
result = NO; |
233 |
result = NO; |
193 |
} |
234 |
} |
Lines 200-206
Link Here
|
200 |
|
241 |
|
201 |
- (void) streamClose |
242 |
- (void) streamClose |
202 |
{ |
243 |
{ |
|
|
244 |
#ifdef LEGACY_FLAC |
203 |
FLAC__file_decoder_delete (fileDecoder); |
245 |
FLAC__file_decoder_delete (fileDecoder); |
|
|
246 |
#else |
247 |
FLAC__stream_decoder_delete (fileDecoder); |
248 |
#endif |
204 |
fileDecoder = NULL; |
249 |
fileDecoder = NULL; |
205 |
} |
250 |
} |
206 |
|
251 |
|
Lines 215-221
Link Here
|
215 |
if (position >= readBufferSize) |
260 |
if (position >= readBufferSize) |
216 |
{ |
261 |
{ |
217 |
position = 0; |
262 |
position = 0; |
|
|
263 |
#ifdef LEGACY_FLAC |
218 |
success = FLAC__file_decoder_process_single (fileDecoder); |
264 |
success = FLAC__file_decoder_process_single (fileDecoder); |
|
|
265 |
#else |
266 |
success = FLAC__stream_decoder_process_single (fileDecoder); |
267 |
#endif |
219 |
} |
268 |
} |
220 |
|
269 |
|
221 |
if (success) |
270 |
if (success) |
Lines 251-263
Link Here
|
251 |
withSize: (unsigned int) bufferSize |
300 |
withSize: (unsigned int) bufferSize |
252 |
{ |
301 |
{ |
253 |
int readBytes; |
302 |
int readBytes; |
|
|
303 |
#ifdef LEGACY_FLAC |
254 |
FLAC__FileDecoderState state; |
304 |
FLAC__FileDecoderState state; |
255 |
|
305 |
|
256 |
state = FLAC__file_decoder_get_state (fileDecoder); |
306 |
state = FLAC__file_decoder_get_state (fileDecoder); |
|
|
307 |
#else |
308 |
FLAC__StreamDecoderState state; |
309 |
|
310 |
state = FLAC__stream_decoder_get_state (fileDecoder); |
311 |
#endif |
257 |
|
312 |
|
|
|
313 |
#ifdef LEGACY_FLAC |
258 |
if (state == FLAC__FILE_DECODER_OK) |
314 |
if (state == FLAC__FILE_DECODER_OK) |
|
|
315 |
#else |
316 |
if (state < FLAC__STREAM_DECODER_END_OF_STREAM) |
317 |
#endif |
259 |
readBytes = [self _processNextChunk: buffer withSize: bufferSize]; |
318 |
readBytes = [self _processNextChunk: buffer withSize: bufferSize]; |
|
|
319 |
#ifdef LEGACY_FLAC |
260 |
else if (state == FLAC__FILE_DECODER_END_OF_FILE) |
320 |
else if (state == FLAC__FILE_DECODER_END_OF_FILE) |
|
|
321 |
#else |
322 |
else if (state == FLAC__STREAM_DECODER_END_OF_STREAM) |
323 |
#endif |
261 |
readBytes = 0; |
324 |
readBytes = 0; |
262 |
else |
325 |
else |
263 |
readBytes = -1; |
326 |
readBytes = -1; |
Lines 272-278
Link Here
|
272 |
|
335 |
|
273 |
- (void) seek: (unsigned int) aPos |
336 |
- (void) seek: (unsigned int) aPos |
274 |
{ |
337 |
{ |
|
|
338 |
#ifdef LEGACY_FLAC |
275 |
FLAC__file_decoder_seek_absolute (fileDecoder, aPos * rate); |
339 |
FLAC__file_decoder_seek_absolute (fileDecoder, aPos * rate); |
|
|
340 |
#else |
341 |
FLAC__stream_decoder_seek_absolute (fileDecoder, aPos * rate); |
342 |
#endif |
276 |
} |
343 |
} |
277 |
|
344 |
|
278 |
- (unsigned int) readChannels |
345 |
- (unsigned int) readChannels |
Lines 295-301
Link Here
|
295 |
if (readBuffer) |
362 |
if (readBuffer) |
296 |
free (readBuffer); |
363 |
free (readBuffer); |
297 |
if (fileDecoder) |
364 |
if (fileDecoder) |
|
|
365 |
#ifdef LEGACY_FLAC |
298 |
FLAC__file_decoder_delete (fileDecoder); |
366 |
FLAC__file_decoder_delete (fileDecoder); |
|
|
367 |
#else |
368 |
FLAC__stream_decoder_delete (fileDecoder); |
369 |
#endif |
299 |
[super dealloc]; |
370 |
[super dealloc]; |
300 |
} |
371 |
} |
301 |
|
372 |
|