Return to Snippet

Revision: 51694
at October 13, 2011 07:33 by Cano0617


Updated Code
# Autthors: Gurkirat, Addison
# Due Wednesday October 12th
import sound 
import time

def rem_vocals(snd):
    #Return a copy of sound with vocals removed
    
    new_snd = sound.copy(snd)
    for sample in new_snd:
        left = sound.get_left(sample)
        right = sound.get_right(sample)
        delete_vocals = (left - right)/2.0
        sound.set_left(sample,int(delete_vocals))
        sound.set_right(sample,int(delete_vocals))
    return new_snd
def fade_in (snd, fade_length):
    #Return a copy of sound with the beginning faded. Number of samples faded is defined by fade_length
    
    '''Return original sound snd with selected number of samples faded in via new_snd'''  
    new_snd2 = sound.copy(snd)
    samps_to_fade = fade_length - 1
    #required due to samples starting at 0, not 1
    index = 0 
    for samp in new_snd2:
        index = sound.get_index(samp)
        if index <= samps_to_fade:
            fade_factor = 1.0 *index/fade_length
            #Tracks number of samples done, is also used as the fade factor
            left2 = (sound.get_left(samp))*fade_factor
            right2 = (sound.get_right(samp))*fade_factor
            sound.set_left(samp, int(left2))
            sound.set_right(samp,int(right2))
    return new_snd2 
def fade_out (snd,fade_length):
    #Return a copy of sound with the end faded. Number of samples faded is defined by fade_length
    
    '''Return original sound snd with selected number of samples faded out via new_snd'''    
    new_snd=sound.copy(snd)
    fade_point= len(snd)-fade_length-1
    #where to start fading
    samp_todo = fade_length 
    #tracks the number of untouched samples
    fade_factor=1.0
    samp_index=0
    for samp in new_snd:
        samp_index=sound.get_index(samp)
        if samp_index>=fade_point: 
            # if we have reached the point to begin fading,then below
            if samp_index == len(snd)-1:
                fade_factor = 0
                #if at last sample, fade factor is set to zero
            fade_factor= ((samp_todo*1.0)/fade_length)
            left = int((sound.get_left(samp))*fade_factor)
            right = int((sound.get_right(samp))*fade_factor)
            sound.set_left(samp, int(left))
            sound.set_right(samp,int(right))
            samp_todo-= 1
 
            #Tracks number of samples done,starts at one and ends at zero
    return new_snd
def fade(snd, fade_length):
    #Returns a copy of sound with the beginning and ending faded.Number of samples faded is defined by fade_legnth
    
    new_snd=sound.copy(snd)
    new_snd=fade_in(new_snd,fade_length)
    new_snd=fade_out(new_snd,fade_length)
    return new_snd
    '''Return original sound snd with selected number of samples 
    faded in and out via new_snd'''
    #new_snd = sound.copy(snd)
    #samps_to_fade_in = fade_length - 1
    #samp_todo = fade_length
    ##tracks the number of untouched samples
    #fade_point_fade_out= len(snd)-fade_length
    #index = 0 
    #fade_factor = 1.0
    #for samp in new_snd:
        #samp_index=sound.get_index(samp)
        #if samp_index <= samps_to_fade_in:
            #fade_factor = 1.0 *samp_index/fade_length
            #left2 = (sound.get_left(samp))*fade_factor
            #right2 = (sound.get_right(samp))*fade_factor
            #sound.set_left(samp, int(left2))
            #sound.set_right(samp,int(right2))
        #if samp_index>=fade_point_fade_out :
            #if samp_index == len(snd)-1:
                #fade_factor = 0
            #left = int((sound.get_left(samp))*fade_factor)
            #right = int((sound.get_right(samp))*fade_factor)
            #sound.set_left(samp, int(left))
            #sound.set_right(samp,int(right))
            #samp_todo-=1
            #fade_factor= ((samp_todo*1.0)/fade_length)
    #return new_snd
    
