Jack Port and Integration on MacOSX Stphane Letz Grame, centre de - - PowerPoint PPT Presentation

jack port and integration on macosx
SMART_READER_LITE
LIVE PREVIEW

Jack Port and Integration on MacOSX Stphane Letz Grame, centre de - - PowerPoint PPT Presentation

LAD 2004 : Jack Port and Integration on MacOSX Jack Port and Integration on MacOSX Stphane Letz Grame, centre de cration musicale Lyon, France GRAME : Centre National de Cration Musicale LAD 2004 : Jack Port and Integration on MacOSX Plan


slide-1
SLIDE 1

GRAME : Centre National de Création Musicale LAD 2004 : Jack Port and Integration on MacOSX

Jack Port and Integration on MacOSX

Stéphane Letz Grame, centre de création musicale Lyon, France

slide-2
SLIDE 2

GRAME : Centre National de Création Musicale LAD 2004 : Jack Port and Integration on MacOSX

Plan

  • Porting the Linux code to MacOSX
  • Integration with CoreAudio architecture : the JackOSX project
  • Jackd evolution : more structure, multi-processor version
slide-3
SLIDE 3

GRAME : Centre National de Création Musicale LAD 2004 : Jack Port and Integration on MacOSX

Porting the Linux code

  • Use of the POSIX shared memory API more reliable on MacOSX
  • Rewriting the engine audio cycle for a callback-based activation scheme
  • Using Mach Remote Procedure Call for client activation : the Linux FIFO based code is not used

anymore, all clients are activated in a loop inside the Jack engine

  • - Synchronous RPC are fast because the scheduler is bypassed
  • - Thread migration : the calling thread parameters (priority, time quantum..) are transferred to the called thread
  • Client Real-Time threads : fixed priority time constrained threads (period, computation, constraint)
  • Use an additional real-time thread for client process call
slide-4
SLIDE 4

GRAME : Centre National de Création Musicale LAD 2004 : Jack Port and Integration on MacOSX

  • Current one : a PortAudio based driver that can also work on Linux
  • In development : a more efficient “native” CoreAudio based driver, using the Apple HALOuputUnit

component (takes care of all audio stream adaptation)

Drivers

slide-5
SLIDE 5

GRAME : Centre National de Création Musicale LAD 2004 : Jack Port and Integration on MacOSX

Performance

  • Measuring the audio cycle on a iBook G3/700 using jackd timing code
  • At 64 frames : finding the maximum additional latency
  • jackd only : ~ 5 us (0.5 %)
  • jackd + 1 jack_metro client : ~ 55 us (3.5 %)
  • jackd + 1 jack_metro client + moving windows + network access… : up to ~ 260 us
  • jackd + 2 jack_metro clients : ~ 120 us (7.5 %)
  • jackd + 2 jack_metro clients + moving windows + network access… : up to ~ 360 us
  • Maximum additional latency of about 200 us
  • Really stable
  • Jackd can be used with 32 frame buffers
  • At 64 frames : client activation time : ~ 50 us (jack_metro in “thru” mode)
slide-6
SLIDE 6

GRAME : Centre National de Création Musicale LAD 2004 : Jack Port and Integration on MacOSX

Integration in the CoreAudio architecture

MacOSX audio architecture : HAL : Hardware Abstraction Layer in user space : multi-channel audio, real-time thread activation (for Audio callback), mixing for output…, expose the API for applications IOKIT : a C++ based layer that implements generic services for driver developers Drivers : kernel drivers, interaction with the hardware

slide-7
SLIDE 7

GRAME : Centre National de Création Musicale LAD 2004 : Jack Port and Integration on MacOSX

HAL model

  • A “software interrupt” based model
  • Each client can use its own buffer size (starting from 14 frames…)
  • The HAL takes care of waking-up real-time (callback) threads at the right time
  • All real-time threads run at a fixed priority, but correct thread interleaving is done by the HAL by carefully

setting the time-constraint parameters : period, computation, constraint

  • Drivers usually publish their “native” capabilities : stream and sample format, sample rate, buffer size….
  • Application may use optimized (Altivec…) AudioConverter components to convert in their own format if

needed

  • AudioUnits : a plug-in API to be used by host applications
slide-8
SLIDE 8

GRAME : Centre National de Création Musicale LAD 2004 : Jack Port and Integration on MacOSX

Jack Audio Router (JAR)

The bridge between regular CoreAudio applications and the Jack server

  • Using JAR, a CoreAudio application becomes a Jack client
  • A user space driver placed between the HAL and IOKit layer
  • Implements the HAL “Plug-in API”
  • Loaded by the HAL like kernel drivers to become available for applications
slide-9
SLIDE 9

GRAME : Centre National de Création Musicale LAD 2004 : Jack Port and Integration on MacOSX

JAR (2) : behaviour

  • JAR presents itself as an n mono non-interleaved stream, fixed buffer size, fixed sample rate

driver

  • Behaves like a kernel driver for the HAL, will be available like other drivers for applications
  • Can be used as the default system driver for applications like iTunes, QuickTime Player, DLSSynth…
slide-10
SLIDE 10

GRAME : Centre National de Création Musicale LAD 2004 : Jack Port and Integration on MacOSX

