Assignment for RMIT Mixed Reality in 2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.3 KiB

  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. #if OVR_PLATFORM_USE_MICROPHONE
  4. using UnityEngine;
  5. using System;
  6. using System.Collections.Generic;
  7. namespace Oculus.Platform
  8. {
  9. public class MicrophoneInputNative : IMicrophone
  10. {
  11. IntPtr mic;
  12. int tempBufferSize = 960 * 10;
  13. float[] tempBuffer;
  14. private Dictionary<int, float[]> micSampleBuffers;
  15. public MicrophoneInputNative()
  16. {
  17. mic = CAPI.ovr_Microphone_Create();
  18. CAPI.ovr_Microphone_Start(mic);
  19. tempBuffer = new float[tempBufferSize];
  20. micSampleBuffers = new Dictionary<int, float[]>();
  21. }
  22. public float[] Update()
  23. {
  24. ulong readSize = (ulong)CAPI.ovr_Microphone_ReadData(mic, tempBuffer, (UIntPtr)tempBufferSize);
  25. if (readSize > 0)
  26. {
  27. float[] samples;
  28. if (!micSampleBuffers.TryGetValue((int)readSize, out samples))
  29. {
  30. samples = new float[readSize];
  31. micSampleBuffers[(int)readSize] = samples;
  32. }
  33. Array.Copy(tempBuffer, samples, (int)readSize);
  34. return samples;
  35. }
  36. return null;
  37. }
  38. public void Start()
  39. {
  40. }
  41. public void Stop()
  42. {
  43. CAPI.ovr_Microphone_Stop(mic);
  44. CAPI.ovr_Microphone_Destroy(mic);
  45. }
  46. }
  47. }
  48. #endif