开发者

Looping music with intro in XNA using SoundEffect

开发者 https://www.devze.com 2022-12-30 02:43 出处:网络
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 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 So开发者_Python百科undEffectInstance.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.


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 :-)


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号