Lines 46-51
Link Here
|
46 |
#include "sfendian.h" |
46 |
#include "sfendian.h" |
47 |
#include "float_cast.h" |
47 |
#include "float_cast.h" |
48 |
|
48 |
|
|
|
49 |
/* FLAC 1.1.3 has FLAC_API_VERSION_CURRENT == 8 */ |
50 |
#if !defined(FLAC_API_VERSION_CURRENT) || FLAC_API_VERSION_CURRENT < 8 |
51 |
#define LEGACY_FLAC |
52 |
#else |
53 |
#undef LEGACY_FLAC |
54 |
#endif |
55 |
|
49 |
/*------------------------------------------------------------------------------ |
56 |
/*------------------------------------------------------------------------------ |
50 |
** Private static functions. |
57 |
** Private static functions. |
51 |
*/ |
58 |
*/ |
Lines 60-67
Link Here
|
60 |
} PFLAC_PCM ; |
67 |
} PFLAC_PCM ; |
61 |
|
68 |
|
62 |
typedef struct |
69 |
typedef struct |
63 |
{ FLAC__SeekableStreamDecoder *fsd ; |
70 |
{ |
|
|
71 |
#ifdef LEGACY_FLAC |
72 |
FLAC__SeekableStreamDecoder *fsd ; |
64 |
FLAC__SeekableStreamEncoder *fse ; |
73 |
FLAC__SeekableStreamEncoder *fse ; |
|
|
74 |
#else |
75 |
FLAC__StreamDecoder *fsd ; |
76 |
FLAC__StreamEncoder *fse ; |
77 |
#endif |
65 |
PFLAC_PCM pcmtype ; |
78 |
PFLAC_PCM pcmtype ; |
66 |
void* ptr ; |
79 |
void* ptr ; |
67 |
unsigned pos, len, remain ; |
80 |
unsigned pos, len, remain ; |
Lines 108-113
Link Here
|
108 |
static int flac_command (SF_PRIVATE *psf, int command, void *data, int datasize) ; |
121 |
static int flac_command (SF_PRIVATE *psf, int command, void *data, int datasize) ; |
109 |
|
122 |
|
110 |
/* Decoder Callbacks */ |
123 |
/* Decoder Callbacks */ |
|
|
124 |
#ifdef LEGACY_FLAC |
111 |
static FLAC__SeekableStreamDecoderReadStatus sf_flac_read_callback (const FLAC__SeekableStreamDecoder *decoder, FLAC__byte buffer [], unsigned *bytes, void *client_data) ; |
125 |
static FLAC__SeekableStreamDecoderReadStatus sf_flac_read_callback (const FLAC__SeekableStreamDecoder *decoder, FLAC__byte buffer [], unsigned *bytes, void *client_data) ; |
112 |
static FLAC__SeekableStreamDecoderSeekStatus sf_flac_seek_callback (const FLAC__SeekableStreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data) ; |
126 |
static FLAC__SeekableStreamDecoderSeekStatus sf_flac_seek_callback (const FLAC__SeekableStreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data) ; |
113 |
static FLAC__SeekableStreamDecoderTellStatus sf_flac_tell_callback (const FLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data) ; |
127 |
static FLAC__SeekableStreamDecoderTellStatus sf_flac_tell_callback (const FLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data) ; |
Lines 116-128
Link Here
|
116 |
static FLAC__StreamDecoderWriteStatus sf_flac_write_callback (const FLAC__SeekableStreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer [], void *client_data) ; |
130 |
static FLAC__StreamDecoderWriteStatus sf_flac_write_callback (const FLAC__SeekableStreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer [], void *client_data) ; |
117 |
static void sf_flac_meta_callback (const FLAC__SeekableStreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data) ; |
131 |
static void sf_flac_meta_callback (const FLAC__SeekableStreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data) ; |
118 |
static void sf_flac_error_callback (const FLAC__SeekableStreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data) ; |
132 |
static void sf_flac_error_callback (const FLAC__SeekableStreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data) ; |
|
|
133 |
#else |
134 |
static FLAC__StreamDecoderReadStatus sf_flac_read_callback (const FLAC__StreamDecoder *decoder, FLAC__byte buffer [], size_t *bytes, void *client_data) ; |
135 |
static FLAC__StreamDecoderSeekStatus sf_flac_seek_callback (const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data) ; |
136 |
static FLAC__StreamDecoderTellStatus sf_flac_tell_callback (const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data) ; |
137 |
static FLAC__StreamDecoderLengthStatus sf_flac_length_callback (const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data) ; |
138 |
static FLAC__bool sf_flac_eof_callback (const FLAC__StreamDecoder *decoder, void *client_data) ; |
139 |
static FLAC__StreamDecoderWriteStatus sf_flac_write_callback (const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer [], void *client_data) ; |
140 |
static void sf_flac_meta_callback (const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data) ; |
141 |
static void sf_flac_error_callback (const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data) ; |
142 |
#endif |
119 |
|
143 |
|
120 |
/* Encoder Callbacks */ |
144 |
/* Encoder Callbacks */ |
|
|
145 |
#ifdef LEGACY_FLAC |
121 |
static FLAC__SeekableStreamEncoderSeekStatus sf_flac_enc_seek_callback (const FLAC__SeekableStreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data) ; |
146 |
static FLAC__SeekableStreamEncoderSeekStatus sf_flac_enc_seek_callback (const FLAC__SeekableStreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data) ; |
122 |
#ifdef HAVE_FLAC_1_1_1 |
147 |
#ifdef HAVE_FLAC_1_1_1 |
123 |
static FLAC__SeekableStreamEncoderTellStatus sf_flac_enc_tell_callback (const FLAC__SeekableStreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data) ; |
148 |
static FLAC__SeekableStreamEncoderTellStatus sf_flac_enc_tell_callback (const FLAC__SeekableStreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data) ; |
124 |
#endif |
149 |
#endif |
125 |
static FLAC__StreamEncoderWriteStatus sf_flac_enc_write_callback (const FLAC__SeekableStreamEncoder *encoder, const FLAC__byte buffer [], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data) ; |
150 |
static FLAC__StreamEncoderWriteStatus sf_flac_enc_write_callback (const FLAC__SeekableStreamEncoder *encoder, const FLAC__byte buffer [], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data) ; |
|
|
151 |
#else |
152 |
static FLAC__StreamEncoderSeekStatus sf_flac_enc_seek_callback (const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data) ; |
153 |
static FLAC__StreamEncoderTellStatus sf_flac_enc_tell_callback (const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data) ; |
154 |
static FLAC__StreamEncoderWriteStatus sf_flac_enc_write_callback (const FLAC__StreamEncoder *encoder, const FLAC__byte buffer [], size_t bytes, unsigned samples, unsigned current_frame, void *client_data) ; |
155 |
#endif |
126 |
|
156 |
|
127 |
static const int legal_sample_rates [] = |
157 |
static const int legal_sample_rates [] = |
128 |
{ 8000, 16000, 22050, 24000, 32000, 44100, 48000, 96000 |
158 |
{ 8000, 16000, 22050, 24000, 32000, 44100, 48000, 96000 |
Lines 283-333
Link Here
|
283 |
} /* flac_buffer_copy */ |
313 |
} /* flac_buffer_copy */ |
284 |
|
314 |
|
285 |
|
315 |
|
|
|
316 |
#ifdef LEGACY_FLAC |
286 |
static FLAC__SeekableStreamDecoderReadStatus |
317 |
static FLAC__SeekableStreamDecoderReadStatus |
287 |
sf_flac_read_callback (const FLAC__SeekableStreamDecoder * UNUSED (decoder), FLAC__byte buffer [], unsigned *bytes, void *client_data) |
318 |
sf_flac_read_callback (const FLAC__SeekableStreamDecoder * UNUSED (decoder), FLAC__byte buffer [], unsigned *bytes, void *client_data) |
|
|
319 |
#else |
320 |
static FLAC__StreamDecoderReadStatus |
321 |
sf_flac_read_callback (const FLAC__StreamDecoder * UNUSED (decoder), FLAC__byte buffer [], size_t *bytes, void *client_data) |
322 |
#endif |
288 |
{ SF_PRIVATE *psf = (SF_PRIVATE*) client_data ; |
323 |
{ SF_PRIVATE *psf = (SF_PRIVATE*) client_data ; |
289 |
|
324 |
|
290 |
*bytes = psf_fread (buffer, 1, *bytes, psf) ; |
325 |
*bytes = psf_fread (buffer, 1, *bytes, psf) ; |
291 |
if (*bytes > 0 && psf->error == 0) |
326 |
if (*bytes > 0 && psf->error == 0) |
|
|
327 |
#ifdef LEGACY_FLAC |
292 |
return FLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_OK ; |
328 |
return FLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_OK ; |
293 |
|
329 |
|
294 |
return FLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_ERROR ; |
330 |
return FLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_ERROR ; |
|
|
331 |
#else |
332 |
return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE ; |
333 |
|
334 |
return FLAC__STREAM_DECODER_READ_STATUS_ABORT ; |
335 |
#endif |
295 |
} /* sf_flac_read_callback */ |
336 |
} /* sf_flac_read_callback */ |
296 |
|
337 |
|
|
|
338 |
#ifdef LEGACY_FLAC |
297 |
static FLAC__SeekableStreamDecoderSeekStatus |
339 |
static FLAC__SeekableStreamDecoderSeekStatus |
298 |
sf_flac_seek_callback (const FLAC__SeekableStreamDecoder * UNUSED (decoder), FLAC__uint64 absolute_byte_offset, void *client_data) |
340 |
sf_flac_seek_callback (const FLAC__SeekableStreamDecoder * UNUSED (decoder), FLAC__uint64 absolute_byte_offset, void *client_data) |
|
|
341 |
#else |
342 |
static FLAC__StreamDecoderSeekStatus |
343 |
sf_flac_seek_callback (const FLAC__StreamDecoder * UNUSED (decoder), FLAC__uint64 absolute_byte_offset, void *client_data) |
344 |
#endif |
299 |
{ SF_PRIVATE *psf = (SF_PRIVATE*) client_data ; |
345 |
{ SF_PRIVATE *psf = (SF_PRIVATE*) client_data ; |
300 |
|
346 |
|
301 |
psf_fseek (psf, absolute_byte_offset, SEEK_SET) ; |
347 |
psf_fseek (psf, absolute_byte_offset, SEEK_SET) ; |
302 |
if (psf->error) |
348 |
if (psf->error) |
|
|
349 |
#ifdef LEGACY_FLAC |
303 |
return FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_ERROR ; |
350 |
return FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_ERROR ; |
304 |
|
351 |
|
305 |
return FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_OK ; |
352 |
return FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_OK ; |
|
|
353 |
#else |
354 |
return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR ; |
355 |
|
356 |
return FLAC__STREAM_DECODER_SEEK_STATUS_OK ; |
357 |
#endif |
306 |
} /* sf_flac_seek_callback */ |
358 |
} /* sf_flac_seek_callback */ |
307 |
|
359 |
|
|
|
360 |
#ifdef LEGACY_FLAC |
308 |
static FLAC__SeekableStreamDecoderTellStatus |
361 |
static FLAC__SeekableStreamDecoderTellStatus |
309 |
sf_flac_tell_callback (const FLAC__SeekableStreamDecoder * UNUSED (decoder), FLAC__uint64 *absolute_byte_offset, void *client_data) |
362 |
sf_flac_tell_callback (const FLAC__SeekableStreamDecoder * UNUSED (decoder), FLAC__uint64 *absolute_byte_offset, void *client_data) |
|
|
363 |
#else |
364 |
static FLAC__StreamDecoderTellStatus |
365 |
sf_flac_tell_callback (const FLAC__StreamDecoder * UNUSED (decoder), FLAC__uint64 *absolute_byte_offset, void *client_data) |
366 |
#endif |
310 |
{ SF_PRIVATE *psf = (SF_PRIVATE*) client_data ; |
367 |
{ SF_PRIVATE *psf = (SF_PRIVATE*) client_data ; |
311 |
|
368 |
|
312 |
*absolute_byte_offset = psf_ftell (psf) ; |
369 |
*absolute_byte_offset = psf_ftell (psf) ; |
313 |
if (psf->error) |
370 |
if (psf->error) |
|
|
371 |
#ifdef LEGACY_FLAC |
314 |
return FLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_ERROR ; |
372 |
return FLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_ERROR ; |
315 |
|
373 |
|
316 |
return FLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_OK ; |
374 |
return FLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_OK ; |
|
|
375 |
#else |
376 |
return FLAC__STREAM_DECODER_TELL_STATUS_ERROR ; |
377 |
|
378 |
return FLAC__STREAM_DECODER_TELL_STATUS_OK ; |
379 |
#endif |
317 |
} /* sf_flac_tell_callback */ |
380 |
} /* sf_flac_tell_callback */ |
318 |
|
381 |
|
|
|
382 |
#ifdef LEGACY_FLAC |
319 |
static FLAC__SeekableStreamDecoderLengthStatus |
383 |
static FLAC__SeekableStreamDecoderLengthStatus |
320 |
sf_flac_length_callback (const FLAC__SeekableStreamDecoder * UNUSED (decoder), FLAC__uint64 *stream_length, void *client_data) |
384 |
sf_flac_length_callback (const FLAC__SeekableStreamDecoder * UNUSED (decoder), FLAC__uint64 *stream_length, void *client_data) |
|
|
385 |
#else |
386 |
static FLAC__StreamDecoderLengthStatus |
387 |
sf_flac_length_callback (const FLAC__StreamDecoder * UNUSED (decoder), FLAC__uint64 *stream_length, void *client_data) |
388 |
#endif |
321 |
{ SF_PRIVATE *psf = (SF_PRIVATE*) client_data ; |
389 |
{ SF_PRIVATE *psf = (SF_PRIVATE*) client_data ; |
322 |
|
390 |
|
323 |
if ((*stream_length = psf->filelength) == 0) |
391 |
if ((*stream_length = psf->filelength) == 0) |
|
|
392 |
#ifdef LEGACY_FLAC |
324 |
return FLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_ERROR ; |
393 |
return FLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_ERROR ; |
325 |
|
394 |
|
326 |
return FLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_OK ; |
395 |
return FLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_OK ; |
|
|
396 |
#else |
397 |
return FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR ; |
398 |
|
399 |
return FLAC__STREAM_DECODER_LENGTH_STATUS_OK ; |
400 |
#endif |
327 |
} /* sf_flac_length_callback */ |
401 |
} /* sf_flac_length_callback */ |
328 |
|
402 |
|
329 |
static FLAC__bool |
403 |
static FLAC__bool |
|
|
404 |
#ifdef LEGACY_FLAC |
330 |
sf_flac_eof_callback (const FLAC__SeekableStreamDecoder *UNUSED (decoder), void *client_data) |
405 |
sf_flac_eof_callback (const FLAC__SeekableStreamDecoder *UNUSED (decoder), void *client_data) |
|
|
406 |
#else |
407 |
sf_flac_eof_callback (const FLAC__StreamDecoder *UNUSED (decoder), void *client_data) |
408 |
#endif |
331 |
{ SF_PRIVATE *psf = (SF_PRIVATE*) client_data ; |
409 |
{ SF_PRIVATE *psf = (SF_PRIVATE*) client_data ; |
332 |
|
410 |
|
333 |
if (psf_ftell (psf) == psf->filelength) |
411 |
if (psf_ftell (psf) == psf->filelength) |
Lines 337-343
Link Here
|
337 |
} /* sf_flac_eof_callback */ |
415 |
} /* sf_flac_eof_callback */ |
338 |
|
416 |
|
339 |
static FLAC__StreamDecoderWriteStatus |
417 |
static FLAC__StreamDecoderWriteStatus |
|
|
418 |
#ifdef LEGACY_FLAC |
340 |
sf_flac_write_callback (const FLAC__SeekableStreamDecoder * UNUSED (decoder), const FLAC__Frame *frame, const FLAC__int32 * const buffer [], void *client_data) |
419 |
sf_flac_write_callback (const FLAC__SeekableStreamDecoder * UNUSED (decoder), const FLAC__Frame *frame, const FLAC__int32 * const buffer [], void *client_data) |
|
|
420 |
#else |
421 |
sf_flac_write_callback (const FLAC__StreamDecoder * UNUSED (decoder), const FLAC__Frame *frame, const FLAC__int32 * const buffer [], void *client_data) |
422 |
#endif |
341 |
{ SF_PRIVATE *psf = (SF_PRIVATE*) client_data ; |
423 |
{ SF_PRIVATE *psf = (SF_PRIVATE*) client_data ; |
342 |
FLAC_PRIVATE* pflac = (FLAC_PRIVATE*) psf->fdata ; |
424 |
FLAC_PRIVATE* pflac = (FLAC_PRIVATE*) psf->fdata ; |
343 |
|
425 |
|
Lines 353-359
Link Here
|
353 |
} /* sf_flac_write_callback */ |
435 |
} /* sf_flac_write_callback */ |
354 |
|
436 |
|
355 |
static void |
437 |
static void |
|
|
438 |
#ifdef LEGACY_FLAC |
356 |
sf_flac_meta_callback (const FLAC__SeekableStreamDecoder * UNUSED (decoder), const FLAC__StreamMetadata *metadata, void *client_data) |
439 |
sf_flac_meta_callback (const FLAC__SeekableStreamDecoder * UNUSED (decoder), const FLAC__StreamMetadata *metadata, void *client_data) |
|
|
440 |
#else |
441 |
sf_flac_meta_callback (const FLAC__StreamDecoder * UNUSED (decoder), const FLAC__StreamMetadata *metadata, void *client_data) |
442 |
#endif |
357 |
{ SF_PRIVATE *psf = (SF_PRIVATE*) client_data ; |
443 |
{ SF_PRIVATE *psf = (SF_PRIVATE*) client_data ; |
358 |
|
444 |
|
359 |
switch (metadata->type) |
445 |
switch (metadata->type) |
Lines 387-393
Link Here
|
387 |
} /* sf_flac_meta_callback */ |
473 |
} /* sf_flac_meta_callback */ |
388 |
|
474 |
|
389 |
static void |
475 |
static void |
|
|
476 |
#ifdef LEGACY_FLAC |
390 |
sf_flac_error_callback (const FLAC__SeekableStreamDecoder * UNUSED (decoder), FLAC__StreamDecoderErrorStatus status, void *client_data) |
477 |
sf_flac_error_callback (const FLAC__SeekableStreamDecoder * UNUSED (decoder), FLAC__StreamDecoderErrorStatus status, void *client_data) |
|
|
478 |
#else |
479 |
sf_flac_error_callback (const FLAC__StreamDecoder * UNUSED (decoder), FLAC__StreamDecoderErrorStatus status, void *client_data) |
480 |
#endif |
391 |
{ SF_PRIVATE *psf = (SF_PRIVATE*) client_data ; |
481 |
{ SF_PRIVATE *psf = (SF_PRIVATE*) client_data ; |
392 |
|
482 |
|
393 |
psf_log_printf (psf, "ERROR : %s\n", FLAC__StreamDecoderErrorStatusString [status]) ; |
483 |
psf_log_printf (psf, "ERROR : %s\n", FLAC__StreamDecoderErrorStatusString [status]) ; |
Lines 407-423
Link Here
|
407 |
return ; |
497 |
return ; |
408 |
} /* sf_flac_error_callback */ |
498 |
} /* sf_flac_error_callback */ |
409 |
|
499 |
|
|
|
500 |
#ifdef LEGACY_FLAC |
410 |
static FLAC__SeekableStreamEncoderSeekStatus |
501 |
static FLAC__SeekableStreamEncoderSeekStatus |
411 |
sf_flac_enc_seek_callback (const FLAC__SeekableStreamEncoder * UNUSED (encoder), FLAC__uint64 absolute_byte_offset, void *client_data) |
502 |
sf_flac_enc_seek_callback (const FLAC__SeekableStreamEncoder * UNUSED (encoder), FLAC__uint64 absolute_byte_offset, void *client_data) |
|
|
503 |
#else |
504 |
static FLAC__StreamEncoderSeekStatus |
505 |
sf_flac_enc_seek_callback (const FLAC__StreamEncoder * UNUSED (encoder), FLAC__uint64 absolute_byte_offset, void *client_data) |
506 |
#endif |
412 |
{ SF_PRIVATE *psf = (SF_PRIVATE*) client_data ; |
507 |
{ SF_PRIVATE *psf = (SF_PRIVATE*) client_data ; |
413 |
|
508 |
|
414 |
psf_fseek (psf, absolute_byte_offset, SEEK_SET) ; |
509 |
psf_fseek (psf, absolute_byte_offset, SEEK_SET) ; |
415 |
if (psf->error) |
510 |
if (psf->error) |
|
|
511 |
#ifdef LEGACY_FLAC |
416 |
return FLAC__SEEKABLE_STREAM_ENCODER_SEEK_STATUS_ERROR ; |
512 |
return FLAC__SEEKABLE_STREAM_ENCODER_SEEK_STATUS_ERROR ; |
417 |
|
513 |
|
418 |
return FLAC__SEEKABLE_STREAM_ENCODER_SEEK_STATUS_OK ; |
514 |
return FLAC__SEEKABLE_STREAM_ENCODER_SEEK_STATUS_OK ; |
|
|
515 |
#else |
516 |
return FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR ; |
517 |
|
518 |
return FLAC__STREAM_ENCODER_SEEK_STATUS_OK ; |
519 |
#endif |
419 |
} /* sf_flac_enc_seek_callback */ |
520 |
} /* sf_flac_enc_seek_callback */ |
420 |
|
521 |
|
|
|
522 |
#ifdef LEGACY_FLAC |
421 |
#ifdef HAVE_FLAC_1_1_1 |
523 |
#ifdef HAVE_FLAC_1_1_1 |
422 |
static FLAC__SeekableStreamEncoderTellStatus |
524 |
static FLAC__SeekableStreamEncoderTellStatus |
423 |
sf_flac_enc_tell_callback (const FLAC__SeekableStreamEncoder *UNUSED (encoder), FLAC__uint64 *absolute_byte_offset, void *client_data) |
525 |
sf_flac_enc_tell_callback (const FLAC__SeekableStreamEncoder *UNUSED (encoder), FLAC__uint64 *absolute_byte_offset, void *client_data) |
Lines 430-438
Link Here
|
430 |
return FLAC__SEEKABLE_STREAM_ENCODER_TELL_STATUS_OK ; |
532 |
return FLAC__SEEKABLE_STREAM_ENCODER_TELL_STATUS_OK ; |
431 |
} /* sf_flac_enc_tell_callback */ |
533 |
} /* sf_flac_enc_tell_callback */ |
432 |
#endif |
534 |
#endif |
|
|
535 |
#else |
536 |
static FLAC__StreamEncoderTellStatus |
537 |
sf_flac_enc_tell_callback (const FLAC__StreamEncoder *UNUSED (encoder), FLAC__uint64 *absolute_byte_offset, void *client_data) |
538 |
{ SF_PRIVATE *psf = (SF_PRIVATE*) client_data ; |
539 |
|
540 |
*absolute_byte_offset = psf_ftell (psf) ; |
541 |
if (psf->error) |
542 |
return FLAC__STREAM_ENCODER_TELL_STATUS_ERROR ; |
543 |
|
544 |
return FLAC__STREAM_ENCODER_TELL_STATUS_OK ; |
545 |
} /* sf_flac_enc_tell_callback */ |
546 |
#endif |
433 |
|
547 |
|
434 |
static FLAC__StreamEncoderWriteStatus |
548 |
static FLAC__StreamEncoderWriteStatus |
|
|
549 |
#ifdef LEGACY_FLAC |
435 |
sf_flac_enc_write_callback (const FLAC__SeekableStreamEncoder * UNUSED (encoder), const FLAC__byte buffer [], unsigned bytes, unsigned UNUSED (samples), unsigned UNUSED (current_frame), void *client_data) |
550 |
sf_flac_enc_write_callback (const FLAC__SeekableStreamEncoder * UNUSED (encoder), const FLAC__byte buffer [], unsigned bytes, unsigned UNUSED (samples), unsigned UNUSED (current_frame), void *client_data) |
|
|
551 |
#else |
552 |
sf_flac_enc_write_callback (const FLAC__StreamEncoder * UNUSED (encoder), const FLAC__byte buffer [], size_t bytes, unsigned UNUSED (samples), unsigned UNUSED (current_frame), void *client_data) |
553 |
#endif |
436 |
{ SF_PRIVATE *psf = (SF_PRIVATE*) client_data ; |
554 |
{ SF_PRIVATE *psf = (SF_PRIVATE*) client_data ; |
437 |
|
555 |
|
438 |
if (psf_fwrite (buffer, 1, bytes, psf) == bytes && psf->error == 0) |
556 |
if (psf_fwrite (buffer, 1, bytes, psf) == bytes && psf->error == 0) |
Lines 509-523
Link Here
|
509 |
return 0 ; |
627 |
return 0 ; |
510 |
|
628 |
|
511 |
if (psf->mode == SFM_WRITE) |
629 |
if (psf->mode == SFM_WRITE) |
512 |
{ FLAC__seekable_stream_encoder_finish (pflac->fse) ; |
630 |
{ |
|
|
631 |
#ifdef LEGACY_FLAC |
632 |
FLAC__seekable_stream_encoder_finish (pflac->fse) ; |
513 |
FLAC__seekable_stream_encoder_delete (pflac->fse) ; |
633 |
FLAC__seekable_stream_encoder_delete (pflac->fse) ; |
|
|
634 |
#else |
635 |
FLAC__stream_encoder_finish (pflac->fse) ; |
636 |
FLAC__stream_encoder_delete (pflac->fse) ; |
637 |
#endif |
514 |
if (pflac->encbuffer) |
638 |
if (pflac->encbuffer) |
515 |
free (pflac->encbuffer) ; |
639 |
free (pflac->encbuffer) ; |
516 |
} ; |
640 |
} ; |
517 |
|
641 |
|
518 |
if (psf->mode == SFM_READ) |
642 |
if (psf->mode == SFM_READ) |
519 |
{ FLAC__seekable_stream_decoder_finish (pflac->fsd) ; |
643 |
{ |
|
|
644 |
#ifdef LEGACY_FLAC |
645 |
FLAC__seekable_stream_decoder_finish (pflac->fsd) ; |
520 |
FLAC__seekable_stream_decoder_delete (pflac->fsd) ; |
646 |
FLAC__seekable_stream_decoder_delete (pflac->fsd) ; |
|
|
647 |
#else |
648 |
FLAC__stream_decoder_finish (pflac->fsd) ; |
649 |
FLAC__stream_decoder_delete (pflac->fsd) ; |
650 |
#endif |
521 |
} ; |
651 |
} ; |
522 |
|
652 |
|
523 |
for (k = 0 ; k < ARRAY_LEN (pflac->rbuffer) ; k++) |
653 |
for (k = 0 ; k < ARRAY_LEN (pflac->rbuffer) ; k++) |
Lines 546-562
Link Here
|
546 |
return SFE_FLAC_BAD_SAMPLE_RATE ; |
676 |
return SFE_FLAC_BAD_SAMPLE_RATE ; |
547 |
|
677 |
|
548 |
psf_fseek (psf, 0, SEEK_SET) ; |
678 |
psf_fseek (psf, 0, SEEK_SET) ; |
549 |
if ((pflac->fse = FLAC__seekable_stream_encoder_new ()) == NULL) |
|
|
550 |
return SFE_FLAC_NEW_DECODER ; |
551 |
FLAC__seekable_stream_encoder_set_write_callback (pflac->fse, sf_flac_enc_write_callback) ; |
552 |
FLAC__seekable_stream_encoder_set_seek_callback (pflac->fse, sf_flac_enc_seek_callback) ; |
553 |
|
554 |
#ifdef HAVE_FLAC_1_1_1 |
555 |
FLAC__seekable_stream_encoder_set_tell_callback (pflac->fse, sf_flac_enc_tell_callback) ; |
556 |
#endif |
557 |
FLAC__seekable_stream_encoder_set_client_data (pflac->fse, psf) ; |
558 |
FLAC__seekable_stream_encoder_set_channels (pflac->fse, psf->sf.channels) ; |
559 |
FLAC__seekable_stream_encoder_set_sample_rate (pflac->fse, psf->sf.samplerate) ; |
560 |
|
679 |
|
561 |
switch (psf->sf.format & SF_FORMAT_SUBMASK) |
680 |
switch (psf->sf.format & SF_FORMAT_SUBMASK) |
562 |
{ case SF_FORMAT_PCM_S8 : |
681 |
{ case SF_FORMAT_PCM_S8 : |
Lines 574-585
Link Here
|
574 |
break ; |
693 |
break ; |
575 |
} ; |
694 |
} ; |
576 |
|
695 |
|
|
|
696 |
#ifdef LEGACY_FLAC |
697 |
if ((pflac->fse = FLAC__seekable_stream_encoder_new ()) == NULL) |
698 |
return SFE_FLAC_NEW_DECODER ; |
699 |
FLAC__seekable_stream_encoder_set_write_callback (pflac->fse, sf_flac_enc_write_callback) ; |
700 |
FLAC__seekable_stream_encoder_set_seek_callback (pflac->fse, sf_flac_enc_seek_callback) ; |
701 |
|
702 |
#ifdef HAVE_FLAC_1_1_1 |
703 |
FLAC__seekable_stream_encoder_set_tell_callback (pflac->fse, sf_flac_enc_tell_callback) ; |
704 |
#endif |
705 |
FLAC__seekable_stream_encoder_set_client_data (pflac->fse, psf) ; |
706 |
FLAC__seekable_stream_encoder_set_channels (pflac->fse, psf->sf.channels) ; |
707 |
FLAC__seekable_stream_encoder_set_sample_rate (pflac->fse, psf->sf.samplerate) ; |
577 |
FLAC__seekable_stream_encoder_set_bits_per_sample (pflac->fse, bps) ; |
708 |
FLAC__seekable_stream_encoder_set_bits_per_sample (pflac->fse, bps) ; |
578 |
|
709 |
|
579 |
if ((bps = FLAC__seekable_stream_encoder_init (pflac->fse)) != FLAC__SEEKABLE_STREAM_DECODER_OK) |
710 |
if ((bps = FLAC__seekable_stream_encoder_init (pflac->fse)) != FLAC__SEEKABLE_STREAM_DECODER_OK) |
580 |
{ psf_log_printf (psf, "Error : FLAC encoder init returned error : %s\n", FLAC__seekable_stream_encoder_get_resolved_state_string (pflac->fse)) ; |
711 |
{ psf_log_printf (psf, "Error : FLAC encoder init returned error : %s\n", FLAC__seekable_stream_encoder_get_resolved_state_string (pflac->fse)) ; |
581 |
return SFE_FLAC_INIT_DECODER ; |
712 |
return SFE_FLAC_INIT_DECODER ; |
582 |
} ; |
713 |
} ; |
|
|
714 |
#else |
715 |
if ((pflac->fse = FLAC__stream_encoder_new ()) == NULL) |
716 |
return SFE_FLAC_NEW_DECODER ; |
717 |
FLAC__stream_encoder_set_channels (pflac->fse, psf->sf.channels) ; |
718 |
FLAC__stream_encoder_set_sample_rate (pflac->fse, psf->sf.samplerate) ; |
719 |
FLAC__stream_encoder_set_bits_per_sample (pflac->fse, bps) ; |
720 |
|
721 |
if ((bps = FLAC__stream_encoder_init_stream (pflac->fse, sf_flac_enc_write_callback, sf_flac_enc_seek_callback, sf_flac_enc_tell_callback, NULL, psf)) != FLAC__STREAM_DECODER_INIT_STATUS_OK) |
722 |
{ psf_log_printf (psf, "Error : FLAC encoder init returned error : %s\n", FLAC__StreamEncoderInitStatusString[bps]) ; |
723 |
return SFE_FLAC_INIT_DECODER ; |
724 |
} ; |
725 |
#endif |
583 |
|
726 |
|
584 |
if (psf->error == 0) |
727 |
if (psf->error == 0) |
585 |
psf->dataoffset = psf_ftell (psf) ; |
728 |
psf->dataoffset = psf_ftell (psf) ; |
Lines 593-598
Link Here
|
593 |
{ FLAC_PRIVATE* pflac = (FLAC_PRIVATE*) psf->fdata ; |
736 |
{ FLAC_PRIVATE* pflac = (FLAC_PRIVATE*) psf->fdata ; |
594 |
|
737 |
|
595 |
psf_fseek (psf, 0, SEEK_SET) ; |
738 |
psf_fseek (psf, 0, SEEK_SET) ; |
|
|
739 |
#ifdef LEGACY_FLAC |
596 |
if ((pflac->fsd = FLAC__seekable_stream_decoder_new ()) == NULL) |
740 |
if ((pflac->fsd = FLAC__seekable_stream_decoder_new ()) == NULL) |
597 |
return SFE_FLAC_NEW_DECODER ; |
741 |
return SFE_FLAC_NEW_DECODER ; |
598 |
|
742 |
|
Lines 610-618
Link Here
|
610 |
return SFE_FLAC_INIT_DECODER ; |
754 |
return SFE_FLAC_INIT_DECODER ; |
611 |
|
755 |
|
612 |
FLAC__seekable_stream_decoder_process_until_end_of_metadata (pflac->fsd) ; |
756 |
FLAC__seekable_stream_decoder_process_until_end_of_metadata (pflac->fsd) ; |
|
|
757 |
#else |
758 |
if ((pflac->fsd = FLAC__stream_decoder_new ()) == NULL) |
759 |
return SFE_FLAC_NEW_DECODER ; |
760 |
|
761 |
if (FLAC__stream_decoder_init_stream (pflac->fsd, sf_flac_read_callback, sf_flac_seek_callback, sf_flac_tell_callback, sf_flac_length_callback, sf_flac_eof_callback, sf_flac_write_callback, sf_flac_meta_callback, sf_flac_error_callback, psf) != FLAC__STREAM_DECODER_INIT_STATUS_OK) |
762 |
return SFE_FLAC_INIT_DECODER ; |
763 |
|
764 |
FLAC__stream_decoder_process_until_end_of_metadata (pflac->fsd) ; |
765 |
#endif |
613 |
if (psf->error == 0) |
766 |
if (psf->error == 0) |
614 |
{ FLAC__uint64 position ; |
767 |
{ FLAC__uint64 position ; |
|
|
768 |
#ifdef LEGACY_FLAC |
615 |
FLAC__seekable_stream_decoder_get_decode_position (pflac->fsd, &position) ; |
769 |
FLAC__seekable_stream_decoder_get_decode_position (pflac->fsd, &position) ; |
|
|
770 |
#else |
771 |
FLAC__stream_decoder_get_decode_position (pflac->fsd, &position) ; |
772 |
#endif |
616 |
psf->dataoffset = position ; |
773 |
psf->dataoffset = position ; |
617 |
} ; |
774 |
} ; |
618 |
|
775 |
|
Lines 676-685
Link Here
|
676 |
flac_buffer_copy (psf) ; |
833 |
flac_buffer_copy (psf) ; |
677 |
|
834 |
|
678 |
while (pflac->pos < pflac->len) |
835 |
while (pflac->pos < pflac->len) |
679 |
{ if (FLAC__seekable_stream_decoder_process_single (pflac->fsd) == 0) |
836 |
{ |
|
|
837 |
#ifdef LEGACY_FLAC |
838 |
if (FLAC__seekable_stream_decoder_process_single (pflac->fsd) == 0) |
680 |
break ; |
839 |
break ; |
681 |
if (FLAC__seekable_stream_decoder_get_state (pflac->fsd) != FLAC__SEEKABLE_STREAM_DECODER_OK) |
840 |
if (FLAC__seekable_stream_decoder_get_state (pflac->fsd) != FLAC__SEEKABLE_STREAM_DECODER_OK) |
682 |
break ; |
841 |
break ; |
|
|
842 |
#else |
843 |
if (FLAC__stream_decoder_process_single (pflac->fsd) == 0) |
844 |
break ; |
845 |
if (FLAC__stream_decoder_get_state (pflac->fsd) >= FLAC__STREAM_DECODER_END_OF_STREAM) |
846 |
break ; |
847 |
#endif |
683 |
} ; |
848 |
} ; |
684 |
|
849 |
|
685 |
pflac->ptr = NULL ; |
850 |
pflac->ptr = NULL ; |
Lines 795-801
Link Here
|
795 |
while (len > 0) |
960 |
while (len > 0) |
796 |
{ writecount = (len >= bufferlen) ? bufferlen : (int) len ; |
961 |
{ writecount = (len >= bufferlen) ? bufferlen : (int) len ; |
797 |
convert (ptr + total, buffer, writecount) ; |
962 |
convert (ptr + total, buffer, writecount) ; |
|
|
963 |
#ifdef LEGACY_FLAC |
798 |
if (FLAC__seekable_stream_encoder_process_interleaved (pflac->fse, buffer, writecount/psf->sf.channels)) |
964 |
if (FLAC__seekable_stream_encoder_process_interleaved (pflac->fse, buffer, writecount/psf->sf.channels)) |
|
|
965 |
#else |
966 |
if (FLAC__stream_encoder_process_interleaved (pflac->fse, buffer, writecount/psf->sf.channels)) |
967 |
#endif |
799 |
thiswrite = writecount ; |
968 |
thiswrite = writecount ; |
800 |
else |
969 |
else |
801 |
break ; |
970 |
break ; |
Lines 837-843
Link Here
|
837 |
while (len > 0) |
1006 |
while (len > 0) |
838 |
{ writecount = (len >= bufferlen) ? bufferlen : (int) len ; |
1007 |
{ writecount = (len >= bufferlen) ? bufferlen : (int) len ; |
839 |
convert (ptr + total, buffer, writecount) ; |
1008 |
convert (ptr + total, buffer, writecount) ; |
|
|
1009 |
#ifdef LEGACY_FLAC |
840 |
if (FLAC__seekable_stream_encoder_process_interleaved (pflac->fse, buffer, writecount/psf->sf.channels)) |
1010 |
if (FLAC__seekable_stream_encoder_process_interleaved (pflac->fse, buffer, writecount/psf->sf.channels)) |
|
|
1011 |
#else |
1012 |
if (FLAC__stream_encoder_process_interleaved (pflac->fse, buffer, writecount/psf->sf.channels)) |
1013 |
#endif |
841 |
thiswrite = writecount ; |
1014 |
thiswrite = writecount ; |
842 |
else |
1015 |
else |
843 |
break ; |
1016 |
break ; |
Lines 879-885
Link Here
|
879 |
while (len > 0) |
1052 |
while (len > 0) |
880 |
{ writecount = (len >= bufferlen) ? bufferlen : (int) len ; |
1053 |
{ writecount = (len >= bufferlen) ? bufferlen : (int) len ; |
881 |
convert (ptr + total, buffer, writecount, psf->norm_float) ; |
1054 |
convert (ptr + total, buffer, writecount, psf->norm_float) ; |
|
|
1055 |
#ifdef LEGACY_FLAC |
882 |
if (FLAC__seekable_stream_encoder_process_interleaved (pflac->fse, buffer, writecount/psf->sf.channels)) |
1056 |
if (FLAC__seekable_stream_encoder_process_interleaved (pflac->fse, buffer, writecount/psf->sf.channels)) |
|
|
1057 |
#else |
1058 |
if (FLAC__stream_encoder_process_interleaved (pflac->fse, buffer, writecount/psf->sf.channels)) |
1059 |
#endif |
883 |
thiswrite = writecount ; |
1060 |
thiswrite = writecount ; |
884 |
else |
1061 |
else |
885 |
break ; |
1062 |
break ; |
Lines 1011-1017
Link Here
|
1011 |
while (len > 0) |
1188 |
while (len > 0) |
1012 |
{ writecount = (len >= bufferlen) ? bufferlen : (int) len ; |
1189 |
{ writecount = (len >= bufferlen) ? bufferlen : (int) len ; |
1013 |
convert (ptr + total, buffer, writecount, psf->norm_double) ; |
1190 |
convert (ptr + total, buffer, writecount, psf->norm_double) ; |
|
|
1191 |
#ifdef LEGACY_FLAC |
1014 |
if (FLAC__seekable_stream_encoder_process_interleaved (pflac->fse, buffer, writecount/psf->sf.channels)) |
1192 |
if (FLAC__seekable_stream_encoder_process_interleaved (pflac->fse, buffer, writecount/psf->sf.channels)) |
|
|
1193 |
#else |
1194 |
if (FLAC__stream_encoder_process_interleaved (pflac->fse, buffer, writecount/psf->sf.channels)) |
1195 |
#endif |
1015 |
thiswrite = writecount ; |
1196 |
thiswrite = writecount ; |
1016 |
else |
1197 |
else |
1017 |
break ; |
1198 |
break ; |
Lines 1131-1140
Link Here
|
1131 |
|
1312 |
|
1132 |
if (psf->mode == SFM_READ) |
1313 |
if (psf->mode == SFM_READ) |
1133 |
{ FLAC__uint64 position ; |
1314 |
{ FLAC__uint64 position ; |
|
|
1315 |
#ifdef LEGACY_FLAC |
1134 |
if (FLAC__seekable_stream_decoder_seek_absolute (pflac->fsd, offset)) |
1316 |
if (FLAC__seekable_stream_decoder_seek_absolute (pflac->fsd, offset)) |
1135 |
{ FLAC__seekable_stream_decoder_get_decode_position (pflac->fsd, &position) ; |
1317 |
{ FLAC__seekable_stream_decoder_get_decode_position (pflac->fsd, &position) ; |
1136 |
return offset ; |
1318 |
return offset ; |
1137 |
} ; |
1319 |
} ; |
|
|
1320 |
#else |
1321 |
if (FLAC__stream_decoder_seek_absolute (pflac->fsd, offset)) |
1322 |
{ FLAC__stream_decoder_get_decode_position (pflac->fsd, &position) ; |
1323 |
return offset ; |
1324 |
} ; |
1325 |
#endif |
1138 |
|
1326 |
|
1139 |
return ((sf_count_t) -1) ; |
1327 |
return ((sf_count_t) -1) ; |
1140 |
} ; |
1328 |
} ; |