How to Enable Libopus Fixed-Point Math

This article provides a direct, step-by-step guide on how to explicitly enable fixed-point mathematics when compiling the libopus audio codec library. It covers the required configuration flags for both the Autotools and CMake build systems, allowing you to optimize the codec for platforms that lack a hardware floating-point unit (FPU), such as microcontrollers and embedded ARM processors.

Why Use Fixed-Point Math in Libopus?

By default, libopus is often compiled to use floating-point mathematics, which provides the highest audio quality and performance on modern desktop and mobile CPUs. However, on embedded systems, smartphones without hardware FPUs, or low-power microprocessors, floating-point emulation is extremely slow. Enabling fixed-point math forces libopus to use integer-based arithmetic, significantly reducing CPU usage on these devices with negligible loss in audio quality.


Method 1: Enabling Fixed-Point with Autotools

If you are building libopus from a release tarball or from the source repository using standard GNU Autotools, you must pass the --enable-fixed-point flag to the configure script.

Step-by-Step Instructions:

  1. Extract or clone the source code:

    tar -xvf opus-1.x.x.tar.gz
    cd opus-1.x.x
  2. Run the autogen script (only if building directly from the Git repository):

    ./autogen.sh
  3. Configure the build with the fixed-point flag:

    ./configure --enable-fixed-point
  4. Compile and install:

    make
    sudo make install

Method 2: Enabling Fixed-Point with CMake

If you are integrating libopus into a project that uses the CMake build system, you must define the OPUS_FIXED_POINT variable and set it to ON.

Step-by-Step Instructions:

  1. Create and navigate to a build directory:

    cd opus-source-directory
    mkdir build
    cd build
  2. Run the CMake configuration with the fixed-point variable enabled:

    cmake -DOPUS_FIXED_POINT=ON ..
  3. Compile the library:

    cmake --build .

Verifying the Configuration

After configuring the build, you can verify that fixed-point math is enabled by checking the generated configuration headers: