Example #1
0
    public void Start(int frequency, int channels, int frameSamplesPerChannel, int playDelayMs)
    {
        const int CHANNEL_COUNT = 2; // stereo

        instanceFramePool = new PrimitiveArrayPool <float>(FRAME_POOL_CAPACITY, "PS4AudioOut");
        instanceFramePool.Init(frameSamplesPerChannel * DEST_SAMPLE_RATE / frequency * CHANNEL_COUNT);
        channelCount = channels;
        lock (locker)
        {
            if (frameBuf == null)
            {
                staticFramePool = new PrimitiveArrayPool <float>(FRAME_POOL_CAPACITY, "PS4AudioOut");
                staticFramePool.Init(GRANULARITY * CHANNEL_COUNT);
                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, true);
                playThreadShouldTerminate = false;
                playThread              = new Thread(Play);
                playThread.Name         = "photon voice audio output thread";
                playThread.IsBackground = true;
                playThread.Start();
                frameBuf = new Dictionary <PS4AudioOut, Queue <float> >();
            }

            frameBuf.Add(this, new Queue <float>());
        }

        this.speakersOut.Start(frequency, channels, frameSamplesPerChannel, playDelayMs);
    }
Example #2
0
    public void Stop()
    {
        if (frameBuf == null)
        {
            return;
        }
        lock (locker)
        {
            frameBuf.Remove(this);
            if (frameBuf.Count > 0)
            {
                return;
            }
            frameBuf = null;
        }
        playThreadShouldTerminate = true;
        instanceFramePool         = null;
        egpvclose(pPhotonVoiceAudioOutput);
        pPhotonVoiceAudioOutput = IntPtr.Zero;

        this.speakersOut.Stop();
    }