mirror of
https://github.com/eried/portapack-mayhem.git
synced 2024-12-24 23:09:26 -05:00
Improved the pitch RSSI. Still looking for better approach.
This commit is contained in:
parent
c85e6a4d52
commit
edcd780402
@ -75,8 +75,10 @@ void RSSI::paint(Painter& painter) {
|
|||||||
Color::black()
|
Color::black()
|
||||||
);
|
);
|
||||||
|
|
||||||
if (pitch_rssi_enabled)
|
if (pitch_rssi_enabled) {
|
||||||
baseband::set_pitch_rssi((avg_ - raw_min) * 2000 / raw_delta, true);
|
//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) {
|
void RSSI::set_pitch_rssi(bool enabled) {
|
||||||
|
@ -53,13 +53,11 @@ void SondeProcessor::execute(const buffer_c8_t& buffer) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(pitch_rssi_enabled) {
|
if(pitch_rssi_enabled && beep_playing) {
|
||||||
if(beep_playing) {
|
generate_beep();
|
||||||
beep_loop();
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
silence_loop();
|
generate_silence();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,33 +88,41 @@ void SondeProcessor::stop_beep() {
|
|||||||
beep_playing = false;
|
beep_playing = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SondeProcessor::beep_loop() {
|
void SondeProcessor::generate_beep() {
|
||||||
for (size_t i = 0; i < sizeof(audio_buffer.p); i++) {
|
// if(curr_sample == sizeof(audio_buffer.p)) {
|
||||||
audio_buffer.p[i] = (sine_table_i8[(tone_phase & 0xFF000000U) >> 24]) * 128;
|
// 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;
|
tone_phase += tone_delta;
|
||||||
}
|
}
|
||||||
|
|
||||||
audio_output.write(audio_buffer);
|
audio_output.write(audio_buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SondeProcessor::silence_loop() {
|
void SondeProcessor::generate_silence() {
|
||||||
for (size_t i = 0; i < sizeof(audio_buffer.p); i++) {
|
for(uint8_t i = 0; i < sizeof(audio_buffer.p); i++) {
|
||||||
audio_buffer.p[i] = 0;
|
audio_buffer.p[i] = 0;
|
||||||
|
tone_phase = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
audio_output.write(audio_buffer);
|
audio_output.write(audio_buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SondeProcessor::pitch_rssi_config(const PitchRSSIConfigureMessage& message) {
|
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;
|
pitch_rssi_enabled = message.enabled;
|
||||||
tone_delta = (message.rssi + 1000) * ((1ULL << 32) / 24000);
|
tone_delta = (message.rssi + 1000) * ((1ULL << 32) / 24000);
|
||||||
|
|
||||||
// log_file.write_entry(datetime, "pitch_rssi_config: tone_delta: " + tone_delta);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
@ -91,7 +91,7 @@
|
|||||||
#include "audio_output.hpp"
|
#include "audio_output.hpp"
|
||||||
#include "tone_gen.hpp"
|
#include "tone_gen.hpp"
|
||||||
#include "tonesets.hpp"
|
#include "tonesets.hpp"
|
||||||
#include "sine_table_int8.hpp"
|
#include "sine_table_int16.hpp"
|
||||||
|
|
||||||
#include "buffer.hpp"
|
#include "buffer.hpp"
|
||||||
|
|
||||||
@ -110,7 +110,7 @@ private:
|
|||||||
static constexpr size_t baseband_fs = 2457600;
|
static constexpr size_t baseband_fs = 2457600;
|
||||||
static constexpr size_t beep_iterations = 60;
|
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 {
|
const buffer_s16_t audio_buffer {
|
||||||
(int16_t*) audio.data(),
|
(int16_t*) audio.data(),
|
||||||
@ -124,6 +124,7 @@ private:
|
|||||||
|
|
||||||
uint32_t tone_delta { 0 };
|
uint32_t tone_delta { 0 };
|
||||||
uint32_t tone_phase { 0 };
|
uint32_t tone_phase { 0 };
|
||||||
|
uint8_t curr_sample { 0 };
|
||||||
|
|
||||||
BasebandThread baseband_thread { baseband_fs, this, NORMALPRIO + 20, baseband::Direction::Receive };
|
BasebandThread baseband_thread { baseband_fs, this, NORMALPRIO + 20, baseband::Direction::Receive };
|
||||||
RSSIThread rssi_thread { NORMALPRIO + 10 };
|
RSSIThread rssi_thread { NORMALPRIO + 10 };
|
||||||
@ -177,8 +178,8 @@ private:
|
|||||||
void play_beep();
|
void play_beep();
|
||||||
void stop_beep();
|
void stop_beep();
|
||||||
|
|
||||||
void beep_loop();
|
void generate_beep();
|
||||||
void silence_loop();
|
void generate_silence();
|
||||||
|
|
||||||
void pitch_rssi_config(const PitchRSSIConfigureMessage& message);
|
void pitch_rssi_config(const PitchRSSIConfigureMessage& message);
|
||||||
};
|
};
|
||||||
|
138
firmware/common/sine_table_int16.hpp
Normal file
138
firmware/common/sine_table_int16.hpp
Normal file
@ -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 <cmath>
|
||||||
|
|
||||||
|
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__*/
|
@ -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
|
-49, -46, -43, -40, -37, -34, -31, -28, -25, -22, -19, -16, -13, -9, -6, -3
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif/*__SINE_TABLE_I8_H__*/
|
#endif/*__SINE_TABLE_I8_H__*/
|
||||||
|
Loading…
Reference in New Issue
Block a user