This is a cute little program I wrote (using SBCL, needs the
"aplay"-Command) for generating beeps:
(defvar *aplay*
(sb-ext:run-program "/usr/bin/aplay"
(list "-r" "44100" "-f" "U16_LE" "-c2")
:input :stream
:output :stream
:error :stream
:wait nil))
(defvar *default-tone-time* 1000)
(defun ton (n &optional (milliseconds *default-tone-time*))
(loop for q from 0 below (* 44100 (/ milliseconds 1000)) do
(let ((right (round (* (1+ n) (sin (* q (expt 2 (/ n 12)) (/ 440
44100))))))
(left (round (* (1+ n) (sin (* q (expt 2 (/ n 12)) (/ 440
44100)))))))
(write-byte (ldb (byte 8 8) right) (sb-ext:process-input *aplay*))
(write-byte (ldb (byte 8 0) right) (sb-ext:process-input *aplay*))
(write-byte (ldb (byte 8 8) left) (sb-ext:process-input *aplay*))
(write-byte (ldb (byte 8 0) left) (sb-ext:process-input *aplay*)))))
(defun playtons (&rest args) (dolist (ton args) (if (typep ton 'cons)
(ton (car ton) (cdr ton)) (ton ton))))
(playtons '(3 . 500) '(5 . 500) 6 8 10 11 13 15)
It uses aplay and sends the sound-data to aplay's stdin. Maybe the worst
kind of generating sounds, but it is funny.
Anyway: I am searching for a real library for creating and mixing sound
under common lisp. I do not want to use sdl-mixer (sdl-mixer is not
really stable under windows, I always have problems using it). For
PortAudio, it doesnt seem like any CL-Binding exists, maybe due to the
fact that PortAudio needs a callback-function which will be called very
often, as far as I read - which may be a performance issue, I dont know.
Does anybody know a sound-library for Common Lisp (which is portable)?
Most things I found on cliki.net under "sound" are... strange.
Strange, I'm doing something very similar right now in SBCL using
aplay. I also have a sort of connection framework so I can string
together various functions, and a function to read uncompressed WAV
files...
On Apr 18, 11:29 pm, C S S <····@swissjabber.ch> wrote:
> This is a cute little program I wrote (using SBCL, needs the
> "aplay"-Command) for generating beeps:
>
> (defvar *aplay*
> (sb-ext:run-program "/usr/bin/aplay"
> (list "-r" "44100" "-f" "U16_LE" "-c2")
> :input :stream
> :output :stream
> :error :stream
> :wait nil))
>
> (defvar *default-tone-time* 1000)
>
> (defun ton (n &optional (milliseconds *default-tone-time*))
> (loop for q from 0 below (* 44100 (/ milliseconds 1000)) do
> (let ((right (round (* (1+ n) (sin (* q (expt 2 (/ n 12)) (/ 440
> 44100))))))
> (left (round (* (1+ n) (sin (* q (expt 2 (/ n 12)) (/ 440
> 44100)))))))
> (write-byte (ldb (byte 8 8) right) (sb-ext:process-input *aplay*))
> (write-byte (ldb (byte 8 0) right) (sb-ext:process-input *aplay*))
> (write-byte (ldb (byte 8 8) left) (sb-ext:process-input *aplay*))
> (write-byte (ldb (byte 8 0) left) (sb-ext:process-input *aplay*)))))
>
> (defun playtons (&rest args) (dolist (ton args) (if (typep ton 'cons)
> (ton (car ton) (cdr ton)) (ton ton))))
>
> (playtons '(3 . 500) '(5 . 500) 6 8 10 11 13 15)
>
> It uses aplay and sends the sound-data to aplay's stdin. Maybe the worst
> kind of generating sounds, but it is funny.
>
> Anyway: I am searching for a real library for creating and mixing sound
> under common lisp. I do not want to use sdl-mixer (sdl-mixer is not
> really stable under windows, I always have problems using it). For
> PortAudio, it doesnt seem like any CL-Binding exists, maybe due to the
> fact that PortAudio needs a callback-function which will be called very
> often, as far as I read - which may be a performance issue, I dont know.
I would find out. assuming things like CLM and Common Music are not
what you want. PortAudio via CFFI should work fine -- CL is pretty
fast and CFFI is pretty solid. Good doc and good support on their list
if you get stuck. Don't worry about the whole binding set, just get
the library open and make it beep, then make a simple callback work.
Once you are all pumped up by that success grinding out the rest of
the binding set wont seem so bad. And you can do it as you need it if
you are lazy like me.
ky
C S S wrote:
> Anyway: I am searching for a real library for creating and mixing sound
> under common lisp. I do not want to use sdl-mixer (sdl-mixer is not
> really stable under windows, I always have problems using it). For
> PortAudio, it doesnt seem like any CL-Binding exists, maybe due to the
> fact that PortAudio needs a callback-function which will be called very
> often, as far as I read - which may be a performance issue, I dont know.
> Does anybody know a sound-library for Common Lisp (which is portable)?
> Most things I found on cliki.net under "sound" are... strange.
PWGL supposedly uses PortAudio.
http://www2.siba.fi/PWGL/pwglsynth.html
- Daniel
C S S <···@swissjabber.ch> writes:
> Anyway: I am searching for a real library for creating and mixing
> sound under common lisp. I do not want to use sdl-mixer (sdl-mixer is
> not really stable under windows, I always have problems using it). For
> PortAudio, it doesnt seem like any CL-Binding exists, maybe due to the
> fact that PortAudio needs a callback-function which will be called
> very often, as far as I read - which may be a performance issue, I
> dont know. Does anybody know a sound-library for Common Lisp (which is
> portable)? Most things I found on cliki.net under "sound"
> are... strange.
PortAudio works find with CFFI, I know, because one of the first things
I wrote in CL was a PortAudio binding. I've not yet gotten around to
polishing it up, but what I've got works fine. Note that the port-audio
20 API (version 19+) has an alternative blocking (non-callback)
interface, which is what I used. AFAICT it should be possible to use the
call-back API too, but you'd need some less-portable CFFI constructs and
a threaded Lisp.
If you're interested, I can put the code somewhere public.
Cheers,
Joost.
--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
Joost Diepenmaat wrote:
> PortAudio works find with CFFI, I know, because one of the first things
> I wrote in CL was a PortAudio binding. I've not yet gotten around to
> polishing it up, but what I've got works fine. Note that the port-audio
> 20 API (version 19+) has an alternative blocking (non-callback)
> interface, which is what I used. AFAICT it should be possible to use the
> call-back API too, but you'd need some less-portable CFFI constructs and
> a threaded Lisp.
>
> If you're interested, I can put the code somewhere public.
I am interested. Please put it somewhere public.
C S S <···@swissjabber.ch> writes:
> Joost Diepenmaat wrote:
>> PortAudio works find with CFFI, I know, because one of the first things
>> I wrote in CL was a PortAudio binding. I've not yet gotten around to
>> polishing it up, but what I've got works fine. Note that the port-audio
>> 20 API (version 19+) has an alternative blocking (non-callback)
>> interface, which is what I used. AFAICT it should be possible to use the
>> call-back API too, but you'd need some less-portable CFFI constructs and
>> a threaded Lisp.
>>
>> If you're interested, I can put the code somewhere public.
> I am interested. Please put it somewhere public.
Ok, it's at: http://joost.zeekat.nl/port-audio.tgz
It's all still pretty rough, but it does include a basic asdf file and one
simple example. No documentation to speak of, though the code is pretty
small so you will probably be able to figure it out.
HTH,
Joost.
--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/