Search code examples
audioraspberry-pialsa

Apply EQ to audio in and monitor audio out?


I am trying to make it possible to take the microphone input, have the input be filtered by the ALSA EQ plugin (or any other controllable EQ), and hear the live filtered output through headphones. I am using a RPI on Raspbain Buster. How might I accomplish this?


Solution

  • You can use the ALSA equal plugin to have a equaliser on by default.

    First you have to install the plugin :

    sudo apt-get install libasound2-plugin-equal
    

    Then you should setup your asoundrc to set it to the default route, save the following to ~/.asoundrc :

    @hooks [
            {
                    func load
                    files [
                            "~/.asoundrc"
                    ]
                    errors false
            }
    ]
    
    pcm.!default {
     type plug
     slave.pcm plugequal;
    }
     
    ctl.equal {
     type equal
    }
     
    pcm.plugequal {
     type equal
     slave.pcm "plughw:ALSA,0"
    }
     
    pcm.equal {
     type plug
     slave.pcm plugequal
    }
    

    Finally you can alter the eq like so :

    alsamixer -D equal
    

    You can listen to the sound while you are adjusting the EQ by playing audio at the sample time :

    aplay audioFile.wav
    

    Now if you want to route your microphone to the output through the equaliser, then you probably want to pipe arecord to aplay like so :

    arecord -Dplughw:mic -f cd | aplay
    

    NOTE: Change "plughw:mic" above to the actual microphone you are using.

    For example if I use my Audio Injector stereo or Ultra soundcard (which both have electret microphones on board) then I would setup their mixers to caputre using the onboard mirophones using alsamixer

    alsamixer -Dhw:0
    

    Then I would replace plughw:mic with plughw:0 as they are always the 0 card on my system.

    arecord -Dplughw:0 -f cd | aplay