JackSharpCore 1.1.1
dotnet add package JackSharpCore --version 1.1.1
NuGet\Install-Package JackSharpCore -Version 1.1.1
<PackageReference Include="JackSharpCore" Version="1.1.1" />
<PackageVersion Include="JackSharpCore" Version="1.1.1" />
<PackageReference Include="JackSharpCore" />
paket add JackSharpCore --version 1.1.1
#r "nuget: JackSharpCore, 1.1.1"
#:package JackSharpCore@1.1.1
#addin nuget:?package=JackSharpCore&version=1.1.1
#tool nuget:?package=JackSharpCore&version=1.1.1
JackSharpCore
.NET bindings for the JACK Audio Connection Kit: clients, ports, real-time-safe audio and MIDI processing, and patching, on Windows, Linux (JACK2, or PipeWire's JACK support) and macOS.
The original repository is residuum/JackSharp, by Thomas Mayer. This fork is based on h3ll5ur7er/JackSharp, which moved it to .NET Core.
NuGet package: JackSharpCore.
Why .NET Core and not .NET Standard?
.NET Standard doesn't provide NativeLibrary, which finds the native JACK library at run time.
Using it
using JackSharp;
// A client with ports and a process callback. Opening throws a JackException if no JACK server is running.
using var processor = new Processor("my-effect");
AudioPort input = processor.RegisterAudioPort("in", Direction.In);
AudioPort output = processor.RegisterAudioPort("out", Direction.Out);
// Runs once per cycle on JACK's real-time thread: buffers are spans on JACK's own memory, and nothing allocates.
processor.Process = context =>
{
Span<float> from = input.GetBuffer(context), to = output.GetBuffer(context);
for (int n = 0; n < context.Frames; n++)
to[n] = from[n] * 0.5f;
};
processor.Activate();
// Every client can see and patch the graph, its own ports and other clients'.
foreach (PortInfo capture in processor.GetPorts(type: PortType.Audio, direction: Direction.Out, physicalOnly: true))
Console.WriteLine($"{capture.FullName} {string.Join(", ", capture.Aliases)}");
input.ConnectTo("system:capture_1");
output.ConnectTo("system:playback_1");
Clientis what every JACK client can do: the server's state (SampleRate,BufferSize,CpuLoad), the graph (GetPorts,GetConnections,Connect,Disconnect,GetLatency), and events for the server (rate and buffer size changes, xruns, shutdown) and the graph (clients and ports coming and going, renames, connections). Events arrive on JACK's notification thread.Processoradds ports, registered and unregistered at any time, and the process callback. MIDI is read withMidiPort.GetEventsand written withMidiPort.GetWriter, in place.AddedLatencyreports the latency it adds, through JACK's latency callback, so programs downstream can compensate.Controlleris a client without ports, for patchbays and monitors.JackLibraryfinds libjack: an explicitJackLibrary.PathorJACK_LIBRARY, else the system's (libjack64.dll,libjack.so.0,libjack.0.dylib), then the usual install folders (JACK2's, PipeWire's, Homebrew's and MacPorts').JackLibrary.SetMessageHandlersroutes JACK's error and information messages, which libjack otherwise prints.
Jack.NAudio adapts a Processor to NAudio's IWavePlayer and IWaveIn.
Tests
dotnet test JackSharpTest runs against a JACK server that's already running, or else starts jackd on JACK's
dummy backend (a timer, with no sound card) and stops it afterwards. The tests only connect their own ports, never
hardware ones. Without libjack or jackd they're skipped.
Known issues
- JACK2 1.9.22 on Windows can stall in
jack_client_closewhen a client closes within milliseconds of activating (see the unmerged jack2 PR #889). A client therefore stays active at least 100 ms before it deactivates or closes. Repeatedly starting a server, then opening and closing a client while a second client of the same process watches the graph, can still stall a close; the tests don't do that, and a program with one long-lived client won't meet it. - JACK2 1.9.22 on Windows ignores
UseExactNameand opens a second client with the same name. A client whose name JACK changes despite it is closed with aJackException.
Changes in this fork
Before 1.0 (h3ll5ur7er, then this fork):
- Moved to .NET 8, and added the AudioTranscription sample.
- Finds the native library with
NativeLibraryat run time, rather than by how it was built; resolution moved to the base client, so aControllercreated first no longer crashes. - Fixed reading MIDI input.
Controller.Connectby port name, and a port typeUnknownfor types other than audio and MIDI.- Published as the JackSharpCore NuGet package.
1.1.1:
- A port without a buffer no longer crashes the process. PipeWire's JACK can answer
jack_port_get_bufferwith no buffer; that became a span over a null pointer, and clearing it in the cycle (after a callback that had thrown) threw out of the[UnmanagedCallersOnly]callback, which ends the process.AudioPort.GetBuffernow gives an empty span then (check its length before copying a cycle in or out), MIDI ports give no events and no writer, and nothing a cycle throws escapes to JACK: it's counted inProcessExceptionslike the callback's own.
1.1:
Processor.AddedLatencyreports a processor's own latency through JACK's latency callback: its outputs' capture latency is its inputs' plus what it adds, and its inputs' playback latency its outputs' plus what it adds.
1.0 (breaking):
- One client, layered as JACK's is. Patching and graph events moved into
Client, so aProcessorcan patch without a second client, andControlleris a client without ports. - A process callback that allocates nothing. Buffers are spans on JACK's memory, and MIDI is read and written in place; before, every cycle allocated arrays, copies of each buffer, and objects per port.
- Ports register and unregister while running. Unregistering waits for any cycle still using the port.
- Errors say why. Opening throws
JackExceptionwith JACK's status flags (NoServer, name taken, version mismatch) instead of returningfalse; a client never starts a server unless asked. - Lifecycle fixes. Disposing after the server shuts down, or from a client's own event handler, is safe, and no finalizer calls into libjack.
- More of JACK: port aliases, latency ranges, CPU load, buffer size changes, and xrun delays.
- Native loading tries each platform's usual names and folders, PipeWire's included, with an explicit override.
- Modern interop: generated
LibraryImportcalls and[UnmanagedCallersOnly]callbacks, compatible with native AOT. - Removed the CSCore binding, whose library is no longer maintained, and the unused transport wrappers.
- Tests rewritten for the new API, starting a dummy JACK server when none is running.
License
MIT, as the original: see LICENSE.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on JackSharpCore:
| Package | Downloads |
|---|---|
|
AudioPlugSharpJack
Jack Audio host for AudioPlugSharp plugins. |
GitHub repositories (2)
Showing the top 2 popular GitHub repositories that depend on JackSharpCore:
| Repository | Stars |
|---|---|
|
mikeoliphant/AudioPlugSharp
Easily create VST (VST3) audio plugins in C# .NET
|
|
|
mikeoliphant/ChartPlayer
Visual player for song charts synchronized to music recordings
|