Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
748 lines (619 sloc) 28.5 KB
;;; sndfile.xtm -- libsndfile bindings for Extempore
;; Author: Ben Swift
;; Keywords: extempore
;; Required dylibs: libsndfile
;;; Commentary:
;; /*
;; ** Copyright (C) 1999-2016 Erik de Castro Lopo <erikd@mega-nerd.com>
;; **
;; ** This program is free software; you can redistribute it and/or modify
;; ** it under the terms of the GNU Lesser General Public License as published by
;; ** the Free Software Foundation; either version 2.1 of the License, or
;; ** (at your option) any later version.
;; **
;; ** This program is distributed in the hope that it will be useful,
;; ** but WITHOUT ANY WARRANTY; without even the implied warranty of
;; ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; ** GNU Lesser General Public License for more details.
;; **
;; ** You should have received a copy of the GNU Lesser General Public License
;; ** along with this program; if not, write to the Free Software
;; ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
;; */
;; /*
;; ** sndfile.h -- system-wide definitions
;; **
;; ** API documentation is in the doc/ directory of the source code tarball
;; ** and at http://www.mega-nerd.com/libsndfile/api.html.
;; */
;;; Code:
(if *impc:compiler:with-cache* (sys:load "libs/aot-cache/sndfile.xtm" 'quiet))
(sys:load-preload-check 'sndfile)
(define *xtmlib-sndfile-loaded* #t)
(impc:aot:suppress-aot-do
(sys:load "libs/base/base.xtm"))
(impc:aot:insert-forms (sys:load "libs/base/base.xtm" 'quiet))
(impc:aot:insert-header "xtmsndfile")
(bind-dylib libsndfile
(cond ((string=? (sys:platform) "OSX") "libsndfile.dylib")
((string=? (sys:platform) "Linux") "libsndfile.so")
((string=? (sys:platform) "Windows") "sndfile.dll"))
"xtmsndfile")
(impc:aot:import-ll "xtmsndfile")
;; /* The following file types can be read and written.
;; ** A file type would consist of a major type (ie SF_FORMAT_WAV) bitwise
;; ** ORed with a minor type (ie SF_FORMAT_PCM). SF_FORMAT_TYPEMASK and
;; ** SF_FORMAT_SUBMASK can be used to separate the major and minor file
;; ** types.
;; */
(bind-val SF_FORMAT_WAV enum #x010000) ;; /* Microsoft WAV format (little endian default). */
(bind-val SF_FORMAT_AIFF enum #x020000) ;; /* Apple/SGI AIFF format (big endian). */
(bind-val SF_FORMAT_AU enum #x030000) ;; /* Sun/NeXT AU format (big endian). */
(bind-val SF_FORMAT_RAW enum #x040000) ;; /* RAW PCM data. */
(bind-val SF_FORMAT_PAF enum #x050000) ;; /* Ensoniq PARIS file format. */
(bind-val SF_FORMAT_SVX enum #x060000) ;; /* Amiga IFF / SVX8 / SV16 format. */
(bind-val SF_FORMAT_NIST enum #x070000) ;; /* Sphere NIST format. */
(bind-val SF_FORMAT_VOC enum #x080000) ;; /* VOC files. */
(bind-val SF_FORMAT_IRCAM enum #x0A0000) ;; /* Berkeley/IRCAM/CARL */
(bind-val SF_FORMAT_W64 enum #x0B0000) ;; /* Sonic Foundry's 64 bit RIFF/WAV */
(bind-val SF_FORMAT_MAT4 enum #x0C0000) ;; /* Matlab (tm) V4.2 / GNU Octave 2.0 */
(bind-val SF_FORMAT_MAT5 enum #x0D0000) ;; /* Matlab (tm) V5.0 / GNU Octave 2.1 */
(bind-val SF_FORMAT_PVF enum #x0E0000) ;; /* Portable Voice Format */
(bind-val SF_FORMAT_XI enum #x0F0000) ;; /* Fasttracker 2 Extended Instrument */
(bind-val SF_FORMAT_HTK enum #x100000) ;; /* HMM Tool Kit format */
(bind-val SF_FORMAT_SDS enum #x110000) ;; /* Midi Sample Dump Standard */
(bind-val SF_FORMAT_AVR enum #x120000) ;; /* Audio Visual Research */
(bind-val SF_FORMAT_WAVEX enum #x130000) ;; /* MS WAVE with WAVEFORMATEX */
(bind-val SF_FORMAT_SD2 enum #x160000) ;; /* Sound Designer 2 */
(bind-val SF_FORMAT_FLAC enum #x170000) ;; /* FLAC lossless file format */
(bind-val SF_FORMAT_CAF enum #x180000) ;; /* Core Audio File format */
(bind-val SF_FORMAT_WVE enum #x190000) ;; /* Psion WVE format */
(bind-val SF_FORMAT_OGG enum #x200000) ;; /* Xiph OGG container */
(bind-val SF_FORMAT_MPC2K enum #x210000) ;; /* Akai MPC 2000 sampler */
(bind-val SF_FORMAT_RF64 enum #x220000) ;; /* RF64 WAV file */
(bind-val SF_FORMAT_PCM_S8 enum #x0001) ;; /* Signed 8 bit data */
(bind-val SF_FORMAT_PCM_16 enum #x0002) ;; /* Signed 16 bit data */
(bind-val SF_FORMAT_PCM_24 enum #x0003) ;; /* Signed 24 bit data */
(bind-val SF_FORMAT_PCM_32 enum #x0004) ;; /* Signed 32 bit data */
(bind-val SF_FORMAT_PCM_U8 enum #x0005) ;; /* Unsigned 8 bit data (WAV and RAW only) */
(bind-val SF_FORMAT_FLOAT enum #x0006) ;; /* 32 bit float data */
(bind-val SF_FORMAT_DOUBLE enum #x0007) ;; /* 64 bit float data */
(bind-val SF_FORMAT_ULAW enum #x0010) ;; /* U-Law encoded. */
(bind-val SF_FORMAT_ALAW enum #x0011) ;; /* A-Law encoded. */
(bind-val SF_FORMAT_IMA_ADPCM enum #x0012) ;; /* IMA ADPCM. */
(bind-val SF_FORMAT_MS_ADPCM enum #x0013) ;; /* Microsoft ADPCM. */
(bind-val SF_FORMAT_GSM610 enum #x0020) ;; /* GSM 6.10 encoding. */
(bind-val SF_FORMAT_VOX_ADPCM enum #x0021) ;; /* OKI / Dialogix ADPCM */
(bind-val SF_FORMAT_G721_32 enum #x0030) ;; /* 32kbs G721 ADPCM encoding. */
(bind-val SF_FORMAT_G723_24 enum #x0031) ;; /* 24kbs G723 ADPCM encoding. */
(bind-val SF_FORMAT_G723_40 enum #x0032) ;; /* 40kbs G723 ADPCM encoding. */
(bind-val SF_FORMAT_DWVW_12 enum #x0040) ;; /* 12 bit Delta Width Variable Word encoding. */
(bind-val SF_FORMAT_DWVW_16 enum #x0041) ;; /* 16 bit Delta Width Variable Word encoding. */
(bind-val SF_FORMAT_DWVW_24 enum #x0042) ;; /* 24 bit Delta Width Variable Word encoding. */
(bind-val SF_FORMAT_DWVW_N enum #x0043) ;; /* N bit Delta Width Variable Word encoding. */
(bind-val SF_FORMAT_DPCM_8 enum #x0050) ;; /* 8 bit differential PCM (XI only) */
(bind-val SF_FORMAT_DPCM_16 enum #x0051) ;; /* 16 bit differential PCM (XI only) */
(bind-val SF_FORMAT_VORBIS enum #x0060) ;; /* Xiph Vorbis encoding. */
(bind-val SF_ENDIAN_FILE enum #x00000000) ;; /* Default file endian-ness. */
(bind-val SF_ENDIAN_LITTLE enum #x10000000) ;; /* Force little endian-ness. */
(bind-val SF_ENDIAN_BIG enum #x20000000) ;; /* Force big endian-ness. */
(bind-val SF_ENDIAN_CPU enum #x30000000) ;; /* Force CPU endian-ness. */
(bind-val SF_FORMAT_SUBMASK enum #x0000FFFF)
(bind-val SF_FORMAT_TYPEMASK enum #x0FFF0000)
(bind-val SF_FORMAT_ENDMASK enum #x30000000)
;; /*
;; ** The following are the valid command numbers for the sf_command()
;; ** interface. The use of these commands is documented in the file
;; ** command.html in the doc directory of the source code distribution.
;; */
(bind-val SFC_GET_LIB_VERSION enum #x1000)
(bind-val SFC_GET_LOG_INFO enum #x1001)
(bind-val SFC_GET_CURRENT_SF_INFO enum #x1002)
(bind-val SFC_GET_NORM_DOUBLE enum #x1010)
(bind-val SFC_GET_NORM_FLOAT enum #x1011)
(bind-val SFC_SET_NORM_DOUBLE enum #x1012)
(bind-val SFC_SET_NORM_FLOAT enum #x1013)
(bind-val SFC_SET_SCALE_FLOAT_INT_READ enum #x1014)
(bind-val SFC_SET_SCALE_INT_FLOAT_WRITE enum #x1015)
(bind-val SFC_GET_SIMPLE_FORMAT_COUNT enum #x1020)
(bind-val SFC_GET_SIMPLE_FORMAT enum #x1021)
(bind-val SFC_GET_FORMAT_INFO enum #x1028)
(bind-val SFC_GET_FORMAT_MAJOR_COUNT enum #x1030)
(bind-val SFC_GET_FORMAT_MAJOR enum #x1031)
(bind-val SFC_GET_FORMAT_SUBTYPE_COUNT enum #x1032)
(bind-val SFC_GET_FORMAT_SUBTYPE enum #x1033)
(bind-val SFC_CALC_SIGNAL_MAX enum #x1040)
(bind-val SFC_CALC_NORM_SIGNAL_MAX enum #x1041)
(bind-val SFC_CALC_MAX_ALL_CHANNELS enum #x1042)
(bind-val SFC_CALC_NORM_MAX_ALL_CHANNELS enum #x1043)
(bind-val SFC_GET_SIGNAL_MAX enum #x1044)
(bind-val SFC_GET_MAX_ALL_CHANNELS enum #x1045)
(bind-val SFC_SET_ADD_PEAK_CHUNK enum #x1050)
(bind-val SFC_SET_ADD_HEADER_PAD_CHUNK enum #x1051)
(bind-val SFC_UPDATE_HEADER_NOW enum #x1060)
(bind-val SFC_SET_UPDATE_HEADER_AUTO enum #x1061)
(bind-val SFC_FILE_TRUNCATE enum #x1080)
(bind-val SFC_SET_RAW_START_OFFSET enum #x1090)
(bind-val SFC_SET_DITHER_ON_WRITE enum #x10A0)
(bind-val SFC_SET_DITHER_ON_READ enum #x10A1)
(bind-val SFC_GET_DITHER_INFO_COUNT enum #x10A2)
(bind-val SFC_GET_DITHER_INFO enum #x10A3)
(bind-val SFC_GET_EMBED_FILE_INFO enum #x10B0)
(bind-val SFC_SET_CLIPPING enum #x10C0)
(bind-val SFC_GET_CLIPPING enum #x10C1)
(bind-val SFC_GET_INSTRUMENT enum #x10D0)
(bind-val SFC_SET_INSTRUMENT enum #x10D1)
(bind-val SFC_GET_LOOP_INFO enum #x10E0)
(bind-val SFC_GET_BROADCAST_INFO enum #x10F0)
(bind-val SFC_SET_BROADCAST_INFO enum #x10F1)
(bind-val SFC_GET_CHANNEL_MAP_INFO enum #x1100)
(bind-val SFC_SET_CHANNEL_MAP_INFO enum #x1101)
(bind-val SFC_RAW_DATA_NEEDS_ENDSWAP enum #x1110)
(bind-val SFC_WAVEX_SET_AMBISONIC enum #x1200)
(bind-val SFC_WAVEX_GET_AMBISONIC enum #x1201)
(bind-val SFC_SET_VBR_ENCODING_QUALITY enum #x1300)
(bind-val SFC_TEST_IEEE_FLOAT_REPLACE enum #x6001)
;; /*
;; ** SFC_SET_ADD_* values are deprecated and will disappear at some
;; ** time in the future. They are guaranteed to be here up to and
;; ** including version 1.0.8 to avoid breakage of existng software.
;; ** They currently do nothing and will continue to do nothing.
;; */
(bind-val SFC_SET_ADD_DITHER_ON_WRITE enum #x1070)
(bind-val SFC_SET_ADD_DITHER_ON_READ enum #x1071)
;; /*
;; ** String types that can be set and read from files. Not all file types
;; ** support this and even the file types which support one, may not support
;; ** all string types.
;; */
(bind-val SF_STR_TITLE enum #x01)
(bind-val SF_STR_COPYRIGHT enum #x02)
(bind-val SF_STR_SOFTWARE enum #x03)
(bind-val SF_STR_ARTIST enum #x04)
(bind-val SF_STR_COMMENT enum #x05)
(bind-val SF_STR_DATE enum #x06)
(bind-val SF_STR_ALBUM enum #x07)
(bind-val SF_STR_LICENSE enum #x08)
(bind-val SF_STR_TRACKNUMBER enum #x09)
(bind-val SF_STR_GENRE enum #x10)
;; /*
;; ** Use the following as the start and end index when doing metadata
;; ** transcoding.
;; */
(bind-val SF_STR_FIRST i32 SF_STR_TITLE)
(bind-val SF_STR_LAST i32 SF_STR_GENRE)
;; /* True and false */
(bind-val SF_FALSE enum 0)
(bind-val SF_TRUE enum 1)
;; /* Modes for opening files. */
(bind-val SFM_READ enum #x10)
(bind-val SFM_WRITE enum #x20)
(bind-val SFM_RDWR enum #x30)
(bind-val SF_AMBISONIC_NONE enum #x40)
(bind-val SF_AMBISONIC_B_FORMAT enum #x4)
;; /* Public error values. These are guaranteed to remain unchanged for the duration
;; ** of the library major version number.
;; ** There are also a large number of private error numbers which are internal to
;; ** the library which can change at any time.
;; */
(bind-val SF_ERR_NO_ERROR enum 0)
(bind-val SF_ERR_UNRECOGNISED_FORMAT enum 1)
(bind-val SF_ERR_SYSTEM enum 2)
(bind-val SF_ERR_MALFORMED_FILE enum 3)
(bind-val SF_ERR_UNSUPPORTED_ENCODING enum 4)
;; /* Channel map values (used with SFC_SET/GET_CHANNEL_MAP).
;; */
(bind-val SF_CHANNEL_MAP_INVALID enum 0)
(bind-val SF_CHANNEL_MAP_MONO enum 1)
(bind-val SF_CHANNEL_MAP_LEFT enum 2) ;; /* Apple calls this 'Left' */
(bind-val SF_CHANNEL_MAP_RIGHT enum 3) ;; /* Apple calls this 'Right' */
(bind-val SF_CHANNEL_MAP_CENTER enum 4) ;; /* Apple calls this 'Center' */
(bind-val SF_CHANNEL_MAP_FRONT_LEFT enum 5)
(bind-val SF_CHANNEL_MAP_FRONT_RIGHT enum 6)
(bind-val SF_CHANNEL_MAP_FRONT_CENTER enum 7)
(bind-val SF_CHANNEL_MAP_REAR_CENTER enum 8) ;; /* Apple calls this 'Center Surround', Msft calls this 'Back Center' */
(bind-val SF_CHANNEL_MAP_REAR_LEFT enum 9) ;; /* Apple calls this 'Left Surround', Msft calls this 'Back Left' */
(bind-val SF_CHANNEL_MAP_REAR_RIGHT enum 10) ;; /* Apple calls this 'Right Surround', Msft calls this 'Back Right' */
(bind-val SF_CHANNEL_MAP_LFE enum 11) ;; /* Apple calls this 'LFEScreen', Msft calls this 'Low Frequency' */
(bind-val SF_CHANNEL_MAP_FRONT_LEFT_OF_CENTER enum 12) ;; /* Apple calls this 'Left Center' */
(bind-val SF_CHANNEL_MAP_FRONT_RIGHT_OF_CENTER enum 13) ;; /* Apple calls this 'Right Center */
(bind-val SF_CHANNEL_MAP_SIDE_LEFT enum 14) ;; /* Apple calls this 'Left Surround Direct' */
(bind-val SF_CHANNEL_MAP_SIDE_RIGHT enum 15) ;; /* Apple calls this 'Right Surround Direct' */
(bind-val SF_CHANNEL_MAP_TOP_CENTER enum 16) ;; /* Apple calls this 'Top Center Surround' */
(bind-val SF_CHANNEL_MAP_TOP_FRONT_LEFT enum 17) ;; /* Apple calls this 'Vertical Height Left' */
(bind-val SF_CHANNEL_MAP_TOP_FRONT_RIGHT enum 18) ;; /* Apple calls this 'Vertical Height Right' */
(bind-val SF_CHANNEL_MAP_TOP_FRONT_CENTER enum 19) ;; /* Apple calls this 'Vertical Height Center' */
(bind-val SF_CHANNEL_MAP_TOP_REAR_LEFT enum 20) ;; /* Apple and MS call this 'Top Back Left' */
(bind-val SF_CHANNEL_MAP_TOP_REAR_RIGHT enum 21) ;; /* Apple and MS call this 'Top Back Right' */
(bind-val SF_CHANNEL_MAP_TOP_REAR_CENTER enum 22) ;; /* Apple and MS call this 'Top Back Center' */
(bind-val SF_CHANNEL_MAP_AMBISONIC_B_W enum 23)
(bind-val SF_CHANNEL_MAP_AMBISONIC_B_X enum 24)
(bind-val SF_CHANNEL_MAP_AMBISONIC_B_Y enum 25)
(bind-val SF_CHANNEL_MAP_AMBISONIC_B_Z enum 26)
(bind-val SF_CHANNEL_MAP_MAX enum 27)
;; /* A SNDFILE* pointer can be passed around much like stdio.h's FILE* pointer. */
(bind-alias SNDFILE i8)
;; /* The following typedef is system specific and is defined when libsndfile is
;; ** compiled. i64 will be a 64 bit value when the underlying OS allows
;; ** 64 bit file offsets.
;; ** On windows, we need to allow the same header file to be compiler by both GCC
;; ** and the Microsoft compiler.
;; */
(bind-alias sf_count_t i64)
(bind-val SF_COUNT_MAX sf_count_t #x7fffffffffffffff)
;; /* A pointer to a SF_INFO structure is passed to sf_open () and filled in.
;; ** On write, the SF_INFO structure is filled in by the user and passed into
;; ** sf_open ().
;; */
;; struct SF_INFO
;; { i64 frames ; ;; /* Used to be called samples. Changed to avoid confusion. */
;; int samplerate ;
;; int channels ;
;; int format ;
;; int sections ;
;; int seekable ;
;; } ;
(bind-type SF_INFO <i64,i32,i32,i32,i32,i32>)
;; /* The SF_FORMAT_INFO struct is used to retrieve information about the sound
;; ** file formats libsndfile supports using the sf_command () interface.
;; **
;; ** Using this interface will allow applications to support new file formats
;; ** and encoding types when libsndfile is upgraded, without requiring
;; ** re-compilation of the application.
;; **
;; ** Please consult the libsndfile documentation (particularly the information
;; ** on the sf_command () interface) for examples of its use.
;; */
;; { int format ;
;; const char *name ;
;; const char *extension ;
;; } SF_FORMAT_INFO ;
(bind-type SF_FORMAT_INFO <i32,i8*,i8*>)
;; /*
;; ** Enums and typedefs for adding dither on read and write.
;; ** See the html documentation for sf_command(), SFC_SET_DITHER_ON_WRITE
;; ** and SFC_SET_DITHER_ON_READ.
;; */
;; enum
;; { SFD_DEFAULT_LEVEL = 0,
;; SFD_CUSTOM_LEVEL = 0x40000000,
;; SFD_NO_DITHER = 500,
;; SFD_WHITE = 501,
;; SFD_TRIANGULAR_PDF = 502
;; } ;
(bind-val SFD_DEFAULT_LEVEL enum 0)
(bind-val SFD_CUSTOM_LEVEL enum #x40000000)
(bind-val SFD_NO_DITHER enum 500)
(bind-val SFD_WHITE enum 501)
(bind-val SFD_TRIANGULAR_PDF enum 502)
;; typedef struct
;; { int type ;
;; double level ;
;; const char *name ;
;; } SF_DITHER_INFO ;
(bind-type SF_DITHER_INFO <i32,double,i8*>)
;; /* Struct used to retrieve information about a file embedded within a
;; ** larger file. See SFC_GET_EMBED_FILE_INFO.
;; */
;; { i64 offset ;
;; i64 length ;
;; } SF_EMBED_FILE_INFO ;
(bind-type SF_EMBED_FILE_INFO <i64,i64>)
;; /*
;; ** Structs used to retrieve music sample information from a file.
;; */
;; enum
;; { /*
;; ** The loop mode field in SF_INSTRUMENT will be one of the following.
;; */
;; SF_LOOP_NONE = 800,
;; SF_LOOP_FORWARD,
;; SF_LOOP_BACKWARD,
;; SF_LOOP_ALTERNATING
;; } ;
(bind-val SF_LOOP_NONE enum 800)
(bind-val SF_LOOP_FORWARD enum 801)
(bind-val SF_LOOP_BACKWARD enum 802)
(bind-val SF_LOOP_ALTERNATING enum 803)
;; typedef struct
;; { int gain ;
;; char basenote, detune ;
;; char velocity_lo, velocity_hi ;
;; char key_lo, key_hi ;
;; int loop_count ;
;; struct
;; { int mode ;
;; unsigned int start ;
;; unsigned int end ;
;; unsigned int count ;
;; } loops [16] ; ;; /* make variable in a sensible way */
;; } SF_INSTRUMENT ;
(bind-type SF_INSTRUMENT <i32,i8,i8,i8,i8,i8,i8,i32,|16,<i32,i32,i32,i32>|>)
;; /* Struct used to retrieve loop information from a file.*/
;; typedef struct
;; {
;; short time_sig_num ; /* any positive integer > 0 */
;; short time_sig_den ; /* any positive power of 2 > 0 */
;; int loop_mode ; /* see SF_LOOP enum */
;; int num_beats ; /* this is NOT the amount of quarter notes !!!*/
;; /* a full bar of 4/4 is 4 beats */
;; /* a full bar of 7/8 is 7 beats */
;; float bpm ; /* suggestion, as it can be calculated using other fields:*/
;; /* file's lenght, file's sampleRate and our time_sig_den*/
;; /* -> bpms are always the amount of _quarter notes_ per minute */
;; int root_key ; /* MIDI note, or -1 for None */
;; int future [6] ;
;; } SF_LOOP_INFO ;
(bind-type SF_LOOP_INFO <|2,i8|,|2,i8|,i32,i32,float,i32,|6,i32|>)
;; /* Open the specified file for read, write or both. On error, this will
;; ** return a NULL pointer. To find the error number, pass a NULL SNDFILE
;; ** to sf_strerror ().
;; ** All calls to sf_open() should be matched with a call to sf_close().
;; */
(bind-lib libsndfile sf_open [SNDFILE*,i8*,i32,SF_INFO*]*)
;; /* Use the existing file descriptor to create a SNDFILE object. If close_desc
;; ** is TRUE, the file descriptor will be closed when sf_close() is called. If
;; ** it is FALSE, the descritor will not be closed.
;; ** When passed a descriptor like this, the library will assume that the start
;; ** of file header is at the current file offset. This allows sound files within
;; ** larger container files to be read and/or written.
;; ** On error, this will return a NULL pointer. To find the error number, pass a
;; ** NULL SNDFILE to sf_strerror ().
;; ** All calls to sf_open_fd() should be matched with a call to sf_close().
;; */
(bind-lib libsndfile sf_open_fd [SNDFILE*,i32,i32,SF_INFO*,i32]*)
;; (bind-lib libsndfile sf_open_virtual [SNDFILE*,SF_VIRTUAL_IO*,i32,SF_INFO*,void*]*)
;; /* sf_error () returns a error number which can be translated to a text
;; ** string using sf_error_number().
;; */
(bind-lib libsndfile sf_error [i32,SNDFILE*]*)
;; /* sf_strerror () returns to the caller a pointer to the current error message for
;; ** the given SNDFILE.
;; */
(bind-lib libsndfile sf_strerror [i8*,SNDFILE*]*)
;; /* sf_error_number () allows the retrieval of the error string for each internal
;; ** error number.
;; **
;; */
(bind-lib libsndfile sf_error_number [i8*,i32]*)
;; /* The following two error functions are deprecated but they will remain in the
;; ** library for the forseeable future. The function sf_strerror() should be used
;; ** in their place.
;; */
;; (bind-lib libsndfile sf_perror [i32,SNDFILE*]*)
;; (bind-lib libsndfile sf_error_str [i32,SNDFILE*,i8*,size_t]*)
;; /* Return TRUE if fields of the SF_INFO struct are a valid combination of values. */
(bind-lib libsndfile sf_command [i32,SNDFILE*,i32,i8*,i32]*)
;; /* Return TRUE if fields of the SF_INFO struct are a valid combination of values. */
(bind-lib libsndfile sf_format_check [i32,SF_INFO*]*)
;; /* Seek within the waveform data chunk of the SNDFILE. sf_seek () uses
;; ** the same values for whence (SEEK_SET, SEEK_CUR and SEEK_END) as
;; ** stdio.h function fseek ().
;; ** An offset of zero with whence set to SEEK_SET will position the
;; ** read / write pointer to the first data sample.
;; ** On success sf_seek returns the current position in (multi-channel)
;; ** samples from the start of the file.
;; ** Please see the libsndfile documentation for moving the read pointer
;; ** separately from the write pointer on files open in mode SFM_RDWR.
;; ** On error all of these functions return -1.
;; */
(bind-lib libsndfile sf_seek [i64,SNDFILE*,i64,i32]*)
;; /* Functions for retrieving and setting string data within sound files.
;; ** Not all file types support this features; AIFF and WAV do. For both
;; ** functions, the str_type parameter must be one of the SF_STR_* values
;; ** defined above.
;; ** On error, sf_set_string() returns non-zero while sf_get_string()
;; ** returns NULL.
;; */
(bind-lib libsndfile sf_set_string [i32,SNDFILE*,i32,i8*]*)
(bind-lib libsndfile sf_get_string [i8*,SNDFILE*,i32]*)
;; /* Return the library version string. */
(bind-lib libsndfile sf_version_string [i8*]*)
;; /* Functions for reading/writing the waveform data of a sound file.
;; */
(bind-lib libsndfile sf_read_raw [i64,SNDFILE*,i8*,i64]*)
(bind-lib libsndfile sf_write_raw [i64,SNDFILE*,i8*,i64]*)
;; /* Functions for reading and writing the data chunk in terms of frames.
;; ** The number of items actually read/written = frames * number of channels.
;; ** sf_xxxx_raw read/writes the raw data bytes from/to the file
;; ** sf_xxxx_short passes data in the native short format
;; ** sf_xxxx_int passes data in the native int format
;; ** sf_xxxx_float passes data in the native float format
;; ** sf_xxxx_double passes data in the native double format
;; ** All of these read/write function return number of frames read/written.
;; */
(bind-lib libsndfile sf_readf_short [i64,SNDFILE*,i16*,i64]*)
(bind-lib libsndfile sf_writef_short [i64,SNDFILE*,i16*,i64]*)
(bind-lib libsndfile sf_readf_int [i64,SNDFILE*,i32*,i64]*)
(bind-lib libsndfile sf_writef_int [i64,SNDFILE*,i32*,i64]*)
(bind-lib libsndfile sf_readf_float [i64,SNDFILE*,float*,i64]*)
(bind-lib libsndfile sf_writef_float [i64,SNDFILE*,float*,i64]*)
(bind-lib libsndfile sf_readf_double [i64,SNDFILE*,double*,i64]*)
(bind-lib libsndfile sf_writef_double [i64,SNDFILE*,double*,i64]*)
(bind-poly sf_readf sf_readf_short)
(bind-poly sf_readf sf_readf_int)
(bind-poly sf_readf sf_readf_float)
(bind-poly sf_readf sf_readf_double)
(bind-poly sf_writef sf_writef_short)
(bind-poly sf_writef sf_writef_int)
(bind-poly sf_writef sf_writef_float)
(bind-poly sf_writef sf_writef_double)
;; /* Functions for reading and writing the data chunk in terms of items.
;; ** Otherwise similar to above.
;; ** All of these read/write function return number of items read/written.
;; */
(bind-lib libsndfile sf_read_short [i64,SNDFILE*,i16*,i64]*)
(bind-lib libsndfile sf_write_short [i64,SNDFILE*,i16*,i64]*)
(bind-lib libsndfile sf_read_int [i64,SNDFILE*,i32*,i64]*)
(bind-lib libsndfile sf_write_int [i64,SNDFILE*,i32*,i64]*)
(bind-lib libsndfile sf_read_float [i64,SNDFILE*,float*,i64]*)
(bind-lib libsndfile sf_write_float [i64,SNDFILE*,float*,i64]*)
(bind-lib libsndfile sf_read_double [i64,SNDFILE*,double*,i64]*)
(bind-lib libsndfile sf_write_double [i64,SNDFILE*,double*,i64]*)
(bind-poly sf_read sf_read_short)
(bind-poly sf_read sf_read_int)
(bind-poly sf_read sf_read_float)
(bind-poly sf_read sf_read_double)
(bind-poly sf_write sf_write_short)
(bind-poly sf_write sf_write_int)
(bind-poly sf_write sf_write_float)
(bind-poly sf_write sf_write_double)
;; /* Close the SNDFILE and clean up all memory allocations associated with this
;; ** file.
;; ** Returns 0 on success, or an error number.
;; */
(bind-lib libsndfile sf_close [i32,SNDFILE*]*)
;; /* If the file is opened SFM_WRITE or SFM_RDWR, call fsync() on the file
;; ** to force the writing of data to disk. If the file is opened SFM_READ
;; ** no action is taken.
;; */
(bind-lib libsndfile sf_write_sync [void,SNDFILE*]*)
;; /* The function sf_wchar_open() is Windows Only!
;; ** Open a file passing in a Windows Unicode filename. Otherwise, this is
;; ** the same as sf_open().
;; **
;; ** In order for this to work, you need to do the following:
;; **
;; ** #include <windows.h>
;; ** #define ENABLE_SNDFILE_WINDOWS_PROTOTYPES 1
;; ** #including <sndfile.h>
;; */
;; #if (defined (ENABLE_SNDFILE_WINDOWS_PROTOTYPES) && ENABLE_SNDFILE_WINDOWS_PROTOTYPES)
;; (bind-lib libsndfile sf_wchar_open [SNDFILE*,LPCWSTR,i32,SF_INFO*]*)
;; #endif
;;;;;;;;;;;;;;;;;
;; xtlang code ;;
;;;;;;;;;;;;;;;;;
;; SF_INFO getters/setters
(bind-func sf_frames
(lambda (info:SF_INFO*)
(tref info 0)))
(bind-func sf_set_frames
(lambda (info:SF_INFO* frames)
(tset! info 0 frames)))
(bind-func sf_samplerate
(lambda (info:SF_INFO*)
(tref info 1)))
(bind-func sf_set_samplerate
(lambda (info:SF_INFO* samplerate)
(tset! info 1 samplerate)))
(bind-func sf_channels
(lambda (info:SF_INFO*)
(tref info 2)))
(bind-func sf_set_channels
(lambda (info:SF_INFO* channels)
(tset! info 2 channels)))
(bind-func sf_format
(lambda (info:SF_INFO*)
(tref info 3)))
(bind-func sf_set_format
(lambda (info:SF_INFO* format)
(tset! info 3 format)))
(bind-func sf_sections
(lambda (info:SF_INFO*)
(tref info 4)))
(bind-func sf_set_sections
(lambda (info:SF_INFO* sections)
(tset! info 4 sections)))
(bind-func sf_seekable
(lambda (info:SF_INFO*)
(tref info 5)))
(bind-func sf_set_seekable
(lambda (info:SF_INFO* seekable)
(tset! info 5 seekable)))
(bind-func sf_frames_from_file
"get the total number of frames from an audio file"
(lambda (filename)
(let ((info:SF_INFO* (salloc))
(audiofile (sf_open filename SFM_READ info)))
(if (null? audiofile)
-1
(begin
(sf_close audiofile)
(sf_frames info))))))
(bind-func sf_channels_from_file
"get the total number of channels from an audio file"
(lambda (filename)
(let ((info:SF_INFO* (salloc))
(audiofile (sf_open filename SFM_READ info)))
(if (null? audiofile)
-1
(begin
(sf_close audiofile)
(sf_channels info))))))
(bind-func sf_samples_from_file
"get the total number of samples (* frames channels) from an audio file"
(lambda (filename)
(let ((info:SF_INFO* (salloc))
(audiofile (sf_open filename SFM_READ info)))
(if (null? audiofile)
-1
(begin
(sf_close audiofile)
(* (sf_frames info)
(convert (sf_channels info))))))))
(bind-func sf_read_file_into_buffer
"fill a SAMPLE* buffer with audio data from file
@param filename
@param data - pointer to memory to fill with audio data
@param start - start frame
@param nframes - number of frames to read
@param print_p - print info?"
(lambda (filename data:SAMPLE* start nframes print_p:i1)
(let ((info:SF_INFO* (salloc))
(audiofile (sf_open filename SFM_READ info))
(channels (convert (tref info 2) i64))
(nsamples (* nframes channels))
(sample_idx (* start channels))
(cnt (sf_seek audiofile sample_idx 0))
(nread (sf_read audiofile data nsamples)))
(if (not (null? audiofile))
(begin
(if print_p
(begin
(printf "---------------\n")
(printf "file name: %s\n" filename)
(printf "samplerate: %d\n" (tref info 1))
(printf "channels: %d\n" (tref info 2))
(printf "frames: %d\n" (tref info 0))
(printf "samples read: %lld\n" nread)))
(sf_close audiofile))
(printf "errors: %s\n" (sf_strerror audiofile)))
nread)))
(bind-func sf_print_audio_file_info
"print info about an audio file"
(lambda (filename)
(let ((info:SF_INFO* (salloc))
(audiofile (sf_open filename SFM_READ info))
(channels (sf_channels info)))
(if (null? audiofile)
(begin (printf "Bad audio file!\n")
void)
(let ((nframes (sf_frames info))
(rate (convert (sf_samplerate info)))
(nseconds (/ nframes rate)))
(printf "---------------\n")
(printf "filename: %s\n" filename)
(printf "samplerate: %d\n" rate)
(printf "channels: %d\n" (sf_channels info))
(printf "format: %#x\n" (sf_format info))
(printf "frames: %lld\n" nframes)
(if (< nframes (* 44100 60 1))
(printf "seconds: %f\n" nseconds)
(if (< nframes (* 44100 60 60))
(printf "minutes: %f\n" (/ (convert nseconds double) 60.))
(printf "hours: %f\n" (/ (convert nseconds double) (* 60. 60.)))))
(let ((loops:SF_LOOP_INFO* (alloc))
(lp1 (sf_command audiofile SFC_GET_LOOP_INFO (cast loops i8*) 44)))
(if (= lp1 SF_TRUE)
(printf "loop-mode: %d - bpm(%f)\n" (tref loops 2) (ftod (tref loops 4)))
(printf "loop-mode:\n")))
(let ((inst:SF_INSTRUMENT* (alloc))
(lp2 (sf_command audiofile SFC_GET_INSTRUMENT (cast inst i8*) 270)))
(if (= lp2 SF_TRUE)
(printf "nframes loops: %d\n" (tref inst 7))
(printf "nframes loops: 0\n")))
(sf_close audiofile)
void)))))
(impc:aot:insert-footer "xtmsndfile")
(define *xtmlib-sndfile-loaded* #t)
You can’t perform that action at this time.