Modified audio sample bit depth to use 16-bits per sample.

Sound emulation for XNA now uses DynamicSoundEffectInstance.

--HG--
extra : convert_revision : svn%3Affd33b8c-2492-42e0-bdc5-587b920b7d6d/trunk%4046563
This commit is contained in:
Sean Fausett 2010-05-20 10:12:56 +00:00
parent bc4caaf2b1
commit 6700099803
8 changed files with 16 additions and 60 deletions

View File

@ -108,9 +108,6 @@
<Compile Include="..\StringBuilderExtensions.cs"> <Compile Include="..\StringBuilderExtensions.cs">
<Link>StringBuilderExtensions.cs</Link> <Link>StringBuilderExtensions.cs</Link>
</Compile> </Compile>
<Compile Include="..\WaveFormat.cs">
<Link>WaveFormat.cs</Link>
</Compile>
<Compile Include="..\XmlSerializerHelpers.cs"> <Compile Include="..\XmlSerializerHelpers.cs">
<Link>XmlSerializerHelpers.cs</Link> <Link>XmlSerializerHelpers.cs</Link>
</Compile> </Compile>

View File

@ -120,9 +120,6 @@
<Compile Include="..\StringBuilderExtensions.cs"> <Compile Include="..\StringBuilderExtensions.cs">
<Link>StringBuilderExtensions.cs</Link> <Link>StringBuilderExtensions.cs</Link>
</Compile> </Compile>
<Compile Include="..\WaveFormat.cs">
<Link>WaveFormat.cs</Link>
</Compile>
<Compile Include="..\XmlSerializerHelpers.cs"> <Compile Include="..\XmlSerializerHelpers.cs">
<Link>XmlSerializerHelpers.cs</Link> <Link>XmlSerializerHelpers.cs</Link>
</Compile> </Compile>

View File

@ -101,12 +101,6 @@
<Compile Include="..\AssemblyCommentAttribute.cs"> <Compile Include="..\AssemblyCommentAttribute.cs">
<Link>AssemblyCommentAttribute.cs</Link> <Link>AssemblyCommentAttribute.cs</Link>
</Compile> </Compile>
<Compile Include="..\DirectSound.cs">
<Link>DirectSound.cs</Link>
</Compile>
<Compile Include="..\DirectSoundInterop.cs">
<Link>DirectSoundInterop.cs</Link>
</Compile>
<Compile Include="..\GCHandleHelpers.cs"> <Compile Include="..\GCHandleHelpers.cs">
<Link>GCHandleHelpers.cs</Link> <Link>GCHandleHelpers.cs</Link>
</Compile> </Compile>
@ -140,9 +134,6 @@
<Compile Include="..\StringBuilderExtensions.cs"> <Compile Include="..\StringBuilderExtensions.cs">
<Link>StringBuilderExtensions.cs</Link> <Link>StringBuilderExtensions.cs</Link>
</Compile> </Compile>
<Compile Include="..\WaveFormat.cs">
<Link>WaveFormat.cs</Link>
</Compile>
<Compile Include="..\XmlSerializerHelpers.cs"> <Compile Include="..\XmlSerializerHelpers.cs">
<Link>XmlSerializerHelpers.cs</Link> <Link>XmlSerializerHelpers.cs</Link>
</Compile> </Compile>

View File

@ -12,16 +12,15 @@ public AudioService(Machine machine) :
public void Output(int data) // machine thread public void Output(int data) // machine thread
{ {
_buffer[_index] = (byte)data; _buffer[_index + 0] = (byte)(data & 0xFF);
_index = (_index + 1) % SampleSize; _buffer[_index + 1] = (byte)((data >> 8) & 0xFF);
_index = (_index + 2) % SampleSize;
if (_index == 0) if (_index == 0)
{ {
_readEvent.Set(); _readEvent.Set();
if (Machine.Settings.Cpu.IsThrottled) if (Machine.Settings.Cpu.IsThrottled)
{ {
#if !WINDOWS_PHONE // TODO remove; implement phone audio
_writeEvent.WaitOne(); _writeEvent.WaitOne();
#endif
} }
} }
} }
@ -52,7 +51,7 @@ protected void Update(int bufferSize, Action<byte[], int> updateBuffer) // audio
public const int SampleRate = 44100; // hz public const int SampleRate = 44100; // hz
public const int SampleChannels = 1; public const int SampleChannels = 1;
public const int SampleBits = 8; public const int SampleBits = 16;
public const int SampleLatency = 40; // ms public const int SampleLatency = 40; // ms
public const int SampleSize = (SampleRate * SampleLatency / 1000) * SampleChannels * (SampleBits / 8); public const int SampleSize = (SampleRate * SampleLatency / 1000) * SampleChannels * (SampleBits / 8);

