Virtu/Virtu/Xna/Services/XnaAudioService.cs
Sean Fausett 26bd5e3aa9 Cosmetic changes.
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
2010-04-01 23:00:24 +00:00

46 lines
1.2 KiB
C#

using System;
using System.Runtime.InteropServices;
using Jellyfish.Library;
namespace Jellyfish.Virtu.Services
{
#if WINDOWS
public sealed class XnaAudioService : AudioService
{
public XnaAudioService(Machine machine, GameBase game) :
base(machine)
{
if (game == null)
{
throw new ArgumentNullException("game");
}
_game = game;
_directSound.Start(_game.Window.Handle);
_directSound.Update += OnDirectSoundUpdate;
_game.Exiting += (sender, e) => _directSound.Stop();
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
_directSound.Dispose();
}
}
private void OnDirectSoundUpdate(object sender, DirectSoundUpdateEventArgs e) // audio thread
{
Update(e.BufferSize, (source, count) =>
{
Marshal.Copy(source, 0, e.Buffer, count);
});
}
private GameBase _game;
private DirectSound _directSound = new DirectSound(SampleRate, SampleChannels, SampleBits, SampleSize);
}
#endif
}