-
Notifications
You must be signed in to change notification settings - Fork 104
feat: Add JACK audio backend for ultra-low latency on Linux (#58) #115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a1a7b9b
feat: Add JACK audio backend for ultra-low latency on Linux (#58)
vansh-09 53a4201
style: include remaining formatting updates
vansh-09 be7a85b
fix: resolve JACK backend build failures
vansh-09 3ce1c84
fix: include JACK header for friend declaration
vansh-09 e44c0f6
Merge branch 'main' into main
vansh-09 26211aa
fix: align JACK callback declaration
vansh-09 e896b4c
Merge branch 'main' into main
vansh-09 43712c7
fix: complete JACK backend CI path
vansh-09 3f414d3
Merge branch 'main' into main
vansh-09 041a435
Merge branch 'main' into main
vansh-09 91a5507
Merge branch 'main' into main
vansh-09 1ee8ded
Removed the mrege
vansh-09 1eff340
Merge branch 'main' into main
vansh-09 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| // Minimal JACK backend factory and helpers | ||
| #include "audio/audio_backend.h" | ||
| #include "audio/audio_backend_jack_internal.h" | ||
| #include <iostream> | ||
|
|
||
| namespace Amplitron | ||
| { | ||
|
|
||
| AudioBackendState *create_audio_backend() | ||
| { | ||
| return new AudioBackendState(); | ||
| } | ||
|
|
||
| void destroy_audio_backend(AudioBackendState *state) | ||
| { | ||
| delete state; | ||
| } | ||
|
|
||
| } // namespace Amplitron |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| #pragma once | ||
|
|
||
| #ifdef WITH_JACK | ||
| #include <jack/jack.h> | ||
|
|
||
| namespace Amplitron | ||
| { | ||
|
|
||
| struct AudioBackendState | ||
| { | ||
| jack_client_t *client = nullptr; | ||
| jack_port_t *input_port = nullptr; | ||
| jack_port_t *output_port = nullptr; | ||
| int measured_latency_ms = 0; | ||
| }; | ||
|
|
||
| } // namespace Amplitron | ||
| #endif // WITH_JACK |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: sudip-mondal-2002/Amplitron
Length of output: 86
🏁 Script executed:
# Read the CMakeLists.txt to understand the context around lines 265-295 wc -l CMakeLists.txtRepository: sudip-mondal-2002/Amplitron
Length of output: 90
🏁 Script executed:
Repository: sudip-mondal-2002/Amplitron
Length of output: 1663
🏁 Script executed:
Repository: sudip-mondal-2002/Amplitron
Length of output: 1081
🏁 Script executed:
Repository: sudip-mondal-2002/Amplitron
Length of output: 1419
🏁 Script executed:
Repository: sudip-mondal-2002/Amplitron
Length of output: 1486
🏁 Script executed:
Repository: sudip-mondal-2002/Amplitron
Length of output: 655
🏁 Script executed:
Repository: sudip-mondal-2002/Amplitron
Length of output: 556
🏁 Script executed:
Repository: sudip-mondal-2002/Amplitron
Length of output: 2196
🏁 Script executed:
Repository: sudip-mondal-2002/Amplitron
Length of output: 4174
🏁 Script executed:
Repository: sudip-mondal-2002/Amplitron
Length of output: 1807
🏁 Script executed:
Repository: sudip-mondal-2002/Amplitron
Length of output: 290
🏁 Script executed:
Repository: sudip-mondal-2002/Amplitron
Length of output: 53
Add fallback logic when JACK is requested but not found to prevent compilation failure.
When
WITH_JACK=ONbut the JACK libraries are not found on the system, the code still setsBACKEND_SOURCESto compile JACK audio backend sources without verifying thatJACK_INCLUDE_DIRSandJACK_LIBRARIESwere successfully resolved. This causes compilation to fail when the jack/jack.h header is missing, rather than gracefully falling back to the PortAudio backend.The current code checks
if(NOT JACK_INCLUDE_DIRS OR NOT JACK_LIBRARIES)to conditionally search for JACK, but lacks validation after the find operations to confirm they succeeded. Add a check after the pkg-config and find_path/find_library attempts: if JACK is still not found, disableWITH_JACKwith a warning message and re-evaluateBACKEND_SOURCESaccordingly.Suggested CMake fix
if(WITH_JACK) if(NOT JACK_INCLUDE_DIRS OR NOT JACK_LIBRARIES) find_package(PkgConfig QUIET) if(PkgConfig_FOUND) pkg_check_modules(JACK QUIET jack) endif() if(NOT JACK_FOUND) find_path(JACK_INCLUDE_DIRS jack/jack.h PATHS /usr/include /usr/local/include /opt/homebrew/include "C:/Program Files/JACK/include" "${CMAKE_SOURCE_DIR}/external/jack") find_library(JACK_LIBRARIES NAMES jack PATHS /usr/lib /usr/local/lib /opt/homebrew/lib "C:/Program Files/JACK/lib" "${CMAKE_SOURCE_DIR}/external/jack") endif() endif() + if(NOT JACK_INCLUDE_DIRS OR NOT JACK_LIBRARIES) + message(WARNING "WITH_JACK=ON but JACK not found; falling back to PortAudio backend.") + set(WITH_JACK OFF CACHE BOOL "Build with JACK audio backend support" FORCE) + endif() +endif() + +if(WITH_JACK) + if(JACK_LIBRARY_DIRS) + link_directories(${JACK_LIBRARY_DIRS}) + endif() + set(BACKEND_SOURCES + src/audio/audio_backend_jack.cpp + src/audio/audio_backend_jack_lifecycle.cpp + ) +else() + set(BACKEND_SOURCES + src/audio/audio_backend_portaudio.cpp + src/audio/audio_backend_portaudio_lifecycle.cpp + src/audio/audio_backend_portaudio_devices.cpp + ) +endif() - - if(JACK_LIBRARY_DIRS) - link_directories(${JACK_LIBRARY_DIRS}) - endif() - set(BACKEND_SOURCES - src/audio/audio_backend_jack.cpp - src/audio/audio_backend_jack_lifecycle.cpp - ) -else() - set(BACKEND_SOURCES - src/audio/audio_backend_portaudio.cpp - src/audio/audio_backend_portaudio_lifecycle.cpp - src/audio/audio_backend_portaudio_devices.cpp - ) -endif()Per coding guidelines, external libraries should validate successful resolution and fallback when not available—this change ensures
WITH_JACKcomplies with that pattern.📝 Committable suggestion
🤖 Prompt for AI Agents