Asound.conf AGC & Denoise

Thought I would throw it in here as tends to be more tinkerers in here.

I think I may mentioned this before but never given any specific details on how to install.

libasound2-plugins (alsa-plugins) doesn’t install the speex plugins because in Debian speex-dsp is an old rc-1 version or something.

So if you have a asound.conf say as

 pcm.!default {
    type asym
    playback.pcm "plughw:2"
    capture.pcm  "agc"
}

pcm.array {
 type hw
 card 2
}

pcm.cap {
 type plug
 slave {
   pcm "array"
   channels 2
   }
 route_policy sum
}

pcm.agc {
 type speex
 slave.pcm "cap"
 agc 1
 agc_level 8000
 denoise yes
 dereverb no
}

Don’t be surprised if it doesn’t work.

First do the usual install

sudo apt install libasound2 libasound2-dev libasound2-plugins
sudo apt install libfftw3-3 libfftw3-dev
sudo apt install libspeex1 libspeexdsp1 libspeex-dev libspeexdsp-dev speex speex-doc
sudo apt install git autotools-dev autoconf libtool pkg-config

Clone the 2 Speex repos

git clone https://gitlab.xiph.org/xiph/speexdsp.git
cd speexdsp
./autogen.sh
./configure --libdir=/usr/lib/arm-linux-gnueabihf
make
sudo make install

Same procedure with speex.
git clone https://gitlab.xiph.org/xiph/speex

blah blah…

You now have the actual releases of Speex and SpeexDSP installed.

So now we have to recompile alsa-plugins (current version) so that it doesn’t omit the speex plugins.

aplay --version
1.1.8 must likely

https://www.alsa-project.org/wiki/Download

wget ftp://ftp.alsa-project.org/pub/plugins/alsa-plugins-1.1.8.tar.bz2
tar -xvzf alsa-plugins-1.1.8.tar.bz2
./configure --libdir=/usr/lib/arm-linux-gnueabihf
make 
sudo make install

Create a /etc/asound.conf like something included in the start and your far field will work much better.
Don’t worry about when AGC ramps up gain and noise becomes a thing as recognition will just ignore and when voice of a required volume is spoken the AGC will ramp down so it doesn’t clip.
It will sound a terrible setup for studio recording but for recognition will work well.

Total pain having old versions of Speex in the repo that alsa will not compile as it references RC2 but we have RC1 but hey the release has been out for ages so at least we are up to date.

Echo seems to be totally useless dunno why as the working EC on github uses exactly the same libs.
Reverb never got completed so just have it off.

asound.conf software AGC can be pretty handy, a pain to install due to a repo mismatch but there you go.
As I just did a install myself and thought I would post before I forget again.

You may also want to run software EC which can be found here.

1 Like

Hello Rolyan,

Thanks for the tip. I’ve setup the PI according to your guide and (with a little bit of tinkering) I can confirm that mic works way better (with auto gain and denoise).

I wouldn’t bother with the denoise auto gain is great as actually found it works better than some sound cards with built in.
Think its SpeexDsp is obviously optimised for voice not so sure what some cheap soundcard AGC are optimised for.

I found depending on intensity denoise can create audio artefacts (that vocoding style of effect) also because of the translation to MFCC the Alg tends to throw out low energy frequency bins so even if it might sound noisy they never get there and you also don’t create artefacts if denoise is off.

The SpeexDSP obviously is tuned for speech and can greatly help with far field.

I have been using uni-directional electrets which are not a laser-beam just have much attenuation from the rear to front in a typical cardoid pattern.
I find the gain circuits of USB sound cards a bit lack-lustre so using cheap active china preamps (max9814 my fave).
That far-field with the SpeexDsp AGC and directional effect of a uni-directional/NS electret is greatly enhanced.

./configure --libdir=/usr/lib/aarch64-linux-gnu/ if using the new 64bit OS which presume many will.

https://downloads.raspberrypi.org/raspios_lite_arm64/images/raspios_lite_arm64-2020-08-24/

Also with the denoise not really sure as suppose you only get the vocoding when AGC ramps up high on silence and its just high gain noise that makes that ‘vocoding’ sound.