Exemplo n.º 1
0
        protected override void CalculateHistoryAdpcm2(int sample, out int last, out int penult)
        {
            last   = 0;
            penult = 0;

            var frame = (sample / 16);

            if (frame == 0)
            {
                return;
            }

            var adpcm2 = new byte[5];
            var pcm16  = new short[16];

            int _last = 0, _penult = 0;

            for (var i = 0; i < frame; ++i)
            {
                for (var j = 0; j < 16; ++j)
                {
                    pcm16[j] = 0;

                    if ((i * 16 + j) < mSampleCount)
                    {
                        ReadPcm16((i * 16 + j), out pcm16[j]);
                    }
                }

                Waveform.Pcm16toAdpcm2(pcm16, adpcm2, ref _last, ref _penult);
                Waveform.Adpcm2toPcm16(adpcm2, pcm16, ref last, ref penult);
            }
        }
Exemplo n.º 2
0
        public override void ReadPcm16(int sample, out short pcm16)
        {
            if (sample < 0 || sample >= mSampleCount)
            {
                throw new ArgumentOutOfRangeException("sample");
            }

            pcm16 = 0;

            switch (mFormat)
            {
            case WaveFormat.Pcm8: {
                mReader.Goto(sample);
                Waveform.Pcm8toPcm16(mReader.ReadS8(), out pcm16);
                break;
            }

            case WaveFormat.Pcm16: {
                mReader.Goto(sample * 2);
                pcm16 = mReader.ReadS16();
                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))
                    {
                        pcm16 = _pcm16[sample - i];
                        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))
                    {
                        pcm16 = _pcm16[sample - i];
                        break;
                    }
                }
                break;
            }
            }
        }
Exemplo n.º 3
0
        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;
            }
            }
        }
Exemplo n.º 4
0
        protected override void WriteAdpcm4(aBinaryWriter writer)
        {
            mReader.Goto(0);

            switch (mFormat)
            {
            case WaveFormat.Pcm8: {
                var pcm16 = new short[16];
                var adpcm4 = new byte[9];
                int last = 0, penult = 0;
                for (var i = 0; i < mSampleCount; i += 16)
                {
                    for (var j = 0; j < 16; ++j)
                    {
                        pcm16[j] = 0;

                        if (i + j < mSampleCount)
                        {
                            Waveform.Pcm8toPcm16(mReader.ReadS8(), out pcm16[j]);
                        }
                    }
                    Waveform.Pcm16toAdpcm4(pcm16, adpcm4, ref last, ref penult);
                    writer.Write8s(adpcm4);
                }
                break;
            }

            case WaveFormat.Pcm16: {
                var pcm16 = new short[16];
                var adpcm4 = new byte[9];
                int _last = 0, _penult = 0;
                for (var i = 0; i < mSampleCount; i += 16)
                {
                    for (var j = 0; j < 16; ++j)
                    {
                        pcm16[j] = (short)(i + j < mSampleCount ? mReader.ReadS16() : 0);
                    }
                    Waveform.Pcm16toAdpcm4(pcm16, adpcm4, ref _last, ref _penult);
                    writer.Write8s(adpcm4);
                }
                break;
            }

            case WaveFormat.Adpcm2: {
                var pcm16 = new short[16];
                var adpcm4 = new byte[9];
                int last1 = 0, penult1 = 0;
                int last2 = 0, penult2 = 0;
                for (var i = 0; i < mSampleCount; i += 16)
                {
                    Waveform.Adpcm2toPcm16(mReader.Read8s(5), pcm16, ref last1, ref penult1);
                    Waveform.Pcm16toAdpcm4(pcm16, adpcm4, ref last2, ref penult2);
                    writer.Write8s(adpcm4);
                }
                break;
            }

            case WaveFormat.Adpcm4: {
                for (var i = 0; i < mSampleCount; i += 16)
                {
                    writer.Write8s(mReader.Read8s(9));
                }
                break;
            }
            }
        }
Exemplo n.º 5
0
        protected override void CalculateHistoryAdpcm4(int sample, out int last, out int penult)
        {
            last   = 0;
            penult = 0;

            var frame = (sample / 16);

            if (frame == 0)
            {
                return;
            }

            switch (mFormat)
            {
            case WaveFormat.Pcm8: {
                var adpcm4 = new byte[9];
                var pcm16 = new short[16];
                int _last = 0, _penult = 0;

                mReader.Goto(0);

                for (var i = 0; i < frame; ++i)
                {
                    for (var j = 0; j < 16; ++j)
                    {
                        pcm16[j] = 0;

                        if ((i * 16 + j) < mSampleCount)
                        {
                            Waveform.Pcm8toPcm16(mReader.ReadS8(), out pcm16[j]);
                        }
                    }

                    Waveform.Pcm16toAdpcm4(pcm16, adpcm4, ref _last, ref _penult);
                    Waveform.Adpcm4toPcm16(adpcm4, pcm16, ref last, ref penult);
                }

                break;
            }

            case WaveFormat.Pcm16: {
                var adpcm4 = new byte[9];
                var pcm16 = new short[16];
                int _last = 0, _penult = 0;

                mReader.Goto(0);

                for (var i = 0; i < frame; ++i)
                {
                    for (var j = 0; j < 16; ++j)
                    {
                        pcm16[j] = 0;

                        if ((i + j) < mSampleCount)
                        {
                            pcm16[j] = mReader.ReadS16();
                        }
                    }

                    Waveform.Pcm16toAdpcm4(pcm16, adpcm4, ref _last, ref _penult);
                    Waveform.Adpcm4toPcm16(adpcm4, pcm16, ref last, ref penult);
                }

                break;
            }

            case WaveFormat.Adpcm2: {
                var adpcm4 = new byte[9];
                var pcm16 = new short[16];
                int last1 = 0, penult1 = 0;
                int last2 = 0, penult2 = 0;

                mReader.Goto(0);

                for (var i = 0; i < frame; ++i)
                {
                    Waveform.Adpcm2toPcm16(mReader.Read8s(5), pcm16, ref last1, ref penult1);
                    Waveform.Pcm16toAdpcm4(pcm16, adpcm4, ref last2, ref penult2);
                    Waveform.Adpcm4toPcm16(adpcm4, pcm16, ref last, ref penult);
                }

                break;
            }

            case WaveFormat.Adpcm4: {
                var pcm16 = new short[16];

                mReader.Goto(0);

                for (var i = 0; i < frame; ++i)
                {
                    Waveform.Adpcm4toPcm16(mReader.Read8s(9), pcm16, ref last, ref penult);
                }

                break;
            }
            }
        }