andrew@0
|
1 /*
|
andrew@0
|
2 ** Copyright (C) 1999-2006 Erik de Castro Lopo <erikd@mega-nerd.com>
|
andrew@0
|
3 **
|
andrew@0
|
4 ** This program is free software; you can redistribute it and/or modify
|
andrew@0
|
5 ** it under the terms of the GNU Lesser General Public License as published by
|
andrew@0
|
6 ** the Free Software Foundation; either version 2.1 of the License, or
|
andrew@0
|
7 ** (at your option) any later version.
|
andrew@0
|
8 **
|
andrew@0
|
9 ** This program is distributed in the hope that it will be useful,
|
andrew@0
|
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
andrew@0
|
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
andrew@0
|
12 ** GNU Lesser General Public License for more details.
|
andrew@0
|
13 **
|
andrew@0
|
14 ** You should have received a copy of the GNU Lesser General Public License
|
andrew@0
|
15 ** along with this program; if not, write to the Free Software
|
andrew@0
|
16 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
andrew@0
|
17 */
|
andrew@0
|
18
|
andrew@0
|
19 /*
|
andrew@0
|
20 ** sndfile.h -- system-wide definitions
|
andrew@0
|
21 **
|
andrew@0
|
22 ** API documentation is in the doc/ directory of the source code tarball
|
andrew@0
|
23 ** and at http://www.mega-nerd.com/libsndfile/api.html.
|
andrew@0
|
24 */
|
andrew@0
|
25
|
andrew@0
|
26 #ifndef SNDFILE_H
|
andrew@0
|
27 #define SNDFILE_H
|
andrew@0
|
28
|
andrew@0
|
29 /* This is the version 1.0.X header file. */
|
andrew@0
|
30 #define SNDFILE_1
|
andrew@0
|
31
|
andrew@0
|
32 #include <stdio.h>
|
andrew@0
|
33
|
andrew@0
|
34 /* For the Metrowerks CodeWarrior Pro Compiler (mainly MacOS) */
|
andrew@0
|
35
|
andrew@0
|
36 #if (defined (__MWERKS__))
|
andrew@0
|
37 #include <unix.h>
|
andrew@0
|
38 #else
|
andrew@0
|
39 #include <sys/types.h>
|
andrew@0
|
40 #endif
|
andrew@0
|
41
|
andrew@0
|
42 #ifdef __cplusplus
|
andrew@0
|
43 extern "C" {
|
andrew@0
|
44 #endif /* __cplusplus */
|
andrew@0
|
45
|
andrew@0
|
46 /* The following file types can be read and written.
|
andrew@0
|
47 ** A file type would consist of a major type (ie SF_FORMAT_WAV) bitwise
|
andrew@0
|
48 ** ORed with a minor type (ie SF_FORMAT_PCM). SF_FORMAT_TYPEMASK and
|
andrew@0
|
49 ** SF_FORMAT_SUBMASK can be used to separate the major and minor file
|
andrew@0
|
50 ** types.
|
andrew@0
|
51 */
|
andrew@0
|
52
|
andrew@0
|
53 enum
|
andrew@0
|
54 { /* Major formats. */
|
andrew@0
|
55 SF_FORMAT_WAV = 0x010000, /* Microsoft WAV format (little endian default). */
|
andrew@0
|
56 SF_FORMAT_AIFF = 0x020000, /* Apple/SGI AIFF format (big endian). */
|
andrew@0
|
57 SF_FORMAT_AU = 0x030000, /* Sun/NeXT AU format (big endian). */
|
andrew@0
|
58 SF_FORMAT_RAW = 0x040000, /* RAW PCM data. */
|
andrew@0
|
59 SF_FORMAT_PAF = 0x050000, /* Ensoniq PARIS file format. */
|
andrew@0
|
60 SF_FORMAT_SVX = 0x060000, /* Amiga IFF / SVX8 / SV16 format. */
|
andrew@0
|
61 SF_FORMAT_NIST = 0x070000, /* Sphere NIST format. */
|
andrew@0
|
62 SF_FORMAT_VOC = 0x080000, /* VOC files. */
|
andrew@0
|
63 SF_FORMAT_IRCAM = 0x0A0000, /* Berkeley/IRCAM/CARL */
|
andrew@0
|
64 SF_FORMAT_W64 = 0x0B0000, /* Sonic Foundry's 64 bit RIFF/WAV */
|
andrew@0
|
65 SF_FORMAT_MAT4 = 0x0C0000, /* Matlab (tm) V4.2 / GNU Octave 2.0 */
|
andrew@0
|
66 SF_FORMAT_MAT5 = 0x0D0000, /* Matlab (tm) V5.0 / GNU Octave 2.1 */
|
andrew@0
|
67 SF_FORMAT_PVF = 0x0E0000, /* Portable Voice Format */
|
andrew@0
|
68 SF_FORMAT_XI = 0x0F0000, /* Fasttracker 2 Extended Instrument */
|
andrew@0
|
69 SF_FORMAT_HTK = 0x100000, /* HMM Tool Kit format */
|
andrew@0
|
70 SF_FORMAT_SDS = 0x110000, /* Midi Sample Dump Standard */
|
andrew@0
|
71 SF_FORMAT_AVR = 0x120000, /* Audio Visual Research */
|
andrew@0
|
72 SF_FORMAT_WAVEX = 0x130000, /* MS WAVE with WAVEFORMATEX */
|
andrew@0
|
73 SF_FORMAT_SD2 = 0x160000, /* Sound Designer 2 */
|
andrew@0
|
74 SF_FORMAT_FLAC = 0x170000, /* FLAC lossless file format */
|
andrew@0
|
75 SF_FORMAT_CAF = 0x180000, /* Core Audio File format */
|
andrew@0
|
76
|
andrew@0
|
77 /* Subtypes from here on. */
|
andrew@0
|
78
|
andrew@0
|
79 SF_FORMAT_PCM_S8 = 0x0001, /* Signed 8 bit data */
|
andrew@0
|
80 SF_FORMAT_PCM_16 = 0x0002, /* Signed 16 bit data */
|
andrew@0
|
81 SF_FORMAT_PCM_24 = 0x0003, /* Signed 24 bit data */
|
andrew@0
|
82 SF_FORMAT_PCM_32 = 0x0004, /* Signed 32 bit data */
|
andrew@0
|
83
|
andrew@0
|
84 SF_FORMAT_PCM_U8 = 0x0005, /* Unsigned 8 bit data (WAV and RAW only) */
|
andrew@0
|
85
|
andrew@0
|
86 SF_FORMAT_FLOAT = 0x0006, /* 32 bit float data */
|
andrew@0
|
87 SF_FORMAT_DOUBLE = 0x0007, /* 64 bit float data */
|
andrew@0
|
88
|
andrew@0
|
89 SF_FORMAT_ULAW = 0x0010, /* U-Law encoded. */
|
andrew@0
|
90 SF_FORMAT_ALAW = 0x0011, /* A-Law encoded. */
|
andrew@0
|
91 SF_FORMAT_IMA_ADPCM = 0x0012, /* IMA ADPCM. */
|
andrew@0
|
92 SF_FORMAT_MS_ADPCM = 0x0013, /* Microsoft ADPCM. */
|
andrew@0
|
93
|
andrew@0
|
94 SF_FORMAT_GSM610 = 0x0020, /* GSM 6.10 encoding. */
|
andrew@0
|
95 SF_FORMAT_VOX_ADPCM = 0x0021, /* OKI / Dialogix ADPCM */
|
andrew@0
|
96
|
andrew@0
|
97 SF_FORMAT_G721_32 = 0x0030, /* 32kbs G721 ADPCM encoding. */
|
andrew@0
|
98 SF_FORMAT_G723_24 = 0x0031, /* 24kbs G723 ADPCM encoding. */
|
andrew@0
|
99 SF_FORMAT_G723_40 = 0x0032, /* 40kbs G723 ADPCM encoding. */
|
andrew@0
|
100
|
andrew@0
|
101 SF_FORMAT_DWVW_12 = 0x0040, /* 12 bit Delta Width Variable Word encoding. */
|
andrew@0
|
102 SF_FORMAT_DWVW_16 = 0x0041, /* 16 bit Delta Width Variable Word encoding. */
|
andrew@0
|
103 SF_FORMAT_DWVW_24 = 0x0042, /* 24 bit Delta Width Variable Word encoding. */
|
andrew@0
|
104 SF_FORMAT_DWVW_N = 0x0043, /* N bit Delta Width Variable Word encoding. */
|
andrew@0
|
105
|
andrew@0
|
106 SF_FORMAT_DPCM_8 = 0x0050, /* 8 bit differential PCM (XI only) */
|
andrew@0
|
107 SF_FORMAT_DPCM_16 = 0x0051, /* 16 bit differential PCM (XI only) */
|
andrew@0
|
108
|
andrew@0
|
109 /* Endian-ness options. */
|
andrew@0
|
110
|
andrew@0
|
111 SF_ENDIAN_FILE = 0x00000000, /* Default file endian-ness. */
|
andrew@0
|
112 SF_ENDIAN_LITTLE = 0x10000000, /* Force little endian-ness. */
|
andrew@0
|
113 SF_ENDIAN_BIG = 0x20000000, /* Force big endian-ness. */
|
andrew@0
|
114 SF_ENDIAN_CPU = 0x30000000, /* Force CPU endian-ness. */
|
andrew@0
|
115
|
andrew@0
|
116 SF_FORMAT_SUBMASK = 0x0000FFFF,
|
andrew@0
|
117 SF_FORMAT_TYPEMASK = 0x0FFF0000,
|
andrew@0
|
118 SF_FORMAT_ENDMASK = 0x30000000
|
andrew@0
|
119 } ;
|
andrew@0
|
120
|
andrew@0
|
121 /*
|
andrew@0
|
122 ** The following are the valid command numbers for the sf_command()
|
andrew@0
|
123 ** interface. The use of these commands is documented in the file
|
andrew@0
|
124 ** command.html in the doc directory of the source code distribution.
|
andrew@0
|
125 */
|
andrew@0
|
126
|
andrew@0
|
127 enum
|
andrew@0
|
128 { SFC_GET_LIB_VERSION = 0x1000,
|
andrew@0
|
129 SFC_GET_LOG_INFO = 0x1001,
|
andrew@0
|
130
|
andrew@0
|
131 SFC_GET_NORM_DOUBLE = 0x1010,
|
andrew@0
|
132 SFC_GET_NORM_FLOAT = 0x1011,
|
andrew@0
|
133 SFC_SET_NORM_DOUBLE = 0x1012,
|
andrew@0
|
134 SFC_SET_NORM_FLOAT = 0x1013,
|
andrew@0
|
135 SFC_SET_SCALE_FLOAT_INT_READ = 0x1014,
|
andrew@0
|
136
|
andrew@0
|
137 SFC_GET_SIMPLE_FORMAT_COUNT = 0x1020,
|
andrew@0
|
138 SFC_GET_SIMPLE_FORMAT = 0x1021,
|
andrew@0
|
139
|
andrew@0
|
140 SFC_GET_FORMAT_INFO = 0x1028,
|
andrew@0
|
141
|
andrew@0
|
142 SFC_GET_FORMAT_MAJOR_COUNT = 0x1030,
|
andrew@0
|
143 SFC_GET_FORMAT_MAJOR = 0x1031,
|
andrew@0
|
144 SFC_GET_FORMAT_SUBTYPE_COUNT = 0x1032,
|
andrew@0
|
145 SFC_GET_FORMAT_SUBTYPE = 0x1033,
|
andrew@0
|
146
|
andrew@0
|
147 SFC_CALC_SIGNAL_MAX = 0x1040,
|
andrew@0
|
148 SFC_CALC_NORM_SIGNAL_MAX = 0x1041,
|
andrew@0
|
149 SFC_CALC_MAX_ALL_CHANNELS = 0x1042,
|
andrew@0
|
150 SFC_CALC_NORM_MAX_ALL_CHANNELS = 0x1043,
|
andrew@0
|
151 SFC_GET_SIGNAL_MAX = 0x1044,
|
andrew@0
|
152 SFC_GET_MAX_ALL_CHANNELS = 0x1045,
|
andrew@0
|
153
|
andrew@0
|
154 SFC_SET_ADD_PEAK_CHUNK = 0x1050,
|
andrew@0
|
155
|
andrew@0
|
156 SFC_UPDATE_HEADER_NOW = 0x1060,
|
andrew@0
|
157 SFC_SET_UPDATE_HEADER_AUTO = 0x1061,
|
andrew@0
|
158
|
andrew@0
|
159 SFC_FILE_TRUNCATE = 0x1080,
|
andrew@0
|
160
|
andrew@0
|
161 SFC_SET_RAW_START_OFFSET = 0x1090,
|
andrew@0
|
162
|
andrew@0
|
163 SFC_SET_DITHER_ON_WRITE = 0x10A0,
|
andrew@0
|
164 SFC_SET_DITHER_ON_READ = 0x10A1,
|
andrew@0
|
165
|
andrew@0
|
166 SFC_GET_DITHER_INFO_COUNT = 0x10A2,
|
andrew@0
|
167 SFC_GET_DITHER_INFO = 0x10A3,
|
andrew@0
|
168
|
andrew@0
|
169 SFC_GET_EMBED_FILE_INFO = 0x10B0,
|
andrew@0
|
170
|
andrew@0
|
171 SFC_SET_CLIPPING = 0x10C0,
|
andrew@0
|
172 SFC_GET_CLIPPING = 0x10C1,
|
andrew@0
|
173
|
andrew@0
|
174 SFC_GET_INSTRUMENT = 0x10D0,
|
andrew@0
|
175 SFC_SET_INSTRUMENT = 0x10D1,
|
andrew@0
|
176
|
andrew@0
|
177 SFC_GET_LOOP_INFO = 0x10E0,
|
andrew@0
|
178
|
andrew@0
|
179 SFC_GET_BROADCAST_INFO = 0x10F0,
|
andrew@0
|
180 SFC_SET_BROADCAST_INFO = 0x10F1,
|
andrew@0
|
181
|
andrew@0
|
182 /* Following commands for testing only. */
|
andrew@0
|
183 SFC_TEST_IEEE_FLOAT_REPLACE = 0x6001,
|
andrew@0
|
184
|
andrew@0
|
185 /*
|
andrew@0
|
186 ** SFC_SET_ADD_* values are deprecated and will disappear at some
|
andrew@0
|
187 ** time in the future. They are guaranteed to be here up to and
|
andrew@0
|
188 ** including version 1.0.8 to avoid breakage of existng software.
|
andrew@0
|
189 ** They currently do nothing and will continue to do nothing.
|
andrew@0
|
190 */
|
andrew@0
|
191 SFC_SET_ADD_DITHER_ON_WRITE = 0x1070,
|
andrew@0
|
192 SFC_SET_ADD_DITHER_ON_READ = 0x1071
|
andrew@0
|
193 } ;
|
andrew@0
|
194
|
andrew@0
|
195
|
andrew@0
|
196 /*
|
andrew@0
|
197 ** String types that can be set and read from files. Not all file types
|
andrew@0
|
198 ** support this and even the file types which support one, may not support
|
andrew@0
|
199 ** all string types.
|
andrew@0
|
200 */
|
andrew@0
|
201
|
andrew@0
|
202 enum
|
andrew@0
|
203 { SF_STR_TITLE = 0x01,
|
andrew@0
|
204 SF_STR_COPYRIGHT = 0x02,
|
andrew@0
|
205 SF_STR_SOFTWARE = 0x03,
|
andrew@0
|
206 SF_STR_ARTIST = 0x04,
|
andrew@0
|
207 SF_STR_COMMENT = 0x05,
|
andrew@0
|
208 SF_STR_DATE = 0x06
|
andrew@0
|
209 } ;
|
andrew@0
|
210
|
andrew@0
|
211 /*
|
andrew@0
|
212 ** Use the following as the start and end index when doing metadata
|
andrew@0
|
213 ** transcoding.
|
andrew@0
|
214 */
|
andrew@0
|
215
|
andrew@0
|
216 #define SF_STR_FIRST SF_STR_TITLE
|
andrew@0
|
217 #define SF_STR_LAST SF_STR_DATE
|
andrew@0
|
218
|
andrew@0
|
219 enum
|
andrew@0
|
220 { /* True and false */
|
andrew@0
|
221 SF_FALSE = 0,
|
andrew@0
|
222 SF_TRUE = 1,
|
andrew@0
|
223
|
andrew@0
|
224 /* Modes for opening files. */
|
andrew@0
|
225 SFM_READ = 0x10,
|
andrew@0
|
226 SFM_WRITE = 0x20,
|
andrew@0
|
227 SFM_RDWR = 0x30
|
andrew@0
|
228 } ;
|
andrew@0
|
229
|
andrew@0
|
230 /* Public error values. These are guaranteed to remain unchanged for the duration
|
andrew@0
|
231 ** of the library major version number.
|
andrew@0
|
232 ** There are also a large number of private error numbers which are internal to
|
andrew@0
|
233 ** the library which can change at any time.
|
andrew@0
|
234 */
|
andrew@0
|
235
|
andrew@0
|
236 enum
|
andrew@0
|
237 { SF_ERR_NO_ERROR = 0,
|
andrew@0
|
238 SF_ERR_UNRECOGNISED_FORMAT = 1,
|
andrew@0
|
239 SF_ERR_SYSTEM = 2,
|
andrew@0
|
240 SF_ERR_MALFORMED_FILE = 3,
|
andrew@0
|
241 SF_ERR_UNSUPPORTED_ENCODING = 4
|
andrew@0
|
242 } ;
|
andrew@0
|
243
|
andrew@0
|
244 /* A SNDFILE* pointer can be passed around much like stdio.h's FILE* pointer. */
|
andrew@0
|
245
|
andrew@0
|
246 typedef struct SNDFILE_tag SNDFILE ;
|
andrew@0
|
247
|
andrew@0
|
248 /* The following typedef is system specific and is defined when libsndfile is.
|
andrew@0
|
249 ** compiled. sf_count_t can be one of loff_t (Linux), off_t (*BSD),
|
andrew@0
|
250 ** off64_t (Solaris), __int64_t (Win32) etc.
|
andrew@0
|
251 */
|
andrew@0
|
252
|
andrew@0
|
253 typedef off_t sf_count_t ;
|
andrew@0
|
254
|
andrew@0
|
255 #define SF_COUNT_MAX 0x7FFFFFFFFFFFFFFFLL
|
andrew@0
|
256
|
andrew@0
|
257 /* A pointer to a SF_INFO structure is passed to sf_open_read () and filled in.
|
andrew@0
|
258 ** On write, the SF_INFO structure is filled in by the user and passed into
|
andrew@0
|
259 ** sf_open_write ().
|
andrew@0
|
260 */
|
andrew@0
|
261
|
andrew@0
|
262 struct SF_INFO
|
andrew@0
|
263 { sf_count_t frames ; /* Used to be called samples. Changed to avoid confusion. */
|
andrew@0
|
264 int samplerate ;
|
andrew@0
|
265 int channels ;
|
andrew@0
|
266 int format ;
|
andrew@0
|
267 int sections ;
|
andrew@0
|
268 int seekable ;
|
andrew@0
|
269 } ;
|
andrew@0
|
270
|
andrew@0
|
271 typedef struct SF_INFO SF_INFO ;
|
andrew@0
|
272
|
andrew@0
|
273 /* The SF_FORMAT_INFO struct is used to retrieve information about the sound
|
andrew@0
|
274 ** file formats libsndfile supports using the sf_command () interface.
|
andrew@0
|
275 **
|
andrew@0
|
276 ** Using this interface will allow applications to support new file formats
|
andrew@0
|
277 ** and encoding types when libsndfile is upgraded, without requiring
|
andrew@0
|
278 ** re-compilation of the application.
|
andrew@0
|
279 **
|
andrew@0
|
280 ** Please consult the libsndfile documentation (particularly the information
|
andrew@0
|
281 ** on the sf_command () interface) for examples of its use.
|
andrew@0
|
282 */
|
andrew@0
|
283
|
andrew@0
|
284 typedef struct
|
andrew@0
|
285 { int format ;
|
andrew@0
|
286 const char *name ;
|
andrew@0
|
287 const char *extension ;
|
andrew@0
|
288 } SF_FORMAT_INFO ;
|
andrew@0
|
289
|
andrew@0
|
290 /*
|
andrew@0
|
291 ** Enums and typedefs for adding dither on read and write.
|
andrew@0
|
292 ** See the html documentation for sf_command(), SFC_SET_DITHER_ON_WRITE
|
andrew@0
|
293 ** and SFC_SET_DITHER_ON_READ.
|
andrew@0
|
294 */
|
andrew@0
|
295
|
andrew@0
|
296 enum
|
andrew@0
|
297 { SFD_DEFAULT_LEVEL = 0,
|
andrew@0
|
298 SFD_CUSTOM_LEVEL = 0x40000000,
|
andrew@0
|
299
|
andrew@0
|
300 SFD_NO_DITHER = 500,
|
andrew@0
|
301 SFD_WHITE = 501,
|
andrew@0
|
302 SFD_TRIANGULAR_PDF = 502
|
andrew@0
|
303 } ;
|
andrew@0
|
304
|
andrew@0
|
305 typedef struct
|
andrew@0
|
306 { int type ;
|
andrew@0
|
307 double level ;
|
andrew@0
|
308 const char *name ;
|
andrew@0
|
309 } SF_DITHER_INFO ;
|
andrew@0
|
310
|
andrew@0
|
311 /* Struct used to retrieve information about a file embedded within a
|
andrew@0
|
312 ** larger file. See SFC_GET_EMBED_FILE_INFO.
|
andrew@0
|
313 */
|
andrew@0
|
314
|
andrew@0
|
315 typedef struct
|
andrew@0
|
316 { sf_count_t offset ;
|
andrew@0
|
317 sf_count_t length ;
|
andrew@0
|
318 } SF_EMBED_FILE_INFO ;
|
andrew@0
|
319
|
andrew@0
|
320 /*
|
andrew@0
|
321 ** Structs used to retrieve music sample information from a file.
|
andrew@0
|
322 */
|
andrew@0
|
323
|
andrew@0
|
324 enum
|
andrew@0
|
325 { /*
|
andrew@0
|
326 ** The loop mode field in SF_INSTRUMENT will be one of the following.
|
andrew@0
|
327 */
|
andrew@0
|
328 SF_LOOP_NONE = 800,
|
andrew@0
|
329 SF_LOOP_FORWARD,
|
andrew@0
|
330 SF_LOOP_BACKWARD,
|
andrew@0
|
331 SF_LOOP_ALTERNATING
|
andrew@0
|
332 } ;
|
andrew@0
|
333
|
andrew@0
|
334 typedef struct
|
andrew@0
|
335 { int gain ;
|
andrew@0
|
336 char basenote, detune ;
|
andrew@0
|
337 char velocity_lo, velocity_hi ;
|
andrew@0
|
338 char key_lo, key_hi ;
|
andrew@0
|
339 int loop_count ;
|
andrew@0
|
340
|
andrew@0
|
341 struct
|
andrew@0
|
342 { int mode ;
|
andrew@0
|
343 unsigned int start ;
|
andrew@0
|
344 unsigned int end ;
|
andrew@0
|
345 unsigned int count ;
|
andrew@0
|
346 } loops [16] ; /* make variable in a sensible way */
|
andrew@0
|
347 } SF_INSTRUMENT ;
|
andrew@0
|
348
|
andrew@0
|
349
|
andrew@0
|
350
|
andrew@0
|
351 /* Struct used to retrieve loop information from a file.*/
|
andrew@0
|
352 typedef struct
|
andrew@0
|
353 {
|
andrew@0
|
354 short time_sig_num ; /* any positive integer > 0 */
|
andrew@0
|
355 short time_sig_den ; /* any positive power of 2 > 0 */
|
andrew@0
|
356 int loop_mode ; /* see SF_LOOP enum */
|
andrew@0
|
357
|
andrew@0
|
358 int num_beats ; /* this is NOT the amount of quarter notes !!!*/
|
andrew@0
|
359 /* a full bar of 4/4 is 4 beats */
|
andrew@0
|
360 /* a full bar of 7/8 is 7 beats */
|
andrew@0
|
361
|
andrew@0
|
362 float bpm ; /* suggestion, as it can be calculated using other fields:*/
|
andrew@0
|
363 /* file's lenght, file's sampleRate and our time_sig_den*/
|
andrew@0
|
364 /* -> bpms are always the amount of _quarter notes_ per minute */
|
andrew@0
|
365
|
andrew@0
|
366 int root_key ; /* MIDI note, or -1 for None */
|
andrew@0
|
367 int future [6] ;
|
andrew@0
|
368 } SF_LOOP_INFO ;
|
andrew@0
|
369
|
andrew@0
|
370
|
andrew@0
|
371 /* Struct used to retrieve broadcast (EBU) information from a file.
|
andrew@0
|
372 ** Strongly (!) based on EBU "bext" chunk format used in Broadcast WAVE.
|
andrew@0
|
373 */
|
andrew@0
|
374 typedef struct
|
andrew@0
|
375 { char description [256] ;
|
andrew@0
|
376 char originator [32] ;
|
andrew@0
|
377 char originator_reference [32] ;
|
andrew@0
|
378 char origination_date [10] ;
|
andrew@0
|
379 char origination_time [8] ;
|
andrew@0
|
380 int time_reference_low ;
|
andrew@0
|
381 int time_reference_high ;
|
andrew@0
|
382 short version ;
|
andrew@0
|
383 char umid [64] ;
|
andrew@0
|
384 char reserved [190] ;
|
andrew@0
|
385 unsigned int coding_history_size ;
|
andrew@0
|
386 char coding_history [256] ;
|
andrew@0
|
387 } SF_BROADCAST_INFO ;
|
andrew@0
|
388
|
andrew@0
|
389 typedef sf_count_t (*sf_vio_get_filelen) (void *user_data) ;
|
andrew@0
|
390 typedef sf_count_t (*sf_vio_seek) (sf_count_t offset, int whence, void *user_data) ;
|
andrew@0
|
391 typedef sf_count_t (*sf_vio_read) (void *ptr, sf_count_t count, void *user_data) ;
|
andrew@0
|
392 typedef sf_count_t (*sf_vio_write) (const void *ptr, sf_count_t count, void *user_data) ;
|
andrew@0
|
393 typedef sf_count_t (*sf_vio_tell) (void *user_data) ;
|
andrew@0
|
394
|
andrew@0
|
395 struct SF_VIRTUAL_IO
|
andrew@0
|
396 { sf_vio_get_filelen get_filelen ;
|
andrew@0
|
397 sf_vio_seek seek ;
|
andrew@0
|
398 sf_vio_read read ;
|
andrew@0
|
399 sf_vio_write write ;
|
andrew@0
|
400 sf_vio_tell tell ;
|
andrew@0
|
401 } ;
|
andrew@0
|
402
|
andrew@0
|
403 typedef struct SF_VIRTUAL_IO SF_VIRTUAL_IO ;
|
andrew@0
|
404
|
andrew@0
|
405 /* Open the specified file for read, write or both. On error, this will
|
andrew@0
|
406 ** return a NULL pointer. To find the error number, pass a NULL SNDFILE
|
andrew@0
|
407 ** to sf_perror () or sf_error_str ().
|
andrew@0
|
408 ** All calls to sf_open() should be matched with a call to sf_close().
|
andrew@0
|
409 */
|
andrew@0
|
410
|
andrew@0
|
411 SNDFILE* sf_open (const char *path, int mode, SF_INFO *sfinfo) ;
|
andrew@0
|
412
|
andrew@0
|
413 /* Use the existing file descriptor to create a SNDFILE object. If close_desc
|
andrew@0
|
414 ** is TRUE, the file descriptor will be closed when sf_close() is called. If
|
andrew@0
|
415 ** it is FALSE, the descritor will not be closed.
|
andrew@0
|
416 ** When passed a descriptor like this, the library will assume that the start
|
andrew@0
|
417 ** of file header is at the current file offset. This allows sound files within
|
andrew@0
|
418 ** larger container files to be read and/or written.
|
andrew@0
|
419 ** On error, this will return a NULL pointer. To find the error number, pass a
|
andrew@0
|
420 ** NULL SNDFILE to sf_perror () or sf_error_str ().
|
andrew@0
|
421 ** All calls to sf_open_fd() should be matched with a call to sf_close().
|
andrew@0
|
422
|
andrew@0
|
423 */
|
andrew@0
|
424
|
andrew@0
|
425 SNDFILE* sf_open_fd (int fd, int mode, SF_INFO *sfinfo, int close_desc) ;
|
andrew@0
|
426
|
andrew@0
|
427 SNDFILE* sf_open_virtual (SF_VIRTUAL_IO *sfvirtual, int mode, SF_INFO *sfinfo, void *user_data) ;
|
andrew@0
|
428
|
andrew@0
|
429 /* sf_error () returns a error number which can be translated to a text
|
andrew@0
|
430 ** string using sf_error_number().
|
andrew@0
|
431 */
|
andrew@0
|
432
|
andrew@0
|
433 int sf_error (SNDFILE *sndfile) ;
|
andrew@0
|
434
|
andrew@0
|
435 /* sf_strerror () returns to the caller a pointer to the current error message for
|
andrew@0
|
436 ** the given SNDFILE.
|
andrew@0
|
437 */
|
andrew@0
|
438
|
andrew@0
|
439 const char* sf_strerror (SNDFILE *sndfile) ;
|
andrew@0
|
440
|
andrew@0
|
441 /* sf_error_number () allows the retrieval of the error string for each internal
|
andrew@0
|
442 ** error number.
|
andrew@0
|
443 **
|
andrew@0
|
444 */
|
andrew@0
|
445
|
andrew@0
|
446 const char* sf_error_number (int errnum) ;
|
andrew@0
|
447
|
andrew@0
|
448 /* The following three error functions are deprecated but they will remain in the
|
andrew@0
|
449 ** library for the forseeable future. The function sf_strerror() should be used
|
andrew@0
|
450 ** in their place.
|
andrew@0
|
451 */
|
andrew@0
|
452
|
andrew@0
|
453 int sf_perror (SNDFILE *sndfile) ;
|
andrew@0
|
454 int sf_error_str (SNDFILE *sndfile, char* str, size_t len) ;
|
andrew@0
|
455
|
andrew@0
|
456
|
andrew@0
|
457 /* Return TRUE if fields of the SF_INFO struct are a valid combination of values. */
|
andrew@0
|
458
|
andrew@0
|
459 int sf_command (SNDFILE *sndfile, int command, void *data, int datasize) ;
|
andrew@0
|
460
|
andrew@0
|
461 /* Return TRUE if fields of the SF_INFO struct are a valid combination of values. */
|
andrew@0
|
462
|
andrew@0
|
463 int sf_format_check (const SF_INFO *info) ;
|
andrew@0
|
464
|
andrew@0
|
465 /* Seek within the waveform data chunk of the SNDFILE. sf_seek () uses
|
andrew@0
|
466 ** the same values for whence (SEEK_SET, SEEK_CUR and SEEK_END) as
|
andrew@0
|
467 ** stdio.h function fseek ().
|
andrew@0
|
468 ** An offset of zero with whence set to SEEK_SET will position the
|
andrew@0
|
469 ** read / write pointer to the first data sample.
|
andrew@0
|
470 ** On success sf_seek returns the current position in (multi-channel)
|
andrew@0
|
471 ** samples from the start of the file.
|
andrew@0
|
472 ** Please see the libsndfile documentation for moving the read pointer
|
andrew@0
|
473 ** separately from the write pointer on files open in mode SFM_RDWR.
|
andrew@0
|
474 ** On error all of these functions return -1.
|
andrew@0
|
475 */
|
andrew@0
|
476
|
andrew@0
|
477 sf_count_t sf_seek (SNDFILE *sndfile, sf_count_t frames, int whence) ;
|
andrew@0
|
478
|
andrew@0
|
479 /* Functions for retrieving and setting string data within sound files.
|
andrew@0
|
480 ** Not all file types support this features; AIFF and WAV do. For both
|
andrew@0
|
481 ** functions, the str_type parameter must be one of the SF_STR_* values
|
andrew@0
|
482 ** defined above.
|
andrew@0
|
483 ** On error, sf_set_string() returns non-zero while sf_get_string()
|
andrew@0
|
484 ** returns NULL.
|
andrew@0
|
485 */
|
andrew@0
|
486
|
andrew@0
|
487 int sf_set_string (SNDFILE *sndfile, int str_type, const char* str) ;
|
andrew@0
|
488
|
andrew@0
|
489 const char* sf_get_string (SNDFILE *sndfile, int str_type) ;
|
andrew@0
|
490
|
andrew@0
|
491 /* Functions for reading/writing the waveform data of a sound file.
|
andrew@0
|
492 */
|
andrew@0
|
493
|
andrew@0
|
494 sf_count_t sf_read_raw (SNDFILE *sndfile, void *ptr, sf_count_t bytes) ;
|
andrew@0
|
495 sf_count_t sf_write_raw (SNDFILE *sndfile, const void *ptr, sf_count_t bytes) ;
|
andrew@0
|
496
|
andrew@0
|
497 /* Functions for reading and writing the data chunk in terms of frames.
|
andrew@0
|
498 ** The number of items actually read/written = frames * number of channels.
|
andrew@0
|
499 ** sf_xxxx_raw read/writes the raw data bytes from/to the file
|
andrew@0
|
500 ** sf_xxxx_short passes data in the native short format
|
andrew@0
|
501 ** sf_xxxx_int passes data in the native int format
|
andrew@0
|
502 ** sf_xxxx_float passes data in the native float format
|
andrew@0
|
503 ** sf_xxxx_double passes data in the native double format
|
andrew@0
|
504 ** All of these read/write function return number of frames read/written.
|
andrew@0
|
505 */
|
andrew@0
|
506
|
andrew@0
|
507 sf_count_t sf_readf_short (SNDFILE *sndfile, short *ptr, sf_count_t frames) ;
|
andrew@0
|
508 sf_count_t sf_writef_short (SNDFILE *sndfile, const short *ptr, sf_count_t frames) ;
|
andrew@0
|
509
|
andrew@0
|
510 sf_count_t sf_readf_int (SNDFILE *sndfile, int *ptr, sf_count_t frames) ;
|
andrew@0
|
511 sf_count_t sf_writef_int (SNDFILE *sndfile, const int *ptr, sf_count_t frames) ;
|
andrew@0
|
512
|
andrew@0
|
513 sf_count_t sf_readf_float (SNDFILE *sndfile, float *ptr, sf_count_t frames) ;
|
andrew@0
|
514 sf_count_t sf_writef_float (SNDFILE *sndfile, const float *ptr, sf_count_t frames) ;
|
andrew@0
|
515
|
andrew@0
|
516 sf_count_t sf_readf_double (SNDFILE *sndfile, double *ptr, sf_count_t frames) ;
|
andrew@0
|
517 sf_count_t sf_writef_double (SNDFILE *sndfile, const double *ptr, sf_count_t frames) ;
|
andrew@0
|
518
|
andrew@0
|
519 /* Functions for reading and writing the data chunk in terms of items.
|
andrew@0
|
520 ** Otherwise similar to above.
|
andrew@0
|
521 ** All of these read/write function return number of items read/written.
|
andrew@0
|
522 */
|
andrew@0
|
523
|
andrew@0
|
524 sf_count_t sf_read_short (SNDFILE *sndfile, short *ptr, sf_count_t items) ;
|
andrew@0
|
525 sf_count_t sf_write_short (SNDFILE *sndfile, const short *ptr, sf_count_t items) ;
|
andrew@0
|
526
|
andrew@0
|
527 sf_count_t sf_read_int (SNDFILE *sndfile, int *ptr, sf_count_t items) ;
|
andrew@0
|
528 sf_count_t sf_write_int (SNDFILE *sndfile, const int *ptr, sf_count_t items) ;
|
andrew@0
|
529
|
andrew@0
|
530 sf_count_t sf_read_float (SNDFILE *sndfile, float *ptr, sf_count_t items) ;
|
andrew@0
|
531 sf_count_t sf_write_float (SNDFILE *sndfile, const float *ptr, sf_count_t items) ;
|
andrew@0
|
532
|
andrew@0
|
533 sf_count_t sf_read_double (SNDFILE *sndfile, double *ptr, sf_count_t items) ;
|
andrew@0
|
534 sf_count_t sf_write_double (SNDFILE *sndfile, const double *ptr, sf_count_t items) ;
|
andrew@0
|
535
|
andrew@0
|
536 /* Close the SNDFILE and clean up all memory allocations associated with this
|
andrew@0
|
537 ** file.
|
andrew@0
|
538 ** Returns 0 on success, or an error number.
|
andrew@0
|
539 */
|
andrew@0
|
540
|
andrew@0
|
541 int sf_close (SNDFILE *sndfile) ;
|
andrew@0
|
542
|
andrew@0
|
543 /* If the file is opened SFM_WRITE or SFM_RDWR, call fsync() on the file
|
andrew@0
|
544 ** to force the writing of data to disk. If the file is opened SFM_READ
|
andrew@0
|
545 ** no action is taken.
|
andrew@0
|
546 */
|
andrew@0
|
547
|
andrew@0
|
548 void sf_write_sync (SNDFILE *sndfile) ;
|
andrew@0
|
549
|
andrew@0
|
550 #ifdef __cplusplus
|
andrew@0
|
551 } /* extern "C" */
|
andrew@0
|
552 #endif /* __cplusplus */
|
andrew@0
|
553
|
andrew@0
|
554 #endif /* SNDFILE_H */
|