Overview.
Write a program to produce a music visualization like the following:
In this assignment, students implement a popular music visualization
algorithm known as MinMax.
The program reads an audio file, stores the audio samples in an array,
and then divides the array into k groups.
For each group, the program computes the maximum absolute value of a sample
and visualizes it as a vertical bar whose height is proportional to the absolute
value.
This produces a dynamic, real-time visual representation of the audio file,
synchronized with the audio playback.
Here are the main topics (and learning objectives) that the assignment covers:
Array manipulation and processing.
Write code to process large arrays. Divide up a large array into subarrays and compute
some statistic in each subarray.
MinMax algorithm.
Implement the MinMax algorithm for visualizing sound.
Digital audio representation.
Understand that digital audio can be modeled as an array of real numbers between –1 and +1.
Signal processing.
Write code to process and manipulate audio data.
Data visualization.
Generate a visual representation of numerical data by plotting bars.
AUDIENCE
CS1.
This programming assignment is intended for early use in a CS1 curriculum (or CSA or CSP),
when introducing arrays (in Java) or lists (in Python).
It appeals not only to computer science majors but also to students in other disciplines.
Initially developed for a summer bridge program for incoming college students
from disadvantaged socio-economic backgrounds,
the assignment proved so engaging that we subsequently adopted it into our main CS1 course.
DIFFICULTY
The soluition is easy to implement from scratch,
requiring only about 25 lines of array-processing code
(excluding comments and blank lines).
It appears as one of three independent exercises in a weekly
programming assignment focused on arrays and input/output.
STRENGTHS
This assignment is nifty because it blends algorithmic thinking, multimedia programming,
and real data to create a compelling music visualizer.
It offers a high reward-to-effort ratio.
Array-processing code.
The assignment reinforces key programming concepts like arrays and array-processing algorithms.
Implementing the MinMax algorithm requires careful iteration and indexing
into subarrays.
Interdisciplinary.
The assignment spans computer science, digital signal processing, and visual arts.
Students write code to transform raw audio data into a visually compelling artifact.
This reinforcing key concepts from these fields in an intuitive, creative, and enjoyable way.
Authenticity.
The MinMax algorithm is widely used in real-world applications, including
Spotify, Soundcloud, and ffmpeg.
Implementing the algorithm provides students with insights into how
real-world music visualizers operate, giving the assignment a high degree of authenticity.
Signal processing.
Students dive into signal processing by working directly with digital audio data,
gaining insights into how digital audio is stored and processed.
Data visualization.
The assignment emphasizes the importance of data visualization by
turning abstract audio data into clear and informative visual output,
a critical skill in computer science and other fields.
Immediate feedback.
The program produces a graphical visualization synchronized with audio playback.
This allows students to see and hear the results of their work in real time,
keeping them engaged and motivated.
Creative freedom.
Students are encouraged to experiment with different audio files,
including their own. This fosters creativity and makes
the project more personally enriching.
Ethics.
The use of different audio files leads naturally to
discussions about ethical issues surrounding copyright laws.
Broadly appealing.
The assignment appeals not only to computer scientists
but also to students in the natural sciences, engineering, and the social sciences.
WEAKNESSES
Debugging and autograding programs that generate audio or graphical output present
some special challenges to students and staff.
Debugging.
Students often make errors when calculating the subarray indices.
Such mistakes can be hard to detect in the graphical output.
We provide students with a few tiny audio files
that were specifically designed to identify such bugs.
Autograding.
Our autograder intercepts all calls to the audio and graphics libraries.
This enables the autograder to check programatically
what graphics would have been drawn to the screen and
which audio samples would have been sent to the sound card.
DEPENDENCIES
This assignment relies on two third-party libraries—one for playing audio samples
and one for drawing graphics.
Audio library.
It relies upon an audio library capable of reading sound files and playing audio samples in real time.
We use an open-source library from Sedgewick–Wayne,
which is available in both Java
and Python.
For Python, Jython Environment for Students
from Guzdial is a suitable alternative.
Graphics library.
It requires a graphics library that can draw lines (or rectangles).
We use an open-source library from Sedgewick–Wayne,
which is available in both Java
and Python.
For Java, the ACM Graphics Library from Roberts is a suitable alternative.
VARIANTS
There are numerous concrete and open-ended opportunities for
variation, innovation, and exploration.
Music visualization algorithm.
Use a different music visualization algorithm, such as Root Mean Square (RMS).
Compare different algorithms.
Stereo. Visualize the left and right audio channels separately.
Colors and shapes.
Incorporate multiple colors and different geometric shapes.
Frequency-based visualization.
Implement a Fast Fourier Transform (FFT) to analyze
the frequency components of the audio signal and
visualize frequency bands.
Interactive user interface.
Introduce a user interface that allows users to select the audio file
and specify the number of groups.
Beat detection.
Add a beat-detection algorithm to highlight rhythmic elements of the music,
allowing the visualizer to react to prominent beats.
Custom visual effects.
Design and implement visual effects, such as waveforms, particles,
or animations that respond dynamically to audio intensity or frequency changes.
Sliding window.
Display a sliding window of the audio signal, to support longer pieces of music.
As the music plays, the window shifts, updating to display only the current
portion of the track.
Data sonification.
Flip the task, where students generate audio from some non-audio data
(like stock prices or weather data) and visualize the resulting sound patterns.