mirror of
https://github.com/digital-jellyfish/Virtu.git
synced 2024-06-02 12:41:31 +00:00
d22639c563
Fixed code analysis warnings. --HG-- extra : convert_revision : svn%3Affd33b8c-2492-42e0-bdc5-587b920b7d6d/trunk%4047095
52 lines
1.4 KiB
C#
52 lines
1.4 KiB
C#
using System;
|
|
using System.Runtime.InteropServices;
|
|
using System.Security;
|
|
using System.Windows;
|
|
using Jellyfish.Library;
|
|
|
|
namespace Jellyfish.Virtu.Services
|
|
{
|
|
public sealed class WpfAudioService : AudioService
|
|
{
|
|
[SecurityCritical]
|
|
public WpfAudioService(Machine machine, Window window) :
|
|
base(machine)
|
|
{
|
|
if (window == null)
|
|
{
|
|
throw new ArgumentNullException("window");
|
|
}
|
|
|
|
_window = window;
|
|
_directSound = new DirectSound(SampleRate, SampleChannels, SampleBits, SampleSize, OnDirectSoundUpdate);
|
|
|
|
_window.SourceInitialized += (sender, e) => _directSound.Start(_window.GetHandle());
|
|
_window.Closed += (sender, e) => _directSound.Stop();
|
|
}
|
|
|
|
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 Window _window;
|
|
private DirectSound _directSound;
|
|
//private int _count;
|
|
}
|
|
}
|