东方耀AI技术分享

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 1997|回复: 1
打印 上一主题 下一主题

[C/C++] 全部运行C++的DSP框架kfr-4.2.1中的例子examples

[复制链接]

1366

主题

1857

帖子

1万

积分

管理员

Rank: 10Rank: 10Rank: 10

积分
14459
QQ
跳转到指定楼层
楼主
发表于 2021-12-15 16:53:40 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
全部运行C++的DSP框架kfr-4.2.1中的例子examples

下载:https://github.com/kfrlib/kfr/releases


https://github.com/kfrlib/kfr
Documentation home:
https://www.kfrlib.com/newdocs/


不是用 cmake ..  make sudo make install了  
而是新的方法 用的cmake提供的build工具 而非make




解压 kfr-4.2.1.zip
cd kfr-4.2.1/    (靠,这个又不需要了 ,明白了)
  1. 报错:
  2. FileNotFoundError: [Errno 2] No such file or directory: '../svg/bessel_lowpass12.svg'

  3. 修改:python_plot.hpp文件中第142行:
  4. 查找命令: find ./ -name "python_plot.*"
  5. 输出源码的位置:./include/kfr/io/python_plot.hpp
  6. 位置:-- Installing: /usr/local/include/kfr/io/python_plot.hpp
  7. plot_show(name, x, concat_args(options, "file='../svg/" + name + ".svg'"));
  8. 改为:
  9. plot_show(name, x, concat_args(options, "file='./svg/" + name + ".svg'"));
复制代码




直接进入例子目录:cd examples/
修改例子里面的CMakeLists.txt文件内容:
  1. cmake_minimum_required(VERSION 3.15)

  2. project("main")     # 我加的

  3. SET(CMAKE_CXX_STANDARD 17)   # 我加的

  4. # Binary output directories  靠,有了这个就不需要改官方的代码了 python_plot.hpp
  5. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${PROJECT_BINARY_DIR}/bin)
  6. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${PROJECT_BINARY_DIR}/bin)

  7. file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/svg)

  8. message("KFR_DIR(参数传入进来的) = " ${KFR_DIR})   # 我加的
  9. # add_子目录 需要子目录里必须有CMakeLists.txt文件的
  10. add_subdirectory(${KFR_DIR} kfr-bin)    # 我加的

  11. add_executable(biquads biquads.cpp)
  12. target_link_libraries(biquads kfr use_arch)

  13. add_executable(iir iir.cpp)
  14. target_link_libraries(iir kfr use_arch)

  15. add_executable(window window.cpp)
  16. target_link_libraries(window kfr use_arch)

  17. add_executable(fir fir.cpp)
  18. target_link_libraries(fir kfr use_arch)

  19. if (ENABLE_DFT)
  20.     target_link_libraries(fir kfr_dft use_arch)
  21.     target_compile_definitions(fir PRIVATE -DHAVE_DFT)
  22. endif ()

  23. add_executable(sample_rate_conversion sample_rate_conversion.cpp)
  24. target_link_libraries(sample_rate_conversion kfr kfr_io use_arch)

  25. if (ENABLE_DFT)
  26.     add_executable(dft dft.cpp)
  27.     target_link_libraries(dft kfr kfr_dft use_arch)
  28.     add_executable(ccv ccv.cpp)
  29.     target_link_libraries(ccv kfr kfr_dft use_arch)
  30. endif ()



  31. # cmake方式依赖Python头文件和库文件的配置 我加的
  32. # 如果使用的是非系统目录下的 Python 可以通过指定 Python3_ROOT_DIR 改变查找路径
  33. set(Python3_ROOT_DIR "/home/jiang/miniconda3/envs/py3_tf2_torch")
  34. # 这里的环境 与 cmd的环境要一致  conda activate py3_tf2_torch
  35. # 因为 有这个:#!/usr/bin/env python
  36. find_package(Python3 COMPONENTS Interpreter Development REQUIRED)
  37. find_package(Python3 COMPONENTS NumPy)
  38. # find_package(PythonLibs REQUIRED)
  39. message("python3头文件目录:" ${Python3_INCLUDE_DIRS})
  40. message("python3的版本信息:" ${Python3_VERSION})
  41. message("python3中numpy的版本信息:" ${Python3_NumPy_VERSION})
  42. message("python3的库文件信息:" ${Python3_LIBRARIES})

  43. # python的头文件 PYTHON_INCLUDE_DIRS
  44. include_directories(${Python3_INCLUDE_DIRS})
  45. # python的库文件 PYTHON_LIBRARIES   
  46. # 解决报错: fatal error: Python.h: 没有那个文件或目录
  47. target_link_libraries(iir ${Python3_LIBRARIES})
