Virtu/Virtu/Xna/Services/XnaAudioService.cs
Sean Fausett 0182641281 Merged machine settings into machine components.
Added save state support to all machine components.
Switched from xml serialization to binary serialization.
Refactored audio service for performance.
Bumped machine version to 0.9.0 for next release.
Miscellaneous cosmetic or minor changes.
2010-11-29 09:08:11 +13:00

57 lines
1.6 KiB
C#

using System;
using Jellyfish.Library;
using Microsoft.Xna.Framework.Audio;
namespace Jellyfish.Virtu.Services
{
public sealed class XnaAudioService : AudioService
{
public XnaAudioService(Machine machine, GameBase game) :
base(machine)
{
if (game == null)
{
throw new ArgumentNullException("game");
}
_game = game;
_dynamicSoundEffect.BufferNeeded += OnDynamicSoundEffectBufferNeeded;
_game.Exiting += (sender, e) => _dynamicSoundEffect.Stop();
_dynamicSoundEffect.SubmitBuffer(SampleZero);
_dynamicSoundEffect.Play();
}
public override void SetVolume(double volume)
{
_dynamicSoundEffect.Volume = (float)volume;
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
_dynamicSoundEffect.Dispose();
}
base.Dispose(disposing);
}
private void OnDynamicSoundEffectBufferNeeded(object sender, EventArgs e) // audio thread
{
//if (_count++ % (1000 / SampleLatency) == 0)
//{
// DebugService.WriteLine("OnDynamicSoundEffectBufferNeeded");
//}
_dynamicSoundEffect.SubmitBuffer(Source, 0, SampleSize);
Update();
}
private GameBase _game;
private DynamicSoundEffectInstance _dynamicSoundEffect = new DynamicSoundEffectInstance(SampleRate, (AudioChannels)SampleChannels);
//private int _count;
}
}