slate: hw2

mic, jack, chuck, soundfiles, binaural soundfiles

Due 11:59pm on Wednesday, October 6 in the Homework Factory

Part Program Needed Files Needed Files to generate and/or Modify Notes
I. Overview
II. Using Jack and Testing the Quad Stations jack, miniAudicle (test setup) for quad station/ 4 channels
III. Using Your Mic to Record slates.wav jack, mic, Audacity slates.wav recording your voice as mono file
IV. Generating to play slates.wav in Quad jack, miniAudicle, Audacity slates.wav for quad station/ 4 channels
V. Converting 4-Channels to Binaural File, binauralSlates.wav jack, miniAudicle, SoX,, binauralSlates.wav to hear using headphones/ stereo
VI. Create hw2.html to Submit on HW Factory html editor (i.e. Word, OpenOffice), binauralSlates.wav hw2.html for homework factory submission

Note: Changes to this page from 10/6 has been marked as red

Additioanl Details: If working at a house linux computer via headphones on a Delta soundcard, you will still hear all four channels but they will be "hard-panned" left and right). Also, when working at any quad setup, in miniAudicle preferences, set output channels to 4 (miniAudicle:edit:preferences). If you go back to a stereo soundcard like a laptop, set it back to 2.

I. Overview

Since we're wired for 4-channel sound this quarter, you'll need to have a channel test tool for sanity's sake. The “slate” program consists of your voice saying. “front left, front right, rear left, rear right” or something to that effect. It's for testing the 4-channel stations (each time you start working).

You'll have 4 files total: a chuck program called “”, two soundfiles (“slates.wav” and “binauralSlates.wav”), and the web page that you turn in by placing it in your homework factory directory “hw2.html

IMPORTANT: If you're considering using your laptop for your homework, see wiki for instructions using the quad system, which includes a link to download drivers if you're using your laptop. Laptops will also need audacity, qjackctl, sox, and miniAudicle. If you do not want to go through the hassle of downloading and seeting up additional softwares, please use one of the CCRMA stations with the Quad system. Additionally, if using your laptop, you will also need to modify some of the file paths used in the provided chuck files. For more about laptop requirements, see footnote1

II. Using Jack and Testing the Quad Stations

At a quad station with your laptop (or at any of the house linux computer where you hear all four channels, even if they are via headphones) launch jack ("qjackctl &") and prepare its setup to be connected to the appropriate soundcard -- as specified by the interface that's selected all the way to the right with the `>' menu (choose "USB Audio") -- and running at 48kHz, 512 frames-per-period. (If working at a house linux computer via headphones on a Delta soundcard, you will still hear all four channels but they will be "hard-panned" left and right)

