0

All. It's finally time to add audio to my game engine.

I have simple SoundEffect->Play() functions working just fine, but I want to have SoundEffectInstances so I can apply 3D effects and such.

When I call SoundEffect->CreateInstance(), it returns a NULL pointer. I tried turning on the debug layer in the audio engine but it didn't give me any information.

The base SoundEffects are working properly otherwise. I am able to play a sound and they have their files loaded (non NULL pointers).

As far as I can tell, I am following the instructions in the tutorial. Am I missing something or is there some reason why the CreateInstance() call would fail? I can confirm that there is no issue with using a pointer to the struct in the vector as I can grab that reference and then SoundEffect->Play() it through the reference.

Thanks.

Code snippet:

struct SoundEffectWrapper
{
    unique_ptr<SoundEffect> sound;
    string soundName;
};

struct SoundEffectInstanceWrapper
{
    unique_ptr<SoundEffectInstance> sound;
    string soundName;
};

vector<SoundEffectWrapper> Sounds;
vector<SoundEffectInstanceWrapper> SoundInstances;

SoundEffectInstanceWrapper* SoundManagerClass::GetSoundInstance(string soundName)
{
//Returns an instance of a non-3D sound
SoundEffectWrapper* pSEW = GetSoundEffectWrapper(soundName);

if (pSEW != NULL)
{
    //DEBUG trying to create the sound directly from the sound instead of through a pointer 
    //to the vector to remove as many layers of abstraction as possible.
    unique_ptr<SoundEffectInstance> testSound = Sounds[2].sound->CreateInstance(); //still returns NULL pointer


    //VVVVcode is supposed to do this VVVVVVV
    SoundInstances.push_back(SoundEffectInstanceWrapper());

    int ind = SoundInstances.size() - 1;

    SoundInstances[ind].sound = pSEW->sound->CreateInstance(); //Returns NULL pointer
    SoundInstances[ind].soundName = pSEW->soundName;

    return &SoundInstances[ind];
}
else
{
    return NULL;
}

}

UPDATE 03/05/19 For Chuck: Thanks for the response, Chuck. I might have misspoke when I said it was returning a null. Specifically, the parameter mBase{voice=null. I created some code to rule out the vector being the issue, and I downloaded the project and stepped into the create instance function. According to the local variable tab, voice was NULL before it called return. Here is a code snippet and a picture showing what I saw on my screen:

wstring filepath = L"..//Resources/Audio/Player/FootStepWalk.wav";
auto sound = make_unique<SoundEffect>(audioEngine.audEngine.get(), filepath.c_str());

auto soundInstance = sound->CreateInstance();

if (!soundInstance)
{
    //This doesn't occur even though voice is null
    MessageBox(NULL, "Failed to create sound instance", "Derp", MB_OK);
}
//This sound doesn't play, but it doesn't throw an exception either.
soundInstance->Play();

DebuggerView

Is it possible that a source voice is failing to be allocated for the sound instance?

UPDATE 2:

Picture of everything looking right but no sound: Debug

GaleRazorwind
  • 229
  • 2
  • 7
  • You should step into the code for ``CreateInstance`` to see what's happened at that point. If you are using the DirectX Tool Kit NuGet package, you may find it easier to switch to the full project-to-project reference so you have the full source there. The only scenario where ``CreateInstance`` returns ``nullptr`` by design at runtime is if you are using ``WaveBank`` and provide an index to a sound that's not present in the wavebank--the soft-fail makes it easier to work around the problem in real development scenarios. ``SoundEffect`` should throw an exception instead of return a nullptr. – Chuck Walbourn Mar 04 '19 at 23:54
  • My suspicion is that's related to your use of ``unique_ptr`` inside a ``vector``. – Chuck Walbourn Mar 04 '19 at 23:54
  • @ChuckWalbourn Thanks for the reply, Chuck. I have updated the main post with more information. – GaleRazorwind Mar 05 '19 at 21:31
  • This is probably due to [voice management](https://github.com/Microsoft/DirectXTK/wiki/AudioEngine#voice-management). Call the ``GetStatistics`` function to see how many voices are allocated vs. the max via the [wiki](https://github.com/Microsoft/DirectXTK/wiki/AudioEngine#statistics). – Chuck Walbourn Mar 05 '19 at 23:18
  • @ChuckWalbourn Hi, Chuck. This keeps getting more interesting. So I called GetStatistics after calling play and I noticed that after I actually play the sound, it's voice pointer is no longer null. The stats say it is playing and there is one voice allocated. Still no sound though. See picture in main post for reference. Thanks for all the help. – GaleRazorwind Mar 06 '19 at 02:42

0 Answers0