mirror of
https://github.com/digital-jellyfish/Virtu.git
synced 2024-06-02 12:41:31 +00:00
6700099803
Sound emulation for XNA now uses DynamicSoundEffectInstance. --HG-- extra : convert_revision : svn%3Affd33b8c-2492-42e0-bdc5-587b920b7d6d/trunk%4046563
50 lines
1.6 KiB
C#
50 lines
1.6 KiB
C#
using System;
|
|
using System.Windows.Controls;
|
|
using Jellyfish.Library;
|
|
|
|
namespace Jellyfish.Virtu.Services
|
|
{
|
|
public sealed class SilverlightAudioService : AudioService
|
|
{
|
|
public SilverlightAudioService(Machine machine, UserControl page, MediaElement media) :
|
|
base(machine)
|
|
{
|
|
if (page == null)
|
|
{
|
|
throw new ArgumentNullException("page");
|
|
}
|
|
if (media == null)
|
|
{
|
|
throw new ArgumentNullException("media");
|
|
}
|
|
|
|
_page = page;
|
|
_media = media;
|
|
|
|
_page.Loaded += (sender, e) => { _media.SetSource(_mediaSource); _media.Play(); };
|
|
_mediaSource.Update += OnMediaSourceUpdate;
|
|
#if !WINDOWS_PHONE
|
|
_page.Unloaded += (sender, e) => _media.Stop();
|
|
#endif
|
|
}
|
|
|
|
private void OnMediaSourceUpdate(object sender, WaveMediaStreamSourceUpdateEventArgs e) // audio thread
|
|
{
|
|
//if (_count++ % (1000 / SampleLatency) == 0)
|
|
//{
|
|
// _page.Dispatcher.BeginInvoke(() =>
|
|
// {
|
|
// ((MainPage)_page)._debug.Text += string.Concat(DateTime.Now, " OnMediaSourceUpdate", Environment.NewLine);
|
|
// });
|
|
//}
|
|
|
|
Update(e.BufferSize, (source, count) => Buffer.BlockCopy(source, 0, e.Buffer, 0, count));
|
|
}
|
|
|
|
private UserControl _page;
|
|
private MediaElement _media;
|
|
private WaveMediaStreamSource _mediaSource = new WaveMediaStreamSource(SampleRate, SampleChannels, SampleBits, SampleSize, SampleLatency);
|
|
//private int _count;
|
|
}
|
|
}
|