mirror of
https://github.com/miek/inspectrum.git
synced 2026-03-03 06:54:17 +01:00
Ability to export raw samples from other plots
This commit is contained in:
committed by
Mike Walters
parent
f08cf08c0e
commit
b35fcd7fc7
23
plotview.cpp
23
plotview.cpp
@@ -110,7 +110,6 @@ void PlotView::contextMenuEvent(QContextMenuEvent * event)
|
||||
exportSamples(src);
|
||||
}
|
||||
);
|
||||
save->setEnabled(src->sampleType() == typeid(std::complex<float>));
|
||||
menu.addAction(save);
|
||||
|
||||
updateViewRange(false);
|
||||
@@ -215,8 +214,18 @@ void PlotView::extractSymbols(std::shared_ptr<AbstractSampleSource> src)
|
||||
|
||||
void PlotView::exportSamples(std::shared_ptr<AbstractSampleSource> src)
|
||||
{
|
||||
auto complexSrc = std::dynamic_pointer_cast<SampleSource<std::complex<float>>>(src);
|
||||
if (!complexSrc) {
|
||||
if (src->sampleType() == typeid(std::complex<float>)) {
|
||||
exportSamples<std::complex<float>>(src);
|
||||
} else {
|
||||
exportSamples<float>(src);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename SOURCETYPE>
|
||||
void PlotView::exportSamples(std::shared_ptr<AbstractSampleSource> src)
|
||||
{
|
||||
auto sampleSrc = std::dynamic_pointer_cast<SampleSource<SOURCETYPE>>(src);
|
||||
if (!sampleSrc) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -250,7 +259,7 @@ void PlotView::exportSamples(std::shared_ptr<AbstractSampleSource> src)
|
||||
|
||||
QGroupBox groupBox2("Decimation");
|
||||
QSpinBox decimation(&groupBox2);
|
||||
decimation.setValue(1 / complexSrc->relativeBandwidth());
|
||||
decimation.setValue(1 / sampleSrc->relativeBandwidth());
|
||||
|
||||
QVBoxLayout vbox2;
|
||||
vbox2.addWidget(&decimation);
|
||||
@@ -270,7 +279,7 @@ void PlotView::exportSamples(std::shared_ptr<AbstractSampleSource> src)
|
||||
end = start + viewRange.length();
|
||||
} else {
|
||||
start = 0;
|
||||
end = complexSrc->count();
|
||||
end = sampleSrc->count();
|
||||
}
|
||||
|
||||
std::ofstream os (fileNames[0].toStdString(), std::ios::binary);
|
||||
@@ -281,10 +290,10 @@ void PlotView::exportSamples(std::shared_ptr<AbstractSampleSource> src)
|
||||
|
||||
for (index = start; index < end; index += step) {
|
||||
off_t length = std::min(step, end - index);
|
||||
auto samples = complexSrc->getSamples(index, length);
|
||||
auto samples = sampleSrc->getSamples(index, length);
|
||||
if (samples != nullptr) {
|
||||
for (auto i = 0; i < length; i += decimation.value()) {
|
||||
os.write((const char*)&samples[i], 8);
|
||||
os.write((const char*)&samples[i], sizeof(SOURCETYPE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user