static void EncodeStreamAdpcm(MicrosoftWaveMixer mixer, aBinaryWriter writer) { var left_adpcm4 = new byte[9]; int left_last = 0, left_penult = 0; var right_adpcm4 = new byte[9]; int right_last = 0, right_penult = 0; var left = new short[16]; var right = new short[16]; for (var i = 0; i < mixer.SampleCount; i += 16) { for (var j = 0; j < 16; ++j) { if ((i + j) < mixer.SampleCount) { mixer.ReadPcm16((i + j), out left[j], out right[j]); } else { left[j] = 0; right[j] = 0; } } Waveform.Pcm16toAdpcm4(left, left_adpcm4, ref left_last, ref left_penult); Waveform.Pcm16toAdpcm4(right, right_adpcm4, ref right_last, ref right_penult); writer.Write8s(left_adpcm4); writer.Write8s(right_adpcm4); if ((i % cMessageInterval) == 0 || (i + 16) >= mixer.SampleCount) { mareep.WriteMessage("\rSamples encoded: {0}/{1}", System.Math.Min((i + 16), mixer.SampleCount), mixer.SampleCount); } } }