def left_to_right (snd, pan_length):
    #Returns a copy of sound with panning applied to it. Left starts at 0,right starts at max
    '''Return original sound snd with selected samples panned to the right
    and others to the left via new_snd'''
    new_snd= sound.copy(snd)
    samps_to_pan = pan_length - 1
    index = 0 
    fade_factor_left = 0.0
    fade_factor_right=0.0
    for samp in new_snd :
        if index <= samps_to_pan :
            left = sound.get_left(samp)
            right = sound.get_right(samp)
            avg= (left+right)/2.0
            fade_factor_left = ((index*1.0)/samps_to_pan)
            fade_factor_right= 1-fade_factor_left
            left = int(avg*fade_factor_left)
            right = int(avg*fade_factor_right)
            sound.set_values(samp,left,right)
            index+=1
    return new_snd

if __name__ == "__main__":
    snd = sound.load_sound("love.wav")
    #sound.play(snd) 
    #sound.play(rem_vocals(snd))
    #sound.play(fade_in(snd, 50000))
    #sound.play(fade_out(snd, 70000))
    #sound.play(left_to_right(snd, 500000))
    sound.play(fade(snd,50000))

Revision: 51693
at October 8, 2011 04:35 by Cano0617


Updated Code
# Autthors: Gurkirat, Addison
# Due Wednesday October 12th

import sound 
import time

def rem_vocals(snd):
    new_snd = sound.copy(snd)
    for samp in new_snd:
        left = sound.get_left(samp)
        right = sound.get_right(samp)
        delete_vocals = (left - right)/2.0
        sound.set_left(samp,int(delete_vocals))
        sound.set_right(samp,int(delete_vocals))
    return new_snd

def fade_in (snd, fade_length):
    new_snd2 = sound.copy(snd)
    samps_to_fade = fade_length - 1
    index = 0 
    fade_factor = 0.0 
    for samp in new_snd2:
        if index <= samps_to_fade:
            left = int((sound.get_left(samp))*fade_factor)
            right = int((sound.get_right(samp))*fade_factor)
            sound.set_left(samp, int(left))
            sound.set_right(samp,int(right))
            index += 1 
            fade_factor = ((index*1.0)/samps_to_fade)
    return new_snd \

def fade_out (snd,fade_length):
    new_snd=sound.copy(snd)
    fade_point= len(snd)-fade_length
    #where to start fading
    samp_todo = fade_length
    #tracks the number of untouched samples
    fade_factor=1.0
    samp_index=0
    for samp in new_snd:
        samp_index=sound.get_index(samp)
        if samp_index>=fade_point :
        # if we have reached the point to begin fading,then below
            left = int((sound.get_left(samp))*fade_factor)
            right = int((sound.get_right(samp))*fade_factor)
            sound.set_left(samp, int(left))
            sound.set_right(samp,int(right))
            samp_todo-=1
            fade_factor= ((samp_todo*1.0)/fade_length)
    return new_snd

def left_to_right (snd, pan_length):
    new_snd= sound.copy(snd)
    samps_to_pan = pan_length - 1
    index = 0 
    fade_factor_left = 0.0
    fade_factor_right=0.0
    for samp in new_snd :
        if index <= samps_to_pan :
            left = sound.get_left(samp)
            right = sound.get_right(samp)
            avg= (left+right)/2.0
            fade_factor_left = ((index*1.0)/samps_to_pan)
            fade_factor_right= 1-fade_factor_left
            left = int(avg*fade_factor_left)
            right = int(avg*fade_factor_right)
            sound.set_values(samp,left,right)
            index+=1
    return new_snd
        
if __name__ == "__main__":
    snd = sound.load_sound("water.wav")
    smpl_rate= sound.get_sampling_rate(snd)
    time_to_fade= float(raw_input("number of seconds to fade\n") )
    how_many_samples_fade = int(time_to_fade*smpl_rate)
    print "stuff"
    sound.play(left_to_right(snd,how_many_samples_fade))
    time.sleep(30)

Revision: 51692
at October 7, 2011 14:58 by Cano0617


Updated Code
# Autthors: Gurkirat, Addison
# Due Wednesday October 12th

import sound 
import time

def rem_vocals(snd):
    new_snd = sound.copy(snd)
    for sample in new_snd:
        left = sound.get_left(sample)
        right = sound.get_right(sample)
        delete_vocals = (left - right)/2.0
        sound.set_left(sample,int(delete_vocals))
        sound.set_right(sample,int(delete_vocals))
    return new_snd

