XNA Creators Club Online
Page 1 of 1 (7 items)
Sort Posts: Previous Next

Silly XAudio2 question regarding IXAudio2SourceVoice's - how many to use?

Last post 3/5/2010 4:52 PM by Iveco. 6 replies.
  • 9/21/2009 9:12 PM

    Silly XAudio2 question regarding IXAudio2SourceVoice's - how many to use?

    Hey, I'm working on updating a game to use XAudio2 instead of Directsound. The way the game handles sounds is the standard affair - load some wav files, create dsound buffers for each and play them when required. I'm a little confused about the source voices - should I create a source voice for every sound I'm loading? I'm sure I saw a post on a forum somewhere saying no to that, but I can't find it now and i'm not 100% sure if that's actually what they said. If you're not supposed to create source voices for all the sounds that can potentially play in your game, how do you handle it? Do you create a pool of source buffers and find an empty one to use when it comes to play a sound? Is it a bad idea to create and release source voices whenever they're required or is there high overhead from doing this? I'm still working on implementing XAudio2 so I haven't had much of a chance to play around with this yet..any help would be appreciated!
  • 9/22/2009 12:37 PM In reply to

    Re: Silly XAudio2 question regarding IXAudio2SourceVoice's - how many to use?

    I recommend reading everything in the SDK about XAudio2 first. There are also a few good tutorials to start with. You will need SourceVoices for each sound but you only will need one MasterVoice. It's important to understand the XAudio2 audio graph (chain). SourceVoices can also be attached to SubMixVoices (effects processing voices). Therefore you can get the chain like: SourceVoice -> SubMixVoice -> MasterVoice (final output device/speakers). Probably you won't need SubMixVoices in the beginning. You can use callbacks from the engine to find out when particular sounds finished their playback and release the SourceVoice afterwards.

    http://www.gamasutra.com/view/feature/3525/sponsored_feature_an_introduction_.php?page=3

    Regards from Germany
  • 9/22/2009 3:05 PM In reply to

    Re: Silly XAudio2 question regarding IXAudio2SourceVoice's - how many to use?

    Thanks for that - I was hoping it'd be a case of a sourcevoice per sound. I tried it last night and I was hearing audio, only sounds were cutting off early or playing late. It's still a work in progress so i'm not worried about that yet. At least I know i'm on the right track! Thanks for the link too, looks good. Didn't see it while googling for some reason..
  • 9/22/2009 4:31 PM In reply to

    Re: Silly XAudio2 question regarding IXAudio2SourceVoice's - how many to use?

    Sure no problem. It's really hard to find useful information about XAudio2. This forum is also a very good source for further information. If you have anymore questions don't hesitate to post here.
    Regards from Germany
  • 12/20/2009 8:20 AM In reply to

    Re: Silly XAudio2 question regarding IXAudio2SourceVoice's - how many to use?

    Iveco,

      In the simple case, you can create a SourceVoice per sound effect that you're playing in your game.  Once you start to push the limits a bit, though, you'll find that this approach doesn't scale.

    The best way to do this is to create a pool of voices at level load time.  Use those voices during gameplay, finding one that is available whenever you need to play a new sound. 

    Since there are some things on a voice that can't change once it's created, you need a two-dimensional vector to store the pool of voices.  One dimension in the number of channels in the source audio (1, 2, 4, 6, etc).  The second dimension is the type of audio.  If you restrict all of your source assets to a single format, then you only need a single dimension in your vector/array.  Each element in the vector should, ideally, be a pointer to a list of SourceVoices, as well as some state associated with each voice. 

    Look for a sample concerning voice reuse in the next DirectX SDK.  One of my colleagues is also talking about this subject at Microsoft Gamefest in Seattle in February.  Keep an eye on http://www.microsoftgamefest.com/ for more details about his talk.

    A non-playing voice takes essentially zero processor time, and uses very little memory, if you use streaming audio.  The actual voice object is very lightweight.  You should be able to have hundreds, if not thousands, created, as long as they aren't all playing.  You should be able to play a hundred or so voices at one time, before you start running into problems outputting the audio.
    Cullen Waters

    XDC

    Microsoft
  • 2/8/2010 7:31 PM In reply to

    Re: Silly XAudio2 question regarding IXAudio2SourceVoice's - how many to use?

    Hi Culin23, I've downloaded the new SDK that came out this month and didn't see any new samples in the XAudio2 folder. Am I missing something? would you be able to elaborate a bit on why the approach of creating a source voice per sound doesn't scale? I really love the XAudio2 api but some parts of it are still a little confusing. Thanks!
  • 3/5/2010 4:52 PM In reply to

    Re: Silly XAudio2 question regarding IXAudio2SourceVoice's - how many to use?

    @Culin23

    Is it right that I see that in this concept the goal is to reuse the existing sourcevoice buffers? So instead of recreating the exact same SourceVoice and parsing the memory, filling the memory etc. I just create another SourceVoice but use the buffer from the existing SourceVoice and so use the same buffer in multiply SourceVoices? At the best they all should preloaded (at level load time) and be ready to be played at any time than. Is that right?

    Regards,

    Iveco

    Regards from Germany
Page 1 of 1 (7 items) Previous Next