Music Visualizer


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:

The height of each vertical bar corresponds to the maximum amplitude of the audio samples in that group. Taller bars represent louder sections of the music. This visualization captures the dynamic intensity of the music over time.


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.