Solved Santa Claus presents: OSS support for audio/cava ... and JACK too?!

I commented out kld_list="${kld_list} cuse" in in /etc/rc.conf.

I followed the suggestion in man virtual_oss:

virtual_oss requires the cuse(3) kernel module. To load the driver as a module at boot time, place the following line in loader.conf(5): cuse_load="YES"


Same story, btw I am using KDE Plasma5 desktop, which starts pulseaudio.
 
I commented out kld_list="${kld_list} cuse" in in /etc/rc.conf.

I followed the suggestion in man virtual_oss:

virtual_oss requires the cuse(3) kernel module. To load the driver as a module at boot time, place the following line in loader.conf(5): cuse_load="YES"

Same story, btw I am using KDE Plasma5 desktop, which starts pulseaudio.
I think cuse(3) is not the problem here. Per your kldstat it is loaded, I believe virtual_oss(8) loads it automatically anyway. If pulseaudio is the culprit here ... I don't know. I mean, sure, pulseaudio is often a problem in general. And I have no idea how pulseaudio and virtual_oss interact, if at all.

That looks like a specific problem with virtual_oss/pulseaudio or something different independend from cava. It would definitly be good to know where the problem is, especially if we want to provide a few infos regarding virtual_oss(8) in the cava documentation. Would you mind opening another thread for this problem? Maybe other users have a fresh eye on your problem. I am a little bit too busy right now with the cava port itself. Sorry I can't help you right now.

EDIT: Note to myself: when the OSS cava port is finished, free KDE from pulseaudio and provide OSS backend for KDE.
 
The addition of the OSS backend and the improved FreeBSD support of CAVA are finished.

Changes:
  • add OSS support for FreeBSD
  • OSS is the default input backend if compiled with OSS support
  • sndio got some love: sndio is now also in the selection sequence for the default input backend. If compiled with sndio support it is the default input backend after OSS
  • increased FreeBSD support in general
  • applied previous port patches, simplifies FreeBSD port
  • especially the VT font creation can be stripped from the port, font creation is now done by CAVA build
  • extended documentation in the example config file and the README.md
A note regarding the "disable noncurses" patch: this patch disabled the noncurses output backend completely because it would garbage the screen (vt(4)). In my tests I haven't encountered this behaviour, therefore I purged this patch and did not apply it.

Currently I have build and tested it only on 13.2-RELEASE with quartely (2023Q4) packages. I build and test on 14.0-RELEASE after the changes get upstreamed to cava. Then is also the time to update the FreeBSD port. If someone wants to build and test the updated CAVA until the port is updated, one can follow these instructions:

Download the git-diff(1) file cava.diff from https://upload.disroot.org/r/KPF8_afo#6wlL13Mo/9U66Wa0Oj2uwZlLRL/aIhx0KAWizNR3yAc=. The file is downloadable for the next 30 days. Put it somewhere inside your build environment, e.g. ~/cava.diff. Then install the build-dependencies:
Code:
# Required
pkg install autotools fftw3 git iniparser pkgconf

# Optional
pkg install autoconf-archive psftools sdl2 sndio
x11-fonts/psftools is needed for the VT font creation, devel/sdl20 is needed for the SDL output backend (you want it), devel/autoconf-archive is needed for the SDL GLSL shader output backend (hell yeah you want it!) and audio/sndio is needed for the sndio input backend (sndio deserves more love too!). Then fetch the latest CAVA source and build it:
Code:
git clone --depth=1 https://github.com/karlstav/cava
cd cava
git apply ~/cava.diff

./autogen.sh

mkdir build
cd build

CFLAGS="-I/usr/local/include" LDFLAGS="-L/usr/local/lib" ../configure --prefix=/opt/cava --disable-input-alsa --disable-input-pipewire --disable-input-pulse --disable-input-portaudio
make
make install

Before running /opt/cava/bin/cava you can copy the updated config file: cp example_files/config ~/.config/cava/config
CAVA doesn't support commandline options or environment variables to change its parameters, but it supports loading a custom config file instead of the standard ~/.config/cava/config with the -p switch. In this way you can have different configurations and appearances for different situations. I have prepared three configs, dependend on which output backend I want:
Code:
$ cat ~/.config/cava/config.ncurses
[output]
alacritty_sync = 1

[smoothing]
monstercat = 1
noise_reduction = 65
Code:
$ cat ~/.config/cava/config.sdl
[general]
framerate = 100

[output]
method = sdl
channels = mono

[color]
background = '#222222'
foreground = '#ffaa00'

[smoothing]
monstercat = 1
noise_reduction = 65
Code:
$ cat ~/.config/cava/config.sdl_glsl
[general]
framerate = 100

[output]
method = sdl_glsl
channels = mono
fragment_shader = northern_lights.frag

[color]
background = '#111111'
foreground = '#00aa55'

[smoothing]
monstercat = 1
noise_reduction = 65
shot.png

Left: sdl
Top right: sdl_glsl
Bottom right: ncurses

Now I need to get in contact with upstream.
 
Hi steps,

I got it working for now, the compiled cava 'we' did a few days ago.

