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: Re-splicing the splice

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

(Back to Fall2003 Midterm Review 2)






Why would you want to do that? "This is a This?" That just doesn't make sense.

It's just a challenge. You could want to move words in unusual ways if, for example, you were building the background vocals of a song. Mark Guzdial


def spliceTest():
  file = r"C:\JES\mediasources\thisisatest.wav"
  source = makeSound(file)
  target = makeSound(file)   # This will be the newly spliced sound
  targetIndex=40327       # targetIndex starts at the end of "a"
  for sourceIndex in range(1,7865): 
    setSampleValueAt(target, targetIndex,  getSampleValueAt( source, sourceIndex))
    targetIndex = targetIndex + 1
    for index in range(1,8500):		#get rid of "test"
       setSampleValueAt(target, targetIndex,0)
       targetIndex = targetIndex + 1

  play(target)	        
  return target

The first part looks good. But in your second "for" loop, why did you choose nest it? Why do you change to using "index" instead of "targetIndex"? And is that really the range you want to manipulate? Lauren Biddle

i'm not sure...it worked though?

But it probably took a LONG time to run. Mark Guzdial




I think this guy should take out the second nested for loop and add:

for source in range(48191,64512):
setSampleValueAt(target,index,0)
index = index + 1
but not nested. Is this right?

I think this is right, but the spacing is off.

i am very confused about the second part. I started with something like that:
for targetindex in range(48192, 64512):
setSampleValueAt(target, targetIndex, o)
targetindex=targetindex+1
Or should i set another target index, like
targetindex=48192
but then i dont know how to go from there. Does all this sound stupid? Please help.

Since there is no info about the starting index, and since there is no pause between "is" and "this," I copied it bottom-up.
def spliceTestreverse():
  file = getMediaPath("thisisatest.wav")
  source = makeSound(file)
  target = makeSound(file)

  tarIndex = 55770
  for sndIndex in range(7864,0,-1):
    setSampleValueAt(target,tarIndex,getSampleValueAt(source,sndIndex))
    tarIndex = tarIndex - 1
  index = tarIndex
  for tarIndex in range(index,40326,-1):
    setSampleValueAt(target,tarIndex,0)
  
  return target




works good.........

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


it actually ran pretty quickly. can someone explain why the first one is wrong?


def spliceTest():
  file = getMediaPath("thisisatest.wav")
  source = makeSound(file)
  target = makeSound(file)

  targetIndex=40328         
  for sourceIndex in range( 1, 7865): 
    setSampleValueAt(target, targetIndex,  getSampleValueAt( source, sourceIndex))
    targetIndex = targetIndex + 1
  
  targetIndex=48192
  for sourceIndex in range (1,55770-(40326+7865)): 
    setSampleValueAt(target,targetIndex,0)
    targetIndex = targetIndex + 1

  play(target)	        
  return target



Anytime you have nested for loops, things take a LONG time to run because each time a cycle in the first for loop is started, you have to go through the ENTIRE nested loop before you return to start the second cycle of the first for loop. I don't know if that makes any sense, so if you are still confused, come see me during my office hours on Monday: 2-3 2nd floor of the Student Center. Brittany Selden

I've noticed that using apostrophes (') when dictating pathnames instead of quotation marks (") denecessitates the usage of an r before the pathname.


No, that's not true. See below: Mark Guzdial
>>> print 'New line\n\tAnd tab'
New line
	And tab



can the second loop look like this?
for targetIndex in range(40327+7865,getLength(file)+1):
    setSampleValueAt(target,targetIndex,0)
play (target)
return target


Sure, why not? Mark Guzdial

But what about 'targetIndex=targetIndex+1' line in this loop above? Don't we need it?

def spliceTest():
file = getMediaPath("thisisatest.wav")
source = makeSound(file)
target = makeSound(file)
#remove test
for silenceIndex in range(40327,getLength(file)+1):
setSampleValueAt(target,targetIndex,0)
#copy this to end
targetIndex=40327
for sourceIndex in range(1,7865):
setSampleValueAt(target, targetIndex, getSampleValueAt( source, sourceIndex))
targetIndex = targetIndex + 1
play (target)
return target

For the second part of the program, where the rest of the word Test needs to be silent, does this make sense:

for targetIndex in range (48192,55770):
setSampleValueAt(target, targetIndex, 0)
targetIndex=targetIndex+1

?????


my for line in this code has some problem. help?
def spliceSound():
file = getMediaPath("gettysburg10.wav")
source = makeSound(file)
target = makeSound(file)
targetIndex =1
for sourceIndex in Range(1,2000):
sourceSampleValue = getSampleValueAt(source, sourceIndex)
setSampleValueAt(target, targetIndex,sourceSampleValue)
targetIndex = targetIndex+1
play(target)
return target

What's the problem? What's the error? Mark Guzdial

local or global name on for sourceIndex line

Don't capitalize range – Range() doesn't exist. Mark Guzdial




Link to this Page