CSC 161 Schedule Readings Labs & Projects Homework Deadlines Resources

Project: Program a Song

Overview

Working in pairs, you will develop a program song.c that makes the Scribbler 2 robot play a song or melody that lasts at least 30 seconds. Within the program, printed text will introduce the song (e.g. by title and composer). You may not use the songs from class examples or labs.

Details

Song Choice

You may work with a song that you have found elsewhere (giving appropriate credit), or you may create your own song. Creativity in identifying a song or melody is encouraged. You may not use any songs which have been used in examples or labs.

Song Introduction

Information (e.g., title and composer) about the song should appear in the opening program header AND printed to the terminal. If the song was written by someone else, the header should give a reasonably complete citation, while the printed introduction may be more concise.

Program Structure

Use a separate file to define the notes used in the song. For example, if the music utilizes a Western, well-tempered note pattern, the program might include scale-notes.h.

Note: Be sure to also submit any file other than song.c that may required for your program to work.

Music usually provides a structure for sound, and your program should reflect this structure. For example, many songs contain several verses with a refrain or chorus that is played after each verse.

Your program must contain at least 5 functions in addition to main. One of them should play the entire song.

Some functions should specify the notes (e.g., calls to rBeep) for smaller parts or phrases of the song. The beginning of each of these functions should include a print statement, so the workstation will display what part of the song is being played (e.g., "phrase 1", "line 1", "chorus", etc.).

At least one function should represent a collection of phrases or lines (e.g., "verse 1", "part 1", "entire song").

Of course, each function should include a descriptive header, indicating what part of the music is played by that function.

The main procedure should be reasonably short—just setting up the pieces (e.g., connecting to MyroC), calling one function to play the song, and wrapping up (disconnecting from MyroC).

Constants

In this project, you will call rBeep with many different values, for example:

rBeep (0.25, 698);
rBeep (0.125, 698);
rBeep (0.25, 698);
rBeep (0.25, 698);

However, this is not readable because these numbers appear to be magic. Why did we choose 0.25 and 698 as the arguments to rBeep? To make sense of these values and avoid repetition, we used "constants" to give these kinds of values names in scale-notes.h. You can do the same for note durations.

const double note8 = 0.125;
const double note16 = 0.0625;
Using these constants makes code more readable.
rBeep (note8,  pitchF5);
rBeep (note16, pitchF5);
rBeep (note8,  pitchF5);
rBeep (note8,  pitchF5);

You should use constants whenever appropriate in your program to make it more readable. When in doubt, if you have a "magic number" that has some additional meaning than just, e.g., 5, then you should enshrine that knowledge as a constant.

Grading

In addition to the general grading guidelines for evaluation, the project is worth 20 points.

A five point penalty will apply to any submission that includes personally identifying information anywhere other than the references/honesty file.