Example #1
0
 public G722ChatCodec()
 {
     bitrate      = 64000;
     encoderState = new G722CodecState(bitrate, G722Flags.None);
     decoderState = new G722CodecState(bitrate, G722Flags.None);
     codec        = new G722Codec();
     RecordFormat = new WaveFormat(16000, 1);
 }
Example #2
0
 public G722ChatCodec()
 {
     BitsPerSecond = 64000;
     _encoderState = new G722CodecState(BitsPerSecond, G722Flags.None);
     _decoderState = new G722CodecState(BitsPerSecond, G722Flags.None);
     _codec        = new G722Codec();
     RecordFormat  = new WaveFormat(16000, 1);
 }
 public G722ChatCodec()
 {
     Bitrate      = 64000;
     EncoderState = new G722CodecState(Bitrate, G722Flags.None);
     DecoderState = new G722CodecState(Bitrate, G722Flags.None);
     Codec        = new G722Codec();
     RecordFormat = new WaveFormat(16000, 1);
 }
Example #4
0
 public G722ChatCodec()
 {
     this.bitrate         = 64000;
     this.encoderState    = new G722CodecState(bitrate, G722Flags.None);
     this.decoderState    = new G722CodecState(bitrate, G722Flags.None);
     this.codec           = new G722Codec();
     this.recordingFormat = new WaveFormat(16000, 1);
 }
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
        // public int Encode(byte[] encoded, short[] pcm)
        // {
        //     if (g722Codec == null)
        //     {
        //         g722Codec = new G722Codec();
        //         g722CodecState = new G722CodecState(G722_BIT_RATE, G722Flags.None);
        //     }

        //     var requiredEncodedByteCount = pcm.Length / 2;
        //     if (encoded.Length < requiredEncodedByteCount)
        //     {
        //         return -1;
        //     }

        //     var encodedByteCount = g722Codec.Encode(g722CodecState, encoded,
        //         pcm, pcm.Length);
        //     return encodedByteCount;
        // }

        public byte[] Encode(short[] pcm)
        {
            if (g722Codec == null)
            {
                g722Codec      = new G722Codec();
                g722CodecState = new G722CodecState(G722_BIT_RATE, G722Flags.None);
            }

            var requiredEncodedByteCount = pcm.Length / 2;
            var enc = new byte[requiredEncodedByteCount];

            g722Codec.Encode(g722CodecState, enc, pcm, pcm.Length);
            return(enc);
        }
Example #7
0
        static private void WaveIn_DataAvailable(object sender, WaveInEventArgs e)
        {
            G722Codec codec = new G722Codec();

            short[] newData = new short[e.BytesRecorded / 2];
            for (int i = 0; i < e.BytesRecorded / 2; i++)
            {
                newData[i]  = (short)(e.Buffer[2 * i] >> 8);
                newData[i] += e.Buffer[2 * i + 1];
            }
            byte[] buffer = new byte[newData.Length * 2];
            //for (int i = 0; i < buffer.Length; i++)
            //buffer[i] = ALawEncoder.LinearToALawSample(newData[i]);

            codec.Encode(_g722CodecState, buffer, newData, newData.Length);
            _bufferedWaveProvider.AddSamples(buffer, 0, buffer.Length);
        }