mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-26 01:39:05 -05:00
Multiple audio support: use device names for sample rates and volumes maps
This commit is contained in:
parent
a4b6edbf07
commit
c500b1853b
@ -18,8 +18,9 @@
|
||||
#include <audio/audiodevicemanager.h>
|
||||
#include "util/simpleserializer.h"
|
||||
|
||||
AudioDeviceManager::AudioDeviceManager(unsigned int defaultAudioSampleRate) :
|
||||
m_defaultAudioSampleRate(defaultAudioSampleRate)
|
||||
const float AudioDeviceManager::m_defaultAudioInputVolume = 0.15f;
|
||||
|
||||
AudioDeviceManager::AudioDeviceManager()
|
||||
{
|
||||
m_inputDevicesInfo = QAudioDeviceInfo::availableDevices(QAudio::AudioInput);
|
||||
m_outputDevicesInfo = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput);
|
||||
@ -34,6 +35,48 @@ AudioDeviceManager::~AudioDeviceManager()
|
||||
}
|
||||
}
|
||||
|
||||
bool AudioDeviceManager::getOutputDeviceName(int outputDeviceIndex, QString &deviceName) const
|
||||
{
|
||||
if (outputDeviceIndex < 0)
|
||||
{
|
||||
deviceName = "System default device";
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (outputDeviceIndex < m_outputDevicesInfo.size())
|
||||
{
|
||||
deviceName = m_outputDevicesInfo[outputDeviceIndex].deviceName();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool AudioDeviceManager::getInputDeviceName(int inputDeviceIndex, QString &deviceName) const
|
||||
{
|
||||
if (inputDeviceIndex < 0)
|
||||
{
|
||||
deviceName = "System default device";
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (inputDeviceIndex < m_inputDevicesInfo.size())
|
||||
{
|
||||
deviceName = m_inputDevicesInfo[inputDeviceIndex].deviceName();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AudioDeviceManager::resetToDefaults()
|
||||
{
|
||||
}
|
||||
@ -68,10 +111,8 @@ void AudioDeviceManager::addAudioSink(AudioFifo* audioFifo, int outputDeviceInde
|
||||
{
|
||||
qDebug("AudioDeviceManager::addAudioSink: %d: %p", outputDeviceIndex, audioFifo);
|
||||
|
||||
if (m_audioOutputs.find(outputDeviceIndex) == m_audioOutputs.end())
|
||||
{
|
||||
if (m_audioOutputs.find(outputDeviceIndex) == m_audioOutputs.end()) {
|
||||
m_audioOutputs[outputDeviceIndex] = new AudioOutput();
|
||||
m_audioOutputSampleRates[outputDeviceIndex] = m_defaultAudioSampleRate;
|
||||
}
|
||||
|
||||
if (m_audioOutputs[outputDeviceIndex]->getNbFifos() == 0) {
|
||||
@ -120,10 +161,8 @@ void AudioDeviceManager::addAudioSource(AudioFifo* audioFifo, int inputDeviceInd
|
||||
{
|
||||
qDebug("AudioDeviceManager::addAudioSource: %d: %p", inputDeviceIndex, audioFifo);
|
||||
|
||||
if (m_audioInputs.find(inputDeviceIndex) == m_audioInputs.end())
|
||||
{
|
||||
if (m_audioInputs.find(inputDeviceIndex) == m_audioInputs.end()) {
|
||||
m_audioInputs[inputDeviceIndex] = new AudioInput();
|
||||
m_audioInputSampleRates[inputDeviceIndex] = m_defaultAudioSampleRate;
|
||||
}
|
||||
|
||||
if (m_audioInputs[inputDeviceIndex]->getNbFifos() == 0) {
|
||||
@ -170,8 +209,24 @@ void AudioDeviceManager::removeAudioSource(AudioFifo* audioFifo)
|
||||
|
||||
void AudioDeviceManager::startAudioOutput(int outputDeviceIndex)
|
||||
{
|
||||
m_audioOutputs[outputDeviceIndex]->start(outputDeviceIndex, m_audioOutputSampleRates[outputDeviceIndex]);
|
||||
m_audioOutputSampleRates[outputDeviceIndex] = m_audioOutputs[outputDeviceIndex]->getRate(); // update with actual rate
|
||||
unsigned int sampleRate;
|
||||
QString deviceName;
|
||||
|
||||
if (getOutputDeviceName(outputDeviceIndex, deviceName))
|
||||
{
|
||||
if (m_audioOutputSampleRates.find(deviceName) == m_audioOutputSampleRates.end()) {
|
||||
sampleRate = m_defaultAudioSampleRate;
|
||||
} else {
|
||||
sampleRate = m_audioOutputSampleRates[deviceName];
|
||||
}
|
||||
|
||||
m_audioOutputs[outputDeviceIndex]->start(outputDeviceIndex, sampleRate);
|
||||
m_audioOutputSampleRates[deviceName] = m_audioOutputs[outputDeviceIndex]->getRate(); // update with actual rate
|
||||
}
|
||||
else
|
||||
{
|
||||
qWarning("AudioDeviceManager::startAudioOutput: unknown device index %d", outputDeviceIndex);
|
||||
}
|
||||
}
|
||||
|
||||
void AudioDeviceManager::stopAudioOutput(int outputDeviceIndex)
|
||||
@ -181,8 +236,32 @@ void AudioDeviceManager::stopAudioOutput(int outputDeviceIndex)
|
||||
|
||||
void AudioDeviceManager::startAudioInput(int inputDeviceIndex)
|
||||
{
|
||||
m_audioInputs[inputDeviceIndex]->start(inputDeviceIndex, m_audioInputSampleRates[inputDeviceIndex]);
|
||||
m_audioInputSampleRates[inputDeviceIndex] = m_audioInputs[inputDeviceIndex]->getRate(); // update with actual rate
|
||||
unsigned int sampleRate;
|
||||
float volume;
|
||||
QString deviceName;
|
||||
|
||||
if (getInputDeviceName(inputDeviceIndex, deviceName))
|
||||
{
|
||||
if (m_audioInputSampleRates.find(deviceName) == m_audioInputSampleRates.end()) {
|
||||
sampleRate = m_defaultAudioSampleRate;
|
||||
} else {
|
||||
sampleRate = m_audioInputSampleRates[deviceName];
|
||||
}
|
||||
|
||||
if (m_audioInputVolumes.find(deviceName) == m_audioInputVolumes.end()) {
|
||||
volume = m_defaultAudioInputVolume;
|
||||
} else {
|
||||
volume = m_audioInputVolumes[deviceName];
|
||||
}
|
||||
|
||||
m_audioInputs[inputDeviceIndex]->start(inputDeviceIndex, sampleRate);
|
||||
m_audioInputSampleRates[deviceName] = m_audioInputs[inputDeviceIndex]->getRate(); // update with actual rate
|
||||
m_audioInputs[inputDeviceIndex]->setVolume(volume);
|
||||
}
|
||||
else
|
||||
{
|
||||
qWarning("AudioDeviceManager::startAudioInput: unknown device index %d", inputDeviceIndex);
|
||||
}
|
||||
}
|
||||
|
||||
void AudioDeviceManager::stopAudioInput(int inputDeviceIndex)
|
||||
|
@ -31,31 +31,37 @@ class AudioFifo;
|
||||
|
||||
class SDRBASE_API AudioDeviceManager {
|
||||
public:
|
||||
AudioDeviceManager(unsigned int defaultAudioSampleRate);
|
||||
AudioDeviceManager();
|
||||
~AudioDeviceManager();
|
||||
|
||||
|
||||
const QList<QAudioDeviceInfo>& getInputDevices() const { return m_inputDevicesInfo; }
|
||||
const QList<QAudioDeviceInfo>& getOutputDevices() const { return m_outputDevicesInfo; }
|
||||
|
||||
bool getOutputDeviceName(int outputDeviceIndex, QString &deviceName) const;
|
||||
bool getInputDeviceName(int outputDeviceIndex, QString &deviceName) const;
|
||||
|
||||
void addAudioSink(AudioFifo* audioFifo, int outputDeviceIndex = -1); //!< Add the audio sink
|
||||
void removeAudioSink(AudioFifo* audioFifo); //!< Remove the audio sink
|
||||
|
||||
void addAudioSource(AudioFifo* audioFifo, int inputDeviceIndex = -1); //!< Add an audio source
|
||||
void removeAudioSource(AudioFifo* audioFifo); //!< Remove an audio source
|
||||
|
||||
static const unsigned int m_defaultAudioSampleRate = 48000;
|
||||
static const float m_defaultAudioInputVolume;
|
||||
private:
|
||||
unsigned int m_defaultAudioSampleRate;
|
||||
|
||||
QList<QAudioDeviceInfo> m_inputDevicesInfo;
|
||||
QList<QAudioDeviceInfo> m_outputDevicesInfo;
|
||||
|
||||
QMap<AudioFifo*, int> m_audioSinkFifos; //< Audio sink FIFO to audio output device index-1 map
|
||||
QMap<int, AudioOutput*> m_audioOutputs; //!< audio device index-1 to audio output map (index -1 is default device)
|
||||
QMap<int, unsigned int> m_audioOutputSampleRates; //!< audio device index-1 to audio sample rate
|
||||
QMap<int, AudioOutput*> m_audioOutputs; //!< audio device index to audio output map (index -1 is default device)
|
||||
QMap<QString, unsigned int> m_audioOutputSampleRates; //!< audio device name to audio sample rate
|
||||
|
||||
QMap<AudioFifo*, int> m_audioSourceFifos; //< Audio source FIFO to audio input device index-1 map
|
||||
QMap<int, AudioInput*> m_audioInputs; //!< audio device index-1 to audio input map (index -1 is default device)
|
||||
QMap<int, unsigned int> m_audioInputSampleRates; //!< audio device index-1 to audio sample rate
|
||||
QMap<int, AudioInput*> m_audioInputs; //!< audio device index to audio input map (index -1 is default device)
|
||||
QMap<QString, unsigned int> m_audioInputSampleRates; //!< audio device name to audio sample rate
|
||||
QMap<QString, float> m_audioInputVolumes; //!< audio device name to input volume
|
||||
|
||||
void resetToDefaults();
|
||||
QByteArray serialize() const;
|
||||
|
@ -26,7 +26,6 @@
|
||||
DSPEngine::DSPEngine() :
|
||||
m_deviceSourceEnginesUIDSequence(0),
|
||||
m_deviceSinkEnginesUIDSequence(0),
|
||||
m_audioDeviceManager(m_defaultAudioSampleRate),
|
||||
m_audioInputDeviceIndex(-1), // default device
|
||||
m_audioOutputDeviceIndex(-1) // default device
|
||||
{
|
||||
|
@ -41,7 +41,7 @@ public:
|
||||
|
||||
static DSPEngine *instance();
|
||||
|
||||
unsigned int getDefaultAudioSampleRate() const { return m_defaultAudioSampleRate; }
|
||||
unsigned int getDefaultAudioSampleRate() const { return AudioDeviceManager::m_defaultAudioSampleRate; }
|
||||
|
||||
DSPDeviceSourceEngine *addDeviceSourceEngine();
|
||||
void removeLastDeviceSourceEngine();
|
||||
@ -82,7 +82,6 @@ private:
|
||||
int m_audioOutputDeviceIndex;
|
||||
QTimer m_masterTimer;
|
||||
bool m_dvSerialSupport;
|
||||
static const unsigned int m_defaultAudioSampleRate = 48000;
|
||||
#ifdef DSD_USE_SERIALDV
|
||||
DVSerialEngine m_dvSerialEngine;
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user