0
votes

I would like to reproduce the effect of active noise-control headphones using regular headphones and a Linux computer, in order to mute any ambiant noise in realtime (not just cleaning a sound input from background noise).

The plan is to loopback the microphone input through Alsa/Pulseaudio, apply a feed-forward narrowband noise cancelling filter (as a LADSPA filter ?), then output the result to the headphones.

The problem is I don't know where to start for the filter part : how should I connect it to Alsa/Pulseaudio ? Is there some sort of C API that can be used to create a custom filter ?

2
This is a programming question, and it might be more suitable for Stack Overflow..telcoM
This is a programming question indeed, but my problem is not on the programming side, more on the wiring side within Linux.Aurélien Pierre

2 Answers

1
votes

1) I recommend doing this in Pulseaudio; redirecting ALSA output through your filter will be more difficult.

2) There are already modules like module-ladspa-sink for Pulseaudio, details e.g. here. The module forwards LADSPA processed sound to master, but as you need both the mic input and the computer sound output, you may have to use some other modules (e.g. combined sink, null sink as a virtual output sink) and/or pulseaudio loopback commands to forward both of them on different sets of channels to the LADSPA module.

Maybe you can also load two LADSPA modules, use one as virtual output, loopback mic input to the other, and process both from a single LADSPA plugin - I didn't try that, but if it works, it may be simpler.

3) There are also already noise-cancelling and echo-cancelling modules for Pulseaudio which are used e.g. in Smartphones based on Linux; maybe one of those is good enough for your needs. Google.

4) If everything else fails, or if LADSPA filters alone are not enough, look at the source of this module (or other Pulseaudio modules), and modify it accordingly.

1
votes

From debianuser on IRC, and it works for me. Replace with whatever your card is named in /proc/asound/cards. You can edit that name in /etc/modprobe.d/alsa-base.conf or similar in an 'options snd-mycard id="mycardname" enable=1' line.

defaults.pcm.dmix.!rate 48000
defaults.pcm.dmix.!format S16_LE
pcm.multi {
    type multi
    slaves.a.pcm "dmix:RealCardName"
    slaves.a.channels 2
    slaves.b.pcm "dmix:Loopback"
    slaves.b.channels 2
    bindings.0 { slave a; channel 0; }
    bindings.1 { slave a; channel 1; }
    bindings.2 { slave b; channel 0; }
    bindings.3 { slave b; channel 1; }
}
pcm.both {
    type route
    slave.pcm "multi"
    ttable.0.0 1
    ttable.1.1 1
    ttable.0.2 1
    ttable.1.3 1
}
pcm.!default {
    type asym
    playback.pcm "plug:both"
    capture.pcm "plug:dsnoop:RealCardName"
}

pcm.nowplaying "plug:\"dsnoop:Loopback,1\""`