Artefact2 / alsaimpulse

An ALSA plugin to apply arbitrary convolution filters to PCM streams.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

alsaimpulse

An ALSA plugin to apply arbitrary convolution filters to PCM streams. Released under the GNU GPLv3+.

FFTW is used with the overlap-add method to convolve the two signals in reasonable CPU time.

Use cases

  • DRC (digital room correction: room EQ, house curves, etc.)
  • Other types of FIR filters

This plugin does not require the use of an ALSA loopback device. This is great for many reasons:

  • No unnecessary latency (of which ALSA programs cannot know about, this is problematic for precise syncing of audio). Of course, because of the way convolution filters work, some latency is inevitable.

  • All sample rates are supported without the need for continous resampling (only the impulse response is resampled, once), which saves system resources during playback.

  • No idle use of system resources (the device is normally closed when no application is playing audio).

Generating impulses

For DRC, you can generate impulses using software like DRC-FIR (libre) or REW (proprietary).

For more general-purpose filters, you can generate impulses with rePhase (proprietary) or ffmpeg's sinc source (among others):

# generate a 100 Hz highpass filter impulse at 44100 Hz sample rate
ffmpeg -f lavfi -i sinc=r=44100:hp=100 -f f32le highpass_impulse.float32.pcm

Finally, you can also reuse impulses available online, some of which can be found on zconvolver's homepage.

Limitations

  • No control mixer for toggling the filter on/off for now, patches welcome

  • 16 channels maximum (can easily be increased in the code)

  • Only works with FLOAT32 samples of native endianness, you will most likely need to use plug slaves to feed data in and out

  • Because dmix requires a hw slave, one instance of the plugin will run for each process playing audio. This is inefficient if you have two (or more) processes that play audio concurrently. This only matters if you use dmix.

  • CPU usage will be significant if you use large impulses or short period sizes.

Compile and install

Dependencies: FFTW and libsamplerate (both lib and lib32 versions).

make
sudo make install

Example configuration (asoundrc)

The plugin requires (and assumes) impulse files are raw PCM data stored as 32-bit floats of native endianness. If your impulse files are in a different format, you can convert them with tools like ffmpeg(1): ffmpeg -i impulse.wav -f f32le impulse.float32.pcm

pcm.impulse {
	type impulse
	slave { pcm "plughw:0" }

	# This is optional but increases CPU efficiency (except the very first time the plugin is loaded)
	# Specified path must be writeable
	# Recommended to delete the file after hardware changes / software upgrades
	wisdom_path "/home/foo/.cache/alsa/impulse_wisdom"

	impulse.0 {
		path "/path/to/left_channel.float32.pcm"
		rate 44100
		gain -20.0 # preamp gain in dB, optional (default 0.0 dB)
	}

	impulse.1 {
		path "/path/to/right_channel.float32.pcm"
		rate 44100
		gain -20.0
	}

	# add more channels as needed...
	#impulse.2 {
	#	path "/path/to/center_channel.float32.pcm"
	#	rate 44100
	#	gain -20.0
	#	fft_size 16384 # for experts only, omit for optimal results
	#}
}
pcm.!default {
	type plug
	slave { pcm impulse }
}

See also

  • pipewire has a convolver plugin that can be used in filter chains, works with all ALSA/PulseAudio/JACK programs

  • BruteFIR and CamillaDSP, both of which can do convolution filters in real-ish time using a loopback device

  • alsaloudness, a loudness-compensated volume control for ALSA, must-have if you are listening at low SPLs

Licence

alsaimpulse is released under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. See the file COPYING for more details.

About

An ALSA plugin to apply arbitrary convolution filters to PCM streams.

License:GNU General Public License v3.0


Languages

Language:C 93.9%Language:Makefile 6.1%