caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Xavier Leroy <xavier.leroy@inria.fr>
To: Likai Liu <liulk@bu.edu>
Cc: caml-list@inria.fr, Likai Liu <liulk@acs.bu.edu>
Subject: Re: [Caml-list] PortAudio on ocaml
Date: Wed, 16 Jul 2003 11:55:44 +0200	[thread overview]
Message-ID: <20030716115544.A29200@pauillac.inria.fr> (raw)
In-Reply-To: <Pine.A41.4.33.0307141618320.96990-100000@acsn03.bu.edu>; from liulk@bu.edu on Mon, Jul 14, 2003 at 04:55:44PM -0400

> 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
        http://caml.inria.fr/archives/200106/msg00199.html

- 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


  parent reply	other threads:[~2003-07-16  9:55 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-07-14 20:55 Likai Liu
2003-07-15  0:37 ` SooHyoung Oh
2003-07-15  2:12   ` Likai Liu
2003-07-16  9:55 ` Xavier Leroy [this message]
2003-07-16 11:59   ` Likai Liu
2003-07-16 16:57     ` Damien Doligez
2003-07-16 17:46       ` Likai Liu
2003-07-18 13:32         ` Damien Doligez
2003-07-19 13:37       ` Likai Liu
2003-07-22 11:17         ` Damien Doligez

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030716115544.A29200@pauillac.inria.fr \
    --to=xavier.leroy@inria.fr \
    --cc=caml-list@inria.fr \
    --cc=liulk@acs.bu.edu \
    --cc=liulk@bu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).