In this lab, we will learn the following computer science concepts:

Computer Science Principles Curriculum

Common Core Standards



This lab demonstrates the use of the Audio library in Quorum. The Audio library can be used to play music files in the ".ogg" or the ".wav" formats. You will write a program that plays a music file that can be shared with classmates. Download this "zip file" for a template to help you get started. To open the template, follow these steps:

1. Download and extract the zip file

2. Open NetBeans

3. Under File, click Open Project

2. Open NetBeans

4. Navigate to where you downloaded the zip file

5. Select your project and click Open Project

You may also use the online versions of the development environment to test your code. For this, we have stored the song file at media/song.ogg.

Goal 1: Accessing the Quorum Standard Library

Open the provided template and navigate to the main.quorum file.

This assignment makes use of the Quorum Audio Library in the Quorum Standard Library. You need to type code at the very top of the main.quorum file that lets Quorum know you want to use this library. Begin by typing the appropriate code to use the Quorum Audio Library in your project. The Audio Library is called Libraries.Sound.Audio.

Example: Tell Quorum we want access to Audio.

// this line tells Quorum we will use the Audio library
use Libraries.Sound.Audio

Any time you want to use a Quorum library, you need to include a statement like this at the top of your program code that lets Quorum know that you will be using that library.

In order to work with files, you also need to use the File library. The File library is called Libraries.System.File. Add a statement to your project that allows you to use the Quorum File library, below the other usestatement.

Activity: Add Statement

You now are able to use these Quorum libraries in your program.

Goal 2: Creating Objects

To put the Audio and File libraries to use, instantiate a new Audio object, calling it audio.

Example: Instantiate an Audio object.

// this creates an Audio object and calls it "audio"
Audio audio

Now, in order for the Audio object to be able to play your song, it needs the file that contains the song. Create a new File object, naming it file.

Activity: Instantiate a File object

In order to use the File object, you need to tell the File object what file it is. Since this file will represent the sound file for your Audio object, your file should be an audio file. Audio files save data that represents all the samples of a sound. The file formats that the Quorum Audio Library supports are ".ogg" or the ".wav" formats.

To set the name of your file, you use the SetPath action. The SetPath action takes a text parameter that represents the name of the file.

Example: Tell the File object the file path.

//This line of code sets the path in the file to media/song.ogg

Now that you have your file set up, you can now tell the Audio object what to do. The Audio object needs to load a file, the file you just set up! Use the Load action to give the Audio object the file you created in your program.

Example: Load the file to the Audio object.

//This line loads a file into the audio object

You are now ready to play your audio file. You can do this by calling the PlayUntilDone action for your Audio object. The PlayUntilDone plays your Audio object until it is done, ensuring that your program does not end until the audio file is done playing.

Activity: Call the PlayUntilDone Action

You can now run your program. There should be no errors, and your audio file should play. If your program does not compile, fix any errors and try again.

Goal 3: Calling Actions on Objects

When playing audio files, you may want the audio to play in only the right ear or the left ear. You can do this in Quorum by calling the SetBalance action on your Audio object.

The SetBalance action takes one parameter, a number . The values for this number can be between -1 and 1. Each has the following behavior:

0 is the default value for the balance of Audio objects. If you never call the SetBalance action, the audio will automatically play in both ears.

Example: Change the balance of your Audio object to the left ear.

// this line of code tells your audio object that its balance should be the 
// number you are passing to it.

Play around with the balance options by changing the parameter of the SetBalance action.

Activity: Change the Balance of your code to the right ear only

You can compile and run your program to hear the differences.

Next Tutorial

In the next tutorial, we will discuss Lab 2.5, which describes how work displaying an image in Quorum..


The music used for this lab is Beachfront Celebration by Kevin MacLeod (incompetech.com). Licensed under Creative Commons: By Attribution 3.0 License.