mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2024-12-13 03:34:35 +00:00
Minor Replay & GPS baseband optimizations (#1289)
* No need to scale progress now that widget is fixed * Use memcpy vs byte copy, elim progress scaling, correct comments * Minor optimization in C16->C8 conversion * Only copy bytes actually read from file
This commit is contained in:
parent
2af95456a2
commit
8eafe27955
@ -65,12 +65,12 @@ void GpsSimAppView::on_file_changed(const fs::path& new_file_path) {
|
||||
field_frequency.set_value(metadata->center_frequency);
|
||||
sample_rate = metadata->sample_rate;
|
||||
} else {
|
||||
sample_rate = 500000;
|
||||
sample_rate = 2600000;
|
||||
}
|
||||
|
||||
// UI Fixup.
|
||||
text_sample_rate.set(unit_auto_scale(sample_rate, 3, 1) + "Hz");
|
||||
progressbar.set_max(file_size / 1024);
|
||||
progressbar.set_max(file_size);
|
||||
text_filename.set(truncate(file_path.filename().string(), 12));
|
||||
|
||||
auto duration = ms_duration(file_size, sample_rate, 2);
|
||||
|
@ -42,34 +42,33 @@ ReplayProcessor::ReplayProcessor() {
|
||||
}
|
||||
|
||||
void ReplayProcessor::execute(const buffer_c8_t& buffer) {
|
||||
/* 4MHz, 2048 samples */
|
||||
/* 2.6MHz, 2048 samples */
|
||||
|
||||
if (!configured) return;
|
||||
|
||||
// File data is in C16 format, we need C8
|
||||
// File samplerate is 500kHz, we're at 4MHz
|
||||
// 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 and duplicate them 8 times each
|
||||
// So 256 * 4 bytes per sample (C16) = 1024 bytes from the file
|
||||
if (stream) { // sizeof(*buffer.p) = sizeof(C8) = 2*int8 = 2 bytes //buffer.count = 2048
|
||||
const size_t bytes_to_read = sizeof(*buffer.p) * 1 * (buffer.count); // *2 (C16), /8 (oversampling) should be == 1024
|
||||
bytes_read += stream->read(iq_buffer.p, bytes_to_read);
|
||||
}
|
||||
// File data is in C8 format, which is what we need
|
||||
// File samplerate is 2.6MHz, which is what we need
|
||||
// To fill up the 2048-sample C8 buffer @ 2 bytes per sample = 4096 bytes
|
||||
if (stream) {
|
||||
const size_t bytes_to_read = sizeof(*buffer.p) * 1 * (buffer.count);
|
||||
size_t bytes_read_this_iteration = stream->read(iq_buffer.p, bytes_to_read);
|
||||
bytes_read += bytes_read_this_iteration;
|
||||
|
||||
// Fill and "stretch"
|
||||
for (size_t i = 0; i < buffer.count; i++) {
|
||||
auto re_out = iq_buffer.p[i].real();
|
||||
auto im_out = iq_buffer.p[i].imag();
|
||||
buffer.p[i] = {(int8_t)re_out, (int8_t)im_out};
|
||||
// NB: Couldn't we have just read the data into buffer.p to start with, or some DMA/cache coherency concern?
|
||||
//
|
||||
// for (size_t i = 0; i < buffer.count; i++) {
|
||||
// auto re_out = iq_buffer.p[i].real();
|
||||
// auto im_out = iq_buffer.p[i].imag();
|
||||
// buffer.p[i] = {(int8_t)re_out, (int8_t)im_out};
|
||||
// }
|
||||
memcpy(buffer.p, iq_buffer.p, bytes_read_this_iteration); // memcpy should be more efficient than 1 byte at a time
|
||||
}
|
||||
|
||||
spectrum_samples += buffer.count;
|
||||
if (spectrum_samples >= spectrum_interval_samples) {
|
||||
spectrum_samples -= spectrum_interval_samples;
|
||||
|
||||
txprogress_message.progress = bytes_read / 1024; // Inform UI about progress
|
||||
txprogress_message.progress = bytes_read; // Inform UI about progress
|
||||
|
||||
txprogress_message.done = false;
|
||||
shared_memory.application_queue.push(txprogress_message);
|
||||
|
@ -59,7 +59,7 @@ void ReplayProcessor::execute(const buffer_c8_t& buffer) {
|
||||
|
||||
// Fill and "stretch"
|
||||
for (size_t i = 0; i < buffer.count; i++) {
|
||||
if (i & 3) {
|
||||
if (i & 7) {
|
||||
buffer.p[i] = buffer.p[i - 1];
|
||||
} else {
|
||||
auto re_out = iq_buffer.p[i >> 3].real() >> 8;
|
||||
|
Loading…
Reference in New Issue
Block a user