Mercurial > core / lisp/ffi/sndfile/pkg.lisp
changeset 694: |
a36280d2ef4e |
parent: |
5f81d888c31f
|
child: |
2bad47888dbf |
author: |
Richard Westhaver <ellis@rwest.io> |
date: |
Thu, 03 Oct 2024 21:54:07 -0400 |
permissions: |
-rw-r--r-- |
description: |
tasks |
1 ;;; sndfile.lisp --- low-level bindings to SNDFILE 5 ;; see http://www.mega-nerd.com/libsndfile/api.html 9 (:use :cl :std :sb-alien) 10 (:export :sf-version-string)) 14 (define-alien-loader "sndfile" t "/usr/lib/") 16 (define-alien-type sf-count long) 18 (define-alien-type sf-info 27 (define-alien-type sf-format-info 28 (struct sf-format-info 31 (extension c-string))) 34 (define-alien-enum (sf-seek-mode int) 40 (define-alien-enum (sf-dither int) 42 :custom-level #x40000000 47 (define-alien-type sf-dither-info 48 (struct sf-dither-info 53 (define-alien-type sf-embed-file-info 54 (struct sf-embed-file-info 58 (define-alien-type sf-cue-point 61 (position unsigned-int) 65 (sample-offset unsigned-int) 66 (name (array char 256)))) 68 (define-alien-enum (sf-loop int) 74 (define-alien-type sf-instrument 92 (define-alien-type sf-loop-info 100 (future (array int 6)))) 102 (define-alien-enum (sf-format int) 103 :wav #x010000 ; Microsoft WAV format (little endian default). 104 :aiff #x020000 ; Apple/SGI AIFF format (big endian). 105 :au #x030000 ; Sun/NeXT AU format (big endian). 106 :raw #x040000 ; RAW PCM data. 107 :paf #x050000 ; Ensoniq PARIS file format. 108 :svx #x060000 ; Amiga IFF / SVX8 / SV16 format. 109 :nist #x070000 ; Sphere NIST format. 110 :voc #x080000 ; VOC files. 111 :ircam #x0A0000 ; Berkeley/IRCAM/CARL 112 :w64 #x0B0000 ; Sonic Foundry's 64 bit RIFF/WAV 113 :mat4 #x0C0000 ; Matlab (tm) V4.2 / GNU Octave 2.0 114 :mat5 #x0D0000 ; Matlab (tm) V5.0 / GNU Octave 2.1 115 :pvf #x0E0000 ; Portable Voice Format 116 :xi #x0F0000 ; Fasttracker 2 Extended Instrument 117 :htk #x100000 ; HMM Tool Kit format 118 :sds #x110000 ; Midi Sample Dump Standard 119 :avr #x120000 ; Audio Visual Research 120 :wavex #x130000 ; MS WAVE with WAVEFORMATEX 121 :sd2 #x160000 ; Sound Designer 2 122 :flac #x170000 ; FLAC lossless file format 123 :caf #x180000) ; Core Audio File format 125 (define-alien-enum (sf-format-subtype int) 127 :pcm-s8 #x0001 ; Signed 8 bit data 128 :pcm-16 #x0002 ; Signed 16 bit data 129 :pcm-24 #x0003 ; Signed 24 bit data 130 :pcm-32 #x0004 ; Signed 32 bit data 131 :pcm-u8 #x0005 ; Unsigned 8 bit data (WAV and RAW only) 133 :float #x0006 ; 32 bit float data 134 :double #x0007 ; 64 bit float data 136 :ulaw #x0010 ; U-Law encoded. 137 :alaw #x0011 ; A-Law encoded. 138 :ima-adpcm #x0012 ; IMA ADPCM. 139 :ms-adpcm #x0013 ; Microsoft ADPCM. 141 :gsm610 #x0020 ; GSM 6.10 encoding. 142 :vox-adpcm #x0021 ; OKI / Dialogix ADPCM 144 :g721-32 #x0030 ; 32kbs G721 ADPCM encoding. 145 :g723-24 #x0031 ; 24kbs G723 ADPCM encoding. 146 :g723-40 #x0032 ; 40kbs G723 ADPCM encoding. 147 :-dwvw-12 #x0040 ; 12 bit Delta Width Variable Word encoding. 148 :dwvw-16 #x0041 ; 16 bit Delta Width Variable Word encoding. 149 :dwvw-24 #x0042 ; 24 bit Delta Width Variable Word encoding. 150 :dwvw-n #x0043 ; N bit Delta Width Variable Word encoding. 152 :dpcm-8 #x0050 ; 8 bit differential PCM (XI only) 153 :dpcm-16 #x0051) ; 16 bit differential PCM (XI only) 155 (defun decode-bitflags (value flag-names) 156 (loop for symbol in flag-names 157 as flag-value = (symbol-value symbol) 158 when (= flag-value (logand value flag-value)) 161 (defun match-field (value flag-names) 162 (loop for symbol in flag-names 163 when (= value (symbol-value symbol)) 166 ;;;; Endian-ness options. 167 (define-alien-enum (sf-endian int) 168 :file #x00000000 ; Default file endian-ness. 169 :little #x10000000 ; Force little endian-ness. 170 :big #x20000000 ; Force big endian-ness. 171 :cpu #x30000000) ; Force CPU endian-ness. 174 (define-alien-enum (sf-format-mask int) 179 (define-alien-enum (sf-str int) 187 ;;;; Public error numbers 188 (define-alien-enum (sf-err int) 190 :unrecognized-format 1 193 :unsupported-encoding 4) 196 (define-alien-enum (sf-command-op int) 197 :get-lib-version #x1000 199 :get-current-sf-info #x1002 200 :get-norm-double #x1010 201 :get-norm-float #x1011 202 :set-norm-double #x1012 203 :set-norm-float #x1013 204 :set-scale-float-int-read #x1014 205 :set-scale-int-float-write #x1015 206 :get-simple-format-count #x1020 207 :get-simple-format #x1021 208 :get-format-info #x1028 209 :get-format-major-count #x1030 210 :get-format-major #x1031 211 :get-format-subtype-count #x1032 212 :get-format-subtype #x1033 213 :calc-signal-max #x1040 214 :calc-norm-signal-max #x1041 215 :calc-max-all-channels #x1042 216 :calc-norm-max-all-channels #x1043 217 :get-signal-max #x1044 218 :get-max-all-channels #x1045 219 :set-add-peak-chunk #x1050 220 :update-header-now #x1060 221 :set-update-header-auto #x1061 222 :file-truncate #x1080 223 :set-raw-start-offset #x1090 224 ;; /* Commands reserved for dithering, which is not implemented. */ 225 :set-dither-on-write #x10A0 226 :set-dither-on-read #x10A1 227 :get-dither-info-count #x10A2 228 :get-dither-info #x10A3 229 :get-embed-file-info #x10B0 232 :get-cue-count #x10CD 235 :get-instrument #x10D0 236 :set-instrument #x10D1 237 :get-loop-info #x10E0 238 :get-broadcast-info #x10F0 239 :set-broadcast-info #x10F1 240 :get-channel-map-info #x1100 241 :set-channel-map-info #x1101 242 :raw-data-needs-endswap #x1110 243 ;; /* Support for Wavex Ambisonics Format */ 244 :wavex-set-ambisonic #x1200 245 :wavex-get-ambisonic #x1201 246 ;; RF64 files can be set so that on-close, writable files 247 ;; that have less than 4GB of data in them are converted to 248 ;; RIFF/WAV, as per EBU recommendations. 249 :rf64-auto-downgrade #x1210 250 :set-vbr-encoding-quality #x1300 251 :set-compression-level #x1301 252 ;; /* Ogg format commands */ 253 :set-ogg-page-latency-ms #x1302 254 :set-ogg-page-latency #x1303 255 :get-ogg-stream-serialno #x1306 256 :get-bitrate-mode #x1304 257 :set-bitrate-mode #x1305 258 ;; /* Cart Chunk support */ 259 :set-cart-info #x1400 260 :get-cart-info #x1401 261 ;; /* Opus files original samplerate metadata */ 262 :set-original-samplerate #x1500 263 :get-original-samplerate #x1501 264 ;; /* Following commands for testing only. */ 265 :test-ieee-float-replace #x6001 266 ;; These SFC_SET_ADD_* values are deprecated and will 267 ;; disappear at some time in the future. They are 268 ;; guaranteed to be here up to and including version 1.0.8 269 ;; to avoid breakage of existing software. They currently 270 ;; do nothing and will continue to do nothing. 271 :set-add-header-pad-chunk #x1051 272 :set-add-dither-on-write #x1070 273 :set-add-dither-on-read #x1071) 276 (define-opaque sndfile t) 278 (define-alien-routine sf-open (* sndfile) (path c-string) (mode int) (sfinfo (* sf-info))) 279 (define-alien-routine sf-open-fd (* sndfile) (fd int) (mode int) (sfinfo (* sf-info))) 280 (define-alien-routine sf-error int (sndfile (* sndfile))) 281 (define-alien-routine sf-strerror c-string (sndfile (* sndfile))) 282 (define-alien-routine sf-error-number c-string (errnum int)) 283 (define-alien-routine sf-perror int (sndfile (* sndfile))) 284 (define-alien-routine sf-error-str int (sndfile (* sndfile)) (str c-string) (len size-t)) 285 (define-alien-routine sf-command int (sndfile (* sndfile)) (command int) (data (* t)) (datasize int)) 286 (define-alien-routine sf-format-check int (info (* sf-info))) 287 (define-alien-routine sf-seek sf-count (sndfile (* sndfile)) (frames sf-count) (whence int)) 289 (define-alien-routine sf-set-string int (sndfile (* sndfile)) (str-type int) (str c-string)) 290 (define-alien-routine sf-get-string c-string (sndfile (* sndfile)) (str-type int)) 291 (define-alien-routine sf-version-string c-string) 292 (define-alien-routine sf-current-byterate int (sndfile (* sndfile))) 293 (define-alien-routine sf-read-raw sf-count (sndfile (* sndfile)) (ptr (* t)) (bytes sf-count)) 294 (define-alien-routine sf-write-raw sf-count (sndfile (* sndfile)) (ptr (* t)) (bytes sf-count)) 296 (define-alien-routine sf-close int (sndfile (* sndfile))) 298 (define-alien-routine sf-write-sync void 299 (sndfile (* sndfile))) 301 (define-alien-type sf-chunk-info 302 (struct sf-chunk-info 308 (define-alien-routine sf-set-chunk int 309 (sndfile (* sndfile)) 310 (chunk-info (* sf-chunk-info))) 312 (define-opaque sf-chunk-iterator) 314 (define-alien-routine sf-get-chunk-iterator (* sf-chunk-iterator) 315 (sndfile (* sndfile)) 316 (chunk-info (* sf-chunk-info))) 318 (define-alien-routine sf-next-chunk-iterator (* sf-chunk-iterator) 319 (iterator (* sf-chunk-iterator))) 321 (define-alien-routine sf-get-chunk-size int 322 (it (* sf-chunk-iterator)) 323 (chunk-info (* sf-chunk-info))) 325 (define-alien-routine sf-get-chunk-data int 326 (it (* sf-chunk-iterator)) 327 (chunk-info (* sf-chunk-info)))