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.

84 lines
2.2 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 false
  4. namespace Oculus.Platform
  5. {
  6. using UnityEngine;
  7. using System.Runtime.InteropServices;
  8. using System.Collections;
  9. public class VoipInput : MonoBehaviour
  10. {
  11. public delegate void OnCompressedData(byte[] compressedData);
  12. public OnCompressedData onCompressedData;
  13. protected IMicrophone micInput;
  14. Encoder encoder;
  15. public bool enableMicRecording;
  16. protected void Start()
  17. {
  18. encoder = new Encoder();
  19. if (UnityEngine.Application.platform == RuntimePlatform.WindowsEditor || UnityEngine.Application.platform == RuntimePlatform.WindowsPlayer)
  20. {
  21. micInput = new MicrophoneInputNative();
  22. }
  23. else
  24. {
  25. micInput = new MicrophoneInput();
  26. }
  27. enableMicRecording = true;
  28. }
  29. void OnApplicationQuit()
  30. {
  31. micInput.Stop();
  32. }
  33. void Update()
  34. {
  35. if (micInput == null || encoder == null)
  36. {
  37. throw new System.Exception("VoipInput failed to init");
  38. }
  39. if (micInput != null && enableMicRecording)
  40. {
  41. float[] rawMicSamples = micInput.Update();
  42. if (rawMicSamples != null && rawMicSamples.Length > 5 * 1024)
  43. {
  44. Debug.Log(string.Format("Giant input mic data {0}", rawMicSamples.Length));
  45. return;
  46. }
  47. if (rawMicSamples != null && rawMicSamples.Length > 0)
  48. {
  49. int startIdx = 0;
  50. int remaining = rawMicSamples.Length;
  51. int splitSize = 480;
  52. do
  53. {
  54. int toCopy = System.Math.Min(splitSize, remaining);
  55. float[] splitInput = new float[toCopy];
  56. System.Array.Copy(rawMicSamples, startIdx, splitInput, 0, toCopy);
  57. startIdx += toCopy;
  58. remaining -= toCopy;
  59. byte[] compressedMic = null;
  60. compressedMic = encoder.Encode(splitInput);
  61. if (compressedMic != null && compressedMic.Length > 0)
  62. {
  63. onCompressedData(compressedMic);
  64. }
  65. } while (remaining > 0);
  66. }
  67. }
  68. }
  69. }
  70. }
  71. #endif