Change Contents of the Bubble
Welcome to CS1315. Click on the python to add comments.

Looking for the book? They have it at the Engineer's Bookstore at 748 Marietta St NW. Here is there website: http://www.engrbookstore.com/ - Monica

Hotspots: Slides and CodeTA CornerComments?AnnouncementsFAQStatic Webspace
View this PageEdit this Page (locked)Uploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Midterm Exam 2 Review Spring 2004: Sound Timing

Comments, answers, and questions go here:

(Link back to Sp2004 Midterm 2 Review)


(a)use getSamplingRate(sound) and multiply by 3. Is this correct? Kelli Webb


You may need int, too. Mark Guzdial


A) int(getSampleRate(snd)*2) would bring you right up the the beginning of the third second. multiplying by 3 would bring you to the fourth. right?
Arseni Zaitsev


Right – now, is anybody going to go after the PROGRAMS? Mark Guzdial


def spliceTest(sourceSound,targetSound):
  source = makeSound(sourceSound)
  target = makeSound(targetSound)   
  rate= getSamplingRate(source)
  targetIndex=int(2*rate)
  start=int(1*rate)
  end=int(1.5 * rate)
  for sourceIndex in range(start,end):  
    setSampleValueAt(target,targetIndex,getSampleValueAt(source, sourceIndex))
    targetIndex = targetIndex + 1
  play(target)	        
  return target



def swap(input):
   source=makeSound(input)
   target=makeSound(input)

   sourceIndex=getLength(source)
   for targetIndex in range (4,getLength(target)-2):
      sourceValue=getSampleValueAt(source, sourceIndex)
      setSampleValueAt(target,targetIndex,sourceValue)
      sourceIndex=sourceIndex+1
     
      return target



Are the above correct?

For the test we will have examples of a program to look at if we were asked questions like the last b) and c)??

So to be where the beginning of the 3rd second is, do we need to add a plus 1 to the equation?? Jennifer Garrett

Also, should the return target be part of the for loop like that? Or should it be lined up with source/target/source/for?

Return should come AFTER the loop, indented only one level in, else the program will stop after the first execution of the loop. Mark Guzdial


Mark, I was confused today in the study session:
The TA's said that to get the sample number for the beginning of the first second we do getSamplingRate(sound)(1.0-1), which makes sense. But does part b) ask for the first second of sound or for the samples one second into the sound, which would really be the beginning of the 2nd second, because it says to copy it to the target starting 2 seconds into the target sound which would really be the beginning of the third second. (maybe this problem just isn't written clearly because part c) makes sense).
I would appreciate it if you could clarify this. Thanks.Amanda Slaughter


def swap(input):
   source=makeSound(input)
   target=makeSound(input)

   sourceIndex=getLength(source)
   for targetIndex in range (4,getLength(target)-2):
      sourceValue=getSampleValueAt(source, sourceIndex)
      setSampleValueAt(target,targetIndex,sourceValue)
      sourceIndex=sourceIndex+1
      return target


In the above example that someone else posted, it doesnt make sense for Part C. It is supposed to be Copying seconds 4-5 to seconds 2-3. Why is it range(4,getLength(target)-2). Shouldnt it be range(4,6). Also, shouldnt sourceIndex be 2?

I'm having trouble reading through that program

def soundshit(source,target):
  source = makeSound(source)
  target = makeSound(target)

  targetindex = int(getSamplingRate(target)*2)
  for index in range(getSamplingRate(source), int(getSamplingRate(source)*(3/2)))
    setSampleValueAt(target, targetindex, getSampleValueAt(source, index))
    targetindex = targetindex+1
  
  return target

#---------------------------------------------
  
def soundshit2(inputsound):
  sound = makeSound(inputsound)
  target = makeSound(inputsound)
  rate = getSamplingRate(sound)

  start = int(rate*3)
  end = int(rate*4)
  
  targetindex = int(rate2)
  for index in range(start, end):
    value = getSampleValueAt(source,index)
    setSampleValueAt(target, targetindex, value)
    targetindex = targetindex + 1

  return target


There are getSamplingRate(sound) number of samples in a second. 2 * getSamplingRate is where the 2nd second of sound starts. Is it +1 or -1? I don't care, and you won't get marked off for it. We're talking about one sample, 1/22050 of a second (or 1/44100 of a second at CD-quality sound). Nobody will ever notice or care. Mark Guzdial




Link to this Page