1 ENGI 2420 Structured Programming (Lab Tutorial 7) Memorial University of Newfoundland
ENGI 2420 – Structured Programming Lab Tutorial 7 2 Preferences in Eclipse Warning message “no newline at end of file” How to enable automatic newline insertion in Eclipse check Window -> Preferences -> C/C++ -> Editor -> Ensure newline at end of file when saving How to show line number in Eclipse check Window -> Preferences -> General -> Editors -> Text Editors -> Show line numbers
ENGI 2420 – Structured Programming Lab Tutorial 7 3 Assignment-7 Purpose of this assignment a filter to implement a fuzzbox effect on a sound (music) file or an echo effect Structure of C++ files - assign7.h (downloadable): contains the declarations for the functions - a7main.cpp (downloadable): main function that can be used as test code - assign7.cpp: contains your implemented functions (only submit this one via web-submit) - you may want to create your own test code in a separate.cpp file (do NOT submit your test code)
ENGI 2420 – Structured Programming Lab Tutorial 7 4 readSoundData int readSoundData(int snd[]) Read the sound data from cin and store it in snd, which can be assumed to be big enough for at least MAX_SND_SIZE (500000) samples. Return the number of samples read, if successful. If the number of samples input is invalid, then return 0
ENGI 2420 – Structured Programming Lab Tutorial 7 5 Data Format Must be strictly adhered to so that your program can interact with MMGood The data consists of a sequence of integers each on a separate line The first number is to be interpreted as the number of samples to follow (i.e., the size of the data), while the remaining numbers are the data
ENGI 2420 – Structured Programming Lab Tutorial 7 6 writeSoundData void writeSoundData(int snd[], int size) Output (to cout) the size samples in snd using the format described above
ENGI 2420 – Structured Programming Lab Tutorial 7 7 fuzzBox int fuzzBox(int snd[], int size, int clip) Clip the size samples in snd to a maximum amplitude (magnitude) of clip. Elements of snd whose magnitude is greater than clip should be set to clip or -clip appropriately, so as not to change the sample's sign. Return the number of samples that had their value changed.
ENGI 2420 – Structured Programming Lab Tutorial 7 8 fuzzBox Example: Initial value of the array clip = 100 Final value of the array
ENGI 2420 – Structured Programming Lab Tutorial 7 9 echoBox void echoBox(int snd[], int size, int delayTime) Add a delayed copy of the sound to the sound Example and the delay time is 2, then the final value of the sample will be
ENGI 2420 – Structured Programming Lab Tutorial 7 10 Running the Program Our main program uses a "program argument" to select the effect (fuzz or echo). 0 is for fuzz and 1 is for echo Windows: from the (windows) command line you launch your program as follows: C:\My Documents\courses\sp\workspace\A7>.\debug\A7 0 or C:\My Documents\courses\sp\workspace\A7>.\debug\A7 1 In Eclipse, you can use the "Run > Open Run Dialog..." command and then edit the "program arguments" to be either "0" or "1" to select fuzzBox or echoBox respectively
ENGI 2420 – Structured Programming Lab Tutorial 7 11 Running with MMGood MMGood is a java program that will execute your program on actual.wav files so you can hear them working Download mmgood.jar to your hard drive Download the sample.wav files: engage.wav and guitar.wav For windows –Download mmgood.bat and put it in the same directory –Double click on mmgood.bat For unix/linux/mac –Download mmgood.sh to the same directory –Make this file executable. –Execute the mmgood.sh file
ENGI 2420 – Structured Programming Lab Tutorial 7 12 Running with MMGood Once mmgood's main window has appeared, and you have compiled your project, you can –Load an input.wav file –Play the input.wav file
ENGI 2420 – Structured Programming Lab Tutorial 7 13 Running with MMGood –Select your assignment 7 executable. (It is in the Debug subdirectory of your project directory and, in Windows, its name will end with ".exe".) –Set the argument to be 0 or 1 –Run the executable –Wait patiently for your program to finish –Play the output sound
ENGI 2420 – Structured Programming Lab Tutorial 7 14 Running with MMGood –Wait patiently for your program to finish –Play the output sound