• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.github/H18-May-2021-10083

example_files/H03-May-2022-186140

iniparser/H18-May-2021-1,704668

input/H03-May-2022-894651

output/H03-May-2022-749562

.clang-formatH A D18-May-202193 76

.gitignoreH A D18-May-2021402 3433

CONTRIBUTING.mdH A D18-May-2021769 1612

LICENSEH A D18-May-20211.1 KiB2016

Makefile.amH A D03-May-20221.2 KiB5842

README.mdH A D18-May-202117.6 KiB477295

autogen.shH A D18-May-2021408 2013

cava.cH A D03-May-202242.7 KiB1,183906

config.cH A D03-May-202218.2 KiB556470

config.hH A D18-May-20211.7 KiB7257

configure.acH A D03-May-20227.8 KiB313248

debug.hH A D18-May-2021313 108

todoH A D18-May-2021231 129

util.hH A D18-May-2021622 118

README.md

1C.A.V.A. [![Build Status](https://github.com/karlstav/cava/workflows/build/badge.svg)](https://github.com/karlstav/cava/actions)
2====================
3
4**C**onsole-based **A**udio **V**isualizer for **A**LSA
5
6also supports audio input from Pulseaudio, fifo (mpd), sndio, squeezelite and portaudio.
7
8Now also works on macOS!
9
10by [Karl Stavestrand](mailto:karl@stavestrand.no)
11
12![spectrum](https://github.com/karlstav/cava/blob/master/example_files/cava.gif "spectrum")
13
14[Demo video](https://youtu.be/9PSp8VA6yjU)
15
16<!-- START doctoc generated TOC please keep comment here to allow auto update -->
17<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
18**Table of Contents**  *generated with [DocToc](https://github.com/thlorenz/doctoc)*
19
20- [What it is](#what-it-is)
21- [Installing](#installing)
22  - [From Source](#from-source)
23    - [Installing Build Requirements](#installing-build-requirements)
24    - [Building](#building)
25    - [Installing](#installing-1)
26    - [Uninstalling](#uninstalling)
27  - [Some distro specific pre-made binaries/recipes](#some-distro-specific-pre-made-binariesrecipes)
28    - [openSUSE](#opensuse)
29    - [Fedora](#fedora)
30    - [Arch](#arch)
31    - [Ubuntu/Debian](#ubuntudebian)
32- [Capturing audio](#capturing-audio)
33  - [Pulseaudio monitor source (Easy, default if supported)](#pulseaudio-monitor-source-easy-default-if-supported)
34  - [ALSA-loopback device (Tricky)](#alsa-loopback-device-tricky)
35  - [mpd's fifo output](#mpds-fifo-output)
36  - [sndio](#sndio)
37  - [squeezelite](#squeezelite)
38  - [macOS](#macos)
39  - [Windows - winscap - WSL](#Windows---winscap---WSL)
40- [Running via ssh](#running-via-ssh)
41  - [Raw Output](#raw-output)
42- [Font notes](#font-notes)
43  - [In ttys](#in-ttys)
44  - [In terminal emulators](#in-terminal-emulators)
45- [Latency notes](#latency-notes)
46- [Usage](#usage)
47  - [Controls](#controls)
48- [Configuration](#configuration)
49- [Contribution](#contribution)
50
51<!-- END doctoc generated TOC please keep comment here to allow auto update -->
52
53
54What it is
55----------
56
57C.A.V.A. is a bar spectrum audio visualizer for the Linux terminal using ALSA, pulseaudio or fifo buffer for input.
58
59This program is not intended for scientific use. It's written to look responsive and aesthetic when used to visualize music.
60
61
62Installing
63------------------
64
65### From Source
66
67#### Installing Build Requirements
68
69Required components:
70* [FFTW](http://www.fftw.org/)
71* libtool
72* automake
73* build-essentials
74* [iniparser](https://github.com/ndevilla/iniparser)
75
76
77Recomended components:
78* [ncursesw dev files](http://www.gnu.org/software/ncurses/) (bundled in ncurses in arch)
79* [ALSA dev files](http://alsa-project.org/), or
80* [Pulseaudio dev files](http://freedesktop.org/software/pulseaudio/doxygen/), or
81* Portaudio, or
82* Sndio
83
84Only FFTW and the other build tools are actually required for CAVA to compile, but this will only give you the ability to read from fifo files. To more easly grab audio from your system pulseaudio, alsa, sndio or portaudio dev files are recommended (depending on what audio system you are using). Not sure how to get the pulseaudio dev files for other distros than debian/ubuntu or if they are bundled in pulseaudio.
85
86
87For better a better visual experience ncurses is also recomended.
88
89Iniparser is also required, but if it is not already installed, a bundled version will be used.
90
91All the requirements can be installed easily in all major distros:
92
93Debian Buster or higher/Ubuntu 18.04 or higher :
94
95    apt install libfftw3-dev libasound2-dev libncursesw5-dev libpulse-dev libtool automake libiniparser-dev
96    export CPPFLAGS=-I/usr/include/iniparser
97
98
99older Debian/Ubuntu:
100
101    apt install libfftw3-dev libasound2-dev libncursesw5-dev libpulse-dev libtool automake
102
103
104ArchLinux:
105
106    pacman -S base-devel fftw ncurses alsa-lib iniparser pulseaudio
107
108
109openSUSE:
110
111    zypper install alsa-devel ncurses-devel fftw3-devel libpulse-devel libtool
112
113
114Fedora:
115
116    dnf install alsa-lib-devel ncurses-devel fftw3-devel pulseaudio-libs-devel libtool
117
118
119macOS:
120
121First install homebrew if you have't already:
122
123    /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
124
125Then install prerequisites:
126
127    brew install fftw ncurses libtool automake portaudio
128
129Then fix macOS not finding libtool and ncursesw:
130
131    export LIBTOOL=`which glibtool`
132    export LIBTOOLIZE=`which glibtoolize`
133    ln -s `which glibtoolize` /usr/local/bin/libtoolize
134    ln -s /usr/lib/libncurses.dylib /usr/local/lib/libncursesw.dylib
135
136Tested on macOS High Sierra.
137
138For M1 Mac I was able to build all prerequisites from source. It might work with homebrew rosetta emulation, but what's the fun in that.
139
140* build and install automake, autoconf and libtool following the instructions [here](https://superuser.com/questions/383580/how-to-install-autoconf-automake-and-related-tools-on-mac-os-x-from-source).
141* build and install fftw from the gz archive [here](http://www.fftw.org/download.html)
142* download ncurses source and configure with these options:
143```
144./configure --prefix=/usr/local \
145  --without-cxx --without-cxx-binding --without-ada --without-progs --with-curses-h \
146  --with-shared --without-debug  \
147  --enable-widec --enable-const --enable-ext-colors --enable-sigwinch --enable-wgetch-events \
148```
149* just clone portaudio repo, build and install.
150* install [Backround Music](https://github.com/kyleneideck/BackgroundMusic) following option 1 in "Installing from Source Code". (requires xcode)
151* then build cava normally and follow the instructions in "capturing audio"
152
153
154
155
156#### Building
157 First of all clone this repo and cd in to it, then run:
158
159    ./autogen.sh
160    ./configure
161    make
162
163If 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).
164
165
166
167#### Installing
168
169Install `cava` to default `/usr/local`:
170
171    make install
172
173Or you can change `PREFIX`, for example:
174
175   ./configure --prefix=PREFIX
176
177#### Uninstalling
178
179    make uninstall
180
181
182### Some distro specific pre-made binaries/recipes
183#### openSUSE
184
185Tumbleweed users have cava in their repo. They can just use:
186
187    zypper in cava
188
189Leap users need to add the multimedia:apps repository first:
190
191    zypper ar -f obs://multimedia:apps/openSUSE_Leap_42.2 multimedia
192
193If you use another version just replace *openSUSE_Leap_42.2* with *openSUSE_13.2*, adjust it to your version.
194
195#### Fedora
196
197Cava is available in Fedora 26 and later.  You can install Cava by
198running:
199
200    dnf install cava
201
202#### Arch
203
204Cava is in [AUR](https://aur.archlinux.org/packages/cava/).
205
206    pacaur -S cava
207
208#### Ubuntu/Debian
209
210##### Ubuntu 20.10 or more recent / Debian (unstable)
211
212    apt install cava
213
214##### Older Ubuntu
215
216Harshal Sheth has added CAVA to his PPA, it can be installed with:
217
218    add-apt-repository ppa:hsheth2/ppa
219    apt update
220    apt install cava
221
222
223All distro specific instalation sources might be out of date.
224
225
226Capturing audio
227---------------
228
229### Pulseaudio monitor source (Easy, default if supported)
230
231Just make sure you have installed pulseaudio dev files and that cava has been built with pulseaudio support (it should be automatically if the dev files are found).
232
233If you're lucky all you have to do is to run cava.
234
235If nothing happens you might have to use a different source than the default. The default might also be your microphone. Look at the [config](#configuration) file for help.
236
237
238### ALSA-loopback device (Tricky)
239
240Set
241
242    method = alsa
243
244in the [config](#configuration) file.
245
246ALSA can be difficult because there is no native way to grab audio from an output. If you want to capture audio straight fom 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.
247
248To create a loopback interface simply run:
249
250`sudo modprobe snd_aloop`
251
252Hopefully your `aplay -l` should now contain a loopback interface.
253
254To make it persistent across boot add the line `snd-aloop` to "/etc/modules". To keep it from being loaded as the first soundcard add the line `options 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.
255
256Playing 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.
257
258Look at the included example file `example_files/etc/asound.conf` on how to use the multi channel. I was able to make this work on my laptop (an Asus UX31 running Ubuntu), but I had no luck with the ALSA method on my Raspberry Pi (Rasbian) with an USB DAC. The PulseAudio method however works perfectly on my Pi.
259
260Read more about the ALSA method [here](http://stackoverflow.com/questions/12984089/capture-playback-on-play-only-sound-card-with-alsa).
261
262If you are having problems with the alsa method on Rasberry PI, try enabling `mmap` by adding the following line to `/boot/config.txt` and reboot:
263
264```
265dtoverlay=i2s-mmap
266```
267
268### mpd's fifo output
269
270Add these lines in mpd:
271
272    audio_output {
273        type                    "fifo"
274        name                    "my_fifo"
275        path                    "/tmp/mpd.fifo"
276        format                  "44100:16:2"
277    }
278
279Uncomment and change input method to `fifo` in the [config](#configuration) file.
280
281The path of the fifo can be specified with the `source` parameter.
282
283I had some trouble with sync (the visualizer was ahead of the sound). Reducing the ALSA buffer in mpd fixed it:
284
285    audio_output {
286            type            "alsa"
287            name            "My ALSA"
288            buffer_time     "50000"   # (50ms); default is 500000 microseconds (0.5s)
289    }
290
291### sndio
292
293sndio is the audio framework used on OpenBSD, but it's also available on
294FreeBSD and Linux. So far this is only tested on FreeBSD.
295
296To test it
297```bash
298# Start sndiod with a monitor sub-device
299$ sndiod -dd -s default -m mon -s monitor
300
301# Set the AUDIODEVICE environment variable to override the default
302# sndio device and run cava
303$ AUDIODEVICE=snd/0.monitor cava
304```
305
306### squeezelite
307[squeezelite](https://en.wikipedia.org/wiki/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.
308Just adapt your [config](#configuration):
309```
310method = shmem
311source = /squeezelite-AA:BB:CC:DD:EE:FF
312```
313where `AA:BB:CC:DD:EE:FF` is squeezelite's MAC address (check the LMS Web GUI (Settings>Information) if unsure).
314Note: squeezelite must be started with the `-v` flag to enable visualizer support.
315
316### macOS
317
318Note: Cava doesn't render correctly within the default macOS terminal. In order to achieve an optimal display, install [Kitty](https://sw.kovidgoyal.net/kitty/index.html). Beware that you may run in to the issue presented in #109; however, it can be resolved with [this](https://stackoverflow.com/questions/7165108/in-os-x-lion-lang-is-not-set-to-utf-8-how-to-fix-it).
319
320**Background Music**
321
322Install [Background Music](https://github.com/kyleneideck/BackgroundMusic) which provides a loopback interface automatically. Once installed and running just edit your [config](#configuration) to use this interface with portaudio:
323
324```
325method = portaudio
326source = "Background Music"
327```
328
329**Sound Flower**
330
331[Soundflower](https://github.com/mattingalls/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, following [this](https://github.com/RogueAmoeba/Soundflower-Original/issues/44#issuecomment-151586106) 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.
332
333Then edit your [config](#configuration) to use this interface with portaudio:
334
335```
336method = portaudio
337source = "Soundflower (2ch)"
338```
339
340### Windows - winscap - WSL
341
342@quantum5 has written a handy tool called [winscap](https://github.com/quantum5/winscap) to capture audio from Windows and output it to stdout. Just follow the instructions in the readme on how to set it up with cava.
343
344
345Running via ssh
346---------------
347
348To run via ssh to an external monitor, redirect output to `/dev/console`:
349
350     ~# ./cava  <> /dev/console >&0 2>&1
351
352exit with ctrl+z then run 'bg' to keep it running after you log out.
353
354(You must be root to redirect to console. Simple sudo is not enough: Run `sudo su` first.)
355
356### Raw Output
357
358You can also use Cava's output for other programs by using raw output mode, which will write bar data to `STDOUT` that can be piped into other processes. More information on this option is documented in [the example config file](/example_files/config).
359
360A useful starting point example script written in python that consumes raw data can be found [here](https://github.com/karlstav/cava/issues/123#issuecomment-307891020).
361
362Font notes
363----------
364
365Since the graphics are simply based on characters, performance is dependent on the terminal font.
366
367### In ttys
368
369If you run this in a TTY the program will change the font to the included `cava.psf` (actually a slightly modified "unifont").
370
371In 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).
372
373So in `cava.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 with `setfont`.
374
375Actually, `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.
376
377### In terminal emulators
378
379In terminal emulators like `xterm`, the font settings is chosen in the software and cannot be changed by an application. So find your terminal settings and try out different fonts and settings. Also character spacing affects the look of the bar spectrum.
380
381Performance is also different, urxvt is the best I found so far, while Gnome-terminal is quite slow.
382
383Cava also disables the terminal cursor, and turns it back on on exit, but in case it terminates unexpectedly, run `setterm -cursor on` to get it back.
384
385Tip: Cava will look much nicer in small font sizes. Use a second terminal emulator for cava and set the font size to 1. Warning, can cause high CPU usage and latency if the terminal window is too large!
386
387
388Latency notes
389-------------
390
391If you see latency issues (sound before image) in a terminal emulator, try increasing the font size. This will reduce the number of characters that have to be shown.
392
393If your audio device has a huge buffer, you might experience that cava is actually faster than the audio you hear. This reduces the experience of the visualization. To fix this, try decreasing the buffer settings in your audio playing software.
394
395Usage
396-----
397
398    Usage : cava [options]
399    Visualize audio input in terminal.
400
401    Options:
402    	    -p          path to config file
403    	    -v          print version
404
405
406
407Exit with ctrl+c or q.
408
409If cava quits unexpectedly or is force killed, echo must be turned on manually with `stty -echo`.
410
411### Controls
412
413NOTE: only works in ncurses output mode.
414
415| Key | Description |
416| --- | ----------- |
417| <kbd>up</kbd> / <kbd>down</kbd>| increase/decrease sensitivity |
418| <kbd>left</kbd> / <kbd>right</kbd>| increase/decrease bar width |
419| <kbd>f</kbd> / <kbd>b</kbd>| change foreground/background color |
420| <kbd>r</kbd> | Reload configuration |
421| <kbd>c</kbd> | Reload colors only |
422| <kbd>q</kbd> or <kbd>CTRL-C</kbd>| Quit C.A.V.A. |
423
424Configuration
425-------------
426
427As of version 0.4.0 all options are done in the config file, no more command-line arguments!
428
429By default a configuration file is located 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.
430
431If for some reason the config file is not in the config dir, copy the [bundled configuration file](/example_files/config) to the config dir manually.
432
433Sending cava a SIGUSR1 signal, will force cava to reload its configuration file. Thus, it behaves as if the user pressed <kbd>r</kbd> in the terminal. One might send a SIGUSR1 signal using `pkill` or `killall`.
434For example:
435```
436$ pkill -USR1 cava
437```
438
439Similarly, sending cava a SIGUSR2 signal will only reload the colors from the configuration file, which is the same as pressing <kbd>c</kbd> in the terminal. This is slightly faster than reloading the entire config as the audio processing does not need to reinitialize.
440```
441$ pkill -USR2 cava
442```
443
444**Examples on how the equalizer works:**
445
446    [eq]
447    1=0
448    2=1
449    3=0
450    4=1
451    5=0
452
453![3_138](https://cloud.githubusercontent.com/assets/6376571/8670183/a54a851e-29e8-11e5-9eff-346bf6ed91e0.png)
454
455    [eq]
456    1=2
457    2=2
458    3=1
459    4=1
460    5=0.5
461
462![3_139](https://cloud.githubusercontent.com/assets/6376571/8670181/9db0ef50-29e8-11e5-81bc-3e2bb9892da0.png)
463
464Contribution
465------
466
467Please read CONTRIBUTING.md before opening a pull request.
468
469Thanks to:
470* [CelestialWalrus](https://github.com/CelestialWalrus)
471* [anko](https://github.com/anko)
472* [livibetter](https://github.com/livibetter)
473
474for major contributions in the early development of this project.
475
476Also thanks to [dpayne](https://github.com/dpayne/) for figuring out how to find the pulseaudio default sink name.
477