Analyze the amplitude of sound with p5.Amplitude.
Amplitude is the magnitude of vibration and is closely related to volume or loudness.
The getLevel() method takes an array of amplitude values collected over a small period of time (1024 samples) and returns the Root Mean Square (RMS) of these values.
Amplitude values for digital audio are typically between -1.0 and 1.0, however RMS will always be positive because it is ‘amplitude squared.’ Rrather than use instantanous amplitude readings that are sampled at a rate of 44,100 times per second, the RMS is an average over time (1024 samples, in this case), which better represents how we hear amplitude.
You might also experiment with analyzing a sound after a lowpass filter to make more complex visualizations.
Measuring Amplitude (Visualization): Edited and maintained by p5.js Contributors and Processing Foundation. Licensed under CC BY-NC-SA 4.0.
Related Examples

An image of sound waves rendered in p5.js.
Making a Beep
Creating tones with an Oscillator.

An image of sound waves rendered in p5.js.
Filtering Sound
Simulate the sound of waves and wind with white noise.

An image of sound waves rendered in p5.js.
Playing Melodies
Create melodic music using an array of pitch values.

An image of sound waves rendered in p5.js.
Echo Synth
Trigger a short sound with an echo effect.

An image of sound waves rendered in p5.js.
Sample Playback
Load a soundfile and change its properties.

An image of sound waves rendered in p5.js.
Measuring Amplitude (Visualization)
Analyze the amplitude of sound with p5.Amplitude.

An image of sound waves rendered in p5.js.
Visualizing Sound
Spectral analysis for audio-responsive animations.

An image of sound waves rendered in p5.js.
Connecting to ToneJS
Working with AudioContexts and cross-library synthesis.