Fast, modern C++ DSP framework, FFT, Sample Rate Conversion, FIR/IIR/Biquad Filters (SSE, AVX, AVX-512, ARM NEON)

KFR - Fast, modern C++ DSP framework

Build Status Gitter License

Compiler support:

Clang 6+ Xcode 9+ GCC 7+ MSVC 2017

https://www.kfr.dev

KFR is an open source C++ DSP framework that focuses on high performance (see benchmark results section).

KFR has no external dependencies except C++17-compatible standard C++ library.

Some C++17 library features will be emulated if not present in the standard library.

Features

What's new in KFR 4.0

  • IIR filter design
    • Butterworth
    • Chebyshev type I and II
    • Bessel
    • Lowpass, highpass, bandpass and bandstop filters
    • Conversion of arbitrary filter from Z,P,K to SOS format (suitable for biquad function and filter)
  • Discrete Cosine Transform type II (and its inverse, also called DCT type III)
  • cmake uninstall target (thank to @acxz)
  • C API: DFT, real DFT, DCT, FIR and IIR filters and convolution, memory allocation
    • Built for SSE2, SSE4.1, AVX, AVX2, AVX512, x86 and x86_64, architecture is selected at runtime
    • Can be used with any compiler and any language with ability to call C functions
    • Windows binaries will be available soon
  • C++17
    • Inline variables
    • Fold expressions
    • Structured binding
  • New vector based types: color, rectangle, point, size, border, geometric vector, 2D matrix
  • Color space conversion (sRGB, XYZ, Lab, LCH)
  • MP3 file reading (using third party dr_lib library, see source code for details)
  • Various optimizations and fixes (thank to @bmanga, @ncorgan, @rotkreis, @mujjingun for fixes and bug reports)

Release notes

  • DFT is limited to Clang due to ICE in MSVC and broken AVX optimization in GCC 8 and 9. Once fixed, support will be added

What's new in KFR 3.0

  • Optimized non-power of two DFT implementation
  • GCC 7+ support
  • MSVC 2017 support
  • AVX-512 support (MSVC and Clang, GCC has incomplete support of AVX-512 instrinsics)
  • EBU R128
  • Ability to include KFR as a subdirectory in cmake project
  • Ability to link objects built for multiple architectures into one binary
  • Number of automatic tests has been increased
  • C API for DFT
  • GPL version changed from 3 to 2+

All features

  • All code in the library is optimized for Intel, AMD (SSE2, SSE3, SSE4.x, AVX and AVX2 and AVX512) and ARM (NEON) processors
  • Mathematical and statistical functions
  • Template expressions (See examples)
  • All data types are supported including complex numbers
  • All vector lengths are also supported. vec<float,1>, vec<unsigned,3>, vec<complex<float>, 11> all are valid vector types in KFR
  • Most of the standard library functions are re-implemented to support vector of any length and data type
  • Runtime cpu detection

Included DSP/audio algorithms:

  • FFT
  • Convolution
  • FIR filtering
  • FIR filter design using the window method
  • Resampling with configurable quality (See resampling.cpp from Examples directory)
  • Goertzel algorithm
  • Fractional delay
  • Biquad filtering
  • Biquad design functions
  • Oscillators: Sine, Square, Sawtooth, Triangle
  • Window functions: Triangular, Bartlett, Cosine, Hann, Bartlett-Hann, Hamming, Bohman, Blackman, Blackman-Harris, Kaiser, Flattop, Gaussian, Lanczos, Rectangular
  • Audio file reading/writing
  • Pseudorandom number generator
  • Sorting
  • Ring (Circular) buffer
  • Simple waveshaper
  • Fast incremental sine/cosine generation
  • EBU R128

Benchmark results

DFT

KFR 3.0.1

Powers of 2, from 16 to 16777216 (Higher is better)

FFT Performance

Prime numbers from 17 to 127 (Higher is better)

DFT Performance

Small numbers from 18 to 119 (Higher is better)

DFT Performance

Random sizes from 120 to 30720000 (Higher is better)

DFT Performance

See fft benchmark for details about benchmarking process.

Biquad

(Higher is better)

Biquad Performance

Usage

