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.

73 lines
1.8 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. //
  4. // NOTE for android developers: The existence of UnityEngine.Microphone causes Unity to insert the
  5. // android.permission.RECORD_AUDIO permission into the AndroidManifest.xml generated at build time
  6. #if OVR_PLATFORM_USE_MICROPHONE
  7. using UnityEngine;
  8. using System.Collections.Generic;
  9. namespace Oculus.Platform
  10. {
  11. public class MicrophoneInput : IMicrophone
  12. {
  13. AudioClip microphoneClip;
  14. int lastMicrophoneSample;
  15. int micBufferSizeSamples;
  16. private Dictionary<int, float[]> micSampleBuffers;
  17. public MicrophoneInput()
  18. {
  19. int bufferLenSeconds = 1; //minimum size unity allows
  20. int inputFreq = 48000; //this frequency is fixed throughout the voip system atm
  21. microphoneClip = Microphone.Start(null, true, bufferLenSeconds, inputFreq);
  22. micBufferSizeSamples = bufferLenSeconds * inputFreq;
  23. micSampleBuffers = new Dictionary<int, float[]>();
  24. }
  25. public void Start()
  26. {
  27. }
  28. public void Stop()
  29. {
  30. }
  31. public float[] Update()
  32. {
  33. int pos = Microphone.GetPosition(null);
  34. int copySize = 0;
  35. if (pos < lastMicrophoneSample)
  36. {
  37. int endOfBufferSize = micBufferSizeSamples - lastMicrophoneSample;
  38. copySize = endOfBufferSize + pos;
  39. }
  40. else
  41. {
  42. copySize = pos - lastMicrophoneSample;
  43. }
  44. if (copySize == 0) {
  45. return null;
  46. }
  47. float[] samples;
  48. if (!micSampleBuffers.TryGetValue(copySize, out samples))
  49. {
  50. samples = new float[copySize];
  51. micSampleBuffers[copySize] = samples;
  52. }
  53. microphoneClip.GetData(samples, lastMicrophoneSample);
  54. lastMicrophoneSample = pos;
  55. return samples;
  56. }
  57. }
  58. }
  59. #endif