philburk / jsyn

Modular audio synthesizer library with unit generators in Java
http://www.softsynth.com/jsyn
Apache License 2.0
217 stars 61 forks source link

Cannot switch between multiple audio devices #125

Open philburk opened 2 months ago

philburk commented 2 months ago

This was reported by Davide Mauro. Thanks Davide.

On Windows 11, in our application we have multiple interfaces that can be selected, and we can select each interface once, if I say I go from 1 to 2, then back to 1, when I select 1 for the second time I get:

INFO: JSyn synthesis thread in finally code.
java.lang.RuntimeException: AudioInput stop attempted when no line created.
at com.jsyn.devices.javasound.JavaSoundAudioDevice$JavaSoundInputStream.stop(Unknown Source)
at com.jsyn.engine.SynthesisEngine$EngineThread.run(Unknown Source).

The process is stop for the current one, start for the new one.

The same code runs fine on Mac OS.

philburk commented 2 months ago

More from Davide:

First time we start with the default: private final Synthesizer synth = JSyn.createSynthesizer(); this.synth.setRealTime(true); this.synth.start();

Then, if we want to change the device: this.synth.stop(); We have a method that gives us a list of devices: AudioDeviceManager audioManager = AudioDeviceFactory.createAudioDeviceManager(); int numDevices = audioManager.getDeviceCount(); ...

Then once we have the deviceID: int deviceInputChannels = this.synth.getAudioDeviceManager().getMaxInputChannels(deviceID); this.synth.start(44100, deviceID,deviceInputChannels,AudioDeviceManager.USE_DEFAULT_DEVICE, 0);

philburk commented 2 months ago

There may be an issue with reusing a synth with different numbers of input and output channels.

Murivan commented 2 months ago

There may be an issue with reusing a synth with different numbers of input and output channels.

We not currently experiencing the problem BUT we have done a number of changes to both JSyn and jportaudio. This was prompted by another problem that we were experiencing. Our target platform is Windows, so we were planning on using ASIO drivers. When we included the relevant portaudio implementation and jportaudio bindings we discovered that some audio cards were working and some were not.

Out of the box the application was working fine with an Audient ID 14 MKII and a RME Babyface FS, but not with a MOTU M4 or a Tascam Model 12, and ASIO 4ALL generic drivers.

The reported error is: WaitForSingleObject() timed out in ReadStream() java.lang.RuntimeException: Wait timed out at com.portaudio.BlockingStream.readFloats(Native Method) at com.portaudio.BlockingStream.read(BlockingStream.java:100) at com.jsyn.devices.jportaudio.JPortAudioDevice$JPAInputStream.read(JPortAudioDevice.java:233) at com.jsyn.devices.jportaudio.JPortAudioDevice$JPAInputStream.read(JPortAudioDevice.java:224) at com.jsyn.engine.SynthesisEngine$EngineThread.run(SynthesisEngine.java:330) Apr 25, 2024 8:45:04 AM com.jsyn.engine.SynthesisEngine$EngineThread run INFO: JSyn synthesis thread in finally code. WaitForSingleObject() timed out in StopStream()

We then modified JPortAudioDevice.java in JSyn from private static final int FRAMES_PER_BUFFER = 128; to private static final int FRAMES_PER_BUFFER = 256;

Recompiling the library made the MOTU M4 (only with a specific set of parameters, screenshot included) and ASIO4ALL (but only with some interfaces, e.g. VB-Cable virtual driver) working, but still no luck with Tascam. Further increasing the value did not lead to improvements. image