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

AudioDeviceManager: make sure a negative or null sample rate is never returned

This commit is contained in:
f4exb 2020-05-15 19:37:50 +02:00
parent da06bc30cc
commit 0260c3aefc
2 changed files with 21 additions and 5 deletions

View File

@ -502,9 +502,17 @@ int AudioDeviceManager::getInputSampleRate(int inputDeviceIndex)
return m_defaultAudioSampleRate; return m_defaultAudioSampleRate;
} }
else else
{
if (deviceInfo.sampleRate > 0)
{ {
return deviceInfo.sampleRate; return deviceInfo.sampleRate;
} }
else
{
qDebug("AudioDeviceManager::getInputSampleRate: device %s has invalid sample rate", qPrintable(deviceName));
return m_defaultAudioSampleRate;
}
}
} }
int AudioDeviceManager::getOutputSampleRate(int outputDeviceIndex) int AudioDeviceManager::getOutputSampleRate(int outputDeviceIndex)
@ -525,9 +533,17 @@ int AudioDeviceManager::getOutputSampleRate(int outputDeviceIndex)
return m_defaultAudioSampleRate; return m_defaultAudioSampleRate;
} }
else else
{
if (deviceInfo.sampleRate > 0)
{ {
return deviceInfo.sampleRate; return deviceInfo.sampleRate;
} }
else
{
qDebug("AudioDeviceManager::getOutputSampleRate: device %s has invalid sample rate", qPrintable(deviceName));
return m_defaultAudioSampleRate;
}
}
} }

View File

@ -45,7 +45,7 @@ public:
sampleRate = m_defaultAudioSampleRate; sampleRate = m_defaultAudioSampleRate;
volume = m_defaultAudioInputVolume; volume = m_defaultAudioInputVolume;
} }
unsigned int sampleRate; int sampleRate;
float volume; float volume;
friend QDataStream& operator<<(QDataStream& ds, const InputDeviceInfo& info); friend QDataStream& operator<<(QDataStream& ds, const InputDeviceInfo& info);
friend QDataStream& operator>>(QDataStream& ds, InputDeviceInfo& info); friend QDataStream& operator>>(QDataStream& ds, InputDeviceInfo& info);
@ -74,7 +74,7 @@ public:
udpChannelCodec = AudioOutput::UDPCodecL16; udpChannelCodec = AudioOutput::UDPCodecL16;
udpDecimationFactor = 1; udpDecimationFactor = 1;
} }
unsigned int sampleRate; int sampleRate;
QString udpAddress; QString udpAddress;
quint16 udpPort; quint16 udpPort;
bool copyToUDP; bool copyToUDP;
@ -114,7 +114,7 @@ public:
void inputInfosCleanup(); //!< Remove input info from map for input devices not present void inputInfosCleanup(); //!< Remove input info from map for input devices not present
void outputInfosCleanup(); //!< Remove output info from map for output devices not present void outputInfosCleanup(); //!< Remove output info from map for output devices not present
static const unsigned int m_defaultAudioSampleRate = 48000; static const int m_defaultAudioSampleRate = 48000;
static const float m_defaultAudioInputVolume; static const float m_defaultAudioInputVolume;
static const QString m_defaultUDPAddress; static const QString m_defaultUDPAddress;
static const quint16 m_defaultUDPPort = 9998; static const quint16 m_defaultUDPPort = 9998;