From c85e6a4d523585bd0838b06759c01bf8679e69c2 Mon Sep 17 00:00:00 2001 From: teixeluis Date: Wed, 9 Jun 2021 09:10:01 +0100 Subject: [PATCH 1/5] Now getting rssi events.Pitch changes still to be improved. --- firmware/application/apps/ui_sonde.cpp | 7 +++++++ firmware/baseband/proc_sonde.cpp | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/firmware/application/apps/ui_sonde.cpp b/firmware/application/apps/ui_sonde.cpp index 278037dd..28796cd7 100644 --- a/firmware/application/apps/ui_sonde.cpp +++ b/firmware/application/apps/ui_sonde.cpp @@ -130,6 +130,13 @@ SondeView::SondeView(NavigationView& nav) { audio::output::start(); audio::output::speaker_unmute(); + // inject a PitchRSSIConfigureMessage in order to arm + // the pitch rssi events that will be used by the + // processor: + const PitchRSSIConfigureMessage message { true, 0 }; + + shared_memory.application_queue.push(message); + baseband::set_pitch_rssi(0, true); } diff --git a/firmware/baseband/proc_sonde.cpp b/firmware/baseband/proc_sonde.cpp index a593bec9..4beb6eb4 100644 --- a/firmware/baseband/proc_sonde.cpp +++ b/firmware/baseband/proc_sonde.cpp @@ -114,7 +114,7 @@ void SondeProcessor::pitch_rssi_config(const PitchRSSIConfigureMessage& message) // log_file.write_entry(datetime, "pitch_rssi_config: message.rssi: " + message.rssi); pitch_rssi_enabled = message.enabled; - tone_delta = (message.rssi * 10 + 1000) * ((1ULL << 32) / 24000); + tone_delta = (message.rssi + 1000) * ((1ULL << 32) / 24000); // log_file.write_entry(datetime, "pitch_rssi_config: tone_delta: " + tone_delta); } From edcd780402273ef59d1043ccf97c98a88faba38f Mon Sep 17 00:00:00 2001 From: teixeluis Date: Thu, 10 Jun 2021 12:10:24 +0100 Subject: [PATCH 2/5] Improved the pitch RSSI. Still looking for better approach. --- firmware/application/ui/ui_rssi.cpp | 6 +- firmware/baseband/proc_sonde.cpp | 46 +++++---- firmware/baseband/proc_sonde.hpp | 9 +- firmware/common/sine_table_int16.hpp | 138 +++++++++++++++++++++++++++ firmware/common/sine_table_int8.hpp | 1 + 5 files changed, 174 insertions(+), 26 deletions(-) create mode 100644 firmware/common/sine_table_int16.hpp diff --git a/firmware/application/ui/ui_rssi.cpp b/firmware/application/ui/ui_rssi.cpp index 98cfed63..ce6acd9a 100644 --- a/firmware/application/ui/ui_rssi.cpp +++ b/firmware/application/ui/ui_rssi.cpp @@ -75,8 +75,10 @@ void RSSI::paint(Painter& painter) { Color::black() ); - if (pitch_rssi_enabled) - baseband::set_pitch_rssi((avg_ - raw_min) * 2000 / raw_delta, true); + if (pitch_rssi_enabled) { + //baseband::set_pitch_rssi((avg_ - raw_min) * 2000 / raw_delta, true); + baseband::set_pitch_rssi((min_ - raw_min) * 2000 / raw_delta, true); + } } void RSSI::set_pitch_rssi(bool enabled) { diff --git a/firmware/baseband/proc_sonde.cpp b/firmware/baseband/proc_sonde.cpp index 4beb6eb4..d967dbb3 100644 --- a/firmware/baseband/proc_sonde.cpp +++ b/firmware/baseband/proc_sonde.cpp @@ -53,13 +53,11 @@ void SondeProcessor::execute(const buffer_c8_t& buffer) { } } - if(pitch_rssi_enabled) { - if(beep_playing) { - beep_loop(); - } - else { - silence_loop(); - } + if(pitch_rssi_enabled && beep_playing) { + generate_beep(); + } + else { + generate_silence(); } } @@ -90,33 +88,41 @@ void SondeProcessor::stop_beep() { beep_playing = false; } -void SondeProcessor::beep_loop() { - for (size_t i = 0; i < sizeof(audio_buffer.p); i++) { - audio_buffer.p[i] = (sine_table_i8[(tone_phase & 0xFF000000U) >> 24]) * 128; +void SondeProcessor::generate_beep() { + // if(curr_sample == sizeof(audio_buffer.p)) { + // audio_output.write(audio_buffer); + // curr_sample = 0; + // //tone_phase = 0; + // } + // else if(beep_playing) { + // audio_buffer.p[curr_sample++] = (sine_table_i16[(tone_phase & 0xFF000000U) >> 24]); + // tone_phase += tone_delta; + // } + // else { + // audio_buffer.p[curr_sample++] = 0; + // tone_phase = 0; + // } + + for(uint8_t i = 0; i < sizeof(audio_buffer.p); i++) { + audio_buffer.p[i] = (sine_table_i16_1024[(tone_phase & 0xFFC00000U) >> 22]); tone_phase += tone_delta; } - + audio_output.write(audio_buffer); } -void SondeProcessor::silence_loop() { - for (size_t i = 0; i < sizeof(audio_buffer.p); i++) { +void SondeProcessor::generate_silence() { + for(uint8_t i = 0; i < sizeof(audio_buffer.p); i++) { audio_buffer.p[i] = 0; + tone_phase = 0; } audio_output.write(audio_buffer); } void SondeProcessor::pitch_rssi_config(const PitchRSSIConfigureMessage& message) { - // rtc::RTC datetime; - // rtcGetTime(&RTCD1, &datetime); - - // log_file.write_entry(datetime, "pitch_rssi_config: message.rssi: " + message.rssi); - pitch_rssi_enabled = message.enabled; tone_delta = (message.rssi + 1000) * ((1ULL << 32) / 24000); - - // log_file.write_entry(datetime, "pitch_rssi_config: tone_delta: " + tone_delta); } int main() { diff --git a/firmware/baseband/proc_sonde.hpp b/firmware/baseband/proc_sonde.hpp index a7b4574f..1662440c 100644 --- a/firmware/baseband/proc_sonde.hpp +++ b/firmware/baseband/proc_sonde.hpp @@ -91,7 +91,7 @@ #include "audio_output.hpp" #include "tone_gen.hpp" #include "tonesets.hpp" -#include "sine_table_int8.hpp" +#include "sine_table_int16.hpp" #include "buffer.hpp" @@ -110,7 +110,7 @@ private: static constexpr size_t baseband_fs = 2457600; static constexpr size_t beep_iterations = 60; - std::array audio { }; + std::array audio { }; const buffer_s16_t audio_buffer { (int16_t*) audio.data(), @@ -124,6 +124,7 @@ private: uint32_t tone_delta { 0 }; uint32_t tone_phase { 0 }; + uint8_t curr_sample { 0 }; BasebandThread baseband_thread { baseband_fs, this, NORMALPRIO + 20, baseband::Direction::Receive }; RSSIThread rssi_thread { NORMALPRIO + 10 }; @@ -177,8 +178,8 @@ private: void play_beep(); void stop_beep(); - void beep_loop(); - void silence_loop(); + void generate_beep(); + void generate_silence(); void pitch_rssi_config(const PitchRSSIConfigureMessage& message); }; diff --git a/firmware/common/sine_table_int16.hpp b/firmware/common/sine_table_int16.hpp new file mode 100644 index 00000000..b0dda364 --- /dev/null +++ b/firmware/common/sine_table_int16.hpp @@ -0,0 +1,138 @@ +/* + * Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc. + * Copyright (C) 2016 Furrtek + * + * This file is part of PortaPack. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING.If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __SINE_TABLE_I16_H__ +#define __SINE_TABLE_I16_H__ + +#include + +static const int16_t sine_table_i16[256] = { 0, 804, 1607, 2410, 3211, 4011, 4807, + 5601, 6392, 7179, 7961, 8739, 9511, 10278, 11039, 11792, 12539, 13278, 14009, 14732, + 15446, 16151, 16845, 17530, 18204, 18867, 19519, 20159, 20787, 21402, 22005, 22594, + 23170, 23731, 24279, 24811, 25329, 25832, 26319, 26790, 27245, 27683, 28105, 28510, + 28898, 29268, 29621, 29956, 30273, 30571, 30852, 31113, 31356, 31580, 31785, 31971, + 32137, 32285, 32412, 32521, 32609, 32678, 32728, 32757, 32767, 32757, 32728, 32678, + 32609, 32521, 32412, 32285, 32137, 31971, 31785, 31580, 31356, 31113, 30852, 30571, + 30273, 29956, 29621, 29268, 28898, 28510, 28105, 27683, 27245, 26790, 26319, 25832, + 25329, 24811, 24279, 23731, 23170, 22594, 22005, 21402, 20787, 20159, 19519, 18867, + 18204, 17530, 16845, 16151, 15446, 14732, 14009, 13278, 12539, 11792, 11039, 10278, + 9511, 8739, 7961, 7179, 6392, 5601, 4807, 4011, 3211, 2410, 1607, 804, 0, -805, -1608, + -2411, -3212, -4012, -4808, -5602, -6393, -7180, -7962, -8740, -9512, -10279, -11040, + -11793, -12540, -13279, -14010, -14733, -15447, -16152, -16846, -17531, -18205, -18868, + -19520, -20160, -20788, -21403, -22006, -22595, -23171, -23732, -24280, -24812, -25330, + -25833, -26320, -26791, -27246, -27684, -28106, -28511, -28899, -29269, -29622, -29957, + -30274, -30572, -30853, -31114, -31357, -31581, -31786, -31972, -32138, -32286, -32413, + -32522, -32610, -32679, -32729, -32758, -32768, -32758, -32729, -32679, -32610, -32522, + -32413, -32286, -32138, -31972, -31786, -31581, -31357, -31114, -30853, -30572, -30274, + -29957, -29622, -29269, -28899, -28511, -28106, -27684, -27246, -26791, -26320, -25833, + -25330, -24812, -24280, -23732, -23171, -22595, -22006, -21403, -20788, -20160, -19520, + -18868, -18205, -17531, -16846, -16152, -15447, -14733, -14010, -13279, -12540, -11793, + -11040, -10279, -9512, -8740, -7962, -7180, -6393, -5602, -4808, -4012, -3212, -2411, + -1608, -805 }; + +static const int16_t sine_table_i16_1024[1024] = {0, 201, 402, 603, 804, 1005, 1206, 1406, + 1607, 1808, 2009, 2209, 2410, 2610, 2811, 3011, 3211, 3411, 3611, 3811, 4011, 4210, 4409, + 4609, 4807, 5006, 5205, 5403, 5601, 5799, 5997, 6195, 6392, 6589, 6786, 6983, 7179, 7375, + 7571, 7766, 7961, 8156, 8351, 8545, 8739, 8933, 9126, 9319, 9511, 9704, 9895, 10087, 10278, + 10469, 10659, 10849, 11039, 11228, 11416, 11605, 11792, 11980, 12167, 12353, 12539, 12725, + 12910, 13094, 13278, 13462, 13645, 13827, 14009, 14191, 14372, 14552, 14732, 14911, 15090, + 15268, 15446, 15623, 15799, 15975, 16151, 16325, 16499, 16673, 16845, 17017, 17189, 17360, + 17530, 17700, 17868, 18037, 18204, 18371, 18537, 18703, 18867, 19031, 19195, 19357, 19519, + 19680, 19841, 20000, 20159, 20317, 20475, 20631, 20787, 20942, 21096, 21250, 21402, 21554, + 21705, 21855, 22005, 22153, 22301, 22448, 22594, 22739, 22884, 23027, 23170, 23311, 23452, + 23592, 23731, 23869, 24007, 24143, 24279, 24413, 24547, 24680, 24811, 24942, 25072, 25201, + 25329, 25456, 25582, 25707, 25832, 25955, 26077, 26198, 26319, 26438, 26556, 26673, 26790, + 26905, 27019, 27132, 27245, 27356, 27466, 27575, 27683, 27790, 27896, 28001, 28105, 28208, + 28310, 28410, 28510, 28609, 28706, 28803, 28898, 28992, 29085, 29177, 29268, 29358, 29447, + 29534, 29621, 29706, 29791, 29874, 29956, 30037, 30117, 30195, 30273, 30349, 30424, 30498, + 30571, 30643, 30714, 30783, 30852, 30919, 30985, 31050, 31113, 31176, 31237, 31297, 31356, + 31414, 31470, 31526, 31580, 31633, 31685, 31736, 31785, 31833, 31880, 31926, 31971, 32014, + 32057, 32098, 32137, 32176, 32213, 32250, 32285, 32318, 32351, 32382, 32412, 32441, 32469, + 32495, 32521, 32545, 32567, 32589, 32609, 32628, 32646, 32663, 32678, 32692, 32705, 32717, + 32728, 32737, 32745, 32752, 32757, 32761, 32765, 32766, 32767, 32766, 32765, 32761, 32757, + 32752, 32745, 32737, 32728, 32717, 32705, 32692, 32678, 32663, 32646, 32628, 32609, 32589, + 32567, 32545, 32521, 32495, 32469, 32441, 32412, 32382, 32351, 32318, 32285, 32250, 32213, + 32176, 32137, 32098, 32057, 32014, 31971, 31926, 31880, 31833, 31785, 31736, 31685, 31633, + 31580, 31526, 31470, 31414, 31356, 31297, 31237, 31176, 31113, 31050, 30985, 30919, 30852, + 30783, 30714, 30643, 30571, 30498, 30424, 30349, 30273, 30195, 30117, 30037, 29956, 29874, + 29791, 29706, 29621, 29534, 29447, 29358, 29268, 29177, 29085, 28992, 28898, 28803, 28706, + 28609, 28510, 28410, 28310, 28208, 28105, 28001, 27896, 27790, 27683, 27575, 27466, 27356, + 27245, 27132, 27019, 26905, 26790, 26673, 26556, 26438, 26319, 26198, 26077, 25955, 25832, + 25707, 25582, 25456, 25329, 25201, 25072, 24942, 24811, 24680, 24547, 24413, 24279, 24143, + 24007, 23869, 23731, 23592, 23452, 23311, 23170, 23027, 22884, 22739, 22594, 22448, 22301, + 22153, 22005, 21855, 21705, 21554, 21402, 21250, 21096, 20942, 20787, 20631, 20475, 20317, + 20159, 20000, 19841, 19680, 19519, 19357, 19195, 19031, 18867, 18703, 18537, 18371, 18204, + 18037, 17868, 17700, 17530, 17360, 17189, 17017, 16845, 16673, 16499, 16325, 16151, 15975, + 15799, 15623, 15446, 15268, 15090, 14911, 14732, 14552, 14372, 14191, 14009, 13827, 13645, + 13462, 13278, 13094, 12910, 12725, 12539, 12353, 12167, 11980, 11792, 11605, 11416, 11228, + 11039, 10849, 10659, 10469, 10278, 10087, 9895, 9704, 9511, 9319, 9126, 8933, 8739, 8545, + 8351, 8156, 7961, 7766, 7571, 7375, 7179, 6983, 6786, 6589, 6392, 6195, 5997, 5799, 5601, + 5403, 5205, 5006, 4807, 4609, 4409, 4210, 4011, 3811, 3611, 3411, 3211, 3011, 2811, 2610, + 2410, 2209, 2009, 1808, 1607, 1406, 1206, 1005, 804, 603, 402, 201, 0, -202, -403, -604, + -805, -1006, -1207, -1407, -1608, -1809, -2010, -2210, -2411, -2611, -2812, -3012, -3212, + -3412, -3612, -3812, -4012, -4211, -4410, -4610, -4808, -5007, -5206, -5404, -5602, -5800, + -5998, -6196, -6393, -6590, -6787, -6984, -7180, -7376, -7572, -7767, -7962, -8157, -8352, + -8546, -8740, -8934, -9127, -9320, -9512, -9705, -9896, -10088, -10279, -10470, -10660, + -10850, -11040, -11229, -11417, -11606, -11793, -11981, -12168, -12354, -12540, -12726, + -12911, -13095, -13279, -13463, -13646, -13828, -14010, -14192, -14373, -14553, -14733, + -14912, -15091, -15269, -15447, -15624, -15800, -15976, -16152, -16326, -16500, -16674, + -16846, -17018, -17190, -17361, -17531, -17701, -17869, -18038, -18205, -18372, -18538, + -18704, -18868, -19032, -19196, -19358, -19520, -19681, -19842, -20001, -20160, -20318, + -20476, -20632, -20788, -20943, -21097, -21251, -21403, -21555, -21706, -21856, -22006, + -22154, -22302, -22449, -22595, -22740, -22885, -23028, -23171, -23312, -23453, -23593, + -23732, -23870, -24008, -24144, -24280, -24414, -24548, -24681, -24812, -24943, -25073, + -25202, -25330, -25457, -25583, -25708, -25833, -25956, -26078, -26199, -26320, -26439, + -26557, -26674, -26791, -26906, -27020, -27133, -27246, -27357, -27467, -27576, -27684, + -27791, -27897, -28002, -28106, -28209, -28311, -28411, -28511, -28610, -28707, -28804, + -28899, -28993, -29086, -29178, -29269, -29359, -29448, -29535, -29622, -29707, -29792, + -29875, -29957, -30038, -30118, -30196, -30274, -30350, -30425, -30499, -30572, -30644, + -30715, -30784, -30853, -30920, -30986, -31051, -31114, -31177, -31238, -31298, -31357, + -31415, -31471, -31527, -31581, -31634, -31686, -31737, -31786, -31834, -31881, -31927, + -31972, -32015, -32058, -32099, -32138, -32177, -32214, -32251, -32286, -32319, -32352, + -32383, -32413, -32442, -32470, -32496, -32522, -32546, -32568, -32590, -32610, -32629, + -32647, -32664, -32679, -32693, -32706, -32718, -32729, -32738, -32746, -32753, -32758, + -32762, -32766, -32767, -32768, -32767, -32766, -32762, -32758, -32753, -32746, -32738, + -32729, -32718, -32706, -32693, -32679, -32664, -32647, -32629, -32610, -32590, -32568, + -32546, -32522, -32496, -32470, -32442, -32413, -32383, -32352, -32319, -32286, -32251, + -32214, -32177, -32138, -32099, -32058, -32015, -31972, -31927, -31881, -31834, -31786, + -31737, -31686, -31634, -31581, -31527, -31471, -31415, -31357, -31298, -31238, -31177, + -31114, -31051, -30986, -30920, -30853, -30784, -30715, -30644, -30572, -30499, -30425, + -30350, -30274, -30196, -30118, -30038, -29957, -29875, -29792, -29707, -29622, -29535, + -29448, -29359, -29269, -29178, -29086, -28993, -28899, -28804, -28707, -28610, -28511, + -28411, -28311, -28209, -28106, -28002, -27897, -27791, -27684, -27576, -27467, -27357, + -27246, -27133, -27020, -26906, -26791, -26674, -26557, -26439, -26320, -26199, -26078, + -25956, -25833, -25708, -25583, -25457, -25330, -25202, -25073, -24943, -24812, -24681, + -24548, -24414, -24280, -24144, -24008, -23870, -23732, -23593, -23453, -23312, -23171, + -23028, -22885, -22740, -22595, -22449, -22302, -22154, -22006, -21856, -21706, -21555, + -21403, -21251, -21097, -20943, -20788, -20632, -20476, -20318, -20160, -20001, -19842, + -19681, -19520, -19358, -19196, -19032, -18868, -18704, -18538, -18372, -18205, -18038, + -17869, -17701, -17531, -17361, -17190, -17018, -16846, -16674, -16500, -16326, -16152, + -15976, -15800, -15624, -15447, -15269, -15091, -14912, -14733, -14553, -14373, -14192, + -14010, -13828, -13646, -13463, -13279, -13095, -12911, -12726, -12540, -12354, -12168, + -11981, -11793, -11606, -11417, -11229, -11040, -10850, -10660, -10470, -10279, -10088, + -9896, -9705, -9512, -9320, -9127, -8934, -8740, -8546, -8352, -8157, -7962, -7767, + -7572, -7376, -7180, -6984, -6787, -6590, -6393, -6196, -5998, -5800, -5602, -5404, + -5206, -5007, -4808, -4610, -4410, -4211, -4012, -3812, -3612, -3412, -3212, -3012, + -2812, -2611, -2411, -2210, -2010, -1809, -1608, -1407, -1207, -1006, -805, -604, + -403, -202 }; + +#endif/*__SINE_TABLE_I16_H__*/ diff --git a/firmware/common/sine_table_int8.hpp b/firmware/common/sine_table_int8.hpp index 828b6db5..0583fa67 100644 --- a/firmware/common/sine_table_int8.hpp +++ b/firmware/common/sine_table_int8.hpp @@ -44,4 +44,5 @@ static const int8_t sine_table_i8[256] = { -49, -46, -43, -40, -37, -34, -31, -28, -25, -22, -19, -16, -13, -9, -6, -3 }; + #endif/*__SINE_TABLE_I8_H__*/ From c2dc7d1cf58d424d3ea4f03d7d0d9683e27f3fff Mon Sep 17 00:00:00 2001 From: teixeluis Date: Fri, 11 Jun 2021 00:13:56 +0100 Subject: [PATCH 3/5] Slight improvement of the tone generator. --- firmware/application/ui/ui_rssi.cpp | 3 +- firmware/baseband/proc_sonde.cpp | 51 ++++++++++++++-------------- firmware/baseband/proc_sonde.hpp | 19 +++++++---- firmware/baseband/tone_gen.cpp | 41 ++++++++++++++++++++-- firmware/baseband/tone_gen.hpp | 21 +++++++++++- firmware/common/sine_table_int16.hpp | 2 +- 6 files changed, 99 insertions(+), 38 deletions(-) diff --git a/firmware/application/ui/ui_rssi.cpp b/firmware/application/ui/ui_rssi.cpp index ce6acd9a..84487b16 100644 --- a/firmware/application/ui/ui_rssi.cpp +++ b/firmware/application/ui/ui_rssi.cpp @@ -76,8 +76,7 @@ void RSSI::paint(Painter& painter) { ); if (pitch_rssi_enabled) { - //baseband::set_pitch_rssi((avg_ - raw_min) * 2000 / raw_delta, true); - baseband::set_pitch_rssi((min_ - raw_min) * 2000 / raw_delta, true); + baseband::set_pitch_rssi((avg_ - raw_min) * 2000 / raw_delta, true); } } diff --git a/firmware/baseband/proc_sonde.cpp b/firmware/baseband/proc_sonde.cpp index d967dbb3..b7397a31 100644 --- a/firmware/baseband/proc_sonde.cpp +++ b/firmware/baseband/proc_sonde.cpp @@ -34,6 +34,8 @@ SondeProcessor::SondeProcessor() { decim_1.configure(taps_11k0_decim_1.taps, 131072); audio_output.configure(false); + + tone_gen.configure(0, 1, ToneGen::tone_type::square); } void SondeProcessor::execute(const buffer_c8_t& buffer) { @@ -53,11 +55,21 @@ void SondeProcessor::execute(const buffer_c8_t& buffer) { } } - if(pitch_rssi_enabled && beep_playing) { - generate_beep(); - } - else { - generate_silence(); + if(pitch_rssi_enabled) { + if(beep_play) { + // if we let the buffer underrun, for some reason + // once it starts looping it ignores zero (silence) + // samples, so we need to keep feeding the buffer + // and not be able to take advantage of the circular + // buffer loop: + //beep_play = false; + generate_beep(); + } + + if(silence_play) { + //silence_play = false; + generate_silence(); + } } } @@ -66,7 +78,7 @@ void SondeProcessor::on_message(const Message* const msg) { case Message::ID::RequestSignal: if ((*reinterpret_cast(msg)).signal == RequestSignalMessage::Signal::BeepRequest) { play_beep(); - chThdSleepMilliseconds(100); + chThdSleepMilliseconds(150); stop_beep(); } break; @@ -81,31 +93,20 @@ void SondeProcessor::on_message(const Message* const msg) { } void SondeProcessor::play_beep() { - beep_playing = true; + beep_play = true; + silence_play = false; } void SondeProcessor::stop_beep() { - beep_playing = false; + beep_play = false; + silence_play = true; } void SondeProcessor::generate_beep() { - // if(curr_sample == sizeof(audio_buffer.p)) { - // audio_output.write(audio_buffer); - // curr_sample = 0; - // //tone_phase = 0; - // } - // else if(beep_playing) { - // audio_buffer.p[curr_sample++] = (sine_table_i16[(tone_phase & 0xFF000000U) >> 24]); - // tone_phase += tone_delta; - // } - // else { - // audio_buffer.p[curr_sample++] = 0; - // tone_phase = 0; - // } + // here we let the samples be created using the ToneGen class: for(uint8_t i = 0; i < sizeof(audio_buffer.p); i++) { - audio_buffer.p[i] = (sine_table_i16_1024[(tone_phase & 0xFFC00000U) >> 22]); - tone_phase += tone_delta; + audio_buffer.p[i] = (int16_t) ((tone_gen.process(0) >> 16) & 0x0000FFFF); } audio_output.write(audio_buffer); @@ -114,7 +115,6 @@ void SondeProcessor::generate_beep() { void SondeProcessor::generate_silence() { for(uint8_t i = 0; i < sizeof(audio_buffer.p); i++) { audio_buffer.p[i] = 0; - tone_phase = 0; } audio_output.write(audio_buffer); @@ -122,7 +122,8 @@ void SondeProcessor::generate_silence() { void SondeProcessor::pitch_rssi_config(const PitchRSSIConfigureMessage& message) { pitch_rssi_enabled = message.enabled; - tone_delta = (message.rssi + 1000) * ((1ULL << 32) / 24000); + uint32_t tone_delta = (message.rssi + 1000) * ((1ULL << 32) / 24000); + tone_gen.configure(tone_delta, 1.0, ToneGen::tone_type::square); } int main() { diff --git a/firmware/baseband/proc_sonde.hpp b/firmware/baseband/proc_sonde.hpp index 1662440c..108c4066 100644 --- a/firmware/baseband/proc_sonde.hpp +++ b/firmware/baseband/proc_sonde.hpp @@ -90,8 +90,6 @@ #include "audio_output.hpp" #include "tone_gen.hpp" -#include "tonesets.hpp" -#include "sine_table_int16.hpp" #include "buffer.hpp" @@ -108,7 +106,6 @@ public: private: static constexpr size_t baseband_fs = 2457600; - static constexpr size_t beep_iterations = 60; std::array audio { }; @@ -119,12 +116,11 @@ private: AudioOutput audio_output { }; - bool beep_playing { false }; + bool beep_play { false }; + bool silence_play { false }; bool pitch_rssi_enabled { false }; - uint32_t tone_delta { 0 }; - uint32_t tone_phase { 0 }; - uint8_t curr_sample { 0 }; + ToneGen tone_gen { }; BasebandThread baseband_thread { baseband_fs, this, NORMALPRIO + 20, baseband::Direction::Receive }; RSSIThread rssi_thread { NORMALPRIO + 10 }; @@ -178,7 +174,16 @@ private: void play_beep(); void stop_beep(); + /** + * Used for filling the audio buffer with the waveform + * generated by the ToneGen class: + * + */ void generate_beep(); + + /** + * Used for filling the audio buffer with silence: + */ void generate_silence(); void pitch_rssi_config(const PitchRSSIConfigureMessage& message); diff --git a/firmware/baseband/tone_gen.cpp b/firmware/baseband/tone_gen.cpp index bbe5587e..d2185f53 100644 --- a/firmware/baseband/tone_gen.cpp +++ b/firmware/baseband/tone_gen.cpp @@ -23,18 +23,55 @@ #include "tone_gen.hpp" #include "sine_table_int8.hpp" + +int32_t ToneGen::tone_from_sine_table() { + int32_t tone_sample = sine_table_i8[(tone_phase_ & 0xFF000000U) >> 24] << 24; + tone_phase_ += delta_; + + return tone_sample; +} + +int32_t ToneGen::tone_square() { + int32_t tone_sample = 0; + + if(tone_phase_ < (UINT32_MAX / 2)) { + tone_sample = INT32_MAX; + } + else { + tone_sample = INT32_MIN; + } + + tone_phase_ += delta_; + + return tone_sample; +} + void ToneGen::configure(const uint32_t delta, const float tone_mix_weight) { delta_ = delta; tone_mix_weight_ = tone_mix_weight; input_mix_weight_ = 1.0 - tone_mix_weight; + current_tone_type_ = sine; +} + +void ToneGen::configure(const uint32_t delta, const float tone_mix_weight, const tone_type tone_type) { + delta_ = delta; + tone_mix_weight_ = tone_mix_weight; + input_mix_weight_ = 1.0 - tone_mix_weight; + current_tone_type_ = tone_type; } int32_t ToneGen::process(const int32_t sample_in) { if (!delta_) return sample_in; - int32_t tone_sample = sine_table_i8[(tone_phase_ & 0xFF000000U) >> 24]; - tone_phase_ += delta_; + int32_t tone_sample = 0; + + if(current_tone_type_ == sine) { + tone_sample = tone_from_sine_table(); + } + else if(current_tone_type_ == square) { + tone_sample = tone_square(); + } return (sample_in * input_mix_weight_) + (tone_sample * tone_mix_weight_); } diff --git a/firmware/baseband/tone_gen.hpp b/firmware/baseband/tone_gen.hpp index ef547f26..d12782c1 100644 --- a/firmware/baseband/tone_gen.hpp +++ b/firmware/baseband/tone_gen.hpp @@ -25,22 +25,41 @@ #include #include +#include + +static const std::bitset<2048> wave_bits (0xFFFFFF); class ToneGen { public: + enum tone_type { sine, square }; + /*ToneGen(const size_t sample_rate ) : sample_rate_ { sample_rate } {};*/ void configure(const uint32_t delta, const float tone_mix_weight); + void configure(const uint32_t delta, const float tone_mix_weight, const tone_type tone_type); + int32_t process(const int32_t sample_in); private: + tone_type current_tone_type_ { sine }; + //size_t sample_rate_; float input_mix_weight_ { 1 }; float tone_mix_weight_ { 0 }; uint32_t delta_ { 0 }; uint32_t tone_phase_ { 0 }; + + /** + * Generator function for sine waves: + */ + int32_t tone_from_sine_table(); + + /** + * Generator function for square waves: + */ + int32_t tone_square(); }; -#endif +#endif /* __TONE_GEN_H__ */ diff --git a/firmware/common/sine_table_int16.hpp b/firmware/common/sine_table_int16.hpp index b0dda364..0909a75c 100644 --- a/firmware/common/sine_table_int16.hpp +++ b/firmware/common/sine_table_int16.hpp @@ -25,7 +25,7 @@ #include -static const int16_t sine_table_i16[256] = { 0, 804, 1607, 2410, 3211, 4011, 4807, +static const int16_t sine_table_i16_256[256] = { 0, 804, 1607, 2410, 3211, 4011, 4807, 5601, 6392, 7179, 7961, 8739, 9511, 10278, 11039, 11792, 12539, 13278, 14009, 14732, 15446, 16151, 16845, 17530, 18204, 18867, 19519, 20159, 20787, 21402, 22005, 22594, 23170, 23731, 24279, 24811, 25329, 25832, 26319, 26790, 27245, 27683, 28105, 28510, From 43e123bafe99a0e60b9e43e6a646ae57e2a0399a Mon Sep 17 00:00:00 2001 From: teixeluis Date: Fri, 11 Jun 2021 00:25:24 +0100 Subject: [PATCH 4/5] Used temporarily for experimental purposes, no longer needed. --- firmware/common/sine_table_int16.hpp | 138 --------------------------- 1 file changed, 138 deletions(-) delete mode 100644 firmware/common/sine_table_int16.hpp diff --git a/firmware/common/sine_table_int16.hpp b/firmware/common/sine_table_int16.hpp deleted file mode 100644 index 0909a75c..00000000 --- a/firmware/common/sine_table_int16.hpp +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc. - * Copyright (C) 2016 Furrtek - * - * This file is part of PortaPack. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING.If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifndef __SINE_TABLE_I16_H__ -#define __SINE_TABLE_I16_H__ - -#include - -static const int16_t sine_table_i16_256[256] = { 0, 804, 1607, 2410, 3211, 4011, 4807, - 5601, 6392, 7179, 7961, 8739, 9511, 10278, 11039, 11792, 12539, 13278, 14009, 14732, - 15446, 16151, 16845, 17530, 18204, 18867, 19519, 20159, 20787, 21402, 22005, 22594, - 23170, 23731, 24279, 24811, 25329, 25832, 26319, 26790, 27245, 27683, 28105, 28510, - 28898, 29268, 29621, 29956, 30273, 30571, 30852, 31113, 31356, 31580, 31785, 31971, - 32137, 32285, 32412, 32521, 32609, 32678, 32728, 32757, 32767, 32757, 32728, 32678, - 32609, 32521, 32412, 32285, 32137, 31971, 31785, 31580, 31356, 31113, 30852, 30571, - 30273, 29956, 29621, 29268, 28898, 28510, 28105, 27683, 27245, 26790, 26319, 25832, - 25329, 24811, 24279, 23731, 23170, 22594, 22005, 21402, 20787, 20159, 19519, 18867, - 18204, 17530, 16845, 16151, 15446, 14732, 14009, 13278, 12539, 11792, 11039, 10278, - 9511, 8739, 7961, 7179, 6392, 5601, 4807, 4011, 3211, 2410, 1607, 804, 0, -805, -1608, - -2411, -3212, -4012, -4808, -5602, -6393, -7180, -7962, -8740, -9512, -10279, -11040, - -11793, -12540, -13279, -14010, -14733, -15447, -16152, -16846, -17531, -18205, -18868, - -19520, -20160, -20788, -21403, -22006, -22595, -23171, -23732, -24280, -24812, -25330, - -25833, -26320, -26791, -27246, -27684, -28106, -28511, -28899, -29269, -29622, -29957, - -30274, -30572, -30853, -31114, -31357, -31581, -31786, -31972, -32138, -32286, -32413, - -32522, -32610, -32679, -32729, -32758, -32768, -32758, -32729, -32679, -32610, -32522, - -32413, -32286, -32138, -31972, -31786, -31581, -31357, -31114, -30853, -30572, -30274, - -29957, -29622, -29269, -28899, -28511, -28106, -27684, -27246, -26791, -26320, -25833, - -25330, -24812, -24280, -23732, -23171, -22595, -22006, -21403, -20788, -20160, -19520, - -18868, -18205, -17531, -16846, -16152, -15447, -14733, -14010, -13279, -12540, -11793, - -11040, -10279, -9512, -8740, -7962, -7180, -6393, -5602, -4808, -4012, -3212, -2411, - -1608, -805 }; - -static const int16_t sine_table_i16_1024[1024] = {0, 201, 402, 603, 804, 1005, 1206, 1406, - 1607, 1808, 2009, 2209, 2410, 2610, 2811, 3011, 3211, 3411, 3611, 3811, 4011, 4210, 4409, - 4609, 4807, 5006, 5205, 5403, 5601, 5799, 5997, 6195, 6392, 6589, 6786, 6983, 7179, 7375, - 7571, 7766, 7961, 8156, 8351, 8545, 8739, 8933, 9126, 9319, 9511, 9704, 9895, 10087, 10278, - 10469, 10659, 10849, 11039, 11228, 11416, 11605, 11792, 11980, 12167, 12353, 12539, 12725, - 12910, 13094, 13278, 13462, 13645, 13827, 14009, 14191, 14372, 14552, 14732, 14911, 15090, - 15268, 15446, 15623, 15799, 15975, 16151, 16325, 16499, 16673, 16845, 17017, 17189, 17360, - 17530, 17700, 17868, 18037, 18204, 18371, 18537, 18703, 18867, 19031, 19195, 19357, 19519, - 19680, 19841, 20000, 20159, 20317, 20475, 20631, 20787, 20942, 21096, 21250, 21402, 21554, - 21705, 21855, 22005, 22153, 22301, 22448, 22594, 22739, 22884, 23027, 23170, 23311, 23452, - 23592, 23731, 23869, 24007, 24143, 24279, 24413, 24547, 24680, 24811, 24942, 25072, 25201, - 25329, 25456, 25582, 25707, 25832, 25955, 26077, 26198, 26319, 26438, 26556, 26673, 26790, - 26905, 27019, 27132, 27245, 27356, 27466, 27575, 27683, 27790, 27896, 28001, 28105, 28208, - 28310, 28410, 28510, 28609, 28706, 28803, 28898, 28992, 29085, 29177, 29268, 29358, 29447, - 29534, 29621, 29706, 29791, 29874, 29956, 30037, 30117, 30195, 30273, 30349, 30424, 30498, - 30571, 30643, 30714, 30783, 30852, 30919, 30985, 31050, 31113, 31176, 31237, 31297, 31356, - 31414, 31470, 31526, 31580, 31633, 31685, 31736, 31785, 31833, 31880, 31926, 31971, 32014, - 32057, 32098, 32137, 32176, 32213, 32250, 32285, 32318, 32351, 32382, 32412, 32441, 32469, - 32495, 32521, 32545, 32567, 32589, 32609, 32628, 32646, 32663, 32678, 32692, 32705, 32717, - 32728, 32737, 32745, 32752, 32757, 32761, 32765, 32766, 32767, 32766, 32765, 32761, 32757, - 32752, 32745, 32737, 32728, 32717, 32705, 32692, 32678, 32663, 32646, 32628, 32609, 32589, - 32567, 32545, 32521, 32495, 32469, 32441, 32412, 32382, 32351, 32318, 32285, 32250, 32213, - 32176, 32137, 32098, 32057, 32014, 31971, 31926, 31880, 31833, 31785, 31736, 31685, 31633, - 31580, 31526, 31470, 31414, 31356, 31297, 31237, 31176, 31113, 31050, 30985, 30919, 30852, - 30783, 30714, 30643, 30571, 30498, 30424, 30349, 30273, 30195, 30117, 30037, 29956, 29874, - 29791, 29706, 29621, 29534, 29447, 29358, 29268, 29177, 29085, 28992, 28898, 28803, 28706, - 28609, 28510, 28410, 28310, 28208, 28105, 28001, 27896, 27790, 27683, 27575, 27466, 27356, - 27245, 27132, 27019, 26905, 26790, 26673, 26556, 26438, 26319, 26198, 26077, 25955, 25832, - 25707, 25582, 25456, 25329, 25201, 25072, 24942, 24811, 24680, 24547, 24413, 24279, 24143, - 24007, 23869, 23731, 23592, 23452, 23311, 23170, 23027, 22884, 22739, 22594, 22448, 22301, - 22153, 22005, 21855, 21705, 21554, 21402, 21250, 21096, 20942, 20787, 20631, 20475, 20317, - 20159, 20000, 19841, 19680, 19519, 19357, 19195, 19031, 18867, 18703, 18537, 18371, 18204, - 18037, 17868, 17700, 17530, 17360, 17189, 17017, 16845, 16673, 16499, 16325, 16151, 15975, - 15799, 15623, 15446, 15268, 15090, 14911, 14732, 14552, 14372, 14191, 14009, 13827, 13645, - 13462, 13278, 13094, 12910, 12725, 12539, 12353, 12167, 11980, 11792, 11605, 11416, 11228, - 11039, 10849, 10659, 10469, 10278, 10087, 9895, 9704, 9511, 9319, 9126, 8933, 8739, 8545, - 8351, 8156, 7961, 7766, 7571, 7375, 7179, 6983, 6786, 6589, 6392, 6195, 5997, 5799, 5601, - 5403, 5205, 5006, 4807, 4609, 4409, 4210, 4011, 3811, 3611, 3411, 3211, 3011, 2811, 2610, - 2410, 2209, 2009, 1808, 1607, 1406, 1206, 1005, 804, 603, 402, 201, 0, -202, -403, -604, - -805, -1006, -1207, -1407, -1608, -1809, -2010, -2210, -2411, -2611, -2812, -3012, -3212, - -3412, -3612, -3812, -4012, -4211, -4410, -4610, -4808, -5007, -5206, -5404, -5602, -5800, - -5998, -6196, -6393, -6590, -6787, -6984, -7180, -7376, -7572, -7767, -7962, -8157, -8352, - -8546, -8740, -8934, -9127, -9320, -9512, -9705, -9896, -10088, -10279, -10470, -10660, - -10850, -11040, -11229, -11417, -11606, -11793, -11981, -12168, -12354, -12540, -12726, - -12911, -13095, -13279, -13463, -13646, -13828, -14010, -14192, -14373, -14553, -14733, - -14912, -15091, -15269, -15447, -15624, -15800, -15976, -16152, -16326, -16500, -16674, - -16846, -17018, -17190, -17361, -17531, -17701, -17869, -18038, -18205, -18372, -18538, - -18704, -18868, -19032, -19196, -19358, -19520, -19681, -19842, -20001, -20160, -20318, - -20476, -20632, -20788, -20943, -21097, -21251, -21403, -21555, -21706, -21856, -22006, - -22154, -22302, -22449, -22595, -22740, -22885, -23028, -23171, -23312, -23453, -23593, - -23732, -23870, -24008, -24144, -24280, -24414, -24548, -24681, -24812, -24943, -25073, - -25202, -25330, -25457, -25583, -25708, -25833, -25956, -26078, -26199, -26320, -26439, - -26557, -26674, -26791, -26906, -27020, -27133, -27246, -27357, -27467, -27576, -27684, - -27791, -27897, -28002, -28106, -28209, -28311, -28411, -28511, -28610, -28707, -28804, - -28899, -28993, -29086, -29178, -29269, -29359, -29448, -29535, -29622, -29707, -29792, - -29875, -29957, -30038, -30118, -30196, -30274, -30350, -30425, -30499, -30572, -30644, - -30715, -30784, -30853, -30920, -30986, -31051, -31114, -31177, -31238, -31298, -31357, - -31415, -31471, -31527, -31581, -31634, -31686, -31737, -31786, -31834, -31881, -31927, - -31972, -32015, -32058, -32099, -32138, -32177, -32214, -32251, -32286, -32319, -32352, - -32383, -32413, -32442, -32470, -32496, -32522, -32546, -32568, -32590, -32610, -32629, - -32647, -32664, -32679, -32693, -32706, -32718, -32729, -32738, -32746, -32753, -32758, - -32762, -32766, -32767, -32768, -32767, -32766, -32762, -32758, -32753, -32746, -32738, - -32729, -32718, -32706, -32693, -32679, -32664, -32647, -32629, -32610, -32590, -32568, - -32546, -32522, -32496, -32470, -32442, -32413, -32383, -32352, -32319, -32286, -32251, - -32214, -32177, -32138, -32099, -32058, -32015, -31972, -31927, -31881, -31834, -31786, - -31737, -31686, -31634, -31581, -31527, -31471, -31415, -31357, -31298, -31238, -31177, - -31114, -31051, -30986, -30920, -30853, -30784, -30715, -30644, -30572, -30499, -30425, - -30350, -30274, -30196, -30118, -30038, -29957, -29875, -29792, -29707, -29622, -29535, - -29448, -29359, -29269, -29178, -29086, -28993, -28899, -28804, -28707, -28610, -28511, - -28411, -28311, -28209, -28106, -28002, -27897, -27791, -27684, -27576, -27467, -27357, - -27246, -27133, -27020, -26906, -26791, -26674, -26557, -26439, -26320, -26199, -26078, - -25956, -25833, -25708, -25583, -25457, -25330, -25202, -25073, -24943, -24812, -24681, - -24548, -24414, -24280, -24144, -24008, -23870, -23732, -23593, -23453, -23312, -23171, - -23028, -22885, -22740, -22595, -22449, -22302, -22154, -22006, -21856, -21706, -21555, - -21403, -21251, -21097, -20943, -20788, -20632, -20476, -20318, -20160, -20001, -19842, - -19681, -19520, -19358, -19196, -19032, -18868, -18704, -18538, -18372, -18205, -18038, - -17869, -17701, -17531, -17361, -17190, -17018, -16846, -16674, -16500, -16326, -16152, - -15976, -15800, -15624, -15447, -15269, -15091, -14912, -14733, -14553, -14373, -14192, - -14010, -13828, -13646, -13463, -13279, -13095, -12911, -12726, -12540, -12354, -12168, - -11981, -11793, -11606, -11417, -11229, -11040, -10850, -10660, -10470, -10279, -10088, - -9896, -9705, -9512, -9320, -9127, -8934, -8740, -8546, -8352, -8157, -7962, -7767, - -7572, -7376, -7180, -6984, -6787, -6590, -6393, -6196, -5998, -5800, -5602, -5404, - -5206, -5007, -4808, -4610, -4410, -4211, -4012, -3812, -3612, -3412, -3212, -3012, - -2812, -2611, -2411, -2210, -2010, -1809, -1608, -1407, -1207, -1006, -805, -604, - -403, -202 }; - -#endif/*__SINE_TABLE_I16_H__*/ From a80d91fb1eb72d829eb781a0077a82f0bf52b632 Mon Sep 17 00:00:00 2001 From: teixeluis Date: Sun, 13 Jun 2021 23:35:33 +0100 Subject: [PATCH 5/5] More improvements to the rssi tone. Added saving of the tuned frequency to the radio model persistent store. --- firmware/application/apps/ui_sonde.cpp | 7 ++++++- firmware/application/apps/ui_sonde.hpp | 8 -------- firmware/baseband/proc_sonde.cpp | 18 ++++++++++++++++-- firmware/baseband/proc_sonde.hpp | 9 +++++++++ 4 files changed, 31 insertions(+), 11 deletions(-) diff --git a/firmware/application/apps/ui_sonde.cpp b/firmware/application/apps/ui_sonde.cpp index 28796cd7..419ad579 100644 --- a/firmware/application/apps/ui_sonde.cpp +++ b/firmware/application/apps/ui_sonde.cpp @@ -66,6 +66,9 @@ SondeView::SondeView(NavigationView& nav) { &button_see_map }); + // start from the frequency currently stored in the receiver_model: + target_frequency_ = receiver_model.tuning_frequency(); + field_frequency.set_value(target_frequency_); field_frequency.set_step(500); //euquiq: was 10000, but we are using this for fine-tunning field_frequency.on_change = [this](rf::Frequency f) { @@ -206,7 +209,9 @@ void SondeView::on_headphone_volume_changed(int32_t v) { void SondeView::set_target_frequency(const uint32_t new_value) { target_frequency_ = new_value; - radio::set_tuning_frequency(tuning_frequency()); + //radio::set_tuning_frequency(tuning_frequency()); + // we better remember the tuned frequency, by using this function instead: + receiver_model.set_tuning_frequency(tuning_frequency()); } uint32_t SondeView::tuning_frequency() const { diff --git a/firmware/application/apps/ui_sonde.hpp b/firmware/application/apps/ui_sonde.hpp index 73591eb3..afc2bbec 100644 --- a/firmware/application/apps/ui_sonde.hpp +++ b/firmware/application/apps/ui_sonde.hpp @@ -55,14 +55,6 @@ class SondeView : public View { public: static constexpr uint32_t sampling_rate = 2457600; static constexpr uint32_t baseband_bandwidth = 1750000; - static constexpr int rssi_sample_range = 256; - static constexpr float rssi_voltage_min = 0.4; - static constexpr float rssi_voltage_max = 2.2; - static constexpr float adc_voltage_max = 3.3; - - static constexpr int raw_min = rssi_sample_range * rssi_voltage_min / adc_voltage_max; - static constexpr int raw_max = rssi_sample_range * rssi_voltage_max / adc_voltage_max; - static constexpr int raw_delta = raw_max - raw_min; SondeView(NavigationView& nav); ~SondeView(); diff --git a/firmware/baseband/proc_sonde.cpp b/firmware/baseband/proc_sonde.cpp index b7397a31..d956372f 100644 --- a/firmware/baseband/proc_sonde.cpp +++ b/firmware/baseband/proc_sonde.cpp @@ -77,8 +77,21 @@ void SondeProcessor::on_message(const Message* const msg) { switch(msg->id) { case Message::ID::RequestSignal: if ((*reinterpret_cast(msg)).signal == RequestSignalMessage::Signal::BeepRequest) { + float rssi_ratio = (float) last_rssi / (float) RSSI_CEILING; + int beep_duration = 0; + + if(rssi_ratio <= PROPORTIONAL_BEEP_THRES) { + beep_duration = BEEP_MIN_DURATION; + } + else if(rssi_ratio < 1) { + beep_duration = (int) rssi_ratio * BEEP_DURATION_RANGE + BEEP_MIN_DURATION; + } + else { + beep_duration = BEEP_DURATION_RANGE + BEEP_MIN_DURATION; + } + play_beep(); - chThdSleepMilliseconds(150); + chThdSleepMilliseconds(beep_duration); stop_beep(); } break; @@ -122,7 +135,8 @@ void SondeProcessor::generate_silence() { void SondeProcessor::pitch_rssi_config(const PitchRSSIConfigureMessage& message) { pitch_rssi_enabled = message.enabled; - uint32_t tone_delta = (message.rssi + 1000) * ((1ULL << 32) / 24000); + uint32_t tone_delta = (int) ((float) message.rssi * (float) RSSI_PITCH_WEIGHT + (float) 1000) * ((float) (1ULL << 32) / (float) 24000); + last_rssi = message.rssi; tone_gen.configure(tone_delta, 1.0, ToneGen::tone_type::square); } diff --git a/firmware/baseband/proc_sonde.hpp b/firmware/baseband/proc_sonde.hpp index 108c4066..fcf4d20b 100644 --- a/firmware/baseband/proc_sonde.hpp +++ b/firmware/baseband/proc_sonde.hpp @@ -97,6 +97,13 @@ #include #include + +#define BEEP_MIN_DURATION 80 +#define BEEP_DURATION_RANGE 150 +#define RSSI_CEILING 1000 +#define PROPORTIONAL_BEEP_THRES 0.8 +#define RSSI_PITCH_WEIGHT 0.7 + class SondeProcessor : public BasebandProcessor { public: SondeProcessor(); @@ -120,6 +127,8 @@ private: bool silence_play { false }; bool pitch_rssi_enabled { false }; + uint32_t last_rssi { 0 }; + ToneGen tone_gen { }; BasebandThread baseband_thread { baseband_fs, this, NORMALPRIO + 20, baseband::Direction::Receive };