I am having a weird problem with the foreign function interface in
Lucid.
I have a C function playnotes
Synopsis:
playnotes(volume, length, tone, decay, octave)
int tone, length;
float volume, decay;
char octave[];
Using the lcl:def-foreign-function I have defined:
(lcl:def-foreign-function (play-notes-internal (:name "_playnotes")
(:return-type :signed-32bit))
(volume :double-float)
(length :signed-32bit )
(tone :signed-32bit)
(decay :double-float)
(octave :pointer :character)
)
The function works as expected.
However if the audio device is busy, I get a segmentation fault from
lucid, even though the C function opens the audio device as
f = open("/dev/audio", O_WRONLY);
if (f < 0) {
fprintf(stderr, "Within playnotes:%s \n", progname);
fprintf(stderr, "%s: Cannot open /dev/audio \n", progname);
exit(1);
}
which blocks until the device becomes available when called from a C
program.
Thus if I write a C program `notes' which calls the above playnotes function,
from one window do
cat > /dev/audio
and from another window call the C program `notes'
then `notes' waits until the cat closes the /dev/audio and then plays the
specified note.
However if I try the same thing but with the lucid function instead of
the C `notes' ie:
From one window do
cat > /dev/audio
and in another window do
(play-notes ...)
Then I get the error:
USER> (play-notes :length 5 :decay 0.09 :volume 100.0)
>>Trap: Interrupt: segmentation violation
PLAY-NOTES-INTERNAL:
Required arg 0 (VOLUME): 100.0
Required arg 1 (LENGTH): 5
Required arg 2 (TONE): 0
Required arg 3 (DECAY): 0.09
Required arg 4 (OCTAVE): #<Foreign-Pointer 7E5AA8 (:POINTER :CHARACTER)>
:A 0: Abort to Lisp Top Level
;;; Note: play-notes just calls play-notes-internal with default
values
So where is the bug?
Thanks for the help,
--Raman
--
T. V. Raman <·····@cs.cornell.edu>Tel: (607)255-9202 R 272-3649
Office: 4116 Upson Hall,
Department of Computer Science, Cornell University Ithaca NY 14853-6201
Res: 226 Bryant Avenue Ithaca NY 14850