Coder Social home page Coder Social logo

artefact2 / alsaimpulse Goto Github PK

View Code? Open in Web Editor NEW
12.0 3.0 2.0 41 KB

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

License: GNU General Public License v3.0

Makefile 6.09% C 93.91%
alsa dsp room-correction drc convolution-filter fir

alsaimpulse's Introduction

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.

alsaimpulse's People

Contributors

artefact2 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

rbob62854 donniet

alsaimpulse's Issues

Problems building on Raspberry Pi 4

I'm interested in trying this out but I'm having problems building.

The first issue is cc: error: unrecognized command line option '-m32'; did you mean '-mbe32'?
I'm not sure why the m32 flag is not recognized. I removed it from the Makefile to see if it would work without it.

The second issue is warning: implicit declaration of function 'snd_config_is_array';

It seems that snd_config_is_array isn't found. After searching, I think this is part of the alsa library, but I have libasound2 libasound2-dev installed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.