# Differences

This shows you the differences between two versions of the page.

 cs190c:lab4_09 [2009/02/06 12:11]tang sdg cs190c:lab4_09 [2009/02/11 10:00] (current)seh Both sides previous revision Previous revision 2009/02/11 10:00 seh 2009/02/06 12:11 tang sdg2009/02/05 15:44 seh created 2009/02/11 10:00 seh 2009/02/06 12:11 tang sdg2009/02/05 15:44 seh created Line 70: Line 70: ===== In-Lab Problem ===== ===== In-Lab Problem ===== Write the required <​html><​code>​sin_sample​ function for the [[cs190c:​project1|project]]. Work in pairs, but turn in your own code on Blackboard (don't have just your partner turn it in). The only file you need to submit is primitives.py. Write the required <​html><​code>​sin_sample​ function for the [[cs190c:​project1|project]]. Work in pairs, but turn in your own code on Blackboard (don't have just your partner turn it in). The only file you need to submit is primitives.py. + + + def sin_sample(freq,​ amp, dur): + """​ + sin_sample(freq,​ amp, dur) + ​ + This function returns a sine wave with frequencey freq, amplitude amp, + and duration dur (in seconds). The smplitude should be specified + with a range of 0 to 1 where 1 represents the maximal amplitude. + + To obtain the actual amplitude in the sample use the WAVE_MAX value + to scale it to an appropriate value. + """​ + output = empty(int(dur*SAMPLE_FREQUENCY),​ dtype=numpy.int16) + factor = WAVE_MAX*amp + + for t in xrange(0,​len(output)):​ + output[t] = factor*math.sin(2*math.pi/​SAMPLE_FREQUENCY*freq*t) + + return output +