BlueGit

blue-star ggj-2020

Files

ggj-2020 / Assets / Oculus / Platform / Scripts / MicrophoneInputNative.cs

MicrophoneInputNative.cs

Project Import
timfa Tim Falken · pushed by timfa · 6 years ago
b77834a1 History
MicrophoneInputNative.cs 1.3 KiB Download Raw
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
5using UnityEngine;
6using System;
7using System.Collections.Generic;
8
9namespace 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