More work on the sink interface

pull/40/head
Ryzerth 2020-11-22 18:26:48 +01:00
rodzic f1084157a3
commit 61a612cf30
11 zmienionych plików z 195 dodań i 13 usunięć

Wyświetl plik

@ -8,7 +8,7 @@ add_subdirectory("recorder")
add_subdirectory("soapy")
add_subdirectory("file_source")
add_subdirectory("rtl_tcp_source")
# add_subdirectory("audio_sink")
add_subdirectory("audio_sink")
add_subdirectory("rx888_source")
add_subdirectory("demo")

Wyświetl plik

@ -3,16 +3,84 @@
#include <gui/gui.h>
#include <signal_path/signal_path.h>
#include <signal_path/sink.h>
#include <portaudio.h>
#include <dsp/audio.h>
#define CONCAT(a, b) ((std::string(a) + b).c_str())
class AudioSink : SinkManager::Sink {
public:
struct AudioDevice_t {
std::string name;
int index;
int channels;
std::vector<double> sampleRates;
std::string txtSampleRates;
};
AudioSink(SinkManager::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() {
}
void start() {
}
void stop() {
}
@ -21,7 +89,32 @@ public:
}
private:
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;
};

Wyświetl plik

@ -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();
}
};

Wyświetl plik

@ -0,0 +1,6 @@
#pragma once
namespace sinkmenu {
void init();
void draw(void* ctx);
};

Wyświetl plik

@ -1,5 +1,6 @@
#include <signal_path/sink.h>
#include <spdlog/spdlog.h>
#include <imgui/imgui.h>
#include <core.h>
SinkManager::SinkManager() {
@ -13,6 +14,14 @@ SinkManager::Stream::Stream(dsp::stream<dsp::stereo_t>* in, const Event<float>::
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) {
std::lock_guard<std::mutex> lck(ctrlMtx);
_in = in;
@ -42,6 +51,7 @@ void SinkManager::registerSinkProvider(std::string name, SinkProvider provider)
return;
}
providers[name] = provider;
providerNames.push_back(name);
}
void SinkManager::registerStream(std::string name, SinkManager::Stream* stream) {
@ -75,6 +85,22 @@ void SinkManager::unregisterStream(std::string name) {
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) {
if (streams.find(name) == streams.end()) {
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);
}
void SinkManager::setStreamSink(std::string name, std::string providerName) {
}
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();
}
}

Wyświetl plik

@ -6,6 +6,7 @@
#include <dsp/routing.h>
#include <mutex>
#include <event.h>
#include <vector>
class SinkManager {
public:
@ -13,6 +14,8 @@ public:
class Sink {
public:
virtual void start() = 0;
virtual void stop() = 0;
virtual void menuHandler() = 0;
};
@ -20,6 +23,9 @@ public:
public:
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);
dsp::stream<dsp::stereo_t>* bindStream();
@ -29,13 +35,14 @@ public:
friend SinkManager::Sink;
Event<float> srChange;
SinkManager::Sink* sink;
int providerId = 0;
private:
void setSampleRate(float sampleRate);
dsp::stream<dsp::stereo_t>* _in;
dsp::Splitter<dsp::stereo_t> splitter;
SinkManager::Sink* sink;
std::mutex ctrlMtx;
float _sampleRate;
@ -51,15 +58,19 @@ public:
void registerStream(std::string name, Stream* stream);
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);
void unbindStream(std::string name, dsp::stream<dsp::stereo_t>* stream);
void showMenu();
private:
// TODO: Replace with std::unordered_map
std::map<std::string, SinkProvider> providers;
std::map<std::string, Stream*> streams;
std::vector<std::string> providerNames;
};

Wyświetl plik

@ -30,7 +30,7 @@ public:
handler.stream = &stream;
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());

Wyświetl plik

@ -3,7 +3,7 @@
"Radio": {
"device": "Speakers (Realtek High Definiti",
"sampleRate": 48000.0,
"volume": 0.385185182094574
"volume": 0.39259257912635803
},
"Radio 1": {
"device": "Speakers (Realtek High Definition Audio)",
@ -20,7 +20,7 @@
"bandPlanEnabled": true,
"defaultSink": "Audio",
"fftHeight": 296,
"frequency": 14004144,
"frequency": 7300000,
"max": 0.0,
"maximized": true,
"menuOrder": [
@ -33,7 +33,7 @@
"Display"
],
"menuWidth": 300,
"min": -63.235294342041016,
"min": -74.26470184326172,
"showWaterfall": true,
"source": "",
"sourceSettings": {},

Wyświetl plik

@ -3,5 +3,7 @@
"Recorder": "./recorder/Release/recorder.dll",
"Soapy": "./soapy/Release/soapy.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"
}

Wyświetl plik

@ -1,5 +1,5 @@
{
"device": "Generic RTL2832U OEM :: 00000001",
"device": "CABLE Output (VB-Audio Virtual Cable)",
"devices": {
"AirSpy HF+ [c852435de0224af7]": {
"gains": {
@ -8,6 +8,9 @@
},
"sampleRate": 768000.0
},
"CABLE Output (VB-Audio Virtual Cable)": {
"sampleRate": 96000.0
},
"Default Device": {
"sampleRate": 32000.0
},

Wyświetl plik

@ -11,7 +11,7 @@
#define CONCAT(a, b) ((std::string(a) + b).c_str())
#define ADC_RATE 64000000
#define ADC_RATE 128000000
#define XFER_TIMEOUT 5000
#define SEL0 (8) // SEL0 GPIO26
@ -170,7 +170,7 @@ private:
// Check if the incomming data is bulk I/Q and end transfer
if (EndPt->Attributes == 2) {
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);
_this->realStream.write(rLen / 2);
}