Jump to content

Phaser and Audio Question


VizuaaLOG
 Share

Recommended Posts

Hello Phaser Users,

 

I have recently started using Phaser after buying Thomas Palef's Phaser book. I was just wondering if Phaser supports a way of interacting with the audio. What I want to try and do is have a tween occur when the audio has a low bass e.g. a bass drum. I wan't to have a kind of pulsing effect on the game when the music hits that part. Not sure if this can even be done is JS but ah well. :)

 

I also have experience with javascript so be as complex as you need :)

 

Thanks,

Tom

Link to comment
Share on other sites

Hi Tom,

 

I haven't had experience with doing this, but I have an interest in audio, so I took a quick look. I figured you'd need to do some kind of frequency analysis (fourier transform) on the audio, and that if anything was going to manage that, the Web Audio API would.

 

Sure enough, there is an AnalyserNode which can sit in the audio chain, analysing the frequencies, but otherwise leaving the audio alone. It has methods getFloatFrequencyData()/getByteFrequencyData(), which you'd need to call in a loop at whatever rate you choose to sample the audio at. There are various demos floating around that use this technique to create audio visualisations (graphic equalizers).

 

When the amplitude at your chosen bass frequency exceeds a certain threshold level, you'd be triggering your tween. The tricky bit might well be finding a suitable audio file with a clear enough bass frequency, then tuning your frequency analysis to pick that frequency up.

 

Note the limited browser support as described in the MDN link, above.

 

I haven't used Phaser before, but after a quick look through the documentation, I couldn't see any Phaser API for accessing this rather advanced audio functionality, which I figured would be the case. However, you should be able to create the AnalyserNode directly yourself without too much difficulty.

 

Would be interested if you manage to get this working - good luck!

 

Vince.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...