-
Notifications
You must be signed in to change notification settings - Fork 133
/
mirisdr_sdr.h
83 lines (65 loc) · 2.25 KB
/
mirisdr_sdr.h
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
73
74
75
76
77
78
79
80
81
82
83
#pragma once
#include "common/dsp_source_sink/dsp_sample_source.h"
#ifdef __ANDROID__
#include "mirisdr/mirisdr.h"
#else
#include "mirisdr/mirisdr.h"
#endif
#include "logger.h"
#include "common/rimgui.h"
#include <thread>
#include "common/widgets/double_list.h"
class MiriSdrSource : public dsp::DSPSampleSource
{
protected:
bool is_open = false, is_started = false;
mirisdr_dev *mirisdr_dev_obj;
static void _rx_callback_8(unsigned char *buf, uint32_t len, void *ctx);
static void _rx_callback_16(unsigned char *buf, uint32_t len, void *ctx);
widgets::DoubleList samplerate_widget;
int bit_depth = 12;
int gain = 0;
bool bias_enabled = false;
void set_gains();
void set_bias();
std::thread work_thread;
bool thread_should_run = false;
bool async_running = false;
void mainThread()
{
int buffer_size = calculate_buffer_size_from_samplerate(samplerate_widget.get_value());
// int buffer_size = std::min<int>(samplerate_widget.get_value() / 250, dsp::STREAM_BUFFER_SIZE);
logger->trace("MiriSDR Buffer size %d", buffer_size);
while (thread_should_run)
{
logger->trace("Starting async reads...");
if (bit_depth == 8)
mirisdr_read_async(mirisdr_dev_obj, _rx_callback_8, &output_stream, 15, buffer_size);
else
mirisdr_read_async(mirisdr_dev_obj, _rx_callback_16, &output_stream, 15, buffer_size);
logger->trace("Stopped async reads...");
}
}
public:
MiriSdrSource(dsp::SourceDescriptor source) : DSPSampleSource(source), samplerate_widget("Samplerate")
{
}
~MiriSdrSource()
{
stop();
close();
}
void set_settings(nlohmann::json settings);
nlohmann::json get_settings();
void open();
void start();
void stop();
void close();
void set_frequency(uint64_t frequency);
void drawControlUI();
void set_samplerate(uint64_t samplerate);
uint64_t get_samplerate();
static std::string getID() { return "mirisdr"; }
static std::shared_ptr<dsp::DSPSampleSource> getInstance(dsp::SourceDescriptor source) { return std::make_shared<MiriSdrSource>(source); }
static std::vector<dsp::SourceDescriptor> getAvailableSources();
};