Hey guys,
I am trying to get XAudio2 to work but I am having some trouble, I would appreciate if anyone can help me out.
Here is what I tried so far:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 | typedef HRESULT X_Audio2Create(IXAudio2 **ppXAudio2, UINT32 Flags, XAUDIO2_PROCESSOR XAudio2Processor);
global X_Audio2Create *xAudio2Create;
[...]
HMODULE XAudioLib = LoadLibrary("xaudio2_9.dll");
if (XAudioLib)
{
xAudio2Create = (X_Audio2Create *)GetProcAddress(XAudioLib, "XAudio2Create");
if (xAudio2Create)
{
IXAudio2 *XAudio = 0;
if (xAudio2Create(&XAudio, 0, XAUDIO2_DEFAULT_PROCESSOR) == S_OK)
{
IXAudio2MasteringVoice *masteringVoice;
if (XAudio->CreateMasteringVoice(&masteringVoice) == S_OK)
{
IXAudio2SourceVoice *sourceVoice;
WAVEFORMATEX waveFormat;
waveFormat.wFormatTag = WAVE_FORMAT_PCM;
waveFormat.nChannels = 2;
waveFormat.nSamplesPerSec = 11025;
waveFormat.wBitsPerSample = 16;
waveFormat.nBlockAlign = (waveFormat.nChannels * waveFormat.wBitsPerSample) / 8;
HRESULT result = XAudio->CreateSourceVoice(&sourceVoice, &waveFormat, XAUDIO2_VOICE_NOSRC,
XAUDIO2_MAX_FREQ_RATIO, &voiceCallback, 0, 0);
if (result == S_OK)
{
int y = 3;
}
}
}
}
}
|
it fails the last if, the error returned is:
XAUDIO2_E_INVALID_CALL
0x88960001
Returned by XAudio2 for certain API usage errors (invalid calls and so on) that are hard to avoid completely and should be handled by a title at runtime. (API usage errors that are completely avoidable, such as invalid parameters, cause an ASSERT in debug builds and undefined behavior in retail builds, so no error code is defined for them.)
I really struggled with audio when I followed handmade hero for the first time.
Now I'm starting the series again and I decided to try Xaudio2 instead, but I don't know much about audio overall.
Thanks!