chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-users] performance isssue with FFI callbacks


From: Tomtom
Subject: [Chicken-users] performance isssue with FFI callbacks
Date: Fri, 25 Mar 2011 10:52:46 +0100
User-agent: Sup/0.11

hi list.

I'm writing a program that communicates with the jack audio server. One thing a
jack client has to do is to register a callback that contains the code the
application has to run for each sample. This is done by calling

> jack_set_process_callback (jack_client, process_callback, arg)

# In C

First, I checked that everything else works fine by registering the callback
directly in C. the program behaves as expected.

> ((foreign-lambda*
>   void ()
> "
> int my_callback(jack_nframes_t nframes, void* arg) { return 0; }
> jack_set_process_callback(client, my_callback, NULL);
> "
> ))
> 
> ;; the jack server starts making calls to the callback
> (jack_activate client)

# Callback in scheme

then I defined the callback in scheme:

> (define-external
>   (my_callback (jack_nframes nframes) ((c-pointer void) arg))
>   int
>   0)
> 
> ((foreign-lambda* 
>   void ()
>   "jack_set_process_callback(client, my_callback, NULL);"))
>
> (jack_activate client)

with this, all I get is a peak on my CPU use, and an error when the program
stops (it call jack_deactivate after a second):

> Error: call of non-procedure: #<unspecified>
> 
>       Call history:
> 
>       jack1.scm:169: jack_activate            
>       ##sys#gc                
>       g9192           
>       jack1.scm:171: sleep            
>       jack1.scm:173: jack_deactivate          
>       jack1.scm:175: jack_port_unregister             
>       jack1.scm:177: jack_client_close                
>       ##sys#implicit-exit-handler                     <--

I also tried to add a printf statement within the callback, to check if this
code is evaluated, and it didn't print anything.

# bonus: writing a binding

I also tried to write a binding with foreign-lambda:

> (define jack_set_process_callback
>   (foreign-lambda
>    int
>    "jack_set_process_callback"
>    (c-pointer jack_client)
>    jack_process_callback
>    (c-pointer void)))
> 
> (define-external
>   (my_callback (jack_nframes nframes) ((c-pointer void) arg))
>   int
>   0)
> 
> (jack_set_process_callback client my_callback #f)

when I do so, I get a segfault as soon as I call jack_activate - I guess my
code is not passing the callback reference properly.


# conclusion

That's it folks ! this is where I am right now.

I hope to read back from you soon !

tom



reply via email to

[Prev in Thread] Current Thread [Next in Thread]