CHRISTMASHAWK

This commit is contained in:
goyuken 2013-12-18 19:36:17 +00:00
parent 6a72763d52
commit 24ef496737
2 changed files with 155 additions and 8 deletions

View File

@ -151,6 +151,7 @@ namespace BizHawk.Client.EmuHawk
GlobalWin.Sound.StartSound();
RewireInputChain();
GlobalWin.Tools = new ToolManager();
RewireSound();
//TODO - replace this with some kind of standard dictionary-yielding parser in a separate component
string cmdRom = null;
string cmdLoadState = null;

View File

@ -5,7 +5,7 @@ using BizHawk.Common;
namespace BizHawk.Emulation.Common
{
public class NullEmulator : IEmulator, IVideoProvider, ISoundProvider
public class NullEmulator : IEmulator, IVideoProvider, ISyncSoundProvider, ISoundProvider
{
public string SystemId { get { return "NULL"; } }
public static readonly ControllerDefinition NullController = new ControllerDefinition { Name = "Null Controller" };
@ -17,10 +17,10 @@ namespace BizHawk.Emulation.Common
public CoreComm CoreComm { get; private set; }
public IVideoProvider VideoProvider { get { return this; } }
public ISoundProvider SoundProvider { get { return this; } }
public ISyncSoundProvider SyncSoundProvider { get { return new FakeSyncSound(this, 735); } }
public ISyncSoundProvider SyncSoundProvider { get { return this; } }
public bool StartAsyncSound() { return true; }
public void EndAsyncSound() { }
public NullEmulator(CoreComm comm)
{
CoreComm = comm;
@ -40,9 +40,11 @@ namespace BizHawk.Emulation.Common
public void FrameAdvance(bool render, bool rendersound)
{
if (render == false) return;
for (int i = 0; i < 256*192; i++)
for (int i = 0; i < 256 * 192; i++)
{
frameBuffer[i] = Colors.Luminosity((byte) rand.Next());
byte b = (byte)rand.Next();
frameBuffer[i] = Colors.ARGB(b, (byte)(255 - b), 0, 255);
//frameBuffer[i] = Colors.Luminosity((byte) rand.Next());
}
}
public ControllerDefinition ControllerDefinition { get { return NullController; } }
@ -68,9 +70,6 @@ namespace BizHawk.Emulation.Common
public int BufferWidth { get { return 256; } }
public int BufferHeight { get { return 192; } }
public int BackgroundColor { get { return 0; } }
public void GetSamples(short[] samples) { }
public void DiscardSamples() { }
public int MaxVolume { get; set; }
private readonly MemoryDomainList memoryDomains;
public MemoryDomainList MemoryDomains { get { return memoryDomains; } }
public void Dispose() { }
@ -79,6 +78,32 @@ namespace BizHawk.Emulation.Common
{
return new List<KeyValuePair<string, int>>();
}
Pleg pleg = new Pleg();
short[] sampbuff = new short[735 * 2];
public void GetSamples(out short[] samples, out int nsamp)
{
nsamp = 735;
samples = sampbuff;
pleg.Generate(samples);
}
public void DiscardSamples()
{
}
public void GetSamples(short[] samples)
{
pleg.Generate(samples);
}
public int MaxVolume
{
get;
set;
}
}
public class NullSound : ISoundProvider
@ -89,4 +114,125 @@ namespace BizHawk.Emulation.Common
public void DiscardSamples() { }
public int MaxVolume { get; set; }
}
class Pleg
{
string data = "H4sICI/2sVICAG91dDMudHh0AOxazdLbIAy8d6bvgkFImFsvufb936Yt3YyKvjBY5UvS6XDSxOZndyULy9H3ylLD1y8/baxHs/Lb5rNG2IT7zVKq9Msmrmf7Tb/st3qcP4ff7rdhb7itw04eXrVzsYWOTuXTt7yzl/OXvYHtDWwN+0cQi0IcqzJnxtchy9lDbo5rVODAAJvbdXWk1PiQooBiMBQPnxcOnYbhfkoCSgGUMmLxbgsoCSgdoCSgFEApwxZQArZ0uryWTp227DUBxVzDpbXLNUhlAVIGJELsZ6hb+kzACdePGqFqxPiE8QnjEualCcUZtb+mRKAUP0tlfyxHQAiIZUEsJ6gZYVXtTlVOiGWBmhk29qoS+zIQ6zQvJZ3rUHFtSwm9I++q5WJUS1At90mNAywhA/CqausZIPaPG/Jtgwhq6ug3qU5GdZMRMg+OmNR7IxfjjQwbDLXD5Q09Yta9QcfqKQfkz4Aw3fptrP0xNVfsCVu++j1S55KPJem01Yi2Bw/R27N2yxfj9znNI9TnESo1dikyT7J68aledNqi6vO1yjUI5RkQplu/mTWRf8u7LVTzZeXaaBRNeUxDTozimi8HRhuNqM/XJZOoiK5IeLJFOF5bEV3XSBGxeHiwjDSbaTXRBkhmuBUBU83T9IiK/wEPUmQOf3RIZxqxI2YVEQfDy7C3VZzJuWTqDuTkDzmW9PUT49KfXHIAlzD0s+qk6CJWx2ptFdzt9mqWsuYF6KT6aBoRAmWGK3MPMfEIkoHg2JIRPfajC39U1/K2TCeQ3SrqHi4V+YSK8VUq2hJoriKDd3So+NJYtBTUnvV4jaqq1omtCVYGsdi9RVmIyDdzqJoPNLdZ6O0q5MhzKh8LUAIFGQSIraFFA8VSg0QOagAJ+5xY1xpaBrGel2I9j2Nd63Kiv8u7tBDb5Mu7xaiYH6uovAcq0ttV5KIxvq6iMxb/HxV7CmpLPV6i6vhrGZdRHp5Us/SEPEwmD5eaXQEzycN5kIfZ5GHjDS7LediftAaxH/DN0r5riPWOLXld3xiI/unqWhgqnbCHieGzU8v9/YJK2wWrSqxHA0404bv+7yjpy1G7HwGBFAoiOIJw9PsABHVVHhBc+G8UJyAAYwv1lJASaZZAiPFbzCN6Pq7zKPq+pUWdtuy7oo9qp2YCNe59xGwe0RmWco1CWaDAfeKUA95KfXmA6+qlWKOpwieUZlTW/0NNSqH9DoAcAfmosUuYx2d5wf+MpP4ZYYbqAdBpoP5x73ExrRFHXwuKpSa+Z0R0mo+aFqsygKRrj9SerYqrZu1V3CRuqRbougPdId0qxLlfR6Psgam9PBxhT+wd+71zcKmeg05bVBWQboBkIF7Zq8xWxdXJ2iuZfILTSuil/SxIqSxDu+bX+RHOYjIxwUZTQIgeKoOuQ2Ac993tbsTdjbi7EXc34u5G3N2IuxtxdyPubsTdjbi7EXc34u5G3N2IuxtxdyPubsTdjbi7EXc34o927dAGAACEgeB27D8SEoVBleRmqGg+ORqRRqQRaUQakUakEWlEGjG1rmlEGpFGpBFpRBqRRqQRaUQakUakEWlEGpFGpBFpRBqRRqQRaUQakUakEWlEGpFGpBFpRBqRRqQRaUQakUb86OhoRBqRRqQRk+qaRqQRaUQakUakEWlEGpFGpBFvGnFXiHMetSzUwqZz46p5AAA=";
List<string> Lines = new List<string>();
int LineIDX = 0;
public Pleg()
{
var gz = new System.IO.Compression.GZipStream(
new MemoryStream(Convert.FromBase64String(data), false),
System.IO.Compression.CompressionMode.Decompress);
var tr = new StreamReader(gz);
string line;
while ((line = tr.ReadLine()) != null)
Lines.Add(line);
}
List<SinMan> SinMen = new List<SinMan>();
int deadtime = 0;
void Off(int c, int n)
{
for (int i = 0; i < SinMen.Count; i++)
{
var s = SinMen[i];
if (s.c == c && s.n == n)
{
SinMen.RemoveAt(i);
break;
}
}
}
void On(int c, int n)
{
if (c == 9)
return;
var s = new SinMan(1500, n);
s.c = c;
s.n = n;
SinMen.Add(s);
}
short Next()
{
int ret = 0;
foreach (var s in SinMen)
ret += s.Next();
if (ret > 32767) ret = 32767;
if (ret < -32767) ret = -32767;
return (short)ret;
}
string FetchNext()
{
string ret = Lines[LineIDX];
LineIDX++;
if (LineIDX == Lines.Count)
LineIDX = 0;
return ret;
}
public void Generate(short[] dest)
{
int idx = 0;
while (idx < dest.Length)
{
if (deadtime > 0)
{
short n = Next();
dest[idx++] = n;
dest[idx++] = n;
deadtime--;
}
else
{
string[] s = FetchNext().Split(':');
char c = s[0][0];
if (c == 'A')
deadtime = int.Parse(s[1]) * 40;
else if (c == 'O')
On(int.Parse(s[2]), int.Parse(s[1]));
else if (c == 'F')
Off(int.Parse(s[2]), int.Parse(s[1]));
}
}
}
}
class SinMan
{
public int c;
public int n;
double theta;
double freq;
double amp;
static double GetFreq(int note)
{
return Math.Pow(2.0, note / 12.0) * 13.0;
}
public short Next()
{
short result = (short)(Math.Sin(theta) * amp);
theta += freq * Math.PI / 22050.0;
if (theta >= Math.PI * 2.0)
theta -= Math.PI * 2.0;
return result;
}
public SinMan(int amp, int note)
{
this.amp = amp;
this.freq = GetFreq(note);
}
}
}