mirror of
https://github.com/AlexandreRouma/SDRPlusPlus.git
synced 2025-02-02 21:04:45 +01:00
More work on the sink interface
This commit is contained in:
parent
f1084157a3
commit
61a612cf30
@ -8,7 +8,7 @@ add_subdirectory("recorder")
|
|||||||
add_subdirectory("soapy")
|
add_subdirectory("soapy")
|
||||||
add_subdirectory("file_source")
|
add_subdirectory("file_source")
|
||||||
add_subdirectory("rtl_tcp_source")
|
add_subdirectory("rtl_tcp_source")
|
||||||
# add_subdirectory("audio_sink")
|
add_subdirectory("audio_sink")
|
||||||
add_subdirectory("rx888_source")
|
add_subdirectory("rx888_source")
|
||||||
add_subdirectory("demo")
|
add_subdirectory("demo")
|
||||||
|
|
||||||
|
@ -3,25 +3,118 @@
|
|||||||
#include <gui/gui.h>
|
#include <gui/gui.h>
|
||||||
#include <signal_path/signal_path.h>
|
#include <signal_path/signal_path.h>
|
||||||
#include <signal_path/sink.h>
|
#include <signal_path/sink.h>
|
||||||
|
#include <portaudio.h>
|
||||||
|
#include <dsp/audio.h>
|
||||||
|
|
||||||
#define CONCAT(a, b) ((std::string(a) + b).c_str())
|
#define CONCAT(a, b) ((std::string(a) + b).c_str())
|
||||||
|
|
||||||
class AudioSink : SinkManager::Sink {
|
class AudioSink : SinkManager::Sink {
|
||||||
public:
|
public:
|
||||||
|
struct AudioDevice_t {
|
||||||
|
std::string name;
|
||||||
|
int index;
|
||||||
|
int channels;
|
||||||
|
std::vector<double> sampleRates;
|
||||||
|
std::string txtSampleRates;
|
||||||
|
};
|
||||||
|
|
||||||
AudioSink(SinkManager::Stream* stream) {
|
AudioSink(SinkManager::Stream* stream) {
|
||||||
_stream = stream;
|
_stream = stream;
|
||||||
|
audioStream = _stream->bindStream();
|
||||||
|
s2m.init(audioStream);
|
||||||
|
monoRB.init(&s2m.out);
|
||||||
|
stereoRB.init(audioStream);
|
||||||
|
|
||||||
|
// Initialize PortAudio
|
||||||
|
Pa_Initialize();
|
||||||
|
devCount = Pa_GetDeviceCount();
|
||||||
|
devId = Pa_GetDefaultOutputDevice();
|
||||||
|
const PaDeviceInfo *deviceInfo;
|
||||||
|
PaStreamParameters outputParams;
|
||||||
|
outputParams.sampleFormat = paFloat32;
|
||||||
|
outputParams.hostApiSpecificStreamInfo = NULL;
|
||||||
|
|
||||||
|
// Gather hardware info
|
||||||
|
for(int i = 0; i < devCount; i++) {
|
||||||
|
deviceInfo = Pa_GetDeviceInfo(i);
|
||||||
|
if (deviceInfo->maxOutputChannels < 1) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
AudioDevice_t dev;
|
||||||
|
dev.name = deviceInfo->name;
|
||||||
|
dev.index = i;
|
||||||
|
dev.channels = std::min<int>(deviceInfo->maxOutputChannels, 2);
|
||||||
|
dev.sampleRates.clear();
|
||||||
|
dev.txtSampleRates = "";
|
||||||
|
for (int j = 0; j < 6; j++) {
|
||||||
|
outputParams.channelCount = dev.channels;
|
||||||
|
outputParams.device = dev.index;
|
||||||
|
outputParams.suggestedLatency = deviceInfo->defaultLowOutputLatency;
|
||||||
|
PaError err = Pa_IsFormatSupported(NULL, &outputParams, POSSIBLE_SAMP_RATE[j]);
|
||||||
|
if (err != paFormatIsSupported) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
dev.sampleRates.push_back(POSSIBLE_SAMP_RATE[j]);
|
||||||
|
dev.txtSampleRates += std::to_string((int)POSSIBLE_SAMP_RATE[j]);
|
||||||
|
dev.txtSampleRates += '\0';
|
||||||
|
}
|
||||||
|
if (dev.sampleRates.size() == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (i == devId) {
|
||||||
|
devListId = devices.size();
|
||||||
|
defaultDev = devListId;
|
||||||
|
}
|
||||||
|
devices.push_back(dev);
|
||||||
|
deviceNames.push_back(deviceInfo->name);
|
||||||
|
txtDevList += deviceInfo->name;
|
||||||
|
txtDevList += '\0';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
~AudioSink() {
|
~AudioSink() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void start() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void stop() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void menuHandler() {
|
void menuHandler() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
SinkManager::Stream* _stream;
|
SinkManager::Stream* _stream;
|
||||||
|
dsp::stream<dsp::stereo_t>* audioStream;
|
||||||
|
dsp::StereoToMono s2m;
|
||||||
|
dsp::RingBufferSink<float> monoRB;
|
||||||
|
dsp::RingBufferSink<dsp::stereo_t> stereoRB;
|
||||||
|
|
||||||
|
int srId = 0;
|
||||||
|
float sampleRate;
|
||||||
|
int devCount;
|
||||||
|
int devId = 0;
|
||||||
|
int devListId = 0;
|
||||||
|
int defaultDev = 0;
|
||||||
|
|
||||||
|
const double POSSIBLE_SAMP_RATE[6] = {
|
||||||
|
48000.0f,
|
||||||
|
44100.0f,
|
||||||
|
24000.0f,
|
||||||
|
22050.0f,
|
||||||
|
12000.0f,
|
||||||
|
11025.0f
|
||||||
|
};
|
||||||
|
|
||||||
|
std::vector<AudioDevice_t> devices;
|
||||||
|
std::vector<std::string> deviceNames;
|
||||||
|
std::string txtDevList;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
12
core/src/gui/menus/sink.cpp
Normal file
12
core/src/gui/menus/sink.cpp
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#include <gui/menus/sink.h>
|
||||||
|
#include <signal_path/signal_path.h>
|
||||||
|
|
||||||
|
namespace sinkmenu {
|
||||||
|
void init() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void draw(void* ctx) {
|
||||||
|
sigpath::sinkManager.showMenu();
|
||||||
|
}
|
||||||
|
};
|
6
core/src/gui/menus/sink.h
Normal file
6
core/src/gui/menus/sink.h
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace sinkmenu {
|
||||||
|
void init();
|
||||||
|
void draw(void* ctx);
|
||||||
|
};
|
@ -1,5 +1,6 @@
|
|||||||
#include <signal_path/sink.h>
|
#include <signal_path/sink.h>
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
|
#include <imgui/imgui.h>
|
||||||
#include <core.h>
|
#include <core.h>
|
||||||
|
|
||||||
SinkManager::SinkManager() {
|
SinkManager::SinkManager() {
|
||||||
@ -13,6 +14,14 @@ SinkManager::Stream::Stream(dsp::stream<dsp::stereo_t>* in, const Event<float>::
|
|||||||
splitter.init(_in);
|
splitter.init(_in);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SinkManager::Stream::start() {
|
||||||
|
sink->start();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SinkManager::Stream::stop() {
|
||||||
|
sink->stop();
|
||||||
|
}
|
||||||
|
|
||||||
void SinkManager::Stream::setInput(dsp::stream<dsp::stereo_t>* in) {
|
void SinkManager::Stream::setInput(dsp::stream<dsp::stereo_t>* in) {
|
||||||
std::lock_guard<std::mutex> lck(ctrlMtx);
|
std::lock_guard<std::mutex> lck(ctrlMtx);
|
||||||
_in = in;
|
_in = in;
|
||||||
@ -42,6 +51,7 @@ void SinkManager::registerSinkProvider(std::string name, SinkProvider provider)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
providers[name] = provider;
|
providers[name] = provider;
|
||||||
|
providerNames.push_back(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SinkManager::registerStream(std::string name, SinkManager::Stream* stream) {
|
void SinkManager::registerStream(std::string name, SinkManager::Stream* stream) {
|
||||||
@ -75,6 +85,22 @@ void SinkManager::unregisterStream(std::string name) {
|
|||||||
delete stream;
|
delete stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SinkManager::startStream(std::string name) {
|
||||||
|
if (streams.find(name) == streams.end()) {
|
||||||
|
spdlog::error("Cannot start stream '{0}', this stream doesn't exist", name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
streams[name]->start();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SinkManager::stopStream(std::string name) {
|
||||||
|
if (streams.find(name) == streams.end()) {
|
||||||
|
spdlog::error("Cannot stop stream '{0}', this stream doesn't exist", name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
streams[name]->stop();
|
||||||
|
}
|
||||||
|
|
||||||
dsp::stream<dsp::stereo_t>* SinkManager::bindStream(std::string name) {
|
dsp::stream<dsp::stereo_t>* SinkManager::bindStream(std::string name) {
|
||||||
if (streams.find(name) == streams.end()) {
|
if (streams.find(name) == streams.end()) {
|
||||||
spdlog::error("Cannot bind to stream '{0}'. Stream doesn't exist", name);
|
spdlog::error("Cannot bind to stream '{0}'. Stream doesn't exist", name);
|
||||||
@ -91,8 +117,37 @@ void SinkManager::unbindStream(std::string name, dsp::stream<dsp::stereo_t>* str
|
|||||||
streams[name]->unbindStream(stream);
|
streams[name]->unbindStream(stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SinkManager::showMenu() {
|
void SinkManager::setStreamSink(std::string name, std::string providerName) {
|
||||||
for (auto const& [name, stream] : streams) {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SinkManager::showMenu() {
|
||||||
|
float menuWidth = ImGui::GetContentRegionAvailWidth();
|
||||||
|
int count = 0;
|
||||||
|
int maxCount = streams.size();
|
||||||
|
|
||||||
|
std::string provStr = "";
|
||||||
|
for (auto const& [name, provider] : providers) {
|
||||||
|
provStr += name;
|
||||||
|
provStr += '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto const& [name, stream] : streams) {
|
||||||
|
ImGui::SetCursorPosX((menuWidth / 2.0f) - (ImGui::CalcTextSize(name.c_str()).x / 2.0f));
|
||||||
|
ImGui::Text("%s", name.c_str());
|
||||||
|
|
||||||
|
if (ImGui::Combo("", &stream->providerId, provStr.c_str())) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
stream->sink->menuHandler();
|
||||||
|
|
||||||
|
ImGui::PopItemWidth();
|
||||||
|
count++;
|
||||||
|
if (count < maxCount) {
|
||||||
|
ImGui::Spacing();
|
||||||
|
ImGui::Separator();
|
||||||
|
}
|
||||||
|
ImGui::Spacing();
|
||||||
|
}
|
||||||
}
|
}
|
@ -6,6 +6,7 @@
|
|||||||
#include <dsp/routing.h>
|
#include <dsp/routing.h>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <event.h>
|
#include <event.h>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
class SinkManager {
|
class SinkManager {
|
||||||
public:
|
public:
|
||||||
@ -13,6 +14,8 @@ public:
|
|||||||
|
|
||||||
class Sink {
|
class Sink {
|
||||||
public:
|
public:
|
||||||
|
virtual void start() = 0;
|
||||||
|
virtual void stop() = 0;
|
||||||
virtual void menuHandler() = 0;
|
virtual void menuHandler() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -20,6 +23,9 @@ public:
|
|||||||
public:
|
public:
|
||||||
Stream(dsp::stream<dsp::stereo_t>* in, const Event<float>::EventHandler& srChangeHandler, float sampleRate);
|
Stream(dsp::stream<dsp::stereo_t>* in, const Event<float>::EventHandler& srChangeHandler, float sampleRate);
|
||||||
|
|
||||||
|
void start();
|
||||||
|
void stop();
|
||||||
|
|
||||||
void setInput(dsp::stream<dsp::stereo_t>* in);
|
void setInput(dsp::stream<dsp::stereo_t>* in);
|
||||||
|
|
||||||
dsp::stream<dsp::stereo_t>* bindStream();
|
dsp::stream<dsp::stereo_t>* bindStream();
|
||||||
@ -29,13 +35,14 @@ public:
|
|||||||
friend SinkManager::Sink;
|
friend SinkManager::Sink;
|
||||||
|
|
||||||
Event<float> srChange;
|
Event<float> srChange;
|
||||||
|
SinkManager::Sink* sink;
|
||||||
|
int providerId = 0;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setSampleRate(float sampleRate);
|
void setSampleRate(float sampleRate);
|
||||||
|
|
||||||
dsp::stream<dsp::stereo_t>* _in;
|
dsp::stream<dsp::stereo_t>* _in;
|
||||||
dsp::Splitter<dsp::stereo_t> splitter;
|
dsp::Splitter<dsp::stereo_t> splitter;
|
||||||
SinkManager::Sink* sink;
|
|
||||||
std::mutex ctrlMtx;
|
std::mutex ctrlMtx;
|
||||||
float _sampleRate;
|
float _sampleRate;
|
||||||
|
|
||||||
@ -51,15 +58,19 @@ public:
|
|||||||
void registerStream(std::string name, Stream* stream);
|
void registerStream(std::string name, Stream* stream);
|
||||||
void unregisterStream(std::string name);
|
void unregisterStream(std::string name);
|
||||||
|
|
||||||
|
void startStream(std::string name);
|
||||||
|
void stopStream(std::string name);
|
||||||
|
|
||||||
|
void setStreamSink(std::string name, std::string providerName);
|
||||||
|
|
||||||
dsp::stream<dsp::stereo_t>* bindStream(std::string name);
|
dsp::stream<dsp::stereo_t>* bindStream(std::string name);
|
||||||
void unbindStream(std::string name, dsp::stream<dsp::stereo_t>* stream);
|
void unbindStream(std::string name, dsp::stream<dsp::stereo_t>* stream);
|
||||||
|
|
||||||
void showMenu();
|
void showMenu();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// TODO: Replace with std::unordered_map
|
|
||||||
std::map<std::string, SinkProvider> providers;
|
std::map<std::string, SinkProvider> providers;
|
||||||
std::map<std::string, Stream*> streams;
|
std::map<std::string, Stream*> streams;
|
||||||
|
std::vector<std::string> providerNames;
|
||||||
|
|
||||||
};
|
};
|
@ -30,7 +30,7 @@ public:
|
|||||||
handler.stream = &stream;
|
handler.stream = &stream;
|
||||||
sigpath::sourceManager.registerSource("File", &handler);
|
sigpath::sourceManager.registerSource("File", &handler);
|
||||||
|
|
||||||
reader = new WavReader("D:/Downloads/20120416_glv_594_2.wav");
|
reader = new WavReader("D:/satpic/raw_recordings/NOAA-18_09-08-2018_21-39-00_baseband_NR.wav");
|
||||||
|
|
||||||
spdlog::info("Samplerate: {0}, Bit depth: {1}, Channel count: {2}", reader->getSampleRate(), reader->getBitDepth(), reader->getChannelCount());
|
spdlog::info("Samplerate: {0}, Bit depth: {1}, Channel count: {2}", reader->getSampleRate(), reader->getBitDepth(), reader->getChannelCount());
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"Radio": {
|
"Radio": {
|
||||||
"device": "Speakers (Realtek High Definiti",
|
"device": "Speakers (Realtek High Definiti",
|
||||||
"sampleRate": 48000.0,
|
"sampleRate": 48000.0,
|
||||||
"volume": 0.385185182094574
|
"volume": 0.39259257912635803
|
||||||
},
|
},
|
||||||
"Radio 1": {
|
"Radio 1": {
|
||||||
"device": "Speakers (Realtek High Definition Audio)",
|
"device": "Speakers (Realtek High Definition Audio)",
|
||||||
@ -20,7 +20,7 @@
|
|||||||
"bandPlanEnabled": true,
|
"bandPlanEnabled": true,
|
||||||
"defaultSink": "Audio",
|
"defaultSink": "Audio",
|
||||||
"fftHeight": 296,
|
"fftHeight": 296,
|
||||||
"frequency": 14004144,
|
"frequency": 7300000,
|
||||||
"max": 0.0,
|
"max": 0.0,
|
||||||
"maximized": true,
|
"maximized": true,
|
||||||
"menuOrder": [
|
"menuOrder": [
|
||||||
@ -33,7 +33,7 @@
|
|||||||
"Display"
|
"Display"
|
||||||
],
|
],
|
||||||
"menuWidth": 300,
|
"menuWidth": 300,
|
||||||
"min": -63.235294342041016,
|
"min": -74.26470184326172,
|
||||||
"showWaterfall": true,
|
"showWaterfall": true,
|
||||||
"source": "",
|
"source": "",
|
||||||
"sourceSettings": {},
|
"sourceSettings": {},
|
||||||
|
@ -3,5 +3,7 @@
|
|||||||
"Recorder": "./recorder/Release/recorder.dll",
|
"Recorder": "./recorder/Release/recorder.dll",
|
||||||
"Soapy": "./soapy/Release/soapy.dll",
|
"Soapy": "./soapy/Release/soapy.dll",
|
||||||
"RTLTCPSource": "./rtl_tcp_source/Release/rtl_tcp_source.dll",
|
"RTLTCPSource": "./rtl_tcp_source/Release/rtl_tcp_source.dll",
|
||||||
"RX888Source": "./rx888_source/Release/rx888_source.dll"
|
"FileSource": "./file_source/Release/file_source.dll",
|
||||||
|
"RX888Source": "./rx888_source/Release/rx888_source.dll",
|
||||||
|
"AudioSink": "./audio_sink/Release/audio_sink.dll"
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"device": "Generic RTL2832U OEM :: 00000001",
|
"device": "CABLE Output (VB-Audio Virtual Cable)",
|
||||||
"devices": {
|
"devices": {
|
||||||
"AirSpy HF+ [c852435de0224af7]": {
|
"AirSpy HF+ [c852435de0224af7]": {
|
||||||
"gains": {
|
"gains": {
|
||||||
@ -8,6 +8,9 @@
|
|||||||
},
|
},
|
||||||
"sampleRate": 768000.0
|
"sampleRate": 768000.0
|
||||||
},
|
},
|
||||||
|
"CABLE Output (VB-Audio Virtual Cable)": {
|
||||||
|
"sampleRate": 96000.0
|
||||||
|
},
|
||||||
"Default Device": {
|
"Default Device": {
|
||||||
"sampleRate": 32000.0
|
"sampleRate": 32000.0
|
||||||
},
|
},
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
#define CONCAT(a, b) ((std::string(a) + b).c_str())
|
#define CONCAT(a, b) ((std::string(a) + b).c_str())
|
||||||
|
|
||||||
#define ADC_RATE 64000000
|
#define ADC_RATE 128000000
|
||||||
#define XFER_TIMEOUT 5000
|
#define XFER_TIMEOUT 5000
|
||||||
|
|
||||||
#define SEL0 (8) // SEL0 GPIO26
|
#define SEL0 (8) // SEL0 GPIO26
|
||||||
@ -170,7 +170,7 @@ private:
|
|||||||
// Check if the incomming data is bulk I/Q and end transfer
|
// Check if the incomming data is bulk I/Q and end transfer
|
||||||
if (EndPt->Attributes == 2) {
|
if (EndPt->Attributes == 2) {
|
||||||
if (EndPt->FinishDataXfer((PUCHAR)buffer, rLen, &inOvLap, context)) {
|
if (EndPt->FinishDataXfer((PUCHAR)buffer, rLen, &inOvLap, context)) {
|
||||||
if (_this->realStream.aquire() < 0) { return; }
|
if (_this->realStream.aquire() < 0) { break; }
|
||||||
memcpy(_this->realStream.data, buffer, rLen);
|
memcpy(_this->realStream.data, buffer, rLen);
|
||||||
_this->realStream.write(rLen / 2);
|
_this->realStream.write(rLen / 2);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user