I entered: doas virtual_oss -Q0 -S -C 2 -c 2 -r 44100 -b 16 -s 1024 -P /dev/dsp5 -R /dev/null -w vdsp.wav -l dsp -T /dev/sndstat -t vdsp.ctl -B

If not using doas: virtual_oss: Could not connect to cuse module
 

Attachments

  • Screenshot_20231229_192300.png
    Screenshot_20231229_192300.png
    193.5 KB · Views: 45
Hi steps,

I got it working for now, the compiled cava 'we' did a few days ago.

I modified /etc/devfs.conf and /etc/devfs.rules permissions from 0660 to 0666.
I entered: doas sysctl security.bsd.unprivileged_idprio=1 because some users on the forum had also trouble with cuse in a different setting.
I entered: doas virtual_oss -Q0 -S -C 2 -c 2 -r 44100 -b 16 -s 1024 -P /dev/dsp5 -R /dev/null -w vdsp.wav -l dsp -T /dev/sndstat -t vdsp.ctl -B

I am glade you found a solution!

Is this a common problem with cuse(3) and/or related with the FreeBSD version (aka 14.0 affected)? I just think that changing the permissions on the devfs files is bit radical.
 
I am glade you found a solution!

Is this a common problem with cuse(3) and/or related with the FreeBSD version (aka 14.0 affected)? I just think that changing the permissions on the devfs files is bit radical.
Oeps, I edited the post because changing the permissions was not needed, also doas sysctl security.bsd.unprivileged_idprio=1 is not needed. For me it was just using doas. Hopefully the guru's on this forum can show us the right way.

I don't know the answer on both cuse(3) or if it's FreeBSD version related. I leave this also for the guru's.
 
Oeps, I edited the post because changing the permissions was not needed, also doas sysctl security.bsd.unprivileged_idprio=1 is not needed. For me it was just using doas. Hopefully the guru's on this forum can show us the right way.

I don't know the answer on both cuse(3) or if it's FreeBSD version related. I leave this also for the guru's.
Ah ok, nah, it was just a permission issue. Yes, virtual_oss should be run with elevated privileges. Ok, that's why it worked for you the first time, because you started it as a service. Puzzle solved ;)

Have to update the README.md. Run virtual_oss(8) with doas or sudo. Thank you.
 
Pull request accepted and merged upstream. karlstav has kindly agreed to create a new release with the recent changes in order to help bring the official FreeBSD port up to date.
Next steps for me: finally upgrade my desktop to 14.0-RELEASE, test CAVA again and prepare the port updates.
 
The updated Makefile for the port is ready. When upstream releases the new version then we are ready.

Makefile:
PORTNAME=       cava
DISTVERSION=    0.10.0
PORTREVISION=   0
CATEGORIES=     audio

MAINTAINER=     vendion@gmail.com
COMMENT=        Cross-platform Audio Visualizer
WWW=            https://github.com/karlstav/cava

LICENSE=        MIT
LICENSE_FILE=   ${WRKSRC}/LICENSE

LIB_DEPENDS=    libfftw3.so:math/fftw3 \
                libiniparser.so:devel/iniparser

USES=           autoreconf compiler:c11 libtool localbase pkgconfig
USE_GITHUB=     yes
GH_ACCOUNT=     karlstav

GNU_CONFIGURE=  yes
CONFIGURE_ARGS= --disable-input-alsa \
                --disable-input-pipewire \
                --disable-input-portaudio \
                --disable-input-pulse

PLIST_FILES=    bin/cava
PORTDOCS=       README.md
PORTEXAMPLES=   config

OPTIONS_DEFINE=         DOCS EXAMPLES VT
OPTIONS_DEFAULT=        GLSL NCURSES OSS SDL SNDIO VT

OPTIONS_GROUP=          INPUT OUTPUT
OPTIONS_GROUP_INPUT=    OSS SNDIO
OPTIONS_GROUP_OUTPUT=   GLSL NCURSES SDL

GLSL_DESC=              Build with GLSL support (implies ${GLSL_IMPLIES})
GLSL_BUILD_DEPENDS=     ${LOCALBASE}/share/aclocal/ax_check_gl.m4:devel/autoconf-archive
GLSL_USES=              gl
GLSL_USE=               gl=egl
GLSL_CONFIGURE_OFF=     --disable-output-sdl-glsl
GLSL_IMPLIES=           SDL

NCURSES_DESC=           Build with ncurses support
NCURSES_USES=           ncurses
NCURSES_CONFIGURE_OFF=  --disable-output-ncurses

OSS_DESC=               Build with OSS support
OSS_CONFIGURE_OFF=      --disable-input-oss

SDL_DESC=               Build with SDL support
SDL_USES=               sdl
SDL_USE=                sdl=sdl2
SDL_CONFIGURE_OFF=      --disable-output-sdl

SNDIO_DESC=             Build with sndio support
SNDIO_LIB_DEPENDS=      libsndio.so:audio/sndio
SNDIO_CONFIGURE_OFF=    --disable-input-sndio

