Selecting audio output device

If you don’t specify a sound device for output or input, Klipspringer uses the Java audio system default, which may not always be what you want. Maybe it’s not the audio hardware you want to use, or maybe the sound data is tampered with, resulting in inferior sound quality or unnecessary inefficiency.

Listing available devices

The klipdevices utility, lists available choices. When run in a terminal window on my Macbook, klipdevices produced the following output.

-------- Inputs: --------
"Default Audio Device" (Direct Audio Device: Default Audio Device)
"Listen Wireless" (Direct Audio Device: Listen Wireless)
"MacBook Air Microphone" (Direct Audio Device: MacBook Air Microphone)
"Microsoft Teams Audio" (Direct Audio Device: Microsoft Teams Audio)
"ZoomAudioDevice" (Direct Audio Device: ZoomAudioDevice)
-------- Outputs: --------
"Default Audio Device" (Direct Audio Device: Default Audio Device)
"Listen Wireless" (Direct Audio Device: Listen Wireless)
"MacBook Air Speakers" (Direct Audio Device: MacBook Air Speakers)
"Microsoft Teams Audio" (Direct Audio Device: Microsoft Teams Audio)
"ZoomAudioDevice" (Direct Audio Device: ZoomAudioDevice)

When running kliptrack or kliptune, the output device can be specified by giving either its number or name as the argument to -output (see below for how to specify it to the Klipspringer hub). The corresponding option to specify the input device of kliptune is -device. For instance, to specify speaker output on my Mac:

kliptrack -output "MacBook Air Speakers" audiofile.flac

If instead I want to hear it in my Bluetooth-connected Focal Listen wireless headphones, I use -output "Listen Wireless".

When I run klipdevices on the computer on my stereo shelf (an Intel NUC with Ubuntu Linux), where Klipspringer is installed with ALSA module support, I get:

-------- Inputs: --------
"default [default]" (Direct Audio Device: default, default, default)
"PCH [plughw:0,0]" (Direct Audio Device: HDA Intel PCH, ALC283 Analog, ALC283 Analog)
"klipalsa:hw:0,0" (HDA Intel PCH, ALC283 Analog)
"klipalsa:plughw:0,0" (HDA Intel PCH, ALC283 Analog)
-------- Outputs: --------
"default [default]" (Direct Audio Device: default, default, default)
"PCH [plughw:0,0]" (Direct Audio Device: HDA Intel PCH, ALC283 Analog, ALC283 Analog)
"PCH [plughw:0,1]" (Direct Audio Device: HDA Intel PCH, ALC283 Digital, ALC283 Digital)
"PCH [plughw:0,3]" (Direct Audio Device: HDA Intel PCH, HDMI 0, HDMI 0)
"PCH [plughw:0,7]" (Direct Audio Device: HDA Intel PCH, HDMI 1, HDMI 1)
"PCH [plughw:0,8]" (Direct Audio Device: HDA Intel PCH, HDMI 2, HDMI 2)
"klipalsa:hw:0,0" (HDA Intel PCH, ALC283 Analog)
"klipalsa:plughw:0,0" (HDA Intel PCH, ALC283 Analog)
"klipalsa:hw:0,1" (HDA Intel PCH, ALC283 Digital)
"klipalsa:plughw:0,1" (HDA Intel PCH, ALC283 Digital)
"klipalsa:hw:0,3" (HDA Intel PCH, HDMI 0)
"klipalsa:plughw:0,3" (HDA Intel PCH, HDMI 0)
"klipalsa:hw:0,7" (HDA Intel PCH, HDMI 1)
"klipalsa:plughw:0,7" (HDA Intel PCH, HDMI 1)
"klipalsa:hw:0,8" (HDA Intel PCH, HDMI 2)
"klipalsa:plughw:0,8" (HDA Intel PCH, HDMI 2)

The device I prefer (for reasons explained in a blog post) is the one numbered 0,1, which is available in three ways: there’s "klipalsa:hw:0,1", which goes directly to the hardware, "klipalsa:plughw:0,1", which goes via ALSA’s plug module for format conversions, and there’s "PCH [plughw:0,1]", which is how the Java audio system wraps it. To check which formats the variants support I use the -f option with klipdevices: the command klipdevices -o -f "klipalsa:hw:0,1" (where -o means list outputs only) outputs:

klipalsa:hw:0,1
    Bit depths: 16, 32
    Sample rates: 44100, 48000, 88200, 96000, 192000 Hz
    Channels: stereo

So the hardware doesn’t support 24-bit audio which I need for some of my audio files, but that’s no problem because the Klipspringer ALSA module can scale up any bit depth between 17 and 31 into 32-bit, and anything less than 16 into 16-bits, so 16, 32 is enough to handle any bit depth. Klipspringer also handles signedness and endianness conversion if necessary (all conversions that just move bits around and don’t impact the sound quality), and since the listed sample rates include what I need, there is no reason to use plug ("klipalsa:plughw:0,1" reports support for sample rates of 4000–4294967295 Hz). There is also no reason to use the Java audio system variant which goes via plug, and furthermore can’t avoid copying audio data back and forth between JVM memory and the outside like klipalsa can.

Setting Klipspringer hub output device

The device to use when playing audio files with the Klipspringer hub is specified with the -joutput option. Once you know which device you want to use, the most convenient way to specify it is in the options file. For example, my stereo computer has an /etc/klipspringer-hub/options.json that looks like this:

{
    "-joutput": "klipalsa:hw:0,1",
    "-remote": "/dev/input/event3",
    "-numpad": "/dev/input/by-id/usb-05a4_USB_Compliant_Keypad-event-kbd",
    "-serverimage": "server_background.jpg",
    "-streamimage": "client_background.jpg",
    "-vlc-args": ["--aout", "alsa", "--alsa-audio-device", "hw:CARD=PCH,DEV=1"]
}

The first property has the effect that the Klipspringer hub plays audio files with the option -output "klipalsa:hw:0,1" to the track player.

Suppress output

You can specify -output none to suppress audio output. This is less useful with kliptrack than with kliptune, which can still generate output by recording (by pressing the r key).

File output

To output audio data to a file rather than a device, specify a file:// URL, for instance:

kliptrack -output 'file://myfullalbum.wav' mytrack1.flac mytrack2.flac

The output file can be in wav, flac, mp3, or raw format, specified by the extension (where flac and mp3 requires that Klipspringer is built with FLAC and LAME support). For raw files, the file name can contain format options as used by klipcook. If the captured bit depth, sample rate, or number of channels differs from the default (16-bit 44100 Hz stereo), the file name must contain -b, -r, or -c options, or you get an error that the format is not compatible. (Endianness, signedness, or padding may differ between input and output.)

VLC output device

How to configure VLC to use your sound device of choice, when invoked by a vlc source, differs between operating systems and VLC installations, so you may need to consult your VLC documentation to find out. As indicated by the final property in the options file above, I have found that running VLC with --aout "alsa" --alsa-audio-device "hw:CARD=PCH,DEV=1" on the command line selects the output I want, and used the --vlc-args option to specify it to the Klipspringer hub.