Improved the pitch RSSI. Still looking for better approach.

This commit is contained in:
teixeluis
2021-06-10 12:10:24 +01:00
parent c85e6a4d52
commit edcd780402
5 changed files with 174 additions and 26 deletions

View File

@@ -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() {

View File

@@ -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<int16_t, 16> audio { };
std::array<int16_t, 32> 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);
};