More debug Audio Beep Test tweaks (#2028)

This commit is contained in:
Mark Thompson 2024-03-23 13:25:36 -05:00 committed by GitHub
parent 28a5fc5915
commit 81e24d582d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 41 additions and 12 deletions

View File

@ -35,39 +35,51 @@ AudioTestView::AudioTestView(NavigationView& nav)
add_children({&labels, add_children({&labels,
&options_sample_rate, &options_sample_rate,
&field_frequency, &field_frequency,
&options_step,
&field_duration, &field_duration,
&field_volume, &field_volume,
&toggle_speaker}); &toggle_speaker});
audio::set_rate(audio::Rate::Hz_24000); audio::set_rate(audio::Rate::Hz_24000);
options_sample_rate.on_change = [this](size_t, int32_t v) { options_sample_rate.on_change = [this](size_t, int32_t v) {
if (options_sample_rate.selected_index_value() == 24000) { switch (v) {
case 12000:
audio::set_rate(audio::Rate::Hz_12000);
break;
case 24000:
audio::set_rate(audio::Rate::Hz_24000); audio::set_rate(audio::Rate::Hz_24000);
field_frequency.set_range(100, v / 2); // 24000/128 = ~100 (audio_dma uses 128 samples) break;
} else { case 48000:
audio::set_rate(audio::Rate::Hz_48000); audio::set_rate(audio::Rate::Hz_48000);
field_frequency.set_range(200, v / 2); // 48000/128 = ~200 break;
} }
field_frequency.set_range(v / 128, v / 2);
update_audio_beep(); update_audio_beep();
}; };
options_sample_rate.set_selected_index(0, 1);
field_frequency.set_value(1000);
field_frequency.on_change = [this](int32_t) { field_frequency.on_change = [this](int32_t) {
update_audio_beep(); update_audio_beep();
}; };
field_frequency.set_value(1000);
options_step.on_change = [this](size_t, int32_t v) {
field_frequency.set_step(v);
};
options_step.set_by_value(100);
field_duration.set_value(100);
field_duration.on_change = [this](int32_t v) { field_duration.on_change = [this](int32_t v) {
(void)v; (void)v;
update_audio_beep(); update_audio_beep();
}; };
field_duration.set_value(100);
toggle_speaker.on_change = [this](bool v) { toggle_speaker.on_change = [this](bool v) {
beep = v; beep = v;
update_audio_beep(); update_audio_beep();
}; };
field_volume.set_value(0); field_volume.set_value(0); // seems that a change is required to force update, so setting to 0 first
field_volume.set_value(80); field_volume.set_value(80);
audio::set_rate(audio::Rate::Hz_24000); audio::set_rate(audio::Rate::Hz_24000);

View File

@ -46,20 +46,31 @@ class AudioTestView : public View {
Labels labels{ Labels labels{
{{7 * 8, 3 * 16}, "Audio Beep Test", Color::light_grey()}, {{7 * 8, 3 * 16}, "Audio Beep Test", Color::light_grey()},
{{0 * 8, 6 * 16}, "Sample Rate (Hz):", Color::light_grey()}, {{0 * 8, 6 * 16}, "Sample Rate (Hz):", Color::light_grey()},
{{25 * 8, 7 * 16}, "Step:", Color::light_grey()},
{{0 * 8, 8 * 16}, "Frequency (Hz):", Color::light_grey()}, {{0 * 8, 8 * 16}, "Frequency (Hz):", Color::light_grey()},
{{0 * 8, 10 * 16}, "Duration (ms):", Color::light_grey()}, {{0 * 8, 10 * 16}, "Duration (ms):", Color::light_grey()},
{{25 * 8, 10 * 16}, "0=con", Color::light_grey()},
{{0 * 8, 12 * 16}, "Volume:", Color::light_grey()}}; {{0 * 8, 12 * 16}, "Volume:", Color::light_grey()}};
OptionsField options_sample_rate{ OptionsField options_sample_rate{
{18 * 8, 6 * 16}, {18 * 8, 6 * 16},
5, 5,
{{"24000", 24000}, {{"24000", 24000},
{"48000", 48000}}}; {"48000", 48000},
{"12000", 12000}}};
OptionsField options_step{
{26 * 8, 8 * 16},
4,
{{" 1", 1},
{" 10", 10},
{" 100", 100},
{"1000", 1000}}};
NumberField field_frequency{ NumberField field_frequency{
{18 * 8, 8 * 16}, {18 * 8, 8 * 16},
5, 5,
{100, 24000 / 2}, {},
100, 100,
' ', ' ',
true}; true};

View File

@ -27,7 +27,13 @@
// Functions for audio beep (used by Sonde RSSI) // Functions for audio beep (used by Sonde RSSI)
void ToneGen::configure_beep(const uint32_t freq, const uint32_t sample_rate) { void ToneGen::configure_beep(const uint32_t freq, const uint32_t sample_rate) {
f_delta_ = (float)(freq * sizeof(sine_table_i8)) / sample_rate; f_delta_ = (float)(freq * sizeof(sine_table_i8)) / sample_rate;
f_tone_phase_ = sizeof(sine_table_i8) / 4; // Start at sine peak to handle case of freq=sample_rate/2 f_tone_phase_ = 0.0;
// For higher frequencies, start at sine peak to handle case of freq=sample_rate/2;
// we don't want to sample the sine wave only when it's crossing 0!
// There is still an amplitude issue though depending on magnitude of selected sine sample deltas.
if (f_delta_ >= sizeof(sine_table_i8) / 4)
f_tone_phase_ = sizeof(sine_table_i8) / 4;
} }
int16_t ToneGen::process_beep() { int16_t ToneGen::process_beep() {