// may be called on any thread public void Push(float[] frame) { if (!this.started) { return; } if (frame.Length == 0) { return; } if (frame.Length != this.frameSize) { logger.LogError("{0} UnityAudioOut audio frames are not of size: {1} != {2}", this.logPrefix, frame.Length, this.frameSize); return; } float[] b = framePool.AcquireOrCreate(); System.Buffer.BlockCopy(frame, 0, b, 0, frame.Length * sizeof(float)); lock (this.frameQueue) { this.frameQueue.Enqueue(b); } }
internal static void Play() { while (!playThreadShouldTerminate) { if (frameBuf != null) { float[] frameMix = null; lock (locker) { foreach (var it in frameBuf) { if (it.Value.Count >= GRANULARITY * 2) { if (frameMix == null) { frameMix = staticFramePool.AcquireOrCreate(); for (int i = 0; i < GRANULARITY * 2; ++i) { frameMix[i] = it.Value.Dequeue(); } } else { for (int i = 0; i < GRANULARITY * 2; ++i) { frameMix[i] += it.Value.Dequeue(); } } it.Key.IsPlaying = true; } } } if (frameMix != null) { unsafe { fixed(float *pArray = frameMix) egpvplay(pPhotonVoiceAudioOutput, new IntPtr(pArray)); } staticFramePool.Release(frameMix); lock (locker) foreach (var it in frameBuf) { it.Key.IsPlaying = false; } } } } }
// 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); } }
// may be called on any thread public void OnAudioFrame(float[] frame) { if (frame.Length == 0) { return; } if (frame.Length != frameSize) { Debug.LogErrorFormat("{0} Audio frames are not of size: {1} != {2}", this.logPrefix, frame.Length, frameSize); //Debug.LogErrorFormat("{0} {1} {2} {3} {4} {5} {6}", frame[0], frame[1], frame[2], frame[3], frame[4], frame[5], frame[6]); return; } // Store last packet float[] b = framePool.AcquireOrCreate(); System.Buffer.BlockCopy(frame, 0, b, 0, frameSize * sizeof(float)); lock (frameQueue) { frameQueue.Enqueue(b); } }