1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
From 5dbad4c421e528b348276c9353d4a6aa895cc181 Mon Sep 17 00:00:00 2001
From: Marc L <marcll@vt.edu>
Date: Sat, 26 Mar 2022 17:17:22 -0400
Subject: [PATCH 28/31] Added support for float64 files (#206)
* added float64 to supported input types
Co-authored-by: Marc Lichtman <mlichtman@perspectalabs.com>
---
README.md | 3 ++-
src/inputsource.cpp | 20 ++++++++++++++++++++
2 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 5195832..eeee898 100644
--- a/README.md
+++ b/README.md
@@ -24,11 +24,12 @@ Build instructions can be found here: https://github.com/miek/inspectrum/wiki/Bu
## Input
inspectrum supports the following file types:
* `*.sigmf-meta, *.sigmf-data` - SigMF recordings
- * `*.cf32`, `*.cfile` - Complex 32-bit floating point samples (GNURadio, osmocom_fft)
+ * `*.cf32`, `*.cfile` - Complex 32-bit floating point samples (GNU Radio, osmocom_fft)
* `*.cs16` - Complex 16-bit signed integer samples (BladeRF)
* `*.cs8` - Complex 8-bit signed integer samples (HackRF)
* `*.cu8` - Complex 8-bit unsigned integer samples (RTL-SDR)
* `*.f32` - Real 32-bit floating point samples
+ * `*.f64` - Real 64-bit floating point samples (MATLAB)
* `*.s16` - Real 16-bit signed integer samples
* `*.s8` - Real 8-bit signed integer samples
* `*.u8` - Real 8-bit unsigned integer samples
diff --git a/src/inputsource.cpp b/src/inputsource.cpp
index aaae361..68181c0 100644
--- a/src/inputsource.cpp
+++ b/src/inputsource.cpp
@@ -119,6 +119,22 @@ public:
}
};
+class RealF64SampleAdapter : public SampleAdapter {
+public:
+ size_t sampleSize() override {
+ return sizeof(double);
+ }
+
+ void copyRange(const void* const src, size_t start, size_t length, std::complex<float>* const dest) override {
+ auto s = reinterpret_cast<const double*>(src);
+ std::transform(&s[start], &s[start + length], dest,
+ [](const double& v) -> std::complex<float> {
+ return {static_cast<float>(v), 0.0f};
+ }
+ );
+ }
+};
+
class RealS16SampleAdapter : public SampleAdapter {
public:
size_t sampleSize() override {
@@ -316,6 +332,10 @@ void InputSource::openFile(const char *filename)
sampleAdapter = std::make_unique<RealF32SampleAdapter>();
_realSignal = true;
}
+ else if (suffix == "f64") {
+ sampleAdapter = std::make_unique<RealF64SampleAdapter>();
+ _realSignal = true;
+ }
else if (suffix == "s16") {
sampleAdapter = std::make_unique<RealS16SampleAdapter>();
_realSignal = true;
--
2.35.1
|