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

Getting the current "position" of a sound playing.

Last post 8/20/2009 9:05 PM by SquigglyFrog Studios. 3 replies.
  • 8/14/2009 11:41 PM

    Getting the current "position" of a sound playing.

    Hello,

    I am trying to get the position (play time) of a sound currently playing.
    I am using SoundEffectInstance for now and could not find something to do this in the help or in the forums.
    Basically, I'm looking for something similar to IDirectSoundBuffer8::GetCurrentPosition from DirectSound but for XNA GameStudio.
    Is it possible? Is there a workaround to get this value? Using something else than SoundEffectInstance?
    Of course, I know I can start a timer when I play the sound, but I want very precise synchronization between sound and the gameplay and need a GetCurrentPosition to recover from lags or anything that could delay the sound. The sound being played can also be quite long.

    Thanks for your attention,

    Dave.
    Frozax Games : Mac, PC and soon X360 games (www.frozax.com)
    Game Dev Blog : http://www.frozax.com/blog/
  • 8/15/2009 2:49 AM In reply to

    Re: Getting the current "position" of a sound playing.

    No dice. There really is not very much in the way of supporting low-level audio in XNA. The best you can get is the visualizer data for a playing music/song instance, and MediaPlayer.PlayPosition, which may or may not very exact (depending on buffering, etc). Also, you have to play data using Song to get to MediaPlayer; SoundEffectInstance doesn't do it.

    However: Diagnostics.Stopwatch is very accurate, and the XNA sound system really won't have any sudden lag spikes -- especially on Xbox, where the hardware is 100% known. Thus, you could probably time your playback with a Stopwatch, and it would be good enough for, say, a Guitar Hero type game. Note that the screen only re-paints every 16.7 milliseconds, so anything you display won't have better precision than that anyway.

    Jon Watte, Direct3D MVP
    Tweets, occasionally
    kW X-port 3ds Max .X exporter
    kW Animation source code
  • 8/15/2009 8:50 AM In reply to

    Re: Getting the current "position" of a sound playing.

    Thanks for the reply, Jon.

    I am a bit surprised but I'll see what I can do.

    I am using SoundEffectInstances because I want to be able to play multiple long sounds at the same time. I think you can't with Songs.

    Also, will I get better performance using XACT ?

    Thanks,

    Dave.

    Frozax Games : Mac, PC and soon X360 games (www.frozax.com)
    Game Dev Blog : http://www.frozax.com/blog/
  • 8/20/2009 9:05 PM In reply to

    Re: Getting the current "position" of a sound playing.

    jwatte:
    No dice. There really is not very much in the way of supporting low-level audio in XNA. The best you can get is the visualizer data for a playing music/song instance, and MediaPlayer.PlayPosition, which may or may not very exact (depending on buffering, etc). Also, you have to play data using Song to get to MediaPlayer; SoundEffectInstance doesn't do it.

    However: Diagnostics.Stopwatch is very accurate, and the XNA sound system really won't have any sudden lag spikes -- especially on Xbox, where the hardware is 100% known. Thus, you could probably time your playback with a Stopwatch, and it would be good enough for, say, a Guitar Hero type game. Note that the screen only re-paints every 16.7 milliseconds, so anything you display won't have better precision than that anyway.



    Thanks for that info as well JWatte.. after spending way too much time playing I Maed a gam3 with zomb1es.. grrr. friggin addicting thing.. I was kind of wondering how that was done adding the lasers etc right at certain beats in the music..
    Main Site | Blog | YouTube | Twitter
    Check out Cannon #12!
    Kollectiv 360 in Review Now
Page 1 of 1 (4 items) Previous Next