VT_DESC=                Build and install custom font for vt(4)
VT_BUILD_DEPENDS=       psf2bdf:x11-fonts/psftools
VT_CONFIGURE_OFF=       --disable-cava-font
VT_PLIST_FILES=         ${DATADIR}/cava.fnt

.include <bsd.port.pre.mk>

.if ${OPSYS} == FreeBSD && ( ${OSVERSION} >= 1400079 || ( ${OSVERSION} >= 1302505 && ${OSVERSION} < 1400000 ))
CFLAGS+=        -Wno-error=deprecated-non-prototype
.endif

pre-configure:
        ${ECHO_CMD} ${DISTVERSION} > ${WRKSRC}/version

post-install-DOCS-on:
        ${MKDIR} ${STAGEDIR}${DOCSDIR}
        ${INSTALL_DATA} ${WRKSRC}/README.md ${STAGEDIR}${DOCSDIR}

post-install-EXAMPLES-on:
        ${MKDIR} ${STAGEDIR}${EXAMPLESDIR}
        ${INSTALL_DATA} ${WRKSRC}/example_files/config ${STAGEDIR}${EXAMPLESDIR}

.include <bsd.port.post.mk>
 
Last edited:
Thank you jbo@ and grahamperrin for your support and help.

And of course thank you rsronin, who ignited the cava fire inside of me and who provided valuable early testing ;).

See you all again in Spaceballs 2: The Search for More Money!
 
bsdcode I was actually giving that a try today. However, I'm not having much success with it (almost definitely PEBKAC).

My system is setup to use sndio (I think. It's either that or just plain OSS). I'm playing music via FireFox (where media.cubeb.backend = oss). Music output via FireFox is definitely working for me.
Firing up audio/cava starts showing the pretty bars but they seem to be almost stuck in some sort of "demo mode". They are moving around but don't seem to "react" to the music playing. Also, if I pause the audio playback, they just keep doing the same thing.

I did briefly glance over $HOME/.config/cava/config and tried explicitly enabling either the sndio or the oss input but to no avail - I always get the same behavior.

Any ideas what I'm doing wrong? Am I too naive to assume that the default config "just works"? :D
 
Any ideas what I'm doing wrong? Am I too naive to assume that the default config "just works"? :D
I know exactly what's going "wrong" on your side ;). The default config works as intented. So let me help you:

First of all (dumb question, just to be sure): you are using the new version 0.10.1, aren't you? Sndio also works in the old 0.7.4 version (albeit with fixed parameters which can prevent it from functioning correctly in certain setups). I assume you are using the recent version with OSS support and improved sndio support.

Did you read the documentation regarding OSS or sndio in the fine /usr/local/share/doc/cava/README.md? The important part is that neither OSS nor sndio are able to record their outgoing audio on their own, i.e. if you play audio over /dev/dsp, which is a symlink to your default audio device /dev/dspX, this audio isn't visualized in CAVA without further setup. I'm sure a cat /dev/sndstat on your side shows us that your default device has a (play/rec) config. What actually gets visualized is your audio input on /dev/dspX, probably your mic or line-in port. And if nothing is connected in that port then CAVA reads "white noise" (I think). That's your "demo mode".

Solution: use audio/virtual_oss for OSS to create a loopback audio device from which CAVA can read your "desktop audio", or start a sndio server and create a monitoring sub-device from which CAVA can read your "desktop audio". I hope that my extended documentation in the README.md can help you. If it still won't work for you then don't hesitate to report here, I'm willing to further investigate with you.

I tested CAVA and www/firefox with OSS and sndio just a moment ago. It sure works just wonderfully :)
 
you are using the new version 0.10.1, aren't you?
That is correct - I am using 0.10.1.

Did you read the documentation regarding OSS or sndio in the fine /usr/local/share/doc/cava/README.md?
I did not. I tried to man cava.
I guess creating a man page is going to be your next upstream contribution 😜
Alternatively, a pkg-message on install might be reasonable (I'm not sure).
Obviously, not trying to shift blame here. Me not reading the documentation is entirely my fault.

I'm sure a cat /dev/sndstat on your side shows us that your default device has a (play/rec) config.
That is correct. Apologies for not having included that in my original message:
Code:
# cat /dev/sndstat
Installed devices:
pcm0: <NVIDIA (0x0083) (HDMI/DP 8ch)> (play)
pcm1: <NVIDIA (0x0083) (HDMI/DP 8ch)> (play)
pcm2: <NVIDIA (0x0083) (HDMI/DP 8ch)> (play)
pcm3: <NVIDIA (0x0083) (HDMI/DP 8ch)> (play)
pcm4: <Realtek ALC1220 (Rear Analog 5.1/2.0)> (play/rec) default
pcm5: <Realtek ALC1220 (Front Analog)> (play/rec)
pcm6: <Realtek ALC1220 (Rear Digital)> (play)
pcm7: <USB audio> (play/rec)
No devices installed from userspace.

I'm gonna give this a try later today or tomorrow. I am clearly inexperienced when it comes to audio on FreeBSD so I need to read up on some stuff first.

Thanks!
 
Back
Top