def fade_in (snd, fade_length):
    new_snd2 = sound.copy(snd)
    samps_to_fade = fade_length - 1
    index = 0 
    fade_factor = 0.0 
    for samp in new_snd2:
        if index <= samps_to_fade:
            left = int((sound.get_left(samp))*fade_factor)
            right = int((sound.get_right(samp))*fade_factor)
            sound.set_left(samp, int(left))
            sound.set_right(samp,int(right))
            index += 1 
            fade_factor = ((index*1.0)/samps_to_fade)
    return new_snd \

def fade_out (snd,fade_length):
    new_snd=sound.copy(snd)
    fade_point= len(snd)-fade_length
    #where to start fading
    samp_todo = fade_length
    #tracks the number of untouched samples
    fade_factor=1.0
    samp_index=0
    for samp in new_snd:
        samp_index=sound.get_index(samp)
        if samp_index>=fade_point :
        # if we have reached the point to begin fading,then below
            left = int((sound.get_left(samp))*fade_factor)
            right = int((sound.get_right(samp))*fade_factor)
            sound.set_left(samp, int(left))
            sound.set_right(samp,int(right))
            samp_todo-=1
            fade_factor= ((samp_todo*1.0)/fade_length)
    return new_snd

        
if __name__ == "__main__":
    snd = sound.load_sound("water.wav")
    smpl_rate= sound.get_sampling_rate(snd)
    time_to_fade= float(raw_input("number of seconds to fade\n") )
    how_many_samples_fade = int(time_to_fade*smpl_rate)
    print "stuff"
    sound.play(fade_out(snd, 2))
    time.sleep(30)

Revision: 51691
at October 1, 2011 14:32 by Cano0617


Updated Code
'''
Created on 2011-09-30

@author: Gurkirat,Addison
'''
import sound 

def rem_vocals (snd):
    new_snd = sound.copy(snd)
    for samp in new_snd:        
        left = sound.get_left(samp)# both get left and right values are the same
        right = sound.get_right(samp)# so delete vocals is to zero,which mutes the enitre song
        delete_vocals = int((left - right)/2.0) #forgot to use int() set left does not accept decimals       
        sound.set_left(samp,delete_vocals)
        sound.set_right(samp,delete_vocals)
    return new_snd
if __name__ == '__main__':
    snd = sound.load_sound("C:/Users/Addison/Documents/Work/Computer Science/Test/src/love_novocals.wav")
    new_snd= sound.copy(rem_vocals(snd))#  okay you didn't quite assign a variable for this
    sound.play(new_snd)
    print "stuff" #just to verify the program actually ended due to the silence

Revision: 51690
at October 1, 2011 13:29 by Cano0617


Updated Code
'''
Created on 2011-09-30

@author: Gurkirat,Addison
'''
import sound 

def rem_vocals (snd):
    new_snd = sound.copy(snd)
    for sample in new_snd:
        left = sound.get_left(sample)
        right = sound.get_right(sample)
        delete_vocals = int((left - right)/2.0) #forgot to use int() set left does not accept decimals
        sound.set_left(sample,delete_vocals)
        sound.set_right(sample,delete_vocals)
    return new_snd
if __name__ == '__main__':
    snd = sound.load_sound("C:/Users/Addison/Documents/Work/Computer Science/Test/src/love.wav")
    new_snd= rem_vocals(snd)#  okay you didn't quite assign a variable for this
    sound.play(new_snd)# for whatever reason this doesn't play anything
    print "stuff" #all of our code looks fine

Revision: 51689
at October 1, 2011 13:26 by Cano0617


Initial Code
'''
Created on 2011-09-30

@author: Gurkirat,Addison
'''
import sound 

def rem_vocals (snd):
    new_snd = sound.copy(snd)
    for sample in new_snd:
        left = sound.get_left(sample)
        right = sound.get_right(sample)
        delete_vocals = int((left - right)/2.0) #forgot to use int() set left does not accept decimals
        sound.set_left(sample,delete_vocals)
        sound.set_right(sample,delete_vocals)
    return new_snd
if __name__ == '__main__':
    snd = sound.load_sound("C:/Users/Addison/Documents/Work/Computer Science/Test/src/love.wav")
    new_snd= rem_vocals(snd)#  okay you didn't quite assign a variable for this
    sound.play(new_snd)
    print "stuff"

Initial URL

                                

Initial Description

                                

Initial Title
Playing with Sounds

Initial Tags

                                

Initial Language
Python