Esempio n. 1
0
def calc_heights(peak_heights, max_size, factor=1):
    ffted_array = impulse.getSnapshot(True)  # True = use fft

    l = len(ffted_array) / 4

    n_bars = len(peak_heights)

    lower_by = int(max_size / 15)
    if lower_by < 1:
        lower_by = 1

    for i in range(0, n_bars):
        fft_index = i * (l / n_bars)
        bar_height = ffted_array[fft_index] * max_size * factor

        if bar_height >= peak_heights[i]:
            pass
        else:
            bar_height = peak_heights[i] - lower_by

        if bar_height < 0:
            bar_height = 0

        if bar_height > max_size:
            bar_height = max_size

        peak_heights[i] = bar_height
Esempio n. 2
0
def calc_heights(peak_heights,max_size,factor=1):
	ffted_array = impulse.getSnapshot( True ) # True = use fft

	l = len( ffted_array ) / 4

	n_bars = len(peak_heights)

	lower_by = int(max_size / 15)
	if lower_by < 1:
		lower_by = 1

	for i in range(0, n_bars):
		fft_index = i * (l / n_bars)
		bar_height = ffted_array[fft_index] * max_size * factor

		if bar_height >= peak_heights[ i ]:
			pass
		else:
			bar_height = peak_heights[i] - lower_by

		if bar_height < 0:
			bar_height = 0

		if bar_height > max_size:
			bar_height = max_size

		peak_heights[i] = bar_height
Esempio n. 3
0
def updateWindow(window):
    global idleDelay
    if impulse.getSnapshot(True)[0] == 0:
        if idleDelay == 10: return True
        else: idleDelay += 1
    else: idleDelay = 0
    window.queue_draw()
    return True
Esempio n. 4
0
    def update (self):
        self.audio_sample_array = impulse.getSnapshot(True)
        self.redraw_canvas()

        if self.sound2light.active:
            self.sound2light.update(self.audio_sample_array)

        return True # keep running this event
Esempio n. 5
0
def drawFreq(widget, cr):
    global prev, screenWidth, barWidth, padding
    cr.set_source_rgba(rgbaColor[0], rgbaColor[1], rgbaColor[2], transparent)
    audio_sample = impulse.getSnapshot(True)[:128]

    raw = map(lambda a, b: (a + b) / 2, audio_sample[::2], audio_sample[1::2])
    raw = map(lambda y: round(-config["height"] * config["scale"] * y), raw)
    if prev == []: prev = raw
    prev = map(lambda p, r: delta(p, r), prev, raw)

    for i, freq in enumerate(prev):
        cr.rectangle(padding * i, config["height"], barWidth, freq)
    cr.fill()
Esempio n. 6
0
    def on_draw ( self, cr ):
        """In here we draw"""

        cr.scale( self.scale, self.scale )

        if not self.theme_module: return

        fft = False

        if hasattr( self.theme_module, "fft" ) and self.theme_module.fft:
            fft = True

        audio_sample_array = impulse.getSnapshot( fft )

        self.theme_module.on_draw( audio_sample_array, cr, self )
Esempio n. 7
0
def draw(window):
    h,w = window.getmaxyx()
    audio_sample_array = impulse.getSnapshot(True)
    i = 0
    l = len(audio_sample_array) / 4
    sum = 0
    step = l / ((w - 10) / 5)
    for x in range(3, w - 5, 5):
        value = audio_sample_array[i]
        bar(window, x, 3, h - 6 , value)
        sum += value
        i += step
            
    leds = 8 - min(8, int(sum * 2))
    wiringPy.digital_write_byte((0xFF * (2 ** leds)) & 0xFF)
Esempio n. 8
0
	def on_draw ( self, cr ):
		"""In here we draw"""

		cr.scale( self.scale, self.scale )

		if not self.theme_module: return

		fft = False

		if hasattr( self.theme_module, "fft" ) and self.theme_module.fft:
			fft = True

		audio_sample_array = impulse.getSnapshot( fft )

		self.theme_module.on_draw( audio_sample_array, cr, self )
