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