analyser.d.ts 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import type { Nullable } from "../types";
  2. import type { Scene } from "../scene";
  3. /**
  4. * Class used to work with sound analyzer using fast fourier transform (FFT)
  5. * @see https://doc.babylonjs.com/features/featuresDeepDive/audio/playingSoundsMusic
  6. */
  7. export declare class Analyser {
  8. /**
  9. * Gets or sets the smoothing
  10. * @ignorenaming
  11. */
  12. SMOOTHING: number;
  13. /**
  14. * Gets or sets the FFT table size
  15. * @ignorenaming
  16. */
  17. FFT_SIZE: number;
  18. /**
  19. * Gets or sets the bar graph amplitude
  20. * @ignorenaming
  21. */
  22. BARGRAPHAMPLITUDE: number;
  23. /**
  24. * Gets or sets the position of the debug canvas
  25. * @ignorenaming
  26. */
  27. DEBUGCANVASPOS: {
  28. x: number;
  29. y: number;
  30. };
  31. /**
  32. * Gets or sets the debug canvas size
  33. * @ignorenaming
  34. */
  35. DEBUGCANVASSIZE: {
  36. width: number;
  37. height: number;
  38. };
  39. private _byteFreqs;
  40. private _byteTime;
  41. private _floatFreqs;
  42. private _webAudioAnalyser;
  43. private _debugCanvas;
  44. private _debugCanvasContext;
  45. private _scene;
  46. private _registerFunc;
  47. private _audioEngine;
  48. /**
  49. * Creates a new analyser
  50. * @param scene defines hosting scene
  51. */
  52. constructor(scene?: Nullable<Scene>);
  53. /**
  54. * Get the number of data values you will have to play with for the visualization
  55. * @see https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode/frequencyBinCount
  56. * @returns a number
  57. */
  58. getFrequencyBinCount(): number;
  59. /**
  60. * Gets the current frequency data as a byte array
  61. * @see https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode/getByteFrequencyData
  62. * @returns a Uint8Array
  63. */
  64. getByteFrequencyData(): Uint8Array;
  65. /**
  66. * Gets the current waveform as a byte array
  67. * @see https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode/getByteTimeDomainData
  68. * @returns a Uint8Array
  69. */
  70. getByteTimeDomainData(): Uint8Array;
  71. /**
  72. * Gets the current frequency data as a float array
  73. * @see https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode/getByteFrequencyData
  74. * @returns a Float32Array
  75. */
  76. getFloatFrequencyData(): Float32Array;
  77. /**
  78. * Renders the debug canvas
  79. */
  80. drawDebugCanvas(): void;
  81. /**
  82. * Stops rendering the debug canvas and removes it
  83. */
  84. stopDebugCanvas(): void;
  85. /**
  86. * Connects two audio nodes
  87. * @param inputAudioNode defines first node to connect
  88. * @param outputAudioNode defines second node to connect
  89. */
  90. connectAudioNodes(inputAudioNode: AudioNode, outputAudioNode: AudioNode): void;
  91. /**
  92. * Releases all associated resources
  93. */
  94. dispose(): void;
  95. }