DEPARTMENT OF COMPUTING

CS 3005: Programming in C++

Envelope Classes

Introduction

Envelopes are used in audio synthesis to control the volume of a sound over time. For example, a sound may start out loud, then become quieter over time. Or it may take time to reach full volume.

Audio designers will try many different envelope shapes to create different sounds.

A simple envelope shape is the “Attack/Decay” (AD) envelope. In this envelope style, the volume initially increases from 0 to the maximum. It then decays to 0.

AD-args-envelope.png

A common envelope shape is the “Attack/Decay/Sustain/Release” (ADSR) envelope. In this envelope style, the volume initially increases from 0 to the maximum. It then decays to an intermediate (sustain) level. Next, it stays at this level for some sustain duration. Finally, it decays to 0 (release).

ADSR-args-envelope.png

You may notice that the AD envelope is a simplified form of the ADSR envelope.

Assignment

In this assignment, you will create a class hierarchy to represent the functionality of an envelope, including specialization for the ADSR and AD envelopes.

The Envelope class will be a base class. ADSREnvelope will inherit from Envelope. ADEnvelope will inherit from ADSREnvelope.

You will also create a simple program that generates an envelope and displays its amplitudes as text. In a future assignment, you’ll use the envelopes together with waveforms to generate sounds.

A sample interaction with the program may look like this:

$ ./program-envelope-test/envelope_test 
Samples/Second: 10
Seconds: 1.0
Envelope style: ADSR
Maximum amplitude: 0.75
Attack seconds: 0.2
Decay seconds: 0.3
Release seconds: 0.4
Sustain amplitude: 0.25

sample_number,amplitude
0,0
1,0.375
2,0.75
3,0.583333
4,0.416667
5,0.25
6,0.25
7,0.1875
8,0.125
9,0.0625

Notice that the output is in CSV form, so you could plot it to produce images like shown above.

This example demonstrates a user giving an invalid envelope style.

$ ./program-envelope-test/envelope_test 
Samples/Second: 10
Seconds: 1.0
Envelope style: USPS
Maximum amplitude: 0.8
Envelope style 'USPS' is not known.

sample_number,amplitude
0,0
1,0
2,0
3,0
4,0
5,0
6,0
7,0
8,0
9,0

Computing Envelopes

See Additional Documentation below for examples of computing the envelope phase positions and amplitudes.

Programming Requirements

Create library-envelope/Envelope.{h,cpp}

Envelope Class

Data Members:

The Envelope class should contain data members to track the following information. These data members should be protected or private. They are not allowed to be public.

public Methods:

Create library-envelope/ADSREnvelope.{h,cpp}

ADSREnvelope Class

Publicly inherits from Envelope.

Data Members:

The ADSREnvelope class should contain data members to track the following information. These data members should be protected or private. They are not allowed to be public.

public Methods:

Create library-envelope/ADEnvelope.{h,cpp}

ADEnvelope Class

Publicly inherits from ADSREnvelope.

Data Members:

The ADEnvelope class does not define any new data members.

public Methods:

Create library-envelope/Makefile

This file must contain rules such that any of the following commands will build the libenvelope.a library:

This file must contain rules such that the following command will install the libenvelope.a library into the lib directory, and all .h files to the include directory:

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

Functions:

Create library-commands/envelope_test_aux.{h,cpp}

Functions:

Update library-commands/Makefile

Add envelope_test_aux.{h,cpp} in the appropriate places to add them to the library and install the header file.

Create program-envelope-test/envelope_test.cpp

Functions:

Create program-envelope-test/Makefile

This file must contain rules such that any of the following commands will build the envelope_test program:

Create program-envelope-test/.gitignore

The file program-envelope-test/.gitignore needs to store one line of text:

envelope_test

Update Makefile

Update the project-level Makefile so that make and make all in the project directory will call make install in the library-envelope directory, and make in the program-envelope-test directory.

Additional Documentation

Grading Instructions

To receive credit for this assignment:

Extra Challenges (Not Required)

TBA

Last Updated 02/28/2025