コード例 #1
0
ファイル: USpeaker.cs プロジェクト: sknchan/LegacyRust
 public void ReceiveAudio(byte[] data)
 {
     byte[] num = null;
     if (this.settings == null)
     {
         UnityEngine.Debug.LogWarning("Trying to receive remote audio data without calling InitializeSettings!\nIncoming packet will be ignored");
         return;
     }
     if (USpeaker.MuteAll || this.Mute || this.SpeakerMode == SpeakerMode.Local && !this.DebugPlayback)
     {
         return;
     }
     if (this.SpeakerMode == SpeakerMode.Remote)
     {
         this.talkTimer = 1f;
     }
     for (int i = 0; i < (int)data.Length; i = i + (int)num.Length)
     {
         int num1 = BitConverter.ToInt32(data, i);
         num = USpeakPoolUtils.GetByte(num1 + 6);
         Array.Copy(data, i, num, 0, (int)num.Length);
         USpeakFrameContainer uSpeakFrameContainer = new USpeakFrameContainer();
         uSpeakFrameContainer.LoadFrom(num);
         USpeakPoolUtils.Return(num);
         float[]  singleArray = USpeakAudioClipCompressor.DecompressAudio(uSpeakFrameContainer.encodedData, (int)uSpeakFrameContainer.Samples, 1, false, this.settings.bandMode, this.codecMgr.Codecs[this.Codec], USpeaker.RemoteGain);
         float    length      = (float)((int)singleArray.Length) / (float)this.audioFrequency;
         USpeaker uSpeaker    = this;
         uSpeaker.received = uSpeaker.received + (double)length;
         Array.Copy(singleArray, 0, this.receivedData, this.index, (int)singleArray.Length);
         USpeakPoolUtils.Return(singleArray);
         USpeaker length1 = this;
         length1.index = length1.index + (int)singleArray.Length;
         if (this.index >= base.audio.clip.samples)
         {
             this.index = 0;
         }
         base.audio.clip.SetData(this.receivedData, 0);
         if (!base.audio.isPlaying)
         {
             this.shouldPlay = true;
             if (this.playDelay <= 0f)
             {
                 this.playDelay = length * 2f;
             }
         }
     }
 }
コード例 #2
0
ファイル: USpeaker.cs プロジェクト: Virobeast2/RCLIENT
 public void ReceiveAudio(byte[] data)
 {
     if (this.settings == null)
     {
         UnityEngine.Debug.LogWarning("Trying to receive remote audio data without calling InitializeSettings!\nIncoming packet will be ignored");
     }
     else if ((!MuteAll && !this.Mute) && ((this.SpeakerMode != SpeakerMode.Local) || this.DebugPlayback))
     {
         byte[] @byte;
         if (this.SpeakerMode == SpeakerMode.Remote)
         {
             this.talkTimer = 1f;
         }
         for (int i = 0; i < data.Length; i += @byte.Length)
         {
             @byte = USpeakPoolUtils.GetByte(BitConverter.ToInt32(data, i) + 6);
             Array.Copy(data, i, @byte, 0, @byte.Length);
             USpeakFrameContainer container = new USpeakFrameContainer();
             container.LoadFrom(@byte);
             USpeakPoolUtils.Return(@byte);
             float[] sourceArray = USpeakAudioClipCompressor.DecompressAudio(container.encodedData, container.Samples, 1, false, this.settings.bandMode, this.codecMgr.Codecs[this.Codec], RemoteGain);
             float   num3        = ((float)sourceArray.Length) / ((float)this.audioFrequency);
             this.received += num3;
             Array.Copy(sourceArray, 0, this.receivedData, this.index, sourceArray.Length);
             USpeakPoolUtils.Return(sourceArray);
             this.index += sourceArray.Length;
             if (this.index >= base.audio.clip.samples)
             {
                 this.index = 0;
             }
             base.audio.clip.SetData(this.receivedData, 0);
             if (!base.audio.isPlaying)
             {
                 this.shouldPlay = true;
                 if (this.playDelay <= 0f)
                 {
                     this.playDelay = num3 * 2f;
                 }
             }
         }
     }
 }
コード例 #3
0
    /// <summary>
    /// Decode and buffer audio data to be played
    /// </summary>
    /// <param name="data">The data passed to USpeakOnSerializeAudio()</param>
    public void ReceiveAudio(byte[] data)
    {
        if (settings == null)
        {
            Debug.LogWarning("Trying to receive remote audio data without calling InitializeSettings!\nIncoming packet will be ignored");
            return;
        }

        if (MuteAll || Mute || (SpeakerMode == SpeakerMode.Local && !DebugPlayback))
        {
            return;
        }

        if (SpeakerMode == SpeakerMode.Remote)
        {
            talkTimer = 1.0f;
        }

        int offset = 0;

        while (offset < data.Length)
        {
            int    len   = System.BitConverter.ToInt32(data, offset);
            byte[] frame = USpeakPoolUtils.GetByte(len + 6);
            System.Array.Copy(data, offset, frame, 0, frame.Length);

            USpeakFrameContainer cont = default(USpeakFrameContainer);
            cont.LoadFrom(frame);

            USpeakPoolUtils.Return(frame);

            float[] sample = USpeakAudioClipCompressor.DecompressAudio(cont.encodedData, (int)cont.Samples, 1, false, settings.bandMode, codecMgr.Codecs[Codec], RemoteGain);

            float sampleTime = ((float)sample.Length / (float)audioFrequency);
            received += sampleTime;

            System.Array.Copy(sample, 0, receivedData, index, sample.Length);

            USpeakPoolUtils.Return(sample);

            // advance the write position into the audio clip
            index += sample.Length;

            // if the write position extends beyond the clip length, wrap around
            if (index >= audio.clip.samples)
            {
                index = 0;
            }

            // write received data to audio clip
            audio.clip.SetData(receivedData, 0);

            // not already playing audio, schedule audio to be played
            if (!audio.isPlaying)
            {
                shouldPlay = true;

                //Debug.Log( "Started receiving at time: " + Time.time );

                // no play delay set, advance play delay to allow more data to arrive (deal with network latency)
                if (playDelay <= 0)
                {
                    playDelay = sampleTime * 5f;
                }
            }

            offset += frame.Length;
        }
    }