*** empty log message ***
[chuck-blob.git] / v2 / util_sndfile.h
blob5708496a62177a1d67f3893ed4c546016cfccae4
1 /*----------------------------------------------------------------------------
2 ChucK Concurrent, On-the-fly Audio Programming Language
3 Compiler and Virtual Machine
5 Copyright (c) 2004 Ge Wang and Perry R. Cook. All rights reserved.
6 http://chuck.cs.princeton.edu/
7 http://soundlab.cs.princeton.edu/
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 U.S.A.
23 -----------------------------------------------------------------------------*/
26 ** libsndfile Copyright (C) 1999-2004 Erik de Castro Lopo <erikd@mega-nerd.com>
28 ** This program is free software; you can redistribute it and/or modify
29 ** it under the terms of the GNU Lesser General Public License as published by
30 ** the Free Software Foundation; either version 2.1 of the License, or
31 ** (at your option) any later version.
33 ** This program is distributed in the hope that it will be useful,
34 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
35 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36 ** GNU Lesser General Public License for more details.
38 ** You should have received a copy of the GNU Lesser General Public License
39 ** along with this program; if not, write to the Free Software
40 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
43 //-----------------------------------------------------------------------------
44 // name: util_sndfile.h
45 // desc: libsndfile for ChucK
47 // authors: Ge Wang (gewang@cs.princeton.edu)
48 // Perry R. Cook (prc@cs.princeton.edu)
49 // Ari Lazier (alazier@alumni.princeton.edu)
50 // libsndfile: Erik de Castro Lopo (erikd@mega-nerd.com)
51 //-----------------------------------------------------------------------------
52 #ifndef __UTIL_SNDFILE_H__
53 #define __UTIL_SNDFILE_H__
55 #include <stdio.h>
56 #include <stdlib.h>
59 // XXX philipd this might break things?
60 // these defines were placed after the machine-dependent
61 // checks below...i'm not sure why
63 #define COMPILER_IS_GCC 1
64 #define CPU_CLIPS_NEGATIVE 1
65 #define ENABLE_EXPERIMENTAL_CODE 0
66 #define GCC_MAJOR_VERSION 3
67 #define HAVE_CALLOC 1
68 #define HAVE_CEIL 1
69 #define HAVE_DECL_S_IRGRP 1
70 #define HAVE_DLFCN_H 1
71 #define HAVE_FLEXIBLE_ARRAY 1
72 #define HAVE_FLOOR 1
73 #define HAVE_FMOD 1
74 #define HAVE_FREE 1
75 #define HAVE_FSTAT 1
76 #define HAVE_FSYNC 1
77 #define HAVE_FTRUNCATE 1
78 #define HAVE_GETPAGESIZE 1
79 #define HAVE_GMTIME 1
80 #define HAVE_GMTIME_R 1
81 #define HAVE_INTTYPES_H 1
82 #define HAVE_LIBM 1
83 #define HAVE_LSEEK 1
84 #define HAVE_MALLOC 1
85 #define HAVE_MEMORY_H 1
86 #define HAVE_MMAP 1
87 #define HAVE_OPEN 1
88 #define HAVE_READ 1
89 #define HAVE_REALLOC 1
90 #define HAVE_SNPRINTF 1
91 #define HAVE_STDINT_H 1
92 #define HAVE_STDLIB_H 1
93 #define HAVE_STRINGS_H 1
94 #define HAVE_STRING_H 1
95 #define HAVE_SYS_STAT_H 1
96 #define HAVE_SYS_TYPES_H 1
97 #define HAVE_SYS_WAIT_H 1
98 #define HAVE_VSNPRINTF 1
99 #define HAVE_WRITE 1
100 #define PACKAGE "libsndfile"
101 #define PACKAGE_BUGREPORT "erikd@mega-nerd.com"
102 #define PACKAGE_NAME "libsndfile"
103 #define PACKAGE_STRING "libsndfile 1.0.10"
104 #define PACKAGE_TARNAME "libsndfile"
105 #define PACKAGE_VERSION "1.0.10"
107 #define SIZEOF_DOUBLE 8
108 #define SIZEOF_FLOAT 4
109 #define SIZEOF_INT 4
110 #define SIZEOF_LONG 4
111 #define SIZEOF_OFF_T 8
112 #define SIZEOF_SF_COUNT_T 8
113 #define SIZEOF_SHORT 2
114 #define SIZEOF_SIZE_T 4
115 #define SIZEOF_SSIZE_T 4
116 #define SIZEOF_VOIDP 4
117 #define STDC_HEADERS 1
119 #define VERSION "1.0.10"
121 #ifdef __MACOSX_CORE__
122 #define CPU_CLIPS_POSITIVE 1
123 #ifdef __LITTLE_ENDIAN__
124 #define CPU_IS_BIG_ENDIAN 0
125 #define CPU_IS_LITTLE_ENDIAN 1
126 #define HAVE_LRINTF 1
127 #define HAVE_LRINT 1
128 #else
129 #define CPU_IS_BIG_ENDIAN 1
130 #define CPU_IS_LITTLE_ENDIAN 0
131 #endif
132 #define HAVE_PREAD 1
133 #define HAVE_PWRITE 1
134 #define OS_IS_MACOSX 1
135 #define OS_IS_WIN32 0
136 #define TYPEOF_SF_COUNT_T off_t
137 #endif
139 #if defined(__PLATFORM_WIN32__) //Dev Studio
140 #define CPU_CLIPS_POSITIVE 0
141 #define CPU_IS_BIG_ENDIAN 0
142 #define CPU_IS_LITTLE_ENDIAN 1
143 #define HAVE_LRINTF 0
144 #define HAVE_LRINT 0
145 #undef HAVE_GMTIME_R
146 #undef HAVE_GMTIME
147 #undef HAVE_SNPRINTF
148 #undef HAVE_FLEXIBLE_ARRAY
149 #define OS_IS_MACOSX 0
150 #define OS_IS_WIN32 1
151 #define TYPEOF_SF_COUNT_T off_t
152 #endif
154 #if defined (__WINDOWS_PTHREAD__) //Cygwin
155 #define CPU_CLIPS_POSITIVE 0
156 #define CPU_IS_BIG_ENDIAN 0
157 #define CPU_IS_LITTLE_ENDIAN 1
158 #define HAVE_LRINTF 0
159 #define HAVE_LRINT 0
160 #define OS_IS_MACOSX 0
161 #define OS_IS_WIN32 0
162 #define TYPEOF_SF_COUNT_T off_t
163 #endif
165 #ifdef __LINUX_ALSA__
166 #define HAVE_ALSA_ASOUNDLIB_H
167 #endif
169 #if defined(__LINUX_ALSA__) || defined(__LINUX_OSS__) || defined(__LINUX_JACK__)
170 #define CPU_CLIPS_POSITIVE 0
171 #define CPU_IS_BIG_ENDIAN 0
172 #define CPU_IS_LITTLE_ENDIAN 1
173 #define HAVE_PREAD 1
174 #define HAVE_PWRITE 1
175 #define OS_IS_MACOSX 0
176 #define OS_IS_WIN32 0
177 #define SIZEOF_OFF64_T 0
178 #define SIZEOF_LOFF_T 8
179 #define TYPEOF_SF_COUNT_T loff_t
180 #define _FILE_OFFSET_BITS 64
181 #define HAVE_FDATASYNC 1
182 #define HAVE_ENDIAN_H 1
183 #define HAVE_LRINTF 1
184 #define HAVE_LRINT 1
185 #endif
189 // XXX 'inline' is necessary for C compilation
190 // in the microsoft vc6 compiler...
191 // and other ms win32 specialteez.
193 #ifdef __PLATFORM_WIN32__
195 #define C_INLINE __inline
196 #define SF_COUNT_MAX 0x7FFFFFFFFFFFFFFF
198 #else
200 #define C_INLINE inline
201 #define SF_COUNT_MAX 0x7FFFFFFFFFFFFFFFLL
202 #define HAVE_UNISTD_H 1
203 #define HAVE_SSIZE_T 1
205 #endif
208 ** sndfile.h -- system-wide definitions
210 ** API documentation is in the doc/ directory of the source code tarball
211 ** and at http://www.mega-nerd.com/libsndfile/api.html.
214 #ifndef SNDFILE_H
215 #define SNDFILE_H
217 /* This is the version 1.0.X header file. */
218 #define SNDFILE_1
221 /* For the Metrowerks CodeWarrior Pro Compiler (mainly MacOS) */
223 #if (defined (__MWERKS__))
224 #else
225 #include <sys/types.h>
226 #endif
228 #ifdef __cplusplus
229 extern "C" {
230 #endif /* __cplusplus */
232 /* The following file types can be read and written.
233 ** A file type would consist of a major type (ie SF_FORMAT_WAV) bitwise
234 ** ORed with a minor type (ie SF_FORMAT_PCM). SF_FORMAT_TYPEMASK and
235 ** SF_FORMAT_SUBMASK can be used to separate the major and minor file
236 ** types.
239 enum
240 { /* Major formats. */
241 SF_FORMAT_WAV = 0x010000, /* Microsoft WAV format (little endian). */
242 SF_FORMAT_AIFF = 0x020000, /* Apple/SGI AIFF format (big endian). */
243 SF_FORMAT_AU = 0x030000, /* Sun/NeXT AU format (big endian). */
244 SF_FORMAT_RAW = 0x040000, /* RAW PCM data. */
245 SF_FORMAT_PAF = 0x050000, /* Ensoniq PARIS file format. */
246 SF_FORMAT_SVX = 0x060000, /* Amiga IFF / SVX8 / SV16 format. */
247 SF_FORMAT_NIST = 0x070000, /* Sphere NIST format. */
248 SF_FORMAT_VOC = 0x080000, /* VOC files. */
249 SF_FORMAT_IRCAM = 0x0A0000, /* Berkeley/IRCAM/CARL */
250 SF_FORMAT_W64 = 0x0B0000, /* Sonic Foundry's 64 bit RIFF/WAV */
251 SF_FORMAT_MAT4 = 0x0C0000, /* Matlab (tm) V4.2 / GNU Octave 2.0 */
252 SF_FORMAT_MAT5 = 0x0D0000, /* Matlab (tm) V5.0 / GNU Octave 2.1 */
253 SF_FORMAT_PVF = 0x0E0000, /* Portable Voice Format */
254 SF_FORMAT_XI = 0x0F0000, /* Fasttracker 2 Extended Instrument */
255 SF_FORMAT_HTK = 0x100000, /* HMM Tool Kit format */
256 SF_FORMAT_SDS = 0x110000, /* Midi Sample Dump Standard */
257 SF_FORMAT_AVR = 0x120000, /* Audio Visual Research */
258 SF_FORMAT_WAVEX = 0x130000, /* MS WAVE with WAVEFORMATEX */
260 /* Subtypes from here on. */
262 SF_FORMAT_PCM_S8 = 0x0001, /* Signed 8 bit data */
263 SF_FORMAT_PCM_16 = 0x0002, /* Signed 16 bit data */
264 SF_FORMAT_PCM_24 = 0x0003, /* Signed 24 bit data */
265 SF_FORMAT_PCM_32 = 0x0004, /* Signed 32 bit data */
266 SF_FORMAT_PCM_U8 = 0x0005, /* Unsigned 8 bit data (WAV and RAW only) */
267 SF_FORMAT_FLOAT = 0x0006, /* 32 bit float data */
268 SF_FORMAT_DOUBLE = 0x0007, /* 64 bit float data */
269 SF_FORMAT_ULAW = 0x0010, /* U-Law encoded. */
270 SF_FORMAT_ALAW = 0x0011, /* A-Law encoded. */
271 SF_FORMAT_IMA_ADPCM = 0x0012, /* IMA ADPCM. */
272 SF_FORMAT_MS_ADPCM = 0x0013, /* Microsoft ADPCM. */
273 SF_FORMAT_GSM610 = 0x0020, /* GSM 6.10 encoding. */
274 SF_FORMAT_VOX_ADPCM = 0x0021, /* OKI / Dialogix ADPCM */
275 SF_FORMAT_G721_32 = 0x0030, /* 32kbs G721 ADPCM encoding. */
276 SF_FORMAT_G723_24 = 0x0031, /* 24kbs G723 ADPCM encoding. */
277 SF_FORMAT_G723_40 = 0x0032, /* 40kbs G723 ADPCM encoding. */
278 SF_FORMAT_DWVW_12 = 0x0040, /* 12 bit Delta Width Variable Word encoding. */
279 SF_FORMAT_DWVW_16 = 0x0041, /* 16 bit Delta Width Variable Word encoding. */
280 SF_FORMAT_DWVW_24 = 0x0042, /* 24 bit Delta Width Variable Word encoding. */
281 SF_FORMAT_DWVW_N = 0x0043, /* N bit Delta Width Variable Word encoding. */
282 SF_FORMAT_DPCM_8 = 0x0050, /* 8 bit differential PCM (XI only) */
283 SF_FORMAT_DPCM_16 = 0x0051, /* 16 bit differential PCM (XI only) */
285 /* Endian-ness options. */
287 SF_ENDIAN_FILE = 0x00000000, /* Default file endian-ness. */
288 SF_ENDIAN_LITTLE = 0x10000000, /* Force little endian-ness. */
289 SF_ENDIAN_BIG = 0x20000000, /* Force big endian-ness. */
290 SF_ENDIAN_CPU = 0x30000000, /* Force CPU endian-ness. */
292 SF_FORMAT_SUBMASK = 0x0000FFFF,
293 SF_FORMAT_TYPEMASK = 0x0FFF0000,
294 SF_FORMAT_ENDMASK = 0x30000000
300 ** The following are the valid command numbers for the sf_command()
301 ** interface. The use of these commands is documented in the file
302 ** command.html in the doc directory of the source code distribution.
307 enum
308 { SFC_GET_LIB_VERSION = 0x1000,
309 SFC_GET_LOG_INFO = 0x1001,
310 SFC_GET_NORM_DOUBLE = 0x1010,
311 SFC_GET_NORM_FLOAT = 0x1011,
312 SFC_SET_NORM_DOUBLE = 0x1012,
313 SFC_SET_NORM_FLOAT = 0x1013,
314 SFC_GET_SIMPLE_FORMAT_COUNT = 0x1020,
315 SFC_GET_SIMPLE_FORMAT = 0x1021,
316 SFC_GET_FORMAT_INFO = 0x1028,
317 SFC_GET_FORMAT_MAJOR_COUNT = 0x1030,
318 SFC_GET_FORMAT_MAJOR = 0x1031,
319 SFC_GET_FORMAT_SUBTYPE_COUNT = 0x1032,
320 SFC_GET_FORMAT_SUBTYPE = 0x1033,
321 SFC_CALC_SIGNAL_MAX = 0x1040,
322 SFC_CALC_NORM_SIGNAL_MAX = 0x1041,
323 SFC_CALC_MAX_ALL_CHANNELS = 0x1042,
324 SFC_CALC_NORM_MAX_ALL_CHANNELS = 0x1043,
325 SFC_SET_ADD_PEAK_CHUNK = 0x1050,
326 SFC_UPDATE_HEADER_NOW = 0x1060,
327 SFC_SET_UPDATE_HEADER_AUTO = 0x1061,
328 SFC_FILE_TRUNCATE = 0x1080,
329 SFC_SET_RAW_START_OFFSET = 0x1090,
330 SFC_SET_DITHER_ON_WRITE = 0x10A0,
331 SFC_SET_DITHER_ON_READ = 0x10A1,
332 SFC_GET_DITHER_INFO_COUNT = 0x10A2,
333 SFC_GET_DITHER_INFO = 0x10A3,
334 SFC_GET_EMBED_FILE_INFO = 0x10B0,
335 SFC_SET_CLIPPING = 0x10C0,
336 SFC_GET_CLIPPING = 0x10C1,
337 SFC_GET_INSTRUMENT = 0x10D0,
338 SFC_SET_INSTRUMENT = 0x10D1,
340 /* Following commands for testing only. */
341 SFC_TEST_IEEE_FLOAT_REPLACE = 0x6001,
344 ** SFC_SET_ADD_* values are deprecated and will disappear at some
345 ** time in the future. They are guaranteed to be here up to and
346 ** including version 1.0.8 to avoid breakage of existng software.
347 ** They currently do nothing and will continue to do nothing.
350 SFC_SET_ADD_DITHER_ON_WRITE = 0x1070,
351 SFC_SET_ADD_DITHER_ON_READ = 0x1071
359 ** String types that can be set and read from files. Not all file types
360 ** support this and even the file types which support one, may not support
361 ** all string types.
365 enum
366 { SF_STR_TITLE = 0x01,
367 SF_STR_COPYRIGHT = 0x02,
368 SF_STR_SOFTWARE = 0x03,
369 SF_STR_ARTIST = 0x04,
370 SF_STR_COMMENT = 0x05,
371 SF_STR_DATE = 0x06
376 enum
377 { /* True and false */
378 SF_FALSE = 0,
379 SF_TRUE = 1,
381 /* Modes for opening files. */
382 SFM_READ = 0x10,
383 SFM_WRITE = 0x20,
384 SFM_RDWR = 0x30
389 /* Pubic error values. These are guaranteed to remain unchanged for the duration
390 ** of the library major version number.
391 ** There are also a large number of private error numbers which are internal to
392 ** the library which can change at any time.
397 enum
398 { SF_ERR_NO_ERROR = 0,
399 SF_ERR_UNRECOGNISED_FORMAT = 1,
400 SF_ERR_SYSTEM = 2
405 /* A SNDFILE* pointer can be passed around much like stdio.h's FILE* pointer. */
407 typedef struct SNDFILE_tag SNDFILE ;
410 /* The following typedef is system specific and is defined when libsndfile is.
411 ** compiled. sf_count_t can be one of loff_t (Linux), off_t (*BSD),
412 ** off64_t (Solaris), __int64_t (Win32) etc.
415 typedef TYPEOF_SF_COUNT_T sf_count_t ;
417 //#define SF_COUNT_MAX 0x7FFFFFFFFFFFFFFFLL
419 /* A pointer to a SF_INFO structure is passed to sf_open_read () and filled in.
420 ** On write, the SF_INFO structure is filled in by the user and passed into
421 ** sf_open_write ().
424 struct SF_INFO
425 { sf_count_t frames ; /* Used to be called samples. Changed to avoid confusion. */
426 int samplerate ;
427 int channels ;
428 int format ;
429 int sections ;
430 int seekable ;
433 typedef struct SF_INFO SF_INFO ;
435 /* The SF_FORMAT_INFO struct is used to retrieve information about the sound
436 ** file formats libsndfile supports using the sf_command () interface.
438 ** Using this interface will allow applications to support new file formats
439 ** and encoding types when libsndfile is upgraded, without requiring
440 ** re-compilation of the application.
442 ** Please consult the libsndfile documentation (particularly the information
443 ** on the sf_command () interface) for examples of its use.
446 typedef struct
447 { int format ;
448 const char *name ;
449 const char *extension ;
450 } SF_FORMAT_INFO ;
453 ** Enums and typedefs for adding dither on read and write.
454 ** See the html documentation for sf_command(), SFC_SET_DITHER_ON_WRITE
455 ** and SFC_SET_DITHER_ON_READ.
458 enum
459 { SFD_DEFAULT_LEVEL = 0,
460 SFD_CUSTOM_LEVEL = 0x40000000,
462 SFD_NO_DITHER = 500,
463 SFD_WHITE = 501,
464 SFD_TRIANGULAR_PDF = 502
467 typedef struct
468 { int type ;
469 double level ;
470 const char *name ;
471 } SF_DITHER_INFO ;
473 /* Struct used to retrieve information about a file embedded within a
474 ** larger file. See SFC_GET_EMBED_FILE_INFO.
477 typedef struct
478 { sf_count_t offset ;
479 sf_count_t length ;
480 } SF_EMBED_FILE_INFO ;
482 /* Struct used to retrieve music sample information from a file.
485 typedef struct
486 { int basenote ;
487 int gain ;
488 int sustain_mode ;
489 int sustain_start, sustain_end ;
490 int release_mode ;
491 int release_start, reslease_end ;
492 } SF_INSTRUMENT ;
494 /* sustain_mode and release_mode will be one of the following. */
496 enum
497 { SF_LOOP_NONE = 800,
498 SF_LOOP_FORWARD,
499 SF_LOOP_BACKWARD
502 /* Open the specified file for read, write or both. On error, this will
503 ** return a NULL pointer. To find the error number, pass a NULL SNDFILE
504 ** to sf_perror () or sf_error_str ().
505 ** All calls to sf_open() should be matched with a call to sf_close().
508 SNDFILE* sf_open (const char *path, int mode, SF_INFO *sfinfo) ;
510 /* Use the existing file descriptor to create a SNDFILE object. If close_desc
511 ** is TRUE, the file descriptor will be closed when sf_close() is called. If
512 ** it is FALSE, the descritor will not be closed.
513 ** When passed a descriptor like this, the library will assume that the start
514 ** of file header is at the current file offset. This allows sound files within
515 ** larger container files to be read and/or written.
516 ** On error, this will return a NULL pointer. To find the error number, pass a
517 ** NULL SNDFILE to sf_perror () or sf_error_str ().
518 ** All calls to sf_open_fd() should be matched with a call to sf_close().
522 SNDFILE* sf_open_fd (int fd, int mode, SF_INFO *sfinfo, int close_desc) ;
524 /* sf_error () returns a error number which can be translated to a text
525 ** string using sf_error_number().
528 int sf_error (SNDFILE *sndfile) ;
530 /* sf_strerror () returns to the caller a pointer to the current error message for
531 ** the given SNDFILE.
534 const char* sf_strerror (SNDFILE *sndfile) ;
536 /* sf_error_number () allows the retrieval of the error string for each internal
537 ** error number.
541 const char* sf_error_number (int errnum) ;
543 /* The following three error functions are deprecated but they will remain in the
544 ** library for the forseeable future. The function sf_strerror() should be used
545 ** in their place.
548 int sf_perror (SNDFILE *sndfile) ;
549 int sf_error_str (SNDFILE *sndfile, char* str, size_t len) ;
552 /* Return TRUE if fields of the SF_INFO struct are a valid combination of values. */
554 int sf_command (SNDFILE *sndfile, int command, void *data, int datasize) ;
556 /* Return TRUE if fields of the SF_INFO struct are a valid combination of values. */
558 int sf_format_check (const SF_INFO *info) ;
560 /* Seek within the waveform data chunk of the SNDFILE. sf_seek () uses
561 ** the same values for whence (SEEK_SET, SEEK_CUR and SEEK_END) as
562 ** stdio.h function fseek ().
563 ** An offset of zero with whence set to SEEK_SET will position the
564 ** read / write pointer to the first data sample.
565 ** On success sf_seek returns the current position in (multi-channel)
566 ** samples from the start of the file.
567 ** Please see the libsndfile documentation for moving the read pointer
568 ** separately from the write pointer on files open in mode SFM_RDWR.
569 ** On error all of these functions return -1.
572 sf_count_t sf_seek (SNDFILE *sndfile, sf_count_t frames, int whence) ;
574 /* Functions for retrieving and setting string data within sound files.
575 ** Not all file types support this features; AIFF and WAV do. For both
576 ** functions, the str_type parameter must be one of the SF_STR_* values
577 ** defined above.
578 ** On error, sf_set_string() returns non-zero while sf_get_string()
579 ** returns NULL.
582 int sf_set_string (SNDFILE *sndfile, int str_type, const char* str) ;
584 const char* sf_get_string (SNDFILE *sndfile, int str_type) ;
586 /* Functions for reading/writing the waveform data of a sound file.
589 sf_count_t sf_read_raw (SNDFILE *sndfile, void *ptr, sf_count_t bytes) ;
590 sf_count_t sf_write_raw (SNDFILE *sndfile, void *ptr, sf_count_t bytes) ;
592 /* Functions for reading and writing the data chunk in terms of frames.
593 ** The number of items actually read/written = frames * number of channels.
594 ** sf_xxxx_raw read/writes the raw data bytes from/to the file
595 ** sf_xxxx_short passes data in the native short format
596 ** sf_xxxx_int passes data in the native int format
597 ** sf_xxxx_float passes data in the native float format
598 ** sf_xxxx_double passes data in the native double format
599 ** All of these read/write function return number of frames read/written.
602 sf_count_t sf_readf_short (SNDFILE *sndfile, short *ptr, sf_count_t frames) ;
603 sf_count_t sf_writef_short (SNDFILE *sndfile, short *ptr, sf_count_t frames) ;
605 sf_count_t sf_readf_int (SNDFILE *sndfile, int *ptr, sf_count_t frames) ;
606 sf_count_t sf_writef_int (SNDFILE *sndfile, int *ptr, sf_count_t frames) ;
608 sf_count_t sf_readf_float (SNDFILE *sndfile, float *ptr, sf_count_t frames) ;
609 sf_count_t sf_writef_float (SNDFILE *sndfile, float *ptr, sf_count_t frames) ;
611 sf_count_t sf_readf_double (SNDFILE *sndfile, double *ptr, sf_count_t frames) ;
612 sf_count_t sf_writef_double (SNDFILE *sndfile, double *ptr, sf_count_t frames) ;
614 /* Functions for reading and writing the data chunk in terms of items.
615 ** Otherwise similar to above.
616 ** All of these read/write function return number of items read/written.
619 sf_count_t sf_read_short (SNDFILE *sndfile, short *ptr, sf_count_t items) ;
620 sf_count_t sf_write_short (SNDFILE *sndfile, short *ptr, sf_count_t items) ;
622 sf_count_t sf_read_int (SNDFILE *sndfile, int *ptr, sf_count_t items) ;
623 sf_count_t sf_write_int (SNDFILE *sndfile, int *ptr, sf_count_t items) ;
625 sf_count_t sf_read_float (SNDFILE *sndfile, float *ptr, sf_count_t items) ;
626 sf_count_t sf_write_float (SNDFILE *sndfile, float *ptr, sf_count_t items) ;
628 sf_count_t sf_read_double (SNDFILE *sndfile, double *ptr, sf_count_t items) ;
629 sf_count_t sf_write_double (SNDFILE *sndfile, double *ptr, sf_count_t items) ;
631 /* Close the SNDFILE and clean up all memory allocations associated with this
632 ** file.
633 ** Returns 0 on success, or an error number.
636 int sf_close (SNDFILE *sndfile) ;
638 #ifdef __cplusplus
639 } /* extern "C" */
640 #endif /* __cplusplus */
642 #endif /* SNDFILE_H */
644 ** Copyright (C) 1999-2004 Erik de Castro Lopo <erikd@mega-nerd.com>
646 ** This program is free software; you can redistribute it and/or modify
647 ** it under the terms of the GNU Lesser General Public License as published by
648 ** the Free Software Foundation; either version 2.1 of the License, or
649 ** (at your option) any later version.
651 ** This program is distributed in the hope that it will be useful,
652 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
653 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
654 ** GNU Lesser General Public License for more details.
656 ** You should have received a copy of the GNU Lesser General Public License
657 ** along with this program; if not, write to the Free Software
658 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
661 #ifndef COMMON_H_INCLUDED
662 #define COMMON_H_INCLUDED
665 #ifndef SNDFILE_H
666 #endif
668 #define SF_BUFFER_LEN (8192*2)
669 #define SF_FILENAME_LEN (256)
670 #define SF_HEADER_LEN (4096)
671 #define SF_TEXT_LEN (1024)
672 #define SF_SYSERR_LEN (256)
673 #define SF_MAX_STRINGS (16)
675 #define SF_SEEK_ERROR ((sf_count_t) -1)
678 #define BITWIDTH2BYTES(x) (((x) + 7) / 8)
680 /* For some reason sizeof returns an unsigned value which causes
681 ** a warning when that value is added or subtracted from a signed
682 ** value. Use SIGNED_SIZEOF instead.
684 #define SIGNED_SIZEOF(x) ((int) sizeof (x))
686 #define ARRAY_LEN(x) ((int) (sizeof (x) / sizeof ((x) [0])))
688 #define SF_MAX(a,b) ((a) > (b) ? (a) : (b))
689 #define SF_MIN(a,b) ((a) < (b) ? (a) : (b))
691 enum
692 { /* PEAK chunk location. */
693 SF_PEAK_START = 42,
694 SF_PEAK_END = 43,
696 /* PEAK chunk location. */
697 SF_SCALE_MAX = 52,
698 SF_SCALE_MIN = 53,
700 /* str_flags values. */
701 SF_STR_ALLOW_START = 0x0100,
702 SF_STR_ALLOW_END = 0x0200,
704 /* Location of strings. */
705 SF_STR_LOCATE_START = 0x0400,
706 SF_STR_LOCATE_END = 0x0800,
708 SFD_TYPEMASK = 0x0FFFFFFF
711 #define SFM_MASK (SFM_READ | SFM_WRITE | SFM_RDWR)
712 #define SFM_UNMASK (~SFM_MASK)
714 /*---------------------------------------------------------------------------------------
715 ** Formats that may be supported at some time in the future.
716 ** When support is finalised, these values move to src/sndfile.h.
719 enum
720 { /* Work in progress. */
722 /* Formats supported read only. */
723 SF_FORMAT_WVE = 0x4020000, /* Psion ALaw Sound File */
724 SF_FORMAT_TXW = 0x4030000, /* Yamaha TX16 sampler file */
725 SF_FORMAT_DWD = 0x4040000, /* DiamondWare Digirized */
727 /* Following are detected but not supported. */
728 SF_FORMAT_OGG = 0x4090000,
730 SF_FORMAT_REX = 0x40A0000, /* Propellorheads Rex/Rcy */
731 SF_FORMAT_SD2 = 0x40C0000, /* Sound Designer 2 */
732 SF_FORMAT_REX2 = 0x40D0000, /* Propellorheads Rex2 */
733 SF_FORMAT_KRZ = 0x40E0000, /* Kurzweil sampler file */
734 SF_FORMAT_WMA = 0x4100000, /* Windows Media Audio. */
735 SF_FORMAT_SHN = 0x4110000, /* Shorten. */
736 SF_FORMAT_FLAC = 0x4120000,
738 /* Unsupported encodings. */
739 SF_FORMAT_VORBIS = 0x1001,
741 SF_FORMAT_SVX_FIB = 0x1020, /* SVX Fibonacci Delta encoding. */
742 SF_FORMAT_SVX_EXP = 0x1021, /* SVX Exponential Delta encoding. */
744 SF_FORMAT_PCM_N = 0x1030
747 /*---------------------------------------------------------------------------------------
748 ** PEAK_CHUNK_OLD - This chunk type is common to both AIFF and WAVE files although their
749 ** endian encodings are different.
752 typedef struct
753 { float value ; /* signed value of peak */
754 unsigned int position ; /* the sample frame for the peak */
755 } PEAK_POS ;
757 typedef struct
758 { unsigned int version ; /* version of the PEAK chunk */
759 unsigned int timestamp ; /* secs since 1/1/1970 */
760 #if HAVE_FLEXIBLE_ARRAY
761 PEAK_POS peaks [] ; /* the per channel peak info */
762 #else
763 PEAK_POS peaks [1] ; /* the per channel peak info */
764 #endif
765 } PEAK_CHUNK ;
767 typedef struct
768 { int type ;
769 int flags ;
770 char *str ;
771 } STR_DATA ;
773 /*=======================================================================================
774 ** SF_PRIVATE stuct - a pointer to this struct is passed back to the caller of the
775 ** sf_open_XXXX functions. The caller however has no knowledge of the struct's
776 ** contents.
779 typedef struct sf_private_tag
780 { /* Force the compiler to double align the start of buffer. */
781 double buffer [SF_BUFFER_LEN / sizeof (double)] ;
782 char filename [SF_FILENAME_LEN] ;
784 char syserr [SF_SYSERR_LEN] ;
786 /* logbuffer and logindex should only be changed within the logging functions
787 ** of common.c
789 char logbuffer [SF_BUFFER_LEN] ;
790 unsigned char header [SF_HEADER_LEN] ; /* Must be unsigned */
791 int rwf_endian ; /* Header endian-ness flag. */
793 /* Storage and housekeeping data for adding/reading strings from
794 ** sound files.
796 STR_DATA strings [SF_MAX_STRINGS] ;
797 char str_storage [SF_BUFFER_LEN] ;
798 char *str_end ;
799 int str_flags ;
801 /* Guard value. If this changes the buffers above have overflowed. */
802 int Magick ;
804 /* Index variables for maintaining logbuffer and header above. */
805 int logindex ;
806 int headindex, headend ;
807 int has_text ;
808 int do_not_close_descriptor ;
810 int filedes ;
812 int end_of_file ;
813 int error ;
815 int mode ; /* Open mode : SFM_READ, SFM_WRITE or SFM_RDWR. */
816 int endian ; /* File endianness : SF_ENDIAN_LITTLE or SF_ENDIAN_BIG. */
817 int float_endswap ; /* Need to endswap float32s? */
819 /* Vairables for handling pipes. */
820 int is_pipe ; /* True if file is a pipe. */
821 sf_count_t pipeoffset ; /* Number of bytes read from a pipe. */
823 /* True if clipping must be performed on float->int conversions. */
824 int add_clipping ;
826 SF_INFO sf ;
828 int have_written ; /* Has a single write been done to the file? */
829 int has_peak ; /* Has a PEAK chunk (AIFF and WAVE) been read? */
830 int peak_loc ; /* Write a PEAK chunk at the start or end of the file? */
831 PEAK_CHUNK *pchunk ;
833 sf_count_t filelength ; /* Overall length of (embedded) file. */
834 sf_count_t fileoffset ; /* Offset in number of bytes from beginning of file. */
836 sf_count_t dataoffset ; /* Offset in number of bytes from beginning of file. */
837 sf_count_t datalength ; /* Length in bytes of the audio data. */
838 sf_count_t dataend ; /* Offset to file tailer. */
840 int blockwidth ; /* Size in bytes of one set of interleaved samples. */
841 int bytewidth ; /* Size in bytes of one sample (one channel). */
843 void *dither ;
844 void *interleave ;
846 int last_op ; /* Last operation; either SFM_READ or SFM_WRITE */
847 sf_count_t read_current ;
848 sf_count_t write_current ;
850 void *fdata ; /* This is a pointer to dynamically allocated file format
851 ** specific data.
854 SF_DITHER_INFO write_dither ;
855 SF_DITHER_INFO read_dither ;
857 int norm_double ;
858 int norm_float ;
860 int auto_header ;
862 int ieee_replace ;
863 /* A set of file specific function pointers */
865 sf_count_t (*read_short) (struct sf_private_tag*, short *ptr, sf_count_t len) ;
866 sf_count_t (*read_int) (struct sf_private_tag*, int *ptr, sf_count_t len) ;
867 sf_count_t (*read_float) (struct sf_private_tag*, float *ptr, sf_count_t len) ;
868 sf_count_t (*read_double) (struct sf_private_tag*, double *ptr, sf_count_t len) ;
870 sf_count_t (*write_short) (struct sf_private_tag*, short *ptr, sf_count_t len) ;
871 sf_count_t (*write_int) (struct sf_private_tag*, int *ptr, sf_count_t len) ;
872 sf_count_t (*write_float) (struct sf_private_tag*, float *ptr, sf_count_t len) ;
873 sf_count_t (*write_double) (struct sf_private_tag*, double *ptr, sf_count_t len) ;
875 sf_count_t (*seek) (struct sf_private_tag*, int mode, sf_count_t samples_from_start) ;
876 int (*write_header) (struct sf_private_tag*, int calc_length) ;
877 int (*command) (struct sf_private_tag*, int command, void *data, int datasize) ;
878 int (*close) (struct sf_private_tag*) ;
880 char *format_desc ;
881 } SF_PRIVATE ;
885 enum
886 { SFE_NO_ERROR = SF_ERR_NO_ERROR,
887 SFE_BAD_OPEN_FORMAT = SF_ERR_UNRECOGNISED_FORMAT,
888 SFE_SYSTEM = SF_ERR_SYSTEM,
890 SFE_BAD_FILE,
891 SFE_BAD_FILE_READ,
892 SFE_OPEN_FAILED,
893 SFE_BAD_SNDFILE_PTR,
894 SFE_BAD_SF_INFO_PTR,
895 SFE_BAD_SF_INCOMPLETE,
896 SFE_BAD_FILE_PTR,
897 SFE_BAD_INT_PTR,
898 SFE_BAD_STAT_SIZE,
899 SFE_MALLOC_FAILED,
900 SFE_UNIMPLEMENTED,
901 SFE_BAD_READ_ALIGN,
902 SFE_BAD_WRITE_ALIGN,
903 SFE_UNKNOWN_FORMAT,
904 SFE_NOT_READMODE,
905 SFE_NOT_WRITEMODE,
906 SFE_BAD_MODE_RW,
907 SFE_BAD_SF_INFO,
908 SFE_BAD_OFFSET,
909 SFE_NO_EMBED_SUPPORT,
910 SFE_NO_EMBEDDED_RDWR,
911 SFE_NO_PIPE_WRITE,
913 SFE_INTERNAL,
914 SFE_LOG_OVERRUN,
915 SFE_BAD_CONTROL_CMD,
916 SFE_BAD_ENDIAN,
917 SFE_CHANNEL_COUNT,
918 SFE_BAD_RDWR_FORMAT,
920 SFE_INTERLEAVE_MODE,
921 SFE_INTERLEAVE_SEEK,
922 SFE_INTERLEAVE_READ,
924 SFE_BAD_SEEK,
925 SFE_NOT_SEEKABLE,
926 SFE_AMBIGUOUS_SEEK,
927 SFE_WRONG_SEEK,
928 SFE_SEEK_FAILED,
930 SFE_BAD_OPEN_MODE,
931 SFE_OPEN_PIPE_RDWR,
932 SFE_RDWR_POSITION,
934 SFE_STR_NO_SUPPORT,
935 SFE_STR_MAX_DATA,
936 SFE_STR_MAX_COUNT,
937 SFE_STR_BAD_TYPE,
938 SFE_STR_NO_ADD_END,
939 SFE_STR_BAD_STRING,
940 SFE_STR_WEIRD,
941 SFE_RDWR_BAD_HEADER,
943 SFE_WAV_NO_RIFF,
944 SFE_WAV_NO_WAVE,
945 SFE_WAV_NO_FMT,
946 SFE_WAV_FMT_SHORT,
947 SFE_WAV_FMT_TOO_BIG,
948 SFE_WAV_BAD_FACT,
949 SFE_WAV_BAD_PEAK,
950 SFE_WAV_PEAK_B4_FMT,
951 SFE_WAV_BAD_FORMAT,
952 SFE_WAV_BAD_BLOCKALIGN,
953 SFE_WAV_NO_DATA,
954 SFE_WAV_ADPCM_NOT4BIT,
955 SFE_WAV_ADPCM_CHANNELS,
956 SFE_WAV_GSM610_FORMAT,
957 SFE_WAV_UNKNOWN_CHUNK,
958 SFE_WAV_WVPK_DATA,
960 SFE_AIFF_NO_FORM,
961 SFE_AIFF_AIFF_NO_FORM,
962 SFE_AIFF_COMM_NO_FORM,
963 SFE_AIFF_SSND_NO_COMM,
964 SFE_AIFF_UNKNOWN_CHUNK,
965 SFE_AIFF_COMM_CHUNK_SIZE,
966 SFE_AIFF_BAD_COMM_CHUNK,
967 SFE_AIFF_PEAK_B4_COMM,
968 SFE_AIFF_BAD_PEAK,
969 SFE_AIFF_NO_SSND,
970 SFE_AIFF_NO_DATA,
971 SFE_AIFF_RW_SSND_NOT_LAST,
973 SFE_AU_UNKNOWN_FORMAT,
974 SFE_AU_NO_DOTSND,
975 SFE_AU_EMBED_BAD_LEN,
977 SFE_RAW_READ_BAD_SPEC,
978 SFE_RAW_BAD_BITWIDTH,
979 SFE_RAW_BAD_FORMAT,
981 SFE_PAF_NO_MARKER,
982 SFE_PAF_VERSION,
983 SFE_PAF_UNKNOWN_FORMAT,
984 SFE_PAF_SHORT_HEADER,
986 SFE_SVX_NO_FORM,
987 SFE_SVX_NO_BODY,
988 SFE_SVX_NO_DATA,
989 SFE_SVX_BAD_COMP,
990 SFE_SVX_BAD_NAME_LENGTH,
992 SFE_NIST_BAD_HEADER,
993 SFE_NIST_CRLF_CONVERISON,
994 SFE_NIST_BAD_ENCODING,
996 SFE_VOC_NO_CREATIVE,
997 SFE_VOC_BAD_FORMAT,
998 SFE_VOC_BAD_VERSION,
999 SFE_VOC_BAD_MARKER,
1000 SFE_VOC_BAD_SECTIONS,
1001 SFE_VOC_MULTI_SAMPLERATE,
1002 SFE_VOC_MULTI_SECTION,
1003 SFE_VOC_MULTI_PARAM,
1004 SFE_VOC_SECTION_COUNT,
1005 SFE_VOC_NO_PIPE,
1007 SFE_IRCAM_NO_MARKER,
1008 SFE_IRCAM_BAD_CHANNELS,
1009 SFE_IRCAM_UNKNOWN_FORMAT,
1011 SFE_W64_64_BIT,
1012 SFE_W64_NO_RIFF,
1013 SFE_W64_NO_WAVE,
1014 SFE_W64_NO_FMT,
1015 SFE_W64_NO_DATA,
1016 SFE_W64_FMT_SHORT,
1017 SFE_W64_FMT_TOO_BIG,
1018 SFE_W64_ADPCM_NOT4BIT,
1019 SFE_W64_ADPCM_CHANNELS,
1020 SFE_W64_GSM610_FORMAT,
1022 SFE_MAT4_BAD_NAME,
1023 SFE_MAT4_NO_SAMPLERATE,
1024 SFE_MAT4_ZERO_CHANNELS,
1026 SFE_MAT5_BAD_ENDIAN,
1027 SFE_MAT5_NO_BLOCK,
1028 SFE_MAT5_SAMPLE_RATE,
1029 SFE_MAT5_ZERO_CHANNELS,
1031 SFE_PVF_NO_PVF1,
1032 SFE_PVF_BAD_HEADER,
1033 SFE_PVF_BAD_BITWIDTH,
1035 SFE_DWVW_BAD_BITWIDTH,
1036 SFE_G72X_NOT_MONO,
1038 SFE_XI_BAD_HEADER,
1039 SFE_XI_EXCESS_SAMPLES,
1040 SFE_XI_NO_PIPE,
1042 SFE_HTK_NO_PIPE,
1044 SFE_SDS_NOT_SDS,
1045 SFE_SDS_BAD_BIT_WIDTH,
1047 SFE_MAX_ERROR /* This must be last in list. */
1050 int subformat_to_bytewidth (int format) ;
1051 int s_bitwidth_to_subformat (int bits) ;
1052 int u_bitwidth_to_subformat (int bits) ;
1054 /* Functions for reading and writing floats and doubles on processors
1055 ** with non-IEEE floats/doubles.
1057 float float32_be_read (unsigned char *cptr) ;
1058 float float32_le_read (unsigned char *cptr) ;
1059 void float32_be_write (float in, unsigned char *out) ;
1060 void float32_le_write (float in, unsigned char *out) ;
1062 double double64_be_read (unsigned char *cptr) ;
1063 double double64_le_read (unsigned char *cptr) ;
1064 void double64_be_write (double in, unsigned char *out) ;
1065 void double64_le_write (double in, unsigned char *out) ;
1067 /* Functions for writing to the internal logging buffer. */
1069 void psf_log_printf (SF_PRIVATE *psf, const char *format, ...) ;
1070 void psf_log_SF_INFO (SF_PRIVATE *psf) ;
1072 void psf_hexdump (void *ptr, int len) ;
1074 /* Functions used when writing file headers. */
1076 int psf_binheader_writef (SF_PRIVATE *psf, const char *format, ...) ;
1077 void psf_asciiheader_printf (SF_PRIVATE *psf, const char *format, ...) ;
1079 /* Functions used when reading file headers. */
1081 int psf_binheader_readf (SF_PRIVATE *psf, char const *format, ...) ;
1083 /* Functions used in the write function for updating the peak chunk. */
1085 void peak_update_short (SF_PRIVATE *psf, short *ptr, size_t items) ;
1086 void peak_update_int (SF_PRIVATE *psf, int *ptr, size_t items) ;
1087 void peak_update_double (SF_PRIVATE *psf, double *ptr, size_t items) ;
1089 /* Functions defined in command.c. */
1091 int psf_get_format_simple_count (void) ;
1092 int psf_get_format_simple (SF_FORMAT_INFO *data) ;
1094 int psf_get_format_info (SF_FORMAT_INFO *data) ;
1096 int psf_get_format_major_count (void) ;
1097 int psf_get_format_major (SF_FORMAT_INFO *data) ;
1099 int psf_get_format_subtype_count (void) ;
1100 int psf_get_format_subtype (SF_FORMAT_INFO *data) ;
1102 void psf_generate_format_desc (SF_PRIVATE *psf) ;
1104 double psf_calc_signal_max (SF_PRIVATE *psf, int normalize) ;
1105 int psf_calc_max_all_channels (SF_PRIVATE *psf, double *peaks, int normalize) ;
1107 /* Functions in strings.c. */
1109 const char* psf_get_string (SF_PRIVATE *psf, int str_type) ;
1110 int psf_store_string (SF_PRIVATE *psf, int str_type, const char *str) ;
1112 /* Default seek function. Use for PCM and float encoded data. */
1113 sf_count_t psf_default_seek (SF_PRIVATE *psf, int mode, sf_count_t samples_from_start) ;
1115 /* Generate the currebt date as a string. */
1116 void psf_get_date_str (char *str, int maxlen) ;
1118 int macos_guess_file_type (SF_PRIVATE *psf, const char *filename) ;
1120 /*------------------------------------------------------------------------------------
1121 ** File I/O functions which will allow access to large files (> 2 Gig) on
1122 ** some 32 bit OSes. Implementation in file_io.c.
1125 int psf_fopen (SF_PRIVATE *psf, const char *pathname, int flags) ;
1126 int psf_set_stdio (SF_PRIVATE *psf, int mode) ;
1127 int psf_filedes_valid (SF_PRIVATE *psf) ;
1128 void psf_set_file (SF_PRIVATE *psf, int fd) ;
1130 sf_count_t psf_fseek (SF_PRIVATE *psf, sf_count_t offset, int whence) ;
1131 sf_count_t psf_fread (void *ptr, sf_count_t bytes, sf_count_t count, SF_PRIVATE *psf) ;
1132 sf_count_t psf_fwrite (void *ptr, sf_count_t bytes, sf_count_t count, SF_PRIVATE *psf) ;
1133 sf_count_t psf_fgets (char *buffer, sf_count_t bufsize, SF_PRIVATE *psf) ;
1134 sf_count_t psf_ftell (SF_PRIVATE *psf) ;
1135 sf_count_t psf_get_filelen (SF_PRIVATE *psf) ;
1137 int psf_is_pipe (SF_PRIVATE *psf) ;
1139 int psf_ftruncate (SF_PRIVATE *psf, sf_count_t len) ;
1140 int psf_fclose (SF_PRIVATE *psf) ;
1143 void psf_fclearerr (SF_PRIVATE *psf) ;
1144 int psf_ferror (SF_PRIVATE *psf) ;
1147 /*------------------------------------------------------------------------------------
1148 ** Functions for reading and writing different file formats.
1151 int aiff_open (SF_PRIVATE *psf) ;
1152 int au_open (SF_PRIVATE *psf) ;
1153 int au_nh_open (SF_PRIVATE *psf) ; /* Headerless version of AU. */
1154 int avr_open (SF_PRIVATE *psf) ;
1155 int htk_open (SF_PRIVATE *psf) ;
1156 int ircam_open (SF_PRIVATE *psf) ;
1157 int mat4_open (SF_PRIVATE *psf) ;
1158 int mat5_open (SF_PRIVATE *psf) ;
1159 int nist_open (SF_PRIVATE *psf) ;
1160 int paf_open (SF_PRIVATE *psf) ;
1161 int pvf_open (SF_PRIVATE *psf) ;
1162 int raw_open (SF_PRIVATE *psf) ;
1163 int sds_open (SF_PRIVATE *psf) ;
1164 int svx_open (SF_PRIVATE *psf) ;
1165 int voc_open (SF_PRIVATE *psf) ;
1166 int w64_open (SF_PRIVATE *psf) ;
1167 int wav_open (SF_PRIVATE *psf) ;
1168 int xi_open (SF_PRIVATE *psf) ;
1170 /* In progress. Do not currently work. */
1172 int ogg_open (SF_PRIVATE *psf) ;
1173 int rx2_open (SF_PRIVATE *psf) ;
1174 int sd2_open (SF_PRIVATE *psf) ;
1175 int txw_open (SF_PRIVATE *psf) ;
1176 int wve_open (SF_PRIVATE *psf) ;
1177 int dwd_open (SF_PRIVATE *psf) ;
1179 int macbinary3_open (SF_PRIVATE *psf) ;
1181 /*------------------------------------------------------------------------------------
1182 ** Init functions for a number of common data encodings.
1185 int pcm_init (SF_PRIVATE *psf) ;
1186 int ulaw_init (SF_PRIVATE *psf) ;
1187 int alaw_init (SF_PRIVATE *psf) ;
1188 int float32_init (SF_PRIVATE *psf) ;
1189 int double64_init (SF_PRIVATE *psf) ;
1190 int dwvw_init (SF_PRIVATE *psf, int bitwidth) ;
1191 int gsm610_init (SF_PRIVATE *psf) ;
1192 int vox_adpcm_init (SF_PRIVATE *psf) ;
1194 int dither_init (SF_PRIVATE *psf, int mode) ;
1196 int wav_w64_ima_init (SF_PRIVATE *psf, int blockalign, int samplesperblock) ;
1197 int wav_w64_msadpcm_init (SF_PRIVATE *psf, int blockalign, int samplesperblock) ;
1199 int aiff_ima_init (SF_PRIVATE *psf, int blockalign, int samplesperblock) ;
1201 int interleave_init (SF_PRIVATE *psf) ;
1203 /*------------------------------------------------------------------------------------
1204 ** Other helper functions.
1207 void *psf_memset (void *s, int c, sf_count_t n) ;
1209 /*------------------------------------------------------------------------------------
1210 ** Here's how we fix systems which don't snprintf / vsnprintf.
1211 ** Systems without these functions should use the
1214 #if (defined (WIN32) || defined (_WIN32))
1215 #define LSF_SNPRINTF _snprintf
1217 #define snprintf _snprintf //XXX really?
1218 #elif (HAVE_SNPRINTF && ! FORCE_MISSING_SNPRINTF)
1219 #define LSF_SNPRINTF snprintf
1220 #else
1221 int missing_snprintf (char *str, size_t n, char const *fmt, ...) ;
1222 #define LSF_SNPRINTF missing_snprintf
1223 #endif
1225 #if (defined (WIN32) || defined (_WIN32))
1226 #define LSF_VSNPRINTF _vsnprintf
1227 #elif (HAVE_VSNPRINTF && ! FORCE_MISSING_SNPRINTF)
1228 #define LSF_VSNPRINTF vsnprintf
1229 #else
1230 int missing_vsnprintf (char *str, size_t n, const char *fmt, ...) ;
1231 #define LSF_VSNPRINTF missing_vsnprintf
1232 #endif
1234 #endif /* COMMON_H_INCLUDED */
1236 /*------------------------------------------------------------------------------------
1237 ** Extra commands for sf_command(). Not for public use yet.
1240 enum
1241 { SFC_TEST_AIFF_ADD_INST_CHUNK = 0x2000,
1242 SFC_TEST_WAV_ADD_INFO_CHUNK = 0x2010
1246 ** Maybe, one day, make these functions or something like them, public.
1248 ** Buffer to buffer dithering. Pointer in and out are allowed to point
1249 ** to the same buffer for in-place dithering.
1252 #if 0
1253 int sf_dither_short (const SF_DITHER_INFO *dither, const short *in, short *out, int count) ;
1254 int sf_dither_int (const SF_DITHER_INFO *dither, const int *in, int *out, int count) ;
1255 int sf_dither_float (const SF_DITHER_INFO *dither, const float *in, float *out, int count) ;
1256 int sf_dither_double (const SF_DITHER_INFO *dither, const double *in, double *out, int count) ;
1257 #endif
1259 ** Do not edit or modify anything in this comment block.
1260 ** The arch-tag line is a file identity tag for the GNU Arch
1261 ** revision control system.
1263 ** arch-tag: 7b45c0ee-5835-4a18-a4ef-994e4cd95b67
1266 ** Copyright (C) 1999-2001 Erik de Castro Lopo <erikd@mega-nerd.com>
1268 ** This program is free software; you can redistribute it and/or modify
1269 ** it under the terms of the GNU Lesser General Public License as published by
1270 ** the Free Software Foundation; either version 2.1 of the License, or
1271 ** (at your option) any later version.
1273 ** This program is distributed in the hope that it will be useful,
1274 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
1275 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1276 ** GNU Lesser General Public License for more details.
1278 ** You should have received a copy of the GNU Lesser General Public License
1279 ** along with this program; if not, write to the Free Software
1280 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1284 ** This file is not the same as the original file from Sun Microsystems. Nearly
1285 ** all the original definitions and function prototypes that were in the file
1286 ** of this name have been moved to private.h.
1289 #ifndef G72X_HEADER_FILE
1290 #define G72X_HEADER_FILE
1293 ** Number of samples per block to process.
1294 ** Must be a common multiple of possible bits per sample : 2, 3, 4, 5 and 8.
1296 #define G72x_BLOCK_SIZE (3*5*8)
1299 ** Identifiers for the differing kinds of G72x ADPCM codecs.
1300 ** The identifiers also define the number of encoded bits per sample.
1303 enum
1304 { G723_16_BITS_PER_SAMPLE = 2,
1305 G723_24_BITS_PER_SAMPLE = 3,
1306 G723_40_BITS_PER_SAMPLE = 5,
1308 G721_32_BITS_PER_SAMPLE = 4,
1309 G721_40_BITS_PER_SAMPLE = 5,
1311 G723_16_SAMPLES_PER_BLOCK = G72x_BLOCK_SIZE,
1312 G723_24_SAMPLES_PER_BLOCK = G723_24_BITS_PER_SAMPLE * (G72x_BLOCK_SIZE / G723_24_BITS_PER_SAMPLE),
1313 G723_40_SAMPLES_PER_BLOCK = G723_40_BITS_PER_SAMPLE * (G72x_BLOCK_SIZE / G723_40_BITS_PER_SAMPLE),
1315 G721_32_SAMPLES_PER_BLOCK = G72x_BLOCK_SIZE,
1316 G721_40_SAMPLES_PER_BLOCK = G721_40_BITS_PER_SAMPLE * (G72x_BLOCK_SIZE / G721_40_BITS_PER_SAMPLE),
1318 G723_16_BYTES_PER_BLOCK = (G723_16_BITS_PER_SAMPLE * G72x_BLOCK_SIZE) / 8,
1319 G723_24_BYTES_PER_BLOCK = (G723_24_BITS_PER_SAMPLE * G72x_BLOCK_SIZE) / 8,
1320 G723_40_BYTES_PER_BLOCK = (G723_40_BITS_PER_SAMPLE * G72x_BLOCK_SIZE) / 8,
1322 G721_32_BYTES_PER_BLOCK = (G721_32_BITS_PER_SAMPLE * G72x_BLOCK_SIZE) / 8,
1323 G721_40_BYTES_PER_BLOCK = (G721_40_BITS_PER_SAMPLE * G72x_BLOCK_SIZE) / 8
1324 } ;
1327 ** This is the public structure for passing data between the caller and
1328 ** the G72x encoder and decoder.
1329 ** The private array is used by the encoder and decoder for internal
1330 ** state information and should not be changed in any way by the caller.
1331 ** When decoding or encoding a stream, the same instance of this struct
1332 ** should be used for every call so that the decoder/encoder keeps the
1333 ** correct state data between calls.
1336 typedef struct
1337 { /* Private data. Don't mess with it. */
1338 unsigned long sprivateo [256 / sizeof (long)] ;
1340 /* Public data. Read only. */
1341 int blocksize, max_bytes, samplesperblock, bytesperblock ;
1343 /* Public data. Read and write. */
1344 int blocks, blockcount, samplecount ;
1345 unsigned char block [G72x_BLOCK_SIZE] ;
1346 short samples [G72x_BLOCK_SIZE] ;
1347 } G72x_DATA ;
1349 /* External function definitions. */
1351 int g72x_reader_init (G72x_DATA *data, int codec) ;
1352 int g72x_writer_init (G72x_DATA *data, int codec) ;
1354 ** Initialize the ADPCM state table for the given codec.
1355 ** Return 0 on success, 1 on fail.
1358 int g72x_decode_block (G72x_DATA *data) ;
1360 ** The caller fills data->block with data->bytes bytes before calling the
1361 ** function. The value data->bytes must be an integer multiple of
1362 ** data->blocksize and be <= data->max_bytes.
1363 ** When it returns, the caller can read out data->samples samples.
1366 int g72x_encode_block (G72x_DATA *data) ;
1368 ** The caller fills state->samples some integer multiple data->samples_per_block
1369 ** (up to G72x_BLOCK_SIZE) samples before calling the function.
1370 ** When it returns, the caller can read out bytes encoded bytes.
1373 #endif /* !G72X_HEADER_FILE */
1375 ** Do not edit or modify anything in this comment block.
1376 ** The arch-tag line is a file identity tag for the GNU Arch
1377 ** revision control system.
1379 ** arch-tag: 6ca84e5f-f932-4ba1-87ee-37056d921621
1383 * This source code is a product of Sun Microsystems, Inc. and is provided
1384 * for unrestricted use. Users may copy or modify this source code without
1385 * charge.
1387 * SUN SOURCE CODE IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING
1388 * THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
1389 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
1391 * Sun source code is provided with no support and without any obligation on
1392 * the part of Sun Microsystems, Inc. to assist in its use, correction,
1393 * modification or enhancement.
1395 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
1396 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THIS SOFTWARE
1397 * OR ANY PART THEREOF.
1399 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
1400 * or profits or other special, indirect and consequential damages, even if
1401 * Sun has been advised of the possibility of such damages.
1403 * Sun Microsystems, Inc.
1404 * 2550 Garcia Avenue
1405 * Mountain View, California 94043
1408 #ifndef G72X_PRIVATE_H
1409 #define G72X_PRIVATE_H
1413 ** The following is the definition of the state structure used by the
1414 ** G.721/G.723 encoder and decoder to preserve their internal state
1415 ** between successive calls. The meanings of the majority of the state
1416 ** structure fields are explained in detail in the CCITT Recommendation
1417 ** G.721. The field names are essentially identical to variable names
1418 ** in the bit level description of the coding algorithm included in this
1419 ** Recommendation.
1422 typedef struct private_g72x
1423 { long yl; /* Locked or steady state step size multiplier. */
1424 short yu; /* Unlocked or non-steady state step size multiplier. */
1425 short dms; /* Short term energy estimate. */
1426 short dml; /* Long term energy estimate. */
1427 short ap; /* Linear weighting coefficient of 'yl' and 'yu'. */
1429 short a[2]; /* Coefficients of pole portion of prediction filter. */
1430 short b[6]; /* Coefficients of zero portion of prediction filter. */
1431 short pk[2]; /*
1432 ** Signs of previous two samples of a partially
1433 ** reconstructed signal.
1435 short dq[6]; /*
1436 ** Previous 6 samples of the quantized difference
1437 ** signal represented in an internal floating point
1438 ** format.
1440 short sr[2]; /*
1441 ** Previous 2 samples of the quantized difference
1442 ** signal represented in an internal floating point
1443 ** format.
1445 char td; /* delayed tone detect, new in 1988 version */
1447 /* The following struct members were added for libsndfile. The original
1448 ** code worked by calling a set of functions on a sample by sample basis
1449 ** which is slow on architectures like Intel x86. For libsndfile, this
1450 ** was changed so that the encoding and decoding routines could work on
1451 ** a block of samples at a time to reduce the function call overhead.
1453 int (*encoder) (int, struct private_g72x* state) ;
1454 int (*decoder) (int, struct private_g72x* state) ;
1456 int codec_bits ;
1457 int byte_index, sample_index ;
1459 } G72x_STATE ;
1463 int predictor_zero (G72x_STATE *state_ptr);
1465 int predictor_pole (G72x_STATE *state_ptr);
1467 int step_size (G72x_STATE *state_ptr);
1469 int quantize (int d, int y, short *table, int size);
1471 int reconstruct (int sign, int dqln, int y);
1473 void update (int code_size, int y, int wi, int fi, int dq, int sr, int dqsez, G72x_STATE *state_ptr);
1475 int g721_encoder (int sample, G72x_STATE *state_ptr);
1476 int g721_decoder (int code, G72x_STATE *state_ptr);
1478 int g723_16_encoder (int sample, G72x_STATE *state_ptr);
1479 int g723_16_decoder (int code, G72x_STATE *state_ptr);
1481 int g723_24_encoder (int sample, G72x_STATE *state_ptr);
1482 int g723_24_decoder (int code, G72x_STATE *state_ptr);
1484 int g723_40_encoder (int sample, G72x_STATE *state_ptr);
1485 int g723_40_decoder (int code, G72x_STATE *state_ptr);
1487 int unpack_bytes (G72x_DATA *data, int bits) ;
1488 int pack_bytes (G72x_DATA *data, int bits) ;
1490 void private_init_state (G72x_STATE *state_ptr) ;
1492 #endif /* G72X_PRIVATE_H */
1494 ** Do not edit or modify anything in this comment block.
1495 ** The arch-tag line is a file identity tag for the GNU Arch
1496 ** revision control system.
1498 ** arch-tag: d9ad4da7-0fa3-471d-8020-720b5cfb5e5b
1502 ** Copyright (C) 1999-2004 Erik de Castro Lopo <erikd@mega-nerd.com>
1504 ** This program is free software; you can redistribute it and/or modify
1505 ** it under the terms of the GNU Lesser General Public License as published by
1506 ** the Free Software Foundation; either version 2.1 of the License, or
1507 ** (at your option) any later version.
1509 ** This program is distributed in the hope that it will be useful,
1510 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
1511 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1512 ** GNU Lesser General Public License for more details.
1514 ** You should have received a copy of the GNU Lesser General Public License
1515 ** along with this program; if not, write to the Free Software
1516 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1521 ** Many file types (ie WAV, AIFF) use sets of four consecutive bytes as a
1522 ** marker indicating different sections of the file.
1523 ** The following MAKE_MARKER macro allows th creation of integer constants
1524 ** for these markers.
1527 #if (CPU_IS_LITTLE_ENDIAN == 1)
1528 #define MAKE_MARKER(a,b,c,d) ((a)|((b)<<8)|((c)<<16)|((d)<<24))
1529 #elif (CPU_IS_BIG_ENDIAN == 1)
1530 #define MAKE_MARKER(a,b,c,d) (((a)<<24)|((b)<<16)|((c)<<8)|(d))
1531 #else
1532 #error "Target CPU endian-ness unknown. May need to hand edit src/config.h"
1533 #endif
1535 /* wo standard endswap macros. */
1537 #define ENDSWAP_SHORT(x) ((((x)>>8)&0xFF)+(((x)&0xFF)<<8))
1538 #define ENDSWAP_INT(x) ((((x)>>24)&0xFF)+(((x)>>8)&0xFF00)+(((x)&0xFF00)<<8)+(((x)&0xFF)<<24))
1540 ** Macros to handle reading of data of a specific endian-ness into host endian
1541 ** shorts and ints. The single input is an unsigned char* pointer to the start
1542 ** of the object. There are two versions of each macro as we need to deal with
1543 ** both big and little endian CPUs.
1546 #if (CPU_IS_LITTLE_ENDIAN == 1)
1547 #define LES2H_SHORT(x) (x)
1548 #define LEI2H_INT(x) (x)
1550 #define BES2H_SHORT(x) ENDSWAP_SHORT(x)
1551 #define BEI2H_INT(x) ENDSWAP_INT(x)
1553 #elif (CPU_IS_BIG_ENDIAN == 1)
1554 #define LES2H_SHORT(x) ENDSWAP_SHORT(x)
1555 #define LEI2H_INT(x) ENDSWAP_INT(x)
1557 #define BES2H_SHORT(x) (x)
1558 #define BEI2H_INT(x) (x)
1560 #else
1561 #error "Target CPU endian-ness unknown. May need to hand edit src/config.h"
1562 #endif
1564 #define LES2H_SHORT_PTR(x) ((x) [0] + ((x) [1] << 8))
1565 #define LES2H_INT_PTR(x) (((x) [0] << 16) + ((x) [1] << 24))
1567 #define LET2H_SHORT_PTR(x) ((x) [1] + ((x) [2] << 8))
1568 #define LET2H_INT_PTR(x) (((x) [0] << 8) + ((x) [1] << 16) + ((x) [2] << 24))
1570 #define LEI2H_SHORT_PTR(x) ((x) [2] + ((x) [3] << 8))
1571 #define LEI2H_INT_PTR(x) ((x) [0] + ((x) [1] << 8) + ((x) [2] << 16) + ((x) [3] << 24))
1573 #define BES2H_SHORT_PTR(x) (((x) [0] << 8) + (x) [1])
1574 #define BES2H_INT_PTR(x) (((x) [0] << 24) + ((x) [1] << 16))
1576 #define BET2H_SHORT_PTR(x) (((x) [0] << 8) + (x) [1])
1577 #define BET2H_INT_PTR(x) (((x) [0] << 24) + ((x) [1] << 16) + ((x) [2] << 8))
1579 #define BEI2H_SHORT_PTR(x) (((x) [0] << 8) + (x) [1])
1580 #define BEI2H_INT_PTR(x) (((x) [0] << 24) + ((x) [1] << 16) + ((x) [2] << 8) + (x) [3])
1582 /* Endian swapping routines implemented in sfendian.c. */
1584 void endswap_short_array (short *ptr, int len) ;
1585 void endswap_int_array (int *ptr, int len) ;
1587 /* Always swaps 8 byte values whether sizeof (long) == 8 or not. */
1588 void endswap_long_array (long *ptr, int len) ;
1590 void endswap_short_copy (short *dest, short *src, int len) ;
1591 void endswap_int_copy (int *dest, int *src, int len) ;
1593 /* Always swaps 8 byte values whether sizeof (long) == 8 or not. */
1594 void endswap_long_copy (long *dest, long *src, int len) ;
1597 ** Do not edit or modify anything in this comment block.
1598 ** The arch-tag line is a file identity tag for the GNU Arch
1599 ** revision control system.
1601 ** arch-tag: f0c5cd54-42d3-4237-90ec-11fe24995de7
1604 * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
1605 * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
1606 * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
1609 #ifndef GSM_H
1610 #define GSM_H
1614 * Interface
1617 typedef struct gsm_state * gsm;
1618 typedef short gsm_signal; /* signed 16 bit */
1619 typedef unsigned char gsm_byte;
1620 typedef gsm_byte gsm_frame[33]; /* 33 * 8 bits */
1622 #define GSM_MAGIC 0xD /* 13 kbit/s RPE-LTP */
1624 #define GSM_PATCHLEVEL 10
1625 #define GSM_MINOR 0
1626 #define GSM_MAJOR 1
1628 #define GSM_OPT_VERBOSE 1
1629 #define GSM_OPT_FAST 2
1630 #define GSM_OPT_LTP_CUT 3
1631 #define GSM_OPT_WAV49 4
1632 #define GSM_OPT_FRAME_INDEX 5
1633 #define GSM_OPT_FRAME_CHAIN 6
1635 gsm gsm_create (void);
1637 /* Added for libsndfile : May 6, 2002 */
1638 void gsm_init (gsm);
1640 void gsm_destroy (gsm);
1642 int gsm_print (FILE *, gsm, gsm_byte *);
1643 int gsm_option (gsm, int, int *);
1645 void gsm_encode (gsm, gsm_signal *, gsm_byte *);
1646 int gsm_decode (gsm, gsm_byte *, gsm_signal *);
1648 int gsm_explode (gsm, gsm_byte *, gsm_signal *);
1649 void gsm_implode (gsm, gsm_signal *, gsm_byte *);
1651 #endif /* GSM_H */
1653 ** Do not edit or modify anything in this comment block.
1654 ** The arch-tag line is a file identity tag for the GNU Arch
1655 ** revision control system.
1657 ** arch-tag: 8cfc7698-5433-4b6f-aeca-967c6fda4dec
1661 ** Copyright (C) 1999-2004 Erik de Castro Lopo <erikd@mega-nerd.com>
1663 ** This program is free software; you can redistribute it and/or modify
1664 ** it under the terms of the GNU Lesser General Public License as published by
1665 ** the Free Software Foundation; either version 2.1 of the License, or
1666 ** (at your option) any later version.
1668 ** This program is distributed in the hope that it will be useful,
1669 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
1670 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1671 ** GNU Lesser General Public License for more details.
1673 ** You should have received a copy of the GNU Lesser General Public License
1674 ** along with this program; if not, write to the Free Software
1675 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1678 #ifndef AU_HEADER_FILE
1679 #define AU_HEADER_FILE
1682 enum
1683 { AU_H_G721_32 = 200,
1684 AU_H_G723_24 = 201,
1685 AU_H_G723_40 = 202
1688 int au_g72x_reader_init (SF_PRIVATE *psf, int codec) ;
1689 int au_g72x_writer_init (SF_PRIVATE *psf, int codec) ;
1691 #endif /* AU_HEADER_FILE */
1693 ** Do not edit or modify anything in this comment block.
1694 ** The arch-tag line is a file identity tag for the GNU Arch
1695 ** revision control system.
1697 ** arch-tag: 63affc81-e204-4468-9705-60abe4d10689
1700 ** Copyright (C) 1999-2004 Erik de Castro Lopo <erikd@mega-nerd.com>
1702 ** This program is free software; you can redistribute it and/or modify
1703 ** it under the terms of the GNU Lesser General Public License as published by
1704 ** the Free Software Foundation; either version 2.1 of the License, or
1705 ** (at your option) any later version.
1707 ** This program is distributed in the hope that it will be useful,
1708 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
1709 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1710 ** GNU Lesser General Public License for more details.
1712 ** You should have received a copy of the GNU Lesser General Public License
1713 ** along with this program; if not, write to the Free Software
1714 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1717 /* This file contains definitions commong to WAV and W64 files. */
1720 #ifndef WAV_W64_H_INCLUDED
1721 #define WAV_W64_H_INCLUDED
1723 /*------------------------------------------------------------------------------
1724 ** List of known WAV format tags
1727 enum
1729 /* keep sorted for wav_w64_format_str() */
1730 WAVE_FORMAT_UNKNOWN = 0x0000, /* Microsoft Corporation */
1731 WAVE_FORMAT_PCM = 0x0001, /* Microsoft PCM format */
1732 WAVE_FORMAT_MS_ADPCM = 0x0002, /* Microsoft ADPCM */
1733 WAVE_FORMAT_IEEE_FLOAT = 0x0003, /* Micrososft 32 bit float format */
1734 WAVE_FORMAT_VSELP = 0x0004, /* Compaq Computer Corporation */
1735 WAVE_FORMAT_IBM_CVSD = 0x0005, /* IBM Corporation */
1736 WAVE_FORMAT_ALAW = 0x0006, /* Microsoft Corporation */
1737 WAVE_FORMAT_MULAW = 0x0007, /* Microsoft Corporation */
1738 WAVE_FORMAT_OKI_ADPCM = 0x0010, /* OKI */
1739 WAVE_FORMAT_IMA_ADPCM = 0x0011, /* Intel Corporation */
1740 WAVE_FORMAT_MEDIASPACE_ADPCM = 0x0012, /* Videologic */
1741 WAVE_FORMAT_SIERRA_ADPCM = 0x0013, /* Sierra Semiconductor Corp */
1742 WAVE_FORMAT_G723_ADPCM = 0x0014, /* Antex Electronics Corporation */
1743 WAVE_FORMAT_DIGISTD = 0x0015, /* DSP Solutions, Inc. */
1744 WAVE_FORMAT_DIGIFIX = 0x0016, /* DSP Solutions, Inc. */
1745 WAVE_FORMAT_DIALOGIC_OKI_ADPCM = 0x0017, /* Dialogic Corporation */
1746 WAVE_FORMAT_MEDIAVISION_ADPCM = 0x0018, /* Media Vision, Inc. */
1747 WAVE_FORMAT_CU_CODEC = 0x0019, /* Hewlett-Packard Company */
1748 WAVE_FORMAT_YAMAHA_ADPCM = 0x0020, /* Yamaha Corporation of America */
1749 WAVE_FORMAT_SONARC = 0x0021, /* Speech Compression */
1750 WAVE_FORMAT_DSPGROUP_TRUESPEECH = 0x0022, /* DSP Group, Inc */
1751 WAVE_FORMAT_ECHOSC1 = 0x0023, /* Echo Speech Corporation */
1752 WAVE_FORMAT_AUDIOFILE_AF36 = 0x0024, /* Audiofile, Inc. */
1753 WAVE_FORMAT_APTX = 0x0025, /* Audio Processing Technology */
1754 WAVE_FORMAT_AUDIOFILE_AF10 = 0x0026, /* Audiofile, Inc. */
1755 WAVE_FORMAT_PROSODY_1612 = 0x0027, /* Aculab plc */
1756 WAVE_FORMAT_LRC = 0x0028, /* Merging Technologies S.A. */
1757 WAVE_FORMAT_DOLBY_AC2 = 0x0030, /* Dolby Laboratories */
1758 WAVE_FORMAT_GSM610 = 0x0031, /* Microsoft Corporation */
1759 WAVE_FORMAT_MSNAUDIO = 0x0032, /* Microsoft Corporation */
1760 WAVE_FORMAT_ANTEX_ADPCME = 0x0033, /* Antex Electronics Corporation */
1761 WAVE_FORMAT_CONTROL_RES_VQLPC = 0x0034, /* Control Resources Limited */
1762 WAVE_FORMAT_DIGIREAL = 0x0035, /* DSP Solutions, Inc. */
1763 WAVE_FORMAT_DIGIADPCM = 0x0036, /* DSP Solutions, Inc. */
1764 WAVE_FORMAT_CONTROL_RES_CR10 = 0x0037, /* Control Resources Limited */
1765 WAVE_FORMAT_NMS_VBXADPCM = 0x0038, /* Natural MicroSystems */
1766 WAVE_FORMAT_ROLAND_RDAC = 0x0039, /* Roland */
1767 WAVE_FORMAT_ECHOSC3 = 0x003A, /* Echo Speech Corporation */
1768 WAVE_FORMAT_ROCKWELL_ADPCM = 0x003B, /* Rockwell International */
1769 WAVE_FORMAT_ROCKWELL_DIGITALK = 0x003C, /* Rockwell International */
1770 WAVE_FORMAT_XEBEC = 0x003D, /* Xebec Multimedia Solutions Limited */
1771 WAVE_FORMAT_G721_ADPCM = 0x0040, /* Antex Electronics Corporation */
1772 WAVE_FORMAT_G728_CELP = 0x0041, /* Antex Electronics Corporation */
1773 WAVE_FORMAT_MSG723 = 0x0042, /* Microsoft Corporation */
1774 WAVE_FORMAT_MPEG = 0x0050, /* Microsoft Corporation */
1775 WAVE_FORMAT_RT24 = 0x0052, /* InSoft Inc. */
1776 WAVE_FORMAT_PAC = 0x0053, /* InSoft Inc. */
1777 WAVE_FORMAT_MPEGLAYER3 = 0x0055, /* MPEG 3 Layer 1 */
1778 WAVE_FORMAT_LUCENT_G723 = 0x0059, /* Lucent Technologies */
1779 WAVE_FORMAT_CIRRUS = 0x0060, /* Cirrus Logic */
1780 WAVE_FORMAT_ESPCM = 0x0061, /* ESS Technology */
1781 WAVE_FORMAT_VOXWARE = 0x0062, /* Voxware Inc */
1782 WAVE_FORMAT_CANOPUS_ATRAC = 0x0063, /* Canopus, Co., Ltd. */
1783 WAVE_FORMAT_G726_ADPCM = 0x0064, /* APICOM */
1784 WAVE_FORMAT_G722_ADPCM = 0x0065, /* APICOM */
1785 WAVE_FORMAT_DSAT = 0x0066, /* Microsoft Corporation */
1786 WAVE_FORMAT_DSAT_DISPLAY = 0x0067, /* Microsoft Corporation */
1787 WAVE_FORMAT_VOXWARE_BYTE_ALIGNED = 0x0069, /* Voxware Inc. */
1788 WAVE_FORMAT_VOXWARE_AC8 = 0x0070, /* Voxware Inc. */
1789 WAVE_FORMAT_VOXWARE_AC10 = 0x0071, /* Voxware Inc. */
1790 WAVE_FORMAT_VOXWARE_AC16 = 0x0072, /* Voxware Inc. */
1791 WAVE_FORMAT_VOXWARE_AC20 = 0x0073, /* Voxware Inc. */
1792 WAVE_FORMAT_VOXWARE_RT24 = 0x0074, /* Voxware Inc. */
1793 WAVE_FORMAT_VOXWARE_RT29 = 0x0075, /* Voxware Inc. */
1794 WAVE_FORMAT_VOXWARE_RT29HW = 0x0076, /* Voxware Inc. */
1795 WAVE_FORMAT_VOXWARE_VR12 = 0x0077, /* Voxware Inc. */
1796 WAVE_FORMAT_VOXWARE_VR18 = 0x0078, /* Voxware Inc. */
1797 WAVE_FORMAT_VOXWARE_TQ40 = 0x0079, /* Voxware Inc. */
1798 WAVE_FORMAT_SOFTSOUND = 0x0080, /* Softsound, Ltd. */
1799 WAVE_FORMAT_VOXARE_TQ60 = 0x0081, /* Voxware Inc. */
1800 WAVE_FORMAT_MSRT24 = 0x0082, /* Microsoft Corporation */
1801 WAVE_FORMAT_G729A = 0x0083, /* AT&T Laboratories */
1802 WAVE_FORMAT_MVI_MV12 = 0x0084, /* Motion Pixels */
1803 WAVE_FORMAT_DF_G726 = 0x0085, /* DataFusion Systems (Pty) (Ltd) */
1804 WAVE_FORMAT_DF_GSM610 = 0x0086, /* DataFusion Systems (Pty) (Ltd) */
1805 /* removed because duplicate */
1806 /* WAVE_FORMAT_ISIAUDIO = 0x0088, */ /* Iterated Systems, Inc. */
1807 WAVE_FORMAT_ONLIVE = 0x0089, /* OnLive! Technologies, Inc. */
1808 WAVE_FORMAT_SBC24 = 0x0091, /* Siemens Business Communications Systems */
1809 WAVE_FORMAT_DOLBY_AC3_SPDIF = 0x0092, /* Sonic Foundry */
1810 WAVE_FORMAT_ZYXEL_ADPCM = 0x0097, /* ZyXEL Communications, Inc. */
1811 WAVE_FORMAT_PHILIPS_LPCBB = 0x0098, /* Philips Speech Processing */
1812 WAVE_FORMAT_PACKED = 0x0099, /* Studer Professional Audio AG */
1813 WAVE_FORMAT_RHETOREX_ADPCM = 0x0100, /* Rhetorex, Inc. */
1815 /* removed because of the following */
1816 /* WAVE_FORMAT_IRAT = 0x0101,*/ /* BeCubed Software Inc. */
1818 /* these three are unofficial */
1819 IBM_FORMAT_MULAW = 0x0101, /* IBM mu-law format */
1820 IBM_FORMAT_ALAW = 0x0102, /* IBM a-law format */
1821 IBM_FORMAT_ADPCM = 0x0103, /* IBM AVC Adaptive Differential PCM format */
1823 WAVE_FORMAT_VIVO_G723 = 0x0111, /* Vivo Software */
1824 WAVE_FORMAT_VIVO_SIREN = 0x0112, /* Vivo Software */
1825 WAVE_FORMAT_DIGITAL_G723 = 0x0123, /* Digital Equipment Corporation */
1826 WAVE_FORMAT_CREATIVE_ADPCM = 0x0200, /* Creative Labs, Inc */
1827 WAVE_FORMAT_CREATIVE_FASTSPEECH8 = 0x0202, /* Creative Labs, Inc */
1828 WAVE_FORMAT_CREATIVE_FASTSPEECH10 = 0x0203, /* Creative Labs, Inc */
1829 WAVE_FORMAT_QUARTERDECK = 0x0220, /* Quarterdeck Corporation */
1830 WAVE_FORMAT_FM_TOWNS_SND = 0x0300, /* Fujitsu Corporation */
1831 WAVE_FORMAT_BZV_DIGITAL = 0x0400, /* Brooktree Corporation */
1832 WAVE_FORMAT_VME_VMPCM = 0x0680, /* AT&T Labs, Inc. */
1833 WAVE_FORMAT_OLIGSM = 0x1000, /* Ing C. Olivetti & C., S.p.A. */
1834 WAVE_FORMAT_OLIADPCM = 0x1001, /* Ing C. Olivetti & C., S.p.A. */
1835 WAVE_FORMAT_OLICELP = 0x1002, /* Ing C. Olivetti & C., S.p.A. */
1836 WAVE_FORMAT_OLISBC = 0x1003, /* Ing C. Olivetti & C., S.p.A. */
1837 WAVE_FORMAT_OLIOPR = 0x1004, /* Ing C. Olivetti & C., S.p.A. */
1838 WAVE_FORMAT_LH_CODEC = 0x1100, /* Lernout & Hauspie */
1839 WAVE_FORMAT_NORRIS = 0x1400, /* Norris Communications, Inc. */
1840 /* removed because duplicate */
1841 /* WAVE_FORMAT_ISIAUDIO = 0x1401, */ /* AT&T Labs, Inc. */
1842 WAVE_FORMAT_SOUNDSPACE_MUSICOMPRESS = 0x1500, /* AT&T Labs, Inc. */
1843 WAVE_FORMAT_DVM = 0x2000, /* FAST Multimedia AG */
1844 WAVE_FORMAT_INTERWAV_VSC112 = 0x7150, /* ????? */
1845 WAVE_FORMAT_EXTENSIBLE = 0xFFFE
1848 typedef struct
1849 { unsigned short format ;
1850 unsigned short channels ;
1851 unsigned int samplerate ;
1852 unsigned int bytespersec ;
1853 unsigned short blockalign ;
1854 unsigned short bitwidth ;
1855 } MIN_WAV_FMT ;
1857 typedef struct
1858 { unsigned short format ;
1859 unsigned short channels ;
1860 unsigned int samplerate ;
1861 unsigned int bytespersec ;
1862 unsigned short blockalign ;
1863 unsigned short bitwidth ;
1864 unsigned short extrabytes ;
1865 unsigned short dummy ;
1866 } WAV_FMT_SIZE20 ;
1868 typedef struct
1869 { unsigned short format ;
1870 unsigned short channels ;
1871 unsigned int samplerate ;
1872 unsigned int bytespersec ;
1873 unsigned short blockalign ;
1874 unsigned short bitwidth ;
1875 unsigned short extrabytes ;
1876 unsigned short samplesperblock ;
1877 unsigned short numcoeffs ;
1878 struct
1879 { short coeff1 ;
1880 short coeff2 ;
1881 } coeffs [7] ;
1882 } MS_ADPCM_WAV_FMT ;
1884 typedef struct
1885 { unsigned short format ;
1886 unsigned short channels ;
1887 unsigned int samplerate ;
1888 unsigned int bytespersec ;
1889 unsigned short blockalign ;
1890 unsigned short bitwidth ;
1891 unsigned short extrabytes ;
1892 unsigned short samplesperblock ;
1893 } IMA_ADPCM_WAV_FMT ;
1895 typedef struct
1896 { unsigned short format ;
1897 unsigned short channels ;
1898 unsigned int samplerate ;
1899 unsigned int bytespersec ;
1900 unsigned short blockalign ;
1901 unsigned short bitwidth ;
1902 unsigned short extrabytes ;
1903 unsigned short auxblocksize ;
1904 } G72x_ADPCM_WAV_FMT ;
1907 typedef struct
1908 { unsigned short format ;
1909 unsigned short channels ;
1910 unsigned int samplerate ;
1911 unsigned int bytespersec ;
1912 unsigned short blockalign ;
1913 unsigned short bitwidth ;
1914 unsigned short extrabytes ;
1915 unsigned short samplesperblock ;
1916 } GSM610_WAV_FMT ;
1918 typedef struct
1919 { unsigned int esf_field1 ;
1920 unsigned short esf_field2 ;
1921 unsigned short esf_field3 ;
1922 char esf_field4 [8] ;
1923 } EXT_SUBFORMAT ;
1925 typedef struct
1926 { unsigned short format ;
1927 unsigned short channels ;
1928 unsigned int samplerate ;
1929 unsigned int bytespersec ;
1930 unsigned short blockalign ;
1931 unsigned short bitwidth ;
1932 unsigned short extrabytes ;
1933 unsigned short validbits ;
1934 unsigned int channelmask ;
1935 EXT_SUBFORMAT esf ;
1936 } EXTENSIBLE_WAV_FMT ;
1938 typedef union
1939 { unsigned short format ;
1940 MIN_WAV_FMT min ;
1941 IMA_ADPCM_WAV_FMT ima ;
1942 MS_ADPCM_WAV_FMT msadpcm ;
1943 G72x_ADPCM_WAV_FMT g72x ;
1944 EXTENSIBLE_WAV_FMT ext ;
1945 GSM610_WAV_FMT gsm610 ;
1946 WAV_FMT_SIZE20 size20 ;
1947 char padding [512] ;
1948 } WAV_FMT ;
1950 typedef struct
1951 { int frames ;
1952 } FACT_CHUNK ;
1954 #define WAV_W64_GSM610_BLOCKSIZE 65
1955 #define WAV_W64_GSM610_SAMPLES 320
1957 /*------------------------------------------------------------------------------------
1958 ** Functions defined in wav_ms_adpcm.c
1961 #define MSADPCM_ADAPT_COEFF_COUNT 7
1963 void msadpcm_write_adapt_coeffs (SF_PRIVATE *psf) ;
1965 /*------------------------------------------------------------------------------------
1966 ** Functions defined in wav_gsm610.c
1969 int wav_w64_srate2blocksize (int srate_chan_product) ;
1970 char const* wav_w64_format_str (int k) ;
1971 int wav_w64_read_fmt_chunk (SF_PRIVATE *psf, WAV_FMT *wav_fmt, int structsize) ;
1973 #endif
1975 ** Do not edit or modify anything in this comment block.
1976 ** The arch-tag line is a file identity tag for the GNU Arch
1977 ** revision control system.
1979 ** arch-tag: 877fde12-9be3-4a31-8a5a-fdae39958613
1982 ** Copyright (C) 1999-2001 Erik de Castro Lopo <erikd@mega-nerd.com>
1984 ** This program is free software; you can redistribute it and/or modify
1985 ** it under the terms of the GNU Lesser General Public License as published by
1986 ** the Free Software Foundation; either version 2.1 of the License, or
1987 ** (at your option) any later version.
1989 ** This program is distributed in the hope that it will be useful,
1990 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
1991 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1992 ** GNU Lesser General Public License for more details.
1994 ** You should have received a copy of the GNU Lesser General Public License
1995 ** along with this program; if not, write to the Free Software
1996 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2000 ** This file is not the same as the original file from Sun Microsystems. Nearly
2001 ** all the original definitions and function prototypes that were in the file
2002 ** of this name have been moved to private.h.
2005 #ifndef G72X_HEADER_FILE
2006 #define G72X_HEADER_FILE
2009 ** Number of samples per block to process.
2010 ** Must be a common multiple of possible bits per sample : 2, 3, 4, 5 and 8.
2012 #define G72x_BLOCK_SIZE (3*5*8)
2015 ** Identifiers for the differing kinds of G72x ADPCM codecs.
2016 ** The identifiers also define the number of encoded bits per sample.
2019 enum
2020 { G723_16_BITS_PER_SAMPLE = 2,
2021 G723_24_BITS_PER_SAMPLE = 3,
2022 G723_40_BITS_PER_SAMPLE = 5,
2024 G721_32_BITS_PER_SAMPLE = 4,
2025 G721_40_BITS_PER_SAMPLE = 5,
2027 G723_16_SAMPLES_PER_BLOCK = G72x_BLOCK_SIZE,
2028 G723_24_SAMPLES_PER_BLOCK = G723_24_BITS_PER_SAMPLE * (G72x_BLOCK_SIZE / G723_24_BITS_PER_SAMPLE),
2029 G723_40_SAMPLES_PER_BLOCK = G723_40_BITS_PER_SAMPLE * (G72x_BLOCK_SIZE / G723_40_BITS_PER_SAMPLE),
2031 G721_32_SAMPLES_PER_BLOCK = G72x_BLOCK_SIZE,
2032 G721_40_SAMPLES_PER_BLOCK = G721_40_BITS_PER_SAMPLE * (G72x_BLOCK_SIZE / G721_40_BITS_PER_SAMPLE),
2034 G723_16_BYTES_PER_BLOCK = (G723_16_BITS_PER_SAMPLE * G72x_BLOCK_SIZE) / 8,
2035 G723_24_BYTES_PER_BLOCK = (G723_24_BITS_PER_SAMPLE * G72x_BLOCK_SIZE) / 8,
2036 G723_40_BYTES_PER_BLOCK = (G723_40_BITS_PER_SAMPLE * G72x_BLOCK_SIZE) / 8,
2038 G721_32_BYTES_PER_BLOCK = (G721_32_BITS_PER_SAMPLE * G72x_BLOCK_SIZE) / 8,
2039 G721_40_BYTES_PER_BLOCK = (G721_40_BITS_PER_SAMPLE * G72x_BLOCK_SIZE) / 8
2040 } ;
2043 ** This is the public structure for passing data between the caller and
2044 ** the G72x encoder and decoder.
2045 ** The private array is used by the encoder and decoder for internal
2046 ** state information and should not be changed in any way by the caller.
2047 ** When decoding or encoding a stream, the same instance of this struct
2048 ** should be used for every call so that the decoder/encoder keeps the
2049 ** correct state data between calls.
2052 typedef struct
2053 { /* Private data. Don't mess with it. */
2054 unsigned long sprivateo [256 / sizeof (long)] ;
2056 /* Public data. Read only. */
2057 int blocksize, max_bytes, samplesperblock, bytesperblock ;
2059 /* Public data. Read and write. */
2060 int blocks, blockcount, samplecount ;
2061 unsigned char block [G72x_BLOCK_SIZE] ;
2062 short samples [G72x_BLOCK_SIZE] ;
2063 } G72x_DATA ;
2065 /* External function definitions. */
2067 int g72x_reader_init (G72x_DATA *data, int codec) ;
2068 int g72x_writer_init (G72x_DATA *data, int codec) ;
2070 ** Initialize the ADPCM state table for the given codec.
2071 ** Return 0 on success, 1 on fail.
2074 int g72x_decode_block (G72x_DATA *data) ;
2076 ** The caller fills data->block with data->bytes bytes before calling the
2077 ** function. The value data->bytes must be an integer multiple of
2078 ** data->blocksize and be <= data->max_bytes.
2079 ** When it returns, the caller can read out data->samples samples.
2082 int g72x_encode_block (G72x_DATA *data) ;
2084 ** The caller fills state->samples some integer multiple data->samples_per_block
2085 ** (up to G72x_BLOCK_SIZE) samples before calling the function.
2086 ** When it returns, the caller can read out bytes encoded bytes.
2089 #endif /* !G72X_HEADER_FILE */
2091 ** Do not edit or modify anything in this comment block.
2092 ** The arch-tag line is a file identity tag for the GNU Arch
2093 ** revision control system.
2095 ** arch-tag: 6ca84e5f-f932-4ba1-87ee-37056d921621
2099 * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
2100 * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
2101 * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
2104 #ifndef PRIVATE_H
2105 #define PRIVATE_H
2107 /* Added by Erik de Castro Lopo */
2108 #define USE_FLOAT_MUL
2109 #define FAST
2110 #define WAV49
2111 /* Added by Erik de Castro Lopo */
2115 typedef short word; /* 16 bit signed int */
2116 typedef int longword; /* 32 bit signed int */
2118 typedef unsigned short uword; /* unsigned word */
2119 typedef unsigned int ulongword; /* unsigned longword */
2121 struct gsm_state
2122 { word dp0[ 280 ] ;
2124 word z1; /* preprocessing.c, Offset_com. */
2125 longword L_z2; /* Offset_com. */
2126 int mp; /* Preemphasis */
2128 word u[8] ; /* short_term_aly_filter.c */
2129 word LARpp[2][8] ; /* */
2130 word j; /* */
2132 word ltp_cut; /* long_term.c, LTP crosscorr. */
2133 word nrp; /* 40 */ /* long_term.c, synthesis */
2134 word v[9] ; /* short_term.c, synthesis */
2135 word msr; /* decoder.c, Postprocessing */
2137 char verbose; /* only used if !NDEBUG */
2138 char fast; /* only used if FAST */
2140 char wav_fmt; /* only used if WAV49 defined */
2141 unsigned char frame_index; /* odd/even chaining */
2142 unsigned char frame_chain; /* half-byte to carry forward */
2144 /* Moved here from code.c where it was defined as static */
2145 word e[50] ;
2148 typedef struct gsm_state GSM_STATE ;
2150 #define MIN_WORD (-32767 - 1)
2151 #define MAX_WORD 32767
2153 #define MIN_LONGWORD (-2147483647 - 1)
2154 #define MAX_LONGWORD 2147483647
2156 /* Signed arithmetic shift right. */
2157 static C_INLINE word
2158 SASR_W (word x, word by)
2159 { return (x >> by) ;
2160 } /* SASR */
2162 static C_INLINE longword
2163 SASR_L (longword x, word by)
2164 { return (x >> by) ;
2165 } /* SASR */
2168 * Prototypes from add.c
2170 word gsm_mult (word a, word b) ;
2171 longword gsm_L_mult (word a, word b) ;
2172 word gsm_mult_r (word a, word b) ;
2174 word gsm_div (word num, word denum) ;
2176 word gsm_add (word a, word b ) ;
2177 longword gsm_L_add (longword a, longword b ) ;
2179 word gsm_sub (word a, word b) ;
2180 longword gsm_L_sub (longword a, longword b) ;
2182 word gsm_abs (word a) ;
2184 word gsm_norm (longword a ) ;
2186 longword gsm_L_asl (longword a, int n) ;
2187 word gsm_asl (word a, int n) ;
2189 longword gsm_L_asr (longword a, int n) ;
2190 word gsm_asr (word a, int n) ;
2193 * Inlined functions from add.h
2196 static C_INLINE longword
2197 GSM_MULT_R (word a, word b)
2198 { return (((longword) (a)) * ((longword) (b)) + 16384) >> 15 ;
2199 } /* GSM_MULT_R */
2201 static C_INLINE longword
2202 GSM_MULT (word a, word b)
2203 { return (((longword) (a)) * ((longword) (b))) >> 15 ;
2204 } /* GSM_MULT */
2206 static C_INLINE longword
2207 GSM_L_MULT (word a, word b)
2208 { return ((longword) (a)) * ((longword) (b)) << 1 ;
2209 } /* GSM_L_MULT */
2211 static C_INLINE longword
2212 GSM_L_ADD (longword a, longword b)
2213 { ulongword utmp ;
2215 if (a < 0 && b < 0)
2216 { utmp = (ulongword)-((a) + 1) + (ulongword)-((b) + 1) ;
2217 return (utmp >= (ulongword) MAX_LONGWORD) ? MIN_LONGWORD : -(longword)utmp-2 ;
2220 if (a > 0 && b > 0)
2221 { utmp = (ulongword) a + (ulongword) b ;
2222 return (utmp >= (ulongword) MAX_LONGWORD) ? MAX_LONGWORD : utmp ;
2225 return a + b ;
2226 } /* GSM_L_ADD */
2228 static C_INLINE longword
2229 GSM_ADD (word a, word b)
2230 { longword ltmp ;
2232 ltmp = ((longword) a) + ((longword) b) ;
2234 if (ltmp >= MAX_WORD)
2235 return MAX_WORD ;
2236 if (ltmp <= MIN_WORD)
2237 return MIN_WORD ;
2239 return ltmp ;
2240 } /* GSM_ADD */
2242 static C_INLINE longword
2243 GSM_SUB (word a, word b)
2244 { longword ltmp ;
2246 ltmp = ((longword) a) - ((longword) b) ;
2248 if (ltmp >= MAX_WORD)
2249 ltmp = MAX_WORD ;
2250 else if (ltmp <= MIN_WORD)
2251 ltmp = MIN_WORD ;
2253 return ltmp ;
2254 } /* GSM_SUB */
2256 static C_INLINE word
2257 GSM_ABS (word a)
2259 if (a > 0)
2260 return a ;
2261 if (a == MIN_WORD)
2262 return MAX_WORD ;
2263 return -a ;
2264 } /* GSM_ADD */
2268 * More prototypes from implementations..
2270 void Gsm_Coder (
2271 struct gsm_state * S,
2272 word * s, /* [0..159] samples IN */
2273 word * LARc, /* [0..7] LAR coefficients OUT */
2274 word * Nc, /* [0..3] LTP lag OUT */
2275 word * bc, /* [0..3] coded LTP gain OUT */
2276 word * Mc, /* [0..3] RPE grid selection OUT */
2277 word * xmaxc,/* [0..3] Coded maximum amplitude OUT */
2278 word * xMc) ;/* [13*4] normalized RPE samples OUT */
2280 void Gsm_Long_Term_Predictor ( /* 4x for 160 samples */
2281 struct gsm_state * S,
2282 word * d, /* [0..39] residual signal IN */
2283 word * dp, /* [-120..-1] d' IN */
2284 word * e, /* [0..40] OUT */
2285 word * dpp, /* [0..40] OUT */
2286 word * Nc, /* correlation lag OUT */
2287 word * bc) ; /* gain factor OUT */
2289 void Gsm_LPC_Analysis (
2290 struct gsm_state * S,
2291 word * s, /* 0..159 signals IN/OUT */
2292 word * LARc) ; /* 0..7 LARc's OUT */
2294 void Gsm_Preprocess (
2295 struct gsm_state * S,
2296 word * s, word * so) ;
2298 void Gsm_Encoding (
2299 struct gsm_state * S,
2300 word * e,
2301 word * ep,
2302 word * xmaxc,
2303 word * Mc,
2304 word * xMc) ;
2306 void Gsm_Short_Term_Analysis_Filter (
2307 struct gsm_state * S,
2308 word * LARc, /* coded log area ratio [0..7] IN */
2309 word * d) ; /* st res. signal [0..159] IN/OUT */
2311 void Gsm_Decoder (
2312 struct gsm_state * S,
2313 word * LARcr, /* [0..7] IN */
2314 word * Ncr, /* [0..3] IN */
2315 word * bcr, /* [0..3] IN */
2316 word * Mcr, /* [0..3] IN */
2317 word * xmaxcr, /* [0..3] IN */
2318 word * xMcr, /* [0..13*4] IN */
2319 word * s) ; /* [0..159] OUT */
2321 void Gsm_Decoding (
2322 struct gsm_state * S,
2323 word xmaxcr,
2324 word Mcr,
2325 word * xMcr, /* [0..12] IN */
2326 word * erp) ; /* [0..39] OUT */
2328 void Gsm_Long_Term_Synthesis_Filtering (
2329 struct gsm_state* S,
2330 word Ncr,
2331 word bcr,
2332 word * erp, /* [0..39] IN */
2333 word * drp) ; /* [-120..-1] IN, [0..40] OUT */
2335 void Gsm_RPE_Decoding (
2336 /*-struct gsm_state *S,-*/
2337 word xmaxcr,
2338 word Mcr,
2339 word * xMcr, /* [0..12], 3 bits IN */
2340 word * erp) ; /* [0..39] OUT */
2342 void Gsm_RPE_Encoding (
2343 /*-struct gsm_state * S,-*/
2344 word * e, /* -5..-1][0..39][40..44 IN/OUT */
2345 word * xmaxc, /* OUT */
2346 word * Mc, /* OUT */
2347 word * xMc) ; /* [0..12] OUT */
2349 void Gsm_Short_Term_Synthesis_Filter (
2350 struct gsm_state * S,
2351 word * LARcr, /* log area ratios [0..7] IN */
2352 word * drp, /* received d [0...39] IN */
2353 word * s) ; /* signal s [0..159] OUT */
2355 void Gsm_Update_of_reconstructed_short_time_residual_signal (
2356 word * dpp, /* [0...39] IN */
2357 word * ep, /* [0...39] IN */
2358 word * dp) ; /* [-120...-1] IN/OUT */
2361 * Tables from table.c
2363 #ifndef GSM_TABLE_C
2365 extern word gsm_A [8], gsm_B [8], gsm_MIC [8], gsm_MAC [8] ;
2366 extern word gsm_INVA [8] ;
2367 extern word gsm_DLB [4], gsm_QLB [4] ;
2368 extern word gsm_H [11] ;
2369 extern word gsm_NRFAC [8] ;
2370 extern word gsm_FAC [8] ;
2372 #endif /* GSM_TABLE_C */
2375 * Debugging
2377 #ifdef NDEBUG
2379 # define gsm_debug_words(a, b, c, d) /* nil */
2380 # define gsm_debug_longwords(a, b, c, d) /* nil */
2381 # define gsm_debug_word(a, b) /* nil */
2382 # define gsm_debug_longword(a, b) /* nil */
2384 #else /* !NDEBUG => DEBUG */
2386 void gsm_debug_words (char * name, int, int, word *) ;
2387 void gsm_debug_longwords (char * name, int, int, longword *) ;
2388 void gsm_debug_longword (char * name, longword) ;
2389 void gsm_debug_word (char * name, word) ;
2391 #endif /* !NDEBUG */
2393 #endif /* PRIVATE_H */
2395 ** Do not edit or modify anything in this comment block.
2396 ** The arch-tag line is a file identity tag for the GNU Arch
2397 ** revision control system.
2399 ** arch-tag: 8bc5fdf2-e8c8-4686-9bd7-a30b512bef0c
2403 ** Copyright (C) 2001-2004 Erik de Castro Lopo <erikd@mega-nerd.com>
2405 ** This program is free software; you can redistribute it and/or modify
2406 ** it under the terms of the GNU Lesser General Public License as published by
2407 ** the Free Software Foundation; either version 2.1 of the License, or
2408 ** (at your option) any later version.
2410 ** This program is distributed in the hope that it will be useful,
2411 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
2412 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2413 ** GNU Lesser General Public License for more details.
2415 ** You should have received a copy of the GNU Lesser General Public License
2416 ** along with this program; if not, write to the Free Software
2417 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2420 /* Version 1.3 */
2423 /*============================================================================
2424 ** On Intel Pentium processors (especially PIII and probably P4), converting
2425 ** from float to int is very slow. To meet the C specs, the code produced by
2426 ** most C compilers targeting Pentium needs to change the FPU rounding mode
2427 ** before the float to int conversion is performed.
2429 ** Changing the FPU rounding mode causes the FPU pipeline to be flushed. It
2430 ** is this flushing of the pipeline which is so slow.
2432 ** Fortunately the ISO C99 specifications define the functions lrint, lrintf,
2433 ** llrint and llrintf which fix this problem as a side effect.
2435 ** On Unix-like systems, the configure process should have detected the
2436 ** presence of these functions. If they weren't found we have to replace them
2437 ** here with a standard C cast.
2441 ** The C99 prototypes for lrint and lrintf are as follows:
2443 ** long int lrintf (float x) ;
2444 ** long int lrint (double x) ;
2449 ** The presence of the required functions are detected during the configure
2450 ** process and the values HAVE_LRINT and HAVE_LRINTF are set accordingly in
2451 ** the config.h file.
2454 #define HAVE_LRINT_REPLACEMENT 0
2456 #if (HAVE_LRINT && HAVE_LRINTF)
2459 ** These defines enable functionality introduced with the 1999 ISO C
2460 ** standard. They must be defined before the inclusion of math.h to
2461 ** engage them. If optimisation is enabled, these functions will be
2462 ** inlined. With optimisation switched off, you have to link in the
2463 ** maths library using -lm.
2466 #define _ISOC9X_SOURCE 1
2467 #define _ISOC99_SOURCE 1
2469 #define __USE_ISOC9X 1
2470 #define __USE_ISOC99 1
2473 #elif ( defined (WIN32) || defined (_WIN32) || defined(__PLATFORM_WIN32__) || defined(__LITTLE_ENDIAN__) )
2475 #undef HAVE_LRINT_REPLACEMENT
2476 #define HAVE_LRINT_REPLACEMENT 1
2479 ** Win32 doesn't seem to have these functions.
2480 ** Therefore implement inline versions of these functions here.
2483 __inline long int
2484 lrint (double flt)
2485 { int intgr ;
2487 _asm
2488 { fld flt
2489 fistp intgr
2492 return intgr ;
2495 __inline long int
2496 lrintf (float flt)
2497 { int intgr ;
2499 _asm
2500 { fld flt
2501 fistp intgr
2504 return intgr ;
2507 #elif (defined (__MWERKS__) && defined (macintosh))
2509 /* This MacOS 9 solution was provided by Stephane Letz */
2511 #undef HAVE_LRINT_REPLACEMENT
2512 #define HAVE_LRINT_REPLACEMENT 1
2514 #undef lrint
2515 #undef lrintf
2517 #define lrint double2int
2518 #define lrintf float2int
2520 inline int
2521 float2int (register float in)
2522 { long res [2] ;
2525 { fctiw in, in
2526 stfd in, res
2528 return res [1] ;
2529 } /* float2int */
2531 inline int
2532 double2int (register double in)
2533 { long res [2] ;
2536 { fctiw in, in
2537 stfd in, res
2539 return res [1] ;
2540 } /* double2int */
2542 #elif (defined (__MACH__) && defined (__APPLE__))
2544 /* For Apple MacOSX. */
2546 #undef HAVE_LRINT_REPLACEMENT
2547 #define HAVE_LRINT_REPLACEMENT 1
2549 #undef lrint
2550 #undef lrintf
2552 #define lrint double2int
2553 #define lrintf float2int
2555 inline static long int
2556 float2int (register float in)
2557 { int res [2] ;
2559 __asm__ __volatile__
2560 ( "fctiw %1, %1\n\t"
2561 "stfd %1, %0"
2562 : "=m" (res) /* Output */
2563 : "f" (in) /* Input */
2564 : "memory"
2567 return res [1] ;
2568 } /* lrintf */
2570 inline static long int
2571 double2int (register double in)
2572 { int res [2] ;
2574 __asm__ __volatile__
2575 ( "fctiw %1, %1\n\t"
2576 "stfd %1, %0"
2577 : "=m" (res) /* Output */
2578 : "f" (in) /* Input */
2579 : "memory"
2582 return res [1] ;
2583 } /* lrint */
2585 #else
2586 #ifndef __sgi
2587 // #warning "Don't have the functions lrint() and lrintf()."
2588 // #warning "Replacing these functions with a standard C cast."
2589 #endif
2592 #define lrint(dbl) ((long) (dbl))
2593 #define lrintf(flt) ((long) (flt))
2595 #endif
2600 ** Do not edit or modify anything in this comment block.
2601 ** The arch-tag line is a file identity tag for the GNU Arch
2602 ** revision control system.
2604 ** arch-tag: 42db1693-ff61-4051-bac1-e4d24c4e30b7
2607 ** Copyright (C) 2002-2004 Erik de Castro Lopo <erikd@mega-nerd.com>
2609 ** This program is free software; you can redistribute it and/or modify
2610 ** it under the terms of the GNU Lesser General Public License as published by
2611 ** the Free Software Foundation; either version 2.1 of the License, or
2612 ** (at your option) any later version.
2614 ** This program is distributed in the hope that it will be useful,
2615 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
2616 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2617 ** GNU Lesser General Public License for more details.
2619 ** You should have received a copy of the GNU Lesser General Public License
2620 ** along with this program; if not, write to the Free Software
2621 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2624 /* Some defines that microsoft 'forgot' to implement. */
2626 #ifndef S_IRWXU
2627 #define S_IRWXU 0000700 /* rwx, owner */
2628 #endif
2630 #ifndef S_IRUSR
2631 #define S_IRUSR 0000400 /* read permission, owner */
2632 #endif
2634 #ifndef S_IWUSR
2635 #define S_IWUSR 0000200 /* write permission, owner */
2636 #endif
2638 #ifndef S_IXUSR
2639 #define S_IXUSR 0000100 /* execute/search permission, owner */
2640 #endif
2642 #ifndef S_IRWXG
2643 #define S_IRWXG 0000070 /* rwx, group */
2644 #endif
2646 #ifndef S_IRGRP
2647 #define S_IRGRP 0000040 /* read permission, group */
2648 #endif
2650 #ifndef S_IWGRP
2651 #define S_IWGRP 0000020 /* write permission, grougroup */
2652 #endif
2654 #ifndef S_IXGRP
2655 #define S_IXGRP 0000010 /* execute/search permission, group */
2656 #endif
2658 #ifndef S_IRWXO
2659 #define S_IRWXO 0000007 /* rwx, other */
2660 #endif
2662 #ifndef S_IROTH
2663 #define S_IROTH 0000004 /* read permission, other */
2664 #endif
2666 #ifndef S_IWOTH
2667 #define S_IWOTH 0000002 /* write permission, other */
2668 #endif
2670 #ifndef S_IXOTH
2671 #define S_IXOTH 0000001 /* execute/search permission, other */
2672 #endif
2674 #ifndef S_ISFIFO
2675 #define S_ISFIFO(mode) (((mode) & _S_IFMT) == _S_IFIFO)
2676 #endif
2678 #ifndef S_ISREG
2679 #define S_ISREG(mode) (((mode) & _S_IFREG) == _S_IFREG)
2680 #endif
2683 ** Don't know if these are still needed.
2685 ** #define _IFMT _S_IFMT
2686 ** #define _IFREG _S_IFREG
2689 ** Do not edit or modify anything in this comment block.
2690 ** The arch-tag line is a file identity tag for the GNU Arch
2691 ** revision control system.
2693 ** arch-tag: 253aea6d-6299-46fd-8d06-bc5f6224c8fe
2696 #endif