Question

I have two sound files:

  • Sound A is an 18 second intro designed to be played once
  • Sound B is a 1 minute looping track

I'd like to play Sound A once, then once Sound A is done, immediately play Sound B and keep looping Sound B until I tell it to stop. This is supposed to be looping town music in an RPG.

I've tried doing this in code using just SoundEffect, but there's a tiny yet noticeable gap between the end of Sound A and the beginning of Sound B. Even if I put monitoring code watching Sound A's SoundEffectInstance.State in the Update() function, I haven't been able to start Sound B exactly when Sound A finishes so that it's seamless.

I'd prefer to use SoundEffect because I can load WMA files rather than being stuck with WAVs in XACT.

Was it helpful?

Solution

A potentially second option. I'd imagine that the gap you're hearing is probably because the second sound needs to be either loaded into memory, or initialized, or the stream opened (not sure of the internal implementation). But if this is the case, I wonder if you could do something like this:

  1. Load the two sound effects (a and b)
  2. Begin playing sound effect A
  3. immediately begin playing sound effect B
  4. pause sound effect B after one frame
  5. when sound effect A finishes, restart sound effect A

My assumption is that since sound effect B is already initialized, it may start up quicker, thus lessening the perceived gap. Would love to hear if you get a chance to try this, and whether it worked :-)

OTHER TIPS

Unfortunately, simplicity in the SoundEffect API is paid for by a reducing the flexibility. This type of audio programming is what XACT excels in ... if you require a complex composition then you probably want to investigate moving to XACT.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top