kfrlib / kfr

Fast, modern C++ DSP framework, FFT, Sample Rate Conversion, FIR/IIR/Biquad Filters (SSE, AVX, AVX-512, ARM NEON)
https://www.kfrlib.com
GNU General Public License v2.0
1.65k stars 253 forks source link

Compiler error on Android only #94

Closed kakyoism closed 4 years ago

kakyoism commented 4 years ago

The following code snippets compile ok on macOS and iOS but fails on Android


    const int nMaxNFFT = 2048;
    univector<complex<fbase>, nMaxNFFT> spectrum = scalar(qnan);
    const int nFramesWinOv = AUDIO_BUFFER_SIZE;
    univector<fbase, nFramesWinOv> reals = make_univector(pAudio, nFramesWinOv);
    reals *= my_win;
    univector<complex<fbase>, nFramesWinOv> inVec(make_complex(reals, zeros()));
    my_dft.execute(spectrum, inVec, m_workBuf);

    univector<complex<fbase>, nMaxNFFT/2> specHalf = scalar(qnan);
    std::copy(spectrum.begin(), spectrum.begin()+nFFT/2, specHalf.begin());

    univector<fbase, nMaxNFFT/2> amps = cabs(specHalf/m_nFFT);
    univector<fbase, nMaxNFFT/2> dbs = amp_to_dB(amps);
    auto clamped = clamp(dbs, -200.f, 0.f);  // failed to compile here

With compiler error

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:externalNativeBuildDebug'.
> Build command failed.
  Error while executing process /Applications/Android/sdk/cmake/3.10.2.4988404/bin/ninja with arguments {-C /path/to/myproj/example/android/app/.cxx/cmake/debug/arm64-v8a nativeguest}
  ninja: Entering directory `/path/to/myproj/example/android/app/.cxx/cmake/debug/arm64-v8a'
  [1/2] Building CXX object CMakeFiles/nativeguest.dir/Users/kakyo/Desktop/_task/mam/src/mam-guest/Common/MamGuestAudioMeter.cpp.o
  FAILED: CMakeFiles/nativeguest.dir/Users/kakyo/Desktop/_task/mam/src/mam-guest/Common/MamGuestAudioMeter.cpp.o 
  /Applications/Android/sdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ --target=aarch64-none-linux-android21 --gcc-toolchain=/Applications/Android/sdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/darwin-x86_64 --sysroot=/Applications/Android/sdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/darwin-x86_64/sysroot  -DOBOE_ENABLE_LOGGING=1 -Dnativeguest_EXPORTS -I/path/to/myproj/example/android/app/src/main/cpp/../../../../../../../../.. -I/path/to/myproj/example/android/app/src/main/cpp/../../../../../../../../../src/mam-common -I/path/to/myproj/example/android/app/src/main/cpp/../../../../../../../../../src/mam-guest/Common -I/path/to/myproj/example/android/app/src/main/cpp/../../../../../../../../../thirdparty/oboe/include -I/path/to/myproj/example/android/app/src/main/cpp/../../../../../../../../../thirdparty/cppzmq -I/path/to/myproj/example/android/app/src/main/cpp/../../../../../../../../../build/android/arm64-v8a/include -I/path/to/myproj/example/android/app/src/main/cpp/../../../../../../../../../thirdparty/protobuf/src -I/Users/kakyo/Desktop/_task/mam/thirdparty/oboe/include -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security  -std=c++14 -fexceptions -frtti -DZMQ_BUILD_DRAFT_API -DZF_LOG_USE_ANDROID_LOG -DDCMT_BASETYPE_F32 -O0 -fno-limit-debug-info  -fPIC   -std=c++1z -MD -MT CMakeFiles/nativeguest.dir/Users/kakyo/Desktop/_task/mam/src/mam-guest/Common/MamGuestAudioMeter.cpp.o -MF CMakeFiles/nativeguest.dir/Users/kakyo/Desktop/_task/mam/src/mam-guest/Common/MamGuestAudioMeter.cpp.o.d -o CMakeFiles/nativeguest.dir/Users/kakyo/Desktop/_task/mam/src/mam-guest/Common/MamGuestAudioMeter.cpp.o -c /Users/kakyo/Desktop/_task/mam/src/mam-guest/Common/MamGuestAudioMeter.cpp
  In file included from /Users/kakyo/Desktop/_task/mam/src/mam-guest/Common/MamGuestAudioMeter.cpp:7:
  In file included from /path/to/myproj/example/android/app/src/main/cpp/../../../../../../../../../build/android/arm64-v8a/include/kfr/math.hpp:25:
  In file included from /path/to/myproj/example/android/app/src/main/cpp/../../../../../../../../../build/android/arm64-v8a/include/kfr/simd.hpp:25:
  In file included from /path/to/myproj/example/android/app/src/main/cpp/../../../../../../../../../build/android/arm64-v8a/include/kfr/simd/comparison.hpp:28:
  In file included from /path/to/myproj/example/android/app/src/main/cpp/../../../../../../../../../build/android/arm64-v8a/include/kfr/dft/../simd/constants.hpp:28:
  In file included from /path/to/myproj/example/android/app/src/main/cpp/../../../../../../../../../build/android/arm64-v8a/include/kfr/math/../simd/types.hpp:31:
  In file included from /path/to/myproj/example/android/app/src/main/cpp/../../../../../../../../../build/android/arm64-v8a/include/kfr/simd/impl/specialconstants.hpp:25:
  In file included from /path/to/myproj/example/android/app/src/main/cpp/../../../../../../../../../build/android/arm64-v8a/include/kfr/simd/../cometa/numeric.hpp:6:
  /path/to/myproj/example/android/app/src/main/cpp/../../../../../../../../../build/android/arm64-v8a/include/kfr/dsp/../testo/../cometa.hpp:121:1: error: no type named 'type' in 'std::__ndk1::result_of<kfr::neon64::fn::clamp (kfr::neon64::vec<double, 1>, kfr::neon64::vec<float, 1>, kfr::neon64::vec<float, 1>)>'
  using invoke_result = typename std::result_of<T(Args...)>::type;
  ^~~~~
  /path/to/myproj/example/android/app/src/main/cpp/../../../../../../../../../build/android/arm64-v8a/include/kfr/dsp/../base/expression.hpp:362:27: note: in instantiation of template type alias 'invoke_result' requested here
      using type = typename invoke_result<Fn, vec<arg_type<Args>, 1>...>::value_type;
                            ^
  /path/to/myproj/example/android/app/src/main/cpp/../../../../../../../../../build/android/arm64-v8a/include/kfr/dsp/../base/expression.hpp:368:33: note: in instantiation of template class 'kfr::neon64::internal::function_value_type<kfr::neon64::fn::clamp, kfr::univector<double, 1024> &, float, float>' requested here
      using value_type = typename function_value_type<Fn, Args...>::type;
                                  ^
  /Users/kakyo/Desktop/_task/mam/src/mam-guest/Common/MamGuestAudioMeter.cpp:54:20: note: in instantiation of template class 'kfr::neon64::internal::expression_function<kfr::neon64::fn::clamp, kfr::univector<double, 1024> &, float, float>' requested here
      auto clamped = clamp(dbs, -200.f, 0.f);
                     ^
  1 error generated.
  ninja: build stopped: subcommand failed.

Any tips to share, please?

kakyoism commented 4 years ago

Was a problem on my part, had a typo in my defines -DDCMT_BASETYPE_F32 should have been -DCMT_BASETYPE_F32, an extra D caused my problem.