Example #1
0
        public override byte[] DecodeToBytes(RTPPacket packet)
        {
            short[] sOutput = new short[packet.PayloadData.Length * 2];
            Codec.Decode(DecodeState, sOutput, packet.PayloadData, packet.PayloadData.Length);

            return(Utils.ConvertShortArrayToByteArray(sOutput));
        }
Example #2
0
        private byte[] DecodeFormat2(byte[] data)
        {
            short[] output = new short[data.Length * 2];
            decode2.Decode(decode2State, output, data, data.Length);

            float[] f = Converters.shorts2floats(output, true);
            float[] s = Converters.mono2stereo(f);

            byte[] o = codecUpSampler.inputResample(Converters.floats2bytes(s), s.Length);

            return(o);
        }
Example #3
0
        public byte[] Decode(byte[] data, int offset, int length)
        {
            if (offset != 0)
            {
                throw new ArgumentException("G722 does not yet support non-zero offsets");
            }
            int decodedLength = length * 4;
            var outputBuffer  = new byte[decodedLength];
            var wb            = new WaveBuffer(outputBuffer);
            int decoded       = codec.Decode(decoderState, wb.ShortBuffer, data, length);

            Debug.Assert(decodedLength == decoded * 2);  // because decoded is a number of samples
            return(outputBuffer);
        }
Example #4
0
        public byte[] Decode(byte[] data, int offset, int length)
        {
            if (offset != 0)
            {
                throw new ArgumentException("G722 does not yet support non-zero offsets");
            }
            int decodedLength = length * 4;

            byte[]     outputBuffer = new byte[decodedLength];
            WaveBuffer wb           = new WaveBuffer(outputBuffer);

            _codec.Decode(_decoderState, wb.ShortBuffer, data, length);
            return(outputBuffer);
        }
Example #5
0
        // public int Decode(short[] pcm, byte[] encoded)
        // {
        //     if (g722Codec == null)
        //     {
        //         g722Codec = new G722Codec();
        //         g722CodecState = new G722CodecState(G722_BIT_RATE, G722Flags.None);
        //     }
        //     var requiredDecodedSampleCount = encoded.Length * 2;
        //     if (pcm.Length < requiredDecodedSampleCount)
        //     {
        //         return -1;
        //     }
        //     var decodedSampleCount = g722Codec.Decode(g722CodecState, pcm,
        //         encoded, encoded.Length);
        //     return decodedSampleCount;
        // }
        public short[] Decode(byte[] encoded)
        {
            if (g722Codec == null)
            {
                g722Codec = new G722Codec();
                g722CodecState = new G722CodecState(G722_BIT_RATE, G722Flags.None);
            }

            var requiredDecodedSampleCount = encoded.Length * 2;
            var pcm = new short[requiredDecodedSampleCount];

            g722Codec.Decode(g722CodecState,pcm,encoded,encoded.Length);
            return pcm;
        }
Example #6
0
        private byte[] DecodeFormat1(byte[] data)
        {
            // SPLIT INTO TWO PARTS
            byte[] L = new byte[data.Length / 2];
            byte[] R = new byte[data.Length / 2];

            Array.Copy(data, L, L.Length);
            Array.Copy(data, L.Length, R, 0, R.Length);


            short[] outputL = new short[L.Length * 2];
            short[] outputR = new short[R.Length * 2];
            decode1L.Decode(decode1Lstate, outputL, L, L.Length);
            decode1R.Decode(decode1Rstate, outputR, R, R.Length);

            short[] output = Converters.MuxDualMono(outputL, outputR);

            return(Converters.floats2bytes(Converters.shorts2floats(output, true)));
        }