template jackd

Most often a computer has multiple soundcards with independent clocks sources. They drift with respect to each other, so trying to group them all in a single jack instance fails.

In some cases this can even apply to multiple devices on the same mainboard or PCB, there may be multple crystals providing clocking.

The Resolution found is to run separate jackd instances, creating a plesiochronous bridge between the synchronous jackd islands.

We define a environment based pcm in ~/.asoundrc to allow separate jackd instances to be steered to their soundcard by environment variable. I have called it jds as short for "jack default server"

This can call hw: pcms set in the environment or others defined in asoundrc if useful to shuffle audio channels to put them in order.

Edit ~/.jackdrc so that it uses the environment

If using qjackctl that can be made to call jds as the input and output alsa device and then different jacks will use their respective alsa hardware.

Define a sub-pcm for the p9d ws onboard...

For the best analogue sound quality use the fastest rate, however toslink attached equipment may not cope with that so downsample if needed,

Upon first attempt a p9d pcm is defined to handle analogue and digital

... and an m-audio m2496 pci card. Here shuffle the digital outputs to the beginning for ease of use.

Lets now startup some jackd. The use of promiscuous mode is useful as then jackd does not include uid in files used to communicate with jack clients. This may enable clients to run in other user accounts in future, for 2019 that does not work well and pulseaudio can be opened up in this way instead.

Suppose alsaplayer connects to the p9d jackd, since subsequenct jackd attached to a running pulseaudio misbehaved, next best things is to loopback the sound between the clocking islands:

At the time of exploring this pulseaudio does not also cope well with being linked to multiple jack instances, so it is probably best to link it to a primary jackd2 that provides clocking, then bridge audio between jacks with jack-record

It is possible to swap p9d with sp2dif in the examples if the latter sounds better.

p9d errors

  1. ERROR: ALSA: could not complete playback of 1024 frames: error = -32
  2. Mon Aug 8 21:05:48 2022: ERROR: ALSA: could not complete read of 1024 frames: error = -32
  3. Mon Aug 8 21:05:48 2022: ERROR: JackAudioDriver::ProcessSync: read error, stopping...

Subsequently it is discovered that PCH pcms drift or something despite being on the same card.

Therefore, instead of using various alsa plugins with PCH, try to make the hardware do it.

  1. pcm.p9d {
  2. type hw
  3. card PCH
  4. }

Use hda-verb to issue instructions to Realtek ALC892

hda-verb /dev/snd/hwC2D0 0 PARAMETERS VENDOR
value = 0x10ec0892 # as in realtek ALC892 codec
hda-verb /dev/snd/hwC2D0 0 PARAMETERS NODE_COUNT
find out how many nodes come off the root 0x00ff00ff (first node index, second node count) = 0x1001, one node
hda-verb /dev/snd/hwC2D0 1 PARAMETERS FUNCTION_TYPE
Find out the function of node 1, 0x101 = audio
hda-verb /dev/snd/hwC2D0 1 PARAMETERS NODE_COUNT
find out how many nodes come off the one at index 1, 0x20025, meaning nodes from 2 to 38 inclusive
Typical default is feeding off sub pcm 3: for ac3 output
hda-verb /dev/snd/`basename /sys/devices/pci0000:00/0000:00:1b.0/sound/card*/hw*` 0x6 0x706 0x60
However I need uncompressed audio, so set the SPDIF output to copy the green rear jack
The 0x50 could be substituted for 0x52 or 0x54 or 0x56 to get grey black and orange jacks
However I need uncompressed audio, so set the SPDIF output to copy the green rear jack
hda-verb /dev/snd/`basename /sys/devices/pci0000:00/0000:00:1b.0/sound/card*/hw*` 0x6 0x706 0x50
The default output 48000Hz, 24-bit, dual channel, is 0x31
hda-verb /dev/snd/`basename /sys/devices/pci0000:00/0000:00:1b.0/sound/card*/hw*` 0x6 GET_STREAM_FORMAT 0
Dual channel, 24-bit 96000Hz output
hda-verb /dev/snd/`basename /sys/devices/pci0000:00/0000:00:1b.0/sound/card*/hw*` 0x6 SET_STREAM_FORMAT 0x831
Dual channel, 32-bit 96000Hz output, the best mode supported by Sennheiser RS220
hda-verb /dev/snd/`basename /sys/devices/pci0000:00/0000:00:1b.0/sound/card*/hw*` 0x6 SET_STREAM_FORMAT 0x841
192000Hz output, Sennheiser RS220 does not support this so get silence, but it can be put back to 96000Hz
hda-verb /dev/snd/`basename /sys/devices/pci0000:00/0000:00:1b.0/sound/card*/hw*` 0x6 SET_STREAM_FORMAT 0x1831

