mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2025-08-14 11:47:43 +00:00
Added back frequency display for CTCSS
Attempted to fix replay, just fixed StreamBuffer read() and added waterfall display... Updated binary
This commit is contained in:
@@ -21,19 +21,20 @@
|
||||
*/
|
||||
|
||||
#include "proc_replay.hpp"
|
||||
#include "sine_table_int8.hpp"
|
||||
|
||||
#include "event_m4.hpp"
|
||||
|
||||
#include "utility.hpp"
|
||||
|
||||
ReplayProcessor::ReplayProcessor() {
|
||||
// TODO: Interpolation filter needed !
|
||||
channel_filter_pass_f = taps_200k_decim_1.pass_frequency_normalized * 1000000; // 162760.416666667
|
||||
channel_filter_stop_f = taps_200k_decim_1.stop_frequency_normalized * 1000000; // 337239.583333333
|
||||
|
||||
/*spectrum_interval_samples = baseband_fs / spectrum_rate_hz;
|
||||
spectrum_interval_samples = (baseband_fs / 8) / spectrum_rate_hz;
|
||||
spectrum_samples = 0;
|
||||
|
||||
channel_spectrum.set_decimation_factor(1);*/
|
||||
|
||||
channel_spectrum.set_decimation_factor(1);
|
||||
}
|
||||
|
||||
void ReplayProcessor::execute(const buffer_c8_t& buffer) {
|
||||
@@ -43,13 +44,13 @@ void ReplayProcessor::execute(const buffer_c8_t& buffer) {
|
||||
|
||||
// File data is in C16 format, we need C8
|
||||
// File samplerate is 500kHz, we're at 4MHz
|
||||
// iq_buffer can only be 512 samples (RAM limitation)
|
||||
// For a full 2048-sample C8 buffer, we need:
|
||||
// iq_buffer can only be 512 C16 samples (RAM limitation)
|
||||
// To fill up the 2048-sample C8 buffer, we need:
|
||||
// 2048 samples * 2 bytes per sample = 4096 bytes
|
||||
// Since we're oversampling by 4M/500k = 8, we only need 2048/8 = 256 samples from the file
|
||||
// Since we're oversampling by 4M/500k = 8, we only need 2048/8 = 256 samples from the file and duplicate them 8 times each
|
||||
// So 256 * 4 bytes per sample (C16) = 1024 bytes from the file
|
||||
if( stream ) {
|
||||
const size_t bytes_to_read = sizeof(*buffer.p) * 2 * (buffer.count / 8); // *2 (C16), /8 (oversampling)
|
||||
const size_t bytes_to_read = sizeof(*buffer.p) * 2 * (buffer.count / 8); // *2 (C16), /8 (oversampling) should be == 1024
|
||||
const auto result = stream->read(iq_buffer.p, bytes_to_read);
|
||||
}
|
||||
|
||||
@@ -57,25 +58,39 @@ void ReplayProcessor::execute(const buffer_c8_t& buffer) {
|
||||
|
||||
// Zero-stuff
|
||||
for (size_t i = 0; i < buffer.count; i++) {
|
||||
if (i & 3)
|
||||
buffer.p[i] = { 0, 0 };
|
||||
else
|
||||
buffer.p[i] = { iq_buffer.p[i >> 3].real() >> 8, iq_buffer.p[i >> 3].imag() >> 8 };
|
||||
|
||||
// DEBUG: This works. Transmits a 1kHz tone
|
||||
/*sample = (sine_table_i8[(tone_phase & 0xFF000000) >> 24]);
|
||||
tone_phase += (1000 * ((1ULL << 32) / baseband_fs));
|
||||
// Do FM
|
||||
delta = sample * 30000 * (0xFFFFFFULL / baseband_fs);
|
||||
phase += delta;
|
||||
sphase = phase + (64 << 24);
|
||||
iq_buffer.p[i >> 3] = { (int16_t)(sine_table_i8[(sphase & 0xFF000000) >> 24]) << 8, (int16_t)(sine_table_i8[(phase & 0xFF000000) >> 24]) << 8 };
|
||||
*/
|
||||
|
||||
/*if (i & 3)
|
||||
buffer.p[i] = buffer.p[i - 1];
|
||||
else {*/
|
||||
auto re_out = iq_buffer.p[i >> 3].real() >> 8;
|
||||
auto im_out = iq_buffer.p[i >> 3].imag() >> 8;
|
||||
buffer.p[i] = { re_out, im_out };
|
||||
//}
|
||||
}
|
||||
|
||||
/*spectrum_samples += channel.count;
|
||||
spectrum_samples += buffer.count;
|
||||
if( spectrum_samples >= spectrum_interval_samples ) {
|
||||
spectrum_samples -= spectrum_interval_samples;
|
||||
channel_spectrum.feed(channel, channel_filter_pass_f, channel_filter_stop_f);
|
||||
}*/
|
||||
channel_spectrum.feed(iq_buffer, channel_filter_pass_f, channel_filter_stop_f);
|
||||
}
|
||||
}
|
||||
|
||||
void ReplayProcessor::on_message(const Message* const message) {
|
||||
switch(message->id) {
|
||||
/*case Message::ID::UpdateSpectrum:
|
||||
case Message::ID::UpdateSpectrum:
|
||||
case Message::ID::SpectrumStreamingConfig:
|
||||
channel_spectrum.on_message(message);
|
||||
break;*/
|
||||
break;
|
||||
|
||||
case Message::ID::ReplayConfig:
|
||||
replay_config(*reinterpret_cast<const ReplayConfigMessage*>(message));
|
||||
|
@@ -43,21 +43,28 @@ public:
|
||||
|
||||
private:
|
||||
static constexpr size_t baseband_fs = 4000000;
|
||||
//static constexpr auto spectrum_rate_hz = 50.0f;
|
||||
static constexpr auto spectrum_rate_hz = 50.0f;
|
||||
|
||||
BasebandThread baseband_thread { baseband_fs, this, NORMALPRIO + 20, baseband::Direction::Transmit };
|
||||
|
||||
std::array<complex16_t, 256> iq { }; // This fits in just right in allocated RAM
|
||||
std::array<complex16_t, 256> iq { }; // This fits in just right in allocated RAM - Too big ?
|
||||
const buffer_c16_t iq_buffer {
|
||||
iq.data(),
|
||||
iq.size()
|
||||
};
|
||||
|
||||
uint32_t channel_filter_pass_f = 0;
|
||||
uint32_t channel_filter_stop_f = 0;
|
||||
|
||||
// DEBUG
|
||||
//uint32_t tone_phase { 0 }, phase { 0 }, delta { 0 }, sphase { 0 };
|
||||
//int8_t sample { 0 };
|
||||
|
||||
std::unique_ptr<StreamOutput> stream { };
|
||||
|
||||
/*SpectrumCollector channel_spectrum;
|
||||
SpectrumCollector channel_spectrum { };
|
||||
size_t spectrum_interval_samples = 0;
|
||||
size_t spectrum_samples = 0;*/
|
||||
size_t spectrum_samples = 0;
|
||||
|
||||
void replay_config(const ReplayConfigMessage& message);
|
||||
};
|
||||
|
@@ -35,7 +35,9 @@ StreamOutput::StreamOutput(ReplayConfig* const config) :
|
||||
config->fifo_buffers_full = &fifo_buffers_full;
|
||||
|
||||
for(size_t i=0; i<config->buffer_count; i++) {
|
||||
// Set buffers to point consecutively in previously allocated unique_ptr "data"
|
||||
buffers[i] = { &(data.get()[i * config->read_size]), config->read_size };
|
||||
// Put all buffer pointers in the "empty buffer" FIFO
|
||||
fifo_buffers_empty.in(&buffers[i]);
|
||||
}
|
||||
}
|
||||
@@ -49,6 +51,8 @@ size_t StreamOutput::read(void* const data, const size_t length) {
|
||||
// We need a full buffer...
|
||||
if( !fifo_buffers_full.out(active_buffer) ) {
|
||||
// ...but none are available. Hole in transmission (inform app and stop ?)
|
||||
//active_buffer = nullptr;
|
||||
//creg::m4txevent::assert();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user