THAPI Question - External Message-Sends?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

THAPI Question - External Message-Sends?

Stephen Travis Pope

Hello all,

I'm working on sound I/O classes for the Siren package in VW that use  
the PortAudio API (http://www.portaudio.com).

PortAudio is a callback-oriented API, meaning that it starts a thread  
that calls a user-supplied function at regular intervals to read/
write sound sample buffers. I've used this in many C++ apps.

My first version of a SoundPort class for VW used Smalltalk  
semaphores that I pass in to the PortAudio initialization functions,  
put in the external registry, and signal from the callback function.  
I have a Smalltalk loop that sleeps waiting for the semaphore, and  
then reads/writes the shared buffers.

This works, but not reliably, and I'm concerned about the performance  
of externally signaled semaphores. I need to service on the order of  
50 callbacks/sec for a block size of 1024 sample frames at 44 kHz  
sample rate.

So, I wrote another version that uses the DLLCC external message  
send. I tested the message-send by sending it from the PortAudio init  
functions (I got it), but, since the run-time callback is in another  
thread, I never get the message-sends from the callback thread.

I've been reading about THAPI (threaded DLLCC API), and am not  
certain that this will fix things, there's doc about external  
callbacks, and they are mentioned as being supported by THAPI, but  
it's not obvious how to set this up. The DLLCC manual (p. 124)  
mentions this, but simply says that callbacks "from any other  
thread" (i.e., not the main VM thread) are handled specially.

My main questions are:

Are externally signaled Semaphores handled by the event mechanism?

What is the reasonable maximum external Semaphore signal frequency?

Which calls should get the tag "_threaded" in the case of an external  
API that forks its own threads?

Can anyone point me to an example that does anything like this?


...any reply appreciated...

stp

--
    Stephen Travis Pope  --  Santa Barbara, California, USA
    http://HeavenEverywhere.com     http://FASTLabInc.com
 
 




pastedGraphic.tiff (3K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: THAPI Question - External Message-Sends?

Stephen Travis Pope

Oh yes, last question:

Is there such a thing as an external message-send (i.e., from another  
thread)?

stp

--
    Stephen Travis Pope  --  Santa Barbara, California, USA
    http://HeavenEverywhere.com     http://FASTLabInc.com
 
 



On Mar 14, 2007, at 8:45 PM, Stephen Travis Pope wrote:

>
> Hello all,
>
> I'm working on sound I/O classes for the Siren package in VW that  
> use the PortAudio API (http://www.portaudio.com).
>
> PortAudio is a callback-oriented API, meaning that it starts a  
> thread that calls a user-supplied function at regular intervals to  
> read/write sound sample buffers. I've used this in many C++ apps.
>
> My first version of a SoundPort class for VW used Smalltalk  
> semaphores that I pass in to the PortAudio initialization  
> functions, put in the external registry, and signal from the  
> callback function. I have a Smalltalk loop that sleeps waiting for  
> the semaphore, and then reads/writes the shared buffers.
>
> This works, but not reliably, and I'm concerned about the  
> performance of externally signaled semaphores. I need to service on  
> the order of 50 callbacks/sec for a block size of 1024 sample  
> frames at 44 kHz sample rate.
>
> So, I wrote another version that uses the DLLCC external message  
> send. I tested the message-send by sending it from the PortAudio  
> init functions (I got it), but, since the run-time callback is in  
> another thread, I never get the message-sends from the callback  
> thread.
>
> I've been reading about THAPI (threaded DLLCC API), and am not  
> certain that this will fix things, there's doc about external  
> callbacks, and they are mentioned as being supported by THAPI, but  
> it's not obvious how to set this up. The DLLCC manual (p. 124)  
> mentions this, but simply says that callbacks "from any other  
> thread" (i.e., not the main VM thread) are handled specially.
>
> My main questions are:
>
> Are externally signaled Semaphores handled by the event mechanism?
>
> What is the reasonable maximum external Semaphore signal frequency?
>
> Which calls should get the tag "_threaded" in the case of an  
> external API that forks its own threads?
>
> Can anyone point me to an example that does anything like this?
>
>
> ...any reply appreciated...
>
> stp
>
> --
>    Stephen Travis Pope  --  Santa Barbara, California, USA
>    http://HeavenEverywhere.com     http://FASTLabInc.com
> <pastedGraphic.tiff>
>
>
>


pastedGraphic.tiff (3K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: THAPI Question - External Message-Sends?

Eliot Miranda-2
In reply to this post by Stephen Travis Pope


On 3/14/07, Stephen Travis Pope <[hidden email]> wrote:

Hello all,

I'm working on sound I/O classes for the Siren package in VW that use
the PortAudio API (http://www.portaudio.com).

PortAudio is a callback-oriented API, meaning that it starts a thread
that calls a user-supplied function at regular intervals to read/
write sound sample buffers. I've used this in many C++ apps.

My first version of a SoundPort class for VW used Smalltalk
semaphores that I pass in to the PortAudio initialization functions,
put in the external registry, and signal from the callback function.
I have a Smalltalk loop that sleeps waiting for the semaphore, and
then reads/writes the shared buffers.

This works, but not reliably, and I'm concerned about the performance
of externally signaled semaphores. I need to service on the order of
50 callbacks/sec for a block size of 1024 sample frames at 44 kHz
sample rate.

There should be no problem on current hardware but something is a little sluggish on Mac OS X.
I just did a simple test of callbacks; load the DLLCC Test Suite parcel and evauate the following:

| dt dti cb n count |
count := 10000.
dt := DLLANDCTest new.
dt mode: #threaded.
dti := dt interface.
n := 0.
cb := CCallback do: [n := n + 1] ofType: dti Callback001.
(Time microsecondsToRun: [[dti testCallback001: cb. n < count] whileTrue]) / count asDouble
Reply | Threaded
Open this post in threaded view
|

Re: THAPI Question - External Message-Sends?

Stephen Travis Pope

Hi there Eliot!

Thanks for the response. 

After getting this to run (NB Cincom folks: the class def. for DLLANDCTestInterface in the latest system doesn't include the test directory for Intel Macs, so all tests fail), I get between 1150 and 1400 usec (1.15 - 1.4 msec) per call. (I'm using an Intel DualCore iMac @ 2 GHz with 2 GB of RAM.)

This is certainly fast enough, so if I can't use Semaphores or external message-sends, I'll rewrite the code to use external callbacks.

Thanks again!

stp

--
   Stephen Travis Pope  --  Santa Barbara, California, USA
  


On Mar 14, 2007, at 10:31 PM, Eliot Miranda wrote:



On 3/14/07, Stephen Travis Pope <[hidden email]> wrote:

Hello all,

I'm working on sound I/O classes for the Siren package in VW that use
the PortAudio API (http://www.portaudio.com).

PortAudio is a callback-oriented API, meaning that it starts a thread
that calls a user-supplied function at regular intervals to read/
write sound sample buffers. I've used this in many C++ apps.

My first version of a SoundPort class for VW used Smalltalk
semaphores that I pass in to the PortAudio initialization functions,
put in the external registry, and signal from the callback function.
I have a Smalltalk loop that sleeps waiting for the semaphore, and
then reads/writes the shared buffers.

This works, but not reliably, and I'm concerned about the performance
of externally signaled semaphores. I need to service on the order of
50 callbacks/sec for a block size of 1024 sample frames at 44 kHz
sample rate.

There should be no problem on current hardware but something is a little sluggish on Mac OS X.
I just did a simple test of callbacks; load the DLLCC Test Suite parcel and evauate the following:

| dt dti cb n count |
count := 10000.
dt := DLLANDCTest new.
dt mode: #threaded.
dti := dt interface.
n := 0.
cb := CCallback do: [n := n + 1] ofType: dti Callback001.
(Time microsecondsToRun: [[dti testCallback001: cb. n < count] whileTrue]) / count asDouble

Reply | Threaded
Open this post in threaded view
|

Re: THAPI Question - External Message-Sends?

Stephen Travis Pope

Hi list,

After rewriting my port class (and the C glue code that talks to PortAudio) to use the external callback, it works like a charm -- Thanks!

stp

--
   Stephen Travis Pope  --  Santa Barbara, California, USA
  


On Mar 14, 2007, at 11:34 PM, Stephen Travis Pope wrote:


Hi there Eliot!

Thanks for the response. 

After getting this to run (NB Cincom folks: the class def. for DLLANDCTestInterface in the latest system doesn't include the test directory for Intel Macs, so all tests fail), I get between 1150 and 1400 usec (1.15 - 1.4 msec) per call. (I'm using an Intel DualCore iMac @ 2 GHz with 2 GB of RAM.)

This is certainly fast enough, so if I can't use Semaphores or external message-sends, I'll rewrite the code to use external callbacks.

Thanks again!

stp

--
   Stephen Travis Pope  --  Santa Barbara, California, USA
  
<pastedGraphic.tiff>



On Mar 14, 2007, at 10:31 PM, Eliot Miranda wrote:



On 3/14/07, Stephen Travis Pope <[hidden email]> wrote:

Hello all,

I'm working on sound I/O classes for the Siren package in VW that use
the PortAudio API (http://www.portaudio.com).

PortAudio is a callback-oriented API, meaning that it starts a thread
that calls a user-supplied function at regular intervals to read/
write sound sample buffers. I've used this in many C++ apps.

My first version of a SoundPort class for VW used Smalltalk
semaphores that I pass in to the PortAudio initialization functions,
put in the external registry, and signal from the callback function.
I have a Smalltalk loop that sleeps waiting for the semaphore, and
then reads/writes the shared buffers.

This works, but not reliably, and I'm concerned about the performance
of externally signaled semaphores. I need to service on the order of
50 callbacks/sec for a block size of 1024 sample frames at 44 kHz
sample rate.

There should be no problem on current hardware but something is a little sluggish on Mac OS X.
I just did a simple test of callbacks; load the DLLCC Test Suite parcel and evauate the following:

| dt dti cb n count |
count := 10000.
dt := DLLANDCTest new.
dt mode: #threaded.
dti := dt interface.
n := 0.
cb := CCallback do: [n := n + 1] ofType: dti Callback001.
(Time microsecondsToRun: [[dti testCallback001: cb. n < count] whileTrue]) / count asDouble