diff --git a/BizHawk.Emulation/BizHawk.Emulation.csproj b/BizHawk.Emulation/BizHawk.Emulation.csproj
index 6f6a10cd86..7e0118d411 100644
--- a/BizHawk.Emulation/BizHawk.Emulation.csproj
+++ b/BizHawk.Emulation/BizHawk.Emulation.csproj
@@ -502,6 +502,7 @@
+
diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/APU.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/APU.cs
index d98d62b147..6177c40212 100644
--- a/BizHawk.Emulation/Consoles/Nintendo/NES/APU.cs
+++ b/BizHawk.Emulation/Consoles/Nintendo/NES/APU.cs
@@ -33,12 +33,17 @@ namespace BizHawk.Emulation.Consoles.Nintendo
public bool EnableNoise = false;
public bool EnableDMC = true;
+ public bool recalculate = false;
+
NES nes;
public APU(NES nes, APU old, bool pal)
{
this.nes = nes;
dmc = new DMCUnit(this, pal);
- noise = new NoiseUnit(pal);
+ noise = new NoiseUnit(this, pal);
+ triangle = new TriangleUnit(this);
+ pulse[0] = new PulseUnit(this, 0);
+ pulse[1] = new PulseUnit(this, 1);
if (old != null)
{
EnableSquare1 = old.EnableSquare1;
@@ -75,8 +80,9 @@ namespace BizHawk.Emulation.Consoles.Nintendo
class PulseUnit
{
- public PulseUnit(int unit) { this.unit = unit; }
+ public PulseUnit(APU apu, int unit) { this.unit = unit; this.apu = apu; }
public int unit;
+ APU apu;
//reg0
int duty_cnt, env_loop, env_constant, env_cnt_value;
@@ -251,26 +257,35 @@ namespace BizHawk.Emulation.Consoles.Nintendo
//reload timer
timer_counter = timer_raw_reload_value;
}
-
+
+ int newsample;
+
if (duty_value) //high state of duty cycle
{
- sample = env_output;
+ newsample = env_output;
if (swp_silence)
- sample = env_output >> 1; //(a little biasing hack here)
+ newsample = env_output >> 1; //(a little biasing hack here)
if (len_cnt == 0) //length counter is 0
- sample = env_output >> 1; //silenced (a little biasing hack here)
+ newsample = env_output >> 1; //silenced (a little biasing hack here)
}
else
- sample = env_output >> 1; //duty cycle is 0, silenced.
+ newsample = env_output >> 1; //duty cycle is 0, silenced.
- sample -= env_output >> 1; //unbias
+ newsample -= env_output >> 1; //unbias
+ if (newsample != sample)
+ {
+ apu.recalculate = true;
+ sample = newsample;
+ }
}
}
class NoiseUnit
{
+ APU apu;
+
//reg0 (sweep)
int env_cnt_value, env_loop, env_constant;
@@ -292,8 +307,9 @@ namespace BizHawk.Emulation.Consoles.Nintendo
int[] NOISE_TABLE;
- public NoiseUnit(bool pal)
+ public NoiseUnit(APU apu, bool pal)
{
+ this.apu = apu;
NOISE_TABLE = pal ? NOISE_TABLE_PAL : NOISE_TABLE_NTSC;
}
@@ -413,9 +429,15 @@ namespace BizHawk.Emulation.Consoles.Nintendo
}
//unbiasing is rolled in here
- if (len_cnt == 0) sample = 0;
- else if (noise_bit) sample = -env_output;
- else sample = env_output;
+ int newsample;
+ if (len_cnt == 0) newsample = 0;
+ else if (noise_bit) newsample = -env_output;
+ else newsample = env_output;
+ if (newsample != sample)
+ {
+ apu.recalculate = true;
+ sample = newsample;
+ }
}
}
@@ -433,6 +455,9 @@ namespace BizHawk.Emulation.Consoles.Nintendo
int seq = 15;
public int sample;
+ APU apu;
+ public TriangleUnit(APU apu) { this.apu = apu; }
+
public void SyncState(Serializer ser)
{
ser.Sync("linear_counter_reload", ref linear_counter_reload);
@@ -500,6 +525,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
//is clocked in frame counter.
if (en)
{
+ int newsample;
if (timer > 0) timer--;
if (timer == 0)
{
@@ -507,16 +533,21 @@ namespace BizHawk.Emulation.Consoles.Nintendo
timer = timer_cnt_reload;
}
if(CFG_DECLICK)
- sample = TRIANGLE_TABLE[(seq+8)&0x1F];
+ newsample = TRIANGLE_TABLE[(seq + 8) & 0x1F];
else
- sample = TRIANGLE_TABLE[seq];
+ newsample = TRIANGLE_TABLE[seq];
//special hack: frequently, games will use the maximum frequency triangle in order to mute it
//apparently this results in the DAC for the triangle wave outputting a steady level at about 7.5
//so we'll emulate it at the digital level
- if (timer_cnt_reload == 1) sample = 8;
+ if (timer_cnt_reload == 1) newsample = 8;
- sample -= 8; //unbias
+ newsample -= 8; //unbias
+ if (newsample != sample)
+ {
+ apu.recalculate = true;
+ sample = newsample;
+ }
}
}
@@ -640,6 +671,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
out_deltacounter -= 2;
}
//apu.nes.LogLine("dmc out sample: {0}", out_deltacounter);
+ apu.recalculate = true;
}
//The right shift register is clocked.
@@ -721,6 +753,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
case 1:
out_deltacounter = val & 0x7F;
//apu.nes.LogLine("~~ out_deltacounter set to {0}", out_deltacounter);
+ apu.recalculate = true;
break;
case 2:
user_address = 0xC000 | (val << 6);
@@ -775,8 +808,8 @@ namespace BizHawk.Emulation.Consoles.Nintendo
SyncIRQ();
}
- PulseUnit[] pulse = { new PulseUnit(0), new PulseUnit(1) };
- TriangleUnit triangle = new TriangleUnit();
+ PulseUnit[] pulse = new PulseUnit[2];
+ TriangleUnit triangle;
NoiseUnit noise; //= new NoiseUnit();
DMCUnit dmc;
@@ -1041,17 +1074,32 @@ namespace BizHawk.Emulation.Consoles.Nintendo
//we want the changes to affect it on the *next* cycle.
}
- int loopy = 0;
- public const int DECIMATIONFACTOR = 20;
- const int QUEUESIZE = 1789773 / DECIMATIONFACTOR; //1 second, should be enough
- public QuickQueue squeue = new QuickQueue(QUEUESIZE);
+ //int loopy = 0;
+ //public const int DECIMATIONFACTOR = 20;
+ //const int QUEUESIZE = 1789773 / DECIMATIONFACTOR; //1 second, should be enough
+ //public QuickQueue squeue = new QuickQueue(QUEUESIZE);
+
+ public struct Delta
+ {
+ public uint time;
+ public int value;
+ public Delta(uint time, int value)
+ {
+ this.time = time;
+ this.value = value;
+ }
+ }
+ public List dlist = new List();
+
+ public uint sampleclock = 0;
+
+ int oldmix = 0;
+
void EmitSample()
{
- //here we throw out 19/20 of the samples, for an easy speedup... blech.
- loopy++;
- if (loopy == DECIMATIONFACTOR)
+ if (recalculate)
{
- loopy = 0;
+ recalculate = false;
int s_pulse0 = pulse[0].sample;
int s_pulse1 = pulse[1].sample;
@@ -1075,24 +1123,24 @@ namespace BizHawk.Emulation.Consoles.Nintendo
//this needs to leave enough headroom for straying DC bias due to the DMC unit getting stuck outputs. smb3 is bad about that.
int mix = (int)(50000 * output);
- //more properly correct
- //float pulse_out, tnd_out;
- //if (s_pulse0 == 0 && s_pulse1 == 0)
- // pulse_out = 0;
- //else pulse_out = 95.88f / ((8128.0f / (s_pulse0 + s_pulse1)) + 100.0f);
- //if (s_tri == 0 && s_noise == 0 && s_dmc == 0)
- // tnd_out = 0;
- //else tnd_out = 159.79f / (1 / ((s_tri / 8227.0f) + (s_noise / 12241.0f * NOISEADJUST) + (s_dmc / 22638.0f)) + 100);
- //float output = pulse_out + tnd_out;
- //output = output * 2 - 1;
- //this needs to leave enough headroom for straying DC bias due to the DMC unit getting stuck outputs. smb3 is bad about that.
- //int mix = (int)(20000 * output);
-
-
-
- if (squeue.Count < QUEUESIZE)
- squeue.Enqueue((short)mix);
+ dlist.Add(new Delta(sampleclock, mix - oldmix));
+ oldmix = mix;
}
+ //more properly correct
+ //float pulse_out, tnd_out;
+ //if (s_pulse0 == 0 && s_pulse1 == 0)
+ // pulse_out = 0;
+ //else pulse_out = 95.88f / ((8128.0f / (s_pulse0 + s_pulse1)) + 100.0f);
+ //if (s_tri == 0 && s_noise == 0 && s_dmc == 0)
+ // tnd_out = 0;
+ //else tnd_out = 159.79f / (1 / ((s_tri / 8227.0f) + (s_noise / 12241.0f * NOISEADJUST) + (s_dmc / 22638.0f)) + 100);
+ //float output = pulse_out + tnd_out;
+ //output = output * 2 - 1;
+ //this needs to leave enough headroom for straying DC bias due to the DMC unit getting stuck outputs. smb3 is bad about that.
+ //int mix = (int)(20000 * output);
+
+
+ sampleclock++;
}
} //class APU
diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/Core.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/Core.cs
index 18b52d891d..5e4318dc54 100644
--- a/BizHawk.Emulation/Consoles/Nintendo/NES/Core.cs
+++ b/BizHawk.Emulation/Consoles/Nintendo/NES/Core.cs
@@ -62,56 +62,84 @@ namespace BizHawk.Emulation.Consoles.Nintendo
}
}
- class MagicSoundProvider : ISoundProvider, IDisposable
+ class MagicSoundProvider : ISoundProvider, ISyncSoundProvider, IDisposable
{
- Sound.Utilities.SpeexResampler resampler;
- ISoundProvider output;
+ Sound.Utilities.BlipBuffer blip;
NES nes;
+ const int blipbuffsize = 4096;
+
public MagicSoundProvider(NES nes, uint infreq)
{
this.nes = nes;
- var actualMetaspu = new Sound.MetaspuSoundProvider(Sound.ESynchMethod.ESynchMethod_V);
+
+ blip = new Sound.Utilities.BlipBuffer(blipbuffsize);
+ blip.SetRates(infreq, 44100);
+
+ //var actualMetaspu = new Sound.MetaspuSoundProvider(Sound.ESynchMethod.ESynchMethod_V);
//1.789773mhz NTSC
- resampler = new Sound.Utilities.SpeexResampler(2, infreq, 44100 * APU.DECIMATIONFACTOR, infreq, 44100, actualMetaspu.buffer.enqueue_samples);
- output = new Sound.Utilities.DCFilter(actualMetaspu);
+ //resampler = new Sound.Utilities.SpeexResampler(2, infreq, 44100 * APU.DECIMATIONFACTOR, infreq, 44100, actualMetaspu.buffer.enqueue_samples);
+ //output = new Sound.Utilities.DCFilter(actualMetaspu);
}
- Random r = new Random();
public void GetSamples(short[] samples)
{
- if (nes.apu.squeue.Count == 0)
- return;
- var monosampbuf = nes.apu.squeue.ToArray(2);
- nes.apu.squeue.Clear();
- if (monosampbuf.Length > 0)
- {
- var stereosampbuf = new short[monosampbuf.Length * 2];
- for (int i = 0; i < monosampbuf.Length; i++)
- {
- stereosampbuf[i * 2 + 0] = monosampbuf[i];
- stereosampbuf[i * 2 + 1] = monosampbuf[i];
- }
- resampler.EnqueueSamples(stereosampbuf, monosampbuf.Length);
- resampler.Flush();
- output.GetSamples(samples);
- }
+ Console.WriteLine("Sync: {0}", nes.apu.dlist.Count);
+ int nsamp = samples.Length / 2;
+ if (nsamp > blipbuffsize) // oh well.
+ nsamp = blipbuffsize;
+ uint targetclock = (uint)blip.ClocksNeeded(nsamp);
+ uint actualclock = nes.apu.sampleclock;
+ foreach (var d in nes.apu.dlist)
+ blip.AddDelta(d.time * targetclock / actualclock, d.value);
+ nes.apu.dlist.Clear();
+ blip.EndFrame(targetclock);
+ nes.apu.sampleclock = 0;
+
+ blip.ReadSamples(samples, nsamp, true);
+ // duplicate to stereo
+ for (int i = 0; i < nsamp * 2; i += 2)
+ samples[i + 1] = samples[i];
//mix in the cart's extra sound circuit
nes.board.ApplyCustomAudio(samples);
}
+ public void GetSamples(out short[] samples, out int nsamp)
+ {
+ Console.WriteLine("ASync: {0}", nes.apu.dlist.Count);
+ foreach (var d in nes.apu.dlist)
+ blip.AddDelta(d.time, d.value);
+ nes.apu.dlist.Clear();
+ blip.EndFrame(nes.apu.sampleclock);
+ nes.apu.sampleclock = 0;
+
+ nsamp = blip.SamplesAvailable();
+ samples = new short[nsamp * 2];
+
+ blip.ReadSamples(samples, nsamp, true);
+ // duplicate to stereo
+ for (int i = 0; i < nsamp * 2; i += 2)
+ samples[i + 1] = samples[i];
+
+ nes.board.ApplyCustomAudio(samples);
+ }
+
public void DiscardSamples()
{
- output.DiscardSamples();
+ nes.apu.dlist.Clear();
+ nes.apu.sampleclock = 0;
}
public int MaxVolume { get; set; }
public void Dispose()
{
- resampler.Dispose();
- resampler = null;
+ if (blip != null)
+ {
+ blip.Dispose();
+ blip = null;
+ }
}
}
MagicSoundProvider magicSoundProvider;
diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/NES.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/NES.cs
index 3cd692a9df..69b905af5e 100644
--- a/BizHawk.Emulation/Consoles/Nintendo/NES/NES.cs
+++ b/BizHawk.Emulation/Consoles/Nintendo/NES/NES.cs
@@ -224,7 +224,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
MyVideoProvider videoProvider;
public IVideoProvider VideoProvider { get { return videoProvider; } }
public ISoundProvider SoundProvider { get { return magicSoundProvider; } }
- public ISyncSoundProvider SyncSoundProvider { get { return new FakeSyncSound(magicSoundProvider, CoreOutputComm.VsyncRate > 55 ? 734 : 882); } }
+ public ISyncSoundProvider SyncSoundProvider { get { return magicSoundProvider; } }
public bool StartAsyncSound() { return true; }
public void EndAsyncSound() { }
diff --git a/BizHawk.Emulation/Sound/Utilities/BlipBuffer.cs b/BizHawk.Emulation/Sound/Utilities/BlipBuffer.cs
new file mode 100644
index 0000000000..4ab0549e64
--- /dev/null
+++ b/BizHawk.Emulation/Sound/Utilities/BlipBuffer.cs
@@ -0,0 +1,140 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Runtime.InteropServices;
+
+namespace BizHawk.Emulation.Sound.Utilities
+{
+ ///
+ /// wrapper around blargg's unmanaged blip_buf
+ ///
+ public class BlipBuffer : IDisposable
+ {
+ // this is transitional only. if the band-limited synthesis idea works out, i'll
+ // make a managed MIT implementation
+
+ static class BlipBufDll
+ {
+ /** Creates new buffer that can hold at most sample_count samples. Sets rates
+ so that there are blip_max_ratio clocks per sample. Returns pointer to new
+ buffer, or NULL if insufficient memory. */
+ [DllImport("blip_buf.dll", CallingConvention = CallingConvention.Cdecl)]
+ public static extern IntPtr blip_new(int sample_count);
+
+ /** Sets approximate input clock rate and output sample rate. For every
+ clock_rate input clocks, approximately sample_rate samples are generated. */
+ [DllImport("blip_buf.dll", CallingConvention = CallingConvention.Cdecl)]
+ public static extern void blip_set_rates(IntPtr context, double clock_rate, double sample_rate);
+
+ /** Maximum clock_rate/sample_rate ratio. For a given sample_rate,
+ clock_rate must not be greater than sample_rate*blip_max_ratio. */
+ public const int blip_max_ratio = 1 << 20;
+
+ /** Clears entire buffer. Afterwards, blip_samples_avail() == 0. */
+ [DllImport("blip_buf.dll", CallingConvention = CallingConvention.Cdecl)]
+ public static extern void blip_clear(IntPtr context);
+
+ /** Adds positive/negative delta into buffer at specified clock time. */
+ [DllImport("blip_buf.dll", CallingConvention = CallingConvention.Cdecl)]
+ public static extern void blip_add_delta(IntPtr context, uint clock_time, int delta);
+
+ /** Same as blip_add_delta(), but uses faster, lower-quality synthesis. */
+ [DllImport("blip_buf.dll", CallingConvention = CallingConvention.Cdecl)]
+ public static extern void blip_add_delta_fast(IntPtr context, uint clock_time, int delta);
+
+ /** Length of time frame, in clocks, needed to make sample_count additional
+ samples available. */
+ [DllImport("blip_buf.dll", CallingConvention = CallingConvention.Cdecl)]
+ public static extern int blip_clocks_needed(IntPtr context, int sample_count);
+
+ /** Maximum number of samples that can be generated from one time frame. */
+ public const int blip_max_frame = 4000;
+
+ /** Makes input clocks before clock_duration available for reading as output
+ samples. Also begins new time frame at clock_duration, so that clock time 0 in
+ the new time frame specifies the same clock as clock_duration in the old time
+ frame specified. Deltas can have been added slightly past clock_duration (up to
+ however many clocks there are in two output samples). */
+ [DllImport("blip_buf.dll", CallingConvention = CallingConvention.Cdecl)]
+ public static extern void blip_end_frame(IntPtr context, uint clock_duration);
+
+ /** Number of buffered samples available for reading. */
+ [DllImport("blip_buf.dll", CallingConvention = CallingConvention.Cdecl)]
+ public static extern int blip_samples_avail(IntPtr context);
+
+ /** Reads and removes at most 'count' samples and writes them to 'out'. If
+ 'stereo' is true, writes output to every other element of 'out', allowing easy
+ interleaving of two buffers into a stereo sample stream. Outputs 16-bit signed
+ samples. Returns number of samples actually read. */
+ [DllImport("blip_buf.dll", CallingConvention = CallingConvention.Cdecl)]
+ public static extern int blip_read_samples(IntPtr context, short[] @out, int count, int stereo);
+
+ /** Frees buffer. No effect if NULL is passed. */
+ [DllImport("blip_buf.dll", CallingConvention = CallingConvention.Cdecl)]
+ public static extern void blip_delete(IntPtr context);
+ }
+
+ IntPtr context;
+
+ public BlipBuffer(int sample_count)
+ {
+ context = BlipBufDll.blip_new(sample_count);
+ if (context == IntPtr.Zero)
+ throw new Exception("blip_new returned NULL!");
+ }
+
+ public void Dispose()
+ {
+ BlipBufDll.blip_delete(context);
+ context = IntPtr.Zero;
+ }
+
+ public void SetRates(double clock_rate, double sample_rate)
+ {
+ BlipBufDll.blip_set_rates(context, clock_rate, sample_rate);
+ }
+
+ public const int MaxRatio = BlipBufDll.blip_max_ratio;
+
+ public void Clear()
+ {
+ BlipBufDll.blip_clear(context);
+ }
+
+
+ public void AddDelta(uint clock_time, int delta)
+ {
+ BlipBufDll.blip_add_delta(context, clock_time, delta);
+ }
+
+ public void AddDeltaFast(uint clock_time, int delta)
+ {
+ BlipBufDll.blip_add_delta_fast(context, clock_time, delta);
+ }
+
+ public int ClocksNeeded(int sample_count)
+ {
+ return BlipBufDll.blip_clocks_needed(context, sample_count);
+ }
+
+ public const int MaxFrame = BlipBufDll.blip_max_frame;
+
+ public void EndFrame(uint clock_duration)
+ {
+ BlipBufDll.blip_end_frame(context, clock_duration);
+ }
+
+ public int SamplesAvailable()
+ {
+ return BlipBufDll.blip_samples_avail(context);
+ }
+
+ public int ReadSamples(short[] output, int count, bool stereo)
+ {
+ if (output.Length < count * (stereo ? 2 : 1))
+ throw new ArgumentOutOfRangeException();
+ return BlipBufDll.blip_read_samples(context, output, count, stereo ? 1 : 0);
+ }
+ }
+}
diff --git a/BizHawk.MultiClient/Sound.cs b/BizHawk.MultiClient/Sound.cs
index 8d4f5a4dcd..006aa24f77 100644
--- a/BizHawk.MultiClient/Sound.cs
+++ b/BizHawk.MultiClient/Sound.cs
@@ -166,6 +166,9 @@ namespace BizHawk.MultiClient
return;
samples = new short[samplesNeeded];
samplesProvided = samplesNeeded;
+
+ if (asyncsoundProvider != null) asyncsoundProvider.DiscardSamples();
+ if (syncsoundProvider != null) syncsoundProvider.DiscardSamples();
}
else if (syncsoundProvider != null)
{
diff --git a/BizHawk.MultiClient/output/dll/blip_buf.dll b/BizHawk.MultiClient/output/dll/blip_buf.dll
new file mode 100644
index 0000000000..a26adfc124
Binary files /dev/null and b/BizHawk.MultiClient/output/dll/blip_buf.dll differ
diff --git a/blip_buf/Makefile b/blip_buf/Makefile
new file mode 100644
index 0000000000..56ee36b874
--- /dev/null
+++ b/blip_buf/Makefile
@@ -0,0 +1,9 @@
+CC = gcc
+
+CFLAGS = -Wall -Wextra -O3
+LFLAGS = -shared
+
+all: blip_buf
+
+blip_buf: blip_buf.c blip_buf.h
+ $(CC) $(CFLAGS) blip_buf.c -o blip_buf.dll $(LFLAGS)
diff --git a/blip_buf/blip_buf.c b/blip_buf/blip_buf.c
new file mode 100644
index 0000000000..362eede49a
--- /dev/null
+++ b/blip_buf/blip_buf.c
@@ -0,0 +1,344 @@
+/* blip_buf 1.1.0. http://www.slack.net/~ant/ */
+
+#include "blip_buf.h"
+
+#include
+#include
+#include
+#include
+
+/* Library Copyright (C) 2003-2009 Shay Green. This library is free software;
+you can redistribute it and/or modify it under the terms of the GNU Lesser
+General Public License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version. This
+library is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+details. You should have received a copy of the GNU Lesser General Public
+License along with this module; if not, write to the Free Software Foundation,
+Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
+
+#if defined (BLARGG_TEST) && BLARGG_TEST
+ #include "blargg_test.h"
+#endif
+
+/* Equivalent to ULONG_MAX >= 0xFFFFFFFF00000000.
+Avoids constants that don't fit in 32 bits. */
+#if ULONG_MAX/0xFFFFFFFF > 0xFFFFFFFF
+ typedef unsigned long fixed_t;
+ enum { pre_shift = 32 };
+
+#elif defined(ULLONG_MAX)
+ typedef unsigned long long fixed_t;
+ enum { pre_shift = 32 };
+
+#else
+ typedef unsigned fixed_t;
+ enum { pre_shift = 0 };
+
+#endif
+
+enum { time_bits = pre_shift + 20 };
+
+static fixed_t const time_unit = (fixed_t) 1 << time_bits;
+
+enum { bass_shift = 9 }; /* affects high-pass filter breakpoint frequency */
+enum { end_frame_extra = 2 }; /* allows deltas slightly after frame length */
+
+enum { half_width = 8 };
+enum { buf_extra = half_width*2 + end_frame_extra };
+enum { phase_bits = 5 };
+enum { phase_count = 1 << phase_bits };
+enum { delta_bits = 15 };
+enum { delta_unit = 1 << delta_bits };
+enum { frac_bits = time_bits - pre_shift };
+
+/* We could eliminate avail and encode whole samples in offset, but that would
+limit the total buffered samples to blip_max_frame. That could only be
+increased by decreasing time_bits, which would reduce resample ratio accuracy.
+*/
+
+/** Sample buffer that resamples to output rate and accumulates samples
+until they're read out */
+struct blip_t
+{
+ fixed_t factor;
+ fixed_t offset;
+ int avail;
+ int size;
+ int integrator;
+};
+
+typedef int buf_t;
+
+/* probably not totally portable */
+#define SAMPLES( buf ) ((buf_t*) ((buf) + 1))
+
+/* Arithmetic (sign-preserving) right shift */
+#define ARITH_SHIFT( n, shift ) \
+ ((n) >> (shift))
+
+enum { max_sample = +32767 };
+enum { min_sample = -32768 };
+
+#define CLAMP( n ) \
+ {\
+ if ( (short) n != n )\
+ n = ARITH_SHIFT( n, 16 ) ^ max_sample;\
+ }
+
+static void check_assumptions( void )
+{
+ int n;
+
+ #if INT_MAX < 0x7FFFFFFF || UINT_MAX < 0xFFFFFFFF
+ #error "int must be at least 32 bits"
+ #endif
+
+ assert( (-3 >> 1) == -2 ); /* right shift must preserve sign */
+
+ n = max_sample * 2;
+ CLAMP( n );
+ assert( n == max_sample );
+
+ n = min_sample * 2;
+ CLAMP( n );
+ assert( n == min_sample );
+
+ assert( blip_max_ratio <= time_unit );
+ assert( blip_max_frame <= (fixed_t) -1 >> time_bits );
+}
+
+blip_t* blip_new( int size )
+{
+ blip_t* m;
+ assert( size >= 0 );
+
+ m = (blip_t*) malloc( sizeof *m + (size + buf_extra) * sizeof (buf_t) );
+ if ( m )
+ {
+ m->factor = time_unit / blip_max_ratio;
+ m->size = size;
+ blip_clear( m );
+ check_assumptions();
+ }
+ return m;
+}
+
+void blip_delete( blip_t* m )
+{
+ if ( m != NULL )
+ {
+ /* Clear fields in case user tries to use after freeing */
+ memset( m, 0, sizeof *m );
+ free( m );
+ }
+}
+
+void blip_set_rates( blip_t* m, double clock_rate, double sample_rate )
+{
+ double factor = time_unit * sample_rate / clock_rate;
+ m->factor = (fixed_t) factor;
+
+ /* Fails if clock_rate exceeds maximum, relative to sample_rate */
+ assert( 0 <= factor - m->factor && factor - m->factor < 1 );
+
+ /* Avoid requiring math.h. Equivalent to
+ m->factor = (int) ceil( factor ) */
+ if ( m->factor < factor )
+ m->factor++;
+
+ /* At this point, factor is most likely rounded up, but could still
+ have been rounded down in the floating-point calculation. */
+}
+
+void blip_clear( blip_t* m )
+{
+ /* We could set offset to 0, factor/2, or factor-1. 0 is suitable if
+ factor is rounded up. factor-1 is suitable if factor is rounded down.
+ Since we don't know rounding direction, factor/2 accommodates either,
+ with the slight loss of showing an error in half the time. Since for
+ a 64-bit factor this is years, the halving isn't a problem. */
+
+ m->offset = m->factor / 2;
+ m->avail = 0;
+ m->integrator = 0;
+ memset( SAMPLES( m ), 0, (m->size + buf_extra) * sizeof (buf_t) );
+}
+
+int blip_clocks_needed( const blip_t* m, int samples )
+{
+ fixed_t needed;
+
+ /* Fails if buffer can't hold that many more samples */
+ assert( samples >= 0 && m->avail + samples <= m->size );
+
+ needed = (fixed_t) samples * time_unit;
+ if ( needed < m->offset )
+ return 0;
+
+ return (needed - m->offset + m->factor - 1) / m->factor;
+}
+
+void blip_end_frame( blip_t* m, unsigned t )
+{
+ fixed_t off = t * m->factor + m->offset;
+ m->avail += off >> time_bits;
+ m->offset = off & (time_unit - 1);
+
+ /* Fails if buffer size was exceeded */
+ assert( m->avail <= m->size );
+}
+
+int blip_samples_avail( const blip_t* m )
+{
+ return m->avail;
+}
+
+static void remove_samples( blip_t* m, int count )
+{
+ buf_t* buf = SAMPLES( m );
+ int remain = m->avail + buf_extra - count;
+ m->avail -= count;
+
+ memmove( &buf [0], &buf [count], remain * sizeof buf [0] );
+ memset( &buf [remain], 0, count * sizeof buf [0] );
+}
+
+int blip_read_samples( blip_t* m, short out [], int count, int stereo )
+{
+ assert( count >= 0 );
+
+ if ( count > m->avail )
+ count = m->avail;
+
+ if ( count )
+ {
+ int const step = stereo ? 2 : 1;
+ buf_t const* in = SAMPLES( m );
+ buf_t const* end = in + count;
+ int sum = m->integrator;
+ do
+ {
+ /* Eliminate fraction */
+ int s = ARITH_SHIFT( sum, delta_bits );
+
+ sum += *in++;
+
+ CLAMP( s );
+
+ *out = s;
+ out += step;
+
+ /* High-pass filter */
+ sum -= s << (delta_bits - bass_shift);
+ }
+ while ( in != end );
+ m->integrator = sum;
+
+ remove_samples( m, count );
+ }
+
+ return count;
+}
+
+/* Things that didn't help performance on x86:
+ __attribute__((aligned(128)))
+ #define short int
+ restrict
+*/
+
+/* Sinc_Generator( 0.9, 0.55, 4.5 ) */
+static short const bl_step [phase_count + 1] [half_width] =
+{
+{ 43, -115, 350, -488, 1136, -914, 5861,21022},
+{ 44, -118, 348, -473, 1076, -799, 5274,21001},
+{ 45, -121, 344, -454, 1011, -677, 4706,20936},
+{ 46, -122, 336, -431, 942, -549, 4156,20829},
+{ 47, -123, 327, -404, 868, -418, 3629,20679},
+{ 47, -122, 316, -375, 792, -285, 3124,20488},
+{ 47, -120, 303, -344, 714, -151, 2644,20256},
+{ 46, -117, 289, -310, 634, -17, 2188,19985},
+{ 46, -114, 273, -275, 553, 117, 1758,19675},
+{ 44, -108, 255, -237, 471, 247, 1356,19327},
+{ 43, -103, 237, -199, 390, 373, 981,18944},
+{ 42, -98, 218, -160, 310, 495, 633,18527},
+{ 40, -91, 198, -121, 231, 611, 314,18078},
+{ 38, -84, 178, -81, 153, 722, 22,17599},
+{ 36, -76, 157, -43, 80, 824, -241,17092},
+{ 34, -68, 135, -3, 8, 919, -476,16558},
+{ 32, -61, 115, 34, -60, 1006, -683,16001},
+{ 29, -52, 94, 70, -123, 1083, -862,15422},
+{ 27, -44, 73, 106, -184, 1152,-1015,14824},
+{ 25, -36, 53, 139, -239, 1211,-1142,14210},
+{ 22, -27, 34, 170, -290, 1261,-1244,13582},
+{ 20, -20, 16, 199, -335, 1301,-1322,12942},
+{ 18, -12, -3, 226, -375, 1331,-1376,12293},
+{ 15, -4, -19, 250, -410, 1351,-1408,11638},
+{ 13, 3, -35, 272, -439, 1361,-1419,10979},
+{ 11, 9, -49, 292, -464, 1362,-1410,10319},
+{ 9, 16, -63, 309, -483, 1354,-1383, 9660},
+{ 7, 22, -75, 322, -496, 1337,-1339, 9005},
+{ 6, 26, -85, 333, -504, 1312,-1280, 8355},
+{ 4, 31, -94, 341, -507, 1278,-1205, 7713},
+{ 3, 35, -102, 347, -506, 1238,-1119, 7082},
+{ 1, 40, -110, 350, -499, 1190,-1021, 6464},
+{ 0, 43, -115, 350, -488, 1136, -914, 5861}
+};
+
+/* Shifting by pre_shift allows calculation using unsigned int rather than
+possibly-wider fixed_t. On 32-bit platforms, this is likely more efficient.
+And by having pre_shift 32, a 32-bit platform can easily do the shift by
+simply ignoring the low half. */
+
+void blip_add_delta( blip_t* m, unsigned time, int delta )
+{
+ unsigned fixed = (unsigned) ((time * m->factor + m->offset) >> pre_shift);
+ buf_t* out = SAMPLES( m ) + m->avail + (fixed >> frac_bits);
+
+ int const phase_shift = frac_bits - phase_bits;
+ int phase = fixed >> phase_shift & (phase_count - 1);
+ short const* in = bl_step [phase];
+ short const* rev = bl_step [phase_count - phase];
+
+ int interp = fixed >> (phase_shift - delta_bits) & (delta_unit - 1);
+ int delta2 = (delta * interp) >> delta_bits;
+ delta -= delta2;
+
+ /* Fails if buffer size was exceeded */
+ assert( out <= &SAMPLES( m ) [m->size + end_frame_extra] );
+
+ out [0] += in[0]*delta + in[half_width+0]*delta2;
+ out [1] += in[1]*delta + in[half_width+1]*delta2;
+ out [2] += in[2]*delta + in[half_width+2]*delta2;
+ out [3] += in[3]*delta + in[half_width+3]*delta2;
+ out [4] += in[4]*delta + in[half_width+4]*delta2;
+ out [5] += in[5]*delta + in[half_width+5]*delta2;
+ out [6] += in[6]*delta + in[half_width+6]*delta2;
+ out [7] += in[7]*delta + in[half_width+7]*delta2;
+
+ in = rev;
+ out [ 8] += in[7]*delta + in[7-half_width]*delta2;
+ out [ 9] += in[6]*delta + in[6-half_width]*delta2;
+ out [10] += in[5]*delta + in[5-half_width]*delta2;
+ out [11] += in[4]*delta + in[4-half_width]*delta2;
+ out [12] += in[3]*delta + in[3-half_width]*delta2;
+ out [13] += in[2]*delta + in[2-half_width]*delta2;
+ out [14] += in[1]*delta + in[1-half_width]*delta2;
+ out [15] += in[0]*delta + in[0-half_width]*delta2;
+}
+
+void blip_add_delta_fast( blip_t* m, unsigned time, int delta )
+{
+ unsigned fixed = (unsigned) ((time * m->factor + m->offset) >> pre_shift);
+ buf_t* out = SAMPLES( m ) + m->avail + (fixed >> frac_bits);
+
+ int interp = fixed >> (frac_bits - delta_bits) & (delta_unit - 1);
+ int delta2 = delta * interp;
+
+ /* Fails if buffer size was exceeded */
+ assert( out <= &SAMPLES( m ) [m->size + end_frame_extra] );
+
+ out [7] += delta * delta_unit - delta2;
+ out [8] += delta2;
+}
diff --git a/blip_buf/blip_buf.h b/blip_buf/blip_buf.h
new file mode 100644
index 0000000000..52703643c4
--- /dev/null
+++ b/blip_buf/blip_buf.h
@@ -0,0 +1,72 @@
+/** \file
+Sample buffer that resamples from input clock rate to output sample rate */
+
+/* blip_buf 1.1.0 */
+#ifndef BLIP_BUF_H
+#define BLIP_BUF_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/** First parameter of most functions is blip_t*, or const blip_t* if nothing
+is changed. */
+typedef struct blip_t blip_t;
+
+/** Creates new buffer that can hold at most sample_count samples. Sets rates
+so that there are blip_max_ratio clocks per sample. Returns pointer to new
+buffer, or NULL if insufficient memory. */
+blip_t* blip_new( int sample_count );
+
+/** Sets approximate input clock rate and output sample rate. For every
+clock_rate input clocks, approximately sample_rate samples are generated. */
+void blip_set_rates( blip_t*, double clock_rate, double sample_rate );
+
+enum { /** Maximum clock_rate/sample_rate ratio. For a given sample_rate,
+clock_rate must not be greater than sample_rate*blip_max_ratio. */
+blip_max_ratio = 1 << 20 };
+
+/** Clears entire buffer. Afterwards, blip_samples_avail() == 0. */
+void blip_clear( blip_t* );
+
+/** Adds positive/negative delta into buffer at specified clock time. */
+void blip_add_delta( blip_t*, unsigned int clock_time, int delta );
+
+/** Same as blip_add_delta(), but uses faster, lower-quality synthesis. */
+void blip_add_delta_fast( blip_t*, unsigned int clock_time, int delta );
+
+/** Length of time frame, in clocks, needed to make sample_count additional
+samples available. */
+int blip_clocks_needed( const blip_t*, int sample_count );
+
+enum { /** Maximum number of samples that can be generated from one time frame. */
+blip_max_frame = 4000 };
+
+/** Makes input clocks before clock_duration available for reading as output
+samples. Also begins new time frame at clock_duration, so that clock time 0 in
+the new time frame specifies the same clock as clock_duration in the old time
+frame specified. Deltas can have been added slightly past clock_duration (up to
+however many clocks there are in two output samples). */
+void blip_end_frame( blip_t*, unsigned int clock_duration );
+
+/** Number of buffered samples available for reading. */
+int blip_samples_avail( const blip_t* );
+
+/** Reads and removes at most 'count' samples and writes them to 'out'. If
+'stereo' is true, writes output to every other element of 'out', allowing easy
+interleaving of two buffers into a stereo sample stream. Outputs 16-bit signed
+samples. Returns number of samples actually read. */
+int blip_read_samples( blip_t*, short out [], int count, int stereo );
+
+/** Frees buffer. No effect if NULL is passed. */
+void blip_delete( blip_t* );
+
+
+/* Deprecated */
+typedef blip_t blip_buffer_t;
+
+#ifdef __cplusplus
+ }
+#endif
+
+#endif
diff --git a/blip_buf/blip_buf.txt b/blip_buf/blip_buf.txt
new file mode 100644
index 0000000000..f7a33cc87b
--- /dev/null
+++ b/blip_buf/blip_buf.txt
@@ -0,0 +1,250 @@
+blip_buf 1.1.0
+--------------
+Author : Shay Green
+Website : http://www.slack.net/~ant/
+License : GNU Lesser General Public License (LGPL)
+
+
+Contents
+--------
+* Overview
+* Buffer creation
+* Waveform generation
+* Time frames
+* Complex waveforms
+* Sample buffering
+* Thanks
+
+
+Overview
+--------
+This library resamples audio waveforms from input clock rate to output
+sample rate. Usage follows this general pattern:
+
+* Create buffer with blip_new().
+* Set clock rate and sample rate with blip_set_rates().
+* Waveform generation loop:
+ - Generate several clocks of waveform with blip_add_delta().
+ - End time frame with blip_end_frame().
+ - Read samples from buffer with blip_read_samples().
+* Free buffer with blip_delete().
+
+
+Buffer creation
+---------------
+Before synthesis, a buffer must be created with blip_new(). Its size is
+the maximum number of unread samples it can hold. For most uses, this
+can be 1/10 the sample rate or less, since samples will usually be read
+out immediately after being generated.
+
+After the buffer is created, the input clock rate and output sample rate
+must be set with blip_set_rates(). This determines how many input clocks
+there are per second, and how many output samples are generated per
+second.
+
+If the compiler supports a 64-bit integer type, then the input-output
+ratio is stored very accurately. If the compiler only supports a 32-bit
+integer type, then the ratio is stored with only 20 fraction bits, so
+some ratios cannot be represented exactly (for example, sample
+rate=48000 and clock rate=48001). The ratio is internally rounded up, so
+there will never be fewer than 'sample rate' samples per second. Having
+too many per second is generally better than having too few.
+
+
+Waveform generation
+-------------------
+Waveforms are generated at the input clock rate. Consider a simple
+square wave with 8 clocks per cycle (4 clocks high, 4 clocks low):
+
+ |<-- 8 clocks ->|
+ +5| ._._._._ ._._._._ ._._._._ ._._
+ | | | | | | | |
+ Amp 0|._._._._ | | | | | |
+ | | | | | | |
+ -5| ._._._._ ._._._._ ._._._._
+ * . . . * . . . * . . . * . . . * . . . * . . . * . . . * .
+ Time 0 4 8 12 16 20 24 28
+
+The wave changes amplitude at time points 0, 4, 8, 12, 16, etc.
+
+The following generates the amplitude at every clock of above waveform
+at the input clock rate:
+
+ int wave [30];
+
+ for ( int i = 4; i < 30; ++i )
+ {
+ if ( i % 8 < 4 )
+ wave [i] = -5;
+ else
+ wave [i] = +5;
+ }
+
+Without this library, the wave array would then need to be resampled
+from the input clock rate to the output sample rate. This library does
+this resampling internally, so it won't be discussed further; waveform
+generation code can focus entirely on the input clocks.
+
+Rather than specify the amplitude at every clock, this library merely
+needs to know the points where the amplitude CHANGES, referred to as a
+delta. The time of a delta is specified with a clock count. The deltas
+for this square wave are shown below the time points they occur at:
+
+ +5| ._._._._ ._._._._ ._._._._ ._._
+ | | | | | | | |
+ Amp 0|._._._._ | | | | | |
+ | | | | | | |
+ -5| ._._._._ ._._._._ ._._._._
+ * . . . * . . . * . . . * . . . * . . . * . . . * . . . * .
+ Time 0 4 8 12 16 20 24 28
+ Delta +5 -10 +10 -10 +10 -10 +10
+
+The following calls generate the above waveform:
+
+ blip_add_delta( blip, 4, +5 );
+ blip_add_delta( blip, 8, -10 );
+ blip_add_delta( blip, 12, +10 );
+ blip_add_delta( blip, 16, -10 );
+ blip_add_delta( blip, 20, +10 );
+ blip_add_delta( blip, 24, -10 );
+ blip_add_delta( blip, 28, +10 );
+
+In the examples above, the amplitudes are small for clarity. The 16-bit
+sample range is -32768 to +32767, so actual waveform amplitudes would
+need to be in the thousands to be audible (for example, -5000 to +5000).
+
+This library allows waveform generation code to pay NO attention to the
+output sample rate. It can focus ENTIRELY on the essence of the
+waveform: the points where its amplitude changes. Since these points can
+be efficiently generated in a loop, synthesis is efficient. Sound chip
+emulation code can be structured to allow full accuracy down to a single
+clock, with the emulated CPU being able to simply tell the sound chip to
+"emulate from wherever you left off, up to clock time T within the
+current time frame".
+
+
+Time frames
+-----------
+Since time keeps increasing, if left unchecked, at some point it would
+overflow the range of an integer. This library's solution to the problem
+is to break waveform generation into time frames of moderate length.
+Clock counts within a time frame are thus relative to the beginning of
+the frame, where 0 is the beginning of the frame. When a time frame of
+length T is ended, what was at time T in the old time frame is now at
+time 0 in the new time frame. Breaking the above waveform into time
+frames of 10 clocks each looks like this:
+
+ +5| ._._._._ ._._._._ ._._._._ ._._
+ | | | | | | | |
+ Amp 0|._._._._ | | | | | |
+ | | | | | | |
+ -5| ._._._._ ._._._._ ._._._._
+ * . . . * . . . * . . . * . . . * . . . * . . . * . . . * .
+ Time |0 4 8 | 2 6 |0 4 8 |
+ | first time frame | second time frame | third time frame |
+ |<--- 10 clocks --->|<--- 10 clocks --->|<--- 10 clocks --->|
+
+The following calls generate the above waveform. After they execute, the
+first 30 clocks of the waveform will have been resampled and be
+available as output samples for reading with blip_read_samples().
+
+ blip_add_delta( blip, 4, +5 );
+ blip_add_delta( blip, 8, -10 );
+ blip_end_frame( blip, 10 );
+
+ blip_add_delta( blip, 2, +10 );
+ blip_add_delta( blip, 6, -10 );
+ blip_end_frame( blip, 10 );
+
+ blip_add_delta( blip, 0, +10 );
+ blip_add_delta( blip, 4, -10 );
+ blip_add_delta( blip, 8, +10 );
+ blip_end_frame( blip, 10 );
+ ...
+
+Time frames can be a convenient length, and the length can vary from one
+frame to the next. Once a time frame is ended, the resulting output
+samples become available for reading immediately, and no more deltas can
+be added to it.
+
+There is a limit of about 4000 output samples per time frame. The number
+of clocks depends on the clock rate. At common sample rates, this allows
+time frames of at least 1/15 second, plenty for most uses. This limit
+allows increased resampling ratio accuracy.
+
+In an emulator, it is usually convenient to have audio time frames
+correspond to video frames, where the CPU's clock counter is reset at
+the beginning of each video frame and thus can be used directly as the
+relative clock counts for audio time frames.
+
+
+Complex waveforms
+-----------------
+Any sort of waveform can be generated, not just a square wave. For
+example, a saw-like wave:
+
+ +5| ._._._._ ._._._._ ._._
+ | | | | | |
+ Amp 0|._._._._ | ._._._._ | ._._._._
+ | | | | |
+ -5| ._._._._ ._._._._
+ * . . . * . . . * . . . * . . . * . . . * . . . * . . . * .
+ Time 0 4 8 12 16 20 24 28
+ Delta +5 -10 +5 +5 -10 +5 +5
+
+Code to generate above waveform:
+
+ blip_add_delta( blip, 4, +5 );
+ blip_add_delta( blip, 8, -10 );
+ blip_add_delta( blip, 12, +5 );
+ blip_add_delta( blip, 16, +5 );
+ blip_add_delta( blip, 20, +10 );
+ blip_add_delta( blip, 24, +5 );
+ blip_add_delta( blip, 28, +5 );
+
+Similarly, multiple waveforms can be added within a time frame without
+problem. It doesn't matter what order they're added, because all the
+library needs are the deltas. The synthesis code doesn't need to know
+all the waveforms at once either; it can calculate and add the deltas
+for each waveform individually. Deltas don't need to be added in
+chronological order either.
+
+
+Sample buffering
+----------------
+Sample buffering is very flexible. Once a time frame is ended, the
+resampled waveforms become output samples that are immediately made
+available for reading with blip_read_samples(). They don't have to be
+read immediately; they can be allowed to accumulate in the buffer, with
+each time frame appending more samples to the buffer. When reading, some
+or all of the samples in can be read out, with the remaining unread
+samples staying in the buffer for later. Usually a program will
+immediately read all available samples after ending a time frame and
+play them immediately. In some systems, a program needs samples in
+fixed-length blocks; in that case, it would keep generating time frames
+until some number of samples are available, then read only that many,
+even if slightly more were available in the buffer.
+
+In some systems, one wants to run waveform generation for exactly the
+number of clocks necessary to generate some desired number of output
+samples, and no more. In that case, use blip_clocks_needed( blip, N ) to
+find out how many clocks are needed to generate N additional samples.
+Ending a time frame with this value will result in exactly N more
+samples becoming available for reading.
+
+
+Thanks
+------
+Thanks to Jsr (FamiTracker author), the Mednafen team (multi-system
+emulator), ShizZie (Nhes GMB author), Marcel van Tongeren, Luke Molnar
+(UberNES author), Fredrick Meunier (Fuse contributor) for using and
+giving feedback for another similar library. Thanks to Disch for his
+interest and discussions about the synthesis algorithm itself, and for
+writing his own implementation of it (Schpune) rather than just using
+mine. Thanks to Xodnizel for Festalon, whose sound quality got me
+interested in video game sound emulation in the first place, and where I
+first came up with the algorithm while optimizing its brute-force
+filter.
+
+--
+Shay Green
diff --git a/blip_buf/changes.txt b/blip_buf/changes.txt
new file mode 100644
index 0000000000..0c50861a9f
--- /dev/null
+++ b/blip_buf/changes.txt
@@ -0,0 +1,39 @@
+Blip_buf Change Log
+-------------------
+
+blip_buf 1.1.0 (2009-10-06)
+--------------
+* Changed library name to blip_buf, to make it easier to find uses of on
+the Web.
+
+* Increased internal input-output ratio accuracy greatly when compiler
+supports 64-bit integer type.
+
+* Renamed blip_buffer_t to blip_t, for consistency with function names.
+Old name is deprecated.
+
+* Reduced high-pass so that a bit more bass comes through.
+
+* Made header file minimally Doxygen-compatible.
+
+* Added unit test suite.
+
+* Added assertions to catch more precondition violations (negative
+values, etc.)
+
+* blip_new() sets default rate to blip_max_ratio clocks per sample.
+
+* blip_delete() can now accept NULL, as originally claimed.
+
+* blip_clocks_needed() now properly returns zero when passed zero.
+
+* blip_add_delta_fast() now adds delta at same place blip_add_delta()'s
+center of delta would be, rather than one sample later as before.
+
+* blip_add_delta() and blip_add_delta_fast() allow adding slightly past
+buffer size, as originally claimed.
+
+
+blip 1.0.0 (2008-12-08)
+----------
+* First release
diff --git a/blip_buf/license.txt b/blip_buf/license.txt
new file mode 100644
index 0000000000..5faba9d48c
--- /dev/null
+++ b/blip_buf/license.txt
@@ -0,0 +1,504 @@
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 2.1, February 1999
+
+ Copyright (C) 1991, 1999 Free Software Foundation, Inc.
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+[This is the first released version of the Lesser GPL. It also counts
+ as the successor of the GNU Library Public License, version 2, hence
+ the version number 2.1.]
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+Licenses are intended to guarantee your freedom to share and change
+free software--to make sure the software is free for all its users.
+
+ This license, the Lesser General Public License, applies to some
+specially designated software packages--typically libraries--of the
+Free Software Foundation and other authors who decide to use it. You
+can use it too, but we suggest you first think carefully about whether
+this license or the ordinary General Public License is the better
+strategy to use in any particular case, based on the explanations below.
+
+ When we speak of free software, we are referring to freedom of use,
+not price. Our General Public Licenses are designed to make sure that
+you have the freedom to distribute copies of free software (and charge
+for this service if you wish); that you receive source code or can get
+it if you want it; that you can change the software and use pieces of
+it in new free programs; and that you are informed that you can do
+these things.
+
+ To protect your rights, we need to make restrictions that forbid
+distributors to deny you these rights or to ask you to surrender these
+rights. These restrictions translate to certain responsibilities for
+you if you distribute copies of the library or if you modify it.
+
+ For example, if you distribute copies of the library, whether gratis
+or for a fee, you must give the recipients all the rights that we gave
+you. You must make sure that they, too, receive or can get the source
+code. If you link other code with the library, you must provide
+complete object files to the recipients, so that they can relink them
+with the library after making changes to the library and recompiling
+it. And you must show them these terms so they know their rights.
+
+ We protect your rights with a two-step method: (1) we copyright the
+library, and (2) we offer you this license, which gives you legal
+permission to copy, distribute and/or modify the library.
+
+ To protect each distributor, we want to make it very clear that
+there is no warranty for the free library. Also, if the library is
+modified by someone else and passed on, the recipients should know
+that what they have is not the original version, so that the original
+author's reputation will not be affected by problems that might be
+introduced by others.
+
+ Finally, software patents pose a constant threat to the existence of
+any free program. We wish to make sure that a company cannot
+effectively restrict the users of a free program by obtaining a
+restrictive license from a patent holder. Therefore, we insist that
+any patent license obtained for a version of the library must be
+consistent with the full freedom of use specified in this license.
+
+ Most GNU software, including some libraries, is covered by the
+ordinary GNU General Public License. This license, the GNU Lesser
+General Public License, applies to certain designated libraries, and
+is quite different from the ordinary General Public License. We use
+this license for certain libraries in order to permit linking those
+libraries into non-free programs.
+
+ When a program is linked with a library, whether statically or using
+a shared library, the combination of the two is legally speaking a
+combined work, a derivative of the original library. The ordinary
+General Public License therefore permits such linking only if the
+entire combination fits its criteria of freedom. The Lesser General
+Public License permits more lax criteria for linking other code with
+the library.
+
+ We call this license the "Lesser" General Public License because it
+does Less to protect the user's freedom than the ordinary General
+Public License. It also provides other free software developers Less
+of an advantage over competing non-free programs. These disadvantages
+are the reason we use the ordinary General Public License for many
+libraries. However, the Lesser license provides advantages in certain
+special circumstances.
+
+ For example, on rare occasions, there may be a special need to
+encourage the widest possible use of a certain library, so that it becomes
+a de-facto standard. To achieve this, non-free programs must be
+allowed to use the library. A more frequent case is that a free
+library does the same job as widely used non-free libraries. In this
+case, there is little to gain by limiting the free library to free
+software only, so we use the Lesser General Public License.
+
+ In other cases, permission to use a particular library in non-free
+programs enables a greater number of people to use a large body of
+free software. For example, permission to use the GNU C Library in
+non-free programs enables many more people to use the whole GNU
+operating system, as well as its variant, the GNU/Linux operating
+system.
+
+ Although the Lesser General Public License is Less protective of the
+users' freedom, it does ensure that the user of a program that is
+linked with the Library has the freedom and the wherewithal to run
+that program using a modified version of the Library.
+
+ The precise terms and conditions for copying, distribution and
+modification follow. Pay close attention to the difference between a
+"work based on the library" and a "work that uses the library". The
+former contains code derived from the library, whereas the latter must
+be combined with the library in order to run.
+
+ GNU LESSER GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License Agreement applies to any software library or other
+program which contains a notice placed by the copyright holder or
+other authorized party saying it may be distributed under the terms of
+this Lesser General Public License (also called "this License").
+Each licensee is addressed as "you".
+
+ A "library" means a collection of software functions and/or data
+prepared so as to be conveniently linked with application programs
+(which use some of those functions and data) to form executables.
+
+ The "Library", below, refers to any such software library or work
+which has been distributed under these terms. A "work based on the
+Library" means either the Library or any derivative work under
+copyright law: that is to say, a work containing the Library or a
+portion of it, either verbatim or with modifications and/or translated
+straightforwardly into another language. (Hereinafter, translation is
+included without limitation in the term "modification".)
+
+ "Source code" for a work means the preferred form of the work for
+making modifications to it. For a library, complete source code means
+all the source code for all modules it contains, plus any associated
+interface definition files, plus the scripts used to control compilation
+and installation of the library.
+
+ Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running a program using the Library is not restricted, and output from
+such a program is covered only if its contents constitute a work based
+on the Library (independent of the use of the Library in a tool for
+writing it). Whether that is true depends on what the Library does
+and what the program that uses the Library does.
+
+ 1. You may copy and distribute verbatim copies of the Library's
+complete source code as you receive it, in any medium, provided that
+you conspicuously and appropriately publish on each copy an
+appropriate copyright notice and disclaimer of warranty; keep intact
+all the notices that refer to this License and to the absence of any
+warranty; and distribute a copy of this License along with the
+Library.
+
+ You may charge a fee for the physical act of transferring a copy,
+and you may at your option offer warranty protection in exchange for a
+fee.
+
+ 2. You may modify your copy or copies of the Library or any portion
+of it, thus forming a work based on the Library, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) The modified work must itself be a software library.
+
+ b) You must cause the files modified to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ c) You must cause the whole of the work to be licensed at no
+ charge to all third parties under the terms of this License.
+
+ d) If a facility in the modified Library refers to a function or a
+ table of data to be supplied by an application program that uses
+ the facility, other than as an argument passed when the facility
+ is invoked, then you must make a good faith effort to ensure that,
+ in the event an application does not supply such function or
+ table, the facility still operates, and performs whatever part of
+ its purpose remains meaningful.
+
+ (For example, a function in a library to compute square roots has
+ a purpose that is entirely well-defined independent of the
+ application. Therefore, Subsection 2d requires that any
+ application-supplied function or table used by this function must
+ be optional: if the application does not supply it, the square
+ root function must still compute square roots.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Library,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Library, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote
+it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Library.
+
+In addition, mere aggregation of another work not based on the Library
+with the Library (or with a work based on the Library) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may opt to apply the terms of the ordinary GNU General Public
+License instead of this License to a given copy of the Library. To do
+this, you must alter all the notices that refer to this License, so
+that they refer to the ordinary GNU General Public License, version 2,
+instead of to this License. (If a newer version than version 2 of the
+ordinary GNU General Public License has appeared, then you can specify
+that version instead if you wish.) Do not make any other change in
+these notices.
+
+ Once this change is made in a given copy, it is irreversible for
+that copy, so the ordinary GNU General Public License applies to all
+subsequent copies and derivative works made from that copy.
+
+ This option is useful when you wish to copy part of the code of
+the Library into a program that is not a library.
+
+ 4. You may copy and distribute the Library (or a portion or
+derivative of it, under Section 2) in object code or executable form
+under the terms of Sections 1 and 2 above provided that you accompany
+it with the complete corresponding machine-readable source code, which
+must be distributed under the terms of Sections 1 and 2 above on a
+medium customarily used for software interchange.
+
+ If distribution of object code is made by offering access to copy
+from a designated place, then offering equivalent access to copy the
+source code from the same place satisfies the requirement to
+distribute the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 5. A program that contains no derivative of any portion of the
+Library, but is designed to work with the Library by being compiled or
+linked with it, is called a "work that uses the Library". Such a
+work, in isolation, is not a derivative work of the Library, and
+therefore falls outside the scope of this License.
+
+ However, linking a "work that uses the Library" with the Library
+creates an executable that is a derivative of the Library (because it
+contains portions of the Library), rather than a "work that uses the
+library". The executable is therefore covered by this License.
+Section 6 states terms for distribution of such executables.
+
+ When a "work that uses the Library" uses material from a header file
+that is part of the Library, the object code for the work may be a
+derivative work of the Library even though the source code is not.
+Whether this is true is especially significant if the work can be
+linked without the Library, or if the work is itself a library. The
+threshold for this to be true is not precisely defined by law.
+
+ If such an object file uses only numerical parameters, data
+structure layouts and accessors, and small macros and small inline
+functions (ten lines or less in length), then the use of the object
+file is unrestricted, regardless of whether it is legally a derivative
+work. (Executables containing this object code plus portions of the
+Library will still fall under Section 6.)
+
+ Otherwise, if the work is a derivative of the Library, you may
+distribute the object code for the work under the terms of Section 6.
+Any executables containing that work also fall under Section 6,
+whether or not they are linked directly with the Library itself.
+
+ 6. As an exception to the Sections above, you may also combine or
+link a "work that uses the Library" with the Library to produce a
+work containing portions of the Library, and distribute that work
+under terms of your choice, provided that the terms permit
+modification of the work for the customer's own use and reverse
+engineering for debugging such modifications.
+
+ You must give prominent notice with each copy of the work that the
+Library is used in it and that the Library and its use are covered by
+this License. You must supply a copy of this License. If the work
+during execution displays copyright notices, you must include the
+copyright notice for the Library among them, as well as a reference
+directing the user to the copy of this License. Also, you must do one
+of these things:
+
+ a) Accompany the work with the complete corresponding
+ machine-readable source code for the Library including whatever
+ changes were used in the work (which must be distributed under
+ Sections 1 and 2 above); and, if the work is an executable linked
+ with the Library, with the complete machine-readable "work that
+ uses the Library", as object code and/or source code, so that the
+ user can modify the Library and then relink to produce a modified
+ executable containing the modified Library. (It is understood
+ that the user who changes the contents of definitions files in the
+ Library will not necessarily be able to recompile the application
+ to use the modified definitions.)
+
+ b) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (1) uses at run time a
+ copy of the library already present on the user's computer system,
+ rather than copying library functions into the executable, and (2)
+ will operate properly with a modified version of the library, if
+ the user installs one, as long as the modified version is
+ interface-compatible with the version that the work was made with.
+
+ c) Accompany the work with a written offer, valid for at
+ least three years, to give the same user the materials
+ specified in Subsection 6a, above, for a charge no more
+ than the cost of performing this distribution.
+
+ d) If distribution of the work is made by offering access to copy
+ from a designated place, offer equivalent access to copy the above
+ specified materials from the same place.
+
+ e) Verify that the user has already received a copy of these
+ materials or that you have already sent this user a copy.
+
+ For an executable, the required form of the "work that uses the
+Library" must include any data and utility programs needed for
+reproducing the executable from it. However, as a special exception,
+the materials to be distributed need not include anything that is
+normally distributed (in either source or binary form) with the major
+components (compiler, kernel, and so on) of the operating system on
+which the executable runs, unless that component itself accompanies
+the executable.
+
+ It may happen that this requirement contradicts the license
+restrictions of other proprietary libraries that do not normally
+accompany the operating system. Such a contradiction means you cannot
+use both them and the Library together in an executable that you
+distribute.
+
+ 7. You may place library facilities that are a work based on the
+Library side-by-side in a single library together with other library
+facilities not covered by this License, and distribute such a combined
+library, provided that the separate distribution of the work based on
+the Library and of the other library facilities is otherwise
+permitted, and provided that you do these two things:
+
+ a) Accompany the combined library with a copy of the same work
+ based on the Library, uncombined with any other library
+ facilities. This must be distributed under the terms of the
+ Sections above.
+
+ b) Give prominent notice with the combined library of the fact
+ that part of it is a work based on the Library, and explaining
+ where to find the accompanying uncombined form of the same work.
+
+ 8. You may not copy, modify, sublicense, link with, or distribute
+the Library except as expressly provided under this License. Any
+attempt otherwise to copy, modify, sublicense, link with, or
+distribute the Library is void, and will automatically terminate your
+rights under this License. However, parties who have received copies,
+or rights, from you under this License will not have their licenses
+terminated so long as such parties remain in full compliance.
+
+ 9. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Library or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Library (or any work based on the
+Library), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Library or works based on it.
+
+ 10. Each time you redistribute the Library (or any work based on the
+Library), the recipient automatically receives a license from the
+original licensor to copy, distribute, link with or modify the Library
+subject to these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties with
+this License.
+
+ 11. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Library at all. For example, if a patent
+license would not permit royalty-free redistribution of the Library by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Library.
+
+If any portion of this section is held invalid or unenforceable under any
+particular circumstance, the balance of the section is intended to apply,
+and the section as a whole is intended to apply in other circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 12. If the distribution and/or use of the Library is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Library under this License may add
+an explicit geographical distribution limitation excluding those countries,
+so that distribution is permitted only in or among countries not thus
+excluded. In such case, this License incorporates the limitation as if
+written in the body of this License.
+
+ 13. The Free Software Foundation may publish revised and/or new
+versions of the Lesser General Public License from time to time.
+Such new versions will be similar in spirit to the present version,
+but may differ in detail to address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Library
+specifies a version number of this License which applies to it and
+"any later version", you have the option of following the terms and
+conditions either of that version or of any later version published by
+the Free Software Foundation. If the Library does not specify a
+license version number, you may choose any version ever published by
+the Free Software Foundation.
+
+ 14. If you wish to incorporate parts of the Library into other free
+programs whose distribution conditions are incompatible with these,
+write to the author to ask for permission. For software which is
+copyrighted by the Free Software Foundation, write to the Free
+Software Foundation; we sometimes make exceptions for this. Our
+decision will be guided by the two goals of preserving the free status
+of all derivatives of our free software and of promoting the sharing
+and reuse of software generally.
+
+ NO WARRANTY
+
+ 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
+WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
+EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
+OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
+KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
+LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
+THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
+WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
+AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
+FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
+CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
+LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
+RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
+FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
+SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Libraries
+
+ If you develop a new library, and you want it to be of the greatest
+possible use to the public, we recommend making it free software that
+everyone can redistribute and change. You can do so by permitting
+redistribution under these terms (or, alternatively, under the terms of the
+ordinary General Public License).
+
+ To apply these terms, attach the following notices to the library. It is
+safest to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least the
+"copyright" line and a pointer to where the full notice is found.
+
+
+ Copyright (C)
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+Also add information on how to contact you by electronic and paper mail.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the library, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the
+ library `Frob' (a library for tweaking knobs) written by James Random Hacker.
+
+ , 1 April 1990
+ Ty Coon, President of Vice
+
+That's all there is to it!
+
+
diff --git a/blip_buf/makefile_orig b/blip_buf/makefile_orig
new file mode 100644
index 0000000000..dbf51fa2e1
--- /dev/null
+++ b/blip_buf/makefile_orig
@@ -0,0 +1,22 @@
+all: demo demo_chip demo_fixed demo_stereo demo.c demo_chip.c demo_fixed.c demo_stereo.c blip_buf.c
+
+demo: demo.c blip_buf.c
+ $(CC) -o demo demo.c blip_buf.c wave_writer.c
+
+demo_chip: demo_chip.c blip_buf.c
+ $(CC) -o demo_chip demo_chip.c blip_buf.c wave_writer.c
+
+demo_fixed: demo_fixed.c blip_buf.c
+ $(CC) -o demo_fixed demo_fixed.c blip_buf.c wave_writer.c
+
+demo_stereo: demo_stereo.c blip_buf.c
+ $(CC) -o demo_stereo demo_stereo.c blip_buf.c wave_writer.c
+
+demo_sdl: demo_sdl.c blip_buf.c
+ $(CC) -o demo_sdl $(shell sdl-config --cflags) $(shell sdl-config --libs) demo_sdl.c blip_buf.c
+
+test: blip_buf.c blip_buf.h
+ $(CXX) -o test -DBLARGG_TEST -I . -I tests/tester blip_buf.c tests/*.cpp tests/tester/*.cpp
+
+clean:
+ -$(RM) demo demo_chip demo_fixed demo_stereo demo_sdl
diff --git a/blip_buf/readme.txt b/blip_buf/readme.txt
new file mode 100644
index 0000000000..4709d3f053
--- /dev/null
+++ b/blip_buf/readme.txt
@@ -0,0 +1,62 @@
+blip_buf 1.1.0: Band-Limited Audio Buffer
+-----------------------------------------
+Blip_buf is a small waveform synthesis library meant for use in classic
+video game sound chip emulation. It greatly simplifies sound chip
+emulation code by handling all the details of resampling. The emulator
+merely sets the input clock rate and output sample rate, adds waveforms
+by specifying the clock times where their amplitude changes, then reads
+the resulting output samples. For a more full-features synthesis
+library, get Blip_Buffer.
+
+* Simple C interface and usage.
+* Several code examples, including simple sound chip emulator.
+* Uses fast, high-quality band-limited resampling algorithm (BLEP).
+* Output is low-pass and high-pass filtered and clamped to 16-bit range.
+* Supports mono, stereo, and multi-channel synthesis.
+
+Author : Shay Green
+Website : http://www.slack.net/~ant/
+License : GNU Lesser General Public License (LGPL)
+Language: C
+
+
+Getting Started
+---------------
+Build the demos by typing "make" at the command-line. If that doesn't
+work, manually build a program from demo.c, blip_buf.c, and
+wave_writer.c. Run "demo", which should record a square wave sweep to
+"out.wav". The others demo advanced topics, and their source code can be
+used as a starting point for experimentation (after making any changes,
+just type "make" to do any necessary recompilation).
+
+To build the SDL demo, type "make demo_sdl" at the command-line, or
+manually build a program from demo_sdl.c, blip_buf.c, and the SDL
+multimedia library.
+
+See blip_buf.h for reference and blip_buf.txt for documentation.
+
+
+Files
+-----
+readme.txt Essential information
+blip_buf.txt Library documentation
+license.txt GNU Lesser General Public License
+
+makefile Builds demos (type "make" at command-line)
+
+demo.c Generates square wave sweep
+demo_stereo.c Generates stereo sound using two blip buffers
+demo_fixed.c Works in fixed-point time rather than clocks
+demo_sdl.c Plays sound live using SDL multimedia library
+demo_chip.c Emulates sound hardware and plays back log.txt
+demo_log.txt Log of sound hardware writes for demo_chip.c
+wave_writer.h Simple wave sound file writer used by demos
+wave_writer.c
+
+blip_buf.h Library header and reference (Doxygen-enabled)
+blip_buf.c source code
+
+tests/ Unit tests (build with "make test")
+
+--
+Shay Green