If you cannot fine the "USB Audio" option, or if sound comes out of headphones instead of the 4-channel system, make sure that the USB cable for the UA-101 interface is connected to the CCRMA machine, and also be sure that the "Digital In" button on the UA-101 interface is not pushed in (there shouldn't be a light blinking next to it).

Hit start. You're good if the GUI starts showing a changing computer status (otherwise, you will get a complaint popup). Sound is now live.

Download and open “" ( in miniAudicle. In miniAudicle preferences, set output channels to 4 (miniAudicle:edit:preferences). Adjust speaker levels for reasonable balance. If this is your first miniAudicle experience, you need to “start virtual machine” and then hit “add shred” ('+' icon). If a channel is missing, that will need to be fixed before proceeding. Quit miniAudicle.

III. Using Your Mic to Record slates.wav

Create a directory (new folder) for your work <user>/220a/hw2/ and plug in your mic into the first channel of the soundcard. Use audacity to record your voice as you name each loudspeaker in the quad setup. Check that audacity's preferences are set so that it is connecting its audio via jack and recording to a mono file. Remember to set your record quality to 48kHz / 16bit. Adjust the mic level knob to see good levels when you speak. Check for a strong level in the file but take care to avoid clipping. Save it as “slates.wav” (by going to File -->Export in Audacity) in your new directory. Check that it's sounding good. (Please do not use a built-in laptop microphone or built-in laptop audio input.)

IV. Generating to Play slates.wav in Quad

Two preliminary versions in chuck will get you to the final version of the program:

[STEP #1]

Play slates.wav from chuck in mono:

Just enter this into the miniAudicle editor and shred it ("+" on the miniAudicle editing window)

SndBuf snd0 => dac.chan(0); // connect a sndBuf to 1st speaker

"220a/hw2/slates.wav" =>; // play file from beginning

1::day => now; // stall for 1 day

Save as a file called “”.

[STEP #2]

Now play slates.wav from chuck in quad, all four channels together:

Extend the above to 4 SndBuf's each with a different name, each going to a different output channel; e.g., the second would be

... // copy first 2 lines from above code-block to have 1st speaker as channel 0

SndBuf snd1 => dac.chan(1); // 2nd speaker as channel 1

"220a/hw2/slates.wav" =>; // same file, to send to the buffer connected to channel 1

... // repeat for 3rd and 4th speakers

1::day => now; // stall for 1 day

(You can overwrite with this new code).


And now, play slates.wav from chuck in quad, each channel announced separately, by doing the following:

(1) after the beginning declarations, mute each Sndbuf, with e.g.,

snd0.gain(0.0); // mute by reducing gain to 0.0

(2) then make an infinite pattern by replacing the above line for stalling for 1 day with this loop:

while (true) // loop the following block


snd0.gain(1.0); // unmute snd0 by setting gain to 1.0

snd0.pos(28000); // play from position 28000 samples

63750::samp=>now; // stall for length of utterance

snd0.gain(0.0); // mute snd0

500::ms=>now; // stall for half second

// next channels...


Hint: These positions and lengths in samples can be measured directly in Audacity by right-clicking on the time measures that show at the bottom of the app. Set the format to read in samples. Make a copy of your completed it in your homework factory directory (~/Library/Web/220a/

V. Converting 4-Channels to Binaural File, binauralSlates.wav

Last thing is to convert the 4-channel sound file into a binaural file, which we can listen to via the web. This is a step which we'll repeat for all homeworks.

[STEP #1]

Download "" ( and open it in miniAudicle.

[STEP #2]

Make a copy of, naming it “”, and replace all dac.chan(n) references with Binaural.pssp[n] (where n = channel number).

Note the syntax difference between “()” and “[]” above...

[STEP #3]

Shred and then shred to hear it come out of 4 “psuedo speakers” in your headphones.

IMPORTANT (If using your laptop): You need to download 8 wave files from, and change the file path in (around line 18) to point to those files!

Note that you can shred (add/remove, "+"/"-") repeatedly, but you can only shred once, else the miniAudicle's console will complain that "class/type 'Binaural' is already defined in namespace 'global' ", and you have to restart miniAudicle...

[STEP #4]

Finally, if working from a laptop download "" from or if working from a house linux machine download "" from (These write into the most likely "scratch" directories).

(The previous direction used to read: Finally, download "" from

While playing the loop ( and, add shred of to capture the two headphone channels to two mono files.

Currently, will remove shred automatically after 10seconds. If you try to manually remove shred before that time is up, recordings will not be made. You can modify this default length of 10 seconds by changing the value chucked to the variable s, around line 8 of

IMPORTANT (if using your laptop): You may need to change the path for filename0 (around line 14) and filename1 (around line 16) of to where you want your two mono files to be saved.

[STEP #5]

From the miniAudicle console, copy the SoX command that prints after 10 seconds and paste that into a terminal to merge the two mono files into a stereo file. The idea is to write your files into a temporary directory. On a laptop, the directory should be /tmp but on a house linux machine it should be /zap.

Here's the laptop command: sox -M /tmp/chuckout-0.wav /tmp/chuckout-1.wav /tmp/merged-stereo.wav

Here's the house linux command: sox -M /zap/chuckout-0.wav /zap/chuckout-1.wav /zap/merged-stereo.wav

(The previous direction used to read: sox -M /tmp/chuckout-0.wav /tmp/chuckout-1.wav /tmp/merged-stereo.wav )

IMPORTANT (if using your laptop): (1) You will need to download SoX. (2) Then, when typing your sox command in the terminal, you'll also need to modify the paths for these two files as well as for merged-stereo.wav accordingly, as you've specified in STEP #4.

Rename /tmp/merged-stereo.wav (or /zap/merged-stereo.wav) to be “binauralSlates.wav” and copy into your homework factory directory (~/Library/Web/220a/

VI. Create hw2.html to Submit on HW Factory

Create “hw2.html” under your homework factory directory with your favorite .html editor (I use OpenOffice). In it, create links to both “” and “binauralSlates.wav”.

Phew... that's a lot of to accomplish but it means you're ready with the machinery for the quarter.

1The real-time binaural processing requires a hefty processor. Not all laptops that can run chuck can run something this heavy. At least a 2MHz processor in linux, for example. Later, we'll add a technique for calculating soundfiles but not in real time which will work for any CPU. Another potential problem is the directory structure involved in writing the binaural output. It expects to write into a “/tmp” directory which is common in Unix machines (linux and mac). On windows check that you can write to a directory with that name.