File: 0029-Add-support-for-complex-double-cf64.patch

package info (click to toggle)
inspectrum 0.2.3-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,312 kB
  • sloc: cpp: 2,675; makefile: 3
file content (62 lines) | stat: -rw-r--r-- 2,348 bytes parent folder | download
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
From 828c13c4930e072a9eea0eacdf14bce59e32522a Mon Sep 17 00:00:00 2001
From: DiGMi <github@digmi.org>
Date: Fri, 10 Sep 2021 14:06:34 +0300
Subject: [PATCH 29/31] Add support for complex double (cf64)

---
 README.md           |  1 +
 src/inputsource.cpp | 19 +++++++++++++++++++
 2 files changed, 20 insertions(+)

diff --git a/README.md b/README.md
index eeee898..6ad78fe 100644
--- a/README.md
+++ b/README.md
@@ -25,6 +25,7 @@ Build instructions can be found here: https://github.com/miek/inspectrum/wiki/Bu
 inspectrum supports the following file types:
  * `*.sigmf-meta, *.sigmf-data` - SigMF recordings
  * `*.cf32`, `*.cfile` - Complex 32-bit floating point samples (GNU Radio, osmocom_fft)
+ * `*.cf64` - Complex 64-bit floating point samples
  * `*.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)
diff --git a/src/inputsource.cpp b/src/inputsource.cpp
index 68181c0..67743fb 100644
--- a/src/inputsource.cpp
+++ b/src/inputsource.cpp
@@ -52,6 +52,22 @@ public:
     }
 };
 
+class ComplexF64SampleAdapter : public SampleAdapter {
+public:
+    size_t sampleSize() override {
+        return sizeof(std::complex<double>);
+    }
+
+    void copyRange(const void* const src, size_t start, size_t length, std::complex<float>* const dest) override {
+        auto s = reinterpret_cast<const std::complex<double>*>(src);
+        std::transform(&s[start], &s[start + length], dest,
+            [](const std::complex<double>& v) -> std::complex<float> {
+                return { static_cast<float>(v.real()) , static_cast<float>(v.imag()) };
+            }
+        );
+    }
+};
+
 class ComplexS16SampleAdapter : public SampleAdapter {
 public:
     size_t sampleSize() override {
@@ -319,6 +335,9 @@ void InputSource::openFile(const char *filename)
     if ((suffix == "cfile") || (suffix == "cf32")  || (suffix == "fc32")) {
         sampleAdapter = std::make_unique<ComplexF32SampleAdapter>();
     }
+    else if ((suffix == "cf64")  || (suffix == "fc64")) {
+        sampleAdapter = std::make_unique<ComplexF64SampleAdapter>();
+    }
     else if ((suffix == "cs16") || (suffix == "sc16") || (suffix == "c16")) {
         sampleAdapter = std::make_unique<ComplexS16SampleAdapter>();
     }
-- 
2.35.1