CS285 -- Lab 3: Guitar Simulator

-->Quiz 1
-->Lab 1
-->Lab 2
->Lab 3
-->Lab 4
-->Lab 5
-->Lab 6
->Electronic Submission
->Old Exams
->C++ Examples
->MSVC Info
->STL Help
->Book Errata
->Tentative Schedule
->Support Forum
->Course Policies


Fall 2002

Objectives Addressed

  • Understand and apply complex data structures and algorithms.
  • Use appropriate algorithms (and associated data structures) to solve complex problems.
  • Have a thorough understanding of the Standard Template Library.
  • Be able to use data structures in software design and implementation.
  • Be able to apply the STL in software design.


This assignment, inspired by a similar assignment by Timothy Snyder, was developed by Dr. Chris Taylor and is based on the Jaffe-Smith algorithm. (See D.A. Jaffe and J.O. Smith in: "Extensions of the Karplus-Strong Plucked-string Algorithm," Computer Music Journal, 7(2), 1983, pp. 56-67.


You are to write program with a command line interface that will generate .wav files. The command line options are as follows:

  • -rev infile.wav
    Should generate infileREV.wav which should be the infile.wav file in reverse. Any additional command line arguments should be ignored if this one is present.
  • -pluck outfile.wav
    Should generate a simulated guitar pluck using the Jaffe-Smith algorithm (described below). The frequency, length, and sampling rate of the pluck should be determined by the following parameters:
  • -freq frequency
    Specifies the frequency of the simulated guitar pluck sound. (Default: 262 Hz)
  • -len length
    Specifies the length of the sound. (Default: 2 seconds)
  • -samp samprate
    Specifies the sampling rate used. (Default: 11025 Hz)
  • -decay decrate
    Specifies the rate of decay (should be between 0 and 1). (Default: 0.99)


I would suggest making use of the utility classes developed by Dr. Fred DePiero for reading and writing .wav files. The classes and an example of how to use them are available from my examples webpage.

In your implementation of the -rev option, you are required to make use of the STL stack class. In your implementation of the -pluck option, you are required to make use of the STL queue class. The Jaffe-Smith algorithm is described below.

You may want to play with the -rev option on these two files: ominous.wav and cinema.wav.

Jaffe-Smith Algorithm

Information on the Jaffe-Smith algorithm (which is based on the Karplus-Strong algorithm) is available here. Here is pseudocode for the algorithm:

enqueue N random numbers between -1.0 and 1.0 into que1
enqueue one 0.0 into que2
repeat the following M times:
  data1 = que1.dequeue();  // Notice that this is not the correct
  data2 = que2.dequeue();  // function call for the std::queue class
  sample = decrate * (data1 + data2) * 0.5;
  write 32000*sample to .wav file (assuming 16 bit data)

where N = samprate/frequency and M = length*samprate.

Lab report (due 11:00pm, the day prior to week 6 lab)

Your report should include:

  • A discussion of how you approached the problem. This should contain a sufficient level of detail to convince your instructor that you were thinking as you worked on this assignment.
  • The Documented source code for your program.
  • A copy of IPreferPi.wav played backwards and a copy of the .wav file generated by the -pluck option with all default parameters. Be sure to follow your instructors instructions on how to submit support files.
  • A brief description of any problems you encountered or questions you have regarding the lab.
  • A discussion of how you worked together as a team.
  • A summary of your activity log indicating how much time you spent on the assignment (following the template provided in the lab3.xml template document). Please use the following categories:
    • Design
    • Coding
    • Debug (before you think it's working)
    • Test (after you think it's working)
    • Documentation
    • Other
  • Note: You should be working together the entire time on this project so your table should mainly contain "both" entries. If you both spent one hour debugging your code together, your activity log should indicate one hour (not two hours) was spent debugging.
  • Any suggestions you have for how the lab could be improved.

As with any report you submit, correct spelling and grammar are required. In addition, your report should be submitted electronically following the Electronic submission guidelines. (You may wish to consult the sample report before submitting your report.) Be sure to keep copies of all your files, in case something gets lost. It may be wise to keep a diskette backup as well.

Your grade will depend on quality of design, clarity of code and documentation, as well as whether your program produces the correct results. If you have any questions, consult your instructor.

© 2001-2002 Dr. Christopher C. Taylor Office: CC-27C Phone: 277-7339 Last Updated: Tue Oct 8 11:27:33 2002
I am responsible for all content posted on these pages; MSOE is welcome to share these opinions but may not want to.