Overview.
In this assignment, you will write a program to create a music visualizer using the
MinMax algorithm.
A music visualizer generates graphical effects that move and change in sync with audio playback,
adding life, color, and energy to the music.
The MinMax algorithm is a widely used method for creating such visualizations
and is used by platforms such as
SoundCloud,
Spotify, and
ffpmeg.
Digital audio.
We represent digital audio (such as streaming music) as a sequence of n
real numbers between –1 and +1.
Each value corresponds to the amplitude of the sound at a specific moment in time.
We refer to the entire sequence of values as an audio signal and
to each individual value as an audio sample.
MinMax algorithm.
The MinMax algorithm divides the audio signal into k groups
and associates a real number (between 0 and 1) with each group.
These k numbers are plotted as vertical bars. Here's how the
process works:
MinMax example.
Here is a tiny example with n = 12 samples and k = 3 groups.
Each group contains 4 samples.
In this example, n is a multiple of k,
so each group contains exactly n / k samples.
If n is not a multiple of k, each group contains
\(\lfloor n \, / \, k \rfloor\) samples.
For simplicity, we will ignore any leftover samples.
Your program.
Write a program MusicVisualizer.java
that takes two command-line arguments
(the name of an audio file and an integer k for the number of groups)
and produces a music visualizer using the MinMax algorithm,
as described above.
Additionally, as you process each audio sample in group i,
play it so that the visualization is synchronized with the audio playback.
Here are some sample executions:
~/Desktop/nifty> javac MusicVisualizer.java ~/Desktop/nifty> java MusicVisualizer tiny.wav 3~/Desktop/nifty> java MusicVisualizer PianoSonata11.wav 1000 ~/Desktop/nifty> java MusicVisualizer IHaveADream.wav 1000
Data files.
Here are a few audio files that you can use for testing. You are also encouraged to experiment with
your own audio files (in WAV format).
audio file description author source license tiny.wav for testing public domain PianoSonata11.wav Piano Sonata 11 Wolfgang Amadeus Mozart MusOpen public domain IHaveADream.wav I Have a Dream Martin Luther King Jr. Internet Archive public domain
Input and output libraries.
This assignment relies upon libraries from real-time audio playback and graphics.
In our course, we use the open-source libraries
StdAudio
and
StdDraw.
FAQ.
StdAudio
library is configured to play 44,100 samples per second,
ensuring automatic synchronization.
This assignment was developed by Kevin Wayne. Copyright © 2022–2025.