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