mirror of
https://github.com/digital-jellyfish/Virtu.git
synced 2024-05-31 15:41:33 +00:00
2167383a00
Upgraded to FxCop 10.0. Dropped Silverlight Toolkit dependency (for now). Modified AudioService to avoid deadlocks by using timeouts. Refactored DebugService and implementations. Modified SilverlightVideoService to handle browser zoom. Split Wpf MainWindow into MainPage child control. --HG-- extra : convert_revision : svn%3Affd33b8c-2492-42e0-bdc5-587b920b7d6d/trunk%4048619
60 lines
1.6 KiB
C#
60 lines
1.6 KiB
C#
using System;
|
|
using System.Runtime.InteropServices;
|
|
using System.Security;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using Jellyfish.Library;
|
|
|
|
namespace Jellyfish.Virtu.Services
|
|
{
|
|
public sealed class WpfAudioService : AudioService
|
|
{
|
|
[SecurityCritical]
|
|
public WpfAudioService(Machine machine, UserControl page) :
|
|
base(machine)
|
|
{
|
|
if (page == null)
|
|
{
|
|
throw new ArgumentNullException("page");
|
|
}
|
|
|
|
_directSound = new DirectSound(SampleRate, SampleChannels, SampleBits, SampleSize, OnDirectSoundUpdate);
|
|
|
|
page.Loaded += (sender, e) =>
|
|
{
|
|
var window = Window.GetWindow(page);
|
|
_directSound.Start(window.GetHandle());
|
|
window.Closed += (_sender, _e) => _directSound.Stop();
|
|
};
|
|
}
|
|
|
|
public override void SetVolume(double volume) // machine thread
|
|
{
|
|
_directSound.SetVolume(volume);
|
|
}
|
|
|
|
protected override void Dispose(bool disposing)
|
|
{
|
|
if (disposing)
|
|
{
|
|
_directSound.Dispose();
|
|
}
|
|
|
|
base.Dispose(disposing);
|
|
}
|
|
|
|
private void OnDirectSoundUpdate(IntPtr buffer, int bufferSize) // audio thread
|
|
{
|
|
//if (_count++ % (1000 / SampleLatency) == 0)
|
|
//{
|
|
// DebugService.WriteLine("OnDirectSoundUpdate");
|
|
//}
|
|
|
|
Update(bufferSize, (source, count) => Marshal.Copy(source, 0, buffer, count));
|
|
}
|
|
|
|
private DirectSound _directSound;
|
|
//private int _count;
|
|
}
|
|
}
|