复制代码




mkdir build && cd build
cmake "-DKFR_DIR=/home/jiang/jjj_kfrlib_works/kfr-4.2.1/" -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_BUILD_TYPE=Release ..
  1. -- The C compiler identification is GNU 8.4.0
  2. -- The CXX compiler identification is Clang 7.0.0
  3. -- Detecting C compiler ABI info
  4. -- Detecting C compiler ABI info - done
  5. -- Check for working C compiler: /usr/bin/cc - skipped
  6. -- Detecting C compile features
  7. -- Detecting C compile features - done
  8. -- Detecting CXX compiler ABI info
  9. -- Detecting CXX compiler ABI info - done
  10. -- Check for working CXX compiler: /usr/bin/clang++ - skipped
  11. -- Detecting CXX compile features
  12. -- Detecting CXX compile features - done
  13. KFR_DIR(参数传入进来的) = /home/jiang/jjj_kfrlib_works/kfr-4.2.1/
  14. -- Detecting native cpu...
  15. -- DETECTED_CPU=avx2
  16. -- CPU_ARCH=avx2
  17. -- Found Python3: /home/jiang/miniconda3/envs/py3_tf2_torch/bin/python3.6 (found version "3.6.10") found components: Interpreter Development Development.Module Development.Embed
  18. -- Found Python3: /home/jiang/miniconda3/envs/py3_tf2_torch/include/python3.6m (found version "3.6.10") found components: NumPy Interpreter Development.Module
  19. python3头文件目录:/home/jiang/miniconda3/envs/py3_tf2_torch/include/python3.6m
  20. python3的版本信息:3.6.10
  21. python3中numpy的版本信息:1.19.5
  22. python3的库文件信息:/home/jiang/miniconda3/envs/py3_tf2_torch/lib/libpython3.6m.so
  23. -- Configuring done
  24. -- Generating done
  25. -- Build files have been written to: /home/jiang/jjj_kfrlib_works/kfr-4.2.1/examples/build
复制代码


cmake "-DKFR_DIR=/home/jiang/jjj_kfrlib_works/kfr-4.2.1/" -DCMAKE_C_COMPILER=/usr/bin/gcc-7 -DCMAKE_CXX_COMPILER=/usr/bin/g++-7 -DCMAKE_BUILD_TYPE=Release ..
  1. -- The C compiler identification is GNU 7.5.0
  2. -- The CXX compiler identification is GNU 7.5.0
  3. -- Detecting C compiler ABI info
  4. -- Detecting C compiler ABI info - done
  5. -- Check for working C compiler: /usr/bin/gcc-7 - skipped
  6. -- Detecting C compile features
  7. -- Detecting C compile features - done
  8. -- Detecting CXX compiler ABI info
  9. -- Detecting CXX compiler ABI info - done
  10. -- Check for working CXX compiler: /usr/bin/g++-7 - skipped
  11. -- Detecting CXX compile features
  12. -- Detecting CXX compile features - done
  13. KFR_DIR(参数传入进来的) = /home/jiang/jjj_kfrlib_works/kfr-4.2.1/
  14. -- Detecting native cpu...
  15. -- DETECTED_CPU=avx2
  16. -- CPU_ARCH=avx2
  17. -- Found Python3: /home/jiang/miniconda3/envs/py3_tf2_torch/bin/python3.6 (found version "3.6.10") found components: Interpreter Development Development.Module Development.Embed
  18. -- Found Python3: /home/jiang/miniconda3/envs/py3_tf2_torch/include/python3.6m (found version "3.6.10") found components: NumPy Interpreter Development.Module
  19. python3头文件目录:/home/jiang/miniconda3/envs/py3_tf2_torch/include/python3.6m
  20. python3的版本信息:3.6.10
  21. python3中numpy的版本信息:1.19.5
  22. python3的库文件信息:/home/jiang/miniconda3/envs/py3_tf2_torch/lib/libpython3.6m.so
  23. -- Configuring done
  24. -- Generating done
  25. -- Build files have been written to: /home/jiang/jjj_kfrlib_works/kfr-4.2.1/examples/build
