Debian Codegraph @

src/core/util_sndfile.h

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