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 PageUploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Fall 2006 Midterm 2 Review: Sound Coding

Post your questions here.

1.
def upDown():
  source=makeSound(sound)
  target=makeSound(sound)
  targetIndex=1
  half=(getLength(source)/2)+1

  for sourceIndex in range(1,half):
    value=getSampleValueAt(source,sourceIndex)
    setSampleValueAt(target,targetIndex,value*2)
    targetIndex=targetIndex+1

  for sourceIndex in range(half,(getLength(source)+1):
    value=getSampleValueAt(source,sourceIndex)
    setSampleValueAt(target,targetIndex,int(value/2))
    targetIndex=targetIndex+1

Don't forget to use code tags when you post your code! :) You have a few problems with this code, primarily in defining variables before you use them. 1.where do you define "value2" in the first for loop, or did you want value*2?2.where do you increase your targetIndex in the second loop?3.do you need to redefine value within the second loop? (hint, if you don't, you won't hear any sound)
4.Can you set a sample value to a sample that has a decimal place? (This deals with the division in the second loop) Amanda Bennett

whats the difference between using "sourceIndex" and "for sample in range"?


2.
def splice():
   source=makeSound(sound1)
   target=makeSound(sound2)
   r=getSamplingRate(source)
   r2=getSamplingRate(target)
   targetIndex=2*r2
   for s in range (r,.5*r):
     v=getSampleValueAt(source,s)
     setSampleValueAt(target,targetIndex,v)
     targetIndex=targetIndex+1
   return target


3.
def move():
  sound=makeSound(sound)
  sound2=makeSound(sound)
  r=getSamplingRate(sound)
  targetIndex=2*r
  for s in range(4*r,5r+1):
    v=getSampleValueAt(sound,s)
    setSampleValueAt(sound2,targetIndex,v)
    targetIndex=targetIndex+1
  return sound2






1.
def upDown (sound):
    for i in range (1, getLength (sound)/2):
       value=getSampleValueAt(sound, i)
       value=value*2
       setSampleValueAt(sound,i,value)
    for i in range (getLength(sound)/2,getLength(sound)):
       value=getSampleValueAt(sound, i)
       value=value/2
       setSampleValueAt(sound,i,value)
    return sound

Stacy Schwaiger

3.
def changeSound(sound):
    targetIndex=88200
    for i in range(176400,220500):
      value=getSampleValueAt(sound,i)
      setSampleValueAt(sound,targetIndex,value)
      targetIndex=targetIndex+1
    return sound

Stacy Schwaiger


2.
def pasteSound(sourceSound, targetSound):
  source=makeSound(sourceSound)
  target=makeSound(targetSound)
  targetIndex=44100
  for s in range(22051,33075):
    value=getSampleValueAt(source,s)
    setSampleValueAt(target,targetIndex,value)
    targetIndex=targetIndex+1
  return target

Jeffrey Wells

How do you know what ranges to use for number two and three?

Here's the right answer to the third question - Bobby Mathew
def sound3(sound):
  
  rate = getSamplingRate(sound)

  start = rate*4
  end = rate*5
  
  targetindex = rate * 2

  for index in range(start, end):
    value = getSampleValueAt(sound,index)
    setSampleValueAt(sound, targetindex, value)
    targetindex = targetindex + 1

  return sound


why did you multiply by 4 and 5 for the start and the end?



Link to this Page