mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 14:55:36 +08:00
Ref T730, also return an output device if there is no exact match
This commit is contained in:
committed by
Mat Sutcliffe
parent
5d9ea83b93
commit
89725c3bb4
@@ -23,7 +23,7 @@ namespace BlackSound
|
|||||||
for (int n = 0; n < inputSamples; n++)
|
for (int n = 0; n < inputSamples; n++)
|
||||||
{
|
{
|
||||||
output[n] = *reinterpret_cast<const qint16 *>(input.data() + n * 2);
|
output[n] = *reinterpret_cast<const qint16 *>(input.data() + n * 2);
|
||||||
output[n] /= 32767.0;
|
output[n] /= 32767.0f;
|
||||||
}
|
}
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
@@ -75,7 +75,7 @@ namespace BlackSound
|
|||||||
QVector<float> output;
|
QVector<float> output;
|
||||||
for (auto sample : input)
|
for (auto sample : input)
|
||||||
{
|
{
|
||||||
output.push_back(sample / 32768.0);
|
output.push_back(sample / 32768.0f);
|
||||||
}
|
}
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
@@ -88,7 +88,7 @@ namespace BlackSound
|
|||||||
else { return QAudioDeviceInfo::defaultOutputDevice(); }
|
else { return QAudioDeviceInfo::defaultOutputDevice(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
QAudio::Mode mode = device.getType() == CAudioDeviceInfo::InputDevice ? QAudio::AudioInput : QAudio::AudioOutput;
|
QAudio::Mode mode = (device.getType() == CAudioDeviceInfo::InputDevice) ? QAudio::AudioInput : QAudio::AudioOutput;
|
||||||
const QList<QAudioDeviceInfo> allQtDevices = QAudioDeviceInfo::availableDevices(mode);
|
const QList<QAudioDeviceInfo> allQtDevices = QAudioDeviceInfo::availableDevices(mode);
|
||||||
|
|
||||||
// Find the one with lowest latency.
|
// Find the one with lowest latency.
|
||||||
@@ -97,15 +97,15 @@ namespace BlackSound
|
|||||||
{
|
{
|
||||||
if (d.deviceName() == device.getName())
|
if (d.deviceName() == device.getName())
|
||||||
{
|
{
|
||||||
if (! d.isFormatSupported(format))
|
if (!d.isFormatSupported(format))
|
||||||
{
|
{
|
||||||
// Check whether the nearest format is acceptable for our needs
|
// Check whether the nearest format is acceptable for our needs
|
||||||
QAudioFormat nearestFormat = d.nearestFormat(format);
|
const QAudioFormat nearestFormat = d.nearestFormat(format);
|
||||||
if (nearestFormat.sampleRate() != format.sampleRate() ||
|
if (nearestFormat.sampleRate() != format.sampleRate() ||
|
||||||
nearestFormat.sampleSize() != format.sampleSize() ||
|
nearestFormat.sampleSize() != format.sampleSize() ||
|
||||||
nearestFormat.sampleType() != format.sampleType() ||
|
nearestFormat.sampleType() != format.sampleType() ||
|
||||||
nearestFormat.byteOrder() != format.byteOrder() ||
|
nearestFormat.byteOrder() != format.byteOrder() ||
|
||||||
nearestFormat.codec() != format.codec())
|
nearestFormat.codec() != format.codec())
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -155,7 +155,6 @@ namespace BlackSound
|
|||||||
QAudioDeviceInfo getHighestCompatibleOutputDevice(const CAudioDeviceInfo &device, QAudioFormat &format)
|
QAudioDeviceInfo getHighestCompatibleOutputDevice(const CAudioDeviceInfo &device, QAudioFormat &format)
|
||||||
{
|
{
|
||||||
if (device.isDefault()) { return QAudioDeviceInfo::defaultOutputDevice(); }
|
if (device.isDefault()) { return QAudioDeviceInfo::defaultOutputDevice(); }
|
||||||
|
|
||||||
const QList<QAudioDeviceInfo> allQtDevices = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput);
|
const QList<QAudioDeviceInfo> allQtDevices = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput);
|
||||||
|
|
||||||
QList<QAudioDeviceInfo> supportedDevices;
|
QList<QAudioDeviceInfo> supportedDevices;
|
||||||
@@ -163,15 +162,26 @@ namespace BlackSound
|
|||||||
{
|
{
|
||||||
if (d.deviceName() == device.getName())
|
if (d.deviceName() == device.getName())
|
||||||
{
|
{
|
||||||
if (d.isFormatSupported(format))
|
// exact match, format supported
|
||||||
{
|
if (d.isFormatSupported(format)) { return d; }
|
||||||
supportedDevices.push_back(d);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
supportedDevices.push_back(d);
|
||||||
if (supportedDevices.size() > 0) { return supportedDevices.at(0); }
|
|
||||||
}
|
}
|
||||||
return {};
|
|
||||||
|
// no suitable device
|
||||||
|
if (supportedDevices.isEmpty())
|
||||||
|
{
|
||||||
|
format = QAudioFormat();
|
||||||
|
return QAudioDeviceInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
// here we could "search the best device", currently only first is taken
|
||||||
|
QAudioDeviceInfo usedDevice = supportedDevices.front();
|
||||||
|
if (!usedDevice.isFormatSupported(format))
|
||||||
|
{
|
||||||
|
format = usedDevice.nearestFormat(format);
|
||||||
|
}
|
||||||
|
return usedDevice;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
Reference in New Issue
Block a user