From 1efdc3a7f6cba76cf475dbc8cc0862981981f9e0 Mon Sep 17 00:00:00 2001 From: Lane Kolbly Date: Wed, 14 Apr 2021 14:37:10 -0500 Subject: examples: Add min dynamic range limit to ascii art DFT example The DFT plotting routine hangs when the dynamic range equals zero, so this change adds a limit so that the dynamic range never goes below 10. --- host/examples/ascii_art_dft.hpp | 4 ++++ host/examples/rx_ascii_art_dft.cpp | 8 +++++--- 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'host/examples') diff --git a/host/examples/ascii_art_dft.hpp b/host/examples/ascii_art_dft.hpp index fe411e400..73e627519 100644 --- a/host/examples/ascii_art_dft.hpp +++ b/host/examples/ascii_art_dft.hpp @@ -233,6 +233,10 @@ std::string dft_to_plot(const log_pwr_dft_type& dft_, float dyn_rng, float ref_lvl) { + if (dyn_rng <= 0.0) { + throw std::runtime_error("dyn_rng must be greater than zero in dft_to_plot"); + } + frame_type frame(width, height); // fill this frame // re-order the dft so dc in in the center diff --git a/host/examples/rx_ascii_art_dft.cpp b/host/examples/rx_ascii_art_dft.cpp index 3652522f2..12f9477a8 100644 --- a/host/examples/rx_ascii_art_dft.cpp +++ b/host/examples/rx_ascii_art_dft.cpp @@ -286,9 +286,11 @@ int UHD_SAFE_MAIN(int argc, char* argv[]) ref_lvl -= 10; else if (ch == 'L') ref_lvl += 10; - else if (ch == 'd') - dyn_rng -= 10; - else if (ch == 'D') + else if (ch == 'd') { + if (dyn_rng > 10) { + dyn_rng -= 10; + } + } else if (ch == 'D') dyn_rng += 10; else if (ch == 's') { if (frame_rate > 1) { -- cgit v1.2.3