Friday, December 16, 2016

Building codec2 for Windows using Cmake and MinGW


Building codec2 for Windows using Cmake and MinGW


I want to build and use codec2 library in my Qt application for Windows. Codec2 is incredible library for speech processing it can encode speech from 3200 up to 700 bit/s. Amazing! Let's play with it!

So I need to do:
  1. build codec2 for Windows
  2. write Qt wrappers for codec2 library;
  3. write application able to use codec2 with QAudio sub-system. 
This post will explain how to do first step - build codec2 for windows using CMake and MinGW



Info (from Wikipedia - codec2):

Codec2 is a low-bitrate speech audio codec (speech coding) that is patent free and open source.[1] Codec2 compresses speech using sinusoidal coding, a method specialized for human speech. Bit rates of 3200 to 700 bit/s have been successfully created. Codec2 was designed to be used for amateur radio and other high compression voice applications.

You need to:
  1. download and install mingw32 (I prefer GUI installer), you can find it here http://www.mingw.org
  2. download and install CMake (you can find it here http://www.cmake.org/ or you can use direct link https://cmake.org/files/v3.7/cmake-3.7.1-win32-x86.msi)
  3. clone or download codec2 sources from GitHub https://github.com/freedv/codec2 or download them directly from Rovetel http://files.freedv.org/codec2
  4. You need add your mingw directory to your system level PATH
For example:
  • I have MinGW installed to the d:\mingw (and this directory in my system PATH);
  • CMake installed to the C:\Program Files\CMake\
Then you need unpack codec2 sources and go to this directory. In my case it will be codec2-master folder.

Going go directory with sources (in command line)
> cd codec2-master

Making directory for binaries:
> mkdir build_windows

Calling CMake (and specifying scenario and path compiler names). Warning! Pay attention to two dots ('.' symbol) at the commands end:
> d:\Program Files\CMake\bin\cmake.exe"  -G "MinGW Makefiles" -D CMAKE_CXX_COMPILER=mingw32-g++.exe -D CMAKE_MAKE_PROGRAM=mingw32-make.exe ..

Compiling using MinGW
> mingw32-make

If everything was made right, you can find libcodec2.dll and libcodec2.dll.a files inside build_windows/src directory

Now we have all needful files:
  • codec2.h 
  • libcodec2.dll
  • libcodec2.dll.a
This files is our target and we will use them at our next steps playing with Qt and codec2.

Note: if you need this files in binary form - feel free to contact with me, I will make them accessible.

Enjoy!

UPD1: you can find more here http://bohdan-danishevsky.blogspot.com/2016/12/qt-wrappers-for-codec2-library.html

1 comment: