Exemple #1
0
        private short ADPCM_Decode(byte originalSample)
        {
            int num = 0;

            num = this.stepsize * originalSample / 4 + this.stepsize / 8;
            if ((originalSample & 4) == 4)
            {
                num = num + this.stepsize;
            }
            if ((originalSample & 2) == 2)
            {
                num = num + (this.stepsize >> 1);
            }
            if ((originalSample & 1) == 1)
            {
                num = num + (this.stepsize >> 2);
            }
            num = num + (this.stepsize >> 3);
            if ((originalSample & 8) == 8)
            {
                num = -num;
            }
            this.newSample = num;
            if (this.newSample > 32767)
            {
                this.newSample = 32767;
            }
            else if (this.newSample < -32768)
            {
                this.newSample = -32768;
            }
            ADPCMCodec aDPCMCodec = this;

            aDPCMCodec.index = aDPCMCodec.index + ADPCMCodec.indexTable[originalSample];
            if (this.index < 0)
            {
                this.index = 0;
            }
            if (this.index > 88)
            {
                this.index = 88;
            }
            this.stepsize = ADPCMCodec.stepsizeTable[this.index];
            return((short)this.newSample);
        }
Exemple #2
0
        private byte ADPCM_Encode(short originalSample)
        {
            int num = originalSample - this.predictedSample;

            if (num < 0)
            {
                this.newSample = 8;
                num            = -num;
            }
            else
            {
                this.newSample = 0;
            }
            byte num1 = 4;
            int  num2 = this.stepsize;

            for (int i = 0; i < 3; i++)
            {
                if (num >= num2)
                {
                    ADPCMCodec aDPCMCodec = this;
                    aDPCMCodec.newSample = aDPCMCodec.newSample | num1;
                    num = num - num2;
                }
                num2 = num2 >> 1;
                num1 = (byte)(num1 >> 1);
            }
            num = this.stepsize >> 3;
            if ((this.newSample & 4) != 0)
            {
                num = num + this.stepsize;
            }
            if ((this.newSample & 2) != 0)
            {
                num = num + (this.stepsize >> 1);
            }
            if ((this.newSample & 1) != 0)
            {
                num = num + (this.stepsize >> 2);
            }
            if ((this.newSample & 8) != 0)
            {
                num = -num;
            }
            ADPCMCodec aDPCMCodec1 = this;

            aDPCMCodec1.predictedSample = aDPCMCodec1.predictedSample + num;
            if (this.predictedSample > 32767)
            {
                this.predictedSample = 32767;
            }
            if (this.predictedSample < -32768)
            {
                this.predictedSample = -32768;
            }
            ADPCMCodec aDPCMCodec2 = this;

            aDPCMCodec2.index = aDPCMCodec2.index + ADPCMCodec.indexTable[this.newSample];
            if (this.index < 0)
            {
                this.index = 0;
            }
            else if (this.index > 88)
            {
                this.index = 88;
            }
            this.stepsize = ADPCMCodec.stepsizeTable[this.index];
            return((byte)this.newSample);
        }