2 ** Copyright (C) 2004-2014 Erik de Castro Lopo <erikd@mega-nerd.com>
3 ** Copyright (C) 2004 Tobias Gehrig <tgehrig@ira.uka.de>
5 ** This program is free software ; you can redistribute it and/or modify
6 ** it under the terms of the GNU Lesser General Public License as published by
7 ** the Free Software Foundation ; either version 2.1 of the License, or
8 ** (at your option) any later version.
10 ** This program is distributed in the hope that it will be useful,
11 ** but WITHOUT ANY WARRANTY ; without even the implied warranty of
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ** GNU Lesser General Public License for more details.
15 ** You should have received a copy of the GNU Lesser General Public License
16 ** along with this program ; if not, write to the Free Software
17 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 #if 0 /* HAVE_EXTERNAL_LIBS : Disable for TIZEN */
34 #include <FLAC/stream_decoder.h>
35 #include <FLAC/stream_encoder.h>
36 #include <FLAC/metadata.h>
38 /*------------------------------------------------------------------------------
39 ** Private static functions.
42 #define FLAC_DEFAULT_COMPRESSION_LEVEL 5
44 #define ENC_BUFFER_SIZE 8192
47 { PFLAC_PCM_SHORT = 50,
55 FLAC__StreamDecoder *fsd ;
56 FLAC__StreamEncoder *fse ;
60 unsigned pos, len, remain ;
62 FLAC__StreamMetadata *metadata ;
64 const FLAC__int32 * const * wbuffer ;
65 FLAC__int32 * rbuffer [FLAC__MAX_CHANNELS] ;
67 FLAC__int32* encbuffer ;
70 const FLAC__Frame *frame ;
72 unsigned compression ;
81 static sf_count_t flac_seek (SF_PRIVATE *psf, int mode, sf_count_t offset) ;
82 static int flac_byterate (SF_PRIVATE *psf) ;
83 static int flac_close (SF_PRIVATE *psf) ;
85 static int flac_enc_init (SF_PRIVATE *psf) ;
86 static int flac_read_header (SF_PRIVATE *psf) ;
88 static sf_count_t flac_read_flac2s (SF_PRIVATE *psf, short *ptr, sf_count_t len) ;
89 static sf_count_t flac_read_flac2i (SF_PRIVATE *psf, int *ptr, sf_count_t len) ;
90 static sf_count_t flac_read_flac2f (SF_PRIVATE *psf, float *ptr, sf_count_t len) ;
91 static sf_count_t flac_read_flac2d (SF_PRIVATE *psf, double *ptr, sf_count_t len) ;
93 static sf_count_t flac_write_s2flac (SF_PRIVATE *psf, const short *ptr, sf_count_t len) ;
94 static sf_count_t flac_write_i2flac (SF_PRIVATE *psf, const int *ptr, sf_count_t len) ;
95 static sf_count_t flac_write_f2flac (SF_PRIVATE *psf, const float *ptr, sf_count_t len) ;
96 static sf_count_t flac_write_d2flac (SF_PRIVATE *psf, const double *ptr, sf_count_t len) ;
98 static void f2flac8_array (const float *src, FLAC__int32 *dest, int count, int normalize) ;
99 static void f2flac16_array (const float *src, FLAC__int32 *dest, int count, int normalize) ;
100 static void f2flac24_array (const float *src, FLAC__int32 *dest, int count, int normalize) ;
101 static void f2flac8_clip_array (const float *src, FLAC__int32 *dest, int count, int normalize) ;
102 static void f2flac16_clip_array (const float *src, FLAC__int32 *dest, int count, int normalize) ;
103 static void f2flac24_clip_array (const float *src, FLAC__int32 *dest, int count, int normalize) ;
104 static void d2flac8_array (const double *src, FLAC__int32 *dest, int count, int normalize) ;
105 static void d2flac16_array (const double *src, FLAC__int32 *dest, int count, int normalize) ;
106 static void d2flac24_array (const double *src, FLAC__int32 *dest, int count, int normalize) ;
107 static void d2flac8_clip_array (const double *src, FLAC__int32 *dest, int count, int normalize) ;
108 static void d2flac16_clip_array (const double *src, FLAC__int32 *dest, int count, int normalize) ;
109 static void d2flac24_clip_array (const double *src, FLAC__int32 *dest, int count, int normalize) ;
111 static int flac_command (SF_PRIVATE *psf, int command, void *data, int datasize) ;
113 /* Decoder Callbacks */
114 static FLAC__StreamDecoderReadStatus sf_flac_read_callback (const FLAC__StreamDecoder *decoder, FLAC__byte buffer [], size_t *bytes, void *client_data) ;
115 static FLAC__StreamDecoderSeekStatus sf_flac_seek_callback (const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data) ;
116 static FLAC__StreamDecoderTellStatus sf_flac_tell_callback (const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data) ;
117 static FLAC__StreamDecoderLengthStatus sf_flac_length_callback (const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data) ;
118 static FLAC__bool sf_flac_eof_callback (const FLAC__StreamDecoder *decoder, void *client_data) ;
119 static FLAC__StreamDecoderWriteStatus sf_flac_write_callback (const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer [], void *client_data) ;
120 static void sf_flac_meta_callback (const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data) ;
121 static void sf_flac_error_callback (const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data) ;
123 /* Encoder Callbacks */
124 static FLAC__StreamEncoderSeekStatus sf_flac_enc_seek_callback (const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data) ;
125 static FLAC__StreamEncoderTellStatus sf_flac_enc_tell_callback (const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data) ;
126 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) ;
129 s2flac8_array (const short *src, FLAC__int32 *dest, int count)
130 { while (--count >= 0)
131 dest [count] = src [count] >> 8 ;
132 } /* s2flac8_array */
135 s2flac16_array (const short *src, FLAC__int32 *dest, int count)
136 { while (--count >= 0)
137 dest [count] = src [count] ;
138 } /* s2flac16_array */
141 s2flac24_array (const short *src, FLAC__int32 *dest, int count)
142 { while (--count >= 0)
143 dest [count] = src [count] << 8 ;
144 } /* s2flac24_array */
147 i2flac8_array (const int *src, FLAC__int32 *dest, int count)
148 { while (--count >= 0)
149 dest [count] = src [count] >> 24 ;
150 } /* i2flac8_array */
153 i2flac16_array (const int *src, FLAC__int32 *dest, int count)
156 dest [count] = src [count] >> 16 ;
157 } /* i2flac16_array */
160 i2flac24_array (const int *src, FLAC__int32 *dest, int count)
161 { while (--count >= 0)
162 dest [count] = src [count] >> 8 ;
163 } /* i2flac24_array */
166 flac_buffer_copy (SF_PRIVATE *psf)
167 { FLAC_PRIVATE* pflac = (FLAC_PRIVATE*) psf->codec_data ;
168 const FLAC__Frame *frame = pflac->frame ;
169 const FLAC__int32* const *buffer = pflac->wbuffer ;
170 unsigned i = 0, j, offset ;
173 ** frame->header.blocksize is variable and we're using a constant blocksize
174 ** of FLAC__MAX_BLOCK_SIZE.
175 ** Check our assumptions here.
177 if (frame->header.blocksize > FLAC__MAX_BLOCK_SIZE)
178 { psf_log_printf (psf, "Ooops : frame->header.blocksize (%d) > FLAC__MAX_BLOCK_SIZE (%d)\n", __func__, __LINE__, frame->header.blocksize, FLAC__MAX_BLOCK_SIZE) ;
179 psf->error = SFE_INTERNAL ;
183 if (pflac->ptr == NULL)
185 ** This pointer is reset to NULL each time the current frame has been
186 ** decoded. Somehow its used during encoding and decoding.
188 for (i = 0 ; i < frame->header.channels ; i++)
190 if (pflac->rbuffer [i] == NULL)
191 pflac->rbuffer [i] = calloc (FLAC__MAX_BLOCK_SIZE, sizeof (FLAC__int32)) ;
193 memcpy (pflac->rbuffer [i], buffer [i], frame->header.blocksize * sizeof (FLAC__int32)) ;
195 pflac->wbuffer = (const FLAC__int32* const*) pflac->rbuffer ;
200 if (pflac->remain % channels != 0)
201 { psf_log_printf (psf, "Error: pflac->remain %u channels %u\n", pflac->remain, channels) ;
205 switch (pflac->pcmtype)
206 { case PFLAC_PCM_SHORT :
207 { short *retpcm = (short*) pflac->ptr ;
208 int shift = 16 - frame->header.bits_per_sample ;
210 { shift = abs (shift) ;
211 for (i = 0 ; i < frame->header.blocksize && pflac->remain > 0 ; i++)
212 { offset = pflac->pos + i * frame->header.channels ;
214 if (pflac->bufferpos >= frame->header.blocksize)
217 for (j = 0 ; j < frame->header.channels ; j++)
218 retpcm [offset + j] = buffer [j][pflac->bufferpos] >> shift ;
219 pflac->remain -= frame->header.channels ;
224 { for (i = 0 ; i < frame->header.blocksize && pflac->remain > 0 ; i++)
225 { offset = pflac->pos + i * frame->header.channels ;
227 if (pflac->bufferpos >= frame->header.blocksize)
230 for (j = 0 ; j < frame->header.channels ; j++)
231 retpcm [offset + j] = ((uint16_t) buffer [j][pflac->bufferpos]) << shift ;
233 pflac->remain -= frame->header.channels ;
241 { int *retpcm = (int*) pflac->ptr ;
242 int shift = 32 - frame->header.bits_per_sample ;
243 for (i = 0 ; i < frame->header.blocksize && pflac->remain > 0 ; i++)
244 { offset = pflac->pos + i * frame->header.channels ;
246 if (pflac->bufferpos >= frame->header.blocksize)
249 for (j = 0 ; j < frame->header.channels ; j++)
250 retpcm [offset + j] = ((uint32_t) buffer [j][pflac->bufferpos]) << shift ;
251 pflac->remain -= frame->header.channels ;
257 case PFLAC_PCM_FLOAT :
258 { float *retpcm = (float*) pflac->ptr ;
259 float norm = (psf->norm_float == SF_TRUE) ? 1.0 / (1 << (frame->header.bits_per_sample - 1)) : 1.0 ;
261 for (i = 0 ; i < frame->header.blocksize && pflac->remain > 0 ; i++)
262 { offset = pflac->pos + i * frame->header.channels ;
264 if (pflac->bufferpos >= frame->header.blocksize)
267 for (j = 0 ; j < frame->header.channels ; j++)
268 retpcm [offset + j] = buffer [j][pflac->bufferpos] * norm ;
269 pflac->remain -= frame->header.channels ;
275 case PFLAC_PCM_DOUBLE :
276 { double *retpcm = (double*) pflac->ptr ;
277 double norm = (psf->norm_double == SF_TRUE) ? 1.0 / (1 << (frame->header.bits_per_sample - 1)) : 1.0 ;
279 for (i = 0 ; i < frame->header.blocksize && pflac->remain > 0 ; i++)
280 { offset = pflac->pos + i * frame->header.channels ;
282 if (pflac->bufferpos >= frame->header.blocksize)
285 for (j = 0 ; j < frame->header.channels ; j++)
286 retpcm [offset + j] = buffer [j][pflac->bufferpos] * norm ;
287 pflac->remain -= frame->header.channels ;
297 offset = i * frame->header.channels ;
298 pflac->pos += i * frame->header.channels ;
301 } /* flac_buffer_copy */
304 static FLAC__StreamDecoderReadStatus
305 sf_flac_read_callback (const FLAC__StreamDecoder * UNUSED (decoder), FLAC__byte buffer [], size_t *bytes, void *client_data)
306 { SF_PRIVATE *psf = (SF_PRIVATE*) client_data ;
308 *bytes = psf_fread (buffer, 1, *bytes, psf) ;
309 if (*bytes > 0 && psf->error == 0)
310 return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE ;
312 return FLAC__STREAM_DECODER_READ_STATUS_ABORT ;
313 } /* sf_flac_read_callback */
315 static FLAC__StreamDecoderSeekStatus
316 sf_flac_seek_callback (const FLAC__StreamDecoder * UNUSED (decoder), FLAC__uint64 absolute_byte_offset, void *client_data)
317 { SF_PRIVATE *psf = (SF_PRIVATE*) client_data ;
319 psf_fseek (psf, absolute_byte_offset, SEEK_SET) ;
321 return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR ;
323 return FLAC__STREAM_DECODER_SEEK_STATUS_OK ;
324 } /* sf_flac_seek_callback */
326 static FLAC__StreamDecoderTellStatus
327 sf_flac_tell_callback (const FLAC__StreamDecoder * UNUSED (decoder), FLAC__uint64 *absolute_byte_offset, void *client_data)
328 { SF_PRIVATE *psf = (SF_PRIVATE*) client_data ;
330 *absolute_byte_offset = psf_ftell (psf) ;
332 return FLAC__STREAM_DECODER_TELL_STATUS_ERROR ;
334 return FLAC__STREAM_DECODER_TELL_STATUS_OK ;
335 } /* sf_flac_tell_callback */
337 static FLAC__StreamDecoderLengthStatus
338 sf_flac_length_callback (const FLAC__StreamDecoder * UNUSED (decoder), FLAC__uint64 *stream_length, void *client_data)
339 { SF_PRIVATE *psf = (SF_PRIVATE*) client_data ;
341 if ((*stream_length = psf->filelength) == 0)
342 return FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR ;
344 return FLAC__STREAM_DECODER_LENGTH_STATUS_OK ;
345 } /* sf_flac_length_callback */
348 sf_flac_eof_callback (const FLAC__StreamDecoder *UNUSED (decoder), void *client_data)
349 { SF_PRIVATE *psf = (SF_PRIVATE*) client_data ;
351 if (psf_ftell (psf) == psf->filelength)
355 } /* sf_flac_eof_callback */
357 static FLAC__StreamDecoderWriteStatus
358 sf_flac_write_callback (const FLAC__StreamDecoder * UNUSED (decoder), const FLAC__Frame *frame, const FLAC__int32 * const buffer [], void *client_data)
359 { SF_PRIVATE *psf = (SF_PRIVATE*) client_data ;
360 FLAC_PRIVATE* pflac = (FLAC_PRIVATE*) psf->codec_data ;
362 pflac->frame = frame ;
363 pflac->bufferpos = 0 ;
365 pflac->wbuffer = buffer ;
367 flac_buffer_copy (psf) ;
369 return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE ;
370 } /* sf_flac_write_callback */
373 sf_flac_meta_get_vorbiscomments (SF_PRIVATE *psf, const FLAC__StreamMetadata *metadata)
375 { { "title", SF_STR_TITLE },
376 { "copyright", SF_STR_COPYRIGHT },
377 { "software", SF_STR_SOFTWARE },
378 { "artist", SF_STR_ARTIST },
379 { "comment", SF_STR_COMMENT },
380 { "date", SF_STR_DATE },
381 { "album", SF_STR_ALBUM },
382 { "license", SF_STR_LICENSE },
383 { "tracknumber", SF_STR_TRACKNUMBER },
384 { "genre", SF_STR_GENRE }
387 const char *value, *cptr ;
390 for (k = 0 ; k < ARRAY_LEN (tags) ; k++)
391 { tag_num = FLAC__metadata_object_vorbiscomment_find_entry_from (metadata, 0, tags [k].tag) ;
396 value = (const char*) metadata->data.vorbis_comment.comments [tag_num].entry ;
397 if ((cptr = strchr (value, '=')) != NULL)
400 psf_log_printf (psf, " %-10s : %s\n", tags [k].tag, value) ;
401 psf_store_string (psf, tags [k].type, value) ;
405 } /* sf_flac_meta_get_vorbiscomments */
408 sf_flac_meta_callback (const FLAC__StreamDecoder * UNUSED (decoder), const FLAC__StreamMetadata *metadata, void *client_data)
409 { SF_PRIVATE *psf = (SF_PRIVATE*) client_data ;
412 switch (metadata->type)
413 { case FLAC__METADATA_TYPE_STREAMINFO :
414 psf->sf.channels = metadata->data.stream_info.channels ;
415 psf->sf.samplerate = metadata->data.stream_info.sample_rate ;
416 psf->sf.frames = metadata->data.stream_info.total_samples ;
418 psf_log_printf (psf, "FLAC Stream Metadata\n Channels : %d\n Sample rate : %d\n", psf->sf.channels, psf->sf.samplerate) ;
420 if (psf->sf.frames == 0)
421 { psf_log_printf (psf, " Frames : 0 (bumping to SF_COUNT_MAX)\n") ;
422 psf->sf.frames = SF_COUNT_MAX ;
425 psf_log_printf (psf, " Frames : %D\n", psf->sf.frames) ;
427 switch (metadata->data.stream_info.bits_per_sample)
429 psf->sf.format |= SF_FORMAT_PCM_S8 ;
433 psf->sf.format |= SF_FORMAT_PCM_16 ;
437 psf->sf.format |= SF_FORMAT_PCM_24 ;
441 psf_log_printf (psf, "sf_flac_meta_callback : bits_per_sample %d not yet implemented.\n", metadata->data.stream_info.bits_per_sample) ;
446 psf_log_printf (psf, " Bit width : %d\n", bitwidth) ;
449 case FLAC__METADATA_TYPE_VORBIS_COMMENT :
450 psf_log_printf (psf, "Vorbis Comment Metadata\n") ;
451 sf_flac_meta_get_vorbiscomments (psf, metadata) ;
454 case FLAC__METADATA_TYPE_PADDING :
455 psf_log_printf (psf, "Padding Metadata\n") ;
458 case FLAC__METADATA_TYPE_APPLICATION :
459 psf_log_printf (psf, "Application Metadata\n") ;
462 case FLAC__METADATA_TYPE_SEEKTABLE :
463 psf_log_printf (psf, "Seektable Metadata\n") ;
466 case FLAC__METADATA_TYPE_CUESHEET :
467 psf_log_printf (psf, "Cuesheet Metadata\n") ;
470 case FLAC__METADATA_TYPE_PICTURE :
471 psf_log_printf (psf, "Picture Metadata\n") ;
474 case FLAC__METADATA_TYPE_UNDEFINED :
475 psf_log_printf (psf, "Undefined Metadata\n") ;
479 psf_log_printf (psf, "sf_flac_meta_callback : metadata-type %d not yet implemented.\n", metadata->type) ;
484 } /* sf_flac_meta_callback */
487 sf_flac_error_callback (const FLAC__StreamDecoder * UNUSED (decoder), FLAC__StreamDecoderErrorStatus status, void *client_data)
488 { SF_PRIVATE *psf = (SF_PRIVATE*) client_data ;
490 psf_log_printf (psf, "ERROR : %s\n", FLAC__StreamDecoderErrorStatusString [status]) ;
493 { case FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC :
494 psf->error = SFE_FLAC_LOST_SYNC ;
496 case FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER :
497 psf->error = SFE_FLAC_BAD_HEADER ;
500 psf->error = SFE_FLAC_UNKOWN_ERROR ;
505 } /* sf_flac_error_callback */
507 static FLAC__StreamEncoderSeekStatus
508 sf_flac_enc_seek_callback (const FLAC__StreamEncoder * UNUSED (encoder), FLAC__uint64 absolute_byte_offset, void *client_data)
509 { SF_PRIVATE *psf = (SF_PRIVATE*) client_data ;
511 psf_fseek (psf, absolute_byte_offset, SEEK_SET) ;
513 return FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR ;
515 return FLAC__STREAM_ENCODER_SEEK_STATUS_OK ;
516 } /* sf_flac_enc_seek_callback */
518 static FLAC__StreamEncoderTellStatus
519 sf_flac_enc_tell_callback (const FLAC__StreamEncoder *UNUSED (encoder), FLAC__uint64 *absolute_byte_offset, void *client_data)
520 { SF_PRIVATE *psf = (SF_PRIVATE*) client_data ;
522 *absolute_byte_offset = psf_ftell (psf) ;
524 return FLAC__STREAM_ENCODER_TELL_STATUS_ERROR ;
526 return FLAC__STREAM_ENCODER_TELL_STATUS_OK ;
527 } /* sf_flac_enc_tell_callback */
529 static FLAC__StreamEncoderWriteStatus
530 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)
531 { SF_PRIVATE *psf = (SF_PRIVATE*) client_data ;
533 if (psf_fwrite (buffer, 1, bytes, psf) == (sf_count_t) bytes && psf->error == 0)
534 return FLAC__STREAM_ENCODER_WRITE_STATUS_OK ;
536 return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR ;
537 } /* sf_flac_enc_write_callback */
540 flac_write_strings (SF_PRIVATE *psf, FLAC_PRIVATE* pflac)
541 { FLAC__StreamMetadata_VorbisComment_Entry entry ;
542 int k, string_count = 0 ;
544 for (k = 0 ; k < SF_MAX_STRINGS ; k++)
545 { if (psf->strings.data [k].type != 0)
549 if (string_count == 0)
552 if (pflac->metadata == NULL && (pflac->metadata = FLAC__metadata_object_new (FLAC__METADATA_TYPE_VORBIS_COMMENT)) == NULL)
553 { psf_log_printf (psf, "FLAC__metadata_object_new returned NULL\n") ;
557 for (k = 0 ; k < SF_MAX_STRINGS && psf->strings.data [k].type != 0 ; k++)
558 { const char * key, * value ;
560 switch (psf->strings.data [k].type)
561 { case SF_STR_SOFTWARE :
567 case SF_STR_COPYRIGHT :
573 case SF_STR_COMMENT :
582 case SF_STR_LICENSE :
585 case SF_STR_TRACKNUMBER :
586 key = "tracknumber" ;
595 value = psf->strings.storage + psf->strings.data [k].offset ;
597 FLAC__metadata_object_vorbiscomment_entry_from_name_value_pair (&entry, key, value) ;
598 FLAC__metadata_object_vorbiscomment_append_comment (pflac->metadata, entry, /* copy */ SF_FALSE) ;
601 if (! FLAC__stream_encoder_set_metadata (pflac->fse, &pflac->metadata, 1))
602 { printf ("%s %d : fail\n", __func__, __LINE__) ;
607 } /* flac_write_strings */
610 flac_write_header (SF_PRIVATE *psf, int UNUSED (calc_length))
611 { FLAC_PRIVATE* pflac = (FLAC_PRIVATE*) psf->codec_data ;
614 flac_write_strings (psf, pflac) ;
616 if ((err = 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)
617 { psf_log_printf (psf, "Error : FLAC encoder init returned error : %s\n", FLAC__StreamEncoderInitStatusString [err]) ;
618 return SFE_FLAC_INIT_DECODER ;
622 psf->dataoffset = psf_ftell (psf) ;
623 pflac->encbuffer = calloc (ENC_BUFFER_SIZE, sizeof (FLAC__int32)) ;
626 } /* flac_write_header */
628 /*------------------------------------------------------------------------------
633 flac_open (SF_PRIVATE *psf)
637 FLAC_PRIVATE* pflac = calloc (1, sizeof (FLAC_PRIVATE)) ;
638 psf->codec_data = pflac ;
640 /* Set the default value here. Over-ridden later if necessary. */
641 pflac->compression = FLAC_DEFAULT_COMPRESSION_LEVEL ;
644 if (psf->file.mode == SFM_RDWR)
645 return SFE_BAD_MODE_RW ;
647 if (psf->file.mode == SFM_READ)
648 { if ((error = flac_read_header (psf)))
652 subformat = SF_CODEC (psf->sf.format) ;
654 if (psf->file.mode == SFM_WRITE)
655 { if ((SF_CONTAINER (psf->sf.format)) != SF_FORMAT_FLAC)
656 return SFE_BAD_OPEN_FORMAT ;
658 psf->endian = SF_ENDIAN_BIG ;
659 psf->sf.seekable = 0 ;
661 psf->strings.flags = SF_STR_ALLOW_START ;
663 if ((error = flac_enc_init (psf)))
666 psf->write_header = flac_write_header ;
669 psf->datalength = psf->filelength ;
670 psf->dataoffset = 0 ;
672 psf->container_close = flac_close ;
673 psf->seek = flac_seek ;
674 psf->byterate = flac_byterate ;
676 psf->command = flac_command ;
679 { case SF_FORMAT_PCM_S8 : /* 8-bit FLAC. */
680 case SF_FORMAT_PCM_16 : /* 16-bit FLAC. */
681 case SF_FORMAT_PCM_24 : /* 24-bit FLAC. */
682 error = flac_init (psf) ;
685 default : return SFE_UNIMPLEMENTED ;
691 /*------------------------------------------------------------------------------
695 flac_close (SF_PRIVATE *psf)
696 { FLAC_PRIVATE* pflac ;
699 if ((pflac = (FLAC_PRIVATE*) psf->codec_data) == NULL)
702 if (pflac->metadata != NULL)
703 FLAC__metadata_object_delete (pflac->metadata) ;
705 if (psf->file.mode == SFM_WRITE)
706 { FLAC__stream_encoder_finish (pflac->fse) ;
707 FLAC__stream_encoder_delete (pflac->fse) ;
709 if (pflac->encbuffer)
710 free (pflac->encbuffer) ;
713 if (psf->file.mode == SFM_READ)
714 { FLAC__stream_decoder_finish (pflac->fsd) ;
715 FLAC__stream_decoder_delete (pflac->fsd) ;
718 for (k = 0 ; k < ARRAY_LEN (pflac->rbuffer) ; k++)
719 free (pflac->rbuffer [k]) ;
722 psf->codec_data = NULL ;
728 flac_enc_init (SF_PRIVATE *psf)
729 { FLAC_PRIVATE* pflac = (FLAC_PRIVATE*) psf->codec_data ;
732 /* To cite the flac FAQ at
733 ** http://flac.sourceforge.net/faq.html#general__samples
734 ** "FLAC supports linear sample rates from 1Hz - 655350Hz in 1Hz
737 if (psf->sf.samplerate < 1 || psf->sf.samplerate > 655350)
738 { psf_log_printf (psf, "flac sample rate out of range.\n", psf->sf.samplerate) ;
739 return SFE_FLAC_BAD_SAMPLE_RATE ;
742 psf_fseek (psf, 0, SEEK_SET) ;
744 switch (SF_CODEC (psf->sf.format))
745 { case SF_FORMAT_PCM_S8 :
748 case SF_FORMAT_PCM_16 :
751 case SF_FORMAT_PCM_24 :
761 FLAC__stream_encoder_delete (pflac->fse) ;
762 if ((pflac->fse = FLAC__stream_encoder_new ()) == NULL)
763 return SFE_FLAC_NEW_DECODER ;
765 if (! FLAC__stream_encoder_set_channels (pflac->fse, psf->sf.channels))
766 { psf_log_printf (psf, "FLAC__stream_encoder_set_channels (%d) return false.\n", psf->sf.channels) ;
767 return SFE_FLAC_INIT_DECODER ;
770 if (! FLAC__stream_encoder_set_sample_rate (pflac->fse, psf->sf.samplerate))
771 { psf_log_printf (psf, "FLAC__stream_encoder_set_sample_rate (%d) returned false.\n", psf->sf.samplerate) ;
772 return SFE_FLAC_BAD_SAMPLE_RATE ;
775 if (! FLAC__stream_encoder_set_bits_per_sample (pflac->fse, bps))
776 { psf_log_printf (psf, "FLAC__stream_encoder_set_bits_per_sample (%d) return false.\n", bps) ;
777 return SFE_FLAC_INIT_DECODER ;
780 if (! FLAC__stream_encoder_set_compression_level (pflac->fse, pflac->compression))
781 { psf_log_printf (psf, "FLAC__stream_encoder_set_compression_level (%d) return false.\n", pflac->compression) ;
782 return SFE_FLAC_INIT_DECODER ;
786 } /* flac_enc_init */
789 flac_read_header (SF_PRIVATE *psf)
790 { FLAC_PRIVATE* pflac = (FLAC_PRIVATE*) psf->codec_data ;
792 psf_fseek (psf, 0, SEEK_SET) ;
794 FLAC__stream_decoder_delete (pflac->fsd) ;
795 if ((pflac->fsd = FLAC__stream_decoder_new ()) == NULL)
796 return SFE_FLAC_NEW_DECODER ;
798 FLAC__stream_decoder_set_metadata_respond_all (pflac->fsd) ;
800 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)
801 return SFE_FLAC_INIT_DECODER ;
803 FLAC__stream_decoder_process_until_end_of_metadata (pflac->fsd) ;
805 psf_log_printf (psf, "End\n") ;
808 { FLAC__uint64 position ;
810 FLAC__stream_decoder_get_decode_position (pflac->fsd, &position) ;
811 psf->dataoffset = position ;
815 } /* flac_read_header */
818 flac_command (SF_PRIVATE * psf, int command, void * data, int datasize)
819 { FLAC_PRIVATE* pflac = (FLAC_PRIVATE*) psf->codec_data ;
823 { case SFC_SET_COMPRESSION_LEVEL :
824 if (data == NULL || datasize != sizeof (double))
827 if (psf->have_written)
830 /* FLAC compression level is in the range [0, 8] while libsndfile takes
831 ** values in the range [0.0, 1.0]. Massage the libsndfile value here.
833 quality = (*((double *) data)) * 8.0 ;
835 pflac->compression = lrint (SF_MAX (0.0, SF_MIN (8.0, quality))) ;
837 psf_log_printf (psf, "%s : Setting SFC_SET_COMPRESSION_LEVEL to %u.\n", __func__, pflac->compression) ;
839 if (flac_enc_init (psf))
852 flac_init (SF_PRIVATE *psf)
854 if (psf->file.mode == SFM_RDWR)
855 return SFE_BAD_MODE_RW ;
857 if (psf->file.mode == SFM_READ)
858 { psf->read_short = flac_read_flac2s ;
859 psf->read_int = flac_read_flac2i ;
860 psf->read_float = flac_read_flac2f ;
861 psf->read_double = flac_read_flac2d ;
864 if (psf->file.mode == SFM_WRITE)
865 { psf->write_short = flac_write_s2flac ;
866 psf->write_int = flac_write_i2flac ;
867 psf->write_float = flac_write_f2flac ;
868 psf->write_double = flac_write_d2flac ;
871 if (psf->filelength > psf->dataoffset)
872 psf->datalength = (psf->dataend) ? psf->dataend - psf->dataoffset : psf->filelength - psf->dataoffset ;
874 psf->datalength = 0 ;
880 flac_read_loop (SF_PRIVATE *psf, unsigned len)
881 { FLAC_PRIVATE* pflac = (FLAC_PRIVATE*) psf->codec_data ;
882 FLAC__StreamDecoderState state ;
886 pflac->remain = len ;
888 state = FLAC__stream_decoder_get_state (pflac->fsd) ;
889 if (state > FLAC__STREAM_DECODER_END_OF_STREAM)
890 { psf_log_printf (psf, "FLAC__stream_decoder_get_state returned %s\n", FLAC__StreamDecoderStateString [state]) ;
891 /* Current frame is busted, so NULL the pointer. */
892 pflac->frame = NULL ;
895 /* First copy data that has already been decoded and buffered. */
896 if (pflac->frame != NULL && pflac->bufferpos < pflac->frame->header.blocksize)
897 flac_buffer_copy (psf) ;
899 while (pflac->pos < pflac->len)
900 { if (FLAC__stream_decoder_process_single (pflac->fsd) == 0)
902 state = FLAC__stream_decoder_get_state (pflac->fsd) ;
903 if (state >= FLAC__STREAM_DECODER_END_OF_STREAM)
904 { psf_log_printf (psf, "FLAC__stream_decoder_get_state returned %s\n", FLAC__StreamDecoderStateString [state]) ;
905 /* Current frame is busted, so NULL the pointer. */
906 pflac->frame = NULL ;
914 } /* flac_read_loop */
917 flac_read_flac2s (SF_PRIVATE *psf, short *ptr, sf_count_t len)
918 { FLAC_PRIVATE* pflac = (FLAC_PRIVATE*) psf->codec_data ;
919 sf_count_t total = 0, current ;
922 pflac->pcmtype = PFLAC_PCM_SHORT ;
925 { pflac->ptr = ptr + total ;
926 readlen = (len - total > 0x1000000) ? 0x1000000 : (unsigned) (len - total) ;
927 current = flac_read_loop (psf, readlen) ;
934 } /* flac_read_flac2s */
937 flac_read_flac2i (SF_PRIVATE *psf, int *ptr, sf_count_t len)
938 { FLAC_PRIVATE* pflac = (FLAC_PRIVATE*) psf->codec_data ;
939 sf_count_t total = 0, current ;
942 pflac->pcmtype = PFLAC_PCM_INT ;
945 { pflac->ptr = ptr + total ;
946 readlen = (len - total > 0x1000000) ? 0x1000000 : (unsigned) (len - total) ;
947 current = flac_read_loop (psf, readlen) ;
954 } /* flac_read_flac2i */
957 flac_read_flac2f (SF_PRIVATE *psf, float *ptr, sf_count_t len)
958 { FLAC_PRIVATE* pflac = (FLAC_PRIVATE*) psf->codec_data ;
959 sf_count_t total = 0, current ;
962 pflac->pcmtype = PFLAC_PCM_FLOAT ;
965 { pflac->ptr = ptr + total ;
966 readlen = (len - total > 0x1000000) ? 0x1000000 : (unsigned) (len - total) ;
967 current = flac_read_loop (psf, readlen) ;
974 } /* flac_read_flac2f */
977 flac_read_flac2d (SF_PRIVATE *psf, double *ptr, sf_count_t len)
978 { FLAC_PRIVATE* pflac = (FLAC_PRIVATE*) psf->codec_data ;
979 sf_count_t total = 0, current ;
982 pflac->pcmtype = PFLAC_PCM_DOUBLE ;
985 { pflac->ptr = ptr + total ;
986 readlen = (len - total > 0x1000000) ? 0x1000000 : (unsigned) (len - total) ;
987 current = flac_read_loop (psf, readlen) ;
994 } /* flac_read_flac2d */
997 flac_write_s2flac (SF_PRIVATE *psf, const short *ptr, sf_count_t len)
998 { FLAC_PRIVATE* pflac = (FLAC_PRIVATE*) psf->codec_data ;
999 void (*convert) (const short *, FLAC__int32 *, int) ;
1000 int bufferlen, writecount, thiswrite ;
1001 sf_count_t total = 0 ;
1002 FLAC__int32* buffer = pflac->encbuffer ;
1004 switch (SF_CODEC (psf->sf.format))
1005 { case SF_FORMAT_PCM_S8 :
1006 convert = s2flac8_array ;
1008 case SF_FORMAT_PCM_16 :
1009 convert = s2flac16_array ;
1011 case SF_FORMAT_PCM_24 :
1012 convert = s2flac24_array ;
1018 bufferlen = ENC_BUFFER_SIZE / (sizeof (FLAC__int32) * psf->sf.channels) ;
1019 bufferlen *= psf->sf.channels ;
1022 { writecount = (len >= bufferlen) ? bufferlen : (int) len ;
1023 convert (ptr + total, buffer, writecount) ;
1024 if (FLAC__stream_encoder_process_interleaved (pflac->fse, buffer, writecount / psf->sf.channels))
1025 thiswrite = writecount ;
1028 total += thiswrite ;
1029 if (thiswrite < writecount)
1036 } /* flac_write_s2flac */
1039 flac_write_i2flac (SF_PRIVATE *psf, const int *ptr, sf_count_t len)
1040 { FLAC_PRIVATE* pflac = (FLAC_PRIVATE*) psf->codec_data ;
1041 void (*convert) (const int *, FLAC__int32 *, int) ;
1042 int bufferlen, writecount, thiswrite ;
1043 sf_count_t total = 0 ;
1044 FLAC__int32* buffer = pflac->encbuffer ;
1046 switch (SF_CODEC (psf->sf.format))
1047 { case SF_FORMAT_PCM_S8 :
1048 convert = i2flac8_array ;
1050 case SF_FORMAT_PCM_16 :
1051 convert = i2flac16_array ;
1053 case SF_FORMAT_PCM_24 :
1054 convert = i2flac24_array ;
1060 bufferlen = ENC_BUFFER_SIZE / (sizeof (FLAC__int32) * psf->sf.channels) ;
1061 bufferlen *= psf->sf.channels ;
1064 { writecount = (len >= bufferlen) ? bufferlen : (int) len ;
1065 convert (ptr + total, buffer, writecount) ;
1066 if (FLAC__stream_encoder_process_interleaved (pflac->fse, buffer, writecount / psf->sf.channels))
1067 thiswrite = writecount ;
1070 total += thiswrite ;
1071 if (thiswrite < writecount)
1078 } /* flac_write_i2flac */
1081 flac_write_f2flac (SF_PRIVATE *psf, const float *ptr, sf_count_t len)
1082 { FLAC_PRIVATE* pflac = (FLAC_PRIVATE*) psf->codec_data ;
1083 void (*convert) (const float *, FLAC__int32 *, int, int) ;
1084 int bufferlen, writecount, thiswrite ;
1085 sf_count_t total = 0 ;
1086 FLAC__int32* buffer = pflac->encbuffer ;
1088 switch (SF_CODEC (psf->sf.format))
1089 { case SF_FORMAT_PCM_S8 :
1090 convert = (psf->add_clipping) ? f2flac8_clip_array : f2flac8_array ;
1092 case SF_FORMAT_PCM_16 :
1093 convert = (psf->add_clipping) ? f2flac16_clip_array : f2flac16_array ;
1095 case SF_FORMAT_PCM_24 :
1096 convert = (psf->add_clipping) ? f2flac24_clip_array : f2flac24_array ;
1102 bufferlen = ENC_BUFFER_SIZE / (sizeof (FLAC__int32) * psf->sf.channels) ;
1103 bufferlen *= psf->sf.channels ;
1106 { writecount = (len >= bufferlen) ? bufferlen : (int) len ;
1107 convert (ptr + total, buffer, writecount, psf->norm_float) ;
1108 if (FLAC__stream_encoder_process_interleaved (pflac->fse, buffer, writecount / psf->sf.channels))
1109 thiswrite = writecount ;
1112 total += thiswrite ;
1113 if (thiswrite < writecount)
1120 } /* flac_write_f2flac */
1123 f2flac8_clip_array (const float *src, FLAC__int32 *dest, int count, int normalize)
1124 { float normfact, scaled_value ;
1126 normfact = normalize ? (8.0 * 0x10) : 1.0 ;
1128 while (--count >= 0)
1129 { scaled_value = src [count] * normfact ;
1130 if (CPU_CLIPS_POSITIVE == 0 && scaled_value >= (1.0 * 0x7F))
1131 { dest [count] = 0x7F ;
1134 if (CPU_CLIPS_NEGATIVE == 0 && scaled_value <= (-8.0 * 0x10))
1135 { dest [count] = 0x80 ;
1138 dest [count] = lrintf (scaled_value) ;
1142 } /* f2flac8_clip_array */
1145 f2flac16_clip_array (const float *src, FLAC__int32 *dest, int count, int normalize)
1146 { float normfact, scaled_value ;
1148 normfact = normalize ? (8.0 * 0x1000) : 1.0 ;
1150 while (--count >= 0)
1151 { scaled_value = src [count] * normfact ;
1152 if (CPU_CLIPS_POSITIVE == 0 && scaled_value >= (1.0 * 0x7FFF))
1153 { dest [count] = 0x7FFF ;
1156 if (CPU_CLIPS_NEGATIVE == 0 && scaled_value <= (-8.0 * 0x1000))
1157 { dest [count] = 0x8000 ;
1160 dest [count] = lrintf (scaled_value) ;
1162 } /* f2flac16_clip_array */
1165 f2flac24_clip_array (const float *src, FLAC__int32 *dest, int count, int normalize)
1166 { float normfact, scaled_value ;
1168 normfact = normalize ? (8.0 * 0x100000) : 1.0 ;
1170 while (--count >= 0)
1171 { scaled_value = src [count] * normfact ;
1172 if (CPU_CLIPS_POSITIVE == 0 && scaled_value >= (1.0 * 0x7FFFFF))
1173 { dest [count] = 0x7FFFFF ;
1177 if (CPU_CLIPS_NEGATIVE == 0 && scaled_value <= (-8.0 * 0x100000))
1178 { dest [count] = 0x800000 ;
1181 dest [count] = lrintf (scaled_value) ;
1185 } /* f2flac24_clip_array */
1188 f2flac8_array (const float *src, FLAC__int32 *dest, int count, int normalize)
1189 { float normfact = normalize ? (1.0 * 0x7F) : 1.0 ;
1191 while (--count >= 0)
1192 dest [count] = lrintf (src [count] * normfact) ;
1193 } /* f2flac8_array */
1196 f2flac16_array (const float *src, FLAC__int32 *dest, int count, int normalize)
1197 { float normfact = normalize ? (1.0 * 0x7FFF) : 1.0 ;
1199 while (--count >= 0)
1200 dest [count] = lrintf (src [count] * normfact) ;
1201 } /* f2flac16_array */
1204 f2flac24_array (const float *src, FLAC__int32 *dest, int count, int normalize)
1205 { float normfact = normalize ? (1.0 * 0x7FFFFF) : 1.0 ;
1207 while (--count >= 0)
1208 dest [count] = lrintf (src [count] * normfact) ;
1209 } /* f2flac24_array */
1212 flac_write_d2flac (SF_PRIVATE *psf, const double *ptr, sf_count_t len)
1213 { FLAC_PRIVATE* pflac = (FLAC_PRIVATE*) psf->codec_data ;
1214 void (*convert) (const double *, FLAC__int32 *, int, int) ;
1215 int bufferlen, writecount, thiswrite ;
1216 sf_count_t total = 0 ;
1217 FLAC__int32* buffer = pflac->encbuffer ;
1219 switch (SF_CODEC (psf->sf.format))
1220 { case SF_FORMAT_PCM_S8 :
1221 convert = (psf->add_clipping) ? d2flac8_clip_array : d2flac8_array ;
1223 case SF_FORMAT_PCM_16 :
1224 convert = (psf->add_clipping) ? d2flac16_clip_array : d2flac16_array ;
1226 case SF_FORMAT_PCM_24 :
1227 convert = (psf->add_clipping) ? d2flac24_clip_array : d2flac24_array ;
1233 bufferlen = ENC_BUFFER_SIZE / (sizeof (FLAC__int32) * psf->sf.channels) ;
1234 bufferlen *= psf->sf.channels ;
1237 { writecount = (len >= bufferlen) ? bufferlen : (int) len ;
1238 convert (ptr + total, buffer, writecount, psf->norm_double) ;
1239 if (FLAC__stream_encoder_process_interleaved (pflac->fse, buffer, writecount / psf->sf.channels))
1240 thiswrite = writecount ;
1243 total += thiswrite ;
1244 if (thiswrite < writecount)
1251 } /* flac_write_d2flac */
1254 d2flac8_clip_array (const double *src, FLAC__int32 *dest, int count, int normalize)
1255 { double normfact, scaled_value ;
1257 normfact = normalize ? (8.0 * 0x10) : 1.0 ;
1259 while (--count >= 0)
1260 { scaled_value = src [count] * normfact ;
1261 if (CPU_CLIPS_POSITIVE == 0 && scaled_value >= (1.0 * 0x7F))
1262 { dest [count] = 0x7F ;
1265 if (CPU_CLIPS_NEGATIVE == 0 && scaled_value <= (-8.0 * 0x10))
1266 { dest [count] = 0x80 ;
1269 dest [count] = lrint (scaled_value) ;
1273 } /* d2flac8_clip_array */
1276 d2flac16_clip_array (const double *src, FLAC__int32 *dest, int count, int normalize)
1277 { double normfact, scaled_value ;
1279 normfact = normalize ? (8.0 * 0x1000) : 1.0 ;
1281 while (--count >= 0)
1282 { scaled_value = src [count] * normfact ;
1283 if (CPU_CLIPS_POSITIVE == 0 && scaled_value >= (1.0 * 0x7FFF))
1284 { dest [count] = 0x7FFF ;
1287 if (CPU_CLIPS_NEGATIVE == 0 && scaled_value <= (-8.0 * 0x1000))
1288 { dest [count] = 0x8000 ;
1291 dest [count] = lrint (scaled_value) ;
1295 } /* d2flac16_clip_array */
1298 d2flac24_clip_array (const double *src, FLAC__int32 *dest, int count, int normalize)
1299 { double normfact, scaled_value ;
1301 normfact = normalize ? (8.0 * 0x100000) : 1.0 ;
1303 while (--count >= 0)
1304 { scaled_value = src [count] * normfact ;
1305 if (CPU_CLIPS_POSITIVE == 0 && scaled_value >= (1.0 * 0x7FFFFF))
1306 { dest [count] = 0x7FFFFF ;
1309 if (CPU_CLIPS_NEGATIVE == 0 && scaled_value <= (-8.0 * 0x100000))
1310 { dest [count] = 0x800000 ;
1313 dest [count] = lrint (scaled_value) ;
1317 } /* d2flac24_clip_array */
1320 d2flac8_array (const double *src, FLAC__int32 *dest, int count, int normalize)
1321 { double normfact = normalize ? (1.0 * 0x7F) : 1.0 ;
1323 while (--count >= 0)
1324 dest [count] = lrint (src [count] * normfact) ;
1325 } /* d2flac8_array */
1328 d2flac16_array (const double *src, FLAC__int32 *dest, int count, int normalize)
1329 { double normfact = normalize ? (1.0 * 0x7FFF) : 1.0 ;
1331 while (--count >= 0)
1332 dest [count] = lrint (src [count] * normfact) ;
1333 } /* d2flac16_array */
1336 d2flac24_array (const double *src, FLAC__int32 *dest, int count, int normalize)
1337 { double normfact = normalize ? (1.0 * 0x7FFFFF) : 1.0 ;
1339 while (--count >= 0)
1340 dest [count] = lrint (src [count] * normfact) ;
1341 } /* d2flac24_array */
1344 flac_seek (SF_PRIVATE *psf, int UNUSED (mode), sf_count_t offset)
1345 { FLAC_PRIVATE* pflac = (FLAC_PRIVATE*) psf->codec_data ;
1350 if (psf->dataoffset < 0)
1351 { psf->error = SFE_BAD_SEEK ;
1352 return ((sf_count_t) -1) ;
1355 pflac->frame = NULL ;
1357 if (psf->file.mode == SFM_READ)
1358 { if (FLAC__stream_decoder_seek_absolute (pflac->fsd, offset))
1361 if (offset == psf->sf.frames)
1363 ** If we've been asked to seek to the very end of the file, libFLAC
1364 ** will return an error. However, we know the length of the file so
1365 ** instead of returning an error, we can return the offset.
1370 psf->error = SFE_BAD_SEEK ;
1371 return ((sf_count_t) -1) ;
1374 /* Seeking in write mode not yet supported. */
1375 psf->error = SFE_BAD_SEEK ;
1377 return ((sf_count_t) -1) ;
1381 flac_byterate (SF_PRIVATE *psf)
1383 if (psf->file.mode == SFM_READ)
1384 return (psf->datalength * psf->sf.samplerate) / psf->sf.frames ;
1387 } /* flac_byterate */
1390 #else /* HAVE_EXTERNAL_LIBS */
1393 flac_open (SF_PRIVATE *psf)
1395 psf_log_printf (psf, "This version of libsndfile was compiled without FLAC support.\n") ;
1396 return SFE_UNIMPLEMENTED ;