Esempio n. 1
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;
            }

            var adpcm4 = new byte[9];
            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.Pcm16toAdpcm4(pcm16, adpcm4, ref _last, ref _penult);
                Waveform.Adpcm4toPcm16(adpcm4, pcm16, ref last, ref penult);
            }
        }
Esempio n. 2
0
        protected override void WriteAdpcm4(aBinaryWriter writer)
        {
            var adpcm4 = new byte[9];
            var pcm16 = new short[16];
            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)
                    {
                        ReadPcm16((i + j), out pcm16[j]);
                    }
                }

                Waveform.Pcm16toAdpcm4(pcm16, adpcm4, ref last, ref penult);
                writer.Write8s(adpcm4);
            }
        }
Esempio n. 3
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;
            }
            }
        }
Esempio n. 4
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;
            }
            }
        }