DEPARTMENT OF COMPUTING

CS 3005: Programming in C++

Audio Track Creator (Additional Features)

Introduction

In the previous assignment, you created a program that creates an AudioTrack object and fills it with data, depending on the user’s choice. In this assignment, you will add additional choices for the form of data that can be added to an AudioTrack object.

The two options are sine and sawtooth waves. The sine wave is generated using the std::sin(angle) function from the C++ standard library. An angle must be computed that corresponds to a position on the horizontal axis of the graph.

Given sample_number (the position in the audio track), frequency (how quickly the wave changes), and samples_per_second (the sample rate)

Then: angle = (6.28 * sample_number * frequency) / samples_per_second

The following is a graph for samples_per_second = 1000 over a 1.23 second interval, at frequency = 10.0.

010_sine_test-render.png

A sawtooth wave also follows a periodic pattern. But, it has straight line edges, that produce a pattern that resembles the teeth of a saw. The

Given: sample_number (the position in the audio track, an unsigned int), frequency (how quickly the wave changes, a double), and samples_per_second (the sample rate, an int)

Then:

Even though frequency is a double, we want cycle_size to be an unsigned int. So, we assign the result of the division into cycle_size and intentionally discard any fractional part of the result. This is necessary because we want a discrete number of samples per cycle.

Now, when we compute j as an unsigned int, the % operator will work find with two integer types as operands.

Finally, amplitude is a double, that is computed from some float and some integer inputs. When (2.0 * j) is computed, j’s value is promoted to double to match the type of 2.0. When the division (2.0 * j) / (cycle_size - 1) happens, the numerator is a double because it’s the result of 2.0 * j. The denominator’s value will be promoted to double to match the type of the numerator. So, the overall computation results in a correct double value.

The following is a graph for samples_per_second = 23 over a 1.34 second interval, at frequency = 5.0.

011_sawtooth_test-render.png

Assignment

In this assignment, you will update the audio_track_creator program to allow the user to select sine or sawtooth wave data in addition to the ramp options that were made available in the previous assignment.

An example interaction with the program could look like this:

Samples/Second: 1000
Seconds: 1.23
Fill style: sine
Frequency: 10

sample_number,amplitude
0,0
1,0.0627587
2,0.12527
3,0.187287
...
1228,0.988864
1229,0.977574

Another example interaction with the program could look like this:

Samples/Second: 1000
Seconds: 1.23
Fill style: whammy
Fill style 'whammy' is not allowed.

Programming Requirements

Update library-application/ApplicationData.{h,cpp}

ApplicationData Class

Data Members:

public Methods:

Update library-commands/audio_track_creator_aux.{h,cpp}

Functions:

Additional Documentation

Grading Instructions

To receive credit for this assignment:

Extra Challenges (Not Required)

Last Updated 02/04/2025