Homework: Data Sonification
- Out: Oct 16, 2024 Wednesday
- Due: Oct 23, 2024 Wednesday
Manipulating Data in Spreadsheets
This assignment assumes familiarity with using spreadsheets for numerical data. Inputting, selecting, saving and plotting (charting).
Data Source
Choose a time series of interest, preferably from your own work.
Or scout for one from an online repository, like:
- data.gov (catalog)
- research.google (dataset search)
- math.ttu (texas tech math class)
- medium article (datasets for data analysis practice)
Two Directories
Two computer drive / file locations will be used below and for easy reference let's call them "cwd" and "hsd." Your "current working directory" (cwd) is where you do your work and can be on your own machine (laptop or dektop) or your account on CCRMA's desktops. The other is the "homework server directory" (hsd) which is the CCRMA server directory for your homework factory assignments. You've already configured and tested your hsd in hw0.
Demo Stages and Your Own Work
There are three stages for this homework -- each uploaded to the hsd, one after the other.
- chartAndSound sonifcation demo test.
- IDE-based sonification demo (replaces the chartAndSound demo).
- Your own sonification player built using the IDE (for completion of the assignment).
Objectives
- Building a synth with frequency, amplitude and timbre parameters from Chuck unit generators (UGens)
- Understanding data mapping functions and iteration in Chuck
- Establishing a workflow for editing and testing algorithms in webchuck
- Working locally in the cwd and posting results to the hsd
- Exploring data sonification
Key Results
- Synthesizer using one or more oscillator (or other sound producing) UGens.
- A data time series of your choosing performed by the synthesizer.
- Exploration of data mappings between the time series data and synthesis parameters.
- cwd and hsd code maintained in sync (same files on both).
- Final work uploaded to the hsd.
Browsers and Caches
Beware of browser caches where what you see is not up to date with what you've changed. For example, suppose you've made an edit but there's no effect in the browser from the change that was made to the file. The browser may still be hanging on to the earlier version when displaying the page. To force it to forget the older version, use the Ctrl + Shift + Delete command and confirm your intent to "clear" recent history. Then do a Ctrl + r to refresh the page. (On Mac, substitute Cmd for Ctrl in these commands.)
Work in your cwd
Download a copy of the hw1 demo to your cwd. Then, replicate it to the hsd so that it plays from the homework factory. Unlike hw0 in which you logged into CCRMA using ssh
to get started, this assignment can all be done while you're in a terminal operating in your cwd. It will use scp
in both directions, download and upload.
Open a terminal and cd
to the directory where you would like your cwd, just the way you created your hsd when completing hw0. Do the following on your own machine (laptop or dektop) or in your account on CCRMA's desktops:
cd <wherever_you_would_prefer>
mkdir 220a
cd 220a
Now, make a subdirectory under 220a called hw1
and then copy the data-sonfication files from the course code repository into hw1. After copying from the repo, list its contents.
mkdir hw1
scp -r USERNAME@ccrma-gate.stanford.edu:~cc/music220a/webchuck/data-sonification/* hw1
ls hw1
- for those using
zsh
for their terminal (particularly on some flavors of mac) please enclose the source in single quotes, like this
scp -r 'USERNAME@ccrma-gate.stanford.edu:~cc/music220a/webchuck/data-sonification/*' hw1
Check that there's an index.html
for running in browsers and a file with the data that it will sonify (the data is in .csv
format -- comma-separated values).
Your cwd is
220a
and it now contains the chartAndSound demo version ofhw1
First stage -- transfer the demo from your cwd to your hsd
Again, do an ls
and be sure you see the hw1
subdirectory. Then, copy this hw1 demo from your cwd to your hsd using scp
.
ls
scp -r hw1 USERNAME@ccrma-gate.stanford.edu:Library/Web/220a/
The above command requires substituting your CCRMA USERNAME (if your username is the same locally then you can elide
USERNAME@
Next, test that you can play the hsd version by going to the homework factory and testing the link for hw1. You may have to refresh the homework factory page a few times to see it as the server catches up. The version of hw1 that's displaying shows a graph of the time series and plays the sonification. This version is a placeholder which you'll be updating as you progress through the assignment.
Ok, to recap -- you've got a cwd with the necessary files. Those have been replicated to your hsd where it is now accessbile via the homework factory and has a link that can be shared and played from anywhere. Onward to updating the NOAA data to the latest.
Second stage -- get fresh data from NOAA and use the Webchuck IDE to sonify it
We're going to walk through
- downloading a time series data file from its source
- preprocessing the data file
- uploading the sonification code and data file into the IDE
- exporting the IDE project as a .zip file
- placing the exported project into your cwd hw1 using unzip
- transferring the cwd project to your hsd
- confirming it works in the homework factory
- Navigate to NOAA Carbon Cycle Greenhouse Gases Trends in CO2 and download the .csv file for Mauna Loa CO2 monthly mean data. The file name is co2_mm_mlo.csv and you'll want to put it in your cwd's hw1 subdirectory (in other words, into
220a/hw1
). - Change the file so that it contains only two columns: decimal date, average. This is best done in a spreadsheet editor. The file contains one row per month, each row having a
decimal date.
Theaverage
gives the monthly average of CO2 in PPM. Delete all other columns (before and after these), and also delete the rows above the one row that has the column names (the header). - Save the edited file (keeping the .csv format).
- Open the Webchuck IDE in a separate browser tab.
- Upload two files from your hw1 directory: the .csv file and sonify.ck.
- Hit "Start WebChuck" and then the green "play" button. The console on the bottom right will display max and min values and a sinusoid sound should play with it's frequency varying according to the CO2 values.
Export the entire Webchuck project into a .zip file by selecting File : Export to : WebChuck. The dialog box will ask for a title (which will be included in the .zip file name), author and a description. Save the exported .zip file to your cwd. Use the following unzip command to put the files into hw1
, and finally transfer to hsd (as was done above). Test from the homework factory.
ls
unzip -o NAMEOFPROJECTFILE.zip -d hw1
scp -r hw1 USERNAME@ccrma-gate.stanford.edu:Library/Web/220a/
The exported project will look different than your IDE session. What's produced is a fully-functional, stand-alone web page with just a "play" button.
Third stage -- sonify your chosen data using the IDE
- your time series data file should be in .csv format
- make sure it is two columns, X = time (or row number), Y = the variable of interest
- what are the X and Y ranges in your data and what is the data update rate?
- construct a synthesizer for the sonification, not just a SinOsc
- map the data to the synthesizer's parameters
- play it in real time
- export the .zip file as above, and transfer to your hw1 directory at CCRMA
- confirmi it works in the homework factory
For simplicity, stick to a file with either an integer or decimal date in the first column and a single floating point variable in the second column. If it has extra columns or rows, remove them as was done above for the CO2 demo. The first column could also just be the row number if not a date.
Things to think about: what is the span of time (or number of rows)? How long do you want the sonification to play for? What are the units of the variable you are sonifying and how would you map those to, for example, oscillator frequency?
Really Quick Tutorial - Chuck script
Let's break it down. What does this do?
SinOsc osc => dac;
SinOsc
is a class of oscillator and we're instantiating one of those and naming the instance,osc
dac
is a special UGen which is our sound output, aka digital-to-analog converter
osc
is wired todac
so we can hear the tone
But for how long? rows
is the number of data points in the time series.
ffor (0 => int i; i < rows; i++) {
...
10::ms => now;
}
The script completes after the last iteration. Total duration
= rows * 10ms
At each iteration the frequency of the oscillator gets updated.
osc.freq(val[i]);
Create a Composition
Once you have the synthesizer and have mapped the dataset, think about how the sound expresses the data. Try to draw out the character or the unique quality of a dataset. Or simply make some music with the material.
The simple example provided in the demo is monophonic
in that it only plays one "voice" at a time. The oscillator gain is by default set to the maximum amplitude -- 1.0. If adding more sound generators / oscillators that play at the same time, be sure to reduce gains, so that the total doesn't exceed the 1.0 maximum signal, otherwise clipping distortion will occur.
This a non-exhaustive list of variables for experimentation in monophonic
texture
- The number of sound generators
- The frequency, amplitude and timbre of the generator(s)
- Harmonic or amplitude relationships if using multiple generators
- Generator event timing can be made to depend on data value
Exploring polyphonic
textures
- Generator start times differ (staggered patterns)
- Each generator's tempo or event timing gets set differently (so generators' events aren't at the same time))
Optional -- I want my HW1 to show a chart like the chartAndSound demo (this involves a small amount of html code)
The file index.html
was generated by the IDE when you exported the project. It's contains the instructions that tell browsers how to display your interactive web page.
index.html
- overview
<head>
block- make it responsive for mobile devices
- include webchuck audio system and ACE editor for live code
- specify the live chuck code
- specify the time series file and give an internal name to the data
- define button press events
- title
<body>
block- author, project description
- play button
To display an image on the page, insert this line of html code after the description and before the play button. The image file should live in the same directory (in other words, in the hw1 directory). Change the name to correspond to your image file.
<img src="CO2-MLOfullRecord.png">
Save the edited index.html file in your cwd and scp hw1 again to the hsd. Refresh the browser page to see the chart displayed.