Lisp HUG Maillist Archive

Read audio data with libsndfile

Hi all,

Would anybody have experience, or know about how to easily read data  
from audio files in LispWorks ?

I am currently writing bindings for the libsndfile library using CFFI.  
At a first sight, it seems that libsndfile requires long-long foreign  
types (int64) which are not supported by CFFI / LW 32-bits. I guess it  
is possible to get round this quite easily (I have not much experience  
with CFFI) but maybe similar things already exist somewhere, which  
would help to start.

Thanks for any help

Jean


Re: Read audio data with libsndfile

Jean Bresson <Jean.Bresson <at> ircam.fr> writes:

> 
> I am currently writing bindings for the libsndfile library using CFFI.  
> At a first sight, it seems that libsndfile requires long-long foreign  
> types (int64) which are not supported by CFFI / LW 32-bits. I guess it  
> is possible to get round this quite easily (I have not much experience  
> with CFFI) but maybe similar things already exist somewhere, which  
> would help to start.
> 

Hi Jean,

I think int64 is available in the LispWorks FLI, at least in the context of
define-foreign-function (as an argument or return type). Maybe you could mix a
bit of FLI and CFFI - I tried it once and it seemed to work (although can't
guarantee).

Personally I do all my sound file IO in Lisp, I don't bother with libsndfile.

If you want to generate bindings very quickly, rather than doing it tediously by
hand, you could try Verrazano (aka Fetter). It just takes a set of C headers and
generates CFFI bindings automatically from them. I've used it for PortAudio and
a few other C libraries that I use. Find it here: 

http://common-lisp.net/project/fetter/

Best,
Chris





RE: Read audio data with libsndfile

Hi Jean,

Yes, I use read-byte and friends, in the context of functions which read the various binary types one would typically encounter in the case of sound files (in both header and data chunks). I read the data I need into the slots of my sound file objects (I'm working with wav and aiff at the moment). The actual sample data itself is normalized and stored in vector format. The code's not fully mature, but it's efficient enough and more than serves my purposes at the moment (waveform and spectrogram display, fft analysis, etc).

I seem to recall that read-sequence is more efficient than multiple calls to read-byte (understandably). I've not tried it in the context of reading from binary streams, though, and I'm not sure it would be meaningful to even consider it given that one only has access to one byte at a time. Best check the CLHS.

Best,
Chris



> From: Jean.Bresson@ircam.fr
> To: relativeflux@hotmail.co.uk
> Subject: Re: Read audio data with libsndfile
> Date: Fri, 5 Jun 2009 10:52:13 +0200
>
> Hi Chris,
>
> thanks for your answer,
>
> You say you do all the sound file I/O in Lisp, you mean using read-
> byte and similar functions ? Don't you have to handle special cases
> for each different file format / sample resolutions, etc. ?
>
> I'll try both solutions anyway,
>
> Best regards,
>
> Jean
>
>
> Le 4 juin 09 à 18:28, Christopher Melen a écrit :
>
> >
> > Jean Bresson <Jean.Bresson <at> ircam.fr> writes:
> >
> >>
> >> I am currently writing bindings for the libsndfile library using
> >> CFFI.
> >> At a first sight, it seems that libsndfile requires long-long foreign
> >> types (int64) which are not supported by CFFI / LW 32-bits. I guess
> >> it
> >> is possible to get round this quite easily (I have not much
> >> experience
> >> with CFFI) but maybe similar things already exist somewhere, which
> >> would help to start.
> >>
> >
> > Hi Jean,
> >
> > I think int64 is available in the LispWorks FLI, at least in the
> > context of
> > define-foreign-function (as an argument or return type). Maybe you
> > could mix a
> > bit of FLI and CFFI - I tried it once and it seemed to work
> > (although can't
> > guarantee).
> >
> > Personally I do all my sound file IO in Lisp, I don't bother with
> > libsndfile.
> >
> > If you want to generate bindings very quickly, rather than doing it
> > tediously by
> > hand, you could try Verrazano (aka Fetter). It just takes a set of C
> > headers and
> > generates CFFI bindings automatically from them. I've used it for
> > PortAudio and
> > a few other C libraries that I use. Find it here:
> >
> > http://common-lisp.net/project/fetter/
> >
> > Best,
> > Chris
> >
> >
> >
> >
> >
>


View your Twitter and Flickr updates from one place – Learn more!
Updated at: 2020-12-10 08:41 UTC