Wednesday, December 31, 2014

Sound Mixture

                                                      Sound Mixture


The first program is related to basic signal processing. It has three different sound files like drum.wav, guitar.wav and bass.wav. In this project, first we will listen all three files in its originality. Then we will take the part of these sound files (from 10th seconds upto 20th second). I tried to incorporate two features here, first i tried to combine all the individual files into single and play all drum, guitar and bass together. Second, I tried to increase and decrease the level of individual file (like i want to increase the bass level and to decrease guitar level and want to keep drum level as it is) and then combined all modified files and then played it. Following is the step by step process to do.


Step 1: First we will read the sound files into Matlab (Sound files are of more than 1 minute)


[Bass, bass_Fs] = wavread ('G:\Second Semester\Pattern Recognition\sound\bass.wav');
[Guit, guit_Fs] = wavread ('G:\Second Semester\Pattern Recognition\sound\ guitar.wav');
[Drums, drums_Fs] = wavread ('G:\Second Semester\Pattern Recognition\sound \ drums.wav');
       
                                                      
Bass.wav

Guitar.wav


Drum.wav


Click below links to download Original Sound files

                                                                1-Bass
                                                                2-Guitar
                                                                3-Drum


Step 2 : I will create 1 frame(of 10 seconds) for each of these sound files and create it .wav file.

drum_seg = drums(drums_Fs*10 : drums_Fs*20);
wavwrite(drum_seg,drums_Fs,16,'drums_frame');

guit_seg = guit(guit_Fs*10 : guit_Fs*20);
wavwrite(guit_seg,guit_Fs,16,'guit_frame');

bass_seg = bass(bass_Fs*10 : bass_Fs*20);
wavwrite(bass_seg,bass_Fs,16,'bass_frame');

Fs = bass_seg = guit_seg = bass_seg;

Step 3 : Play Individual frame files by asking choice from the user.

prompt = 'what to play? Press '1' for drum, '2' for guitar, '3' for bass press '0' to end';
result = input(prompt);
while(result ~= 0)
if(result == 1)
      
        sound(drum_seg,drums_Fs);
  
elseif (result == 2)
      
        sound(guit_seg,guit_Fs);
  
elseif (result == 3)
      
        sound(bass_seg,bass_Fs);
end
prompt = 'what to play? 1 for drum, 2 for guitar, 3 for bass press 0 to end';
result = input(prompt);

end
Click below links to listen download generated 10 second frame.

1-Brass_frame
2-Guitar_frame
3-Drum_frame


Step 4 : Play all three sound frames ( drum, guitar, bass) together) is my first feature.

prompt = 'want to play all together? 1 for yes, 2 for no';
result = input(prompt);
if(result == 1)
    comp = drum_seg + guit_seg + bass_seg;
    sound(comp, Fs);
elseif (result == 2)
    disp(' ok no problem ');

end


Combined_Sound_Mixture


Click below links listen sound frames combined together.
Listen : Combine_sound_Mixture


Step 5 :  Increase or Decrease the level of sound files and play all together to feel different effect is my second feature.

prompt = 'want to increase bass or drum or guitar ? 1 for drum , 2 for guitar, 3 for bass';
result = input(prompt);
if(result == 1)
        prompt = 'howmuch to increase? enter x meanse x times';
        inc = input(prompt);
        drum_seg = drum_seg*inc;
elseif(result == 2)
        prompt = 'howmuch to increase? enter x meanse x times';
        inc = input(prompt);
        guit_seg = guit_seg*inc;
  
elseif (result == 3)
       prompt = 'howmuch to increase? enter x meanse x times';
       inc = input(prompt);
       bass_seg = bass_seg*inc;
end

prompt = 'want to decrease bass or drum or guitar ? 1 for drum , 2 for guitar, 3 for bass';
result = input(prompt);
if(result == 1)
        prompt = 'howmuch to increase? enter x meanse x times';
        dec = input(prompt);
        drum_seg = drum_seg*dec;
elseif(result == 2)
        prompt = 'howmuch to increase? enter x meanse x times';
        dec = input(prompt);
        guit_seg = guit_seg*dec;
  
