Monorepo for Aesthetic.Computer aesthetic.computer
at main 40 lines 1.4 kB view raw
1;;; ALSA PCM bindings via CFFI 2 3(in-package :ac-native.alsa) 4 5(cffi:define-foreign-library libasound 6 (:unix "libasound.so.2")) 7 8(cffi:use-foreign-library libasound) 9 10;;; PCM 11(cffi:defcfun ("snd_pcm_open" pcm-open%) :int 12 (pcm :pointer) (name :string) (stream :int) (mode :int)) 13 14(defun pcm-open (name &key (stream 0) (mode 0)) 15 "Open an ALSA PCM device. Returns (values pcm-handle error-code)." 16 (cffi:with-foreign-object (handle :pointer) 17 (let ((err (pcm-open% handle name stream mode))) 18 (values (if (zerop err) (cffi:mem-ref handle :pointer) nil) err)))) 19 20(cffi:defcfun ("snd_pcm_close" pcm-close) :int (pcm :pointer)) 21(cffi:defcfun ("snd_pcm_prepare" pcm-prepare) :int (pcm :pointer)) 22(cffi:defcfun ("snd_pcm_writei" pcm-writei) :long 23 (pcm :pointer) (buffer :pointer) (size :unsigned-long)) 24(cffi:defcfun ("snd_pcm_recover" pcm-recover) :int 25 (pcm :pointer) (err :int) (silent :int)) 26 27;;; Simplified setup 28(cffi:defcfun ("snd_pcm_set_params" pcm-set-params) :int 29 (pcm :pointer) (format :int) (access :int) (channels :unsigned-int) 30 (rate :unsigned-int) (soft-resample :int) (latency :unsigned-int)) 31 32;;; Constants 33(defconstant +snd-pcm-stream-playback+ 0) 34(defconstant +snd-pcm-stream-capture+ 1) 35(defconstant +snd-pcm-format-s16-le+ 2) 36(defconstant +snd-pcm-format-float-le+ 14) 37(defconstant +snd-pcm-access-rw-interleaved+ 3) 38 39;;; Error strings 40(cffi:defcfun ("snd_strerror" snd-strerror) :string (errnum :int))