mirror of
https://github.com/digital-jellyfish/Virtu.git
synced 2025-02-19 17:31:34 +00:00
Added audio volume to machine settings.
--HG-- extra : convert_revision : svn%3Affd33b8c-2492-42e0-bdc5-587b920b7d6d/trunk%4047214
This commit is contained in:
parent
d22639c563
commit
9fca4b220f
@ -26,6 +26,15 @@ namespace Jellyfish.Library
|
||||
_stopEvent.Close();
|
||||
}
|
||||
|
||||
public void SetVolume(double volume)
|
||||
{
|
||||
int attenuation = (volume < 0.01) ? (int)BufferVolume.Min : (int)Math.Floor(100 * 20 * Math.Log10(volume)); // 100 db
|
||||
if (_buffer != null)
|
||||
{
|
||||
_buffer.SetVolume(attenuation);
|
||||
}
|
||||
}
|
||||
|
||||
public void Start(IntPtr window)
|
||||
{
|
||||
_window = window;
|
||||
@ -62,8 +71,6 @@ namespace Jellyfish.Library
|
||||
};
|
||||
((IDirectSoundNotify)_buffer).SetNotificationPositions(positionEvents.Length, positionEvents);
|
||||
|
||||
_buffer.SetVolume(-1500); // 50 %
|
||||
|
||||
_buffer.Play(0, 0, BufferPlay.Looping);
|
||||
}
|
||||
|
||||
@ -113,10 +120,12 @@ namespace Jellyfish.Library
|
||||
{
|
||||
_buffer.Stop();
|
||||
Marshal.ReleaseComObject(_buffer);
|
||||
_buffer = null;
|
||||
}
|
||||
if (_device != null)
|
||||
{
|
||||
Marshal.ReleaseComObject(_device);
|
||||
_device = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,8 @@ namespace Jellyfish.Library
|
||||
[Flags]
|
||||
private enum BufferStatus { Playing = 0x00000001, BufferLost = 0x00000002, Looping = 0x00000004, Terminated = 0x00000020 }
|
||||
|
||||
private enum BufferVolume { Min = -10000, Max = 0 }
|
||||
|
||||
private enum CooperativeLevel { Normal = 1, Priority = 2 }
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
|
@ -7,6 +7,11 @@
|
||||
return (value < min) ? min : (value > max) ? max : value;
|
||||
}
|
||||
|
||||
public static double Clamp(double value, double min, double max)
|
||||
{
|
||||
return (value < min) ? min : (value > max) ? max : value;
|
||||
}
|
||||
|
||||
public static int ClampByte(int value)
|
||||
{
|
||||
return Clamp(value, byte.MinValue, byte.MaxValue);
|
||||
|
@ -154,8 +154,7 @@ namespace Jellyfish.Virtu
|
||||
_memory = Machine.Memory;
|
||||
|
||||
UpdateSettings();
|
||||
|
||||
Machine.Video.VSync += OnVideoVSync;
|
||||
Machine.Video.VSync += (sender, e) => UpdateSettings();
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
@ -3205,11 +3204,6 @@ namespace Jellyfish.Virtu
|
||||
}
|
||||
#endregion
|
||||
|
||||
private void OnVideoVSync(object sender, EventArgs e)
|
||||
{
|
||||
UpdateSettings();
|
||||
}
|
||||
|
||||
private void UpdateSettings()
|
||||
{
|
||||
_executeOpCode = Machine.Settings.Cpu.Is65C02 ? ExecuteOpCode65C02 : ExecuteOpCode65N02;
|
||||
|
@ -36,6 +36,7 @@ namespace Jellyfish.Virtu.Settings
|
||||
Button0 = 0, Button1 = 0, Button2 = 0
|
||||
}
|
||||
};
|
||||
Audio = new AudioSettings { Volume = 0.5 };
|
||||
Video = new VideoSettings
|
||||
{
|
||||
IsFullScreen = false, IsMonochrome = false, ScannerOptions = ScannerOptions.None,
|
||||
@ -168,6 +169,11 @@ namespace Jellyfish.Virtu.Settings
|
||||
Button2 = (int)buttons.Attribute("Button2")
|
||||
}
|
||||
};
|
||||
var audio = root.Element(ns + "Audio");
|
||||
Audio = new AudioSettings
|
||||
{
|
||||
Volume = (double)audio.Attribute("Volume")
|
||||
};
|
||||
var video = root.Element(ns + "Video");
|
||||
var color = video.Element(ns + "Color");
|
||||
Video = new VideoSettings
|
||||
@ -268,6 +274,8 @@ namespace Jellyfish.Virtu.Settings
|
||||
new XAttribute("Button0", Keyboard.Key.Button0),
|
||||
new XAttribute("Button1", Keyboard.Key.Button1),
|
||||
new XAttribute("Button2", Keyboard.Key.Button2)))),
|
||||
new XElement(ns + "Audio",
|
||||
new XAttribute("Volume", Audio.Volume)),
|
||||
new XElement(ns + "Video",
|
||||
new XAttribute("IsFullScreen", Video.IsFullScreen),
|
||||
new XAttribute("IsMonochrome", Video.IsMonochrome),
|
||||
@ -301,6 +309,7 @@ namespace Jellyfish.Virtu.Settings
|
||||
public DiskIISettings DiskII { get; set; }
|
||||
public KeyboardSettings Keyboard { get; set; }
|
||||
public GamePortSettings GamePort { get; set; }
|
||||
public AudioSettings Audio { get; set; }
|
||||
public VideoSettings Video { get; set; }
|
||||
|
||||
public const string FileName = "Settings.xml";
|
||||
@ -360,6 +369,11 @@ namespace Jellyfish.Virtu.Settings
|
||||
public KeySettings Key { get; set; }
|
||||
}
|
||||
|
||||
public sealed class AudioSettings
|
||||
{
|
||||
public double Volume { get; set; }
|
||||
};
|
||||
|
||||
public sealed class ColorSettings
|
||||
{
|
||||
public uint Black { get; set; }
|
||||
|
@ -4,9 +4,9 @@ using System.Threading;
|
||||
|
||||
namespace Jellyfish.Virtu.Services
|
||||
{
|
||||
public class AudioService : MachineService
|
||||
public abstract class AudioService : MachineService
|
||||
{
|
||||
public AudioService(Machine machine) :
|
||||
protected AudioService(Machine machine) :
|
||||
base(machine)
|
||||
{
|
||||
}
|
||||
@ -31,6 +31,8 @@ namespace Jellyfish.Virtu.Services
|
||||
Buffer.BlockCopy(SampleZero, 0, _buffer, 0, SampleSize);
|
||||
}
|
||||
|
||||
public abstract void SetVolume(double volume); // machine thread
|
||||
|
||||
public override void Stop() // main thread
|
||||
{
|
||||
_readEvent.Set(); // signal events; avoids deadlock
|
||||
|
@ -29,6 +29,11 @@ namespace Jellyfish.Virtu.Services
|
||||
#endif
|
||||
}
|
||||
|
||||
public override void SetVolume(double volume) // machine thread
|
||||
{
|
||||
_media.Dispatcher.BeginInvoke(() => _media.Volume = volume);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
|
@ -15,6 +15,9 @@ namespace Jellyfish.Virtu
|
||||
{
|
||||
_audioService = Machine.Services.GetService<AudioService>();
|
||||
|
||||
UpdateSettings();
|
||||
Machine.Video.VSync += (sender, e) => UpdateSettings();
|
||||
|
||||
Machine.Events.AddEvent(CyclesPerFlush * Machine.Settings.Cpu.Multiplier, _flushOutputEvent);
|
||||
}
|
||||
|
||||
@ -51,6 +54,11 @@ namespace Jellyfish.Virtu
|
||||
_lastCycles = Machine.Cpu.Cycles;
|
||||
}
|
||||
|
||||
private void UpdateSettings()
|
||||
{
|
||||
_audioService.SetVolume(Machine.Settings.Audio.Volume);
|
||||
}
|
||||
|
||||
private const int CyclesPerFlush = 23;
|
||||
|
||||
private Action _flushOutputEvent;
|
||||
|
@ -24,6 +24,11 @@ namespace Jellyfish.Virtu.Services
|
||||
_window.Closed += (sender, e) => _directSound.Stop();
|
||||
}
|
||||
|
||||
public override void SetVolume(double volume) // machine thread
|
||||
{
|
||||
_directSound.SetVolume(volume);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
|
@ -23,6 +23,11 @@ namespace Jellyfish.Virtu.Services
|
||||
_dynamicSoundEffect.Play();
|
||||
}
|
||||
|
||||
public override void SetVolume(double volume) // machine thread
|
||||
{
|
||||
_dynamicSoundEffect.Volume = (float)volume;
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
|
Loading…
x
Reference in New Issue
Block a user