Esempio n. 9
0
    def paint(self, canvas):
        if not self.theme_module: 
            return

        fft = False
        if hasattr( self.theme_module, "fft" ) and self.theme_module.fft:
            fft = True

        audio_sample_array = impulse.getSnapshot( fft )
        
        if self.backlight_acquisition is not None:
            self.backlight_acquisition.set_value(self._col_avg(audio_sample_array))
        
        if self.mkey_acquisition is not None:
            self._set_mkey_lights(self._tot_avg(audio_sample_array))
        
        canvas.save()
        self.theme_module.on_draw( audio_sample_array, canvas, self )
        canvas.restore()
Esempio n. 10
0
 def update(self, audio_sample_array=None):
     if audio_sample_array is None:
         print "Standalone Modus:"
         audio_sample_array = impulse.getSnapshot(True)
     
     l = len(audio_sample_array)
     
     for freq in range(0, l, l/self.bars):
         value = int(audio_sample_array[freq]*100)
         
         channels = self.manager.getChannelList(freq)
         #print freq, ":", channels
         for chan in channels:
             newval = self.manager.getValue(freq, value, self.data[chan])
             
             #print freq, chan, oldval, newval, '\t|\t',
             self.data[chan] = newval
     
     dataArray = array.array('B', self.data)
     self.client.SendDmx(self.universe, dataArray)
Esempio n. 11
0
	def update (self):
	
		spectrum = [0.0] * bars
		audio_sample_array = impulse.getSnapshot( True )
		
		sections = int((len(audio_sample_array)/4) / bars)
		
		for i in range(0, bars):
			spectrum[i] = math.fsum(audio_sample_array[sections*i:sections*(i+1)]) / sections * self.arg["gain"] * bars
			
		if arg["debug"]: print "FFT Array: %i, Sections: %i" % (len(audio_sample_array), sections)
		if arg["debug"]: print "F", spectrum
		if arg["debug"]: print "L", self.last
		
		for i in range(0, bars):
			if self.last[i] >= bars:
				self.last[i] = bars
		
		for n in range(0, bars):
			self.last[n] -= arg["decay"]
			if self.last[n] < 0.0:
				self.last[n] = 0.0
			if (spectrum[n] < self.last[n]):
				spectrum[n] = self.last[n]
			else:
				self.last[n] = spectrum[n]
		
		fg = hex2rgb( arg["fore"] )
		bg = hex2rgb( arg["back"] )
		
		leds.send("C");
		for y in range(0, bars):
			for x in range(0, bars):
				if spectrum[x] > bars-y:
					leds.send("S",map(lambda x: int(x/float(arg["reduced"])), fg))
				else:
					leds.send("S",map(lambda x: int(x/float(arg["reduced"])), bg))
		leds.send("D");
				
		
		return True # keep running this event
Esempio n. 12
0
def calc_heights(peak_heights,max_size):
	ffted_array = impulse.getSnapshot( True ) # True = use fft

	l = len( ffted_array ) / 4

	# start drawing spectrum
	n_bars = 32

	# no idea what this does - just taken from impulse :-)
	for i in range( 1, l, l / n_bars ):
		peak_index = int( ( i - 1 ) / ( l / n_bars ) )

		bar_amp_norm = ffted_array[ i ]
		bar_height = bar_amp_norm * max_size

		if bar_height > peak_heights[ peak_index ]:
			peak_heights[ peak_index ] = bar_height
		else:
			peak_heights[ peak_index ] -= int(max_size/20)

		if peak_heights[ peak_index ] < 0:
			peak_heights[ peak_index ] = 0
Esempio n. 13
0
	def update(self):
		"""Main update loop handler """
		self.audio_sample = impulse.getSnapshot(True)[:128]
		self.draw_area.queue_draw()
		return True
Esempio n. 14
0
	def update(self):
		"""Main update loop handler """
		self.audio_sample = impulse.getSnapshot(True)[:128]
		self.draw_area.queue_draw()
		return True
Esempio n. 15
0
def get_snapshot():
    return impulse.getSnapshot( True ) 
Esempio n. 16
0
	def update (self):
	
		samp_r = 0
		samp_g = 0
		samp_b = 0

		audio_sample_array = impulse.getSnapshot( True )
		
		sections = audio_sample_array.__len__() / self.arg["sample-sections"]
		
		start_r = self.arg["sample-section-bottom-red"]
		start_g = self.arg["sample-section-bottom-green"]
		start_b = self.arg["sample-section-bottom-blue"]
		len_r = self.arg["sample-section-top-red"] - start_r
		len_g = self.arg["sample-section-top-green"] - start_g
		len_b = self.arg["sample-section-top-blue"] - start_b
		
