Search code examples
directxdirectx-12xaudio2directxtk

DirectXTK 3D audio uses only left channel


I've decided to try the DirectXTK12 audio and it's working fine except for the 3D sound. I'm following the guide from wiki but the sound is always in the left speaker no matter how I position the listener/emitter. What's wrong? My code looks like this:

HRESULT hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED);
if (FAILED(hr)) {...}

std::unique_ptr<DirectX::AudioEngine> audEngine;

DirectX::AUDIO_ENGINE_FLAGS eflags = DirectX::AudioEngine_Default;
#ifdef _DEBUG
    eflags |= DirectX::AudioEngine_Debug;
#endif

std::unique_ptr<DirectX::SoundEffect> soundEffect;
soundEffect = std::make_unique<DirectX::SoundEffect>(audEngine.get(), L"Sound.wav");
auto effect = soundEffect->CreateInstance(DirectX::SoundEffectInstance_Use3D);

effect->Play(false);

DirectX::AudioListener listener;
listener.SetPosition(DirectX::XMFLOAT3(0.0f, 0.0f, 0.0f));

DirectX::AudioEmitter emitter;
emitter.SetPosition(DirectX::XMFLOAT3(0.0f, 0.0f, 0.0f));

effect->Apply3D(listener, emitter, false);

It should be in the center but it's only using the left channel although there are no errors in the output, the only thing the output says is this:

INFO: XAudio 2.9 debugging enabled
INFO: mastering voice has 2 channels, 96000 sample rate, 00000003 channel mask

Playing the sound without 3D uses both speakers as expected.


Solution

  • I've fixed the issue by converting used Sound.wav to mono (1 channel) sound.