I receive the Error XAUDIO2_E_INVALID_CALL
when I try to call IXAudio2Engine::CreateSourceVoice
. My code for creating a source voice is as follows:
auto sample_rate = quality_to_sample_rate(settings.quality, sound_category::effect);
WAVEFORMATEX wave_format{ // 8000Hz 16 bit mono WAV
.wFormatTag = WAVE_FORMAT_PCM,
.nChannels = 1,
.nSamplesPerSec = sample_rate,
.nAvgBytesPerSec = sample_rate* 2,
.wBitsPerSample = 16,
.cbSize = 0,
};
XAUDIO2_SEND_DESCRIPTOR send_descriptor{.Flags = 0, .pOutputVoice = master_voice};
XAUDIO2_VOICE_SENDS sends{.SendCount = 1, .pSends = &send_descriptor};
res = sound_engine->CreateSourceVoice(&v, &wave_format, 0, 2.0f, nullptr, &sends);
if(FAILED(res)) {
log_error("Could not create effect source voice with", sample_rate, "Hz");
throw std::runtime_error("Could not create effect source voice");
}
log_debug("Created effect source voice with ", sample_rate, "Hz at ", (void*)v);
master_voice
is not nullptr
and is of type IXAudio2MasteringVoice*
(i.e. CreateMasteringVoice
returned S_OK
!)
What am I missing?
Edit:
According to XAudio2 and *.wav loading, HRESULT 0x88960001 ,
it is possible to set pSendList
to NULL
which would result in using the MasteringVoice. but that does not help either.
Reading the docs helps:
nBlockAlign
and nAvgBytesPerSecond
need to be set correctly.
nBlockAlign
needs to be (nChannels * (nBitsPerSample/8)) / 8
and
nAvgBytesPerSecond
is nBlockAlign * nSamplesPerSecond