Beispiel #1
0
 /// <summary>
 /// Sets the AudioSessionParameters for iOS audio initialization when Photon MicrophoneType is used.
 /// </summary>
 /// <param name="asp">You can use custom value or one from presets, <see cref="IOS.AudioSessionParametersPresets"/></param>
 /// <returns>If a change has been made.</returns>
 public bool SetIosAudioSessionParameters(IOS.AudioSessionParameters asp)
 {
     return(this.SetIosAudioSessionParameters(asp.Category, asp.Mode, asp.CategoryOptions));
 }
Beispiel #2
0
        private LocalVoice CreateLocalVoiceAudioAndSource()
        {
            switch (SourceType)
            {
            case InputSourceType.Microphone:
            {
                if (this.MicrophoneType == MicType.Photon)
                {
                        #if UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX || UNITY_EDITOR_WIN
                    var hwMicDev = this.PhotonMicrophoneDeviceId;
                    if (this.Logger.IsInfoEnabled)
                    {
                        this.Logger.LogInfo("Setting recorder's source to Photon microphone device [{0}] \"{1}\"", hwMicDev, PhotonMicrophoneEnumerator.NameAtIndex(hwMicDev));
                    }
                        #else
                    if (this.Logger.IsInfoEnabled)
                    {
                        this.Logger.LogInfo("Setting recorder's source to Photon microphone device");
                    }
                        #endif
                        #if UNITY_STANDALONE_WIN && !UNITY_EDITOR || UNITY_EDITOR_WIN
                    if (this.Logger.IsInfoEnabled)
                    {
                        this.Logger.LogInfo("Setting recorder's source to WindowsAudioInPusher");
                    }
                    inputSource = new Windows.WindowsAudioInPusher(hwMicDev, this.Logger);
                        #elif UNITY_IOS && !UNITY_EDITOR
                    IOS.AudioSessionParameters audioSessionParameters = IOS.AudioSessionParametersPresets.Game;
                    if (this.Logger.IsInfoEnabled)
                    {
                        this.Logger.LogInfo("Setting recorder's source to IOS.AudioInPusher with session {0}", audioSessionParameters);
                    }
                    inputSource = new IOS.AudioInPusher(audioSessionParameters, this.Logger);
                        #elif UNITY_STANDALONE_OSX && !UNITY_EDITOR || UNITY_EDITOR_OSX
                    if (this.Logger.IsInfoEnabled)
                    {
                        this.Logger.LogInfo("Setting recorder's source to MacOS.AudioInPusher");
                    }
                    inputSource = new MacOS.AudioInPusher(hwMicDev, this.Logger);
                        #elif UNITY_ANDROID && !UNITY_EDITOR
                    if (this.Logger.IsInfoEnabled)
                    {
                        this.Logger.LogInfo("Setting recorder's source to UnityAndroidAudioInAEC");
                    }
                    inputSource = new UnityAndroidAudioInAEC(this.Logger);
                        #else
                    inputSource = new AudioDesc(0, 0, "Photon microphone type is not supported for the current platform.");
                        #endif
                    if (inputSource.Error == null)
                    {
                        break;
                    }
                    if (this.Logger.IsErrorEnabled)
                    {
                        this.Logger.LogError("Photon microphone input source creation failure: {0}. Falling back to Unity microphone", inputSource.Error);
                    }
                }
                if (Microphone.devices.Length < 1)
                {
                    if (this.Logger.IsInfoEnabled)
                    {
                        this.Logger.LogInfo("No Microphone");
                    }
                    return(LocalVoiceAudioDummy.Dummy);
                }
                var micDev = this.UnityMicrophoneDevice;
                if (this.Logger.IsInfoEnabled)
                {
                    this.Logger.LogInfo("Setting recorder's source to Unity microphone device {0}", micDev);
                }
                // mic can ignore passed sampling rate and set its own
                inputSource = new MicWrapper(micDev, (int)SamplingRate, this.Logger);
                if (inputSource.Error != null && this.Logger.IsErrorEnabled)
                {
                    this.Logger.LogError("Unity microphone input source creation failure: {0}.", inputSource.Error);
                }
            }
            break;

            case InputSourceType.AudioClip:
            {
                if (AudioClip == null)
                {
                    if (this.Logger.IsErrorEnabled)
                    {
                        this.Logger.LogError("AudioClip property must be set for AudioClip audio source");
                    }
                    return(LocalVoiceAudioDummy.Dummy);
                }
                inputSource = new AudioClipWrapper(AudioClip);     // never fails, no need to check Error
                if (this.LoopAudioClip)
                {
                    ((AudioClipWrapper)inputSource).Loop = true;
                }
            }
            break;

            case InputSourceType.Factory:
            {
                if (InputFactory == null)
                {
                    if (this.Logger.IsErrorEnabled)
                    {
                        this.Logger.LogError("Recorder.InputFactory must be specified if Recorder.Source set to Factory");
                    }
                    return(LocalVoiceAudioDummy.Dummy);
                }
                inputSource = InputFactory();
                if (inputSource.Error != null && this.Logger.IsErrorEnabled)
                {
                    this.Logger.LogError("InputFactory creation failure: {0}.", inputSource.Error);
                }
            }
            break;

            default:
                if (this.Logger.IsErrorEnabled)
                {
                    this.Logger.LogError("unknown Source value {0}", SourceType);
                }
                return(LocalVoiceAudioDummy.Dummy);
            }

            VoiceInfo voiceInfo = VoiceInfo.CreateAudioOpus(SamplingRate, inputSource.SamplingRate, inputSource.Channels, FrameDuration, Bitrate, UserData);
            return(client.CreateLocalVoiceAudioFromSource(voiceInfo, inputSource, forceShort));
        }