View File

@ -38,10 +38,7 @@ private void OnMediaSourceUpdate(object sender, WaveMediaStreamSourceUpdateEvent
// }); // });
//} //}
Update(e.BufferSize, (source, count) => Update(e.BufferSize, (source, count) => Buffer.BlockCopy(source, 0, e.Buffer, 0, count));
{
Buffer.BlockCopy(source, 0, e.Buffer, 0, count);
});
} }
private UserControl _page; private UserControl _page;

View File

@ -34,7 +34,7 @@ public void ToggleOutput()
private void FlushOutputEvent() private void FlushOutputEvent()
{ {
UpdateCycles(); UpdateCycles();
_audioService.Output(_highCycles * 255 / _totalCycles); // quick and dirty decimation _audioService.Output(_highCycles * short.MaxValue / _totalCycles); // quick and dirty decimation
_highCycles = _totalCycles = 0; _highCycles = _totalCycles = 0;
Machine.Events.AddEvent(CyclesPerFlush * Machine.Settings.Cpu.Multiplier, _flushOutputEvent); Machine.Events.AddEvent(CyclesPerFlush * Machine.Settings.Cpu.Multiplier, _flushOutputEvent);

View File

@ -44,10 +44,7 @@ private void OnDirectSoundUpdate(object sender, DirectSoundUpdateEventArgs e) //
// }); // });
//} //}
Update(e.BufferSize, (source, count) => Update(e.BufferSize, (source, count) => Marshal.Copy(source, 0, e.Buffer, count));
{
Marshal.Copy(source, 0, e.Buffer, count);
});
} }
private Window _window; private Window _window;

View File

@ -1,14 +1,11 @@
using System; using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using System.Threading;
using Jellyfish.Library; using Jellyfish.Library;
using Microsoft.Xna.Framework.Audio;
namespace Jellyfish.Virtu.Services namespace Jellyfish.Virtu.Services
{ {
public sealed class XnaAudioService : AudioService public sealed class XnaAudioService : AudioService
{ {
[SuppressMessage("Microsoft.Mobility", "CA1601:DoNotUseTimersThatPreventPowerStateChanges")]
public XnaAudioService(Machine machine, GameBase game) : public XnaAudioService(Machine machine, GameBase game) :
base(machine) base(machine)
{ {
@ -19,47 +16,28 @@ public XnaAudioService(Machine machine, GameBase game) :
_game = game; _game = game;
#if WINDOWS _dynamicSoundEffect.BufferNeeded += OnDynamicSoundEffectBufferNeeded;
_directSound.Start(_game.Window.Handle); _game.Exiting += (sender, e) => _dynamicSoundEffect.Stop();
_directSound.Update += OnDirectSoundUpdate;
_game.Exiting += (sender, e) => _directSound.Stop(); _dynamicSoundEffect.Play();
#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) protected override void Dispose(bool disposing)
{ {
if (disposing) if (disposing)
{ {
#if WINDOWS _dynamicSoundEffect.Dispose();
_directSound.Dispose();
#else
_timer.Dispose();
#endif
} }
base.Dispose(disposing); base.Dispose(disposing);
} }
#if WINDOWS private void OnDynamicSoundEffectBufferNeeded(object sender, EventArgs e) // audio thread
private void OnDirectSoundUpdate(object sender, DirectSoundUpdateEventArgs e) // audio thread
{ {
Update(e.BufferSize, (source, count) => Marshal.Copy(source, 0, e.Buffer, count)); Update(SampleSize, (source, count) => _dynamicSoundEffect.SubmitBuffer(source, 0, count));
} }
#else
private void OnTimerUpdate(object state) // audio thread
{
Update(0, null);
}
#endif
private GameBase _game; private GameBase _game;
#if WINDOWS private DynamicSoundEffectInstance _dynamicSoundEffect = new DynamicSoundEffectInstance(SampleRate, (AudioChannels)SampleChannels);
private DirectSound _directSound = new DirectSound(SampleRate, SampleChannels, SampleBits, SampleSize);
#else
private Timer _timer;
#endif
} }
} }