コード例 #1
0
    private Voice.LocalVoice createLocalVoiceAudioAndSource()
    {
        var pvs = PhotonVoiceSettings.Instance;

        switch (Source)
        {
        case AudioSource.Microphone:
        {
            Application.RequestUserAuthorization(UserAuthorization.Microphone);
            if (this.MicrophoneType == MicAudioSourceType.Settings && pvs.MicrophoneType == PhotonVoiceSettings.MicAudioSourceType.Photon ||
                this.MicrophoneType == MicAudioSourceType.Photon)
            {
                var hwMicDev = this.PhotonMicrophoneDeviceID != -1 ? this.PhotonMicrophoneDeviceID : PhotonVoiceNetwork.PhotonMicrophoneDeviceID;
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
                if (PhotonVoiceSettings.Instance.DebugInfo)
                {
                    Debug.LogFormat("PUNVoice: Setting recorder's source to Photon microphone device {0}", hwMicDev);
                }

                audioSource = new WindowsAudioInPusher(hwMicDev);
                if (PhotonVoiceSettings.Instance.DebugInfo)
                {
                    Debug.LogFormat("PUNVoice: Setting recorder's source to WindowsAudioInPusher");
                }
                break;
#elif UNITY_IOS && !UNITY_EDITOR || (UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX)
                audioSource = new AppleAudioInPusher(hwMicDev);
                if (PhotonVoiceSettings.Instance.DebugInfo)
                {
                    Debug.LogFormat("PUNVoice: Setting recorder's source to AppleAudioInPusher");
                }
                break;
#elif UNITY_ANDROID && !UNITY_EDITOR
                audioSource = new AndroidAudioInAEC();
                if (PhotonVoiceSettings.Instance.DebugInfo)
                {
                    Debug.LogFormat("PUNVoice: Setting recorder's source to AndroidAudioInAEC");
                }
                break;
#else
                Debug.LogFormat("PUNVoice: Photon microphone type is not supported for the current platform. Using Unity microphone.");
#endif
            }
            if (Microphone.devices.Length < 1)
            {
                // Error already logged in PhotonVoiceNetwork.Start()
                return(Voice.LocalVoiceAudio.Dummy);
            }
            var micDev = this.MicrophoneDevice != null ? this.MicrophoneDevice : PhotonVoiceNetwork.MicrophoneDevice;

            if (PhotonVoiceSettings.Instance.DebugInfo)
            {
                Debug.LogFormat("PUNVoice: Setting recorder's source to microphone device {0}", micDev);
            }
            // mic can ignore passed sampling rate and set it's own
            var mic = new MicWrapper(micDev, (int)pvs.SamplingRate);
            audioSource = mic;
        }
        break;

        case AudioSource.AudioClip:
        {
            if (AudioClip == null)
            {
                Debug.LogErrorFormat("PUNVoice: AudioClip property must be set for AudioClip audio source");
                return(Voice.LocalVoiceAudio.Dummy);
            }
            audioSource = new AudioClipWrapper(AudioClip);
            if (this.LoopAudioClip)
            {
                ((AudioClipWrapper)audioSource).Loop = true;
            }
        }
        break;

        case AudioSource.Factory:
        {
            if (PhotonVoiceNetwork.AudioSourceFactory == null)
            {
                Debug.LogErrorFormat("PUNVoice: PhotonVoiceNetwork.AudioSourceFactory must be specified if PhotonVoiceRecorder.Source set to Factory");
                return(Voice.LocalVoiceAudio.Dummy);
            }
            audioSource = PhotonVoiceNetwork.AudioSourceFactory(this);
        }
        break;

        default:
            Debug.LogErrorFormat("PUNVoice: unknown Source value {0}", Source);
            return(Voice.LocalVoiceAudio.Dummy);
        }

        Voice.VoiceInfo voiceInfo = Voice.VoiceInfo.CreateAudioOpus(pvs.SamplingRate, audioSource.SamplingRate, audioSource.Channels, pvs.FrameDuration, pvs.Bitrate, photonView.viewID);
        return(createLocalVoiceAudio(voiceInfo, audioSource));
    }
コード例 #2
0
    // Token: 0x0600006B RID: 107 RVA: 0x00003B3C File Offset: 0x00001D3C
    private LocalVoice createLocalVoiceAudioAndSource()
    {
        PhotonVoiceSettings instance = PhotonVoiceSettings.Instance;

        switch (this.Source)
        {
        case PhotonVoiceRecorder.AudioSource.Microphone:
            if ((this.MicrophoneType == PhotonVoiceRecorder.MicAudioSourceType.Settings && instance.MicrophoneType == PhotonVoiceSettings.MicAudioSourceType.Photon) || this.MicrophoneType == PhotonVoiceRecorder.MicAudioSourceType.Photon)
            {
                int num = (this.PhotonMicrophoneDeviceID != -1) ? this.PhotonMicrophoneDeviceID : PhotonVoiceNetwork.PhotonMicrophoneDeviceID;
                if (PhotonVoiceSettings.Instance.DebugInfo)
                {
                    Debug.LogFormat("PUNVoice: Setting recorder's source to Photon microphone device {0}", new object[]
                    {
                        num
                    });
                }
                this.audioSource = new WindowsAudioInPusher(num);
                if (PhotonVoiceSettings.Instance.DebugInfo)
                {
                    Debug.LogFormat("PUNVoice: Setting recorder's source to WindowsAudioInPusher", Array.Empty <object>());
                }
            }
            else
            {
                if (Microphone.devices.Length < 1)
                {
                    return(LocalVoiceAudio.Dummy);
                }
                string text = (this.MicrophoneDevice != null) ? this.MicrophoneDevice : PhotonVoiceNetwork.MicrophoneDevice;
                if (PhotonVoiceSettings.Instance.DebugInfo)
                {
                    Debug.LogFormat("PUNVoice: Setting recorder's source to microphone device {0}", new object[]
                    {
                        text
                    });
                }
                MicWrapper micWrapper = new MicWrapper(text, (int)instance.SamplingRate);
                this.audioSource = micWrapper;
            }
            break;

        case PhotonVoiceRecorder.AudioSource.AudioClip:
            if (this.AudioClip == null)
            {
                Debug.LogErrorFormat("PUNVoice: AudioClip property must be set for AudioClip audio source", Array.Empty <object>());
                return(LocalVoiceAudio.Dummy);
            }
            this.audioSource = new AudioClipWrapper(this.AudioClip);
            if (this.LoopAudioClip)
            {
                ((AudioClipWrapper)this.audioSource).Loop = true;
            }
            break;

        case PhotonVoiceRecorder.AudioSource.Factory:
            if (PhotonVoiceNetwork.AudioSourceFactory == null)
            {
                Debug.LogErrorFormat("PUNVoice: PhotonVoiceNetwork.AudioSourceFactory must be specified if PhotonVoiceRecorder.Source set to Factory", Array.Empty <object>());
                return(LocalVoiceAudio.Dummy);
            }
            this.audioSource = PhotonVoiceNetwork.AudioSourceFactory(this);
            break;

        default:
            Debug.LogErrorFormat("PUNVoice: unknown Source value {0}", new object[]
            {
                this.Source
            });
            return(LocalVoiceAudio.Dummy);
        }
        VoiceInfo voiceInfo = VoiceInfo.CreateAudioOpus(instance.SamplingRate, this.audioSource.SamplingRate, this.audioSource.Channels, instance.FrameDuration, instance.Bitrate, base.photonView.viewID);

        return(this.createLocalVoiceAudio(voiceInfo, this.audioSource));
    }