elseif (result == 3)
       prompt = 'howmuch to increase? enter x meanse x times';
       dec = input(prompt);
       bass_seg = bass_seg*dec;

end

comp = drum_seg + guit_seg + bass_seg;
plot(comp);
sound(comp, Fs);

Click below to listen Sound_Mixture file in which bass level is increased 5 times and guitar level is decreased by 0.3 times.

1-Sound_Mixture_Effect












Friday, December 5, 2014

wikipedia

from turtle import Screen, Turtle, mainloop
from time import clock, sleep

def mn_eck(p, ne,sz):
    turtlelist = [p]
    #create ne-1 additional turtles
    for i in range(1,ne):
        q = p.clone()
        q.rt(150.0/ne)
        turtlelist.append(q)
        p = q
    for i in range(ne):
        c = abs (do / 2.0-i) / (do * .7)
        # let those ne turtles make a step
        # in parallel:
        for t in turtlelist:
            t.rt(200./ne)
            t.pencolor(1-c,0,c)
            t.fd(sz)

def main():
    s = Screen()
    s.bgcolor ("black")
    p=Turtle()
    p.speed()
    p.showturtle()
    p.pencolor("yellow")
    p.pensize(4)

    s.tracer(36,0)

    at = clock()
    mn_eck(p, 36, 19)
    and = clock ()
    = z1 and-at

    sleep(2)

    at = clock()
    while any([t.undobufferentries() for t in s.turtles()]):
        for t in s.turtles():
            t.undo()
    and = clock ()
    return "runtime: %.3f sec" % (z1+et-at)


if __name__ == '__main__':
    msg = main()
    print(msg)
    mainloop()









paint


#!/usr/bin/env python3
"""       turtle-example-suite:

            tdemo_paint.py

A simple  event-driven paint program

- left mouse button moves turtle
- middle mouse button changes color
- right mouse button toogles betweem pen up
(no line drawn when the turtle moves) and
pen down (line is drawn). If pen up follows
at least two pen-down moves, the polygon that
includes the starting point is filled.
 -------------------------------------------
 Play around by clicking into the canvas
 using all three mouse buttons.
 -------------------------------------------
          To exit press STOP button
 -------------------------------------------
"""
from turtle import *

switchupdown def (x = 0, y = 0):
    if pen()["pendown"]:
        end_fill()
        up()
    else:
        down()
        begin_fill()
     

changeColor def (x = 0, y = 0):
    global colors
    colors = colors[1:]+colors[:1]
    color(colors[0])

def main():
    global colors
    shape("triangle")
    resizemode("user")
    shapesize(3)
    width(20)
    colors=["green", "blue", "yellow"]
    color(colors[2])
    switchupdown()
    onscreenclick(goto,2)
    onscreenclick(changecolor,1)
    onscreenclick(switchupdown,3)
 
    return "Complete"

if __name__ == "__main__":
    msg = main()
    print(msg)
    mainloop()

Thursday, December 4, 2014


Round Dance





from turtle import *

def stop():
    global running
    running = False

def main():
    global running
    clearscreen()    
    bgcolor ("white") 
    tracer(False)
    shape("circle")  
    f =   0.793402
    phi = 9.064678
    s = 3
    c = 1
    # create compound shape
    sh = Shape("compound")
    for i in range(10):
        shapesize(s)
        p =get_shapepoly()
        s *= f
        c *= f
        tilt(phi)
        sh.addcomponent(p, (c, 0.25, 1-c), "black")
    register_shape("multitri", sh)
    # create dancers
    shapesize(1)
    shape("multitri")
    been ()
    setpos (0, -200)
    dancers = []
    for i in range(180):
        f (9)
        tilt(-6)
        pl (2)
        update()
        if i % 18 == 0:
            dancers.append(clone())
    home()
    # dance
    running = True
    onkeypress(stop)
    listen()
    cs = 1
    while running:
        a = -4
        for dancer in dancers:
            dancer.fd(9)
            dancer.lt (2)
            dancer.tilt(ta)
            ta = -4 if ta > 0 else 2
        if cs < 180:
            right(4)
            shapesize(cs)
            cs *= 1.005
        update()
    return "DONE!"

if __name__=='__main__':
    print(main())
    mainloop()