Repository navigation
Add proper ASIO support for sound library. - #113
Open
trackme518 wants to merge 6 commits into
Open
trackme518 wants to merge 6 commits into
trackme518 wants to merge 6 commits into
Conversation
The PortAudio bindings' ASIO host fails to open many ASIO drivers in practice, so this adds a second ASIO path based on JAsioHost, which talks to the drivers directly. It is enabled with MultiChannel.useJASIO() and keeps all existing functionality (JavaSound, PortAudio, multichannel, audio input) untouched. JAsioHost (LGPL) is bundled as sources under jasiohost-master/ and built into library/JAsioHost.jar by the new jasio-deps ant target; the native dlls ship in library/windows-amd64/.
GitHub now auto-fails workflows using the retired upload-artifact v3 backend, and the old action versions run on deprecated Node runtimes. Bump all actions to their current majors and check out the repository in pr.yml before referencing the local composite setup action.
Realtek's ASIO driver (and teardown of some others) can report channels that never get an audio buffer, or fire bufferSwitch callbacks while the buffers are being disposed of. Check that every opened channel really has a buffer before starting the driver so such drivers fail with a clear error message, null-guard AsioChannel.setBufferIndex in JAsioHost, and swallow RuntimeExceptions from callbacks that race with shutdown.
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This adds a native ASIO output backend to the Sound library on Windows, built on
JAsioHost, and fixes the driver enumeration
problems that make ASIO unreliable through PortAudio.
The existing PortAudio ASIO path was previously documented in #87. My test reports
there show it failing or stalling with real multichannel interfaces:
WaitForSingleObject() timed out in WriteStream()/RuntimeException: Wait timed outBlocking API not supported yetSoundFile, so it is not specific to the JSyn synthThis PR talks to the ASIO drivers directly through JAsioHost instead.
What changed
Added
MultiChannel.useJASIO()andJAsioAudioDeviceManager, a JAsioHost-backedAudioDeviceManagerwith interleaved ring-buffered input/output streams.useJASIO()switches the backend without loading a driver, soSound.list()canenumerate all registered ASIO drivers. Select one afterwards:
Rewrote the Windows ASIO driver enumerator in the bundled native DLL:
HKLM\SOFTWARE\ASIOin both the 64-bit and 32-bit registry viewsHKCU\Software\ASIOInprocServer32pathsCOM server before advertising it
JASIOHOST_DEBUG=1prints a scan report and rejection reasons to stderrEngine.selectOutputDevice()now stops the current synth before probing thenext device, and the ASIO callback path is synchronized against driver
teardown. ASIO drivers can therefore be switched at runtime without leaving a
driver loaded.
Bundled the JAsioHost Java sources; the new
jasio-depstarget inbuild.xmlcompiles
JAsioHost.jar. Prebuilt native DLLs are included so no ASIO SDKbuild is required.
Updated
examples/IO/AsioOutputto list all registered ASIO drivers and play adifferent note on every reported output channel.
Added
jasiohost-master/PATCHES.mddocumenting the native changes and the MSVCbuild command.
Testing
Tested on Windows 11 with Processing 4.5.7:
Focusrite USB ASIO): opens and plays(
Focusrite USB ASIO) and VB-Matrix VASIO-8 in a single JVM: 15 switches withaudio callbacks running plus 30 rapid switches, no JVM crash; switching back
to PortAudio unloads the last ASIO driver cleanly
AsioOutputexample compiles with Processing's preprocessor andis configured to play one different note per output channel
C++ runtime compatibility
ASIO driver DLLs are C++ COM servers and therefore depend on the Microsoft C++
runtime (
msvcp140.dll/vcruntime140.dll). Which runtime version an ASIOdriver requires depends on the toolchain it was compiled with.
Windows loads native DLL dependencies from the host executable's directory
first. Processing 4.3.4 bundles an old
msvcp140.dll(14.27) inprocessing-4.3.4/java/bin, so the Focusrite Scarlett 16i16 ASIO driver bindsto that old runtime and crashes inside its own
ASIOInit(crash log:focusriteusbasio.dll->msvcp140.dll). The same driver and library work inProcessing 4.5.7, whose JDK uses the newer system runtime. This is not a
problem in the Sound library and cannot be fixed from inside the JVM, because
the host's private runtime DLL is already loaded before the ASIO driver is.
The Microsoft 14.x C++ runtime is backward compatible: a newer runtime can
serve components built against older ones, but not the reverse. In practice
this means older ASIO drivers should be fine with an older bundled runtime,
while the very newest ASIO drivers may require a newer runtime than an old
Processing release provides. Using a current Processing release (4.5.x at the
time of writing) avoids the issue.
Native DLLs / building
The prebuilt 64-bit
jasiohost64.dllis included inlibrary/windows-amd64/and
jasiohost-master/; the maintainer does not need to build it. ASIO SDKsources are not committed because of Steinberg's license.
PATCHES.mddocuments the exact changes and the MSVC build command. The 32-bit DLL is
unchanged; Processing 4 uses a 64-bit JVM.
Notes
limitation.
Refs #87