We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2163

Summary: Add JACK backend to SDL
Product: SDL Reporter: le.businessman
Component: audioAssignee: Ryan C. Gordon <icculus>
Status: RESOLVED FIXED QA Contact: Ryan C. Gordon <icculus>
Severity: enhancement    
Priority: P2 CC: jakemsr, philipp.wiesemann, pshirkey, slouken, stormbyte
Version: HG 2.0   
Hardware: x86   
OS: Linux   
Attachments: Patch for JACK support in SDL

Description le.businessman 2013-10-19 03:39:33 UTC
Created attachment 1376 [details]
Patch for JACK support in SDL

Background:
JACK (http://jackaudio.org/) is an audio backend targetting low-latency applications.

Adding JACK support to SDL was previously discussed here:
https://forums.libsdl.org/viewtopic.php?t=5682

Patrick Shirkey wrote the JACK mailing list with a patch based on the code from the forum post:
http://boosthardware.com/sdl-jack-patch.tar.bz2

I subsequently wrote a patch which I believe addresses the issues of the initial patch. I've tested it with a slightly modified version of the simple mixer application from http://olofson.net/examples.html (modified because the app assumed 16-bit audio).

Feedback welcome.
Comment 1 Philipp Wiesemann 2013-10-19 08:35:32 UTC
SDL is currently distributed under the zlib license which is more permissive then the LPGL license used for the files in the patch.

In most cases it will not matter match but maybe it would be useful to have only similar licenses in SDL.
Comment 2 le.businessman 2013-10-19 23:04:03 UTC
(In reply to Philipp Wiesemann from comment #1)
> SDL is currently distributed under the zlib license which is more permissive
> then the LPGL license used for the files in the patch.
> 
> In most cases it will not matter match but maybe it would be useful to have
> only similar licenses in SDL.

Fine by me since it's likely that the license was just copy-pasted from another SDL file when SDL was still LGPL. However, it's my understanding that Jacob Meuser and Sam Lantinga would have to give the ok as well.

Reference:
http://www.paritynews.com/2013/08/13/2298/sdl-2-0-released-does-away-with-gpllgpl-to-adopt-zlib-licensing/
Comment 3 le.businessman 2013-10-19 23:20:59 UTC
(In reply to le.businessman from comment #2)
> (In reply to Philipp Wiesemann from comment #1)
> > SDL is currently distributed under the zlib license which is more permissive
> > then the LPGL license used for the files in the patch.
> > 
> > In most cases it will not matter match but maybe it would be useful to have
> > only similar licenses in SDL.
> 
> Fine by me since it's likely that the license was just copy-pasted from
> another SDL file when SDL was still LGPL. However, it's my understanding
> that Jacob Meuser and Sam Lantinga would have to give the ok as well.

I've cc'd Jacob and Sam to see if they're ok with changing the license from LGPL to zlib.
Comment 4 pshirkey 2013-10-22 22:19:50 UTC
I can confirm this patch is working. Tested with simplemixer and tesseract on Linux.

export SDL_AUDIODRIVER=jack;

./simplemixer
Comment 5 Ryan C. Gordon 2013-11-22 14:52:09 UTC
(In reply to le.businessman from comment #3)
> I've cc'd Jacob and Sam to see if they're ok with changing the license from
> LGPL to zlib.

I assume Sam would be okay with it, but we'd need to hear back from Jacob before going further with this patch. Let me know if he responds, and where I can read a copy of his response.

Thanks,
--ryan.
Comment 6 le.businessman 2013-11-22 18:41:46 UTC
(In reply to Ryan C. Gordon from comment #5)
> (In reply to le.businessman from comment #3)
> > I've cc'd Jacob and Sam to see if they're ok with changing the license from
> > LGPL to zlib.
> 
> I assume Sam would be okay with it, but we'd need to hear back from Jacob
> before going further with this patch. Let me know if he responds, and where
> I can read a copy of his response.

For sure, may be easier said than done though:
http://linux-unix-open-source.1053819.n5.nabble.com/Kinda-OT-Whereabouts-of-Jacob-Meuser-td5570016.html
Comment 7 David Carlos Manuelda 2014-12-07 07:22:49 UTC
Any news on this? I think this is really useful, specially since Steam, for example, uses libSDL2 as part of its runtime, and its support for jack could be very useful,
Comment 8 pshirkey 2014-12-08 12:42:03 UTC
(In reply to David Carlos Manuelda from comment #7)
> Any news on this? I think this is really useful, specially since Steam, for
> example, uses libSDL2 as part of its runtime, and its support for jack could
> be very useful,

Maybe we can change the license of the patch to zlib instead of the other way around? Is the LGPL permissive enough for that?
Comment 9 Ryan C. Gordon 2017-06-09 05:01:24 UTC
> Maybe we can change the license of the patch to zlib instead of the other
> way around? Is the LGPL permissive enough for that?

No, but I've now written a JACK target from scratch to replace it. I did not use Jacob's code for a reference (this used the existing PulseAudio target as a template--though it doesn't look much like it now--and the API docs at http://jackaudio.org/ ).

As of https://hg.libsdl.org/SDL/rev/5da1c02714b0, JACK should work, but you'll likely have to force it on, since SDL will currently favor ALSA, OSS, Pulse, etc first and probably find _one_ of those. So be sure to:

    export SDL_AUDIODRIVER=jack

This might change at some point (chances are if you're running a JACK server you probably want JACK, so maybe SDL should try it first at some point).

This code supports capture devices, so not only can you play audio, but you can also read in data from a JACK port (record audio from a microphone) and receive it via SDL.

The source code is in src/audio/jack ...

https://hg.libsdl.org/SDL/file/tip/src/audio/jack/SDL_jackaudio.c

There are likely improvements to make to this code, but it already works pretty well here. So I'm resolving this bug.

--ryan.