2 ** Copyright (C) 1999-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
4 ** This program is free software; you can redistribute it and/or modify
5 ** it under the terms of the GNU Lesser General Public License as published by
6 ** the Free Software Foundation; either version 2.1 of the License, or
7 ** (at your option) any later version.
9 ** This program is distributed in the hope that it will be useful,
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ** GNU Lesser General Public License for more details.
14 ** You should have received a copy of the GNU Lesser General Public License
15 ** along with this program; if not, write to the Free Software
16 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 #ifndef SNDFILE_COMMON_H
20 #define SNDFILE_COMMON_H
38 #error "This code is not designed to be compiled with a C++ compiler."
41 #if (SIZEOF_LONG == 8)
42 # define SF_PLATFORM_S64(x) x##l
43 #elif (SIZEOF_LONG_LONG == 8)
44 # define SF_PLATFORM_S64(x) x##ll
46 # define SF_PLATFORM_S64(x) x##ll
48 # define SF_PLATFORM_S64(x) x##I64
50 # error "Don't know how to define a 64 bit integer constant."
56 ** Inspiration : http://sourcefrog.net/weblog/software/languages/C/unused.html
59 #elif defined (__GNUC__)
60 # define UNUSED(x) UNUSED_ ## x __attribute__ ((unused))
61 #elif defined (__LCLINT__)
62 # define UNUSED(x) /*@unused@*/ x
68 # define WARN_UNUSED __attribute__ ((warn_unused_result))
73 #define SF_BUFFER_LEN (8192*2)
74 #define SF_FILENAME_LEN (512)
75 #define SF_SYSERR_LEN (256)
76 #define SF_MAX_STRINGS (32)
77 #define SF_STR_BUFFER_LEN (8192)
78 #define SF_HEADER_LEN (4100 + SF_STR_BUFFER_LEN)
80 #define PSF_SEEK_ERROR ((sf_count_t) -1)
83 #define BITWIDTH2BYTES(x) (((x) + 7) / 8)
85 /* For some reason sizeof returns an unsigned value which causes
86 ** a warning when that value is added or subtracted from a signed
87 ** value. Use SIGNED_SIZEOF instead.
89 #define SIGNED_SIZEOF(x) ((int) sizeof (x))
91 #define ARRAY_LEN(x) ((int) (sizeof (x) / sizeof ((x) [0])))
93 #define NOT(x) (! (x))
95 #if (COMPILER_IS_GCC == 1)
96 #define SF_MAX(x,y) ({ \
97 typeof (x) sf_max_x1 = (x) ; \
98 typeof (y) sf_max_y1 = (y) ; \
99 (void) (&sf_max_x1 == &sf_max_y1) ; \
100 sf_max_x1 > sf_max_y1 ? sf_max_x1 : sf_max_y1 ; })
102 #define SF_MIN(x,y) ({ \
103 typeof (x) sf_min_x2 = (x) ; \
104 typeof (y) sf_min_y2 = (y) ; \
105 (void) (&sf_min_x2 == &sf_min_y2) ; \
106 sf_min_x2 < sf_min_y2 ? sf_min_x2 : sf_min_y2 ; })
108 #define SF_MAX(a,b) ((a) > (b) ? (a) : (b))
109 #define SF_MIN(a,b) ((a) < (b) ? (a) : (b))
113 #define SF_MAX_CHANNELS 256
117 * Macros for spliting the format file of SF_INFI into contrainer type,
118 ** codec type and endian-ness.
120 #define SF_CONTAINER(x) ((x) & SF_FORMAT_TYPEMASK)
121 #define SF_CODEC(x) ((x) & SF_FORMAT_SUBMASK)
122 #define SF_ENDIAN(x) ((x) & SF_FORMAT_ENDMASK)
125 { /* PEAK chunk location. */
129 /* PEAK chunk location. */
133 /* str_flags values. */
134 SF_STR_ALLOW_START
= 0x0100,
135 SF_STR_ALLOW_END
= 0x0200,
137 /* Location of strings. */
138 SF_STR_LOCATE_START
= 0x0400,
139 SF_STR_LOCATE_END
= 0x0800,
141 SFD_TYPEMASK
= 0x0FFFFFFF
144 #define SFM_MASK (SFM_READ | SFM_WRITE | SFM_RDWR)
145 #define SFM_UNMASK (~SFM_MASK)
147 /*---------------------------------------------------------------------------------------
148 ** Formats that may be supported at some time in the future.
149 ** When support is finalised, these values move to src/sndfile.h.
153 { /* Work in progress. */
154 SF_FORMAT_SPEEX
= 0x5000000,
155 SF_FORMAT_OGGFLAC
= 0x5000001,
157 /* Formats supported read only. */
158 SF_FORMAT_TXW
= 0x4030000, /* Yamaha TX16 sampler file */
159 SF_FORMAT_DWD
= 0x4040000, /* DiamondWare Digirized */
161 /* Following are detected but not supported. */
162 SF_FORMAT_REX
= 0x40A0000, /* Propellorheads Rex/Rcy */
163 SF_FORMAT_REX2
= 0x40D0000, /* Propellorheads Rex2 */
164 SF_FORMAT_KRZ
= 0x40E0000, /* Kurzweil sampler file */
165 SF_FORMAT_WMA
= 0x4100000, /* Windows Media Audio. */
166 SF_FORMAT_SHN
= 0x4110000, /* Shorten. */
168 /* Unsupported encodings. */
169 SF_FORMAT_SVX_FIB
= 0x1020, /* SVX Fibonacci Delta encoding. */
170 SF_FORMAT_SVX_EXP
= 0x1021, /* SVX Exponential Delta encoding. */
172 SF_FORMAT_PCM_N
= 0x1030
175 /*---------------------------------------------------------------------------------------
176 ** PEAK_CHUNK - This chunk type is common to both AIFF and WAVE files although their
177 ** endian encodings are different.
181 { double value
; /* signed value of peak */
182 sf_count_t position
; /* the sample frame for the peak */
186 { /* libsndfile internal : write a PEAK chunk at the start or end of the file? */
190 unsigned int version
; /* version of the PEAK chunk */
191 unsigned int timestamp
; /* secs since 1/1/1970 */
194 unsigned int edit_number
;
196 #if HAVE_FLEXIBLE_ARRAY
197 /* the per channel peak info */
201 ** This is not ISO compliant C. It works on some compilers which
202 ** don't support the ISO standard flexible struct array which is
203 ** used above. If your compiler doesn't like this I suggest you find
204 ** youself a 1999 ISO C standards compilant compiler. GCC-3.X is
205 ** highly recommended.
211 static inline PEAK_INFO
*
212 peak_info_calloc (int channels
)
213 { return calloc (1, sizeof (PEAK_INFO
) + channels
* sizeof (PEAK_POS
)) ;
214 } /* peak_info_calloc */
224 { return (size_t) x
;
225 } /* size_t_of_int */
227 typedef SF_BROADCAST_INFO_VAR (16 * 1024) SF_BROADCAST_INFO_16K
;
229 #if SIZEOF_WCHAR_T == 2
230 typedef wchar_t sfwchar_t
;
232 typedef int16_t sfwchar_t
;
236 ** This version of isprint specifically ignores any locale info. Its used for
237 ** determining which characters can be printed in things like hexdumps.
241 { return (ch
>= ' ' && ch
<= '~') ;
244 /*=======================================================================================
245 ** SF_PRIVATE stuct - a pointer to this struct is passed back to the caller of the
246 ** sf_open_XXXX functions. The caller however has no knowledge of the struct's
253 { char c
[SF_FILENAME_LEN
] ;
254 sfwchar_t wc
[SF_FILENAME_LEN
] ;
258 { char c
[SF_FILENAME_LEN
] ;
259 sfwchar_t wc
[SF_FILENAME_LEN
] ;
263 { char c
[SF_FILENAME_LEN
/ 4] ;
264 sfwchar_t wc
[SF_FILENAME_LEN
/ 4] ;
269 ** These fields can only be used in src/file_io.c.
270 ** They are basically the same as a windows file HANDLE.
272 void *handle
, *hsaved
;
276 /* These fields can only be used in src/file_io.c. */
277 int filedes
, savedes
;
280 int do_not_close_descriptor
;
281 int mode
; /* Open mode : SFM_READ, SFM_WRITE or SFM_RDWR. */
285 typedef struct sf_private_tag
287 /* Canary in a coal mine. */
289 { /* Place a double here to encourage double alignment. */
294 /* Force the compiler to double align the start of buffer. */
296 { double dbuf
[SF_BUFFER_LEN
/ sizeof (double)] ;
297 #if (defined (SIZEOF_INT64_T) && (SIZEOF_INT64_T == 8))
298 int64_t lbuf
[SF_BUFFER_LEN
/ sizeof (int64_t)] ;
300 long lbuf
[SF_BUFFER_LEN
/ sizeof (double)] ;
302 float fbuf
[SF_BUFFER_LEN
/ sizeof (float)] ;
303 int ibuf
[SF_BUFFER_LEN
/ sizeof (int)] ;
304 short sbuf
[SF_BUFFER_LEN
/ sizeof (short)] ;
305 char cbuf
[SF_BUFFER_LEN
/ sizeof (char)] ;
306 signed char scbuf
[SF_BUFFER_LEN
/ sizeof (signed char)] ;
307 unsigned char ucbuf
[SF_BUFFER_LEN
/ sizeof (signed char)] ;
311 PSF_FILE file
, rsrc
;
313 char syserr
[SF_SYSERR_LEN
] ;
315 /* logbuffer and logindex should only be changed within the logging functions
318 char logbuffer
[SF_BUFFER_LEN
] ;
319 unsigned char header
[SF_HEADER_LEN
] ; /* Must be unsigned */
320 int rwf_endian
; /* Header endian-ness flag. */
322 /* Storage and housekeeping data for adding/reading strings from
325 STR_DATA strings
[SF_MAX_STRINGS
] ;
326 char str_storage
[SF_STR_BUFFER_LEN
] ;
330 /* Guard value. If this changes the buffers above have overflowed. */
335 /* Index variables for maintaining logbuffer and header above. */
337 int headindex
, headend
;
342 int endian
; /* File endianness : SF_ENDIAN_LITTLE or SF_ENDIAN_BIG. */
343 int data_endswap
; /* Need to endswap data? */
346 ** Maximum float value for calculating the multiplier for
347 ** float/double to short/int conversions.
352 int scale_int_float
;
354 /* Vairables for handling pipes. */
355 int is_pipe
; /* True if file is a pipe. */
356 sf_count_t pipeoffset
; /* Number of bytes read from a pipe. */
358 /* True if clipping must be performed on float->int conversions. */
363 int have_written
; /* Has a single write been done to the file? */
364 PEAK_INFO
*peak_info
;
367 SF_LOOP_INFO
*loop_info
;
368 SF_INSTRUMENT
*instrument
;
370 /* Broadcast (EBU) Info */
371 SF_BROADCAST_INFO_16K
*broadcast_16k
;
373 /* Channel map data (if present) : an array of ints. */
376 sf_count_t filelength
; /* Overall length of (embedded) file. */
377 sf_count_t fileoffset
; /* Offset in number of bytes from beginning of file. */
379 sf_count_t rsrclength
; /* Length of the resource fork (if it exists). */
381 sf_count_t dataoffset
; /* Offset in number of bytes from beginning of file. */
382 sf_count_t datalength
; /* Length in bytes of the audio data. */
383 sf_count_t dataend
; /* Offset to file tailer. */
385 int blockwidth
; /* Size in bytes of one set of interleaved samples. */
386 int bytewidth
; /* Size in bytes of one sample (one channel). */
391 int last_op
; /* Last operation; either SFM_READ or SFM_WRITE */
392 sf_count_t read_current
;
393 sf_count_t write_current
;
395 void *container_data
; /* This is a pointer to dynamically allocated file
396 ** container format specific data.
399 void *codec_data
; /* This is a pointer to dynamically allocated file
400 ** codec format specific data.
403 SF_DITHER_INFO write_dither
;
404 SF_DITHER_INFO read_dither
;
413 /* A set of file specific function pointers */
414 sf_count_t (*read_short
) (struct sf_private_tag
*, short *ptr
, sf_count_t len
) ;
415 sf_count_t (*read_int
) (struct sf_private_tag
*, int *ptr
, sf_count_t len
) ;
416 sf_count_t (*read_float
) (struct sf_private_tag
*, float *ptr
, sf_count_t len
) ;
417 sf_count_t (*read_double
) (struct sf_private_tag
*, double *ptr
, sf_count_t len
) ;
419 sf_count_t (*write_short
) (struct sf_private_tag
*, const short *ptr
, sf_count_t len
) ;
420 sf_count_t (*write_int
) (struct sf_private_tag
*, const int *ptr
, sf_count_t len
) ;
421 sf_count_t (*write_float
) (struct sf_private_tag
*, const float *ptr
, sf_count_t len
) ;
422 sf_count_t (*write_double
) (struct sf_private_tag
*, const double *ptr
, sf_count_t len
) ;
424 sf_count_t (*seek
) (struct sf_private_tag
*, int mode
, sf_count_t samples_from_start
) ;
425 int (*write_header
) (struct sf_private_tag
*, int calc_length
) ;
426 int (*command
) (struct sf_private_tag
*, int command
, void *data
, int datasize
) ;
429 ** Separate close functions for the codec and the container.
430 ** The codec close function is always called first.
432 int (*codec_close
) (struct sf_private_tag
*) ;
433 int (*container_close
) (struct sf_private_tag
*) ;
437 /* Virtual I/O functions. */
440 void *vio_user_data
;
446 { SFE_NO_ERROR
= SF_ERR_NO_ERROR
,
447 SFE_BAD_OPEN_FORMAT
= SF_ERR_UNRECOGNISED_FORMAT
,
448 SFE_SYSTEM
= SF_ERR_SYSTEM
,
449 SFE_MALFORMED_FILE
= SF_ERR_MALFORMED_FILE
,
450 SFE_UNSUPPORTED_ENCODING
= SF_ERR_UNSUPPORTED_ENCODING
,
452 SFE_ZERO_MAJOR_FORMAT
,
453 SFE_ZERO_MINOR_FORMAT
,
459 SFE_BAD_SF_INCOMPLETE
,
473 SFE_NO_EMBED_SUPPORT
,
474 SFE_NO_EMBEDDED_RDWR
,
478 SFE_BAD_COMMAND_PARAM
,
480 SFE_CHANNEL_COUNT_ZERO
,
500 SFE_BAD_BROADCAST_INFO_SIZE
,
501 SFE_BAD_BROADCAST_INFO_TOO_BIG
,
521 SFE_WAV_BAD_BLOCKALIGN
,
524 SFE_WAV_ADPCM_NOT4BIT
,
525 SFE_WAV_ADPCM_CHANNELS
,
526 SFE_WAV_GSM610_FORMAT
,
527 SFE_WAV_UNKNOWN_CHUNK
,
531 SFE_AIFF_AIFF_NO_FORM
,
532 SFE_AIFF_COMM_NO_FORM
,
533 SFE_AIFF_SSND_NO_COMM
,
534 SFE_AIFF_UNKNOWN_CHUNK
,
535 SFE_AIFF_COMM_CHUNK_SIZE
,
536 SFE_AIFF_BAD_COMM_CHUNK
,
537 SFE_AIFF_PEAK_B4_COMM
,
541 SFE_AIFF_RW_SSND_NOT_LAST
,
543 SFE_AU_UNKNOWN_FORMAT
,
545 SFE_AU_EMBED_BAD_LEN
,
547 SFE_RAW_READ_BAD_SPEC
,
548 SFE_RAW_BAD_BITWIDTH
,
553 SFE_PAF_UNKNOWN_FORMAT
,
554 SFE_PAF_SHORT_HEADER
,
555 SFE_PAF_BAD_CHANNELS
,
561 SFE_SVX_BAD_NAME_LENGTH
,
564 SFE_NIST_CRLF_CONVERISON
,
565 SFE_NIST_BAD_ENCODING
,
571 SFE_VOC_BAD_SECTIONS
,
572 SFE_VOC_MULTI_SAMPLERATE
,
573 SFE_VOC_MULTI_SECTION
,
575 SFE_VOC_SECTION_COUNT
,
579 SFE_IRCAM_BAD_CHANNELS
,
580 SFE_IRCAM_UNKNOWN_FORMAT
,
586 SFE_W64_ADPCM_NOT4BIT
,
587 SFE_W64_ADPCM_CHANNELS
,
588 SFE_W64_GSM610_FORMAT
,
591 SFE_MAT4_NO_SAMPLERATE
,
595 SFE_MAT5_SAMPLE_RATE
,
599 SFE_PVF_BAD_BITWIDTH
,
601 SFE_DWVW_BAD_BITWIDTH
,
605 SFE_XI_EXCESS_SAMPLES
,
611 SFE_SDS_BAD_BIT_WIDTH
,
613 SFE_SD2_FD_DISALLOWED
,
614 SFE_SD2_BAD_DATA_OFFSET
,
615 SFE_SD2_BAD_MAP_OFFSET
,
616 SFE_SD2_BAD_DATA_LENGTH
,
617 SFE_SD2_BAD_MAP_LENGTH
,
619 SFE_SD2_BAD_SAMPLE_SIZE
,
622 SFE_FLAC_NEW_DECODER
,
623 SFE_FLAC_INIT_DECODER
,
625 SFE_FLAC_BAD_SAMPLE_RATE
,
626 SFE_FLAC_UNKOWN_ERROR
,
631 SFE_VORBIS_ENCODER_BUG
,
635 SFE_MAX_ERROR
/* This must be last in list. */
638 int subformat_to_bytewidth (int format
) ;
639 int s_bitwidth_to_subformat (int bits
) ;
640 int u_bitwidth_to_subformat (int bits
) ;
642 /* Functions for reading and writing floats and doubles on processors
643 ** with non-IEEE floats/doubles.
645 float float32_be_read (unsigned char *cptr
) ;
646 float float32_le_read (unsigned char *cptr
) ;
647 void float32_be_write (float in
, unsigned char *out
) ;
648 void float32_le_write (float in
, unsigned char *out
) ;
650 double double64_be_read (unsigned char *cptr
) ;
651 double double64_le_read (unsigned char *cptr
) ;
652 void double64_be_write (double in
, unsigned char *out
) ;
653 void double64_le_write (double in
, unsigned char *out
) ;
655 /* Functions for writing to the internal logging buffer. */
657 void psf_log_printf (SF_PRIVATE
*psf
, const char *format
, ...) ;
658 void psf_log_SF_INFO (SF_PRIVATE
*psf
) ;
660 int32_t psf_rand_int32 (void) ;
662 void append_snprintf (char * dest
, size_t maxlen
, const char * fmt
, ...) ;
663 void psf_strlcpy_crlf (char *dest
, const char *src
, size_t destmax
, size_t srcmax
) ;
665 /* Functions used when writing file headers. */
667 int psf_binheader_writef (SF_PRIVATE
*psf
, const char *format
, ...) ;
668 void psf_asciiheader_printf (SF_PRIVATE
*psf
, const char *format
, ...) ;
670 /* Functions used when reading file headers. */
672 int psf_binheader_readf (SF_PRIVATE
*psf
, char const *format
, ...) ;
674 /* Functions used in the write function for updating the peak chunk. */
676 void peak_update_short (SF_PRIVATE
*psf
, short *ptr
, size_t items
) ;
677 void peak_update_int (SF_PRIVATE
*psf
, int *ptr
, size_t items
) ;
678 void peak_update_double (SF_PRIVATE
*psf
, double *ptr
, size_t items
) ;
680 /* Functions defined in command.c. */
682 int psf_get_format_simple_count (void) ;
683 int psf_get_format_simple (SF_FORMAT_INFO
*data
) ;
685 int psf_get_format_info (SF_FORMAT_INFO
*data
) ;
687 int psf_get_format_major_count (void) ;
688 int psf_get_format_major (SF_FORMAT_INFO
*data
) ;
690 int psf_get_format_subtype_count (void) ;
691 int psf_get_format_subtype (SF_FORMAT_INFO
*data
) ;
693 void psf_generate_format_desc (SF_PRIVATE
*psf
) ;
695 double psf_calc_signal_max (SF_PRIVATE
*psf
, int normalize
) ;
696 int psf_calc_max_all_channels (SF_PRIVATE
*psf
, double *peaks
, int normalize
) ;
698 int psf_get_signal_max (SF_PRIVATE
*psf
, double *peak
) ;
699 int psf_get_max_all_channels (SF_PRIVATE
*psf
, double *peaks
) ;
701 /* Functions in strings.c. */
703 const char* psf_get_string (SF_PRIVATE
*psf
, int str_type
) ;
704 int psf_set_string (SF_PRIVATE
*psf
, int str_type
, const char *str
) ;
705 int psf_store_string (SF_PRIVATE
*psf
, int str_type
, const char *str
) ;
706 int psf_location_string_count (const SF_PRIVATE
* psf
, int location
) ;
708 /* Default seek function. Use for PCM and float encoded data. */
709 sf_count_t
psf_default_seek (SF_PRIVATE
*psf
, int mode
, sf_count_t samples_from_start
) ;
711 int macos_guess_file_type (SF_PRIVATE
*psf
, const char *filename
) ;
713 /*------------------------------------------------------------------------------------
714 ** File I/O functions which will allow access to large files (> 2 Gig) on
715 ** some 32 bit OSes. Implementation in file_io.c.
718 int psf_fopen (SF_PRIVATE
*psf
) ;
719 int psf_set_stdio (SF_PRIVATE
*psf
) ;
720 int psf_file_valid (SF_PRIVATE
*psf
) ;
721 void psf_set_file (SF_PRIVATE
*psf
, int fd
) ;
722 void psf_init_files (SF_PRIVATE
*psf
) ;
723 void psf_use_rsrc (SF_PRIVATE
*psf
, int on_off
) ;
725 SNDFILE
* psf_open_file (SF_PRIVATE
*psf
, SF_INFO
*sfinfo
) ;
727 sf_count_t
psf_fseek (SF_PRIVATE
*psf
, sf_count_t offset
, int whence
) ;
728 sf_count_t
psf_fread (void *ptr
, sf_count_t bytes
, sf_count_t count
, SF_PRIVATE
*psf
) ;
729 sf_count_t
psf_fwrite (const void *ptr
, sf_count_t bytes
, sf_count_t count
, SF_PRIVATE
*psf
) ;
730 sf_count_t
psf_fgets (char *buffer
, sf_count_t bufsize
, SF_PRIVATE
*psf
) ;
731 sf_count_t
psf_ftell (SF_PRIVATE
*psf
) ;
732 sf_count_t
psf_get_filelen (SF_PRIVATE
*psf
) ;
734 void psf_fsync (SF_PRIVATE
*psf
) ;
736 int psf_is_pipe (SF_PRIVATE
*psf
) ;
738 int psf_ftruncate (SF_PRIVATE
*psf
, sf_count_t len
) ;
739 int psf_fclose (SF_PRIVATE
*psf
) ;
741 /* Open and close the resource fork of a file. */
742 int psf_open_rsrc (SF_PRIVATE
*psf
) ;
743 int psf_close_rsrc (SF_PRIVATE
*psf
) ;
746 void psf_fclearerr (SF_PRIVATE *psf) ;
747 int psf_ferror (SF_PRIVATE *psf) ;
750 /*------------------------------------------------------------------------------------
751 ** Functions for reading and writing different file formats.
754 int aiff_open (SF_PRIVATE
*psf
) ;
755 int au_open (SF_PRIVATE
*psf
) ;
756 int avr_open (SF_PRIVATE
*psf
) ;
757 int htk_open (SF_PRIVATE
*psf
) ;
758 int ircam_open (SF_PRIVATE
*psf
) ;
759 int mat4_open (SF_PRIVATE
*psf
) ;
760 int mat5_open (SF_PRIVATE
*psf
) ;
761 int nist_open (SF_PRIVATE
*psf
) ;
762 int paf_open (SF_PRIVATE
*psf
) ;
763 int pvf_open (SF_PRIVATE
*psf
) ;
764 int raw_open (SF_PRIVATE
*psf
) ;
765 int sd2_open (SF_PRIVATE
*psf
) ;
766 int sds_open (SF_PRIVATE
*psf
) ;
767 int svx_open (SF_PRIVATE
*psf
) ;
768 int voc_open (SF_PRIVATE
*psf
) ;
769 int w64_open (SF_PRIVATE
*psf
) ;
770 int wav_open (SF_PRIVATE
*psf
) ;
771 int xi_open (SF_PRIVATE
*psf
) ;
772 int flac_open (SF_PRIVATE
*psf
) ;
773 int caf_open (SF_PRIVATE
*psf
) ;
774 int mpc2k_open (SF_PRIVATE
*psf
) ;
775 int rf64_open (SF_PRIVATE
*psf
) ;
777 /* In progress. Do not currently work. */
779 int ogg_vorbis_open (SF_PRIVATE
*psf
) ;
780 int ogg_speex_open (SF_PRIVATE
*psf
) ;
781 int ogg_pcm_open (SF_PRIVATE
*psf
) ;
784 int mpeg_open (SF_PRIVATE
*psf
) ;
785 int ogg_open (SF_PRIVATE
*psf
) ;
786 int rx2_open (SF_PRIVATE
*psf
) ;
787 int txw_open (SF_PRIVATE
*psf
) ;
788 int wve_open (SF_PRIVATE
*psf
) ;
789 int dwd_open (SF_PRIVATE
*psf
) ;
791 int macbinary3_open (SF_PRIVATE
*psf
) ;
793 /*------------------------------------------------------------------------------------
794 ** Init functions for a number of common data encodings.
797 int pcm_init (SF_PRIVATE
*psf
) ;
798 int ulaw_init (SF_PRIVATE
*psf
) ;
799 int alaw_init (SF_PRIVATE
*psf
) ;
800 int float32_init (SF_PRIVATE
*psf
) ;
801 int double64_init (SF_PRIVATE
*psf
) ;
802 int dwvw_init (SF_PRIVATE
*psf
, int bitwidth
) ;
803 int gsm610_init (SF_PRIVATE
*psf
) ;
804 int vox_adpcm_init (SF_PRIVATE
*psf
) ;
805 int flac_init (SF_PRIVATE
*psf
) ;
806 int g72x_init (SF_PRIVATE
* psf
) ;
808 int dither_init (SF_PRIVATE
*psf
, int mode
) ;
810 int wav_w64_ima_init (SF_PRIVATE
*psf
, int blockalign
, int samplesperblock
) ;
811 int wav_w64_msadpcm_init (SF_PRIVATE
*psf
, int blockalign
, int samplesperblock
) ;
813 int aiff_ima_init (SF_PRIVATE
*psf
, int blockalign
, int samplesperblock
) ;
815 int interleave_init (SF_PRIVATE
*psf
) ;
817 /*------------------------------------------------------------------------------------
818 ** Chunk logging functions.
831 void pchk4_store (PRIV_CHUNK4
* pchk
, int marker
, sf_count_t offset
, sf_count_t len
) ;
832 int pchk4_find (PRIV_CHUNK4
* pchk
, int marker
) ;
834 /*------------------------------------------------------------------------------------
835 ** Functions that work like OpenBSD's strlcpy/strlcat to replace strncpy/strncat.
837 ** See : http://www.gratisoft.us/todd/papers/strlcpy.html
839 ** These functions are available on *BSD, but are not avaialble everywhere so we
840 ** implement them here.
842 ** The argument order has been changed to that of strncpy/strncat to cause
843 ** compiler errors if code is carelessly converted from one to the other.
847 psf_strlcat (char *dest
, size_t n
, const char *src
)
848 { strncat (dest
, src
, n
- strlen (dest
) - 1) ;
853 psf_strlcpy (char *dest
, size_t n
, const char *src
)
854 { strncpy (dest
, src
, n
- 1) ;
858 /*------------------------------------------------------------------------------------
859 ** Other helper functions.
862 void *psf_memset (void *s
, int c
, sf_count_t n
) ;
864 SF_INSTRUMENT
* psf_instrument_alloc (void) ;
866 void psf_sanitize_string (char * cptr
, int len
) ;
868 /* Generate the current date as a string. */
869 void psf_get_date_str (char *str
, int maxlen
) ;
871 SF_BROADCAST_INFO_16K
* broadcast_var_alloc (void) ;
872 int broadcast_var_set (SF_PRIVATE
*psf
, const SF_BROADCAST_INFO
* data
, size_t datasize
) ;
873 int broadcast_var_get (SF_PRIVATE
*psf
, SF_BROADCAST_INFO
* data
, size_t datasize
) ;
881 int audio_detect (SF_PRIVATE
* psf
, AUDIO_DETECT
*ad
, const unsigned char * data
, int datalen
) ;
882 int id3_skip (SF_PRIVATE
* psf
) ;
884 /*------------------------------------------------------------------------------------
885 ** Helper/debug functions.
888 void psf_hexdump (const void *ptr
, int len
) ;
890 const char * str_of_major_format (int format
) ;
891 const char * str_of_minor_format (int format
) ;
892 const char * str_of_open_mode (int mode
) ;
893 const char * str_of_endianness (int end
) ;
895 /*------------------------------------------------------------------------------------
896 ** Extra commands for sf_command(). Not for public use yet.
900 { SFC_TEST_AIFF_ADD_INST_CHUNK
= 0x2000,
901 SFC_TEST_WAV_ADD_INFO_CHUNK
= 0x2010
905 ** Maybe, one day, make these functions or something like them, public.
907 ** Buffer to buffer dithering. Pointer in and out are allowed to point
908 ** to the same buffer for in-place dithering.
912 int sf_dither_short (const SF_DITHER_INFO
*dither
, const short *in
, short *out
, int count
) ;
913 int sf_dither_int (const SF_DITHER_INFO
*dither
, const int *in
, int *out
, int count
) ;
914 int sf_dither_float (const SF_DITHER_INFO
*dither
, const float *in
, float *out
, int count
) ;
915 int sf_dither_double (const SF_DITHER_INFO
*dither
, const double *in
, double *out
, int count
) ;
918 #endif /* SNDFILE_COMMON_H */