IAudioEngine.d.ts 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import type { Observable } from "../../Misc/observable";
  2. import type { IDisposable } from "../../scene";
  3. import type { Nullable } from "../../types";
  4. import type { Analyser } from "../analyser";
  5. /**
  6. * This represents an audio engine and it is responsible
  7. * to play, synchronize and analyse sounds throughout the application.
  8. * @see https://doc.babylonjs.com/features/featuresDeepDive/audio/playingSoundsMusic
  9. */
  10. export interface IAudioEngine extends IDisposable {
  11. /**
  12. * Gets whether the current host supports Web Audio and thus could create AudioContexts.
  13. */
  14. readonly canUseWebAudio: boolean;
  15. /**
  16. * Gets the current AudioContext if available.
  17. */
  18. readonly audioContext: Nullable<AudioContext>;
  19. /**
  20. * The master gain node defines the global audio volume of your audio engine.
  21. */
  22. readonly masterGain: GainNode;
  23. /**
  24. * Gets whether or not mp3 are supported by your browser.
  25. */
  26. readonly isMP3supported: boolean;
  27. /**
  28. * Gets whether or not ogg are supported by your browser.
  29. */
  30. readonly isOGGsupported: boolean;
  31. /**
  32. * Defines if Babylon should emit a warning if WebAudio is not supported.
  33. * @ignoreNaming
  34. */
  35. WarnedWebAudioUnsupported: boolean;
  36. /**
  37. * Defines if the audio engine relies on a custom unlocked button.
  38. * In this case, the embedded button will not be displayed.
  39. */
  40. useCustomUnlockedButton: boolean;
  41. /**
  42. * Gets whether or not the audio engine is unlocked (require first a user gesture on some browser).
  43. */
  44. readonly unlocked: boolean;
  45. /**
  46. * Event raised when audio has been unlocked on the browser.
  47. */
  48. onAudioUnlockedObservable: Observable<IAudioEngine>;
  49. /**
  50. * Event raised when audio has been locked on the browser.
  51. */
  52. onAudioLockedObservable: Observable<IAudioEngine>;
  53. /**
  54. * Flags the audio engine in Locked state.
  55. * This happens due to new browser policies preventing audio to autoplay.
  56. */
  57. lock(): void;
  58. /**
  59. * Unlocks the audio engine once a user action has been done on the dom.
  60. * This is helpful to resume play once browser policies have been satisfied.
  61. */
  62. unlock(): void;
  63. /**
  64. * Gets the global volume sets on the master gain.
  65. * @returns the global volume if set or -1 otherwise
  66. */
  67. getGlobalVolume(): number;
  68. /**
  69. * Sets the global volume of your experience (sets on the master gain).
  70. * @param newVolume Defines the new global volume of the application
  71. */
  72. setGlobalVolume(newVolume: number): void;
  73. /**
  74. * Connect the audio engine to an audio analyser allowing some amazing
  75. * synchronization between the sounds/music and your visualization (VuMeter for instance).
  76. * @see https://doc.babylonjs.com/features/featuresDeepDive/audio/playingSoundsMusic#using-the-analyser
  77. * @param analyser The analyser to connect to the engine
  78. */
  79. connectToAnalyser(analyser: Analyser): void;
  80. }