processing / processing-sound

Audio library for Processing built with JSyn
https://processing.org/reference/libraries/sound/
GNU Lesser General Public License v2.1
149 stars 50 forks source link

Add support for 24 bit output devices on Windows #85

Closed kevinstadler closed 1 year ago

kevinstadler commented 1 year ago

Many audio interfaces currently throw a javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported on Windows because 16 bit resolution is hard-coded in JSyn's JavaSoundAudioDevice (or don't list any audio devices to begin with, such as the Motu Ultralite mk5).

This might be fixable by bundling the JPortAudio bindings for Windows and making use of the JPortAudioDevice instead.

Work-in-progress

It turns out that getting (and) keeping the engine and synth in a valid state between device manager/synth switches is actually quite tricky. It goes something like this:

Assuming we are on JavaSound:

After this first (silent) startup, there is a running SynthesisEngine with volume and output nodes.

Whenever the user selects a different input or output device, do the following:

Two outstanding glitches/corner cases:

kevinstadler commented 1 year ago

When the PortAudio dlls and jportaudio.jar are bundled with the library, JSyn will automatically use the JPortAudioDevice as long as

System.loadLibrary("portaudio_x64");

is called before instantiating the AudioDeviceManager.

Since the PortAudio support is still considered experimental, it should probably not become the default mode for Windows, but only be loaded when:

kevinstadler commented 1 year ago

cfb0a1b also prepared the option of including PortAudio libraries for Mac, since JavaSound can sometimes negatively affect the sound output quality when using Bluetooth devices.

Closing this, with many thanks to @trackme518 for testing and support!