Ejemplo n.º 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);
    }
Ejemplo n.º 2
0
        // may be called on any thread
        public void Push(float[] frame)
        {
            if (frame.Length == 0)
            {
                return;
            }

            //TODO: call framePool.AcquireOrCreate(frame.Length) and test
            if (framePool.Info != frame.Length)
            {
                framePool.Init(frame.Length);
            }
            float[] b = framePool.AcquireOrCreate();
            System.Buffer.BlockCopy(frame, 0, b, 0, frame.Length * sizeof(float));
            lock (frameQueue)
            {
                frameQueue.Enqueue(b);
            }
        }