Benutzer-Werkzeuge

Webseiten-Werkzeuge


ws1617:the_art_of_music:protokolle:09

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen gezeigt.

Link zu dieser Vergleichsansicht

Beide Seiten der vorigen Revision Vorhergehende Überarbeitung
Nächste Überarbeitung
Vorhergehende Überarbeitung
ws1617:the_art_of_music:protokolle:09 [2017/02/23 14:02]
cm.mint.2016
ws1617:the_art_of_music:protokolle:09 [2017/02/24 14:02] (aktuell)
cm.mint.2016
Zeile 1: Zeile 1:
 ====== 2017-02-23/​24:​ Blocktermin====== ====== 2017-02-23/​24:​ Blocktermin======
  
-02-23: Wir befinden uns in der Vollendung. Heute werden wir die Visualisierung weitestgehend beenden und uns auch mit der genauen musikalischen Umsetzung befassen. ​+**2017-02-23:** 
 +Wir befinden uns in der Vollendung. Heute werden wir die Visualisierung weitestgehend beenden und uns auch mit der genauen musikalischen Umsetzung befassen. ​ 
 + 
 +test-moving-circles b1207-beta defining new circles 
 + 
 +<code python>​ 
 + 
 +from __future__ import division 
 + 
 +import numpy as np 
 +import moving_circles 
 +import time 
 +from scipy.fftpack import * 
 +from moving_circles import Canvas, Circle 
 +from microlistener import MicroListener 
 +from random import randint, uniform 
 + 
 +# chose '​VISPY'​ or '​MATPLOTLIB'​ 
 + 
 +PREFERRED_BACKEND = '​MATPLOTLIB_WX'​ 
 + 
 +######################################################​ 
 +# One possible use case: 
 +# Use timer event of backend to change graphic objects. 
 +# Here 10 circles are created and a callback function 
 +# action(...) is registered to be called at each timer 
 +# event. 
 +######################################################​ 
 +###​micolistener###​ 
 +CHANNELS=2 
 +RATE=44100 
 +CHUNK=2**11 
 +z=[] 
 +last_values1 = (0,0,0) 
 +last_values2 = (0,0,0) 
 +last_values3 = (0,0,0) 
 +  
 +def micro_callback(in_data,​ frame_count,​ time_info,​status):​ 
 + global z 
 + y=np.array(np.fromstring(in_data,​dtype=np.short),​dtype=np.float) 
 + yf = fft(y) 
 + xf = np.linspace(0.0,​ (2.0*RATE), CHUNK/2) 
 + if CHANNELS==2:​ 
 + y=y.reshape((y.shape[0]//​2,​2)) 
 + else: 
 + y=y.reshape((y.shape[0],​1)) 
 + #print int(np.linalg.norm(y[:,​0])/​2000.)*'​*'​ 
 + z=np.abs(yf) 
 + return (in_data, status) 
 + 
 +listen=MicroListener(RATE,​CHANNELS,​CHUNK,​micro_callback) 
 +### 
 +l_kreise=[] 
 +def action(objects,​ event): 
 + starttime=time.time() 
 + global z, last_values1,​ last_values2,​ last_values3 
 + n = 50 
 + #print z[2048]/​1000000.0 
 + last_values1 = (last_values1[1],​ last_values1[2],​ sum(z[186:​186+n])/​(n*100000.0)) ##​1000 Hz (?) 
 + endtime=time.time() 
 + print starttime 
 + print endtime 
 +#​ last_values2 = (last_values2[1],​ last_values2[2],​ sum(z[19:​19+n])/​(n*1000000.0)) ##​100 Hz (?) 
 +#​ last_values3 = (last_values3[1],​ last_values3[2],​ sum(z[1115:​1115+n])/​(n*10000.0)) ##​6000 Hz (?) 
 +#​ circ.set_radius(sum(last_values1)/​3) 
 +#​ circ2.set_radius(sum(last_values2)/​3) 
 +#​ circ3.set_radius(sum(last_values3)/​3) 
 + #dt, elapsed = event.dt, event.elapsed 
 + #for i,circ in enumerate(objects):​ 
 + #    circ.move(0.7*dt*np.sin(elapsed*(i+1)),​ 0.7*dt*np.cos(elapsed*(i+1))) 
 + #    circ.set_color( (np.abs(np.sin(elapsed*(i+1))),​np.abs(np.sin(elapsed*2*(i+1))),​ np.abs(np.sin(elapsed*3*(i+1))),​0.3) ) 
 + '''​ 
 + i = 0.01 
 + for circ_temp in l_kreise: 
 + circ_temp.set_radius(i) 
 + i+=0.005 
 + '''​ 
 + 
 +last_alpha=0 
 + 
 +def WinkelPos(i,​alpha):​ 
 + global last_posx, last_posy, last_alpha 
 + #​last_alpha=0 
 + #​last_posx=0 
 + #​last_posy=0 
 + #Abstand konstant 0.1 
 + abstand=0.1 
 + if i==0: 
 + posx=0 
 + posy=0 
 + last_posx=posx 
 + last_posy=posy 
 + return (posx,​posy) 
 + else: 
 + posx=last_posx+(np.cos(last_alpha+alpha)*abstand) 
 +# print posx 
 + posy=last_posy+(np.sin(last_alpha+alpha)*abstand) 
 +# print posy 
 + last_alpha+=alpha 
 + last_posx=posx 
 + last_posy=posy 
 + return (posx,​posy) 
 + 
 + 
 +# create objects, register callback and start program.  
 + 
 +win = Canvas()  
 +objects = [] 
 + 
 +#for i in range(10):​ 
 +# circ = Circle(win, pos=(-0.6+0.05*i,​0),​ radius=0.1,​color = (1,​0,​0,​0.2)) 
 +#​ objects.append(circ) 
 + 
 +#​coordinates 
 +x1=0.0 
 +y1=0.25 
 +x2=-0.5/​np.sqrt(5) 
 +y2=-0.25/​np.sqrt(5) 
 +x3=0.5/​np.sqrt(5) 
 +y3=-0.25/​np.sqrt(5) 
 + 
 + 
 +for i in range(20):​ 
 + #​l_kreise.append(Circle(win,​pos=(randint(-400,​400)/​400,​randint(-400,​400)/​400),​ radius=0, color=(randint(0,​10)/​10,​randint(0,​10)/​10,​randint(0,​10)/​10,​0.2))) 
 + l_kreise.append(Circle(win,​pos=WinkelPos(i,​uniform(-np.pi/​2,​np.pi/​2)),​ radius=uniform(0.01,​0.1),​ color=(randint(0,​10)/​10,​randint(0,​10)/​10,​randint(0,​10)/​10,​0.2))) 
 +# print i 
 + 
 + 
 + 
 +#circ = Circle(win, pos=(x1,​y1),​radius = 0.1, color=(1,​0,​0,​0.2)) 
 +#circ2 = Circle(win, pos=(x2,​y2),​radius = 0.1, color=(0,​1,​0,​0.2)) 
 +#circ3 = Circle(win, pos=(x3,​y3),​radius = 0.1, color=(0,​0,​1,​0.2)) 
 + 
 +while True: 
 + win.set_action(action,​ objects) 
 + #print z[0] 
 + win.run() 
 +</​code>​ 
 + 
 +**2017-02-24:​** 
 + 
ws1617/the_art_of_music/protokolle/09.1487854934.txt.gz · Zuletzt geändert: 2017/02/23 14:02 von cm.mint.2016