Trouble using xaudio2 - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Trouble using xaudio2

Hi,

I am trying to use xaudio2 in my C++ project to add some sound to a simple 2D space shooter I have made. I am trying to get sound effects for the shooting. Each time I shoot, the playBackAudio() function is called which contains the two lines required to play back my .wav file.

[code]
void playBackAudio()
{
g_source->FlushSourceBuffers();
g_source->SubmitSourceBuffer(bufferShoot.xaBuffer());
}
[/code]

The trouble is, each time the sound is played, the program waits for the sample to complete before playing the next (it queues up). I tried putting the FlushSourceBuffer() in which I thought would flush the buffer and stop the sample to allow the sample to be played again.

The net affect I am after is for the sound to begin to play but if the space bar (shoot) is held down, I want the next sample to interrupt the current sample and start again (if that makes sense).

I have tried putting g_source->Stop(); followed by g_source->Start(); in the function, thinking that this may help but it made no difference.

Can anyone help?

Thanks
Sign In or Register to comment.