I've followed the tutorial along Microsoft's website, and created my own SoundEngine and Sound class structure to have the code abstracted away in main, however whenever I make a call such as batmanWav->play()
, it will only play the audio if I write std::cin.get()
or system("PAUSE")
Why is this? I will be trying to port this to a game that's already been worked on, but I obviously don't want the game to stop every time a sound is played.
EDIT: I was asked to show some code which has the issues
int main()
{
CoInitializeEx(nullptr, COINIT_MULTITHREADED);
Sound batman("batman.wav");
Sound alien("alien.wav");
alien.play();
batman.play();
system("PAUSE");
CoUninitialize();
}
Sound.cpp
HRESULT Sound::play()
{
HRESULT hr = S_OK;
if (FAILED(hr = pSourceVoice->Start(0)))
return hr;
return hr;
}
For each Sound object I initialized a source voice, and each one refers to the same mastering voice and IXAudio2 *pXAudio2
object. The code I used to load wave file data was taken straight off MSDN docs.