JAR (3) : mapping the CoreAudio API on the Jack API

  • Parameter query API : AudioDeviceGetProperty
  • Client activation

AudioDeviceAddIOProc ==> jack_client_new jack_client_port_register jack_set_process_callback AudioDeviceStopOProc ==> jack_client_deactivate AudioDeviceStartIOProc ==> jack_client_activate AudioDeviceRemoveIOProc ==> jack_client_port_unregister jack_client_close

  • Described in global settings :
  • number of input/ouput jack ports
  • auto connection with drivers
  • JAR as default system driver
slide-11
SLIDE 11

GRAME : Centre National de Création Musicale LAD 2004 : Jack Port and Integration on MacOSX

Jack Plug-ins, JackPilot

  • Extend the audio routing capabilities inside plug-ins host applications : track insert…..
  • JackAU (AudioUnit API) and JackVST (VST API)
  • JackPilot : global settings : jackd parameters, connections manager

CoreAudio Applications (with plugin support) Cubase SX, Logic, Max/MSP ... JackVST or JackAU channel insert … CoreAudio Applications (with plugin support) Cubase SX, Logic, Max/MSP ... JackVST or JackAU channel insert … Audio Hardware Built-In, MOTU 828 … CoreAudio Applications (without plugin support) Reason, iTunes, Quicktime ...

Native Jack Clients

Pure Data

Jack Server

JAR JAR

slide-12
SLIDE 12

GRAME : Centre National de Création Musicale LAD 2004 : Jack Port and Integration on MacOSX

JackOSX project

  • All the components are distributed in a package called JackOSX
  • Source Forge project : JAR, Jack Plug-ins, CoreAudio drivers
  • Web site : www.jackosx.com
  • In collaboration with Johnny Petrantoni and Dan Nigrin
slide-13
SLIDE 13

GRAME : Centre National de Création Musicale LAD 2004 : Jack Port and Integration on MacOSX

Synchronization

  • Allowing transparent synchronization between Jack native clients and CoreAudio applications
  • Mapping the Jack transport API to the MIDI clock sync API
  • Converting Jack transport state events to MIDI Start, Stop, Continue, SongPos messages

using the CoreMIDI API

slide-14
SLIDE 14

GRAME : Centre National de Création Musicale LAD 2004 : Jack Port and Integration on MacOSX

Jack evolution : MacOSX specifics

  • In MacOSX, the natural way to implement a server/client system is to use the

Mach Interface Generator (MIG) to define new Remote Procedure Calls

  • Synchronous and asynchronous functions can be defined :
  • function call is actually done using Mach ports and messages
  • MIG takes care of parameter management
  • synchronous calls are implemented with send/receive Mach messages

that use the fast “thread migration” system

  • Socket based communications can be completely suppressed
  • The server defines a public Mach port for client/server communication
  • When opening, each client defines its own private port for server/client communication
  • Opening a client : rpc_jack_client_new (mach_port_t server, const char* name, int* refnum…)
  • Calling the client process callback : rpc_jack_client_process(mach_port_t client, jack_frame_t frames,….)
slide-15
SLIDE 15

GRAME : Centre National de Création Musicale LAD 2004 : Jack Port and Integration on MacOSX

Multi-processor version (1)

  • In the current version, the client graph is sorted to determine an order for client activation

each time the graph topology changes

  • Multi-processor version : activate parallel nodes on different processors
  • no more “a priori” sorting
  • a data flow model : a node become runnable when all of its input ports

have been filled up

slide-16
SLIDE 16

GRAME : Centre National de Création Musicale LAD 2004 : Jack Port and Integration on MacOSX

Multi-processor version (2)

  • Using system primitives :
  • describe data dependencies between nodes with semaphores
  • need of inter-process semaphores
  • Implementing a “mini” scheduler, for an audio cycle :
  • starting from the input, find all runnable nodes, put them on a lock-free shared list
  • one thread per processor that takes a runnable node, execute it, propagate output port “readiness”

to connected inputs

  • re-compute runnable nodes
  • until all nodes have been executed
slide-17
SLIDE 17

GRAME : Centre National de Création Musicale LAD 2004 : Jack Port and Integration on MacOSX

Jackd architecture re-organisation (1)

  • More structure:
  • Isolate the server/client communication code
  • Isolate the client activation code (FIFO on Linux, futexes on kernel 2.6, synchronous

RPC on MacOSX, semaphores…)

  • More secure use of shared memory segment : distinguish between R/W and R only

segments on the client side

  • Move all port data structure and connections to shared memory
  • Thinking in term of lock-free access whenever possible
slide-18
SLIDE 18

GRAME : Centre National de Création Musicale LAD 2004 : Jack Port and Integration on MacOSX

Jackd architecture re-organisation (2)

  • More structure :
  • Moving the FreeWheel code as an autonomous driver
  • Isolate Watch Dog thread code

……

  • Fix some API problems :
  • Memory leak (jack_port_by_id and jack_port_by_name…)
  • Some state change are not notified to other clients : change of port names…

……

slide-19
SLIDE 19

GRAME : Centre National de Création Musicale LAD 2004 : Jack Port and Integration on MacOSX

DEMO