neverpanic.de

S/PDIF keepalive using mpv and ffmpeg

| Comments

For sound output at my desk, I connect my dock to a digital audio receiver with a Toslink optical audio cable using S/PDIF. In this setup, the connection between my laptop and the reciever stops if there is no audio output for a while. This power saving measure is the road to hell that’s paved with good intentions: if audio output resumes for a notification sound, it takes the receiver about half a second before it starts playing. This delay cuts off the start of the sound.

Teufel decoderstation 5 showing 'No Signal' on optical input 2

To make matters worse, the amplifier in my subwoofer also has a power saving feature and turns off if it detects no output for a while.

To prevent this, I needed continuous sound output that would keep both the S/PDIF channel between my dock and my receiver open as well as my amplifier convinced that it’s still playing audio. At the same time, that audio stream should be as imperceptible as possible to me.

The open source ffmpeg library contains a configurable noise generator that can solve this problem. The anoisesrc audio source provides different “colors” of noise, and the mpv(1) player can play these sources. A small script called silence in my $PATH now prevents my receiver and amplifier from going into power saving:

#!/bin/sh
exec mpv av://lavfi:anoisesrc=r=44100:a=0.01:c=violet

I settled on the “violet” noise color (c=violet), because I found it to be the one I would notice the least. The a=0.01 parameter reduces the volume of the noise signal, while r=44100 sets the sample rate to 44.1 kHz.

For now, I start this script manually when I need it. I should probably automate starting it when my audio output is via S/PDIF and I’m not trying to use it for encoded output such as Dolby Digital or DTS, but I won’t let good enough be the enemy of perfect here.

Teufel decoderstation 5 showing '5.1 Stereo' on optical input 2

Comments

Please enable JavaScript to view comments. Note that comments are provided by a local instance of Isso. No data is sent to third party servers. For more information, see the privacy policy.