mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-12-17 23:28:50 -05:00
Multi device support: moved audio output multi client support to audio output object itself
This commit is contained in:
parent
83e1b84c38
commit
90b1fae799
@ -24,7 +24,8 @@
|
||||
|
||||
AudioOutput::AudioOutput() :
|
||||
m_mutex(),
|
||||
m_audioOutput(NULL),
|
||||
m_audioOutput(0),
|
||||
m_audioUsageCount(0),
|
||||
m_audioFifos()
|
||||
{
|
||||
}
|
||||
@ -47,73 +48,83 @@ bool AudioOutput::start(int device, int rate)
|
||||
{
|
||||
QMutexLocker mutexLocker(&m_mutex);
|
||||
|
||||
//Q_UNUSED(device);
|
||||
//Q_UNUSED(rate);
|
||||
|
||||
QAudioDeviceInfo devInfo;
|
||||
|
||||
if (device < 0)
|
||||
if (m_audioUsageCount == 0)
|
||||
{
|
||||
devInfo = QAudioDeviceInfo::defaultOutputDevice();
|
||||
qWarning("AudioOutput::start: using default device %s", qPrintable(devInfo.defaultOutputDevice().deviceName()));
|
||||
}
|
||||
else
|
||||
{
|
||||
QList<QAudioDeviceInfo> devicesInfo = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput);
|
||||
QAudioDeviceInfo devInfo;
|
||||
|
||||
if (device < devicesInfo.size())
|
||||
{
|
||||
devInfo = devicesInfo[device];
|
||||
qWarning("AudioOutput::start: using audio device #%d: %s", device, qPrintable(devInfo.defaultOutputDevice().deviceName()));
|
||||
}
|
||||
else
|
||||
{
|
||||
devInfo = QAudioDeviceInfo::defaultOutputDevice();
|
||||
qWarning("AudioOutput::start: audio device #%d does not exist. Using default device %s", device, qPrintable(devInfo.defaultOutputDevice().deviceName()));
|
||||
}
|
||||
if (device < 0)
|
||||
{
|
||||
devInfo = QAudioDeviceInfo::defaultOutputDevice();
|
||||
qWarning("AudioOutput::start: using default device %s", qPrintable(devInfo.defaultOutputDevice().deviceName()));
|
||||
}
|
||||
else
|
||||
{
|
||||
QList<QAudioDeviceInfo> devicesInfo = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput);
|
||||
|
||||
if (device < devicesInfo.size())
|
||||
{
|
||||
devInfo = devicesInfo[device];
|
||||
qWarning("AudioOutput::start: using audio device #%d: %s", device, qPrintable(devInfo.defaultOutputDevice().deviceName()));
|
||||
}
|
||||
else
|
||||
{
|
||||
devInfo = QAudioDeviceInfo::defaultOutputDevice();
|
||||
qWarning("AudioOutput::start: audio device #%d does not exist. Using default device %s", device, qPrintable(devInfo.defaultOutputDevice().deviceName()));
|
||||
}
|
||||
}
|
||||
|
||||
//QAudioDeviceInfo devInfo(QAudioDeviceInfo::defaultOutputDevice());
|
||||
|
||||
m_audioFormat.setSampleRate(rate);
|
||||
m_audioFormat.setChannelCount(2);
|
||||
m_audioFormat.setSampleSize(16);
|
||||
m_audioFormat.setCodec("audio/pcm");
|
||||
m_audioFormat.setByteOrder(QAudioFormat::LittleEndian);
|
||||
m_audioFormat.setSampleType(QAudioFormat::SignedInt);
|
||||
|
||||
if (!devInfo.isFormatSupported(m_audioFormat))
|
||||
{
|
||||
m_audioFormat = devInfo.nearestFormat(m_audioFormat);
|
||||
qWarning("AudioOutput::start: %d Hz S16_LE audio format not supported. New rate: %d", rate, m_audioFormat.sampleRate());
|
||||
}
|
||||
|
||||
if (m_audioFormat.sampleSize() != 16)
|
||||
{
|
||||
qWarning("AudioOutput::start: Audio device ( %s ) failed", qPrintable(devInfo.defaultOutputDevice().deviceName()));
|
||||
return false;
|
||||
}
|
||||
|
||||
m_audioOutput = new QAudioOutput(devInfo, m_audioFormat);
|
||||
|
||||
QIODevice::open(QIODevice::ReadOnly);
|
||||
|
||||
m_audioOutput->start(this);
|
||||
|
||||
if (m_audioOutput->state() != QAudio::ActiveState)
|
||||
{
|
||||
qWarning("AudioOutput::start: cannot start");
|
||||
}
|
||||
}
|
||||
|
||||
//QAudioDeviceInfo devInfo(QAudioDeviceInfo::defaultOutputDevice());
|
||||
|
||||
m_audioFormat.setSampleRate(rate);
|
||||
m_audioFormat.setChannelCount(2);
|
||||
m_audioFormat.setSampleSize(16);
|
||||
m_audioFormat.setCodec("audio/pcm");
|
||||
m_audioFormat.setByteOrder(QAudioFormat::LittleEndian);
|
||||
m_audioFormat.setSampleType(QAudioFormat::SignedInt);
|
||||
|
||||
if (!devInfo.isFormatSupported(m_audioFormat))
|
||||
{
|
||||
m_audioFormat = devInfo.nearestFormat(m_audioFormat);
|
||||
qWarning("AudioOutput::start: %d Hz S16_LE audio format not supported. New rate: %d", rate, m_audioFormat.sampleRate());
|
||||
}
|
||||
|
||||
if (m_audioFormat.sampleSize() != 16)
|
||||
{
|
||||
qWarning("AudioOutput::start: Audio device ( %s ) failed", qPrintable(devInfo.defaultOutputDevice().deviceName()));
|
||||
return false;
|
||||
}
|
||||
|
||||
m_audioOutput = new QAudioOutput(devInfo, m_audioFormat);
|
||||
|
||||
QIODevice::open(QIODevice::ReadOnly);
|
||||
|
||||
m_audioOutput->start(this);
|
||||
|
||||
if (m_audioOutput->state() != QAudio::ActiveState)
|
||||
{
|
||||
qWarning("AudioOutput::start: cannot start");
|
||||
}
|
||||
m_audioUsageCount++;
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
void AudioOutput::stop()
|
||||
{
|
||||
QMutexLocker mutexLocker(&m_mutex);
|
||||
QIODevice::close();
|
||||
delete m_audioOutput;
|
||||
|
||||
if (m_audioUsageCount > 0)
|
||||
{
|
||||
m_audioUsageCount--;
|
||||
|
||||
if (m_audioUsageCount == 0)
|
||||
{
|
||||
QIODevice::close();
|
||||
delete m_audioOutput;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AudioOutput::addFifo(AudioFifo* audioFifo)
|
||||
|
@ -45,6 +45,7 @@ public:
|
||||
private:
|
||||
QMutex m_mutex;
|
||||
QAudioOutput* m_audioOutput;
|
||||
uint m_audioUsageCount;
|
||||
|
||||
typedef std::list<AudioFifo*> AudioFifos;
|
||||
AudioFifos m_audioFifos;
|
||||
|
@ -21,10 +21,8 @@
|
||||
|
||||
DSPEngine::DSPEngine() :
|
||||
m_deviceEnginesUIDSequence(0),
|
||||
m_audioSampleRate(48000), // Use default output device at 48 kHz
|
||||
m_audioUsageCount(0)
|
||||
m_audioSampleRate(48000) // Use default output device at 48 kHz
|
||||
{
|
||||
//m_deviceEngines.push_back(new DSPDeviceEngine(0)); // TODO: multi device support
|
||||
m_dvSerialSupport = false;
|
||||
}
|
||||
|
||||
@ -88,26 +86,13 @@ void DSPEngine::stopAllDeviceEngines()
|
||||
|
||||
void DSPEngine::startAudio()
|
||||
{
|
||||
if (m_audioUsageCount == 0)
|
||||
{
|
||||
m_audioOutput.start(-1, m_audioSampleRate);
|
||||
m_audioSampleRate = m_audioOutput.getRate(); // update with actual rate
|
||||
}
|
||||
|
||||
m_audioUsageCount++;
|
||||
m_audioOutput.start(-1, m_audioSampleRate);
|
||||
m_audioSampleRate = m_audioOutput.getRate(); // update with actual rate
|
||||
}
|
||||
|
||||
void DSPEngine::stopAudio()
|
||||
{
|
||||
if (m_audioUsageCount > 0)
|
||||
{
|
||||
m_audioUsageCount--;
|
||||
|
||||
if (m_audioUsageCount == 0)
|
||||
{
|
||||
m_audioOutput.stop();
|
||||
}
|
||||
}
|
||||
m_audioOutput.stop();
|
||||
}
|
||||
|
||||
void DSPEngine::startAudioImmediate()
|
||||
|
@ -89,7 +89,6 @@ private:
|
||||
AudioOutput m_audioOutput;
|
||||
uint m_audioSampleRate;
|
||||
bool m_dvSerialSupport;
|
||||
uint m_audioUsageCount;
|
||||
#ifdef DSD_USE_SERIALDV
|
||||
DVSerialEngine m_dvSerialEngine;
|
||||
#endif
|
||||
|
@ -223,9 +223,18 @@ void MainWindow::removeLastDevice()
|
||||
|
||||
ui->tabChannels->removeTab(ui->tabChannels->count() - 1);
|
||||
|
||||
ui->tabInputsView->removeTab(ui->tabInputsView->count() - 1);
|
||||
ui->tabInputsSelect->removeTab(ui->tabInputsSelect->count() - 1);
|
||||
|
||||
m_deviceWidgetTabs.removeLast();
|
||||
ui->tabInputsView->clear();
|
||||
|
||||
for (int i = 0; i < m_deviceWidgetTabs.size(); i++)
|
||||
{
|
||||
qDebug("MainWindow::removeLastDevice: adding back tab for %s", m_deviceWidgetTabs[i].displayName.toStdString().c_str());
|
||||
ui->tabInputsView->addTab(m_deviceWidgetTabs[i].gui, m_deviceWidgetTabs[i].tabName);
|
||||
ui->tabInputsView->setTabToolTip(i, m_deviceWidgetTabs[i].displayName);
|
||||
}
|
||||
|
||||
delete m_deviceUIs.back();
|
||||
|
||||
lastDeviceEngine->stop();
|
||||
|
Loading…
Reference in New Issue
Block a user