复制代码



cmake --build .  (不需要手动编译,用cmake自动编译)
  1. Scanning dependencies of target kfr_dft
  2. [  4%] Building CXX object kfr-bin/CMakeFiles/kfr_dft.dir/include/kfr/dft/impl/convolution-impl.cpp.o
  3. [  8%] Building CXX object kfr-bin/CMakeFiles/kfr_dft.dir/include/kfr/dft/impl/dft-impl-f32.cpp.o
  4. [ 12%] Building CXX object kfr-bin/CMakeFiles/kfr_dft.dir/include/kfr/dft/impl/dft-impl-f64.cpp.o
  5. [ 16%] Building CXX object kfr-bin/CMakeFiles/kfr_dft.dir/include/kfr/dft/impl/fft-impl-f32.cpp.o
  6. [ 20%] Building CXX object kfr-bin/CMakeFiles/kfr_dft.dir/include/kfr/dft/impl/fft-impl-f64.cpp.o
  7. [ 25%] Linking CXX static library libkfr_dft.a
  8. [ 25%] Built target kfr_dft
  9. Scanning dependencies of target ccv
  10. [ 29%] Building CXX object CMakeFiles/ccv.dir/ccv.cpp.o
  11. [ 33%] Linking CXX executable bin/ccv
  12. [ 33%] Built target ccv
  13. Scanning dependencies of target fir
  14. [ 37%] Building CXX object CMakeFiles/fir.dir/fir.cpp.o
  15. [ 41%] Linking CXX executable bin/fir
  16. [ 41%] Built target fir
  17. Scanning dependencies of target biquads
  18. [ 45%] Building CXX object CMakeFiles/biquads.dir/biquads.cpp.o
  19. [ 50%] Linking CXX executable bin/biquads
  20. [ 50%] Built target biquads
  21. Scanning dependencies of target window
  22. [ 54%] Building CXX object CMakeFiles/window.dir/window.cpp.o
  23. [ 58%] Linking CXX executable bin/window
  24. [ 58%] Built target window
  25. Scanning dependencies of target dft
  26. [ 62%] Building CXX object CMakeFiles/dft.dir/dft.cpp.o
  27. [ 66%] Linking CXX executable bin/dft
  28. [ 66%] Built target dft
  29. Scanning dependencies of target iir
  30. [ 70%] Building CXX object CMakeFiles/iir.dir/iir.cpp.o
  31. [ 75%] Linking CXX executable bin/iir
  32. [ 75%] Built target iir
  33. Scanning dependencies of target kfr_io
  34. [ 79%] Building CXX object kfr-bin/CMakeFiles/kfr_io.dir/include/kfr/io/impl/audiofile-impl.cpp.o
  35. [ 83%] Linking CXX static library libkfr_io.a
  36. [ 83%] Built target kfr_io
  37. Scanning dependencies of target sample_rate_conversion
  38. [ 87%] Building CXX object CMakeFiles/sample_rate_conversion.dir/sample_rate_conversion.cpp.o
  39. [ 91%] Linking CXX executable bin/sample_rate_conversion
  40. [ 91%] Built target sample_rate_conversion
  41. Scanning dependencies of target detect_cpu
  42. [ 95%] Building CXX object kfr-bin/CMakeFiles/detect_cpu.dir/cmake/detect_cpu.cpp.o
  43. [100%] Linking CXX executable ../bin/detect_cpu
  44. [100%] Built target detect_cpu
复制代码



In this case you do not need to build KFR binaries manually, cmake will do it automatically for you.
use_arch is a virtual target that exists only in cmake environment.
It's intended for setting correct arch flags for you own executables, you should not use it in GCC command line













cmake_kfr_新方式.png (139.4 KB, 下载次数: 128)

cmake_kfr_新方式.png
让天下人人学会人工智能!人工智能的前景一片大好!
回复

使用道具 举报

0

主题

1

帖子

6

积分

新手上路

Rank: 1

积分
6
沙发
发表于 2022-1-6 22:45:59 | 只看该作者
我想看BP帖子,没有权限。。。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|人工智能工程师的摇篮 ( 湘ICP备2020019608号-1 )

GMT+8, 2024-6-24 20:12 , Processed in 0.194376 second(s), 21 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表