3
0

MicrophoneBus.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <AzCore/EBus/EBus.h>
  10. #include <IAudioInterfacesCommonData.h>
  11. namespace Audio
  12. {
  13. /**
  14. * Interface for connecting with a hardware Microphone device.
  15. * The pattern that should be used is as follows:
  16. *
  17. * InitializeDevice
  18. * StartSession
  19. * (Capturing Mic Data...)
  20. * EndSession
  21. * ...
  22. * (optional: additional StartSession/EndSession pairs)
  23. * ...
  24. * ShutdownDevice
  25. */
  26. class MicrophoneRequests
  27. : public AZ::EBusTraits
  28. {
  29. public:
  30. /**
  31. * EBus Traits
  32. */
  33. static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single;
  34. static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single;
  35. using MutexType = AZStd::recursive_mutex;
  36. /**
  37. * Initialize a hardware Microphone input device with the OS.
  38. * @return True if the Microphone was initialized without errors, false otherwise.
  39. */
  40. virtual bool InitializeDevice() = 0;
  41. /**
  42. * Shutdown the connection to the Microphone device.
  43. */
  44. virtual void ShutdownDevice() = 0;
  45. /**
  46. * Start capturing Microphone data.
  47. * @return True if the Microphone capturing session was started without errors, false otherwise.
  48. */
  49. virtual bool StartSession() = 0;
  50. /**
  51. * Stop capturing Microphone data.
  52. */
  53. virtual void EndSession() = 0;
  54. /**
  55. * Check if the Microphone is actively capturing data.
  56. * @return True if a capturing session has started and is running, false otherwise.
  57. */
  58. virtual bool IsCapturing() = 0;
  59. /**
  60. * Obtain the format set up for the mic capture session.
  61. * @return Configuration of the Microphone.
  62. */
  63. virtual SAudioInputConfig GetFormatConfig() const = 0;
  64. /**
  65. * Consume a number of sample frames from the captured data.
  66. * @param outputData Where the data will be copied to.
  67. * @param numFrames The number of sample frames requested.
  68. * @param targetConfig The configuration of the data sink (sample rate, channels, sample type, etc).
  69. * @param shouldDeinterleave Ask for a deinterleaved copy when in stereo: [LRLRLRLR] --> [LLLL, RRRR]
  70. * @return The number of sample frames obtained.
  71. */
  72. virtual AZStd::size_t GetData(void** outputData, AZStd::size_t numFrames, const SAudioInputConfig& targetConfig, bool shouldDeinterleave) = 0;
  73. };
  74. using MicrophoneRequestBus = AZ::EBus<MicrophoneRequests>;
  75. } // namespace Audio