- Notifications
You must be signed in to change notification settings - Fork275
Cross-platform Audio Visualizer
License
karlstav/cava
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Cross-platformAudioVisualizer
Now also supportsdumb terminals!
- What it is
- Installing
- Capturing audio
- Running via ssh
- Troubleshooting
- Usage
- Configuration
- Using cava in other applications
- Contribution
Cava is a bar spectrum audio visualizer for terminal or desktop (SDL).
works on:
- Linux
- FreeBSD
- macOS
- Windows
This program is not intended for scientific use. It's written to look responsive and aesthetic when used to visualize music.
Required components:
Recommended components:
The development lib of one of these audio frameworks, depending on your distro:
- ALSA
- Pulseaudio
- Pipewire
- Portaudio
- Sndio
- JACK
Optional components:
- SDL2 dev files
- autoconf-archive (needed for setting up OpenGL)
- ncursesw dev files (bundled in ncurses in arch)
Only FFTW, iniparser and the build tools are actually required for CAVA to compile, but this will only give you the ability to read from fifo files. To capture audio directly from your system pipewire, pulseaudio, alsa, sndio, jack or portaudio dev files are required (depending on what audio system you are using).
Ncurses can be used as an alternative output method if you have issues with the default one. But it is not required.
All the requirements can be installed easily in all major distros:
FreeBSD
pkg install autoconf automake fftw3 iniparser jackit libglvnd libtool pkgconf psftools sdl2 sndioAdditionally, run these commands on FreeBSD before building:
export CFLAGS="-I/usr/local/include"export LDFLAGS="-L/usr/local/lib"Debian/Ubuntu:
sudo apt install build-essential libfftw3-dev libasound2-dev libpulse-dev libtool automake libiniparser-dev libsdl2-2.0-0 libsdl2-dev libpipewire-0.3-dev libjack-jackd2-dev pkgconfArchLinux:
pacman -S base-devel fftw alsa-lib iniparser pulseaudio pkgconfopenSUSE:
zypper install alsa-devel fftw3-devel libpulse-devel libtool pkgconfFedora:
dnf install alsa-lib-devel fftw3-devel pulseaudio-libs-devel libtool iniparser-devel pkgconfmacOS:
First install homebrew if you have't already:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"Then install prerequisites:
brew install fftw libtool automake pkgconf portaudio iniparserThe installation location for Homebrew packages is different between Intel Macs and Apple Silicon Macs.As such, the commands will be a little bit different.You can find out which type you havehere
For both machines, run these commands to fix macOS not finding libtool:
export LIBTOOL=`which glibtool`export LIBTOOLIZE=`which glibtoolize`ln -s `which glibtoolize` /usr/local/bin/libtoolizeNote that the file name may be a little bit different depending on the versions, but the directory should be the same.
Additionally, run these commands on Apple Silicon Macs so that ./configure can find the Homebrew packages:
export LDFLAGS="-L/opt/homebrew/lib"export CPPFLAGS="-I/opt/homebrew/include"Intel Mac instructions tested on macOS Big Sur.
Apple Silicon instructions tested on macOS Ventura.
Windows:
see separate readme incava_win folder.
First of all clone this repo and cd in to it, then run:
./autogen.sh./configuremakeIf you have a recommended component installed, but do not wish to use it (perhaps if building a binary on one machine to be used on another), then the corresponding feature can be disabled during configuration (see configure --help for details).
For windows there is a VS solution file in thecava_win folder.
Installcava to default/usr/local:
make installOr you can changePREFIX, for example:
./configure --prefix=PREFIX
make uninstallAll distro specific installation sources might be out of date. Please check version before reporting any issues here.
pkg install cavaTumbleweed users have cava in their repo. They can just use:
zypper in cavaLeap users need to add the multimedia:apps repository first:
zypper ar -f obs://multimedia:apps/openSUSE_Leap_42.2 multimediaIf you use another version just replaceopenSUSE_Leap_42.2 withopenSUSE_13.2, adjust it to your version.
Cava is available in Fedora 26 and later. You can install Cava byrunning:
dnf install cavaCava is available in Arch Linux official repo:
pacman -S cavasudo apt install cavaHarshal Sheth has added CAVA to his PPA, it can be installed with:
add-apt-repository ppa:hsheth2/ppaapt updateapt install cavacava is in homebrew.
brew install cavaAll config options are set in theconfig file.
method = pipewireThis is the default input method if supported on your system. The default source isauto and will most likely be your currently selected output.If you run wireplumber you can usewpctl to get theobject.path orobject.serial of the desired device to visualize.
e.g.
source = alsa:pcm:3:front:3:playbackmethod = pulseThe default source isauto and should be your currently selected output.
If nothing happens you might have to use a different source than the default. The default might also be your microphone.
method = alsaALSA can be difficult because there is no native way to grab audio from an output. If you want to capture audio straight from the output (not just mic or line-in), you must create an ALSA loopback interface, then output the audio simultaneously to both the loopback and your normal interface.
To create a loopback interface simply run:
sudo modprobe snd_aloop
Hopefully youraplay -l should now contain a loopback interface.
To make it persistent across boot add the linesnd-aloop to "/etc/modules". To keep it from being loaded as the first soundcard add the lineoptions snd-aloop index=1 to "/etc/modprobe.d/alsa-base.conf", this will load it at '1'. You can replace '1' with whatever makes most sense in your audio setup.
Playing the audio through your Loopback interface makes it possible for cava to capture it, but there will be no sound in your speakers. In order to play audio on the loopback interface and your actual interface you must make use of the ALSA multi channel.
Look at the included example fileexample_files/etc/asound.conf on how to use the multi channel. I was able to make this work with an HD Audio Intel PCH sound card, but I had no luck with a USB DAC.
Read more about the ALSA methodhere.
If you are having problems with the alsa method on Raspberry PI, try enablingmmap by adding the following line to/boot/config.txt and reboot:
dtoverlay=i2s-mmap@reluekiss, was able to make cava work with dmix. Check out the example config inexample_files/etc/asound_dmix.conf and issue534.
Add these lines in mpd:
audio_output { type "fifo" name "my_fifo" path "/tmp/mpd.fifo" format "44100:16:2"}Uncomment and change input method tofifo in theconfig file.
The path of the fifo can be specified with thesource parameter.
I had some trouble with sync (the visualizer was ahead of the sound). Reducing the ALSA buffer in mpd fixed it:
audio_output { type "alsa" name "My ALSA" buffer_time "50000" # (50ms); default is 500000 microseconds (0.5s)}method = sndioSndio is the audio framework used on OpenBSD, but it's also available on FreeBSD, NetBSD and Linux.So far this is only tested on FreeBSD, but it's probably very similar on other operating systems. Thefollowing example demonstrates how to setup CAVA for sndio on FreeBSD (please consult theOSSsection for a deeper explanation of the variouspcmX sound devices and the corresponding/dev/dspXaudio devices in this example).
$ cat /dev/sndstatInstalled devices:pcm0:<Realtek ALC1220 (Rear Analog)> (play/rec) defaultpcm1:<Realtek ALC1220 (Front Analog Mic)> (rec)pcm2:<USB audio> (play/rec)No devices installed from userspace.
Sndio operates on device descriptors. In general for every/dev/dspX audio device there is a correspondingrsnd/X sndio raw device descriptor. In this example there arersnd/0,rsnd/1 andrsnd/2 (theyare not listed in/dev, sndio uses these descriptors to access the corresponding audio devices internally).Sndio also handles the implicitdefault device descriptor, which acts like a symlink to the raw devicedescriptor corresponding to the default audio device/dev/dsp. In this example it acts like a symlinktorsnd/0 because the default audio device/dev/dsp symlinks to/dev/dsp0. Sndio also evaluatesthe environment variablesAUDIODEVICE andAUDIORECDEVICE. If one of these is set (AUDIORECDEVICEoverridesAUDIODEVICE if both are set) and a sndio-aware program tries to open thedefault devicedescriptor or an unspecified device descriptor, then the program will use the device descriptor specifiedin the environment variable.
Now in order to visualize the mic input in CAVA, thesource value in the configuration file mustbe set to the corresponding audio descriptor:
source = default # default; symlink to rsnd/0 in this example; AUDIORECDEVICE and AUDIODEVICE evaluationsource = # unspecified device descriptor; same as default abovesource = rsnd/0 # for the pcm0 mic on the rearsource = rsnd/1 # for the pcm1 mic on the frontsource = rsnd/2 # for the pcm2 mic on the USB headsetWithsource = default one can switch the visualization on the commandline without changing the configurationfile again:
$ AUDIODEVICE=rsnd/0 cava$ AUDIODEVICE=rsnd/1 cava$ AUDIODEVICE=rsnd/2 cava
Sndio can't record the played back audio with just the raw device descriptors, i.e. the sounds froma music player or a browser which play on the external stereo speakers throughrsnd/0 are not visualizedin CAVA. For this to work the sndio server has to be started and a monitoring sub-device has to becreated. The following example shows how to start the server and create a monitoring sub-devicesnd/0fromrsnd/0 and then start CAVA withAUDIODEVICE pointing to the new monitoring sub-device:
$ sndiod -f rsnd/0 -m play,mon$ AUDIODEVICE=snd/0 cava
Switch between the speakers and the USB headset:
$ sndiod -f rsnd/2 -m play,mon -s usb -f rsnd/0 -m play,mon -s speakers$ AUDIODEVICE=snd/usb cava$ AUDIODEVICE=snd/speakers cava
Consult the manpagesndiod(8) for further information regarding configuration and startup of a sndioserver.
method = ossThe audio system used on FreeBSD is the Open Sound System (OSS).The following example demonstrates how to setup CAVA for OSS on FreeBSD:
$ cat /dev/sndstatInstalled devices:pcm0:<Realtek ALC1220 (Rear Analog)> (play/rec) defaultpcm1:<Realtek ALC1220 (Front Analog Mic)> (rec)pcm2:<USB audio> (play/rec)No devices installed from userspace.
The system has threepcm sound devices,pcm0,pcm1 andpcm2.pcm0 corresponds to the analogoutput jack on the rear, in which external stereo speakers are plugged in, and the analog input jack,in which one could plug in a microphone. Because it encapsulates both, output and input, it is markedasplay/rec. It is also set as thedefault sound device.pcm1 corresponds to another analog inputjack for a mic on the front side and is markedrec. A USB headset with an integrated mic is pluggedin an USB port and the system has created thepcm2 sound device withplay/rec capabilities forit.
In general for everypcmX device there is a corresponding/dev/dspX audio device. In this examplethere are/dev/dsp0,/dev/dsp1 and/dev/dsp2 (the system creates them when needed, they are notlisted vials /dev if they are currently not in use). The system also creates an implicit/dev/dsp,which acts like a symlink to thedefault audio device, in this example to/dev/dsp0.
Now in order to visualize the mic input in CAVA, thesource value in the configuration file mustbe set to the corresponding audio device:
source = /dev/dsp # default; symlink to /dev/dsp0 in this examplesource = /dev/dsp0 # for the pcm0 mic on the rearsource = /dev/dsp1 # for the pcm1 mic on the frontsource = /dev/dsp2 # for the pcm2 mic on the USB headsetOSS can't record the outgoing audio on its own, i.e. the sounds from a music player or a browser whichplay on the external stereo speakers through/dev/dsp0 are not visualized in CAVA. A solution isto use Virtual OSS. It can create virtual audio devices from existing audio devices, in particularit can create a loopback audio device from/dev/dsp0 and from which the played back audio can befed into CAVA:
$ doas pkg install virtual_oss$ doas virtual_oss -r44100 -b16 -c2 -s4ms -O /dev/dsp0 -R /dev/null -T /dev/sndstat -l dsp.cava$ cat /dev/sndstatInstalled devices:pcm0:<Realtek ALC1220 (Rear Analog)> (play/rec) defaultpcm1:<Realtek ALC1220 (Front Analog Mic)> (rec)pcm2:<USB audio> (play/rec)Installed devices from userspace:dsp.cava:<Virtual OSS> (play/rec)
It created a virtual loopback device/dev/dsp.cava from/dev/dsp0. Now the audio is visualizedin CAVA withsource = /dev/dsp.cava in the configuration file. The playback program must have a configurationto use the/dev/dsp.cava device. For programs where this is not possible, e.g. which always use/dev/dsp,replace-l dsp.cava with-l dsp. Virtual OSS can be configured and started as a service on FreeBSD.
method = jackThe JACK Audio Connection Kit (JACK) is a professional sound server API which is available on severaloperating systems, e.g. FreeBSD and Linux.
CAVA is a JACK client with the base client namecava and adheres to the standard server start andstop behaviour, i.e. CAVA starts a JACK server if none is already running and the environment variableJACK_START_SERVER is defined, in which case the server also stops when all clients have exited. Thesource in the CAVA configuration file specifies the name of the JACK server to which CAVA tries toconnect to. The default value isdefault, which is also the default JACK server name. The value canbe empty, in which case it impliesdefault. Therefore the following three entries are equivalent:
; source = defaultsource = defaultsource =One exception is the combination of an emptysource entry and the environment variableJACK_DEFAULT_SERVER.If the environment variable is defined, e.g.export JACK_DEFAULT_SERVER=foo, then the following entriesare equivalent:
source = foosource =Consult the manpagejackd(1) for further information regarding configuration and startup of a JACKserver.
CAVA creates terminal audio-typed (so no MIDI support) input ports. These ports can connect to outputports of other JACK clients, e.g. connect to the output ports of a music player and CAVA will visualizethe music. Currently CAVA supports up to two input ports, i.e. it supports mono and stereo. The numberof input ports can be controlled via thechannels option in the input section of the configurationfile:
channels = 1 # one input port, monochannels = 2 # two input ports, stereo (default)The port's short name is simplyM for mono, andL andR for stereo. The full name of the inputport according to the base client name iscava:M for mono, andcava:L andcava:R for stereo.
The optionautoconnect controls the connection strategy for CAVA's ports to other client's ports:
autoconnect = 0 # don't connect to other ports automaticallyautoconnect = 1 # only connect to other ports during startupautoconnect = 2 # reconnect to new ports regularly (default)The automatic connection strategies scan the physical terminal input-ports, i.e. the real audio devicewhich actually outputs the sound, and applies the same connections to CAVA's ports. In this way CAVAvisualizes the played back audio from JACK clients by default.
In order to control and manage the connection between CAVA's ports and ports of other client programs,there are connection management programs for JACK. Some well known connection managers with a graphicaluser interface are QjackCtl and Cadence. The JACK package itself often comes with CLI tools. Dependingon the operating system it could be necessary to install them separately, e.g. on FreeBSD:
$ doas pkg install jack-example-tools
Among the tools are the programsjack_lsp andjack_connect. These two tools are enough to listand connect ports on the commandline. The following example demonstrates how to setup connections withthese tools:
$ jack_lspsystem:capture_1system:capture_2system:playback_1system:playback_2cava:Lmoc:output0moc:output1cava:R
This listing shows all full port names that are currently available. These correspond to two externalJACK clients,cava andmoc, and one internal JACK clientsystem. The types and current activeconnections between the ports can be listed with the-p and-c switches forjack_lsp. In orderto connect the ports of CAVA and MOC,jack_connect is used:
$ jack_connect cava:L moc:output0$ jack_connect cava:R moc:output1
Now CAVA visualizes the outgoing audio from MOC.
squeezelite is one of several software clients available for the Logitech Media Server. Squeezelite can export its audio data as shared memory, which is what this input module uses.Just adapt yourconfig:
method = shmemsource = /squeezelite-AA:BB:CC:DD:EE:FFwhereAA:BB:CC:DD:EE:FF is squeezelite's MAC address (check the LMS Web GUI (Settings>Information) if unsure).Note: squeezelite must be started with the-v flag to enable visualizer support.
method = portaudioPortaudio is the default and only supported way of capturing audio on macOS. Unfortunately portaudio can not capture audio directly from the output, but there are several ways to achieve this:
Background Music
InstallBackground Music which provides a loopback interface automatically. Once installed and running just edit yourconfig to use this interface with portaudio:
source = "Background Music"BlackHole
InstallBlackHole and create aMulti Output Device, making sure you have your speaker as the first output device in the list, and BlackHole as second (check the2ch to16ch or64ch if you're using those):
source = "BlackHole 2ch"Sound Flower
Soundflower also works to create a loopback interface. Use Audio MIDI Setup to configure a virtual interface that outputs audio to both your speakers and the loopback interface, followingthis recipe. By creating a multi-output device you lose the ability to control the volume on your keyboard. Because of this, we recommend the Background Music app which still gives you keyboard controls.
Then edit yourconfig to use this interface with portaudio:
method = portaudiosource = "Soundflower (2ch)"Note: Cava doesn't render correctly within the default macOS terminal. In order to achieve an optimal display, installKitty. Beware that you may run in to the issue presented in #109; however, it can be resolved withthis.
Should capture the audio from the default output device automatically. No config needed.
To run via ssh to an external monitor, redirect output to/dev/console:
~# ./cava <> /dev/console >&0 2>&1exit with ctrl+z then run 'bg' to keep it running after you log out.
(You must be root to redirect to console. Simple sudo is not enough: Runsudo su first.)
Most likely issue#399. Locale settings need to be set correctly in order for cava to work.
Read the chapter oncapturing audio. Depending on your system this might not work automatically. For example if you have pipewire dev files on your system, but are still using pulseaudio, you will have to specifypulse as your input method in the cava config file.
This is a known issue with pipewire. Try the workaround describedhere
This is either an issue with the font, or line spacing being enabled in the terminal emulator. Try to change font or disable line spacing.
Since the graphics are simply based on characters, try decreasing the font size.
Some terminal emulators are just slow. Cava will look best in a GPU based terminal like kitty or alacritty. You can also try to increase the font size
If you run cava in a TTY (like ctrl+alt+F2) the program will change the font to the includedcava.psf (actually a slightly modified "unifont").
In console fonts it seems that only 256 Unicode characters are supported, probably because they are bitmap fonts. I could not find a font with Unicode characters 2581-2587 (the 1/8 - 7/8 blocks used on the top of each bar to increase resolution).
So incava.psf, the characters 1-7 are actually replaced by Unicode characters 2581-2587. When cava exits, it changes the font back. If cava exits abnormally and you notice that 1-7 are replaced by partial blocks, just change the font withsetfont.
Actually,setfont is supposed to return the default font, but this usually isn't set. I haven't found another way to get the current font. So cava sets the font to "Lat2-Fixed16" when interrupted. All major distros should have it. It will revert to your default font at reboot.
Konsole simply does not support this.#194
Usage : cava [options]Visualize audio input in terminal.Options: -p path to config file -v print versionExit with ctrl+c or q.
If cava quits unexpectedly or is force killed, echo must be turned on manually withstty -echo.
| Key | Description |
|---|---|
| up /down | increase/decrease sensitivity |
| left /right | increase/decrease bar width |
| f /b | change foreground/background color |
| r | Reload configuration |
| c | Reload colors only |
| q orCTRL-C | Quit C.A.V.A. |
By default a configuration file is created upon first launch in$XDG_CONFIG_HOME/cava/config or$HOME/.config/cava/config, but cava can also be made to use a different file with the-p option.
Sending cava a SIGUSR1 signal, will force cava to reload its configuration file. Thus, it behaves as if the user pressedr in the terminal. One might send a SIGUSR1 signal usingpkill orkillall.For example:
$ pkill -USR1 cavaSimilarly, sending cava a SIGUSR2 signal will only reload the colors from the configuration file, which is the same as pressingc in the terminal. This is slightly faster than reloading the entire config as the audio processing does not need to reinitialize.
$ pkill -USR2 cavaColors can be loaded from a separate file by using thetheme option in the config.
Examples on how the equalizer works:
[eq]1=02=13=04=15=0[eq]1=22=23=14=15=0.5The core processing engine in cava has been split into a separate librarycavacore. See CAVACORE.md for details.
You can also use Cava's output for other programs by using raw output mode, which will write bar data toSTDOUT that can be piped into other processes. More information on this option is documented inthe example config file.
A useful starting point example script written in python that consumes raw data can be foundhere.
is a stand-alone component for making Cava's raw values available asserver-sent events. With this, any application can use CAVA's output data over the network.
Please readCONTRIBUTING.md before opening a pull request.
Thanks to:
for major contributions in the early development of this project.
Also thanks todpayne for figuring out how to find the pulseaudio default sink name.
About
Cross-platform Audio Visualizer
Topics
Resources
License
Contributing
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.


