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 Fall 2003: Rewrite the Splice

Answers? Comments? Questions on Answers? Questions on Comments?

(Back to Fall2003 Midterm Review 2)



part A doesn't make any sense. could someone reword it?


are we suppost to be putting the target into the sound?


In all three versions, you're going from source to target. In the given program, the sourceIndex is being used as the index variable for the for loop, and targetIndex is incremented (added one to) in the body of the loop. Do the EXACT same splice, but reverse that – put the targetIndex as in the index variable in the for, and increment the sourceIndex. Mark Guzdial

b.
def spliceTest():
  file = getMediaPath("thisisatest.wav")
  source = makeSound(file)
  target = makeSound(file)
  sourceIndex = 40327
  for targetIndex in range(1,15443):
    setSampleValueAt(target,targetIndex,getSampleValueAt(source,int(sourceIndex)))
    sourceIndex = sourceIndex + 2
  play(source)
  return(source)

Where did you get these numbers from? Mark Guzdial

sorry the tabs didn't show up but you get the idea


def spliceTest():
  file = getMediaPath("thisisatest.wav")
  source = makeSound(file)
  target = makeSound(file)
  sourceIndex = 40327
  for targetIndex in range(1,15443):
      setSampleValueAt(target,targetIndex,getSampleValueAt(source,int(sourceIndex)))
       sourceIndex = sourceIndex + 0.5
  play(source)
  return(source)

If the above one is right, the bottom one can't be right. You can't cover the same range in the target if you have twice as many samples in one program than in the other. Mark Guzdial

that was part C


def spliceTest():
  file = getMediaPath("thisisatest.wav")
  source = makeSound(file)
  target = makeSound(file)
  sourceIndex = 40327
  for targetIndex in range(1,getLength(target)+1):
    setSampleValueAt(target,targetIndex,getSampleValueAt(source,int(sourceIndex)))
    sourceIndex = sourceIndex + 1
  play(source)
  return(source)



that was part A


a.def spliceTest():
    file = getMediaPath("thisisatest.wav")
    source = makeSound(file)
    target = makeSound(file)
    sourceIndex = 40327
    for targetIndex in range(1,55770-40327):
      sourceSampleValue = getSampleValueAt(source,sourceIndex)
      setSampleValueAt(target,targetIndex,sourceSampleValue)
      sourceIndex = sourceIndex + 1
    play(target)
    return target

b. def spliceTest():
   file = getMediaPath("thisisatest.wav")
   source = makeSound(file)
   target = makeSound(file)
   targetIndex = 1
   for sourceIndex in range(40327,55770):
     sourceSampleValue = getSampleValueAt(source,sourceIndex)
     setSampleValueAt(target,targetIndex,sourceSampleValue)
     targetIndex = targetIndex + 2
   play(target)
   return target

c. def spliceTest():
    file = getMediaPath("thisisatest.wav")
    source = makeSound(file)
    target = makeSound(file)
    targetIndex = 1
    for sourceIndex in range(40327,55770):
      sourceSampleValue = getSampleValueAt(source,sourceIndex)
      setSampleValueAt(target,int(targetIndex),sourceSampleValue)
      targetIndex = targetIndex + 0.5
    play(target)
    return target



On C I think you have to have 'targetIndex = int(targetIndex + 0.5) don't you?

No, if you do that it will stay the same every time - the int(targetIndex) in the setSampleValue line takes care of it.

c)
def spliceTest():
  file = r"C:\Documents and Settings\Christen\My Documents\JES\mediasources\thisisatest.wav"
  source = makeSound(file)
  target = makeSound(file)   # This will be the newly spliced sound
  targetIndex=1         # targetIndex starts at the beginning
  for sourceIndex in range( 40327, 55770):  # Where the word "Test" is in the sound
    setSampleValueAt(target, targetIndex,  getSampleValueAt( source, sourceIndex))
    targetIndex = targetIndex + 1
    setSampleValueAt(target, targetIndex,  getSampleValueAt( source, sourceIndex))
    targetIndex = targetIndex + 1
  play(target)	        #Let's hear and return the result
  return target


this one works for me b/c i tried something similar to the part c. above and it didnt work for me, i was copying each sample to the same targetIndex twice

should you add .5 or 1 to the targetIndex?

for b, isn't this one like the remixing the recipe questoin, and we should put a ,2 after the range to make it half as long?

You can do it that way (adding ",2" in the sourceIndex range) or you can increment your targetIndex by .5 - either way sounds like it will work to me! How would you go about doubling the size of test? Brittany Selden

if we add ,2 to the source index to take up half as much space, then can we add .5 to the sourceIndex to double the length?

Yuppers. Skipping every other sample shrinks the sound by half. Taking every sample twice doubles the size of the sound. Mark Guzdial




Link to this Page