1

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.

Chuck Walbourn
  • 38,259
  • 2
  • 58
  • 81
Flone
  • 187
  • 1
  • 3
  • 11
  • With both emitter and listener at the same point, I'm not sure you are getting a valid test. What happens if you move the emitter left or right? Also you should probably dump the details about ``Sound.wav`` into the question. You can do it with this utility [wavdump.cpp](https://raw.githubusercontent.com/wiki/Microsoft/DirectXTK/wavdump.cpp). Also, check your audio device in the Windows control panel to make sure both left & right are working properly and that you have the Stereo speaker type set. – Chuck Walbourn Apr 03 '21 at 18:36
  • Note that the math breaks down if you have both listener and emitter at exactly the same spot, so don't trust that as a test. Also, XAudio2 is multithreaded so you need to enter a loop somewhere to wait for the sound to play on the worker thread. See [this tutorial](https://github.com/microsoft/DirectXTK/wiki/Using-positional-audio) for a full walkthrough of using positional audio via *DirectX Tool Kit for DX11*. – Chuck Walbourn Apr 10 '21 at 08:25
  • Another note, if your ``Sound.wav`` file has more than 1 channel, you need to add: ``emitter.ChannelCount = soundEffect->GetFormat()->nChannels;`` – Chuck Walbourn Apr 11 '21 at 05:30

1 Answers1

1

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

Flone
  • 187
  • 1
  • 3
  • 11
  • The problem was a mis-configured multi-channel sound. The fix was to use a mono wav file -or- to set ``emitter.ChannelCount`` and ``emitter.EmitterAzimuths`` to sensible values for the stereo sound per [GameFest 2010: The (3D) Sound of Success: X3DAudio and Sound Positioning](https://www.microsoft.com/en-us/download/details.aspx?id=17627). – Chuck Walbourn Apr 11 '21 at 20:28