1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-16 05:11:49 -05:00

Multiple audio support: moved AudioDeviceInfo in DSPEngine and added management methods to AudioDeviceInfo

This commit is contained in:
f4exb 2018-03-23 17:52:16 +01:00
parent ee027eda6a
commit f85111251b
9 changed files with 135 additions and 36 deletions

View File

@ -21,6 +21,8 @@
AudioDeviceInfo::AudioDeviceInfo() : AudioDeviceInfo::AudioDeviceInfo() :
m_inputDeviceIndex(-1), // default device m_inputDeviceIndex(-1), // default device
m_outputDeviceIndex(-1), // default device m_outputDeviceIndex(-1), // default device
m_audioOutputSampleRate(48000), // Use default output device at 48 kHz
m_audioInputSampleRate(48000), // Use default input device at 48 kHz
m_inputVolume(1.0f) m_inputVolume(1.0f)
{ {
m_inputDevicesInfo = QAudioDeviceInfo::availableDevices(QAudio::AudioInput); m_inputDevicesInfo = QAudioDeviceInfo::availableDevices(QAudio::AudioInput);
@ -82,3 +84,72 @@ void AudioDeviceInfo::setInputVolume(float inputVolume)
{ {
m_inputVolume = inputVolume < 0.0 ? 0.0 : inputVolume > 1.0 ? 1.0 : inputVolume; m_inputVolume = inputVolume < 0.0 ? 0.0 : inputVolume > 1.0 ? 1.0 : inputVolume;
} }
void AudioDeviceInfo::addAudioSink(AudioFifo* audioFifo)
{
qDebug("AudioDeviceInfo::addAudioSink");
m_audioOutput.addFifo(audioFifo);
}
void AudioDeviceInfo::removeAudioSink(AudioFifo* audioFifo)
{
qDebug("AudioDeviceInfo::removeAudioSink");
m_audioOutput.removeFifo(audioFifo);
}
void AudioDeviceInfo::addAudioSource(AudioFifo* audioFifo)
{
qDebug("AudioDeviceInfo::addAudioSource");
m_audioInput.addFifo(audioFifo);
}
void AudioDeviceInfo::removeAudioSource(AudioFifo* audioFifo)
{
qDebug("AudioDeviceInfo::removeAudioSource");
m_audioInput.removeFifo(audioFifo);
}
void AudioDeviceInfo::startAudioOutput()
{
m_audioOutput.start(m_outputDeviceIndex, m_audioOutputSampleRate);
m_audioOutputSampleRate = m_audioOutput.getRate(); // update with actual rate
}
void AudioDeviceInfo::stopAudioOutput()
{
m_audioOutput.stop();
}
void AudioDeviceInfo::startAudioOutputImmediate()
{
m_audioOutput.startImmediate(m_outputDeviceIndex, m_audioOutputSampleRate);
m_audioOutputSampleRate = m_audioOutput.getRate(); // update with actual rate
}
void AudioDeviceInfo::stopAudioOutputImmediate()
{
m_audioOutput.stopImmediate();
}
void AudioDeviceInfo::startAudioInput()
{
m_audioInput.start(m_inputDeviceIndex, m_audioInputSampleRate);
m_audioInputSampleRate = m_audioInput.getRate(); // update with actual rate
}
void AudioDeviceInfo::stopAudioInput()
{
m_audioInput.stop();
}
void AudioDeviceInfo::startAudioInputImmediate()
{
m_audioInput.startImmediate(m_inputDeviceIndex, m_audioInputSampleRate);
m_audioInputSampleRate = m_audioInput.getRate(); // update with actual rate
}
void AudioDeviceInfo::stopAudioInputImmediate()
{
m_audioInput.stopImmediate();
}

View File

@ -22,26 +22,55 @@
#include <QList> #include <QList>
#include <QAudioDeviceInfo> #include <QAudioDeviceInfo>
#include "audio/audioinput.h"
#include "audio/audiooutput.h"
#include "export.h" #include "export.h"
class AudioFifo;
class SDRBASE_API AudioDeviceInfo { class SDRBASE_API AudioDeviceInfo {
public: public:
AudioDeviceInfo(); AudioDeviceInfo();
const QList<QAudioDeviceInfo>& getInputDevices() const { return m_inputDevicesInfo; } const QList<QAudioDeviceInfo>& getInputDevices() const { return m_inputDevicesInfo; }
const QList<QAudioDeviceInfo>& getOutputDevices() const { return m_outputDevicesInfo; } const QList<QAudioDeviceInfo>& getOutputDevices() const { return m_outputDevicesInfo; }
int getInputDeviceIndex() const { return m_inputDeviceIndex; } int getInputDeviceIndex() const { return m_inputDeviceIndex; }
int getOutputDeviceIndex() const { return m_outputDeviceIndex; } int getOutputDeviceIndex() const { return m_outputDeviceIndex; }
float getInputVolume() const { return m_inputVolume; } float getInputVolume() const { return m_inputVolume; }
void setInputDeviceIndex(int inputDeviceIndex); void setInputDeviceIndex(int inputDeviceIndex);
void setOutputDeviceIndex(int inputDeviceIndex); void setOutputDeviceIndex(int inputDeviceIndex);
void setInputVolume(float inputVolume); void setInputVolume(float inputVolume);
unsigned int getAudioSampleRate() const { return m_audioOutputSampleRate; }
void addAudioSink(AudioFifo* audioFifo); //!< Add the audio sink
void removeAudioSink(AudioFifo* audioFifo); //!< Remove the audio sink
void addAudioSource(AudioFifo* audioFifo); //!< Add an audio source
void removeAudioSource(AudioFifo* audioFifo); //!< Remove an audio source
void startAudioOutput();
void stopAudioOutput();
void startAudioOutputImmediate();
void stopAudioOutputImmediate();
void startAudioInput();
void stopAudioInput();
void startAudioInputImmediate();
void stopAudioInputImmediate();
void setAudioInputVolume(float volume) { m_audioInput.setVolume(volume); }
private: private:
QList<QAudioDeviceInfo> m_inputDevicesInfo; QList<QAudioDeviceInfo> m_inputDevicesInfo;
QList<QAudioDeviceInfo> m_outputDevicesInfo; QList<QAudioDeviceInfo> m_outputDevicesInfo;
int m_inputDeviceIndex; int m_inputDeviceIndex;
int m_outputDeviceIndex; int m_outputDeviceIndex;
unsigned int m_audioOutputSampleRate;
unsigned int m_audioInputSampleRate;
AudioOutput m_audioOutput;
AudioInput m_audioInput;
float m_inputVolume; float m_inputVolume;
void resetToDefaults(); void resetToDefaults();

View File

@ -22,6 +22,7 @@
#include <QTimer> #include <QTimer>
#include <vector> #include <vector>
#include "audio/audiodeviceinfo.h"
#include "audio/audiooutput.h" #include "audio/audiooutput.h"
#include "audio/audioinput.h" #include "audio/audioinput.h"
#include "export.h" #include "export.h"
@ -48,6 +49,7 @@ public:
DSPDeviceSinkEngine *addDeviceSinkEngine(); DSPDeviceSinkEngine *addDeviceSinkEngine();
void removeLastDeviceSinkEngine(); void removeLastDeviceSinkEngine();
AudioDeviceInfo *getAudioDeviceInfo() { return &m_audioDeviceInfo; }
void startAudioOutput(); void startAudioOutput();
void stopAudioOutput(); void stopAudioOutput();
void startAudioOutputImmediate(); void startAudioOutputImmediate();
@ -93,6 +95,7 @@ private:
uint m_deviceSourceEnginesUIDSequence; uint m_deviceSourceEnginesUIDSequence;
std::vector<DSPDeviceSinkEngine*> m_deviceSinkEngines; std::vector<DSPDeviceSinkEngine*> m_deviceSinkEngines;
uint m_deviceSinkEnginesUIDSequence; uint m_deviceSinkEnginesUIDSequence;
AudioDeviceInfo m_audioDeviceInfo;
AudioOutput m_audioOutput; AudioOutput m_audioOutput;
AudioInput m_audioInput; AudioInput m_audioInput;
uint m_audioOutputSampleRate; uint m_audioOutputSampleRate;

View File

@ -97,7 +97,7 @@ MainWindow::MainWindow(qtwebapp::LoggerWithFile *logger, const MainParser& parse
qDebug() << "MainWindow::MainWindow: start"; qDebug() << "MainWindow::MainWindow: start";
m_instance = this; m_instance = this;
m_settings.setAudioDeviceInfo(&m_audioDeviceInfo); m_settings.setAudioDeviceInfo(m_dspEngine->getAudioDeviceInfo());
ui->setupUi(this); ui->setupUi(this);
createStatusBar(); createStatusBar();
@ -1412,11 +1412,11 @@ void MainWindow::on_action_Loaded_Plugins_triggered()
void MainWindow::on_action_Audio_triggered() void MainWindow::on_action_Audio_triggered()
{ {
AudioDialog audioDialog(&m_audioDeviceInfo, this); AudioDialog audioDialog(m_dspEngine->getAudioDeviceInfo(), this);
audioDialog.exec(); audioDialog.exec();
m_dspEngine->setAudioInputVolume(m_audioDeviceInfo.getInputVolume()); m_dspEngine->setAudioInputVolume(m_dspEngine->getAudioDeviceInfo()->getInputVolume());
m_dspEngine->setAudioInputDeviceIndex(m_audioDeviceInfo.getInputDeviceIndex()); m_dspEngine->setAudioInputDeviceIndex(m_dspEngine->getAudioDeviceInfo()->getInputDeviceIndex());
m_dspEngine->setAudioOutputDeviceIndex(m_audioDeviceInfo.getOutputDeviceIndex()); m_dspEngine->setAudioOutputDeviceIndex(m_dspEngine->getAudioDeviceInfo()->getOutputDeviceIndex());
} }
void MainWindow::on_action_Logging_triggered() void MainWindow::on_action_Logging_triggered()

View File

@ -33,7 +33,6 @@ class QTreeWidgetItem;
class QDir; class QDir;
class SamplingDeviceControl; class SamplingDeviceControl;
class AudioDeviceInfo;
class DSPEngine; class DSPEngine;
class DSPDeviceSourceEngine; class DSPDeviceSourceEngine;
class DSPDeviceSinkEngine; class DSPDeviceSinkEngine;
@ -303,7 +302,6 @@ private:
static MainWindow *m_instance; static MainWindow *m_instance;
Ui::MainWindow* ui; Ui::MainWindow* ui;
AudioDeviceInfo m_audioDeviceInfo;
MessageQueue m_inputMessageQueue; MessageQueue m_inputMessageQueue;
MainSettings m_settings; MainSettings m_settings;
std::vector<DeviceUISet*> m_deviceUIs; std::vector<DeviceUISet*> m_deviceUIs;

View File

@ -227,17 +227,17 @@ int WebAPIAdapterGUI::instanceAudioGet(
SWGSDRangel::SWGAudioDevices& response, SWGSDRangel::SWGAudioDevices& response,
SWGSDRangel::SWGErrorResponse& error __attribute__((unused))) SWGSDRangel::SWGErrorResponse& error __attribute__((unused)))
{ {
const QList<QAudioDeviceInfo>& audioInputDevices = m_mainWindow.m_audioDeviceInfo.getInputDevices(); const QList<QAudioDeviceInfo>& audioInputDevices = m_mainWindow.m_dspEngine->getAudioDeviceInfo()->getInputDevices();
const QList<QAudioDeviceInfo>& audioOutputDevices = m_mainWindow.m_audioDeviceInfo.getOutputDevices(); const QList<QAudioDeviceInfo>& audioOutputDevices = m_mainWindow.m_dspEngine->getAudioDeviceInfo()->getOutputDevices();
int nbInputDevices = audioInputDevices.size(); int nbInputDevices = audioInputDevices.size();
int nbOutputDevices = audioOutputDevices.size(); int nbOutputDevices = audioOutputDevices.size();
response.init(); response.init();
response.setNbInputDevices(nbInputDevices); response.setNbInputDevices(nbInputDevices);
response.setInputDeviceSelectedIndex(m_mainWindow.m_audioDeviceInfo.getInputDeviceIndex()); response.setInputDeviceSelectedIndex(m_mainWindow.m_dspEngine->getAudioDeviceInfo()->getInputDeviceIndex());
response.setNbOutputDevices(nbOutputDevices); response.setNbOutputDevices(nbOutputDevices);
response.setOutputDeviceSelectedIndex(m_mainWindow.m_audioDeviceInfo.getOutputDeviceIndex()); response.setOutputDeviceSelectedIndex(m_mainWindow.m_dspEngine->getAudioDeviceInfo()->getOutputDeviceIndex());
response.setInputVolume(m_mainWindow.m_audioDeviceInfo.getInputVolume()); response.setInputVolume(m_mainWindow.m_dspEngine->getAudioDeviceInfo()->getInputVolume());
QList<SWGSDRangel::SWGAudioDevice*> *inputDevices = response.getInputDevices(); QList<SWGSDRangel::SWGAudioDevice*> *inputDevices = response.getInputDevices();
QList<SWGSDRangel::SWGAudioDevice*> *outputDevices = response.getOutputDevices(); QList<SWGSDRangel::SWGAudioDevice*> *outputDevices = response.getOutputDevices();
@ -267,8 +267,8 @@ int WebAPIAdapterGUI::instanceAudioPatch(
int inputIndex = response.getInputIndex(); int inputIndex = response.getInputIndex();
int outputIndex = response.getOutputIndex(); int outputIndex = response.getOutputIndex();
const QList<QAudioDeviceInfo>& audioInputDevices = m_mainWindow.m_audioDeviceInfo.getInputDevices(); const QList<QAudioDeviceInfo>& audioInputDevices = m_mainWindow.m_dspEngine->getAudioDeviceInfo()->getInputDevices();
const QList<QAudioDeviceInfo>& audioOutputDevices = m_mainWindow.m_audioDeviceInfo.getOutputDevices(); const QList<QAudioDeviceInfo>& audioOutputDevices = m_mainWindow.m_dspEngine->getAudioDeviceInfo()->getOutputDevices();
int nbInputDevices = audioInputDevices.size(); int nbInputDevices = audioInputDevices.size();
int nbOutputDevices = audioOutputDevices.size(); int nbOutputDevices = audioOutputDevices.size();
@ -276,17 +276,17 @@ int WebAPIAdapterGUI::instanceAudioPatch(
inputIndex = inputIndex < -1 ? -1 : inputIndex > nbInputDevices ? nbInputDevices-1 : inputIndex; inputIndex = inputIndex < -1 ? -1 : inputIndex > nbInputDevices ? nbInputDevices-1 : inputIndex;
outputIndex = outputIndex < -1 ? -1 : outputIndex > nbOutputDevices ? nbOutputDevices-1 : outputIndex; outputIndex = outputIndex < -1 ? -1 : outputIndex > nbOutputDevices ? nbOutputDevices-1 : outputIndex;
m_mainWindow.m_audioDeviceInfo.setInputVolume(inputVolume); m_mainWindow.m_dspEngine->getAudioDeviceInfo()->setInputVolume(inputVolume);
m_mainWindow.m_audioDeviceInfo.setInputDeviceIndex(inputIndex); m_mainWindow.m_dspEngine->getAudioDeviceInfo()->setInputDeviceIndex(inputIndex);
m_mainWindow.m_audioDeviceInfo.setOutputDeviceIndex(outputIndex); m_mainWindow.m_dspEngine->getAudioDeviceInfo()->setOutputDeviceIndex(outputIndex);
m_mainWindow.m_dspEngine->setAudioInputVolume(inputVolume); m_mainWindow.m_dspEngine->setAudioInputVolume(inputVolume);
m_mainWindow.m_dspEngine->setAudioInputDeviceIndex(inputIndex); m_mainWindow.m_dspEngine->setAudioInputDeviceIndex(inputIndex);
m_mainWindow.m_dspEngine->setAudioOutputDeviceIndex(outputIndex); m_mainWindow.m_dspEngine->setAudioOutputDeviceIndex(outputIndex);
response.setInputVolume(m_mainWindow.m_audioDeviceInfo.getInputVolume()); response.setInputVolume(m_mainWindow.m_dspEngine->getAudioDeviceInfo()->getInputVolume());
response.setInputIndex(m_mainWindow.m_audioDeviceInfo.getInputDeviceIndex()); response.setInputIndex(m_mainWindow.m_dspEngine->getAudioDeviceInfo()->getInputDeviceIndex());
response.setOutputIndex(m_mainWindow.m_audioDeviceInfo.getOutputDeviceIndex()); response.setOutputIndex(m_mainWindow.m_dspEngine->getAudioDeviceInfo()->getOutputDeviceIndex());
return 200; return 200;
} }

View File

@ -59,7 +59,7 @@ MainCore::MainCore(qtwebapp::LoggerWithFile *logger, const MainParser& parser, Q
qDebug() << "MainCore::MainCore: start"; qDebug() << "MainCore::MainCore: start";
m_instance = this; m_instance = this;
m_settings.setAudioDeviceInfo(&m_audioDeviceInfo); m_settings.setAudioDeviceInfo(m_dspEngine->getAudioDeviceInfo());
m_pluginManager = new PluginManager(this); m_pluginManager = new PluginManager(this);
m_pluginManager->loadPlugins(QString("pluginssrv")); m_pluginManager->loadPlugins(QString("pluginssrv"));

View File

@ -28,7 +28,6 @@
#include "export.h" #include "export.h"
#include "mainparser.h" #include "mainparser.h"
class AudioDeviceInfo;
class DSPEngine; class DSPEngine;
class DSPDeviceSourceEngine; class DSPDeviceSourceEngine;
class DSPDeviceSinkEngine; class DSPDeviceSinkEngine;
@ -282,7 +281,6 @@ private:
QTimer m_masterTimer; QTimer m_masterTimer;
std::vector<DeviceSet*> m_deviceSets; std::vector<DeviceSet*> m_deviceSets;
PluginManager* m_pluginManager; PluginManager* m_pluginManager;
AudioDeviceInfo m_audioDeviceInfo;
WebAPIRequestMapper *m_requestMapper; WebAPIRequestMapper *m_requestMapper;
WebAPIServer *m_apiServer; WebAPIServer *m_apiServer;

View File

@ -228,17 +228,17 @@ int WebAPIAdapterSrv::instanceAudioGet(
SWGSDRangel::SWGAudioDevices& response, SWGSDRangel::SWGAudioDevices& response,
SWGSDRangel::SWGErrorResponse& error __attribute__((unused))) SWGSDRangel::SWGErrorResponse& error __attribute__((unused)))
{ {
const QList<QAudioDeviceInfo>& audioInputDevices = m_mainCore.m_audioDeviceInfo.getInputDevices(); const QList<QAudioDeviceInfo>& audioInputDevices = m_mainCore.m_dspEngine->getAudioDeviceInfo()->getInputDevices();
const QList<QAudioDeviceInfo>& audioOutputDevices = m_mainCore.m_audioDeviceInfo.getOutputDevices(); const QList<QAudioDeviceInfo>& audioOutputDevices = m_mainCore.m_dspEngine->getAudioDeviceInfo()->getOutputDevices();
int nbInputDevices = audioInputDevices.size(); int nbInputDevices = audioInputDevices.size();
int nbOutputDevices = audioOutputDevices.size(); int nbOutputDevices = audioOutputDevices.size();
response.init(); response.init();
response.setNbInputDevices(nbInputDevices); response.setNbInputDevices(nbInputDevices);
response.setInputDeviceSelectedIndex(m_mainCore.m_audioDeviceInfo.getInputDeviceIndex()); response.setInputDeviceSelectedIndex(m_mainCore.m_dspEngine->getAudioDeviceInfo()->getInputDeviceIndex());
response.setNbOutputDevices(nbOutputDevices); response.setNbOutputDevices(nbOutputDevices);
response.setOutputDeviceSelectedIndex(m_mainCore.m_audioDeviceInfo.getOutputDeviceIndex()); response.setOutputDeviceSelectedIndex(m_mainCore.m_dspEngine->getAudioDeviceInfo()->getOutputDeviceIndex());
response.setInputVolume(m_mainCore.m_audioDeviceInfo.getInputVolume()); response.setInputVolume(m_mainCore.m_dspEngine->getAudioDeviceInfo()->getInputVolume());
QList<SWGSDRangel::SWGAudioDevice*> *inputDevices = response.getInputDevices(); QList<SWGSDRangel::SWGAudioDevice*> *inputDevices = response.getInputDevices();
QList<SWGSDRangel::SWGAudioDevice*> *outputDevices = response.getOutputDevices(); QList<SWGSDRangel::SWGAudioDevice*> *outputDevices = response.getOutputDevices();
@ -268,8 +268,8 @@ int WebAPIAdapterSrv::instanceAudioPatch(
int inputIndex = response.getInputIndex(); int inputIndex = response.getInputIndex();
int outputIndex = response.getOutputIndex(); int outputIndex = response.getOutputIndex();
const QList<QAudioDeviceInfo>& audioInputDevices = m_mainCore.m_audioDeviceInfo.getInputDevices(); const QList<QAudioDeviceInfo>& audioInputDevices = m_mainCore.m_dspEngine->getAudioDeviceInfo()->getInputDevices();
const QList<QAudioDeviceInfo>& audioOutputDevices = m_mainCore.m_audioDeviceInfo.getOutputDevices(); const QList<QAudioDeviceInfo>& audioOutputDevices = m_mainCore.m_dspEngine->getAudioDeviceInfo()->getOutputDevices();
int nbInputDevices = audioInputDevices.size(); int nbInputDevices = audioInputDevices.size();
int nbOutputDevices = audioOutputDevices.size(); int nbOutputDevices = audioOutputDevices.size();
@ -277,17 +277,17 @@ int WebAPIAdapterSrv::instanceAudioPatch(
inputIndex = inputIndex < -1 ? -1 : inputIndex > nbInputDevices ? nbInputDevices-1 : inputIndex; inputIndex = inputIndex < -1 ? -1 : inputIndex > nbInputDevices ? nbInputDevices-1 : inputIndex;
outputIndex = outputIndex < -1 ? -1 : outputIndex > nbOutputDevices ? nbOutputDevices-1 : outputIndex; outputIndex = outputIndex < -1 ? -1 : outputIndex > nbOutputDevices ? nbOutputDevices-1 : outputIndex;
m_mainCore.m_audioDeviceInfo.setInputVolume(inputVolume); m_mainCore.m_dspEngine->getAudioDeviceInfo()->setInputVolume(inputVolume);
m_mainCore.m_audioDeviceInfo.setInputDeviceIndex(inputIndex); m_mainCore.m_dspEngine->getAudioDeviceInfo()->setInputDeviceIndex(inputIndex);
m_mainCore.m_audioDeviceInfo.setOutputDeviceIndex(outputIndex); m_mainCore.m_dspEngine->getAudioDeviceInfo()->setOutputDeviceIndex(outputIndex);
m_mainCore.m_dspEngine->setAudioInputVolume(inputVolume); m_mainCore.m_dspEngine->setAudioInputVolume(inputVolume);
m_mainCore.m_dspEngine->setAudioInputDeviceIndex(inputIndex); m_mainCore.m_dspEngine->setAudioInputDeviceIndex(inputIndex);
m_mainCore.m_dspEngine->setAudioOutputDeviceIndex(outputIndex); m_mainCore.m_dspEngine->setAudioOutputDeviceIndex(outputIndex);
response.setInputVolume(m_mainCore.m_audioDeviceInfo.getInputVolume()); response.setInputVolume(m_mainCore.m_dspEngine->getAudioDeviceInfo()->getInputVolume());
response.setInputIndex(m_mainCore.m_audioDeviceInfo.getInputDeviceIndex()); response.setInputIndex(m_mainCore.m_dspEngine->getAudioDeviceInfo()->getInputDeviceIndex());
response.setOutputIndex(m_mainCore.m_audioDeviceInfo.getOutputDeviceIndex()); response.setOutputIndex(m_mainCore.m_dspEngine->getAudioDeviceInfo()->getOutputDeviceIndex());
return 200; return 200;
} }