Sie sind auf Seite 1von 2

EE285 Lab Report Lab # 3 Section: A 1 -- Overview In lab 3 we were to write a program in C that displays the frequencies of the

musical scale (A-G with sharps and flats). We were to incorporate user interaction and accurate frequencies. In my code I used loops and 'if' statements to make it more fluent and usable. 2 -- Design High Level Components Number Name 2.1 Input 2.2 Compute Frequency 2.3 Generate Waveform 2.4 Output Waveform 2.1 Input The user will be prompted for the following: Note letter (A single character between A and G inclusive) Flat, sharp, or none indicated by (b, #, or space) Octave Number: An integer (0-8) Example inputs: Ab3 G5 This is implemented as a scanf in the main function. 2.2 Compute Frequency The formula for frequency is on the website provided. All that had to be done was implement variables and constants. The variables are that which were scanned in for the input (2.1note letter, flat/sharp/natural and octave number). These had to be passed to my function (calcFreq) so that it outputted the proper frequency. I made the constants (#define) sample rate, the base in the frequency formula ('2^(1/12)') and the duration. Describe the Functionality Get a Note from the user Given a note, compute the frequency in Hz Given a frequency computed in 2.1, calculate the points of the wave form for the tone. Output the waveform points from 2.3 in a suitable format to be played. Name: Kyle Shearer Lab Partner: Chase

2.3 Generate Waveform Generating a waveform was just another formula to be used (though not in a separate function). I didn't use it in another function because of the required format for the sound producing

program. I made a for-loop to print out the sine wave as it progressed along (44000 points a second). 2.4 Output Waveform Outputting the waveform was a formatting problem. All that was required was to match what was given so that the program that produces the sound can understand it. Configuring the printf statements was what had to be done. 3 -- Deliverables (Code, Output, Answers to Questions in Lab Writeup, etc.)

4 -- Testing To ensure my system worked I compiled it and fixed anything improper. I did this throughout the creation of my code so that I could pinpoint any mistakes as I went along. That made it relatively easy to keep it bug free until the end. After that I ran it to see if it did what I had planned (it didn't most of the time) and fixed any errors that the compiler didn't catch (my bad programming). When everything seemed to be running properly I tested every element of the code (assignments, functions, output and outputting the wave form). It is running as it should now! 5 -- Comments on Lab I had a bit of trouble with significant figures until I made my integers into floats (I had integers in my frequency equation at first so some of the output was .1 hz off). Also there were a couple hiccups in how things were scanned in. I had to insert a space after the first in 'scanf(&f,...' for it to ask for both the note and the sharp/flat/natural how I wanted it to. Also making it look good was a bit challenging; figuring out where the new lines needed to be was tricky. The hardest part for me was definitely finding a formula the accommodates the mixed patterns the musical scale presents. I found using true-false (0 or 1) statements to be very useful (I hope this is a legitimate practice). I'm learning new syntax every day and every time I work in C. I know it's writing little programs like this that help mature my programming/problem solving abilities and prepare me for my engineering future. Improvements are hard to suggest for this lab; I think a more restrictive starting point would be nice. But that would take away some of the challenges it presents. I was informed after I finished my code the first time that I had to do it differently (so the previous statement stands). I changed it fairly easily using ASCII values and a long formula compensating for the changing pattern in note scale increments (B-C, E-F).

Das könnte Ihnen auch gefallen