more work

This commit is contained in:
AlexandreRouma
2023-07-09 18:34:52 +02:00
parent 2a741932e0
commit 4c584847de
13 changed files with 131 additions and 126 deletions

View File

@ -35,6 +35,9 @@ namespace streamsmenu {
sink->showMenu();
// Volume slider + mute button
ImGui::FillWidth();
if (ImGui::Button(CONCAT("Remove##sdrpp_streams_remove_type_", name))) {
sinksToBeRemoved.push_back(id);
@ -50,7 +53,7 @@ namespace streamsmenu {
ImGui::SameLine();
ImGui::FillWidth();
if (ImGui::Button(CONCAT("Add##sdrpp_streams_add_btn_", name))) {
stream->addSink("Sink 2");
stream->addSink("Audio");
}
ImGui::EndTable();

View File

@ -144,7 +144,6 @@ AudioStream::AudioStream(StreamManager* manager, const std::string& name, dsp::s
// Initialize DSP
split.init(stream);
split.start();
}
AudioStream::~AudioStream() {
@ -173,11 +172,14 @@ void AudioStream::setInput(dsp::stream<dsp::stereo_t>* stream, double samplerate
this->samplerate = samplerate;
// Stop DSP
split.stop();
for (auto& [id, sink] : sinks) {
sink->stopDSP();
if (running) {
split.stop();
for (auto& [id, sink] : sinks) {
sink->stopDSP();
}
}
// Set input and samplerate
split.setInput(stream);
for (auto& [id, sink] : sinks) {
@ -185,10 +187,12 @@ void AudioStream::setInput(dsp::stream<dsp::stereo_t>* stream, double samplerate
}
// Start DSP
for (auto& [id, sink] : sinks) {
sink->startDSP();
if (running) {
for (auto& [id, sink] : sinks) {
sink->startDSP();
}
split.start();
}
split.start();
}
void AudioStream::setSamplerate(double samplerate) {
@ -198,9 +202,11 @@ void AudioStream::setSamplerate(double samplerate) {
this->samplerate = samplerate;
// Stop DSP
split.stop();
for (auto& [id, sink] : sinks) {
sink->stopDSP();
if (running) {
split.stop();
for (auto& [id, sink] : sinks) {
sink->stopDSP();
}
}
// Set samplerate
@ -209,10 +215,12 @@ void AudioStream::setSamplerate(double samplerate) {
}
// Start DSP
for (auto& [id, sink] : sinks) {
sink->startDSP();
if (running) {
for (auto& [id, sink] : sinks) {
sink->startDSP();
}
split.start();
}
split.start();
}
const std::string& AudioStream::getName() const {
@ -246,7 +254,7 @@ SinkID AudioStream::addSink(const std::string& type, SinkID id) {
// Start the sink and DSP
sink->startSink();
sink->startDSP();
if (running) { sink->startDSP(); }
// Bind the sinks's input
split.bindStream(&sink->input);
@ -313,6 +321,36 @@ const std::map<SinkID, std::shared_ptr<SinkEntry>>& AudioStream::getSinks() cons
return sinks;
}
void AudioStream::startDSP() {
// TODO: Maybe add a different mutex for the stream?
std::unique_lock<std::shared_mutex> lck(sinksMtx);
// Check if already running
if (running) { return; }
// Start all DSP
split.start();
for (auto& [id, sink] : sinks) {
sink->startDSP();
}
running = true;
}
void AudioStream::stopDSP() {
// TODO: Maybe add a different mutex for the stream?
std::unique_lock<std::shared_mutex> lck(sinksMtx);
// Check if already running
if (!running) { return; }
// Start all DSP
split.stop();
for (auto& [id, sink] : sinks) {
sink->stopDSP();
}
running = false;
}
std::shared_ptr<AudioStream> StreamManager::createStream(const std::string& name, dsp::stream<dsp::stereo_t>* stream, double samplerate) {
std::unique_lock<std::shared_mutex> lck(streamsMtx);

View File

@ -146,7 +146,6 @@ private:
dsp::multirate::RationalResampler<dsp::stereo_t> resamp;
dsp::audio::Volume volumeAdjust;
SinkProvider* provider = NULL;
std::unique_ptr<Sink> sink;
std::string type;
@ -216,6 +215,18 @@ public:
*/
const std::map<SinkID, std::shared_ptr<SinkEntry>>& getSinks() const;
// TODO: This should only be callable by the module that created the stream
/**
* Start the DSP.
*/
void startDSP();
/**
* Stop the DSP.
*/
void stopDSP();
// Emitted when the samplerate of the stream was changed
NewEvent<double> onSamplerateChanged;
// Emitted when a sink was added
@ -228,6 +239,7 @@ private:
const std::string name;
double samplerate;
dsp::routing::Splitter<dsp::stereo_t> split;
bool running = false;
std::map<SinkID, std::shared_ptr<SinkEntry>> sinks;
std::shared_mutex sinksMtx;