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

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


--=-KDvBC6lBvPw7cC0s4LlY
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?

Jorge

PST Attached is the test code and microbinding



--=-KDvBC6lBvPw7cC0s4LlY
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(){
			jack_client_close(Raw);
		}


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

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

			return;
		}


		[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);
		}
		
	}

}//namespace

--=-KDvBC6lBvPw7cC0s4LlY
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;

			for(i=0;i<1024;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");

			jk.SetSignalCallback(2,signal);
			jk.SetShutdownCallback(shutdown);
			//jk.SetProcessCallback(process);

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

			int secs = 15;
                        for(int i = 0;i<secs;i++){
                                Console.WriteLine((secs - i) + " seconds to exit ...");
                                System.Threading.Thread.Sleep(1000);
                        }

			jk.Close();

		}

	}

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

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


MCS=mcs
MCSFLAGS=

all: jack-sharp test

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

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

clean:
	rm -f jack-sharp.dll test.exe

--=-KDvBC6lBvPw7cC0s4LlY--