Xbox LIVE Indie Games
Sort Discussions: Previous Discussion Next Discussion
Page 1 of 1 (13 posts)

PlayCue has a gap between loops

Last post 12/18/2009 7:20 PM by imtrobin. 12 replies.
  • 12/12/2009 7:27 PM

    PlayCue has a gap between loops

    Hi

    I'm trying to play a machine gun loop when a key is pressed. To avoid memory allocation, I'm not calling GetCue but using soundBank.PlayCue directly. So when I detect a key is pressed, I call soundBank.PlayCue.

    In the XACT, I set the Instance Limit to 1 with "Fail To Play" Behavior at Max so the sound won't mix together into a large noise. This works fine but when I hold down the key, there is a slight gap when the cue is played again. The sound source loops fine, and if I set the sound to be "Infinite", there is also no gap, so it's not the file issue. How do I be able to setup to get the effect without memory allocation?
  • 12/13/2009 12:17 AM In reply to

    Re: PlayCue has a gap between loops

    How big a gap are we talking about here? If it's a small gap, is it possible that the sound is finishing before your code to play the sound again is reached? Personally, I prefer to set the Behaviour at Max to Replace and set up a random pitch variation to make it sound better. Otherwise, you could try having a cue instance, setting it to loop infinitely, and stop and start the cue manually.
  • 12/13/2009 6:34 AM In reply to

    Re: PlayCue has a gap between loops

    It's a short gap of about half a second but enought to break the continuity of the machine gun. It's not quite possible for that because I'm using the Audio3DSample, and I put the PlayCue call in HandleInput, which is 60 fps.

    I tried Max to Replace but it becomes random garble.

    The Cue instance is not good because of the memory allocation. For a machine gun, I fire it on and off a lot of times, generating a fair bit of garbage.
  • 12/13/2009 3:54 PM In reply to

    Re: PlayCue has a gap between loops

    imtrobin:
    n the XACT, I set the Instance Limit to 1 with "Fail To Play" Behavior at Max so the sound won't mix together into a large noise

    Why would it mix into a large noise? I'd say use PlayCue, leave it to mix but don't play a sound every frame... just when your shots are fired. Have the actual sample be fairly short and contain only a single shot and get the machine gun effect but playing more of them.

    On top of that if looping is important, I'd make a que and queue all most machine gun sounds then have a timer that checks if sounds are in the queue and issues a sound every so often... you can even run that on a separate thread if it was that important to get it spot on.

  • 12/14/2009 12:56 AM In reply to

    Re: PlayCue has a gap between loops

    I'm working on exactly the same problem at the moment, my approach isn't working just yet, but I think it's the right approach.

    I'm setting my cue to infinite loop. I instanciate the cue with its associated game object and that cue will persist for the entire game.

    Then, I plan to pause and resume the cue to start and stop the sound.

    I'm running into a bug right now whenever I try to resume the cue, I'll probably write a tutorial and post the code on my game site once I've got it.
  • 12/14/2009 7:07 AM In reply to

    Re: PlayCue has a gap between loops

    It mixed into a large noise because the source has a few machine guns chained together. My way is to cut the source up into 1 small gun sound and fire as fast as possible. It doesn't sound as good but I guess the important thing is it doesn't cause memory allocation.
  • 12/14/2009 6:15 PM In reply to

    Re: PlayCue has a gap between loops

    Um, excuse my ignorance here, but what is the memory allocation issue with a single cue? I don't know how the XACT engine deals with a cue, but I wouldn't have thought that having a private cue instance in your game would take up more memory than XACT uses internally when playing a cue.
  • 12/14/2009 7:19 PM In reply to

    Re: PlayCue has a gap between loops

    Actually, to echo manzo's post, are you sure you get garbage with just using Cues? Do you then set any local variables on that Cue enumerating them by name - the enumerators are usually creating garbage and if you set any paramters that way it might be easier to address your problem.
  • 12/18/2009 9:15 AM In reply to

    Re: PlayCue has a gap between loops

    The garbage happens on xbox, not PC.

    http://social.msdn.microsoft.com/Forums/en/xnaframework/thread/4afe59b7-68fc-4f54-9947-f005893045dd

    http://blogs.msdn.com/shawnhar/archive/2007/02/05/two-common-xact-gotchas.aspx

    I found my "solution" don't work well on xbox. It stutters after like 3 seconds, like this.....bbbbbb  b b bb  bb b b bbbb b. Gaps in between randomly. On PC, it sounds fine.
  • 12/18/2009 9:58 AM In reply to

    Re: PlayCue has a gap between loops

    The garbage happens becuase you don't keep references to your Cue instances not because the Cue instances allocate. That can easily be avoided by you preallocate a number of Cue isntances in an array and then use them in a round-robin fashion. That way you never loose reference to your instances and you dont create garbage - yet still have all advantages of your Cues. Think of it like you manually are recycling you garbage - people have been doing that for agest in other languages.

    We never experienced such stutters - are you sure you are not creating too many sounds? Having a limited number of pre-allocated Cue instances would also allow you to debug your timing better and see if you are saturating the system more than you should :)




  • 12/18/2009 10:39 AM In reply to

    Re: PlayCue has a gap between loops

    Preallocating cues will still cause garbage because you need to call GetCue again from the system once it finishes playing. I have tried that solution before some time ago. Are you testing on the xbox? Because on PC, it sounds great.

    I also noticed that on Xbox, the mixer seems to be flooded more easily. If I have two of such continuous sound playing from PlayCue (one for machine gun, one for engines), the stutter gap is much more worse than if I have one gun firing only. Again, on PC, no such issue. The mix priority in XACT seems to make no difference.

    I also noticed, on xbox, 3d sound position seems to be lagged. When I fire the gun while turning, on xbox, I can hear it turning softer when turning. Not on PC, using joypad controls too.

    I running at 30fps, but I doubt this should cause any timing issue with sound

    this.TargetElapsedTime = System.TimeSpan.FromMilliseconds (33);

     

  • 12/18/2009 11:26 AM In reply to

    Re: PlayCue has a gap between loops

    Don't you only need to call GetCue when you want to load a different cue into the cue instance? I'd thought that if you want to play the same cue again, then you don't need to call GetCue again. Are you talking about loading a different cue onto the instance?
  • 12/18/2009 7:20 PM In reply to

    Re: PlayCue has a gap between loops

    The GetCue I know don't work like that. Once the sound finish playing, you need to call GetCue again. Anyway, I tweaked variously settings quite throughly for half a day, and so far, I'm quite happy with the results, and should move on to other things.
Page 1 of 1 (13 posts) Previous Discussion Next Discussion
var gDomain='m.webtrends.com'; var gDcsId='dcschd84w10000w4lw9hcqmsz_8n3x'; var gTrackEvents=1; var gFpc='WT_FPC'; /*<\/scr"+"ipt>");} /*]]>*/
DCSIMG