Categories
Uncategorized

Tutorial: Audio Analysis in Chuck

Although it is not directly relevant to my groups final project, I wanted to take advantage of an opportunity to apply the digital humanities to my own area of interest. I have recently become familiar with the computer music programming language Chuck, which has expanded my ability to understand how we think about the relationship between digital audio tools and music as a historical practice.

In this tutorial I will be covering the basics of how to apply unit analyzers to an audio file of your choosing. With the correct background knowledge, Chuck’s unit analyzers can offer an informative and technical view of various elements of an audio file. IN this case we will be looking at how to apply a Fast Fourier Transform to our data. This will allow us to take a waveform in real space (think of a sin wave) and covert it to data that can be expressed in frequency space (think different tones).

Note: the example I’m going through has been taken off of the Chuck documentation website. It is posted as a public example of how to use unit analyzers in Chuck.

Step 1: Download Chuck

Follow this link to get a list of the downloads. Once you have downloaded the correct executable for your operating system go ahead and double click the file to start the installation.

Step 2: Open Chuck

Chuck runs on a program called miniAudicle that is installed along with our initial download. Search for miniAudicle and open it.

Three windows will open up. One window should resemble a command line, the first window is called console and should resemble a command line. The second window is called miniAudicle and should resemble an empty text editor. The third window is called Virtual Machine. Go ahead and click the button on the bottom of this window that says Start Virtual Machine. This button will need to be clicked at the beginning of every session in Chuck for any of your future code to run

Step 3: Starting to Code

The first step in our coding process is to either load an audio file, or create a waveform that we want to transform. In this case we will be transforming a sin oscillator. We begin by typing into a blank document in the miniAudicle window.

The first line of code in the picture above initializes a sin oscillator called g, then initializes a Fast Fourier Transform object called fft. In the same line of code, the sin oscillator is passed into the FFT object and then passed into blackhole, which converts digital audio data into analog audio data, but does not return any sound.

The second line of code calculates the number of samples in a second. Chuck is a can easily compute units of time and the language comes with most units of time built in. In this case, we divide one second by the length of sample to get the number of samples per second. this is stored as a float in the variable srate.

The final line of code is used to set the size of our fft. Larger sizes generally correspond to more accurate frequency data, but are also more computationally intensive.

Step 4: Applying our Transformation

We are now going to get to the main block of code. Note that all of the text in green are comments and are not run as code.

We begin by initializing a integer variable called div. We then follow it with a while loop.

For the sake of this article, the contents of the while loop are not particularly relevant. We are essentially setting an updating the frequency of our oscillator at each iteration. We are also continually updating div based on the size of our fft object.

fft.upchuck() applies the transformation, the command on lines 20 and 21 prints out the complex polar coodinates that correspond to our frequencies. The final line of code advances the time in chuck by 100 ms.

Step 5: Running and Stopping a Script

We have now completed our script.

First, check to make sure that you have clicked the “start virtual machine” button in the virtual machine window. Then, click the green plus in the top right corner of the miniAudicle window to start the script. Data will be printed in the console.

To stop the script hit the red minus sign next to the replace shred button on the miniAudicle window.

Chuck has vast utility outside of Fourier Transforms, but I wanted to give an example of how we can use chuck to obtain mathematical data on sound. Although in this case we just looked at a sin oscillator, in theory we could apply this to any audio file. This method has potential to easily gather frequency data on any audio which in turn has vast potential for all kinds of academic research in music.

Leave a Reply

Your email address will not be published. Required fields are marked *

css.php