Chapter 5. Analysis and Visualization
So far we’ve only talked about audio synthesis and processing, but that is only half of the functionality that the Web Audio API provides. The other half, audio analysis, is all about understanding what the sound that is being played is like. The canonical example of this feature is visualization, but there are many other applications far outside the scope of this book, including pitch detection, rhythm detection, and speech recognition.
This is an important topic for us as game developers and interactive application builders for a couple of reasons. Firstly, a good visual analyzer can act as a sort of debugging tool (obviously in addition to your ears and a good metering setup) for tweaking sounds to be just right. Secondly, visualization is critical for any games and applications related to music, from games like Guitar Hero to software like GarageBand.
Frequency Analysis
The main way of doing sound analysis with the Web Audio API is to
use AnalyserNodes. These nodes do not change the sound in any
way, and can be placed anywhere in your audio context. Once this node is
in your graph, it provides two main ways for you to inspect the sound
wave: over the time domain and over the frequency domain.
The results you get are based on FFT analysis over a certain buffer size. We have a few knobs to customize the output of the node:
fftSizeThis defines the buffer size that is used to perform the analysis. It must be a power of two. Higher values will result ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access