コード例 #1
0
    // initializes the speaker with remote voice info
    internal void OnVoiceLinked(int frequency, int channels, int frameSamplesPerChannel, int playDelayMs)
    {
#if !UNITY_EDITOR && UNITY_PS4
        if (frameBuf == null)
        {
            if (framePool == null)
            {
                framePool = new ExitGames.Client.Photon.Voice.PrimitiveArrayPool <float>(FRAME_POOL_CAPACITY, "PhotonVoiceSpeaker");
                framePool.Init(frameSamplesPerChannel * channels);
            }

            int userID = PhotonVoiceSettings.Instance.PS4UserID;
            if (userID == 0)
            {
                UserProfiles.LocalUsers localUsers = new UserProfiles.LocalUsers();
                UserProfiles.GetLocalUsers(localUsers);
                userID = localUsers.LocalUsersIds[0].UserId.Id;
            }
            pPhotonVoiceAudioOutput = egpvopen(userID, GRANULARITY, channels > 1);
            framer = new Framer <float>(GRANULARITY * channels);
            playThreadShouldTerminate = false;
            playThread              = new Thread(Play);
            playThread.Name         = "photon voice audio output thread";
            playThread.IsBackground = true;
            playThread.Start();
            frameBuf = new Dictionary <int, Queue <float[]> >();
        }
        lock (frameBuf)
        {
            frameBuf.Add(GetInstanceID(), new Queue <float[]>());
        }
#endif
        this.player.Start(frequency, channels, frameSamplesPerChannel, playDelayMs);
    }
コード例 #2
0
    void Cleanup()
    {
#if !UNITY_EDITOR && UNITY_PS4
        if (frameBuf == null)
        {
            return;
        }
        lock (frameBuf)
        {
            frameBuf.Remove(GetInstanceID());
            if (frameBuf.Count > 0)
            {
                return;
            }
            frameBuf = null;
        }
        playThreadShouldTerminate = true;
        framePool = null;
        egpvclose(pPhotonVoiceAudioOutput);
        pPhotonVoiceAudioOutput = IntPtr.Zero;
#endif
        this.player.Stop();
    }