Sign in to follow this  
chadsxe

XAudio2 question - or audio in general.

Recommended Posts

Hi, For those familiar with XAudio2 you should know that in order to play a sound you have to load the audio data into a IXAudio2SourceVoice. Currently I am able to load the proper data into a IXAudio2SourceVoice and play it back with no problems. My question is that once a IXAudio2SourceVoice stops playing the audio do I have to then again reload data back into the IXAudio2SourceVoice in order to resue it, or am I suppose to be able to load the data once and call IXAudio2SourceVoice::Start as much as I need. At this current time I have to reload the data into the IXAudio2SourceVoice every time before I play the voice. Regards Chad

Share this post


Link to post
Share on other sites
You can reuse the same data, or even play the data multiple times at once. Just make sure you never change any data XAudio2 is using. I always create a new IXAudio2SourceVoice for each sound to play, and havnt had any performance issues with that.

eg

//abstract class which loads audio data from a file into a buffer
//which is then used by the playing sounds
SoundData *soundData;
...
//create the source voice
//SoundData::getFormat returns a WAVEFORMATEX pointer
IXAudio2SourceVoice* voice;
if(FAILED(audio->getXAudio2()->CreateSourceVoice(
&voice, soundData->getFormat(),
0,2,0,0,0)))
throwex(XAudio2Error);
//create buffer description
XAUDIO2_BUFFER buffer = {0};
//get a pointer to the SoundData's internal buffer
buffer.pAudioData = soundData->getData();
buffer.AudioBytes = soundData->getSize();
//no more audio data follows this
buffer.Flags = XAUDIO2_END_OF_STREAM;
//submit buffer
if(FAILED(voice->SubmitSourceBuffer(&buffer)))
throwex(XAudio2Error);


Share this post


Link to post
Share on other sites
Quote:
Original post by Fire Lancer
You can reuse the same data, or even play the data multiple times at once. Just make sure you never change any data XAudio2 is using. I always create a new IXAudio2SourceVoice for each sound to play, and havnt had any performance issues with that.

eg
*** Source Snippet Removed ***


So based off you example you are saying you can do something like this?


// Populate and load IXAudio2SourceVoice

// Play voice the 1st time
voice->Start( 0 );

// Play voice the 2nd time without having to repopulate IXAudio2SourceVoice
voice->Start( 0 );



Regards

Chad

[Edited by - chadsxe on February 14, 2010 6:08:24 PM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this