Testing microphone performance for Codec 2

Codec 2 is the open source and patent-free voice codec used in FreeDV, a digital voice mode used in amateur radio. Since Codec 2 is designed to be used at very low bitrates (the current version of FreeDV uses 1300bps and 700bps), it does an adequate job at encoding voice, but can't encode well other types of sounds, and thus fails poorly in the presence of noise. Hence, microphones which may be good enough for other applications can give poor results when used for FreeDV (if, for instance, they pick up too much ambient noise or have too much echo). This is a small note about how to test the microphone performance for Codec 2.

I find that a good test is just to make a "loopback" test, where you record your voice with the microphone, encode the voice with Codec 2, decode the encoded digital voice, and listen to the result with headphones to avoid feedback. Doing this in real-time allows one to tune different parameters, such as microphone gain and placement. This loopback can be done easily with the tools c2enc and c2dec from the Codec 2 package and rec and play from SoX.

An easy way to obtain the tools c2enc and c2dec is to compile Codec 2 from source. The source archive can be found in the FreeDV homepage (as of writing this post, the archive for the current version is codec2-0.5.tar.xz). To compile the code, run

mkdir build
cd build
cmake ..

in the source folder. Then c2enc and c2dec may be found under src/ in the build folder.

The loopback test can be run as

rec -t raw -r 8000 -e signed-integer -b 16 -c 1 - | \
./c2enc 1300 - - | ./c2dec 1300 - - | \
play -t raw -r 8000 -e signed-integer -b 16 -c 1 -

(from build/src). As I'm using PulseAudio, I can select the input and output devices on the fly using pavucontrol.

This loopback test runs Codec 2 at 1300bps. A nice thing is that there is some delay in the loop, which I find better to hear myself back properly. Variations of this loopback test are also interesting. One can replace 1300 by 700B to run Codec 2 at the 700bps mode used in FreeDV 700B. One can also remove c2enc and c2dec from the pipeline to listen to the analog audio. Note that the sampling rate is 8kHz, which is adequate for communications quality, but is far from being Hi-Fi. The parameter -r 8000 can be replaced with -r 44100 or -r 48000 for Hi-Fi quality (but not when running the Codec 2 tools, which expect a 8kHz sampling rate and won't really benefit from a higher sampling rate).

7 Replies to “Testing microphone performance for Codec 2”

  1. Hello Sir,
    I want to do feedback using freedv/codec2.
    Can it be done using the freedv api? If yes, how?

    How do i setup codec2 for loopback? I am new to this and not very comfortable with cmake command line.

    Please help.
    Thank You

    1. Dear Archit, I don't understand very well what you want to accomplish. Even if you use FreeDV API you will have to compile from source (and that involves using cmake).

      1. Hello Sir,
        How do i compile codec2 on windows (using cmake)?
        I have 32 bit pc with visual c++ 6 installed.

        Thank You.

          1. Hello Sir,
            I switched to using Ubuntu.
            I have GNU Make 3.18 installed, and so the commant 'cmake .. ' gives error.
            How do i compile using GNU Make?

            Thank You.

  2. Hello Sir,
    after the command " cmake .. " it gave the following errors,
    -- The C compiler identification is GNU
    -- Check for working C compiler: /usr/bin/gcc
    -- Check for working C compiler: /usr/bin/gcc -- works
    -- Detecting C compiler ABI info
    -- Detecting C compiler ABI info - done
    CMake Error at CMakeLists.txt:12 (include):
    include could not find load file:


    -- codec2 version: 0.4.1
    -- Build type is: Release
    -- Compiler Flags: -Wall -g -O2
    -- Looking for include files HAVE_STDLIB_H
    -- Looking for include files HAVE_STDLIB_H - found
    -- Looking for include files HAVE_STRING_H
    -- Looking for include files HAVE_STRING_H - found
    -- Looking for floor
    -- Looking for floor - found
    -- Looking for ceil
    -- Looking for ceil - found
    -- Looking for pow
    -- Looking for pow - found
    -- Looking for sqrt
    -- Looking for sqrt - found
    -- Looking for sin
    -- Looking for sin - found
    -- Looking for cos
    -- Looking for cos - found
    -- Looking for atan2
    -- Looking for atan2 - found
    -- Looking for log10
    -- Looking for log10 - found
    -- Looking for round
    -- Looking for round - found
    -- Looking for getopt
    -- Looking for getopt - found
    CMake Error at src/CMakeLists.txt:283 (install):
    install TARGETS given no LIBRARY DESTINATION for shared library target

    CMake Error at src/CMakeLists.txt:294 (install):
    install TARGETS given no RUNTIME DESTINATION for executable target

    -- Configuring incomplete, errors occurred!

    how to solve these?

    Thank You.

Leave a Reply

Your email address will not be published. Required fields are marked *