| 1 | //This file is deprecated. Use the high level voip system instead: |
| 2 | // https://developer.oculus.com/documentation/platform/latest/concepts/dg-cc-voip/ |
| 3 | |
| 4 | #if OVR_PLATFORM_USE_MICROPHONE |
| 5 | using UnityEngine; |
| 6 | using System; |
| 7 | using System.Collections.Generic; |
| 8 | |
| 9 | namespace Oculus.Platform |
| 10 | { |
| 11 | public class MicrophoneInputNative : IMicrophone |
| 12 | { |
| 13 | IntPtr mic; |
| 14 | |
| 15 | int tempBufferSize = 960 * 10; |
| 16 | float[] tempBuffer; |
| 17 | |
| 18 | private Dictionary<int, float[]> micSampleBuffers; |
| 19 | |
| 20 | public MicrophoneInputNative() |
| 21 | { |
| 22 | mic = CAPI.ovr_Microphone_Create(); |
| 23 | CAPI.ovr_Microphone_Start(mic); |
| 24 | tempBuffer = new float[tempBufferSize]; |
| 25 | |
| 26 | micSampleBuffers = new Dictionary<int, float[]>(); |
| 27 | } |
| 28 | |
| 29 | public float[] Update() |
| 30 | { |
| 31 | ulong readSize = (ulong)CAPI.ovr_Microphone_ReadData(mic, tempBuffer, (UIntPtr)tempBufferSize); |
| 32 | if (readSize > 0) |
| 33 | { |
| 34 | float[] samples; |
| 35 | if (!micSampleBuffers.TryGetValue((int)readSize, out samples)) |
| 36 | { |
| 37 | samples = new float[readSize]; |
| 38 | micSampleBuffers[(int)readSize] = samples; |
| 39 | } |
| 40 | Array.Copy(tempBuffer, samples, (int)readSize); |
| 41 | return samples; |
| 42 | } |
| 43 | return null; |
| 44 | } |
| 45 | |
| 46 | public void Start() |
| 47 | { |
| 48 | |
| 49 | } |
| 50 | |
| 51 | public void Stop() |
| 52 | { |
| 53 | CAPI.ovr_Microphone_Stop(mic); |
| 54 | CAPI.ovr_Microphone_Destroy(mic); |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | #endif |