changelog shortlog graph tags branches changeset file revisions annotate raw help

Mercurial > core / lisp/ffi/sndfile/pkg.lisp

revision 693: 5f81d888c31f
parent 238: 6fa723592550
child 694: a36280d2ef4e
     1.1--- a/lisp/ffi/sndfile/pkg.lisp	Thu Oct 03 17:56:11 2024 -0400
     1.2+++ b/lisp/ffi/sndfile/pkg.lisp	Thu Oct 03 19:04:57 2024 -0400
     1.3@@ -2,85 +2,153 @@
     1.4 
     1.5 ;;; Commentary:
     1.6 
     1.7+;; see http://www.mega-nerd.com/libsndfile/api.html
     1.8+
     1.9 ;;; Code:
    1.10 (defpackage :sndfile
    1.11   (:use :cl :std :sb-alien)
    1.12-  (:export ))
    1.13+  (:export :sf-version-string))
    1.14 
    1.15 (in-package :sndfile)
    1.16 
    1.17 (define-alien-loader "sndfile" t "/usr/lib/")
    1.18-;; (load-sndfile)
    1.19+
    1.20+(define-alien-type sf-count long)
    1.21+
    1.22+(define-alien-type sf-info
    1.23+    (struct sf-info
    1.24+            (frames sf-count)
    1.25+            (samplerate int)
    1.26+            (channels int)
    1.27+            (format int)
    1.28+            (sections int)
    1.29+            (seekable int)))
    1.30 
    1.31-(defconstant %seek-set 0)
    1.32-(defconstant %seek-cur 1)
    1.33-(defconstant %seek-end 2)
    1.34+(define-alien-type sf-format-info
    1.35+    (struct sf-format-info
    1.36+            (format int)
    1.37+            (name c-string)
    1.38+            (extension c-string)))
    1.39 
    1.40-(defvar *type-constants* nil)
    1.41-(defvar *subtype-constants* nil)
    1.42+;; SF_SEEK_*
    1.43+(define-alien-enum (sf-seek-mode int)
    1.44+                   :set 0
    1.45+                   :cur 1
    1.46+                   :end 2)
    1.47 
    1.48-(defmacro define-format-type (name value)
    1.49-  `(progn
    1.50-     (defconstant ,name ,value)
    1.51-     (pushnew ',name *type-constants*)))
    1.52+;; SFD_*
    1.53+(define-alien-enum (sf-dither int)
    1.54+                   :default-level 0
    1.55+                   :custom-level #x40000000
    1.56+                   :no-dither 500
    1.57+                   :white 501
    1.58+                   :triangular-pdf 502)
    1.59+
    1.60+(define-alien-type sf-dither-info
    1.61+    (struct sf-dither-info
    1.62+            (type int)
    1.63+            (level double)
    1.64+            (name c-string)))
    1.65 
    1.66-(defmacro define-format-subtype (name value)
    1.67-  `(progn
    1.68-     (defconstant ,name ,value)
    1.69-     (pushnew ',name *subtype-constants*)))
    1.70+(define-alien-type sf-embed-file-info
    1.71+    (struct sf-embed-file-info
    1.72+            (offset sf-count)
    1.73+            (length sf-count)))
    1.74+
    1.75+(define-alien-type sf-cue-point
    1.76+    (struct sf-cue-point
    1.77+            (indx int)
    1.78+            (position unsigned-int)
    1.79+            (fcc-chunk int)
    1.80+            (chunk-start int)
    1.81+            (block-start int)
    1.82+            (sample-offset unsigned-int)
    1.83+            (name (array char 256))))
    1.84+
    1.85+(define-alien-enum (sf-loop int)
    1.86+                   :none 800
    1.87+                   :forward 801
    1.88+                   :backward 802
    1.89+                   :alternating 803)
    1.90 
    1.91-(define-format-type sf-format-wav #x010000)               ; Microsoft WAV format (little endian default). 
    1.92-(define-format-type sf-format-aiff #x020000)               ; Apple/SGI AIFF format (big endian). 
    1.93-(define-format-type sf-format-au #x030000)               ; Sun/NeXT AU format (big endian). 
    1.94-(define-format-type sf-format-raw #x040000)               ; RAW PCM data. 
    1.95-(define-format-type sf-format-paf #x050000)               ; Ensoniq PARIS file format. 
    1.96-(define-format-type sf-format-svx #x060000)               ; Amiga IFF / SVX8 / SV16 format. 
    1.97-(define-format-type sf-format-nist #x070000)               ; Sphere NIST format. 
    1.98-(define-format-type sf-format-voc #x080000)               ; VOC files. 
    1.99-(define-format-type sf-format-ircam #x0A0000)               ; Berkeley/IRCAM/CARL 
   1.100-(define-format-type sf-format-w64 #x0B0000)               ; Sonic Foundry's 64 bit RIFF/WAV 
   1.101-(define-format-type sf-format-mat4 #x0C0000)               ; Matlab (tm) V4.2 / GNU Octave 2.0 
   1.102-(define-format-type sf-format-mat5 #x0D0000)               ; Matlab (tm) V5.0 / GNU Octave 2.1 
   1.103-(define-format-type sf-format-pvf #x0E0000)               ; Portable Voice Format 
   1.104-(define-format-type sf-format-xi #x0F0000)               ; Fasttracker 2 Extended Instrument 
   1.105-(define-format-type sf-format-htk #x100000)               ; HMM Tool Kit format 
   1.106-(define-format-type sf-format-sds #x110000)               ; Midi Sample Dump Standard 
   1.107-(define-format-type sf-format-avr #x120000)               ; Audio Visual Research 
   1.108-(define-format-type sf-format-wavex #x130000)               ; MS WAVE with WAVEFORMATEX 
   1.109-(define-format-type sf-format-sd2 #x160000)               ; Sound Designer 2 
   1.110-(define-format-type sf-format-flac #x170000)               ; FLAC lossless file format 
   1.111-(define-format-type sf-format-caf #x180000)               ; Core Audio File format 
   1.112+(define-alien-type sf-instrument
   1.113+    (struct sf-instrument
   1.114+            (gain int)
   1.115+            (detune char)
   1.116+            (basenote char)
   1.117+            (velocity-lo char)
   1.118+            (velocity-hi char)
   1.119+            (key-lo char)
   1.120+            (key-hi char)
   1.121+            (loop-count int)
   1.122+            (loops (array
   1.123+                    (struct nil
   1.124+                            (mode int)
   1.125+                            (start unsigned-int)
   1.126+                            (end unsigned-int)
   1.127+                            (count unsigned-int))
   1.128+                    16))))
   1.129 
   1.130-;;;; Subtypes from here on. 
   1.131+(define-alien-type sf-loop-info
   1.132+    (struct sf-loop-info
   1.133+            (time-sig-num short)
   1.134+            (time-sig-den short)
   1.135+            (loop-mode int)
   1.136+            (num-beats int)
   1.137+            (bpm float)
   1.138+            (root-key int)
   1.139+            (future (array int 6))))
   1.140 
   1.141-(define-format-subtype sf-format-pcm-s8 #x0001)                 ; Signed 8 bit data 
   1.142-(define-format-subtype sf-format-pcm-16 #x0002)                 ; Signed 16 bit data 
   1.143-(define-format-subtype sf-format-pcm-24 #x0003)                 ; Signed 24 bit data 
   1.144-(define-format-subtype sf-format-pcm-32 #x0004)                 ; Signed 32 bit data 
   1.145-(define-format-subtype sf-format-pcm-u8 #x0005)                 ; Unsigned 8 bit data (WAV and RAW only) 
   1.146-
   1.147-(define-format-subtype sf-format-float #x0006)                 ; 32 bit float data 
   1.148-(define-format-subtype sf-format-double #x0007)                 ; 64 bit float data 
   1.149-
   1.150-(define-format-subtype sf-format-ulaw #x0010)                 ; U-Law encoded. 
   1.151-(define-format-subtype sf-format-alaw #x0011)                 ; A-Law encoded. 
   1.152-(define-format-subtype sf-format-ima-adpcm #x0012)                 ; IMA ADPCM. 
   1.153-(define-format-subtype sf-format-ms-adpcm #x0013)                 ; Microsoft ADPCM. 
   1.154+(define-alien-enum (sf-format int)
   1.155+                   :wav #x010000               ; Microsoft WAV format (little endian default). 
   1.156+                   :aiff #x020000               ; Apple/SGI AIFF format (big endian). 
   1.157+                   :au #x030000               ; Sun/NeXT AU format (big endian). 
   1.158+                   :raw #x040000               ; RAW PCM data. 
   1.159+                   :paf #x050000               ; Ensoniq PARIS file format. 
   1.160+                   :svx #x060000               ; Amiga IFF / SVX8 / SV16 format. 
   1.161+                   :nist #x070000               ; Sphere NIST format. 
   1.162+                   :voc #x080000               ; VOC files. 
   1.163+                   :ircam #x0A0000               ; Berkeley/IRCAM/CARL 
   1.164+                   :w64 #x0B0000               ; Sonic Foundry's 64 bit RIFF/WAV 
   1.165+                   :mat4 #x0C0000               ; Matlab (tm) V4.2 / GNU Octave 2.0 
   1.166+                   :mat5 #x0D0000               ; Matlab (tm) V5.0 / GNU Octave 2.1 
   1.167+                   :pvf #x0E0000               ; Portable Voice Format 
   1.168+                   :xi #x0F0000               ; Fasttracker 2 Extended Instrument 
   1.169+                   :htk #x100000               ; HMM Tool Kit format 
   1.170+                   :sds #x110000               ; Midi Sample Dump Standard 
   1.171+                   :avr #x120000               ; Audio Visual Research 
   1.172+                   :wavex #x130000               ; MS WAVE with WAVEFORMATEX 
   1.173+                   :sd2 #x160000               ; Sound Designer 2 
   1.174+                   :flac #x170000               ; FLAC lossless file format 
   1.175+                   :caf #x180000               ; Core Audio File format 
   1.176 
   1.177-(define-format-subtype sf-format-gsm610 #x0020)                 ; GSM 6.10 encoding. 
   1.178-(define-format-subtype sf-format-vox-adpcm #x0021)                 ; OKI / Dialogix ADPCM 
   1.179+                   :pcm-s8 #x0001                 ; Signed 8 bit data 
   1.180+                   :pcm-16 #x0002                 ; Signed 16 bit data 
   1.181+                   :pcm-24 #x0003                 ; Signed 24 bit data 
   1.182+                   :pcm-32 #x0004                 ; Signed 32 bit data 
   1.183+                   :pcm-u8 #x0005                 ; Unsigned 8 bit data (WAV and RAW only) 
   1.184 
   1.185-(define-format-subtype sf-format-g721-32 #x0030)                 ; 32kbs G721 ADPCM encoding. 
   1.186-(define-format-subtype sf-format-g723-24 #x0031)                 ; 24kbs G723 ADPCM encoding. 
   1.187-(define-format-subtype sf-format-g723-40 #x0032)                 ; 40kbs G723 ADPCM encoding. 
   1.188+                   :float #x0006                 ; 32 bit float data 
   1.189+                   :double #x0007                 ; 64 bit float data 
   1.190+
   1.191+                   :ulaw #x0010                 ; U-Law encoded. 
   1.192+                   :alaw #x0011                 ; A-Law encoded. 
   1.193+                   :ima-adpcm #x0012                 ; IMA ADPCM. 
   1.194+                   :ms-adpcm #x0013                 ; Microsoft ADPCM. 
   1.195 
   1.196-(define-format-subtype sf-format-dwvw-12 #x0040)                 ; 12 bit Delta Width Variable Word encoding. 
   1.197-(define-format-subtype sf-format-dwvw-16 #x0041)                 ; 16 bit Delta Width Variable Word encoding. 
   1.198-(define-format-subtype sf-format-dwvw-24 #x0042)                 ; 24 bit Delta Width Variable Word encoding. 
   1.199-(define-format-subtype sf-format-dwvw-n #x0043)                 ; N bit Delta Width Variable Word encoding. 
   1.200+                   :gsm610 #x0020                 ; GSM 6.10 encoding. 
   1.201+                   :vox-adpcm #x0021                 ; OKI / Dialogix ADPCM 
   1.202 
   1.203-(define-format-subtype sf-format-dpcm-8 #x0050)                 ; 8 bit differential PCM (XI only)
   1.204-(define-format-subtype sf-format-dpcm-16 #x0051)                 ; 16 bit differential PCM (XI only)
   1.205+                   :g721-32 #x0030                 ; 32kbs G721 ADPCM encoding. 
   1.206+                   :g723-24 #x0031                 ; 24kbs G723 ADPCM encoding. 
   1.207+                   :g723-40 #x0032                 ; 40kbs G723 ADPCM encoding. 
   1.208+                   :-dwvw-12 #x0040                 ; 12 bit Delta Width Variable Word encoding. 
   1.209+                   :dwvw-16 #x0041                 ; 16 bit Delta Width Variable Word encoding. 
   1.210+                   :dwvw-24 #x0042                 ; 24 bit Delta Width Variable Word encoding. 
   1.211+                   :dwvw-n #x0043                 ; N bit Delta Width Variable Word encoding. 
   1.212+
   1.213+                   :dpcm-8 #x0050                 ; 8 bit differential PCM (XI only)
   1.214+                   :dpcm-16 #x0051)                 ; 16 bit differential PCM (XI only)
   1.215 
   1.216 (defun decode-bitflags (value flag-names)
   1.217   (loop for symbol in flag-names
   1.218@@ -94,26 +162,164 @@
   1.219        return symbol))
   1.220 
   1.221 ;;;; Endian-ness options. 
   1.222+(define-alien-enum (sf-endian int)
   1.223+                   :file #x00000000     ; Default file endian-ness. 
   1.224+                   :little #x10000000     ; Force little endian-ness. 
   1.225+                   :big #x20000000     ; Force big endian-ness. 
   1.226+                   :cpu #x30000000)     ; Force CPU endian-ness. 
   1.227 
   1.228-(defconstant sf-endian-file #x00000000)     ; Default file endian-ness. 
   1.229-(defconstant sf-endian-little #x10000000)     ; Force little endian-ness. 
   1.230-(defconstant sf-endian-big #x20000000)     ; Force big endian-ness. 
   1.231-(defconstant sf-endian-cpu #x30000000)     ; Force CPU endian-ness. 
   1.232 
   1.233-(defconstant sf-format-submask #x0000FFFF)
   1.234-(defconstant sf-format-typemask #x0FFF0000)
   1.235-(defconstant sf-format-endmask #x30000000)
   1.236+(define-alien-enum (sf-format-mask int)
   1.237+                   :sub #x0000FFFF
   1.238+                   :type #x0FFF0000
   1.239+                   :end #x30000000)
   1.240 
   1.241-(defconstant sf-str-title 1)
   1.242-(defconstant sf-str-copyright 2)
   1.243-(defconstant sf-str-software 3)
   1.244-(defconstant sf-str-artist 4)
   1.245-(defconstant sf-str-comment 5)
   1.246-(defconstant sf-str-date 6)
   1.247+(define-alien-enum (sf-str int)
   1.248+                   :title 1
   1.249+                   :copyright 2
   1.250+                   :software 3
   1.251+                   :artist 4
   1.252+                   :comment 5
   1.253+                   :date 6)
   1.254 
   1.255 ;;;; Public error numbers
   1.256-(defconstant sf-err-no-error 0)
   1.257-(defconstant sf-err-unrecognized-format 1)
   1.258-(defconstant sf-err-system 2)
   1.259-(defconstant sf-err-malformed-file 3)
   1.260-(defconstant sf-err-unsupported-encoding 4)
   1.261+(define-alien-enum (sf-err int)
   1.262+                   :no-error 0
   1.263+                   :unrecognized-format 1
   1.264+                   :system 2
   1.265+                   :malformed-file 3
   1.266+                   :unsupported-encoding 4)
   1.267+
   1.268+;;;; SF commands
   1.269+(define-alien-enum (sf-command-op int)
   1.270+                   :get-lib-version #x1000
   1.271+                   :get-log-info #x1001
   1.272+                   :get-current-sf-info #x1002
   1.273+                   :get-norm-double #x1010
   1.274+                   :get-norm-float #x1011
   1.275+                   :set-norm-double #x1012
   1.276+                   :set-norm-float #x1013
   1.277+                   :set-scale-float-int-read #x1014
   1.278+                   :set-scale-int-float-write #x1015
   1.279+                   :get-simple-format-count #x1020
   1.280+                   :get-simple-format #x1021
   1.281+                   :get-format-info #x1028
   1.282+                   :get-format-major-count #x1030
   1.283+                   :get-format-major #x1031
   1.284+                   :get-format-subtype-count #x1032
   1.285+                   :get-format-subtype #x1033
   1.286+                   :calc-signal-max #x1040
   1.287+                   :calc-norm-signal-max #x1041
   1.288+                   :calc-max-all-channels #x1042
   1.289+                   :calc-norm-max-all-channels #x1043
   1.290+                   :get-signal-max #x1044
   1.291+                   :get-max-all-channels #x1045
   1.292+                   :set-add-peak-chunk #x1050
   1.293+                   :update-header-now #x1060
   1.294+                   :set-update-header-auto #x1061
   1.295+                   :file-truncate #x1080
   1.296+                   :set-raw-start-offset #x1090
   1.297+                   ;; /* Commands reserved for dithering, which is not implemented. */
   1.298+                   :set-dither-on-write #x10A0
   1.299+                   :set-dither-on-read #x10A1
   1.300+                   :get-dither-info-count #x10A2
   1.301+                   :get-dither-info #x10A3
   1.302+                   :get-embed-file-info #x10B0
   1.303+                   :set-clipping #x10C0
   1.304+                   :get-clipping #x10C1
   1.305+                   :get-cue-count #x10CD
   1.306+                   :get-cue #x10CE
   1.307+                   :set-cue #x10CF
   1.308+                   :get-instrument #x10D0
   1.309+                   :set-instrument #x10D1
   1.310+                   :get-loop-info #x10E0
   1.311+                   :get-broadcast-info #x10F0
   1.312+                   :set-broadcast-info #x10F1
   1.313+                   :get-channel-map-info #x1100
   1.314+                   :set-channel-map-info #x1101
   1.315+                   :raw-data-needs-endswap #x1110
   1.316+                   ;; /* Support for Wavex Ambisonics Format */
   1.317+                   :wavex-set-ambisonic #x1200
   1.318+                   :wavex-get-ambisonic #x1201
   1.319+                   ;; RF64 files can be set so that on-close, writable files
   1.320+                   ;; that have less than 4GB of data in them are converted to
   1.321+                   ;; RIFF/WAV, as per EBU recommendations.
   1.322+                   :rf64-auto-downgrade #x1210
   1.323+                   :set-vbr-encoding-quality #x1300
   1.324+                   :set-compression-level #x1301
   1.325+                   ;; /* Ogg format commands */
   1.326+                   :set-ogg-page-latency-ms #x1302
   1.327+                   :set-ogg-page-latency #x1303
   1.328+                   :get-ogg-stream-serialno #x1306
   1.329+                   :get-bitrate-mode #x1304
   1.330+                   :set-bitrate-mode #x1305
   1.331+                   ;; /* Cart Chunk support */
   1.332+                   :set-cart-info #x1400
   1.333+                   :get-cart-info #x1401
   1.334+                   ;; /* Opus files original samplerate metadata */
   1.335+                   :set-original-samplerate #x1500
   1.336+                   :get-original-samplerate #x1501
   1.337+                   ;; /* Following commands for testing only. */
   1.338+                   :test-ieee-float-replace #x6001
   1.339+                   ;; These SFC_SET_ADD_* values are deprecated and will
   1.340+                   ;; disappear at some time in the future. They are
   1.341+                   ;; guaranteed to be here up to and including version 1.0.8
   1.342+                   ;; to avoid breakage of existing software.  They currently
   1.343+                   ;; do nothing and will continue to do nothing.
   1.344+                   :set-add-header-pad-chunk #x1051
   1.345+                   :set-add-dither-on-write #x1070
   1.346+                   :set-add-dither-on-read #x1071)
   1.347+
   1.348+;;; Functions
   1.349+(define-opaque sndfile t)
   1.350+
   1.351+(define-alien-routine sf-open (* sndfile) (path c-string) (mode int) (sfinfo (* sf-info)))
   1.352+(define-alien-routine sf-open-fd (* sndfile) (fd int) (mode int) (sfinfo (* sf-info)))
   1.353+(define-alien-routine sf-error int (sndfile (* sndfile)))
   1.354+(define-alien-routine sf-strerror c-string (sndfile (* sndfile)))
   1.355+(define-alien-routine sf-error-number c-string (errnum int))
   1.356+(define-alien-routine sf-perror int (sndfile (* sndfile)))
   1.357+(define-alien-routine sf-error-str int (sndfile (* sndfile)) (str c-string) (len size-t))
   1.358+(define-alien-routine sf-command int (sndfile (* sndfile)) (command int) (data (* t)) (datasize int))
   1.359+(define-alien-routine sf-format-check int (info (* sf-info)))
   1.360+(define-alien-routine sf-seek sf-count (sndfile (* sndfile)) (frames sf-count) (whence int))
   1.361+
   1.362+(define-alien-routine sf-set-string int (sndfile (* sndfile)) (str-type int) (str c-string))
   1.363+(define-alien-routine sf-get-string c-string (sndfile (* sndfile)) (str-type int))
   1.364+(define-alien-routine sf-version-string c-string)
   1.365+(define-alien-routine sf-current-byterate int (sndfile (* sndfile)))
   1.366+(define-alien-routine sf-read-raw sf-count (sndfile (* sndfile)) (ptr (* t)) (bytes sf-count))
   1.367+(define-alien-routine sf-write-raw sf-count (sndfile (* sndfile)) (ptr (* t)) (bytes sf-count))
   1.368+;; ...
   1.369+(define-alien-routine sf-close int (sndfile (* sndfile)))
   1.370+
   1.371+(define-alien-routine sf-write-sync void
   1.372+  (sndfile (* sndfile)))
   1.373+
   1.374+(define-alien-type sf-chunk-info
   1.375+  (struct sf-chunk-info
   1.376+          (id (array char 64))
   1.377+          (id-size unsigned)
   1.378+          (datalen unsigned)
   1.379+          (data (* t))))
   1.380+
   1.381+(define-alien-routine sf-set-chunk int
   1.382+  (sndfile (* sndfile))
   1.383+  (chunk-info (* sf-chunk-info)))
   1.384+
   1.385+(define-opaque sf-chunk-iterator)
   1.386+
   1.387+(define-alien-routine sf-get-chunk-iterator (* sf-chunk-iterator)
   1.388+  (sndfile (* sndfile))
   1.389+  (chunk-info (* sf-chunk-info)))
   1.390+
   1.391+(define-alien-routine sf-next-chunk-iterator (* sf-chunk-iterator)
   1.392+  (iterator (* sf-chunk-iterator)))
   1.393+
   1.394+(define-alien-routine sf-get-chunk-size int
   1.395+  (it (* sf-chunk-iterator))
   1.396+  (chunk-info (* sf-chunk-info)))
   1.397+
   1.398+(define-alien-routine sf-get-chunk-data int
   1.399+  (it (* sf-chunk-iterator))
   1.400+  (chunk-info (* sf-chunk-info)))