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();
Is it possible that a source voice is failing to be allocated for the sound instance?
UPDATE 2: