10#include <audioclient.h>
69 wfx.Format.wBitsPerSample = wfx.Samples.wValidBitsPerSample = format
.bytesPerSample()*8;
71 wfx.Format.nBlockAlign = (wfx.Format.wBitsPerSample / 8) * wfx.Format.nChannels;
72 wfx.Format.nAvgBytesPerSec = wfx.Format.nBlockAlign * wfx.Format.nSamplesPerSec;
73 wfx.Format.cbSize = 0;
76 wfx.Format.wFormatTag = WAVE_FORMAT_IEEE_FLOAT;
77 wfx.SubFormat = KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;
79 wfx.Format.wFormatTag = WAVE_FORMAT_PCM;
80 wfx.SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
84 wfx.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
85 wfx.Format.cbSize = 22;
86 wfx.dwChannelMask = format.channelConfig() == QAudioFormat::ChannelConfigUnknown ? KSAUDIO_SPEAKER_DIRECTOUT
87 : DWORD(format.channelConfig());
96 WAVEFORMATEXTENSIBLE ret{};
97 if (formatToWaveFormatExtensible(format, ret))
108 if (in.wFormatTag == WAVE_FORMAT_PCM) {
109 if (in.wBitsPerSample == 8)
111 else if (in.wBitsPerSample == 16)
113 else if (in.wBitsPerSample == 32)
115 }
else if (in.wFormatTag == WAVE_FORMAT_EXTENSIBLE) {
116 if (in.cbSize >= 22) {
117 auto wfe =
reinterpret_cast<
const WAVEFORMATEXTENSIBLE &>(in);
118 if (wfe.SubFormat == KSDATAFORMAT_SUBTYPE_IEEE_FLOAT)
120 if (qPopulationCount(wfe.dwChannelMask) >= in.nChannels)
121 out.setChannelConfig(maskToChannelConfig(wfe.dwChannelMask, in.nChannels));
123 }
else if (in.wFormatTag == WAVE_FORMAT_IEEE_FLOAT) {
137 if (SUCCEEDED(mediaType->GetUINT32(MF_MT_AUDIO_NUM_CHANNELS, &val))) {
140 qWarning() <<
"Could not determine channel count from IMFMediaType";
144 if (SUCCEEDED(mediaType->GetUINT32(MF_MT_AUDIO_CHANNEL_MASK, &val))) {
145 if (
int(qPopulationCount(val)) >= format.channelCount())
146 format.setChannelConfig(maskToChannelConfig(val, format.channelCount()));
149 if (SUCCEEDED(mediaType->GetUINT32(MF_MT_AUDIO_SAMPLES_PER_SECOND, &val))) {
152 UINT32 bitsPerSample = 0;
153 mediaType->GetUINT32(MF_MT_AUDIO_BITS_PER_SAMPLE, &bitsPerSample);
156 if (SUCCEEDED(mediaType->GetGUID(MF_MT_SUBTYPE, &subType))) {
157 if (subType == MFAudioFormat_Float) {
159 }
else if (bitsPerSample == 8) {
161 }
else if (bitsPerSample == 16) {
163 }
else if (bitsPerSample == 32){
172 ComPtr<IMFMediaType> mediaType;
177 wmf.mfCreateMediaType(mediaType.GetAddressOf());
179 mediaType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Audio);
181 mediaType->SetGUID(MF_MT_SUBTYPE, MFAudioFormat_Float);
183 mediaType->SetGUID(MF_MT_SUBTYPE, MFAudioFormat_PCM);
186 mediaType->SetUINT32(MF_MT_AUDIO_NUM_CHANNELS, UINT32(format.channelCount()));
187 if (format.channelConfig() != QAudioFormat::ChannelConfigUnknown)
188 mediaType->SetUINT32(MF_MT_AUDIO_CHANNEL_MASK, channelConfigToMask(format.channelConfig()));
189 mediaType->SetUINT32(MF_MT_AUDIO_SAMPLES_PER_SECOND, UINT32(format.sampleRate()));
191 mediaType->SetUINT32(MF_MT_AUDIO_BLOCK_ALIGNMENT, alignmentBlock);
193 mediaType->SetUINT32(MF_MT_AUDIO_AVG_BYTES_PER_SECOND, avgBytesPerSec);
194 mediaType->SetUINT32(MF_MT_AUDIO_BITS_PER_SAMPLE, UINT32(format.bytesPerSample()*8));
195 mediaType->SetUINT32(MF_MT_ALL_SAMPLES_INDEPENDENT, TRUE);
203 UINT32 framesPadding = 0;
204 if (SUCCEEDED(client->GetCurrentPadding(&framesPadding)))
205 return framesPadding;
212 UINT32 bufferFrameCount = 0;
213 if (SUCCEEDED(client->GetBufferSize(&bufferFrameCount)))
214 return bufferFrameCount;
Combined button and popup list for selecting options.
std::optional< quint32 > allocatedFrames(IAudioClient *client)
std::optional< WAVEFORMATEXTENSIBLE > toWaveFormatExtensible(const QAudioFormat &format)
std::optional< quint32 > usedFrames(IAudioClient *client)
ComPtr< IMFMediaType > formatToMediaType(QWindowsMediaFoundation &, const QAudioFormat &format)
QAudioFormat waveFormatExToFormat(const WAVEFORMATEX &in)
bool formatToWaveFormatExtensible(const QAudioFormat &format, WAVEFORMATEXTENSIBLE &wfx)
QAudioFormat::ChannelConfig maskToChannelConfig(UINT32 mask, int count)
static UINT32 channelConfigToMask(QAudioFormat::ChannelConfig config)
static QT_BEGIN_NAMESPACE QAudioFormat::AudioChannelPosition channelFormatMap[]