sbyte MixPcm8() { sbyte pcm8 = 0; if (mChannelCount == 1) { if (mBitDepth == 8) { pcm8 = ReadPcm8(); } else { Waveform.Pcm16toPcm8(ReadPcm16(), out pcm8); } } else { if (mBitDepth == 8) { var left = ReadPcm8(); var right = ReadPcm8(); pcm8 = MixStereoPcm8(left, right); } else { var left = ReadPcm16(); var right = ReadPcm16(); Waveform.Pcm16toPcm8(MixStereoPcm16(left, right), out pcm8); } } return(pcm8); }
public override void ReadPcm8(int sample, out sbyte pcm8) { if (sample < 0 || sample >= mSampleCount) { throw new ArgumentOutOfRangeException("sample"); } pcm8 = 0; switch (mFormat) { case WaveFormat.Pcm8: { mReader.Goto(sample); pcm8 = mReader.ReadS8(); break; } case WaveFormat.Pcm16: { mReader.Goto(sample * 2); Waveform.Pcm16toPcm8(mReader.ReadS16(), out pcm8); break; } case WaveFormat.Adpcm2: { int last = 0, penult = 0; var pcm16 = new short[16]; for (var i = 0; i < mSampleCount; i += 16) { Waveform.Adpcm2toPcm16(mReader.Read8s(5), pcm16, ref last, ref penult); if (i <= sample && sample < (i + 16)) { Waveform.Pcm16toPcm8(pcm16[sample - i], out pcm8); break; } } break; } case WaveFormat.Adpcm4: { int last = 0, penult = 0; var pcm16 = new short[16]; for (var i = 0; i < mSampleCount; i += 16) { Waveform.Adpcm4toPcm16(mReader.Read8s(9), pcm16, ref last, ref penult); if (i <= sample && sample < (i + 16)) { Waveform.Pcm16toPcm8(pcm16[sample - i], out pcm8); break; } } break; } } }
protected override void WritePcm8(aBinaryWriter writer) { mReader.Goto(0); switch (mFormat) { case WaveFormat.Pcm8: { writer.WriteS8s(mReader.ReadS8s(mSampleCount)); break; } case WaveFormat.Pcm16: { for (var i = 0; i < mSampleCount; ++i) { sbyte pcm8; Waveform.Pcm16toPcm8(mReader.ReadS16(), out pcm8); writer.WriteS8(pcm8); } break; } case WaveFormat.Adpcm2: { var pcm8 = new sbyte[16]; var pcm16 = new short[16]; int last = 0, penult = 0; for (var i = 0; i < mSampleCount; i += 16) { Waveform.Adpcm2toPcm16(mReader.Read8s(5), pcm16, ref last, ref penult); for (var j = 0; j < 16; ++j) { Waveform.Pcm16toPcm8(pcm16[j], out pcm8[j]); } writer.WriteS8s(pcm8, System.Math.Min(16, (mSampleCount - i))); } break; } case WaveFormat.Adpcm4: { var pcm8 = new sbyte[16]; var pcm16 = new short[16]; int last = 0, penult = 0; for (var i = 0; i < mSampleCount; i += 16) { Waveform.Adpcm4toPcm16(mReader.Read8s(9), pcm16, ref last, ref penult); for (var j = 0; j < 16; ++j) { Waveform.Pcm16toPcm8(pcm16[j], out pcm8[j]); } writer.WriteS8s(pcm8, System.Math.Min(16, (mSampleCount - i))); } break; } } }
public override void ReadPcm8(int sample, out sbyte left, out sbyte right) { if (sample < 0 || sample >= mSampleCount) { throw new ArgumentOutOfRangeException("sample"); } GotoSample(sample); if (mChannelCount == 1) { sbyte pcm8; if (mBitDepth == 8) { pcm8 = ReadPcm8(); } else { Waveform.Pcm16toPcm8(ReadPcm16(), out pcm8); } left = pcm8; right = pcm8; } else { if (mBitDepth == 8) { left = ReadPcm8(); right = ReadPcm8(); } else { Waveform.Pcm16toPcm8(ReadPcm16(), out left); Waveform.Pcm16toPcm8(ReadPcm16(), out right); } } }