mirror of
https://github.com/eried/portapack-mayhem.git
synced 2024-12-24 23:09:26 -05:00
specan: cleared up terminology, accounted for decimation.
Channel spectrum decimation now accounted for when computing filter frequencies. Renamed a bunch of variables relating to channel spectrum bandwidth and filter frequencies.
This commit is contained in:
parent
98bd9c54e4
commit
ffc50785b7
@ -37,29 +37,29 @@ namespace spectrum {
|
|||||||
|
|
||||||
class FrequencyScale : public Widget {
|
class FrequencyScale : public Widget {
|
||||||
public:
|
public:
|
||||||
void set_spectrum_bandwidth(const uint32_t new_bandwidth, const size_t new_spectrum_bins) {
|
void set_spectrum_sampling_rate(const uint32_t new_sampling_rate, const size_t new_spectrum_bins) {
|
||||||
if( (spectrum_bandwidth != new_bandwidth) ||
|
if( (spectrum_sampling_rate != new_sampling_rate) ||
|
||||||
(spectrum_bins != new_spectrum_bins) ) {
|
(spectrum_bins != new_spectrum_bins) ) {
|
||||||
spectrum_bandwidth = new_bandwidth;
|
spectrum_sampling_rate = new_sampling_rate;
|
||||||
spectrum_bins = new_spectrum_bins;
|
spectrum_bins = new_spectrum_bins;
|
||||||
set_dirty();
|
set_dirty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_channel_filter(
|
void set_channel_filter(
|
||||||
const uint32_t pass_bandwidth,
|
const uint32_t pass_frequency,
|
||||||
const uint32_t stop_bandwidth
|
const uint32_t stop_frequency
|
||||||
) {
|
) {
|
||||||
if( (channel_filter_pass_bandwidth != pass_bandwidth) ||
|
if( (channel_filter_pass_frequency != pass_frequency) ||
|
||||||
(channel_filter_stop_bandwidth != stop_bandwidth) ) {
|
(channel_filter_stop_frequency != stop_frequency) ) {
|
||||||
channel_filter_pass_bandwidth = pass_bandwidth;
|
channel_filter_pass_frequency = pass_frequency;
|
||||||
channel_filter_stop_bandwidth = stop_bandwidth;
|
channel_filter_stop_frequency = stop_frequency;
|
||||||
set_dirty();
|
set_dirty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void paint(Painter& painter) override {
|
void paint(Painter& painter) override {
|
||||||
if( !spectrum_bandwidth || !spectrum_bins ) {
|
if( !spectrum_sampling_rate || !spectrum_bins ) {
|
||||||
// Can't draw without non-zero scale.
|
// Can't draw without non-zero scale.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -77,16 +77,16 @@ public:
|
|||||||
);
|
);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if( channel_filter_pass_bandwidth ) {
|
if( channel_filter_pass_frequency ) {
|
||||||
const auto pass_width = channel_filter_pass_bandwidth * spectrum_bins / spectrum_bandwidth;
|
const auto pass_offset = channel_filter_pass_frequency * spectrum_bins / spectrum_sampling_rate;
|
||||||
const auto stop_width = channel_filter_stop_bandwidth * spectrum_bins / spectrum_bandwidth;
|
const auto stop_offset = channel_filter_stop_frequency * spectrum_bins / spectrum_sampling_rate;
|
||||||
|
|
||||||
const auto pass_x_lo = x_center - pass_width / 2;
|
const auto pass_x_lo = x_center - pass_offset;
|
||||||
const auto pass_x_hi = x_center + pass_width / 2;
|
const auto pass_x_hi = x_center + pass_offset;
|
||||||
|
|
||||||
if( channel_filter_stop_bandwidth ) {
|
if( channel_filter_stop_frequency ) {
|
||||||
const auto stop_x_lo = x_center - stop_width / 2;
|
const auto stop_x_lo = x_center - stop_offset;
|
||||||
const auto stop_x_hi = x_center + stop_width / 2;
|
const auto stop_x_hi = x_center + stop_offset;
|
||||||
|
|
||||||
const Rect r_stop_lo {
|
const Rect r_stop_lo {
|
||||||
static_cast<Coord>(r.left() + stop_x_lo), r.top(),
|
static_cast<Coord>(r.left() + stop_x_lo), r.top(),
|
||||||
@ -131,10 +131,10 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint32_t spectrum_bandwidth { 0 };
|
uint32_t spectrum_sampling_rate { 0 };
|
||||||
size_t spectrum_bins { 0 };
|
size_t spectrum_bins { 0 };
|
||||||
uint32_t channel_filter_pass_bandwidth { 0 };
|
uint32_t channel_filter_pass_frequency { 0 };
|
||||||
uint32_t channel_filter_stop_bandwidth { 0 };
|
uint32_t channel_filter_stop_frequency { 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
class WaterfallView : public Widget {
|
class WaterfallView : public Widget {
|
||||||
@ -225,11 +225,19 @@ private:
|
|||||||
|
|
||||||
void on_channel_spectrum(const ChannelSpectrum& spectrum) {
|
void on_channel_spectrum(const ChannelSpectrum& spectrum) {
|
||||||
waterfall_view.on_channel_spectrum(spectrum);
|
waterfall_view.on_channel_spectrum(spectrum);
|
||||||
frequency_scale.set_spectrum_bandwidth(spectrum.bandwidth, spectrum.db_count);
|
frequency_scale.set_spectrum_sampling_rate(spectrum.sampling_rate, spectrum.db_count);
|
||||||
|
|
||||||
// TODO: Set with actual information.
|
// TODO: Set with actual information.
|
||||||
//taps_64_lp_042_078_tfilter
|
//taps_64_lp_042_078_tfilter
|
||||||
frequency_scale.set_channel_filter(spectrum.bandwidth * 2 * 42 / 1000, spectrum.bandwidth * 2 * 78 / 1000);
|
// TODO: Pass these details, don't hard-code them.
|
||||||
|
// Channel spectrum is channel filter input, decimated by 2 by the
|
||||||
|
// channel filter, then by 4 by the channel spectrum decimator.
|
||||||
|
constexpr size_t channel_spectrum_decimation = 2 * 4;
|
||||||
|
// TODO: Rename spectrum.bandwidth to spectrum.sampling_rate so this makes sense. */
|
||||||
|
frequency_scale.set_channel_filter(
|
||||||
|
spectrum.sampling_rate * channel_spectrum_decimation * 42 / 1000,
|
||||||
|
spectrum.sampling_rate * channel_spectrum_decimation * 78 / 1000
|
||||||
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -337,7 +337,7 @@ private:
|
|||||||
|
|
||||||
static volatile bool channel_spectrum_request_update { false };
|
static volatile bool channel_spectrum_request_update { false };
|
||||||
static std::array<complex16_t, 256> channel_spectrum;
|
static std::array<complex16_t, 256> channel_spectrum;
|
||||||
static uint32_t channel_spectrum_bandwidth { 0 };
|
static uint32_t channel_spectrum_sampling_rate { 0 };
|
||||||
|
|
||||||
class BasebandProcessor {
|
class BasebandProcessor {
|
||||||
public:
|
public:
|
||||||
@ -380,7 +380,7 @@ protected:
|
|||||||
if( !channel_spectrum_request_update ) {
|
if( !channel_spectrum_request_update ) {
|
||||||
channel_spectrum_request_update = true;
|
channel_spectrum_request_update = true;
|
||||||
std::copy(&data.p[0], &data.p[data.count], channel_spectrum.begin());
|
std::copy(&data.p[0], &data.p[data.count], channel_spectrum.begin());
|
||||||
channel_spectrum_bandwidth = data.sampling_rate;
|
channel_spectrum_sampling_rate = data.sampling_rate;
|
||||||
events_flag(EVT_MASK_SPECTRUM);
|
events_flag(EVT_MASK_SPECTRUM);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -860,8 +860,8 @@ private:
|
|||||||
|
|
||||||
/* TODO: Rename .db -> .magnitude, or something more (less!) accurate. */
|
/* TODO: Rename .db -> .magnitude, or something more (less!) accurate. */
|
||||||
spectrum_message.spectrum.db = &spectrum_db;
|
spectrum_message.spectrum.db = &spectrum_db;
|
||||||
//spectrum_message.spectrum.db_count = 256;
|
spectrum_message.spectrum.db_count = spectrum_db.size();
|
||||||
spectrum_message.spectrum.bandwidth = channel_spectrum_bandwidth;
|
spectrum_message.spectrum.sampling_rate = channel_spectrum_sampling_rate;
|
||||||
shared_memory.application_queue.push(&spectrum_message);
|
shared_memory.application_queue.push(&spectrum_message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -185,7 +185,7 @@ public:
|
|||||||
struct ChannelSpectrum {
|
struct ChannelSpectrum {
|
||||||
std::array<uint8_t, 256>* db { nullptr };
|
std::array<uint8_t, 256>* db { nullptr };
|
||||||
size_t db_count { 256 };
|
size_t db_count { 256 };
|
||||||
uint32_t bandwidth { 0 };
|
uint32_t sampling_rate { 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
class ChannelSpectrumMessage : public Message {
|
class ChannelSpectrumMessage : public Message {
|
||||||
|
Loading…
Reference in New Issue
Block a user