It is also useful to mention programmability of VREFOUT, that is the electrical backfeed of between 2 and 4 volts present on the pc microphone jack, intended to power a preamplifier in a pc microphone, and said to be able to sink upto 5 milliamp of current.

I ended up with a systemd unit to automate that

  1. [Unit]
  2. Description=setup PCH hda
  3. [Service]
  4. ExecStart=/bin/sh -c '\
  5. hda-verb /dev/snd/$(basename /sys/*/*0000:00/0000:00:1b.0/*/*/hw*) 0x6 SET_CHANNEL_STREAMID 0x50\
  6. hda-verb /dev/snd/$(basename /sys/*/*/0000:00:1b.0/*/*/hw*) 0x6 SET_STREAM_FORMAT 0x841\
  7. '
  8. [Install]
  9. WantedBy=sound.target

Enjoy music with sound effects

Debian used to package jack-rack, that has been dropped though it can be still be compiled from source.

Debian also carries jconvolver for an even more realistic virtual concert experience, however not all the impulse response files ship with it, probably for copyright reasons.

Users may replace /var/local/union with the actual path of unpacked downloads.

  1. #!/bin/sh
  2. N=/var/local/union/http/kokkinizita.linuxaudio.org/linuxaudio/downloads/jconvolver-reverbs.tar.bz2/reverbs
  3. R=/var/local/union/http/legacy.spa.aalto.fi/projects/poririrs/wavs/porihall
  4. S=/usr/share/jconvolver/config-files/demo-reverbs/street
  5. C=$(readlink -f $1)
  6. < $C sed -s '
  7. s_/audio/reverbs/spacenet_/net/stat/mirror/https/webfiles.york.ac.uk/OPENAIR/IRs_g;
  8. s+HM2_000_WXYZ_48k.amb+hamilton-mausoleum/b-format/hm2_000_bformat_48k.wav+g;
  9. s+Lyd3_000_WXYZ_48k.amb+st-andrews-church/b-format/lyd3_000_bformat_48k.wav+g;
  10. s+MH3_000_WXYZ_48k.amb+maes-howe/b-format/mh3_000_bformat_48k.wav+g;
  11. s+Minster1_000_WXYZ_48k.amb+york-minster/b-format/minster1_bformat_48k.wav+g;
  12. s_/home/fons/acoustics/impresp/xtc_/usr/share/jconvolver/config-files/xtalk-cancel_g;
  13. s_/audio/reverbs/porihall_'$R'_g;
  14. s_/audio/reverbs_'$N'_g;
  15. s_street_'$S'_g;
  16. ' | jconvolver -s "${JACK_DEFAULT_SERVER}" /dev/stdin

Jackd for OpenAL (Such as ut2004)

Two files in the home directory allow openal applications like unreal tournament 2004 to be used with jack, and so with ALSA cards that do not really have their own mixer.

cat >> ~/.openalrc << EOF
(define devices '(alsa native))
(define alsa-device "plug:SLAVE=jack")

cat >> ~/.asoundrc << EOF
pcm.jack {
        type jack
        playback_ports {
                0 alsa_pcm:playback_1
                1 alsa_pcm:playback_2
        capture_ports {
                0 alsa_pcm:capture_1
                1 alsa_pcm:capture_2

Use Jack / ALSA for festival output

(Parameter.set 'Audio_Method 'Audio_Command)
(Parameter.set 'Audio_Required_Format 'riff)
(Parameter.set 'Audio_Command "aplay -q -D plug:SLAVE=jack $FILE")

Goes in /etc/festival.scm

mkfifo ~/.ut2004/System/speech
while true
        cat ~/.ut2004/System/speech | while read
                echo -ne "(SayText \""
                echo -n $REPLY | sed 's/\\/\\\\/g
                echo -e ".\")"
done | festival

This can now be used to provide a speech device instead of the other method involving a speechd for ut2004