mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-02-08 18:58:34 -05: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);
|
field_frequency.set_value(metadata->center_frequency);
|
||||||
sample_rate = metadata->sample_rate;
|
sample_rate = metadata->sample_rate;
|
||||||
} else {
|
} else {
|
||||||
sample_rate = 500000;
|
sample_rate = 2600000;
|
||||||
}
|
}
|
||||||
|
|
||||||
// UI Fixup.
|
// UI Fixup.
|
||||||
text_sample_rate.set(unit_auto_scale(sample_rate, 3, 1) + "Hz");
|
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));
|
text_filename.set(truncate(file_path.filename().string(), 12));
|
||||||
|
|
||||||
auto duration = ms_duration(file_size, sample_rate, 2);
|
auto duration = ms_duration(file_size, sample_rate, 2);
|
||||||
|
@ -42,34 +42,33 @@ ReplayProcessor::ReplayProcessor() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ReplayProcessor::execute(const buffer_c8_t& buffer) {
|
void ReplayProcessor::execute(const buffer_c8_t& buffer) {
|
||||||
/* 4MHz, 2048 samples */
|
/* 2.6MHz, 2048 samples */
|
||||||
|
|
||||||
if (!configured) return;
|
if (!configured) return;
|
||||||
|
|
||||||
// File data is in C16 format, we need C8
|
// File data is in C8 format, which is what we need
|
||||||
// File samplerate is 500kHz, we're at 4MHz
|
// File samplerate is 2.6MHz, which is what we need
|
||||||
// iq_buffer can only be 512 C16 samples (RAM limitation)
|
// To fill up the 2048-sample C8 buffer @ 2 bytes per sample = 4096 bytes
|
||||||
// To fill up the 2048-sample C8 buffer, we need:
|
if (stream) {
|
||||||
// 2048 samples * 2 bytes per sample = 4096 bytes
|
const size_t bytes_to_read = sizeof(*buffer.p) * 1 * (buffer.count);
|
||||||
// Since we're oversampling by 4M/500k = 8, we only need 2048/8 = 256 samples from the file and duplicate them 8 times each
|
size_t bytes_read_this_iteration = stream->read(iq_buffer.p, bytes_to_read);
|
||||||
// So 256 * 4 bytes per sample (C16) = 1024 bytes from the file
|
bytes_read += bytes_read_this_iteration;
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fill and "stretch"
|
// 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();
|
// for (size_t i = 0; i < buffer.count; i++) {
|
||||||
auto im_out = iq_buffer.p[i].imag();
|
// auto re_out = iq_buffer.p[i].real();
|
||||||
buffer.p[i] = {(int8_t)re_out, (int8_t)im_out};
|
// 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;
|
spectrum_samples += buffer.count;
|
||||||
if (spectrum_samples >= spectrum_interval_samples) {
|
if (spectrum_samples >= spectrum_interval_samples) {
|
||||||
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;
|
txprogress_message.done = false;
|
||||||
shared_memory.application_queue.push(txprogress_message);
|
shared_memory.application_queue.push(txprogress_message);
|
||||||
|
@ -59,7 +59,7 @@ void ReplayProcessor::execute(const buffer_c8_t& buffer) {
|
|||||||
|
|
||||||
// Fill and "stretch"
|
// Fill and "stretch"
|
||||||
for (size_t i = 0; i < buffer.count; i++) {
|
for (size_t i = 0; i < buffer.count; i++) {
|
||||||
if (i & 3) {
|
if (i & 7) {
|
||||||
buffer.p[i] = buffer.p[i - 1];
|
buffer.p[i] = buffer.p[i - 1];
|
||||||
} else {
|
} else {
|
||||||
auto re_out = iq_buffer.p[i >> 3].real() >> 8;
|
auto re_out = iq_buffer.p[i >> 3].real() >> 8;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user