Homework: Mixer

Turn it up.

For this homework, you're going to create an interactive command line mixer that allows you to open sounds, manipulate and play them.

As noted in lab, I sccrewed up and gave you started code with a number of homework elements already done. Oh well. I'm not going to change the homework, instead here's an opportunity for good learning process. You should do this:

  1. Finish the lab.
  2. Check out the HW repo, which doesn't have any of the extra stuff it's not supposed to have.
  3. Without looking at your lab, try to update the Wav class in the HW with the proper destructor, copy constructor and assignment operator. Test it by copying like we did in lab. If you get stuck, then look back at your lab.
  4. Try to complete each section of the HW, as specified below, on your own first. Use the code that I accidentally put into the lab for some of the audio effects as a reference only once you have thoroughly tried it on your own. Do not copy the code from the lab over! Try to study it and then re-implement yourself.
https://cssvn.utrgv.edu/svn_etomai/201720_2380/hw03_mixer/<your username>

Behold the list where I keep my WAVs

Create a list class, just like we've done before, that holds WAVs. It should make it easy to add new ones, remove them by position and access them by position. In order to avoid copying issues, I recommend that you make your list hold WAV pointers (WAV*) rather than the objects themselves. That way you're not copying the objects every time you move them in and out of the list. Linked-list or dynamic array both work fine as an underlying data store.

For minor extra credit, templates your list class. Good experience in any case.

As always, test in isolation to make sure your class works as expected before making things more complicated.

Interactivity

Make the basic user interface next. You can arrange the code into classes, methods and functions however you like.

The program should show a numbered list of sounds, followed by a command prompt. You can just hardcode the filenames of the .wav files into an array. Something like:

1: door
2: luke
3: boom
cmd> 

At the prompt, the user should be able to give the following commands (effects are discussed in the next section). Notice that the different commands have different arguments just like functions do.

  • play position: play the sound at that position (e.g. play 3)
  • delete position: delete the sound at that position and remove it from the list
  • reverse position name: create a new sound name by applying the reverse effect to the sound at that position. the new sound should be added to list with the specified name.
  • half position name: create a new sound name by applying the half_time effect to the sound at that position. the new sound should be added to list with the specified name.
  • double position name: create a new sound name by applying the double_time effect to the sound at that position. the new sound should be added to list with the specified name.
  • mix pos1 pos2 name: create a new sound name by applying the mix effect to the sounds at pos1 and pos2. the new sound should be added to list with the specified name.
  • echo position delay name: create a new sound name by applying the echo effect to the sound at that position with the specified delay. the new sound should be added to list with the specified name.

After executing any command, the program should show the list of sound files again.

Dealing with Command Arguments

Because the different commands have different numbers and types of arguments, you have to get the command name first, then based on that name get the correct number/type of arguments. For simplicity, assume that all name arguments are a single word with no spaces. Your program must be able to deal with invalid positions (i.e. it doesn't crash and lets the user know), but you can assume that the user will only type valid commands with the correct number of arguments, and type numbers where numbers are required.

The Fanciness

Each effect command must create a new sound and add it to the list. There are a couple ways to do this: you could copy a sound and then alter its samples, or you could create a new sound object and set its data. Either way, make sure you’re managing your memory and not altering the existing sounds. I already gave you a reverse method in the lab/starter code, so you have one point of reference.

Test the effectsin isolation! Just like the lab really, make a sound, apply an effect, see how it sounds. Make sure it still copies and destroys correctly.

Half Time

This effect speeds up the sound so that it takes half as long to play. To do this, you just skip every other sample value. This means you’ll end up with an array that’s half the size.

Double Time

This effect slows down the sound so that it takes twice as long to play. This means you’ll end up with an array that’s double the size, with every sample put in twice.

Mix

To mix two samples together, you just average their samples together, one by one. Which is freaky cool, that you actually hear the two sounds playing together. (Average instead of sum so that it doesn't get twice as loud).

Echo! (echo)

An echo is just mixing a sound with itself, delayed in time. Use the delay argument to indicate the number of samples by which to offset. 5000 creates an echo, while 1000 is more of a reverb.