English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[Caml-list] PortAudio on ocaml
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-07-16 (09:55)
From: Xavier Leroy <xavier.leroy@i...>
Subject: Re: [Caml-list] PortAudio on ocaml
> I'm trying to evaluate on porting PortAudio API to O'Caml, which would
> enable an entire genre of sound applications being written in this nice
> language. What concerns me is that PortAudio uses asynchronous callbacks,
> much like signals, to tell the application that some audio sample has
> arrived, needs to be played, or both.

That's the crux of the problem, indeed.  I looked at the PortAudio
tutorial and found this little gem:

  Your callback function is often called by an interrupt, or low level
  process so you should not do any complex system activities like
  allocating memory, or reading or writing files, or printf(). Just
  crunch numbers and generate audio signals.

So, calling Caml code from the callback function is definitely out of
the question.

> [Snipped investigation of internals of OCaml runtime system]
> What do the O'Caml developers say about this?

That no matter how much you peek under the hood, you cannot
meet the requirements of the PortAudio "interrupt handler" model.

My advice is that there are essentially only two programming models
for C libraries that can reasonably be interfaced with OCaml:

- Synchronous calls (block the calling thread till results are available,
  then return into Caml).

- Event loops (register Caml callbacks, then enter a library-provider event
  handler that will block and invoke the callbacks one at a time,
  but not from a signal or interrupt context).

In both cases, you can make the design thread-compatible by using the
Caml runtime system functions enter_blocking_section and
leave_blocking_section, see

- Xavier Leroy

To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners