[Gtk-sharp-list] jack-sharp micro binding

Jorge García jgarcia@ac.upc.es
Thu, 15 Jul 2004 01:44:31 +0200

Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hi all,

while learning how c-sharp delegates work I'm trying to get a micro
subset of jack (jackit.sf.net) working on mono. Yes, I know that jack
likes realtime processing, but I wanted to prove mono's performance.

I have achieved to register a jack client and some ports, but after some
hours of tests jack callbacks continue to not work. It's native code
calling to managed code. I have achieved this linking the SIGINT signal
to a callback, but not with jack's.

Any ideas?


PST Attached is the test code and microbinding

Content-Disposition: attachment; filename=Jack.cs
Content-Type: text/x-csharp; name=Jack.cs; charset=ISO-8859-15
Content-Transfer-Encoding: 7bit

using System;
using System.Runtime.InteropServices;

namespace Jack{

	public  delegate int  ProcessDelegate(UInt32 nframes, IntPtr ptr);
	public  delegate void ShutdownDelegate(IntPtr args);
	public  delegate void SignalDelegate(int signal);
	public class JackClient{

		private IntPtr Raw;

		[DllImport ("libjack")]
		private static extern IntPtr jack_client_new(string client_name);

		public JackClient(string client_name){
			Raw = jack_client_new(client_name);
			if(Raw == IntPtr.Zero)
				Console.WriteLine("Error calling jack_client_new");

		[DllImport ("libjack")]
		private static extern int jack_client_close (IntPtr client);
		public void Close(){

		[DllImport ("libjack")]
		private static extern int jack_activate (IntPtr client);

		public void Activate(){
			if(jack_activate(Raw) != 0)
				Console.WriteLine("Error calling jack_activate");


		[DllImport ("libjack")]
		private static extern IntPtr jack_port_register (
			IntPtr client, string port_name, string port_type,
			long flags, long buffer_size);

		public JackPort PortRegister(string port_name, string port_type,
					     long flags, long buffer_size){
			JackPort port;
			port = new JackPort(
				jack_port_register(Raw,port_name, port_type,flags,buffer_size));
			return port;

		[DllImport ("libjack")]
		private static extern int jack_set_process_callback(	
			IntPtr client, ProcessDelegate process_callback, IntPtr args);

		public void SetProcessCallback(ProcessDelegate process_cb){

			if(jack_set_process_callback(Raw,process_cb, IntPtr.Zero)!= 0)
				Console.WriteLine("Error calling SetProcessCallback");

		[DllImport ("libjack")]
		private static extern int jack_on_shutdown(	
			IntPtr client, ShutdownDelegate on_shutdown,IntPtr arg);

		public void SetShutdownCallback(ShutdownDelegate on_shutdown_cb){

			if(jack_on_shutdown(Raw,on_shutdown_cb,IntPtr.Zero)!= 0)
				Console.WriteLine("Error calling SetShutdownCallback");


		[DllImport ("libc")]
		private static extern void signal(int signum, SignalDelegate on_signal);	

		public void SetSignalCallback(int signum, SignalDelegate on_signal_cb){

			signal(signum, on_signal_cb);

	public class JackPort{
		private IntPtr Raw;

		public JackPort(IntPtr port){
			Raw = port;

		[DllImport ("libjack")]
		private static extern float[] jack_port_get_buffer (IntPtr port, int n_frames);

		public float[] GetBuffer(int nframes){
			return jack_port_get_buffer(Raw,nframes);


Content-Disposition: attachment; filename=Test.cs
Content-Type: text/x-csharp; name=Test.cs; charset=ISO-8859-15
Content-Transfer-Encoding: 7bit

using System;
using Jack;

using System.Runtime.InteropServices;

public class Test{
	public class Work {

		private static JackClient jk;
		private static JackPort portInput;
		private static JackPort portOutput;

		private static ShutdownDelegate shutdown;
		private static ProcessDelegate process;
		private static SignalDelegate  signal;

		public static void  on_shutdown_cb (IntPtr args)
			System.Console.WriteLine("Executing shutdown callback");

		public static int on_process_cb (UInt32 nframes, IntPtr ptr)
			Console.WriteLine("Executing process callback");

			float[] outbuff   = portOutput.GetBuffer(1024);
			float[] inputbuff = portInput.GetBuffer(1024);
			int i;

				outbuff[i] = inputbuff[i];
			return 0;

		public static void  on_signal_cb (int num)
			System.Console.WriteLine("Executing signal callback");

		public Work(){

			shutdown = new ShutdownDelegate(on_shutdown_cb);
			process = new ProcessDelegate(on_process_cb);
			signal  = new SignalDelegate(on_signal_cb);

			jk =  new JackClient("test");


			portInput  = jk.PortRegister("input", "32 bit float mono audio",0x1,0); 
			portOutput = jk.PortRegister("output","32 bit float mono audio",0x2,0); 

			int secs = 15;
                        for(int i = 0;i<secs;i++){
                                Console.WriteLine((secs - i) + " seconds to exit ...");




	public static void Main(){
		System.Console.WriteLine("Test of jack-sharp");	
		Work wk = new Work();

Content-Disposition: attachment; filename=Makefile
Content-Type: text/x-makefile; name=Makefile; charset=ISO-8859-15
Content-Transfer-Encoding: 7bit


all: jack-sharp test

	$(MCS) $(MCSFLAGS) Jack.cs /out:jack-sharp.dll /target:library

test: Test.cs
	$(MCS)	-r:jack-sharp.dll Test.cs -o test.exe

	rm -f jack-sharp.dll test.exe