idoleat / vsnd

Virtual Linux soundcard driver

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Virtual Soundcard Driver for Linux Kernel

vsnd implements a Linux device driver that introduces a virtual soundcard. Typically, a sound card is a hardware component that enables computers to play audio files. This virtual soundcard, however, is designed to transmit audio PCM data received from various programs directly into a FIFO file.

Prerequisites

The following packages must be installed before building vsnd.

To compile the kernel driver successfully, package versions of currently used kernel, kernel-devel and kernel-headers need to be matched.

$ sudo apt install linux-headers-$(uname -r)

Additional packages are required for verification purpose.

$ sudo apt install alsa-utils ffmpeg

Build and Run

After running make, you should be able to generate the file vsnd.ko.

Before loading this kernel module, you have to satisfy its dependency:

$ sudo modprobe snd_pcm

A FIFO file is required during kernel module initialization and is used for transmitting audio PCM data.

$ mkfifo /tmp/audio.pcm

The module can be loaded to Linux kernel by runnning the command:

$ sudo insmod vsnd.ko out_fifo_name=/tmp/audio.pcm

Then, use aplay to check the soundcard device provided by vsnd.

$ aplay -l

Reference output:

card 0: vsnd [vsnd], device 0: vsnd PCM [vsnd PCM]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

See scripts/verify.sh for automated test.

Run on PulseAudio-enabled environment

If your system uses PulseAudio to control the sound ouput device (i.e., sink), you may undergo with the following error when you select the sink as vsnd from PulseAudio then you try to remove vsnd:

$ sudo rmmod vsnd
rmmod: ERROR: Module vsnd is in use

The reason is that PulseAudio occupies vsnd. Though you can tell PulseAudio to disable vsnd so that you can remove vsnd, we suggest you to disable temporarily when using vsnd by the following command:

$ systemctl --user stop pulseaudio.socket
$ systemctl --user stop pulseaudio.service

After using vsnd, you can execute the following command to bring back PulseAudio:

$ systemctl --user start pulseaudio.service
$ systemctl --user start pulseaudio.socket

Run on PipeWire-enabled environment

In systems use the PipeWire (e.g., Ubuntu 24.04 LTS), you might also encounter the problem that you are not able to remove the vsnd module.

To solve this problem, you need to stop the PipeWire with:

$ systemctl --user stop pipewire.socket
$ systemctl --user stop pipewire

And after removing the module, restart it with:

$ systemctl --user start pipewire

License

vsndis released under the MIT license. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.

Reference

About

Virtual Linux soundcard driver

License:MIT License


Languages

Language:C 96.0%Language:Makefile 2.1%Language:Shell 2.0%