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

pull/154/head
f4exb 2018-03-23 17:52:16 +01:00
rodzic ee027eda6a
commit f85111251b
9 zmienionych plików z 135 dodań i 36 usunięć

Wyświetl plik

@ -21,6 +21,8 @@
AudioDeviceInfo::AudioDeviceInfo() :
m_inputDeviceIndex(-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_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;
}
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();
}

Wyświetl plik

@ -22,26 +22,55 @@
#include <QList>
#include <QAudioDeviceInfo>
#include "audio/audioinput.h"
#include "audio/audiooutput.h"
#include "export.h"
class AudioFifo;
class SDRBASE_API AudioDeviceInfo {
public:
AudioDeviceInfo();
const QList<QAudioDeviceInfo>& getInputDevices() const { return m_inputDevicesInfo; }
const QList<QAudioDeviceInfo>& getOutputDevices() const { return m_outputDevicesInfo; }
int getInputDeviceIndex() const { return m_inputDeviceIndex; }
int getOutputDeviceIndex() const { return m_outputDeviceIndex; }
float getInputVolume() const { return m_inputVolume; }
void setInputDeviceIndex(int inputDeviceIndex);
void setOutputDeviceIndex(int inputDeviceIndex);
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:
QList<QAudioDeviceInfo> m_inputDevicesInfo;
QList<QAudioDeviceInfo> m_outputDevicesInfo;
int m_inputDeviceIndex;
int m_outputDeviceIndex;
unsigned int m_audioOutputSampleRate;
unsigned int m_audioInputSampleRate;
AudioOutput m_audioOutput;
AudioInput m_audioInput;
float m_inputVolume;
void resetToDefaults();

Wyświetl plik

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

Wyświetl plik

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

Wyświetl plik

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

Wyświetl plik

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

Wyświetl plik

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

Wyświetl plik

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

Wyświetl plik

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