Common prerequisites

  • CMake 3.0 or newer for building tests and examples
  • Python 2.7 or 3.x for running examples
  • (Optional) Ninja (https://ninja-build.org/)

For running examples and plotting frequency responses of filters the following python packages are required:

pip install matplotlib
pip install numpy
pip install scipy

Or download prebuilt python packages for windows

To obtain the full code, including examples and tests, you can clone the git repository:

git clone https://github.com/kfrlib/kfr.git

Building KFR C API

Windows

These commands must be executed in MSVC2017 command prompt

cd <path_to_kfr_repository>
mkdir build && cd build
cmake -GNinja -DENABLE_CAPI_BUILD=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER="<PATH_TO_LLVM_DIR>/bin/clang-cl.exe" ..
ninja kfr_capi

Linux, macOS, other

cd <path_to_kfr_repository>
mkdir build && cd build
cmake -GNinja -DENABLE_CAPI_BUILD=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=clang++ ..
ninja kfr_capi

ArchLinux Package

KFR is available on the ArchLinux User Repository (AUR). You can install it with an AUR helper, like yay, as follows:

yay -S kfr

To discuss any issues related to this AUR package refer to the comments section of kfr.

Prebuilt binaries will be available soon.

Including in CMake project

CMakeLists.txt contains these libraries:

  • kfr - header only interface library
  • kfr_dft - static library for DFT and related algorithms
  • kfr_io - static library for file IO and audio IO
# Include KFR subdirectory
add_subdirectory(kfr)

# Add header-only KFR to your executable or library, this sets include directories etc
target_link_libraries(your_executable_or_library kfr)

# Add KFR DFT to your executable or library, (cpp file will be built for this)
target_link_libraries(your_executable_or_library kfr_dft)

# Add KFR IO to your executable or library, (cpp file will be built for this)
target_link_libraries(your_executable_or_library kfr_io)

Makefile, command line etc (Unix-like systems)

# Add this to command line
-Ipath_to_kfr/include

# And this if needed
-lkfr_dft -lkfr_io

# C++17 mode must be enabled
-std=c++17
# or
-std=gnu++17

Linux

Prerequisites

  • GCC 7 or newer
  • Clang 6.0 or newer

Command line

cd <path_to_kfr>
mkdir build && cd build
cmake -DENABLE_TESTS=ON -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_BUILD_TYPE=Release ..
make -- -j

Or using Ninja

cd <path_to_kfr>
mkdir build && cd build
cmake -GNinja -DENABLE_TESTS=ON -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_BUILD_TYPE=Release ..
ninja

macOS

Prerequisites

  • XCode 9.x, 10.x or 11.x

Command line

Using Xcode project:

cd <path_to_kfr>
mkdir build && cd build
cmake -GXcode -DENABLE_TESTS=ON -DCMAKE_BUILD_TYPE=Release ..
cmake --build .

Using Unix Makefiles:

cd <path_to_kfr>
mkdir build && cd build
cmake -G"Unix Makefiles" -DENABLE_TESTS=ON -DCMAKE_BUILD_TYPE=Release ..
make -- -j

Or using Ninja:

cd <path_to_kfr>
mkdir build && cd build
cmake -GNinja -DENABLE_TESTS=ON -DCMAKE_BUILD_TYPE=Release ..
ninja

Visual Studio

Prerequisites

  • Visual Studio 2017
  • Latest Clang (http://llvm.org/)
  • Ninja is highly recommended because Visual Studio does not support parallel build with Clang at this moment.

Visual Studio IDE

To work with KFR in Visual Studio you must add the path to the include directory inside KFR directory to the list of the project's include directories.
More details: https://docs.microsoft.com/en-us/cpp/ide/vcpp-directories-property-page?view=vs-2017

Make sure that LLVM toolset is set for the project

Download and install official LLVM extension:

More details: https://docs.microsoft.com/en-us/cpp/ide/general-property-page-project?view=vs-2017

LLVM/Clang has very good compatibility with MSVC ABI and it's widely used for building large projects on Windows (including Chrome), so switching to LLVM/Clang should not cause compatibility problems.

Command line

Using Ninja:

cd <path_to_kfr>
mkdir build && cd build
call "C:\<path to your Visual Studio installation>\VC\Auxiliary\Build\vcvars64.bat"
cmake -GNinja -DENABLE_TESTS=ON -DCMAKE_CXX_COMPILER="C:/Program Files/LLVM/bin/clang-cl.exe" -DCMAKE_CXX_FLAGS=-m64 -DCMAKE_BUILD_TYPE=Release ..
ninja

Or generate Visual Studio solution (building will be slower):

cd <path_to_kfr>
mkdir build && cd build
cmake -G"Visual Studio 15 2017 Win64" -DENABLE_TESTS=ON -Tllvm -DCMAKE_BUILD_TYPE=Release ..

MinGW/MSYS

Prerequisites

  • Latest MinGW or MSYS2
  • Clang 6.0 or newer

Using Makefiles:

cd <path_to_kfr>
mkdir build && cd build
cmake -DENABLE_TESTS=ON -DCMAKE_BUILD_TYPE=Release ..
make -- -j

Using Ninja:

cd <path_to_kfr>
mkdir build && cd build
cmake -GNinja -DENABLE_TESTS=ON -DCMAKE_BUILD_TYPE=Release ..
ninja

Documentation

Documentation home:

https://www.kfrlib.com/newdocs/

Built with

Branches

dev - current development version. Pull requests should go to dev.

master - current stable version passing all compiler/architecture tests.

Tests

Every commit is tested in various OS, compilers, compiler settings etc.

You can run the tests using these commands:

cd <path_to_cmake_build_directory>
cd tests
ctest -V

Tested on the following systems:

macOS

  • (Intel AVX2) macOS 10.13.6 / Xcode 10 / AppleClang 10.0.0.10001145
  • (Intel AVX Azure Pipelines) macOS 10.13.6 / Xcode 10.1 / AppleClang 10.0.0.10001145
  • (Intel AVX Azure Pipelines) macOS 10.13.6 / Xcode 10 / AppleClang 10.0.0.10001145
  • (Intel AVX Azure Pipelines) macOS 10.13.6 / Xcode 9.4.1 / AppleClang 9.1.0.9020039
  • (Intel AVX Azure Pipelines) macOS 10.13.6 / Xcode 9.0.1 / AppleClang 9.0.0.9000038
  • (Intel AVX Azure Pipelines) macOS 10.13.6 / Xcode 8.3.3 / AppleClang 8.1.0.8020042
  • (Intel AVX2) macOS 10.11.6 / Xcode 7.3 / AppleClang 7.3.0.7030031
  • (Intel AVX2) macOS 10.11.4 / Xcode 7.3 / AppleClang 7.3.0.7030031
  • (ARMv7, ARMv7s, ARM64) macOS 10.11.6 / Xcode 7.3 / AppleClang 7.3.0.7030031
  • (Intel AVX) macOS 10.10.5 / Xcode 7.1 / AppleClang 7.0.0.7000176
  • (SSE4.2 Travis-CI) macOS 10.11.6 / Xcode 8 (beta4) / AppleClang 8.0.0.8000035
  • (SSE4.2 Travis-CI) macOS 10.11.5 / Xcode 7.3 / AppleClang 7.3.0.7030031
  • (SSE4.2 Travis-CI) macOS 10.11.5 / Xcode 7.2 / AppleClang 7.0.2.7000181
  • (SSE4.2 Travis-CI) macOS 10.10.5 / Xcode 7.1 / AppleClang 7.0.0.7000176
  • (SSE4.2 Travis-CI) macOS 10.10.5 / Xcode 7 / AppleClang 7.0.0.7000072
  • (SSE4.2 Travis-CI) macOS 10.10.5 / Xcode 6.4 / AppleClang 6.1.0.6020053
  • (SSE4.2 Travis-CI) macOS 10.10.3 / Xcode 6.3 / AppleClang 6.1.0.6020049

Ubuntu

  • (Intel AVX2) Ubuntu 18.04 / gcc-7.x / clang version 7.0.0 (tags/RELEASE_700/final)
  • (Intel AVX2) Ubuntu 16.04 / gcc-5.4.0 / clang version 3.8.0 (tags/RELEASE_380/final)
  • (ARMv7 NEON) Ubuntu 16.04 / gcc-5.4.0 / clang version 3.8.0 (tags/RELEASE_380/final)
  • (ARMv7 NEON) Ubuntu 14.04 / gcc-4.8.4 / clang version 3.8.0 (tags/RELEASE_380/final)
  • (ARMv7 NEON Travis-CI) Ubuntu 14.04 / gcc-4.8.4 / clang version 3.8.0 (tags/RELEASE_380/final)
  • (Intel AVX2 Travis-CI) Ubuntu 12.04 / gcc-5.4.0 / clang version 3.8.0 (tags/RELEASE_380/final)
  • (Intel AVX2 Travis-CI) Ubuntu 14.04 / gcc-5.3.0 (Ubuntu 5.3.0-3ubuntu1~14.04) 5.3.0 20151204 / clang version 3.8.0 (tags/RELEASE_380/final)

Windows

  • (Intel AVX512) Windows 10 / Visual Studio 2017 / Clang 7.0
  • (Intel AVX512) Windows 10 / Visual Studio 2017 / Clang 6.0
  • (Intel AVX2) Windows 10 / MinGW-W64 5.2 / clang version 3.8.0 (branches/release_38)
  • (Intel AVX2) Windows 10 / MinGW-W64 4.8 / clang version 3.8.0 (branches/release_38)
  • (Intel AVX) Windows 8.1 / MinGW-W64 5.4 / clang version 3.8.0 (branches/release_38)
  • (Intel AVX) Windows 8.1 / Visual Studio 2015 Update 2 / clang version 3.9.0 (SVN r273898 (27 June 2016))

Linux on Windows 10

  • (Intel AVX2) Windows 10.0.17134.407 compatible with Ubuntu 18.04 / gcc-7.x / clang version 7.0.0 (tags/RELEASE_700/final)
  • (Intel AVX2) Windows 10.0.14393 compatible with Ubuntu 14.04 / gcc-5.4.0 / clang version 3.8.0 (tags/RELEASE_380/final)

Planned for future versions

  • Parallel execution of algorithms
  • Serialization/Deserialization of any expression
  • More formats for audio file reading/writing

License

KFR is dual-licensed, available under both commercial and open-source GPL 2+ license.

If you want to use KFR in commercial product or a closed-source project, you need to purchase a Commercial License

Comments
  • Make DFT compile with GCC

    Make DFT compile with GCC

    Fixes some issues preventing dft from compiling on GCC. Tested on gcc 6 & 7. gcc 6 gives warnings on required alignments, but it still passes the tests (KFR 3.0.9 avx2 64-bit (gcc-6.5.0/linux) +in running on avx2)

  • [Implementation] Implementing a simple low pass filter

    [Implementation] Implementing a simple low pass filter

    I would like to use this library to implementing a low pass filter, instead of writing my own low pass filter, however, after spending some time looking at the examples and the documentation I am a bit lost in whether I can achieve what I want with kfr. If anyone could help me/point me in the right direction it would be much appreciated. Forgive me for my naivety I am not too exposed to DSP.

    Problem: I am receiving a data stream of samples (digital, just doubles) along with their associated timestamps. When I sample this data stream the data is noisy, as such I would like convert the sampled output of the data stream to a filtered less noisy sample, say filtering out data greater than some cutoff frequency. Note: I would not like to keep track of all the previous samples, (I know I need to keep track of the previous sample based on (1st order) low pass filter equations I am familiar with).

    From what I understand so far I can design parameters (taps) for a filter at specific cutoff frequencies and with a window method. However, after reading and running the example code on fir.cpp and looking at the output images (amplitude and gain plots) I am not sure what the cutoff value actually means. It does not seem to represent cutoff frequencies for a filter.

    From the output taps of designing the filter I can create a filter. Now my question is how I can use my filter on individual samples rather than the entire datastream. When I use filter.apply(output, input) can my input be a single sample? Another question I have is how to incorporate the associated timestamps along with the incoming samples? This information is vital for outputting a filtered sample.

    After some more research it seems that an IIR filter is a solution to my problem instead of a FIR filter. However, kfr does not seem to have any implementations of IIR filters, however there are biquad implementations, but I am still not sure how to specify my dt when I apply the filter on a single sample.

    As for the cutoff value, I know understand that to be the ratio: freq_cutoff/freq_sampling.

  • error: ‘audio_reader_flac’ was not declared in this scope

    error: ‘audio_reader_flac’ was not declared in this scope

    How to read a flac file?

    #include <kfr/base.hpp>
    #include <kfr/dsp.hpp>
    #include <kfr/io.hpp>
    
    int main() {
    
        audio_reader_flac<float> reader(open_file_for_reading("6319-64726-0013.flac"));
        return 0;
    }
    
    
    (kfr) [email protected]:~/kfr$ g++ -std=c++17 flacfileRead.cpp -o flacfileRead
    flacfileRead.cpp: In function ‘int main()’:
    flacfileRead.cpp:7:5: error: ‘audio_reader_flac’ was not declared in this scope
         audio_reader_flac<float> reader(open_file_for_reading("6319-64726-0013.flac"));
         ^~~~~~~~~~~~~~~~~
    flacfileRead.cpp:7:5: note: suggested alternative: ‘__io_read_fn’
         audio_reader_flac<float> reader(open_file_for_reading("6319-64726-0013.flac"));
         ^~~~~~~~~~~~~~~~~
         __io_read_fn
    flacfileRead.cpp:7:23: error: expected primary-expression before ‘float’
          audio_reader_flac<float> reader(open_file_for_reading("6319-64726-0013.flac"));
                            ^~~~~
    (kfr) [email protected]:~/kfr$ 
    

    Looking forward to your kind help. Marco

  • g++ 7.1.1 and vec: requested alignment is not an integer constant

    g++ 7.1.1 and vec: requested alignment is not an integer constant

    Hi. I have a compilation error in the master branch of kfr.

    On an attempt to use the DFT with Linux and gcc 7.1.1, the following error is produced:

    thirdparty/kfr/include/kfr/base/simd_intrin.hpp: In instantiation of ‘struct kfr::vec<float, 4>’:
    thirdparty/kfr/include/kfr/base/simd_x86.hpp:11:44:   required from here
    thirdparty/kfr/include/kfr/base/simd_intrin.hpp:136:97: error: requested alignment is not an integer constant
     struct alignas(const_min(platform<>::maximum_vector_alignment, sizeof(T) * next_poweroftwo(N))) vec
    

    origin of the error

    From what I observe, recent gcc refuses to accept the parameter of alignas as a compile time constant. On the same machine I have also tested with clang and gcc5 and it builds with these other compilers.

  • Build Failure [GCC]

    Build Failure [GCC]

    OS: ArchLinux GCC: 9.1 kfr: master ( 11d9a15) at the time of posting EDIT: same errors reported with the dev branch as well ( 1b4afb3) at the time of posting

    I am getting the following errors: error: requested alignment is not an integer constant. This issue is very similar to #16, however, that issue was fixed for GCC 8.x, but now I am getting the same issue on GCC 9.1.

    Here is a more complete sample of the output:

    /home/acxz/vcs/github/acxz/kfr/include/kfr/io/impl/../../base/../simd/impl/../../base/../simd/impl/simd.hpp: In instantiation of ‘struct kfr::sse2::intrinsics::simd_array<short int, 8>’:
    /home/acxz/vcs/github/acxz/kfr/include/kfr/io/impl/../../base/../simd/impl/../../base/../simd/impl/backend_generic.hpp:1118:31:   required from ‘T kfr::sse2::intrinsics::simd_get_element(kfr::sse2::intrinsics::simd<T, N1>&, std::size_t) [with T = short int; long unsigned int N = 8; kfr::sse2::intrinsics::simd<T, N1> = __vector(2) long long int; std::size_t = long unsigned int]’
    /home/acxz/vcs/github/acxz/kfr/include/kfr/io/impl/../../base/../simd/impl/../../base/../simd/vec.hpp:321:50:   required from ‘constexpr kfr::sse2::vec<T, N>::value_type kfr::sse2::vec<T, N>::get(std::size_t) const [with int dummy = 0; typename std::enable_if<((dummy == 0) && cometa::compound_type_traits<T>::is_scalar), cometa::details::unique_enum_impl<318>::type>::type <anonymous> = cometa::details::unique_enum_impl<318>::value; T = short int; long unsigned int N = 8; kfr::sse2::vec<T, N>::value_type = short int; std::size_t = long unsigned int]’
    /home/acxz/vcs/github/acxz/kfr/include/kfr/io/impl/../../base/../simd/impl/../../base/../simd/vec.hpp:308:107:   required from ‘constexpr kfr::sse2::vec<T, N>::value_type kfr::sse2::vec<T, N>::operator[](std::size_t) const & [with T = short int; long unsigned int N = 8; kfr::sse2::vec<T, N>::value_type = short int; std::size_t = long unsigned int]’
    /home/acxz/vcs/github/acxz/kfr/include/kfr/io/impl/../../base/../simd/impl/basicoperators_generic.hpp:115:5:   required from here
    /home/acxz/vcs/github/acxz/kfr/include/kfr/io/impl/../../base/../simd/impl/../../base/../simd/impl/simd.hpp:70:35: error: requested alignment is not an integer constant
    

    Note: Clang 8.0 works fine.

  • make_univector doesn't work with std::vector

    make_univector doesn't work with std::vector

    Hi there,

    I tried to use make_univector function to convert input. However, when testing this example taken from the documentation page

    std::vector<float> data; // existing data, or std::array<N, float>
    float val = rms(make_univector(data)); // No data copy
    

    I got these errors:

    .../kfr-master/include/kfr/io/../base/univector.hpp:478:32: note: candidate function
          template not viable: requires 2 arguments, but 1 was provided
    KFR_INTRINSIC univector_ref<T> make_univector(T* data, size_t size)
                                   ^
    .../kfr-master/include/kfr/io/../base/univector.hpp:485:38: note: candidate function
          template not viable: requires 2 arguments, but 1 was provided
    KFR_INTRINSIC univector_ref<const T> make_univector(const T* data, size_t size)
    

    It seems that make_univector doesn't take std::vector, or did I get something wrong? Thanks.

  • kfr::complex / std::complex troubles

    kfr::complex / std::complex troubles

    Hi, I have trouble with float complex type. I try to use std::complex to make easier the integration with other code and I have compiler errors. for example with the resampler:

    .../include/kfr/dsp/sample_rate_conversion.hpp:115:25: error: invalid operands to binary expression ('kfr::sse2::samplerate_converter<std::complex >::ftype' (aka 'std::complex') and 'const long') cutoff = cutoff / std::max(decimation_factor, interpolation_factor); ~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .../include/kfr/dsp/sample_rate_conversion.hpp:404:12: note: in instantiation of member function 'kfr::sse2::samplerate_converter<std::complex >::samplerate_converter' requested here return samplerate_converter(quality, itype(interpolation_factor), itype(decimation_factor), scale, ^

    there is other errors with other kfr object, the resampler is just an example.

    Is kfr::c32 totally compatible with std::complex Or, what is the purpose of that type? Is it necessary to have 2 complex types?

    to bypass the problem I implement my dsp classes with kfr::complex and "cast" from my calling code with: auto ucpx = make_univector<kfr::c32>( reinterpret_cast<kfr::c32*>(m_cpx_buffer.data()), m_cpx_buffer.size());

    Is it correct? Is there a better way?

    with my best regards

  • fft_accuracy test failure with Clang 11

    fft_accuracy test failure with Clang 11

    The testcase fft_accuracy fails quite badly after building with clang 11.

    ...
        type = float, size = 254; complex-inverse:
        [fail]    rms_diff_outofplace < min_prec | 6.27181 < 0.00140648
    [----RUN----] dct...
    [--SUCCESS--] 2 subtests of 2
    ===============================================================================
    [--SUCCESS--] 145/146 tests 2677857/2678067 checks
    [---ERROR---] 1/146 tests 210/2678067 checks
                  fft_accuracy
    
    • My development machine is running Fedora 33, and I build with clang-11, cmake 3.18.4 and Ninja, the cpu is an i7-10510U, and the build uses avx2.
    • It worked with clang-10, and interestingly enough I have seen no issues when building in debug either.
    • Also get a lot of psABI warnings, but don't think the ABI would pertain to this issue seeing how the tests are all in the same application built with the same toolchain.
  • Release 3.0.5 breaks Android Support

    Release 3.0.5 breaks Android Support

    Due to a custom implementation of pthreads in Android the latest release of KFR can not easily be included in an Android. The 3.0.5 release currently results in a build error of 'cannot find -lpthread' when adding KFR to CMakeList using add_subdirectory().

    https://developer.android.com/ndk/guides/stable_apis#clib

    Edit : I've added a branch in my project to illustrate the issue : https://github.com/Jman420/menrva/tree/feature/upgrade-kfr

  • Overflow for small input lengths in zero latency biquad

    Overflow for small input lengths in zero latency biquad

    In the zero latency biquad expression the begin_block may overflow if the input source is less than the number of filters - 1:

    This line: https://github.com/kfrlib/kfr/blob/master/include/kfr/dsp/biquad.hpp#L178

    This code block assumes the input source will be greater than or equal to filters - 1 in length:

        CMT_INLINE void begin_block(cinput_t cinput, size_t size) const
        {
            block_end = size;
            for (size_t i = 0; i < filters - 1; i++)
            {
                const vec<T, 1> in = this->argument_first(cinput, i, vec_t<T, 1>());
                state.out = process(bq, state, insertleft(in[0], state.out));
            }
        }
    

    For real time audio applications this isn't going to be a good assumption for large numbers of filters.

  • kfrlib doesn't work at Qt 5.7.0

    kfrlib doesn't work at Qt 5.7.0

    Hi dlevin256, When I build my Qt project, it gives me the compile output, like this:

    /home/bearsuny/Libs/kfr-1.2.0/include/kfr/base/min_max.hpp:43: error: cannot convert ‘const simd_t {aka const __vector(16) unsigned char}’ to ‘__m128i {aka __vector(2) long long int}’ for argument ‘1’ to ‘__m128i _mm_min_epu8(__m128i, __m128i)’ And my project is simple, like this #include <QCoreApplication> #include <iostream> #include <kfr/dft.hpp> using namespace kfr; using namespace std; int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); return a.exec(); } The .pro file: QT += core QT -= gui CONFIG += c++14 TARGET = PipeMonitor CONFIG += console CONFIG -= app_bundle TEMPLATE = app SOURCES += main.cpp INCLUDEPATH += /home/bearsuny/Libs/kfr-1.2.0/include the version of kfrlib is 1.2.0 and I don't know that should I use kfrlib 1.0.0 or else? Thank you

  • Add vcpkg installation instructions

    Add vcpkg installation instructions

    kfr is available as a port in vcpkg, a C++ library manager that simplifies installation for kfr and other project dependencies. Documenting the install process here will help users get started by providing a single set of commands to build kfr, ready to be included in their projects.

    We also test whether our library ports build in various configurations (dynamic, static) on various platforms (OSX, Linux, Windows: x86, x64) to keep a wide coverage for users.

    I'm a maintainer for vcpkg, and here is what the port script looks like. We try to keep the library maintained as close as possible to the original library. 😊

  • Building KFR C API - MSVC2017

    Building KFR C API - MSVC2017

    Hello I try to build KFR C API with MSVC2017 according to instructions in README. However this is the error message :

    lld-link: error: : undefined symbol: mainCRTStartup

    The whole log:

    C:\Users\msd\DSP\kfr\build>cmake -GNinja -DENABLE_CAPI_BUILD=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER="C:\Program Files\LLVM\bin\clang-cl.exe" .. -- The CXX compiler identification is Clang 14.0.6 with MSVC-like command-line -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - failed -- Check for working CXX compiler: C:\Program Files\LLVM\bin\clang-cl.exe -- Check for working CXX compiler: C:\Program Files\LLVM\bin\clang-cl.exe - broken CMake Error at C:/Program Files/CMake/share/cmake-3.24/Modules/CMakeTestCXXCompiler.cmake:62 (message): The C++ compiler

    "C:\Program Files\LLVM\bin\clang-cl.exe"
    

    is not able to compile a simple test program.

    It fails with the following output:

    Change Dir: C:/Users/msd/DSP/kfr/build/CMakeFiles/CMakeTmp

    Run Build Command(s):C:/PROGRA~1/NINJA-~1/ninja.exe cmTC_9cb05 && [1/2] Building CXX object CMakeFiles\cmTC_9cb05.dir\testCXXCompiler.cxx.obj

    [2/2] Linking CXX executable cmTC_9cb05.exe

    FAILED: cmTC_9cb05.exe cmd.exe /C "cd . && "C:\Program Files\CMake\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\cmTC_9cb05.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100177~1.0\x86\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100177~1.0\x86\mt.exe --manifests -- C:\PROGRA~1\LLVM\bin\lld-link.exe /nologo CMakeFiles\cmTC_9cb05.dir\testCXXCompiler.cxx.obj /out:cmTC_9cb05.exe /implib:cmTC_9cb05.lib /pdb:cmTC_9cb05.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ." LINK Pass 1: command "C:\PROGRA~1\LLVM\bin\lld-link.exe /nologo CMakeFiles\cmTC_9cb05.dir\testCXXCompiler.cxx.obj /out:cmTC_9cb05.exe /implib:cmTC_9cb05.lib /pdb:cmTC_9cb05.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFiles\cmTC_9cb05.dir/intermediate.manifest CMakeFiles\cmTC_9cb05.dir/manifest.res" failed (exit code 1) with the following output: lld-link: error: : undefined symbol: mainCRTStartup ninja: build stopped: subcommand failed.

    CMake will not be able to correctly generate this project. Call Stack (most recent call first): CMakeLists.txt:23 (project)

    -- Configuring incomplete, errors occurred! See also "C:/Users/msd/DSP/kfr/build/CMakeFiles/CMakeOutput.log". See also "C:/Users/msd/DSP/kfr/build/CMakeFiles/CMakeError.log". You have changed variables that require your cache to be deleted. Configure will be re-run and you may have to reset some variables. The following variables have changed: CMAKE_CXX_COMPILER= C:\Program Files\LLVM\bin\clang-cl.exe

    -- Generating done CMake Warning: Manually-specified variables were not used by the project:

    ENABLE_CAPI_BUILD
    

    CMake Generate step failed. Build files cannot be regenerated correctly.

    Can anybody give me a hint what is wrong?

  • Availability of functionality

    Availability of functionality

    Hi.

    Are there any implementations of the following functionality in the KFR library, with intrinsics:

    • correlation of two vectors, with a single double-number output (Pearson correlation coefficient), and a correlation of two complex vectors;
    • shift of signal carrier frequency;
    • interpolation of signal samples with preservation of signal frequency characteristics (the one "resampling" on FFT is too slow) - like Farrow filter, using Lagrange polynomial?

    I tried but didn't find it.

  • Fix cometa ambiguities

    Fix cometa ambiguities

    Hello,

    I have been facing some issues installing KFR on a basic Ubuntu distribution. My setup is using a scientific framework (ROOT CERN) which is compiled with Clang10, and some other parts with GCC9.

    I had to update many namespace to avoid ambiguities between cometa:: and std:: methods. Here is a working update, that I compile using : mkdir build && cd build cmake -DENABLE_TESTS=ON -DBUILD_SHARED_LIBS=ON -DCMAKE_CXX_COMPILER=clang++ -DENABLE_CAPI_BUILD=ON ../

    Can somebody have a look at that ?

  • Build a test program with GCC9

    Build a test program with GCC9

    Hello,

    I have successfully built KFR (incl. C api) with shared library option enabled. Right now, I am trying to compile a class using GCC9 (std=c++17) including some basic call to dft.

    univector<complex<double>, 256> data = cexp(linspace(0, c_pi<double, 2>, 256) * make_complex(0, 1));
    univector<complex<double>, 256> freq;
        
    freq = dft(data);
    

    I am getting some issue like :

          ^
    In file included from input_line_9:5:
    In file included from /home/marcomeyer/Software/escalade/src/lib/UMO/include/UMO/TSignal.h:28:
    In file included from /home/marcomeyer/Software/kfr/4.2.1/include/kfr/dft.hpp:25:
    In file included from /home/marcomeyer/Software/kfr/4.2.1/include/kfr/base.hpp:25:
    In file included from /home/marcomeyer/Software/kfr/4.2.1/include/kfr/math.hpp:25:
    In file included from /home/marcomeyer/Software/kfr/4.2.1/include/kfr/simd.hpp:25:
    
    In file included from /home/marcomeyer/Software/kfr/4.2.1/include/kfr/simd/comparison.hpp:28:
    
    In file included from /home/marcomeyer/Software/kfr/4.2.1/include/kfr/simd/constants.hpp:28:
    /home/marcomeyer/Software/kfr/4.2.1/include/kfr/simd/types.hpp:404:75: error: reference to 'is_same' is ambiguous
        is_same<T, float> || is_same<T, double> || is_same<T, signed char> || is_same<T, unsigned char> ||
                                                                              ^
    /home/marcomeyer/Software/kfr/4.2.1/include/kfr/simd/../cometa.hpp:181:23: note: candidate found by name lookup is 'cometa::is_same'
    constexpr inline bool is_same = std::is_same<T1, T2>::value;
                          ^
    /usr/include/c++/9/type_traits:1285:12: note: candidate found by name lookup is 'std::is_same'
        struct is_same
    

    I thought about some conflict with "using namespace std;" so II removed these lines. but the problem still persist. Additionally I have noticed these error message as well:

    In file included from /home/marcomeyer/Software/kfr/4.2.1/include/kfr/dft.hpp:25:
    In file included from /home/marcomeyer/Software/kfr/4.2.1/include/kfr/base.hpp:25:
    In file included from /home/marcomeyer/Software/kfr/4.2.1/include/kfr/math.hpp:25:
    In file included from /home/marcomeyer/Software/kfr/4.2.1/include/kfr/simd.hpp:25:
    In file included from /home/marcomeyer/Software/kfr/4.2.1/include/kfr/simd/comparison.hpp:29:
    In file included from /home/marcomeyer/Software/kfr/4.2.1/include/kfr/simd/impl/function.hpp:25:
    In file included from /home/marcomeyer/Software/kfr/4.2.1/include/kfr/simd/impl/../../base/expression.hpp:29:
    In file included from /home/marcomeyer/Software/kfr/4.2.1/include/kfr/simd/impl/../../base/../simd/shuffle.hpp:28:
    In file included from /home/marcomeyer/Software/kfr/4.2.1/include/kfr/simd/mask.hpp:28:
    /home/marcomeyer/Software/kfr/4.2.1/include/kfr/simd/vec.hpp:231:41: error: reference to 'is_convertible' is ambiguous
        template <typename U, KFR_ENABLE_IF(is_convertible<U, value_type>&& compound_type_traits<T>::is_scalar)>
                                            ^
    /home/marcomeyer/Software/kfr/4.2.1/include/kfr/simd/impl/intrinsics.h:50:23: note: expanded from macro 'KFR_ENABLE_IF'
    #define KFR_ENABLE_IF CMT_ENABLE_IF
                          ^
    /home/marcomeyer/Software/kfr/4.2.1/include/kfr/simd/../cometa.hpp:187:23: note: candidate found by name lookup is 'cometa::is_convertible'
    constexpr inline bool is_convertible = std::is_convertible<Tfrom, Tto>::value;
                          ^
    /usr/include/c++/9/type_traits:1328:12: note: candidate found by name lookup is 'std::is_convertible'
        struct is_convertible
               ^
    In file included from input_line_9:5:
    In file included from /home/marcomeyer/Software/escalade/src/lib/UMO/include/UMO/TSignal.h:28:
    In file included from /home/marcomeyer/Software/kfr/4.2.1/include/kfr/dft.hpp:25:
    In file included from /home/marcomeyer/Software/kfr/4.2.1/include/kfr/base.hpp:25:
    In file included from /home/marcomeyer/Software/kfr/4.2.1/include/kfr/math.hpp:25:
    In file included from /home/marcomeyer/Software/kfr/4.2.1/include/kfr/simd.hpp:25:
    In file included from /home/marcomeyer/Software/kfr/4.2.1/include/kfr/simd/comparison.hpp:29:
    In file included from /home/marcomeyer/Software/kfr/4.2.1/include/kfr/simd/impl/function.hpp:25:
    In file included from /home/marcomeyer/Software/kfr/4.2.1/include/kfr/simd/impl/../../base/expression.hpp:29:
    In file included from /home/marcomeyer/Software/kfr/4.2.1/include/kfr/simd/impl/../../base/../simd/shuffle.hpp:28:
    In file included from /home/marcomeyer/Software/kfr/4.2.1/include/kfr/simd/mask.hpp:28:
    /home/marcomeyer/Software/kfr/4.2.1/include/kfr/simd/vec.hpp:231:27: error: parameter declarator cannot be qualified
        template <typename U, KFR_ENABLE_IF(is_convertible<U, value_type>&& compound_type_traits<T>::is_scalar)>
                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    /home/marcomeyer/Software/kfr/4.2.1/include/kfr/simd/impl/intrinsics.h:50:23: note: expanded from macro 'KFR_ENABLE_IF'
    #define KFR_ENABLE_IF CMT_ENABLE_IF
                          ^
    /home/marcomeyer/Software/kfr/4.2.1/include/kfr/simd/../cometa.hpp:874:28: note: expanded from macro 'CMT_ENABLE_IF'
    #define CMT_ENABLE_IF(...) CMT_ENABLE_IF_IMPL(__LINE__, __VA_ARGS__)
                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    /home/marcomeyer/Software/kfr/4.2.1/include/kfr/simd/../cometa.hpp:870:95: note: expanded from macro 'CMT_ENABLE_IF_IMPL'
        typename ::std::enable_if<(__VA_ARGS__), typename ::cometa::details::unique_enum_impl<N>::type>::type =  \
                                                                                                ~~^
    fatal error: too many errors emitted, stopping now [-ferror-limit=]
    

    Anybody might help me to understand or fix that issue ?

A wrapper for intel SSE/AVX vector instructions

VMath A wrapper for intel SSE/AVX vector instructions This is just a toy thing to figure out what working with intrinsics is like. I tried to keep it

Apr 24, 2022
SIMD (SSE) implementation of the infamous Fast Inverse Square Root algorithm from Quake III Arena.

simd_fastinvsqrt SIMD (SSE) implementation of the infamous Fast Inverse Square Root algorithm from Quake III Arena. Why Why not. How This video explai

Sep 18, 2022
Header only FFT library

dj_fft: Header-only FFT library Details This repository provides a header-only library to compute fourier transforms in 1D, 2D, and 3D. Its goal is to

Sep 1, 2022
Kraken is an open-source modern math library that comes with a fast-fixed matrix class and math-related functions.

Kraken ?? Table of Contents Introduction Requirement Contents Installation Introduction Kraken is a modern math library written in a way that gives ac

Aug 26, 2022
✨sigmatch - Modern C++ 20 Signature Match / Search Library

sigmatch Modern C++ 20 Signature Match / Search Library ✨ Features ?? Header-only, no dependencies, no exceptions. ☕ Compile-time literal signature st

Sep 6, 2022
A modern, C++20-native, single-file header-only dense 2D matrix library.
A modern, C++20-native, single-file header-only dense 2D matrix library.

A modern, C++20-native, single-file header-only dense 2D matrix library. Contents Example usage creating matrices basic operations row, col, size, sha

Sep 26, 2022
Random for modern C++ with convenient API

Random for modern C++ with convenient API Design goals Supported compilers Integration Five-minute tutorial Number range Common type number range Char

Oct 2, 2022
SymEngine is a fast symbolic manipulation library, written in C++

SymEngine SymEngine is a standalone fast C++ symbolic manipulation library. Optional thin wrappers allow usage of the library from other languages, e.

Sep 30, 2022
Fast math tool written on asm/c

math_tool fast math tool written on asm/c This project was created for easy use of mathematical / geometric rules and operations. This project contain

Mar 8, 2022
Blazing-fast Expression Templates Library (ETL) with GPU support, in C++

Expression Templates Library (ETL) 1.3.0 ETL is a header only library for C++ that provides vector and matrix classes with support for Expression Temp

Jul 25, 2022
(Python, R, C++) Library-agnostic evaluation framework for implicit-feedback recommender systems

RecoMetrics Library-agnostic evaluation framework for implicit-feedback recommender systems that are based on low-rank matrix factorization models or

Sep 12, 2022
C++ image processing and machine learning library with using of SIMD: SSE, SSE2, SSE3, SSSE3, SSE4.1, SSE4.2, AVX, AVX2, AVX-512, VMX(Altivec) and VSX(Power7), NEON for ARM.

Introduction The Simd Library is a free open source image processing and machine learning library, designed for C and C++ programmers. It provides man

Sep 30, 2022
C++ wrappers for SIMD intrinsics and parallelized, optimized mathematical functions (SSE, AVX, NEON, AVX512)

C++ wrappers for SIMD intrinsics and parallelized, optimized mathematical functions (SSE, AVX, NEON, AVX512)

Oct 2, 2022
Faster Non-Integer Sample Rate Conversion
Faster Non-Integer Sample Rate Conversion

Non-Integer Sample Rate Conversion This repository contains a comparison of sample-rate conversion (SRC) algorithms, with an emphasis on performance f

Jul 5, 2022
Math library using hlsl syntax with SSE/NEON support
Math library using hlsl syntax with SSE/NEON support

HLSL++ Small header-only math library for C++ with the same syntax as the hlsl shading language. It supports any SSE (x86/x64 devices like PC, Mac, PS

Sep 22, 2022
A wrapper for intel SSE/AVX vector instructions

VMath A wrapper for intel SSE/AVX vector instructions This is just a toy thing to figure out what working with intrinsics is like. I tried to keep it

Apr 24, 2022
Neon - neon - an HTTP/1.1 and WebDAV client library with a C API

neon neon is an HTTP and WebDAV client library, with a C language API. Mailing list: [email protected] || Web site: https://notroj.github.io/n

Sep 18, 2022
Fft-benchmark - A benchmark for comparison of FFT algorithms performance

FFT benchmark A benchmark for comparison of FFT algorithms performance. Currently supports Intel IPP, KFR, FFTW and KissFFT. Requires: Clang 6.0+ (GCC

Apr 7, 2022
This repo is for the open source DSP filters made for alt:V.

voice-filters This repo is for the open source DSP filters made for alt:V. Editing & building Run generate.bat and find the Visual Studio project file

Jun 16, 2022
DSP C++ audio filters

DSP filters in C++ This repo contains some DSP biquad filters used in audio. I've extracted those filters from the Designing Audio Effect Plug-Ins in

Sep 21, 2022