mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2025-08-21 12:17:35 +00:00
Improved tone generator for proper frequency control. Also
features a square wave mode. Added proportional beep duration based on the RSSI as well. Now reading the current radiosonde frequency from the battery backed RAM instead starting with the same frequency all the time.
This commit is contained in:
@@ -24,8 +24,8 @@
|
||||
#include "sine_table_int8.hpp"
|
||||
|
||||
|
||||
int32_t ToneGen::tone_from_sine_table() {
|
||||
int32_t tone_sample = sine_table_i8[(tone_phase_ & 0xFF000000U) >> 24] << 24;
|
||||
int32_t ToneGen::tone_sine() {
|
||||
int32_t tone_sample = sine_table_i8[tone_phase_] * 0x1000000;
|
||||
tone_phase_ += delta_;
|
||||
|
||||
return tone_sample;
|
||||
@@ -47,14 +47,15 @@ int32_t ToneGen::tone_square() {
|
||||
}
|
||||
|
||||
void ToneGen::configure(const uint32_t delta, const float tone_mix_weight) {
|
||||
delta_ = delta;
|
||||
delta_ = (uint8_t) ((delta & 0xFF000000U) >> 24);
|
||||
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;
|
||||
void ToneGen::configure(const uint32_t freq, const float tone_mix_weight, const tone_type tone_type, const uint32_t sample_rate) {
|
||||
delta_ = (uint8_t) ((freq * sizeof(sine_table_i8)) / sample_rate);
|
||||
tone_mix_weight_ = tone_mix_weight;
|
||||
input_mix_weight_ = 1.0 - tone_mix_weight;
|
||||
current_tone_type_ = tone_type;
|
||||
@@ -67,7 +68,7 @@ int32_t ToneGen::process(const int32_t sample_in) {
|
||||
int32_t tone_sample = 0;
|
||||
|
||||
if(current_tone_type_ == sine) {
|
||||
tone_sample = tone_from_sine_table();
|
||||
tone_sample = tone_sine();
|
||||
}
|
||||
else if(current_tone_type_ == square) {
|
||||
tone_sample = tone_square();
|
||||
|
Reference in New Issue
Block a user