mirror of
https://github.com/digital-jellyfish/Virtu.git
synced 2024-06-02 12:41:31 +00:00
5f8c4ce9d8
Bumped version to 0.8.1 for next release. --HG-- extra : convert_revision : svn%3Affd33b8c-2492-42e0-bdc5-587b920b7d6d/trunk%4044502
64 lines
1.7 KiB
C#
64 lines
1.7 KiB
C#
using System;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
using System.Runtime.InteropServices;
|
|
using System.Threading;
|
|
using Jellyfish.Library;
|
|
|
|
namespace Jellyfish.Virtu.Services
|
|
{
|
|
public sealed class XnaAudioService : AudioService
|
|
{
|
|
[SuppressMessage("Microsoft.Mobility", "CA1601:DoNotUseTimersThatPreventPowerStateChanges")]
|
|
public XnaAudioService(Machine machine, GameBase game) :
|
|
base(machine)
|
|
{
|
|
if (game == null)
|
|
{
|
|
throw new ArgumentNullException("game");
|
|
}
|
|
|
|
_game = game;
|
|
|
|
#if WINDOWS
|
|
_directSound.Start(_game.Window.Handle);
|
|
_directSound.Update += OnDirectSoundUpdate;
|
|
_game.Exiting += (sender, e) => _directSound.Stop();
|
|
#else
|
|
_timer = new Timer(OnTimerUpdate, null, 0, SampleLatency);
|
|
_game.Exiting += (sender, e) => _timer.Change(Timeout.Infinite, Timeout.Infinite);
|
|
#endif
|
|
}
|
|
|
|
protected override void Dispose(bool disposing)
|
|
{
|
|
if (disposing)
|
|
{
|
|
#if WINDOWS
|
|
_directSound.Dispose();
|
|
#else
|
|
_timer.Dispose();
|
|
#endif
|
|
}
|
|
}
|
|
|
|
#if WINDOWS
|
|
private void OnDirectSoundUpdate(object sender, DirectSoundUpdateEventArgs e) // audio thread
|
|
{
|
|
Update(e.BufferSize, (source, count) => Marshal.Copy(source, 0, e.Buffer, count));
|
|
}
|
|
#else
|
|
private void OnTimerUpdate(object state) // audio thread
|
|
{
|
|
Update(0, null);
|
|
}
|
|
#endif
|
|
|
|
private GameBase _game;
|
|
#if WINDOWS
|
|
private DirectSound _directSound = new DirectSound(SampleRate, SampleChannels, SampleBits, SampleSize);
|
|
#else
|
|
private Timer _timer;
|
|
#endif
|
|
}
|
|
}
|