Benutzer-Werkzeuge

Webseiten-Werkzeuge


Seitenleiste

ws1617:the_art_of_music:protokolle:06

Dies ist eine alte Version des Dokuments!


2017-02-02:

Wir haben uns weiter mit der Visualisierung beschäftigt. Inzwischen existiert ein Programm, welches durch den Input von verschiedenen Frequenzen, Kreise, in Abhängigkeit der Frequenzen, ausgibt. Diese variieren in der Größe und haben unterschiedliche Farben.

#!/usr/bin/env python # -*- coding: utf-8 -*- # # test_moving_circles.py # # # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA. # # from future import division

import numpy as np import moving_circles from scipy.fftpack import * from moving_circles import Canvas, Circle from microlistener import MicroListener

# 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=[]

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) ###

def action(objects, event):

global z
print z[2048]/1000000.0
circ.set_radius(z[186]/1000000.0)	##1000 Hz (?)
circ2.set_radius(z[19]/10000000.0)	##100 Hz (?)
circ3.set_radius(z[1115]/50000.0)	##6000 Hz (?)
  #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) )

# 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)

circ = Circle(win, pos=(x1,y1),radius = 0.1, color=(1,0,0,0.5)) circ2 = Circle(win, pos=(x2,y2),radius = 0.1, color=(0,1,0,0.5)) circ3 = Circle(win, pos=(x3,y3),radius = 0.1, color=(0,0,1,0.5))

while True:

win.set_action(action, objects)
#print z[0]
win.run()
ws1617/the_art_of_music/protokolle/06.1486651513.txt.gz · Zuletzt geändert: 2017/02/09 15:45 von beate_jung-mint1997