#		samp_x = sum of sample section / size of sample section
		try:
			samp_r = math.fsum(audio_sample_array[sections*start_r : sections*(start_r+len_r)]) / sections * len_r
			samp_g = math.fsum(audio_sample_array[sections*start_g : sections*(start_g+len_g)]) / sections * len_g
			samp_b = math.fsum(audio_sample_array[sections*start_b : sections*(start_b+len_b)]) / sections * len_b
		except:
			pass
		
		self.samp_r_old.pop(0) #remove oldest sample
		self.samp_g_old.pop(0)
		self.samp_b_old.pop(0)
		
		self.samp_r_old.append(samp_r) #append new sample
		self.samp_g_old.append(samp_g)
		self.samp_b_old.append(samp_b)
		
#		samp_x = sum of sample value buffer / lenght of sample value buffer
		samp_r_avg = sum(self.samp_r_old) / self.samp_r_old.__len__()
		samp_g_avg = sum(self.samp_g_old) / self.samp_g_old.__len__()
		samp_b_avg = sum(self.samp_b_old) / self.samp_b_old.__len__()
		
#		if sample < sample avrage then sample = sample avrage, else sample buffer is all set to sample
#		This creates a nice effect of light comming at same time as sound and then fading out
		if (samp_r < samp_r_avg): samp_r = samp_r_avg
		else: self.samp_r_old = [samp_r]*self.samp_r_old.__len__()
		if (samp_g < samp_g_avg): samp_g = samp_g_avg
		else: self.samp_g_old = [samp_g]*self.samp_g_old.__len__()
		if (samp_b < samp_b_avg): samp_b = samp_b_avg
		else: self.samp_b_old = [samp_b]*self.samp_b_old.__len__()
		
		samp_r *= self.arg["gain"] * self.arg["gain-red"]
		samp_g *= self.arg["gain"] * self.arg["gain-green"]
		samp_b *= self.arg["gain"] * self.arg["gain-blue"]
			
		if (samp_r > self.arg["output-top-red"]): samp_r = self.arg["output-top-red"]
		if (samp_g > self.arg["output-top-green"]): samp_g = self.arg["output-top-green"]
		if (samp_b > self.arg["output-top-blue"]): samp_b = self.arg["output-top-blue"]
		
		if (samp_r < self.arg["output-bottom-red"]): samp_r = self.arg["output-bottom-red"]
		if (samp_g < self.arg["output-bottom-green"]): samp_g = self.arg["output-bottom-green"]
		if (samp_b < self.arg["output-bottom-blue"]): samp_b = self.arg["output-bottom-blue"]
		
		if (self.arg["invert-red"]): samp_r = 255 - samp_r
		if (self.arg["invert-green"]): samp_g = 255 - samp_g
		if (self.arg["invert-blue"]): samp_b = 255 - samp_b
		
		if (self.arg["hsv"]):
			import colorsys
			if arg["debug"]: print ("hsv: " + str(samp_r) + " " + str(samp_g) + " " + str(samp_b) + " = " + str(float(samp_r) / 255) +" "+ str(float(samp_g) / 255) +" "+ str(float(samp_b) / 255))
			samp = colorsys.hsv_to_rgb( float(samp_r) / 255, float(samp_g) / 255, float(samp_b) / 255 )
			samp_r = 255 * samp[0]
			samp_g = 255 * samp[1]
			samp_b = 255 * samp[2]
			if arg["debug"]: print ("rgb: " + str(samp_r) + " " + str(samp_g) + " " + str(samp_b))
		
		output_r = str(hex(int(samp_r)).replace("0x","").rjust(2,'0'))
		output_g = str(hex(int(samp_g)).replace("0x","").rjust(2,'0'))
		output_b = str(hex(int(samp_b)).replace("0x","").rjust(2,'0'))
		
		u.sendData(arg["transmit-endpoint"], "A" + output_r + output_g + output_b)
		if arg["debug"]: print("output: A" + output_r + output_g + output_b)
		
		
		
		return True # keep running this event