private void voiceplay(float hearDistance, int setupData, byte[] data) { Camera main = Camera.main; if ((main != null) && (hearDistance > 0f)) { USpeaker uspeaker = this.uspeaker; if (uspeaker == null) { Debug.LogWarning("voiceplayback:" + base.gameObject + " didn't have a USpeaker!?"); } if (!uspeaker.HasSettings()) { uspeaker.InitializeSettings(setupData); } if (data == null) { Debug.LogWarning("voiceplayback: data was null!"); } float num = Vector3.Distance(main.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0.0001f)), base.eyesOrigin); float num2 = Mathf.Clamp01(1f - (num / hearDistance)); uspeaker.SpeakerVolume = num2; uspeaker.ReceiveAudio(data); AudioSource audio = uspeaker.audio; if (audio != null) { audio.rolloffMode = AudioRolloffMode.Linear; audio.maxDistance = hearDistance; audio.minDistance = 1f; } } }
void Start() { if (!GetComponent <NetworkView>().isMine) { USpeaker.Get(this).SpeakerMode = SpeakerMode.Remote; } }
void Start() { if (!networkView.isMine) { USpeaker.Get(this).SpeakerMode = SpeakerMode.Remote; } }
IEnumerator JitterSend(byte[] data) { if (Random.Range(0.0f, 1.0f) <= ChanceOfPacketLoss) { yield break; } yield return(new WaitForSeconds(Random.Range(0.0f, (float)PingJitterMS / 1000.0f))); USpeaker.Get(this).ReceiveAudio(data); }
// Token: 0x06004CFA RID: 19706 RVA: 0x0019C8D0 File Offset: 0x0019ACD0 public override void Awake() { base.Awake(); this.spk = USpeaker.Get(this); if (base.photonView.isMine) { this.spk.SpeakerMode = SpeakerMode.Local; } else { this.spk.SpeakerMode = SpeakerMode.Remote; } }
IEnumerator fakeSendPacket(byte[] data) { float rand = Random.Range(0f, 100f); if (rand < packetLoss) { yield break; } float delay = Random.Range(ping, ping + jitter) / 1000f; yield return(new WaitForSeconds(delay)); USpeaker.Get(this).ReceiveAudio(data); }
// Token: 0x06004CC4 RID: 19652 RVA: 0x0019BA84 File Offset: 0x00199E84 private IEnumerator fakeSendPacket(byte[] data) { float rand = UnityEngine.Random.Range(0f, 100f); if (rand < this.packetLoss) { yield break; } float delay = UnityEngine.Random.Range(this.ping, this.ping + this.jitter) / 1000f; yield return(new WaitForSeconds(delay)); USpeaker.Get(this).ReceiveAudio(data); yield break; }
// Token: 0x06006152 RID: 24914 RVA: 0x00224EB4 File Offset: 0x002232B4 private void RefreshLabel() { bool flag = string.IsNullOrEmpty(VRCInputManager.micDeviceName); string friendlyInputDeviceName = USpeaker.GetFriendlyInputDeviceName(); string text = string.Empty; if (flag || string.IsNullOrEmpty(friendlyInputDeviceName)) { text = "Default - " + ((!string.IsNullOrEmpty(friendlyInputDeviceName)) ? friendlyInputDeviceName : "None"); } else { text = friendlyInputDeviceName; } this.labelMic.text = text; }
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; } } } }
// Token: 0x06006154 RID: 24916 RVA: 0x00224F84 File Offset: 0x00223384 public void SelectNextMic() { bool flag = string.IsNullOrEmpty(VRCInputManager.micDeviceName); int deviceID = (!flag) ? (USpeaker.GetInputDeviceID() + 1) : 0; bool flag2 = USpeaker.TrySetInputDevice(deviceID); if (flag2) { VRCInputManager.micDeviceName = USpeaker.GetInputDeviceName(); } else { VRCInputManager.micDeviceName = string.Empty; USpeaker.SetInputDevice(0); } this.RefreshLabel(); }
// Token: 0x060062D6 RID: 25302 RVA: 0x00230E84 File Offset: 0x0022F284 private void CheckUiActive() { bool flag = this.ActiveScreens.Count > 0; if (flag != this.UiActive) { if (flag) { this.PlaceUi(); } this.UiActive = flag; VRCUiCursorManager.SetUiActive(flag); USpeaker.CacheDevices(); this.menuContentTransform.gameObject.GetComponent <Collider>().enabled = flag; if (flag && QuickMenu.Instance != null && QuickMenu.Instance && QuickMenu.Instance.IsActive) { QuickMenu.Instance.CloseMenu(); } } }
private void voiceplay(float hearDistance, int setupData, byte[] data) { Camera camera = Camera.main; if (!camera) { return; } if (hearDistance <= 0f) { return; } USpeaker uSpeaker = this.uspeaker; if (!uSpeaker) { Debug.LogWarning(string.Concat("voiceplayback:", base.gameObject, " didn't have a USpeaker!?")); } if (!uSpeaker.HasSettings()) { uSpeaker.InitializeSettings(setupData); } if (data == null) { Debug.LogWarning("voiceplayback: data was null!"); } Vector3 worldPoint = camera.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0.0001f)); float single = Vector3.Distance(worldPoint, base.eyesOrigin); float single1 = Mathf.Clamp01(1f - single / hearDistance); uSpeaker.SpeakerVolume = single1; uSpeaker.ReceiveAudio(data); AudioSource audioSource = uSpeaker.audio; if (audioSource) { audioSource.rolloffMode = AudioRolloffMode.Linear; audioSource.maxDistance = hearDistance; audioSource.minDistance = 1f; } }
public override void OnInspectorGUI() { USpeaker tg = (USpeaker)target; tg.SpeakerMode = (SpeakerMode)EditorGUILayout.EnumPopup("Speaker Mode", tg.SpeakerMode); tg.BandwidthMode = (BandMode)EditorGUILayout.Popup("Bandwidth Mode", (int)tg.BandwidthMode, new string[] { "Narrow - 8 kHz", "Wide - 16 kHz" }); if ((int)tg.BandwidthMode > 1) { tg.BandwidthMode = BandMode.Narrow; } tg.SendingMode = (SendBehavior)EditorGUILayout.Popup("Sending Mode", (int)tg.SendingMode, new string[] { "Send while recording", "Record then send" }); tg.UseVAD = EditorGUILayout.Toggle("Volume Activated", tg.UseVAD); tg.DebugPlayback = EditorGUILayout.Toggle("Debug Playback", tg.DebugPlayback); string sendrate = tg.SendRate + "/sec"; if (tg.SendRate < 1.0f) { sendrate = "1 per " + (1.0f / tg.SendRate) + " secs"; } tg.SendRate = EditorGUILayout.FloatField("Send Rate (" + sendrate + ")", tg.SendRate); if (tg.SendRate <= 0) { tg.SendRate = Mathf.Epsilon; } tg.Is3D = EditorGUILayout.Toggle("3D", tg.Is3D); tg.AskPermission = EditorGUILayout.Toggle("Ask for Mic Permission", tg.AskPermission); tg.PlayBufferSize = EditorGUILayout.FloatField("Play Buffer Length (s)", tg.PlayBufferSize); tg.GetInputHandler(); tg.DrawTalkControllerUI(); }
// Token: 0x06004CC6 RID: 19654 RVA: 0x0019BBD8 File Offset: 0x00199FD8 private void OnGUI() { if (Network.peerType == NetworkPeerType.Disconnected) { if (GUI.Button(new Rect(10f, 10f, 100f, 30f), "Connect")) { Network.Connect(this.remoteIP, this.remotePort); } if (GUI.Button(new Rect(10f, 50f, 100f, 30f), "Start Server")) { Network.InitializeServer(32, this.listenPort, true); } this.remoteIP = GUI.TextField(new Rect(120f, 10f, 100f, 20f), this.remoteIP); this.remotePort = int.Parse(GUI.TextField(new Rect(230f, 10f, 40f, 20f), this.remotePort.ToString())); } else { if (GUI.Button(new Rect(10f, 10f, 100f, 50f), "Disconnect")) { Network.Disconnect(200); } GUILayout.BeginArea(new Rect(10f, 60f, 200f, 500f)); int num = 0; foreach (string text in Microphone.devices) { if (GUILayout.Button(text, new GUILayoutOption[] { GUILayout.Width(200f) })) { USpeaker.SetInputDevice(num); } num++; } GUILayout.EndArea(); } }
void OnGUI() { if (Network.peerType == NetworkPeerType.Disconnected) { if (GUI.Button(new Rect(10, 10, 100, 30), "Connect")) { Network.Connect(remoteIP, remotePort); } if (GUI.Button(new Rect(10, 50, 100, 30), "Start Server")) { Network.InitializeServer(32, listenPort, true); } remoteIP = GUI.TextField(new Rect(120, 10, 100, 20), remoteIP); remotePort = int.Parse(GUI.TextField(new Rect(230, 10, 40, 20), remotePort.ToString())); } else { if (GUI.Button(new Rect(10, 10, 100, 50), "Disconnect")) { Network.Disconnect(200); } GUILayout.BeginArea(new Rect(10, 60, 200, 500)); int idx = 0; foreach (string mic in Microphone.devices) { if (GUILayout.Button(mic, GUILayout.Width(200f))) { USpeaker.SetInputDevice(idx); } idx++; } GUILayout.EndArea(); } }
public void USpeakInitializeSettings(int data) { USpeaker.Get(this).InitializeSettings(data); }
void init(int data) { USpeaker.Get(this).InitializeSettings(data); }
void vc(byte[] data) { USpeaker.Get(this).ReceiveAudio(data); }
private void Update() { bool value; int num; USpeaker uSpeaker = this; uSpeaker.talkTimer = uSpeaker.talkTimer - Time.deltaTime; base.audio.volume = this.SpeakerVolume; if (this.last3DMode != this._3DMode) { this.last3DMode = this._3DMode; this.StopPlaying(); base.audio.clip = AudioClip.Create("vc", this.audioFrequency * 10, 1, this.audioFrequency, this._3DMode == ThreeDMode.Full3D, false); base.audio.loop = true; } if (this._3DMode == ThreeDMode.SpeakerPan) { Transform transforms = Camera.main.transform; Vector3 vector3 = Vector3.Cross(transforms.up, transforms.forward); vector3.Normalize(); float single = Vector3.Dot(base.transform.position - transforms.position, vector3); float single1 = Vector3.Dot(base.transform.position - transforms.position, transforms.forward); float single2 = Mathf.Sin(Mathf.Atan2(single, single1)); base.audio.pan = single2; } if (base.audio.isPlaying) { if (this.lastTime > base.audio.time) { USpeaker uSpeaker1 = this; uSpeaker1.played = uSpeaker1.played + (double)base.audio.clip.length; } this.lastTime = base.audio.time; if (this.played + (double)base.audio.time >= this.received) { this.StopPlaying(); this.shouldPlay = false; } } else if (this.shouldPlay) { USpeaker uSpeaker2 = this; uSpeaker2.playDelay = uSpeaker2.playDelay - Time.deltaTime; if (this.playDelay <= 0f) { base.audio.Play(); } } if (this.SpeakerMode == SpeakerMode.Remote) { return; } if (this.audioHandler == null) { return; } if (this.devicesCached == null) { this.devicesCached = Microphone.devices; base.InvokeRepeating("RefreshDevices", 4.2f, 4.2f); } string[] strArrays = this.devicesCached; if ((int)strArrays.Length == 0) { return; } if (strArrays[Mathf.Min(USpeaker.InputDeviceID, (int)strArrays.Length - 1)] != this.currentDeviceName) { this.currentDeviceName = strArrays[Mathf.Min(USpeaker.InputDeviceID, (int)strArrays.Length - 1)]; MonoBehaviour.print(string.Concat("Using input device: ", this.currentDeviceName)); this.recording = Microphone.Start(this.currentDeviceName, false, 21, this.audioFrequency); this.lastReadPos = 0; } if (this.lastBandMode != this.BandwidthMode || this.lastCodec != this.Codec) { this.UpdateSettings(); this.lastBandMode = this.BandwidthMode; this.lastCodec = this.Codec; } int position = Microphone.GetPosition(null); if (position >= this.audioFrequency * 20) { position = 0; this.lastReadPos = 0; UnityEngine.Object.DestroyImmediate(this.recording); Microphone.End(null); this.recording = Microphone.Start(this.currentDeviceName, false, 21, this.audioFrequency); } if (position <= this.overlap) { return; } bool?nullable = null; try { int num1 = position - this.lastReadPos; int sampleSize = this.codecMgr.Codecs[this.Codec].GetSampleSize(this.audioFrequency); if (sampleSize == 0) { sampleSize = 100; } if (sampleSize != 0) { int num2 = this.lastReadPos; int num3 = Mathf.FloorToInt((float)(num1 / sampleSize)); for (int i = 0; i < num3; i++) { float[] singleArray = USpeakPoolUtils.GetFloat(sampleSize); this.recording.GetData(singleArray, num2); if (!nullable.HasValue) { bool?nullable1 = new bool?((this.talkController == null ? false : this.talkController.ShouldSend())); nullable = nullable1; value = nullable1.Value; } else { value = nullable.Value; } if (value) { this.talkTimer = 1f; this.OnAudioAvailable(singleArray); } USpeakPoolUtils.Return(singleArray); num2 = num2 + sampleSize; } this.lastReadPos = num2; } else { if (num1 > sampleSize) { float[] singleArray1 = new float[num1 - 1]; this.recording.GetData(singleArray1, this.lastReadPos); if (this.talkController == null || this.talkController.ShouldSend()) { this.talkTimer = 1f; this.OnAudioAvailable(singleArray1); } } this.lastReadPos = position; } } catch (Exception exception) { } this.ProcessPendingEncodeBuffer(); bool flag = true; if (this.SendingMode == SendBehavior.RecordThenSend && this.talkController != null) { if (!nullable.HasValue) { bool?nullable2 = new bool?(this.talkController.ShouldSend()); nullable = nullable2; num = (int)nullable2.Value; } else { num = (int)nullable.Value; } flag = num == 0; } USpeaker uSpeaker3 = this; uSpeaker3.sendTimer = uSpeaker3.sendTimer + Time.deltaTime; if (this.sendTimer >= this.sendt && flag) { this.sendTimer = 0f; this.tempSendBytes.Clear(); foreach (USpeakFrameContainer uSpeakFrameContainer in this.sendBuffer) { this.tempSendBytes.AddRange(uSpeakFrameContainer.ToByteArray()); } this.sendBuffer.Clear(); if (this.tempSendBytes.Count > 0) { this.audioHandler.USpeakOnSerializeAudio(this.tempSendBytes.ToArray()); } } }
// Token: 0x0600614E RID: 24910 RVA: 0x00224E4F File Offset: 0x0022324F private void OnEnable() { AudioSettings.OnAudioConfigurationChanged += this.OnAudioConfigurationChanged; USpeaker.SetInputDeviceFromPrefs(); this.RefreshLabel(); }
public void USpeakOnSerializeAudio(byte[] data) { USpeaker.Get(this).ReceiveAudio(data); }
// Token: 0x06004D1A RID: 19738 RVA: 0x0019D932 File Offset: 0x0019BD32 private void Awake() { this.spk = USpeaker.Get(this); Debug.LogError("FIX PREVIOUS LINES"); UnityEngine.Object.DontDestroyOnLoad(base.gameObject); }
// Token: 0x06004CC3 RID: 19651 RVA: 0x0019BA73 File Offset: 0x00199E73 public void USpeakInitializeSettingsForPlayer(int data, Player p) { USpeaker.Get(this).InitializeSettings(data); }