17QnxAudioDeviceInfo::QnxAudioDeviceInfo(
const QByteArray &deviceName, QAudioDevice::Mode mode)
18 : QAudioDevicePrivate(deviceName, mode)
20 isDefault = id.contains(
"Preferred");
22 preferredFormat.setChannelCount(mode == QAudioDevice::Input ? 1 : 2);
24 description = QString::fromUtf8(id);
26 minimumChannelCount = 1;
27 maximumChannelCount = 2;
29 const std::optional<snd_pcm_channel_info_t> info = pcmChannelInfo(id, mode);
34 minimumSampleRate = info->min_rate;
35 maximumSampleRate = info->max_rate;
37 constexpr std::array sampleRates { 48000, 44100, 22050, 16000, 11025, 8000 };
39 for (
int rate : sampleRates) {
40 if (rate <= maximumSampleRate && rate >= minimumSampleRate) {
41 preferredFormat.setSampleRate(rate);
46 if (info->formats & SND_PCM_FMT_U8) {
47 supportedSampleFormats << QAudioFormat::UInt8;
48 preferredFormat.setSampleFormat(QAudioFormat::UInt8);
51 if (info->formats & SND_PCM_FMT_S16) {
52 supportedSampleFormats << QAudioFormat::Int16;
53 preferredFormat.setSampleFormat(QAudioFormat::Int16);
56 if (info->formats & SND_PCM_FMT_S32)
57 supportedSampleFormats << QAudioFormat::Int32;
59 if (info->formats & SND_PCM_FMT_FLOAT)
60 supportedSampleFormats << QAudioFormat::Float;
67bool QnxAudioDeviceInfo::isFormatSupported(
const QAudioFormat &format)
const
69 const HandleUniquePtr handle = openPcmDevice(id, mode);
74 const std::optional<snd_pcm_channel_info_t> info = pcmChannelInfo(handle.get(), mode);
79 snd_pcm_channel_params_t params = formatToChannelParams(format, mode, info->max_fragment_size);
80 const int errorCode = snd_pcm_plugin_params(handle.get(), ¶ms);
82 return errorCode == 0;