简体   繁体   English

Windows Phone 7多声音滞后

[英]Windows Phone 7 Multiple Sounds Lag

I'm making a drum machine. 我在做鼓机。 From what I've read, it looks like the XNA SoundEffect class runs based on a timer, which causes a noticeable lag, and stops the rhythm being smooth. 从我看过的内容看, XNA SoundEffect类看起来是基于计时器运行的,这会导致明显的延迟,并使节奏变得不平稳。

I tried to use MediaElement, 'til I found out you cannot play multiple sounds at the same time. 我尝试使用MediaElement,直到我发现您无法同时播放多种声音。

Are there any workarounds for this? 有什么解决方法吗? The sounds are handled by a timer, and need to play instantly. 声音由计时器处理,需要立即播放。

I've done some in-game use of the XNA SoundEffect class and not seen any lag when responding to user events - eg button presses - especially when the sound effect is pre-loaded from resources. 我已经在游戏中使用了XNA SoundEffect类,并且在响应用户事件(例如按钮按下)时没有看到任何滞后,尤其是在从资源中预加载声音效果时。

The XNA class is designed to be used for sound effects - so it should be ideal for a single drum machine hit. XNA类旨在用于声音效果-因此,它对于单鼓乐器打击非常理想。

If you then see problems with timing on IsLooping, then I guess you'll have to implement your own timer to trigger new instances - but my advice would be to try it first. 如果然后您发现IsLooping上的计时问题,那么我猜您将必须实现自己的计时器来触发新实例-但我的建议是先尝试一下。

Hope that helps 希望能有所帮助

I've been using some sound in my app and I used the code from the example given on the msdn code samples website: http://msdn.microsoft.com/en-us/library/ff431744(v=vs.92).aspx 我一直在应用程序中使用一些声音,并且使用了msdn代码示例网站上给出的示例代码: http : //msdn.microsoft.com/zh-cn/library/ff431744( v= vs.92) .aspx

It looks like they are updating the timer every 50ms. 看来他们每50毫秒更新一次计时器。 Also note that the SoundEffect variables ( coyoteSound and birdSound ) are private data members where they only load once. 还要注意, SoundEffect变量( coyoteSoundbirdSound )是私有数据成员,它们仅加载一次。 The event handler on the button clicks simply call SoundEffect.play() . 单击按钮上的事件处理程序只需调用SoundEffect.play()

public MainPage()
{
    InitializeComponent();

    LoadSound("Resources/NightAmbientCreatureOneShot_01.wav", out coyoteSound);
    LoadSound("Resources/AfternoonAmbientBirdOneShot_09.wav", out birdSound);
    LoadSoundInstance("Resources/NightAmbienceSimple_01.wav", out ambienceSound, out ambienceInstance);

    // Set the volume a little lower than full so it becomes the background.
    ambienceInstance.Volume = 0.8f;

    // Turn on looping so it runs continually in the background.
    ambienceInstance.IsLooped = true;

    // Timer to simulate the XNA game loop (SoundEffect classes are from the XNA Framework)
    DispatcherTimer XnaDispatchTimer = new DispatcherTimer();
    XnaDispatchTimer.Interval = TimeSpan.FromMilliseconds(50);

    // Call FrameworkDispatcher.Update to update the XNA Framework internals.
    XnaDispatchTimer.Tick += delegate { try { FrameworkDispatcher.Update(); } catch { } };

    // Start the DispatchTimer running.
    XnaDispatchTimer.Start();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM