コード例 #1
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);
        }
コード例 #2
0
        /**
         * FORMAT 2
         * G722 16kHz mono
         **/
        private byte[] EncodeFormat2(float[] data)
        {
            byte[]  rs = codecDownSampler.inputResample(Converters.floats2bytes(data), data.Length);
            float[] f  = Converters.bytes2floats(rs);

            float[] mono = Converters.stereo2mono(f);

            short[] shorts = Converters.floats2shorts(mono, true);

            int bytes = (int)(shorts.Length / 2);

            byte[] output = new byte[bytes];

            encode2.Encode(encode2State, output, shorts, shorts.Length);
            return(output);
        }
コード例 #3
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)));
        }
コード例 #4
0
        private byte[] DecodeOpus(byte[] data, int packetSize)
        {
            // Decoding loop
            int frames    = data.Length / packetSize;
            int frameSize = 960;             // must be same as framesize used in input, you can use OpusPacketInfo.GetNumSamples() to determine this dynamically

            short[]      outputBuffer;
            List <float> outData = new List <float>();

            for (int i = 0; i < frames; i++)
            {
                outputBuffer = new short[frameSize * 2];

                int thisFrameSize = opus_decoder.Decode(data, i * packetSize, packetSize, outputBuffer, 0, frameSize, false);

                outData.AddRange(Converters.shorts2floats(outputBuffer, true));
            }

            return(Converters.floats2bytes(outData.ToArray()));
        }
コード例 #5
0
ファイル: Audio_functions.cs プロジェクト: jiehuali/CrossTalk
        private void FetchAudioFromInputBuffer()
        {
            if (inputBuffer != null)
            {
                double samplesToFetch = (inputBuffer.BufferedDuration.TotalMilliseconds - 50d) * ((internalFormatStereo.SampleRate * internalFormatStereo.Channels) / 1000d);

                // CHECK FOR WHOLE NUMBER
                if (samplesToFetch - (int)samplesToFetch != 0)
                {
                    throw new ApplicationException("FetchAudioFromInputBuffer cannot fetch fractional samples. Adjust either internal sample rate or main server interval.");
                }

                // ONLY FETCH AUDIO IF BUFFER CONAINS ENOUGH
                if (inputBuffer.BufferedBytes > samplesToFetch && inputBuffer.BufferedDuration.TotalMilliseconds > 100)
                {
                    float[] input = new float[(int)samplesToFetch];
                    inputResampler.Read(input, 0, (int)samplesToFetch);

                    initialAudioProccessing(Converters.floats2bytes(input));
                }
            }
        }
コード例 #6
0
 /**
  * FORMAT 0
  * PCM 32bit float 48kHz
  **/
 private byte[] EncodeFormat0(float[] data)
 {
     return(Converters.floats2bytes(data));
 }