/go-jack

Go bindings for Jack Audio Connection Kit

Primary LanguageGoMIT LicenseMIT

go-jack GoDoc

Go bindings for Jack Audio Connection Kit

Usage

For a working passthrough example see example/passthrough.go

Import the package:

import "github.com/xthexder/go-jack"

Connect to an existing jack server:

client, _ := jack.ClientOpen("Example Client", jack.NoStartServer)
if client == nil {
	fmt.Println("Could not connect to jack server.")
	return
}
defer client.Close()

Add a processing callback:

func process(nframes uint32) int {
	// Do processing here
	return 0
}

/* ... */

if code := client.SetProcessCallback(process); code != 0 {
	fmt.Println("Failed to set process callback.")
	return
}

Activate the client:

if code := client.Activate(); code != 0 {
	fmt.Println("Failed to activate client.")
	return
}

Add an output port:

port := client.PortRegister("out_1", jack.DEFAULT_AUDIO_TYPE, jack.PortIsOutput, 0)

Output a sine wave:

var Port *jack.Port

func process(nframes uint32) int {
	samples := Port.GetBuffer(nframes)
	nsamples := float64(len(samples))
	for i := range samples {
		samples[i] = jack.AudioSample(math.Sin(float64(i)*math.Pi*20/nsamples) / 2)
	}
	return 0
}

Implemented Bindings

  • jack_client_t jack_client_open(client_name, options, *status)
  • int jack_client_close()
  • int jack_client_name_size()
  • char* jack_get_client_name(client)
  • jack_nframes_t jack_get_sample_rate(client)
  • void jack_on_shutdown(client, callback, arg)
  • int jack_set_process_callback(client, callback, arg)
  • jack_port_t jack_port_register(client, name, type, flags, buffer_size)
  • int jack_port_unregister(client, port)
  • void* jack_port_get_buffer(port, nframes)
  • int jack_midi_event_get(event, port_buffer, event_index)
  • void jack_midi_clear_buffer(port_buffer)
  • int jack_midi_event_write(port_buffer, time, data, data_size)
  • void jack_set_error_function(callback)
  • void jack_set_info_function(callback)

See Official Jack API for detailed documentation on each of these functions.