mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-26 01:39:05 -05:00
Multiple audio support: serialization and deserialization of audio data
This commit is contained in:
parent
c500b1853b
commit
bfce9a4fcc
@ -1,270 +1,358 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2017 F4EXB //
|
||||
// written by Edouard Griffiths //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation as version 3 of the License, or //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License V3 for more details. //
|
||||
// //
|
||||
// You should have received a copy of the GNU General Public License //
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <audio/audiodevicemanager.h>
|
||||
#include "util/simpleserializer.h"
|
||||
|
||||
const float AudioDeviceManager::m_defaultAudioInputVolume = 0.15f;
|
||||
|
||||
AudioDeviceManager::AudioDeviceManager()
|
||||
{
|
||||
m_inputDevicesInfo = QAudioDeviceInfo::availableDevices(QAudio::AudioInput);
|
||||
m_outputDevicesInfo = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput);
|
||||
}
|
||||
|
||||
AudioDeviceManager::~AudioDeviceManager()
|
||||
{
|
||||
QMap<int, AudioOutput*>::iterator it = m_audioOutputs.begin();
|
||||
|
||||
for (; it != m_audioOutputs.end(); ++it) {
|
||||
delete(*it);
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
}
|
||||
|
||||
QByteArray AudioDeviceManager::serialize() const
|
||||
{
|
||||
SimpleSerializer s(1);
|
||||
return s.final();
|
||||
}
|
||||
|
||||
bool AudioDeviceManager::deserialize(const QByteArray& data)
|
||||
{
|
||||
SimpleDeserializer d(data);
|
||||
|
||||
if(!d.isValid()) {
|
||||
resetToDefaults();
|
||||
return false;
|
||||
}
|
||||
|
||||
if(d.getVersion() == 1)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
resetToDefaults();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void AudioDeviceManager::addAudioSink(AudioFifo* audioFifo, int outputDeviceIndex)
|
||||
{
|
||||
qDebug("AudioDeviceManager::addAudioSink: %d: %p", outputDeviceIndex, audioFifo);
|
||||
|
||||
if (m_audioOutputs.find(outputDeviceIndex) == m_audioOutputs.end()) {
|
||||
m_audioOutputs[outputDeviceIndex] = new AudioOutput();
|
||||
}
|
||||
|
||||
if (m_audioOutputs[outputDeviceIndex]->getNbFifos() == 0) {
|
||||
startAudioOutput(outputDeviceIndex);
|
||||
}
|
||||
|
||||
if (m_audioSinkFifos.find(audioFifo) == m_audioSinkFifos.end()) // new FIFO
|
||||
{
|
||||
m_audioOutputs[outputDeviceIndex]->addFifo(audioFifo);
|
||||
}
|
||||
else
|
||||
{
|
||||
int audioOutputDeviceIndex = m_audioSinkFifos[audioFifo];
|
||||
|
||||
if (audioOutputDeviceIndex != outputDeviceIndex) // change of audio device
|
||||
{
|
||||
removeAudioSink(audioFifo); // remove from current
|
||||
m_audioOutputs[outputDeviceIndex]->addFifo(audioFifo); // add to new
|
||||
}
|
||||
}
|
||||
|
||||
m_audioSinkFifos[audioFifo] = outputDeviceIndex; // register audio FIFO
|
||||
}
|
||||
|
||||
void AudioDeviceManager::removeAudioSink(AudioFifo* audioFifo)
|
||||
{
|
||||
qDebug("AudioDeviceManager::removeAudioSink: %p", audioFifo);
|
||||
|
||||
if (m_audioSinkFifos.find(audioFifo) == m_audioSinkFifos.end())
|
||||
{
|
||||
qWarning("AudioDeviceManager::removeAudioSink: audio FIFO %p not found", audioFifo);
|
||||
return;
|
||||
}
|
||||
|
||||
int audioOutputDeviceIndex = m_audioSinkFifos[audioFifo];
|
||||
m_audioOutputs[audioOutputDeviceIndex]->removeFifo(audioFifo);
|
||||
|
||||
if (m_audioOutputs[audioOutputDeviceIndex]->getNbFifos() == 0) {
|
||||
stopAudioOutput(audioOutputDeviceIndex);
|
||||
}
|
||||
|
||||
m_audioSinkFifos.remove(audioFifo); // unregister audio FIFO
|
||||
}
|
||||
|
||||
void AudioDeviceManager::addAudioSource(AudioFifo* audioFifo, int inputDeviceIndex)
|
||||
{
|
||||
qDebug("AudioDeviceManager::addAudioSource: %d: %p", inputDeviceIndex, audioFifo);
|
||||
|
||||
if (m_audioInputs.find(inputDeviceIndex) == m_audioInputs.end()) {
|
||||
m_audioInputs[inputDeviceIndex] = new AudioInput();
|
||||
}
|
||||
|
||||
if (m_audioInputs[inputDeviceIndex]->getNbFifos() == 0) {
|
||||
startAudioInput(inputDeviceIndex);
|
||||
}
|
||||
|
||||
if (m_audioSourceFifos.find(audioFifo) == m_audioSourceFifos.end()) // new FIFO
|
||||
{
|
||||
m_audioInputs[inputDeviceIndex]->addFifo(audioFifo);
|
||||
}
|
||||
else
|
||||
{
|
||||
int audioInputDeviceIndex = m_audioSourceFifos[audioFifo];
|
||||
|
||||
if (audioInputDeviceIndex != inputDeviceIndex) // change of audio device
|
||||
{
|
||||
removeAudioSource(audioFifo); // remove from current
|
||||
m_audioInputs[inputDeviceIndex]->addFifo(audioFifo); // add to new
|
||||
}
|
||||
}
|
||||
|
||||
m_audioSourceFifos[audioFifo] = inputDeviceIndex; // register audio FIFO
|
||||
}
|
||||
|
||||
void AudioDeviceManager::removeAudioSource(AudioFifo* audioFifo)
|
||||
{
|
||||
qDebug("AudioDeviceManager::removeAudioSource: %p", audioFifo);
|
||||
|
||||
if (m_audioSourceFifos.find(audioFifo) == m_audioSourceFifos.end())
|
||||
{
|
||||
qWarning("AudioDeviceManager::removeAudioSource: audio FIFO %p not found", audioFifo);
|
||||
return;
|
||||
}
|
||||
|
||||
int audioInputDeviceIndex = m_audioSourceFifos[audioFifo];
|
||||
m_audioOutputs[audioInputDeviceIndex]->removeFifo(audioFifo);
|
||||
|
||||
if (m_audioOutputs[audioInputDeviceIndex]->getNbFifos() == 0) {
|
||||
stopAudioInput(audioInputDeviceIndex);
|
||||
}
|
||||
|
||||
m_audioSourceFifos.remove(audioFifo); // unregister audio FIFO
|
||||
}
|
||||
|
||||
void AudioDeviceManager::startAudioOutput(int outputDeviceIndex)
|
||||
{
|
||||
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)
|
||||
{
|
||||
m_audioOutputs[outputDeviceIndex]->stop();
|
||||
}
|
||||
|
||||
void AudioDeviceManager::startAudioInput(int inputDeviceIndex)
|
||||
{
|
||||
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)
|
||||
{
|
||||
m_audioInputs[inputDeviceIndex]->stop();
|
||||
}
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2017 F4EXB //
|
||||
// written by Edouard Griffiths //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation as version 3 of the License, or //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License V3 for more details. //
|
||||
// //
|
||||
// You should have received a copy of the GNU General Public License //
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "audio/audiodevicemanager.h"
|
||||
#include "util/simpleserializer.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
const float AudioDeviceManager::m_defaultAudioInputVolume = 0.15f;
|
||||
|
||||
QDataStream& operator<<(QDataStream& ds, const AudioDeviceManager::InputDeviceInfo& info)
|
||||
{
|
||||
ds << info.sampleRate << info.volume;
|
||||
return ds;
|
||||
}
|
||||
|
||||
QDataStream& operator>>(QDataStream& ds, AudioDeviceManager::InputDeviceInfo& info)
|
||||
{
|
||||
ds >> info.sampleRate >> info.volume;
|
||||
return ds;
|
||||
}
|
||||
|
||||
AudioDeviceManager::AudioDeviceManager()
|
||||
{
|
||||
m_inputDevicesInfo = QAudioDeviceInfo::availableDevices(QAudio::AudioInput);
|
||||
m_outputDevicesInfo = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput);
|
||||
}
|
||||
|
||||
AudioDeviceManager::~AudioDeviceManager()
|
||||
{
|
||||
QMap<int, AudioOutput*>::iterator it = m_audioOutputs.begin();
|
||||
|
||||
for (; it != m_audioOutputs.end(); ++it) {
|
||||
delete(*it);
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
}
|
||||
|
||||
QByteArray AudioDeviceManager::serialize() const
|
||||
{
|
||||
qDebug("AudioDeviceManager::serialize");
|
||||
debugAudioInputInfos();
|
||||
debugAudioOutputInfos();
|
||||
|
||||
SimpleSerializer s(1);
|
||||
QByteArray data;
|
||||
|
||||
serializeInputMap(data);
|
||||
s.writeBlob(1, data);
|
||||
serializeOutputMap(data);
|
||||
s.writeBlob(2, data);
|
||||
|
||||
return s.final();
|
||||
}
|
||||
|
||||
void AudioDeviceManager::serializeInputMap(QByteArray& data) const
|
||||
{
|
||||
QDataStream *stream = new QDataStream(&data, QIODevice::WriteOnly);
|
||||
*stream << m_audioInputInfos;
|
||||
delete stream;
|
||||
}
|
||||
|
||||
void AudioDeviceManager::serializeOutputMap(QByteArray& data) const
|
||||
{
|
||||
QDataStream *stream = new QDataStream(&data, QIODevice::WriteOnly);
|
||||
*stream << m_audioOutputSampleRates;
|
||||
delete stream;
|
||||
}
|
||||
|
||||
bool AudioDeviceManager::deserialize(const QByteArray& data)
|
||||
{
|
||||
qDebug("AudioDeviceManager::deserialize");
|
||||
|
||||
SimpleDeserializer d(data);
|
||||
|
||||
if(!d.isValid()) {
|
||||
resetToDefaults();
|
||||
return false;
|
||||
}
|
||||
|
||||
if(d.getVersion() == 1)
|
||||
{
|
||||
QByteArray data;
|
||||
|
||||
d.readBlob(1, &data);
|
||||
deserializeInputMap(data);
|
||||
d.readBlob(2, &data);
|
||||
deserializeOutputMap(data);
|
||||
|
||||
debugAudioInputInfos();
|
||||
debugAudioOutputInfos();
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
resetToDefaults();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void AudioDeviceManager::deserializeInputMap(QByteArray& data)
|
||||
{
|
||||
QDataStream readStream(&data, QIODevice::ReadOnly);
|
||||
readStream >> m_audioInputInfos;
|
||||
}
|
||||
|
||||
void AudioDeviceManager::deserializeOutputMap(QByteArray& data)
|
||||
{
|
||||
QDataStream readStream(&data, QIODevice::ReadOnly);
|
||||
readStream >> m_audioOutputSampleRates;
|
||||
}
|
||||
|
||||
void AudioDeviceManager::addAudioSink(AudioFifo* audioFifo, int outputDeviceIndex)
|
||||
{
|
||||
qDebug("AudioDeviceManager::addAudioSink: %d: %p", outputDeviceIndex, audioFifo);
|
||||
|
||||
if (m_audioOutputs.find(outputDeviceIndex) == m_audioOutputs.end()) {
|
||||
m_audioOutputs[outputDeviceIndex] = new AudioOutput();
|
||||
}
|
||||
|
||||
if (m_audioOutputs[outputDeviceIndex]->getNbFifos() == 0) {
|
||||
startAudioOutput(outputDeviceIndex);
|
||||
}
|
||||
|
||||
if (m_audioSinkFifos.find(audioFifo) == m_audioSinkFifos.end()) // new FIFO
|
||||
{
|
||||
m_audioOutputs[outputDeviceIndex]->addFifo(audioFifo);
|
||||
}
|
||||
else
|
||||
{
|
||||
int audioOutputDeviceIndex = m_audioSinkFifos[audioFifo];
|
||||
|
||||
if (audioOutputDeviceIndex != outputDeviceIndex) // change of audio device
|
||||
{
|
||||
removeAudioSink(audioFifo); // remove from current
|
||||
m_audioOutputs[outputDeviceIndex]->addFifo(audioFifo); // add to new
|
||||
}
|
||||
}
|
||||
|
||||
m_audioSinkFifos[audioFifo] = outputDeviceIndex; // register audio FIFO
|
||||
}
|
||||
|
||||
void AudioDeviceManager::removeAudioSink(AudioFifo* audioFifo)
|
||||
{
|
||||
qDebug("AudioDeviceManager::removeAudioSink: %p", audioFifo);
|
||||
|
||||
if (m_audioSinkFifos.find(audioFifo) == m_audioSinkFifos.end())
|
||||
{
|
||||
qWarning("AudioDeviceManager::removeAudioSink: audio FIFO %p not found", audioFifo);
|
||||
return;
|
||||
}
|
||||
|
||||
int audioOutputDeviceIndex = m_audioSinkFifos[audioFifo];
|
||||
m_audioOutputs[audioOutputDeviceIndex]->removeFifo(audioFifo);
|
||||
|
||||
if (m_audioOutputs[audioOutputDeviceIndex]->getNbFifos() == 0) {
|
||||
stopAudioOutput(audioOutputDeviceIndex);
|
||||
}
|
||||
|
||||
m_audioSinkFifos.remove(audioFifo); // unregister audio FIFO
|
||||
}
|
||||
|
||||
void AudioDeviceManager::addAudioSource(AudioFifo* audioFifo, int inputDeviceIndex)
|
||||
{
|
||||
qDebug("AudioDeviceManager::addAudioSource: %d: %p", inputDeviceIndex, audioFifo);
|
||||
|
||||
if (m_audioInputs.find(inputDeviceIndex) == m_audioInputs.end()) {
|
||||
m_audioInputs[inputDeviceIndex] = new AudioInput();
|
||||
}
|
||||
|
||||
if (m_audioInputs[inputDeviceIndex]->getNbFifos() == 0) {
|
||||
startAudioInput(inputDeviceIndex);
|
||||
}
|
||||
|
||||
if (m_audioSourceFifos.find(audioFifo) == m_audioSourceFifos.end()) // new FIFO
|
||||
{
|
||||
m_audioInputs[inputDeviceIndex]->addFifo(audioFifo);
|
||||
}
|
||||
else
|
||||
{
|
||||
int audioInputDeviceIndex = m_audioSourceFifos[audioFifo];
|
||||
|
||||
if (audioInputDeviceIndex != inputDeviceIndex) // change of audio device
|
||||
{
|
||||
removeAudioSource(audioFifo); // remove from current
|
||||
m_audioInputs[inputDeviceIndex]->addFifo(audioFifo); // add to new
|
||||
}
|
||||
}
|
||||
|
||||
m_audioSourceFifos[audioFifo] = inputDeviceIndex; // register audio FIFO
|
||||
}
|
||||
|
||||
void AudioDeviceManager::removeAudioSource(AudioFifo* audioFifo)
|
||||
{
|
||||
qDebug("AudioDeviceManager::removeAudioSource: %p", audioFifo);
|
||||
|
||||
if (m_audioSourceFifos.find(audioFifo) == m_audioSourceFifos.end())
|
||||
{
|
||||
qWarning("AudioDeviceManager::removeAudioSource: audio FIFO %p not found", audioFifo);
|
||||
return;
|
||||
}
|
||||
|
||||
int audioInputDeviceIndex = m_audioSourceFifos[audioFifo];
|
||||
m_audioInputs[audioInputDeviceIndex]->removeFifo(audioFifo);
|
||||
|
||||
if (m_audioInputs[audioInputDeviceIndex]->getNbFifos() == 0) {
|
||||
stopAudioInput(audioInputDeviceIndex);
|
||||
}
|
||||
|
||||
m_audioSourceFifos.remove(audioFifo); // unregister audio FIFO
|
||||
}
|
||||
|
||||
void AudioDeviceManager::startAudioOutput(int outputDeviceIndex)
|
||||
{
|
||||
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)
|
||||
{
|
||||
m_audioOutputs[outputDeviceIndex]->stop();
|
||||
}
|
||||
|
||||
void AudioDeviceManager::startAudioInput(int inputDeviceIndex)
|
||||
{
|
||||
unsigned int sampleRate;
|
||||
float volume;
|
||||
QString deviceName;
|
||||
|
||||
if (getInputDeviceName(inputDeviceIndex, deviceName))
|
||||
{
|
||||
if (m_audioInputInfos.find(deviceName) == m_audioInputInfos.end())
|
||||
{
|
||||
sampleRate = m_defaultAudioSampleRate;
|
||||
volume = m_defaultAudioInputVolume;
|
||||
}
|
||||
else
|
||||
{
|
||||
sampleRate = m_audioInputInfos[deviceName].sampleRate;
|
||||
volume = m_audioInputInfos[deviceName].volume;
|
||||
}
|
||||
|
||||
m_audioInputs[inputDeviceIndex]->start(inputDeviceIndex, sampleRate);
|
||||
m_audioInputs[inputDeviceIndex]->setVolume(volume);
|
||||
m_audioInputInfos[deviceName].sampleRate = m_audioInputs[inputDeviceIndex]->getRate();
|
||||
m_audioInputInfos[deviceName].volume = volume;
|
||||
}
|
||||
else
|
||||
{
|
||||
qWarning("AudioDeviceManager::startAudioInput: unknown device index %d", inputDeviceIndex);
|
||||
}
|
||||
}
|
||||
|
||||
void AudioDeviceManager::stopAudioInput(int inputDeviceIndex)
|
||||
{
|
||||
m_audioInputs[inputDeviceIndex]->stop();
|
||||
}
|
||||
|
||||
void AudioDeviceManager::debugAudioInputInfos() const
|
||||
{
|
||||
QMap<QString, InputDeviceInfo>::const_iterator it = m_audioInputInfos.begin();
|
||||
|
||||
for (; it != m_audioInputInfos.end(); ++it)
|
||||
{
|
||||
qDebug() << "AudioDeviceManager::debugAudioInputInfos:"
|
||||
<< " name: " << it.key()
|
||||
<< " sampleRate: " << it.value().sampleRate
|
||||
<< " volume: " << it.value().volume;
|
||||
}
|
||||
}
|
||||
|
||||
void AudioDeviceManager::debugAudioOutputInfos() const
|
||||
{
|
||||
QMap<QString, unsigned int>::const_iterator it = m_audioOutputSampleRates.begin();
|
||||
|
||||
for (; it != m_audioOutputSampleRates.end(); ++it)
|
||||
{
|
||||
qDebug() << "AudioDeviceManager::debugAudioOutputInfos:"
|
||||
<< " name: " << it.key()
|
||||
<< " sampleRate: " << it.value();
|
||||
}
|
||||
}
|
||||
|
@ -1,79 +1,98 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2017 F4EXB //
|
||||
// written by Edouard Griffiths //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation as version 3 of the License, or //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License V3 for more details. //
|
||||
// //
|
||||
// You should have received a copy of the GNU General Public License //
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef INCLUDE_AUDIODEVICEMANGER_H
|
||||
#define INCLUDE_AUDIODEVICEMANGER_H
|
||||
|
||||
#include <QStringList>
|
||||
#include <QList>
|
||||
#include <QMap>
|
||||
#include <QAudioDeviceInfo>
|
||||
|
||||
#include "audio/audioinput.h"
|
||||
#include "audio/audiooutput.h"
|
||||
#include "export.h"
|
||||
|
||||
class AudioFifo;
|
||||
|
||||
class SDRBASE_API AudioDeviceManager {
|
||||
public:
|
||||
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:
|
||||
|
||||
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 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 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;
|
||||
bool deserialize(const QByteArray& data);
|
||||
|
||||
void startAudioOutput(int outputDeviceIndex);
|
||||
void stopAudioOutput(int outputDeviceIndex);
|
||||
void startAudioInput(int inputDeviceIndex);
|
||||
void stopAudioInput(int inputDeviceIndex);
|
||||
|
||||
friend class AudioDialog;
|
||||
friend class MainSettings;
|
||||
};
|
||||
|
||||
#endif // INCLUDE_AUDIODEVICEMANGER_H
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2017 F4EXB //
|
||||
// written by Edouard Griffiths //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation as version 3 of the License, or //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License V3 for more details. //
|
||||
// //
|
||||
// You should have received a copy of the GNU General Public License //
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef INCLUDE_AUDIODEVICEMANGER_H
|
||||
#define INCLUDE_AUDIODEVICEMANGER_H
|
||||
|
||||
#include <QStringList>
|
||||
#include <QList>
|
||||
#include <QMap>
|
||||
#include <QAudioDeviceInfo>
|
||||
#include <QDataStream>
|
||||
|
||||
#include "audio/audioinput.h"
|
||||
#include "audio/audiooutput.h"
|
||||
#include "export.h"
|
||||
|
||||
class AudioFifo;
|
||||
|
||||
class SDRBASE_API AudioDeviceManager {
|
||||
public:
|
||||
class InputDeviceInfo
|
||||
{
|
||||
public:
|
||||
unsigned int sampleRate;
|
||||
float volume;
|
||||
friend QDataStream& operator<<(QDataStream& ds, const InputDeviceInfo& info);
|
||||
friend QDataStream& operator>>(QDataStream& ds, InputDeviceInfo& info);
|
||||
};
|
||||
|
||||
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:
|
||||
|
||||
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 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 to audio input map (index -1 is default device)
|
||||
QMap<QString, InputDeviceInfo> m_audioInputInfos; //!< audio device name to audio input device info
|
||||
|
||||
void resetToDefaults();
|
||||
QByteArray serialize() const;
|
||||
bool deserialize(const QByteArray& data);
|
||||
|
||||
void startAudioOutput(int outputDeviceIndex);
|
||||
void stopAudioOutput(int outputDeviceIndex);
|
||||
void startAudioInput(int inputDeviceIndex);
|
||||
void stopAudioInput(int inputDeviceIndex);
|
||||
|
||||
void serializeInputMap(QByteArray& data) const;
|
||||
void deserializeInputMap(QByteArray& data);
|
||||
void debugAudioInputInfos() const;
|
||||
|
||||
void serializeOutputMap(QByteArray& data) const;
|
||||
void deserializeOutputMap(QByteArray& data);
|
||||
void debugAudioOutputInfos() const;
|
||||
|
||||
friend class AudioDialog;
|
||||
friend class MainSettings;
|
||||
};
|
||||
|
||||
QDataStream& operator<<(QDataStream& ds, const AudioDeviceManager::InputDeviceInfo& info);
|
||||
|
||||
#endif // INCLUDE_AUDIODEVICEMANGER_H
|
||||
|
Loading…
Reference in New Issue
Block a user