mirror of
https://github.com/digital-jellyfish/Virtu.git
synced 2024-06-11 10:29:31 +00:00
26bd5e3aa9
Modified to clear audio buffer on reset. Refactored keyboard services and unified key bindings where practical. --HG-- extra : convert_revision : svn%3Affd33b8c-2492-42e0-bdc5-587b920b7d6d/trunk%4044385
51 lines
1.7 KiB
C#
51 lines
1.7 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;
|
|
//_page.Closed += (sender, e) => _media.Stop(); // SL is missing Closed / Unloaded event
|
|
}
|
|
|
|
private void OnMediaSourceUpdate(object sender, WaveMediaStreamSourceUpdateEventArgs e) // audio thread
|
|
{
|
|
//if (_count++ % (1000 / SampleLatency) == 0)
|
|
//{
|
|
// _page.Dispatcher.BeginInvoke(new Action(() =>
|
|
// {
|
|
// ((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;
|
|
}
|
|
}
|