rdw-archive / WebClient

[Proof of Concept] Browser-based client capable of rendering networked multiplayer games using modern web technologies
1 stars 0 forks source link

Implement ``C_WebAudio.connectAnalyzer()`` functionality #138

Open Duckwhale opened 2 years ago

Duckwhale commented 2 years ago

Split off from #54 since it requires connecting an AudioAnalyzer widget, which is NYI.

The widget library is a huge mess, and I want to refactor it before adding even more stuff if at all possible.

Duckwhale commented 2 years ago

Actually, looks like BJS can draw a widget by itself:

var myAnalyser = new BABYLON.Analyser(scene);
BABYLON.Engine.audioEngine.connectToAnalyser(myAnalyser);
myAnalyser.drawDebugCanvas();

This may not be the best, but for debugging purposes it's likely sufficient.

Duckwhale commented 2 years ago

Confirmed that this is trivial:

image

However, it looks kinda bad (not a big problem). More importantly, it needs to be disabled also, so a separate API is required.

Also TBD: Can it be attached to just a single sound track, and can multiple analyzers be displayed simultaneously, so that each channel can be observed on its own?

Update: Yup, works as expected. See https://doc.babylonjs.com/divingDeeper/audio/playingSoundsMusic#using-the-analyser

So I guess it would make sense to have an API connectAnalyzer(trackID), and if the ID is omitted it just connects to the audio engine (visualizes all channels) instead of a given audio track.