def chase_beatDetection(brightnessFactor): # always here global nStrips, lStrip client = fastopc.FastOPC('localhost:7890') # setup stream = micStream.Stream(fps=30, nBuffers=4) powerSmooth1 = lib.ExpFilter(val=1.0, alpha_rise=0.05, alpha_decay=0.05) powerMinFreqIndex1 = int(0 / stream.dFreq) powerMaxFreqIndex1 = int(120 / stream.dFreq) beatObj1 = music.Beat(thresh=1.5, waitFrames=5) powerSmooth2 = lib.ExpFilter(val=1.0, alpha_rise=0.1, alpha_decay=0.1) powerMinFreqIndex2 = int(9000 / stream.dFreq) powerMaxFreqIndex2 = int(10000 / stream.dFreq) beatObj2 = music.Beat(thresh=2.5, waitFrames=2) dir = 1 pixels = lib.Pixels(nStrips, lStrip, 20) theoStrip = np.zeros([lStrip * nStrips, 3]) color = 2 for n in range(0, lStrip * nStrips, lStrip // 2 + 2): theoStrip[n, color] = 255 # loop while True: success = stream.readAndCalc() if success: power1 = np.sum( stream.freqSpectrum[powerMinFreqIndex1:powerMaxFreqIndex1]) powerSmooth1.update(power1) #powerTot = np.sum(stream.freqSpectrum) powerSmooth1.update(power1) powerNorm1 = power1 / powerSmooth1.value beatObj1.update(powerNorm1) power2 = np.sum( stream.freqSpectrum[powerMinFreqIndex2:powerMaxFreqIndex2]) powerSmooth2.update(power2) powerNorm2 = power2 / powerSmooth2.value beatObj2.update(powerNorm2) if beatObj1.getBeatStatus() == True: dir *= -1 theoStrip = np.roll(theoStrip, 1, axis=1) lib.clDisplay(powerNorm1) theoStrip = np.roll(theoStrip, dir, axis=0) pixels.update(theoStrip, 1.0, 0.05) client.putPixels(0, brightnessFactor * pixels.getArrayForDisplay()) n += dir time.sleep(0.003)
def bassScrollTop(brightnessFactor): # always here global nStrips, lStrip client = fastopc.FastOPC('localhost:7890') # setup pixels = lib.Pixels(nStrips, lStrip, 0) theoStrip = np.zeros([lStrip, 3]) stream = micStream.Stream(fps=30, nBuffers=4) powerSmooth = lib.ExpFilter(val=1.0, alpha_rise=0.01, alpha_decay=0.01) nColorWheel = 300 colorWheel = lib.getColorWheel(nColorWheel) frameCount = 0 powerMinFreqIndex = int(0 / stream.dFreq) powerMaxFreqIndex = int(120 / stream.dFreq) # loop while True: success = stream.readAndCalc() if success: frameNumEff = np.mod(frameCount, nColorWheel) power = np.sum( stream.freqSpectrum[powerMinFreqIndex:powerMaxFreqIndex]) powerSmooth.update(power) displayPower = int(122 * np.power(power / powerSmooth.value, 1.5)) theoStrip = np.roll(theoStrip, -1, axis=0) theoStrip[-2] = displayPower * colorWheel[frameNumEff] theoStrip[-1] = 1000 * colorWheel[frameNumEff] pixels.update(theoStrip, 0.7, 0.5) client.putPixels(0, brightnessFactor * pixels.getArrayForDisplay()) frameCount += 1
def bassWiden(brightnessFactor): # always here global nStrips, lStrip client = fastopc.FastOPC('localhost:7890') # setup pixels = lib.Pixels(nStrips, lStrip, 20) theoStrip = np.zeros([lStrip // 2, 3]) stream = micStream.Stream(fps=30, nBuffers=4) powerMinFreqIndex1 = int(0 / stream.dFreq) powerMaxFreqIndex1 = int(200 / stream.dFreq) powerSmooth = lib.ExpFilter(val=1.0, alpha_rise=0.01, alpha_decay=0.01) nColorWheel = 600 colorWheel = lib.getColorWheel(nColorWheel) frameCount = 0 # loop while True: success = stream.readAndCalc() if success: frameNumEff = np.mod(frameCount, nColorWheel) power = np.sum( stream.freqSpectrum[powerMinFreqIndex1:powerMaxFreqIndex1]) powerSmooth.update(power) displayPower = max(int(122 * power / powerSmooth.value), 50) width = int(2 + 0.5 * np.sqrt(float(displayPower))) theoStrip[width:] = displayPower * colorWheel[np.mod( frameNumEff + 200, nColorWheel)] theoStrip[0:width] = 255 * colorWheel[np.mod( frameNumEff, nColorWheel)] #pixels.update(theoStrip, 0.7, 0.2) pixels.update(theoStrip, 1.0, 1.0) client.putPixels(0, brightnessFactor * pixels.getArrayForDisplay()) frameCount += 1
def kickDrum(brightnessFactor): # always here global nStrips, lStrip client = fastopc.FastOPC('localhost:7890') # setup pixels = lib.Pixels(nStrips, lStrip, 0) theoStrip = np.zeros([lStrip // 2, 3]) stream = micStream.Stream(fps=60, nBuffers=4) powerSmooth = lib.ExpFilter(val=0.05, alpha_rise=0.1, alpha_decay=0.1) nColorWheel = 300 colorWheel = lib.getColorWheel(nColorWheel) frameCount = 0 # loop while True: success = stream.readAndCalc() if success: frameNumEff = np.mod(frameCount, nColorWheel) #power = np.sum(stream.freqSpectrum[20//7:250//7]) power = np.sum(stream.freqSpectrum[:20]) powerSmooth.update(power) if power > 1.e4: displayPower = int(122 * np.power(power / powerSmooth.value, 1.5)) theoStrip[:] = displayPower * colorWheel[frameNumEff] #theoStrip[0] = 1000*colorWheel[frameNumEff] pixels.update(theoStrip, 1.0, 0.4) client.putPixels( 0, brightnessFactor * pixels.getArrayForDisplay()) frameCount += 1 else: theoStrip[:] = np.zeros_like(theoStrip[:]) #theoStrip[0] = 1000*colorWheel[frameNumEff] pixels.update(theoStrip, 1.0, 0.4) client.putPixels( 0, brightnessFactor * pixels.getArrayForDisplay())
def beatDetection(): stream = micStream.Stream(fps=30, nBuffers=4) #powerSmooth = lib.ExpFilter(val=1.0, alpha_rise=0.05, alpha_decay=0.05) powerSmooth = lib.ExpFilter(val=1.0, alpha_rise=0.05, alpha_decay=0.05) print(stream.freqs.shape) print(stream.freqs) print(stream.notes) for i in range(0, 10): print(stream.freqsToMelMatrix[0, i * 10:(i + 1) * 10]) powerMinFreqIndex = int(0 / stream.dFreq) powerMaxFreqIndex = int(250 / stream.dFreq) thresh = 1.3 recentBeat = 0 powerNorm = np.asarray([0., 0., 0.]) while True: success = stream.readAndCalc() if success: power = np.sum( stream.freqSpectrum[powerMinFreqIndex:powerMaxFreqIndex]) powerSmooth.update(power) powerNorm[2] = powerNorm[1] powerNorm[1] = powerNorm[0] powerNorm[0] = power / powerSmooth.value lib.clDisplay(powerNorm[0]) if powerNorm[2] < powerNorm[1] and powerNorm[1] > powerNorm[ 0] and powerNorm[1] > thresh and recentBeat <= 0: recentBeat = 4 print('BEAT ' * 21) recentBeat -= 1
def scroll(brightnessFactor): global lNeck, lBody, lStrap client = fastopc.FastOPC('localhost:7890') pixels = lib.BassPixels(lNeck, lBody, lStrap, 0) theoNeck = np.zeros([lNeck, 3]) theoBody = np.zeros([lBody, 3]) theoStrap = np.zeros([lStrap, 3]) stream = micStream.Stream(fps=30, nBuffers=4) powerSmooth = lib.ExpFilter(val=0.05, alpha_rise=0.05, alpha_decay=0.05) nColorWheel = 600 colorWheel = lib.getColorWheel(nColorWheel) frameCount = 0 while True: success = stream.readAndCalc() if success: frameNumEff = np.mod(frameCount, nColorWheel) power = np.sum(stream.freqSpectrum[20//7:250//7]) powerSmooth.update(power) displayPower = int(122*np.power(power/powerSmooth.value, 1.5)) theoNeck = np.roll(theoNeck, 1, axis=0) theoNeck[0] = displayPower * colorWheel[frameNumEff] theoBody = displayPower * colorWheel[np.mod(frameNumEff+200, nColorWheel)] pixels.updateBody(theoBody, 0.5, 0.5) pixels.updateNeck(theoNeck, 0.5, 0.5) client.putPixels(0, brightnessFactor*pixels.getArrayForDisplay()) frameCount+=1
def basic(brightnessFactor): print('brightness factor is ' + str(brightnessFactor)) global lNeck, lBody, lStrap client = fastopc.FastOPC('localhost:7890') pixels = lib.BassPixels(lNeck, lBody, lStrap, 0) theoNeck = np.zeros([lNeck, 3]) theoBody = np.zeros([lBody, 3]) theoStrap = np.zeros([lStrap, 3]) stream = micStream.Stream(fps=30, nBuffers=4) powerSmooth = lib.ExpFilter(val=0.05, alpha_rise=0.05, alpha_decay=0.05) nColorWheel = 600 colorWheel = lib.getColorWheel(nColorWheel) frameCount = 0 while True: success = stream.readAndCalc() if success: frameNumEff = np.mod(frameCount, nColorWheel) power = np.sum(stream.freqSpectrum[20//7:250//7]) powerSmooth.update(power) displayPower = int(122*power/powerSmooth.value) width = int(5 + np.sqrt(float(displayPower))) theoBody = displayPower * colorWheel[np.mod(frameNumEff+200, nColorWheel)] theoNeck[0:width] = 255 * colorWheel[np.mod(frameNumEff, nColorWheel)] pixels.updateBody(theoBody, 0.7, 0.1) pixels.updateNeck(theoNeck, 0.7, 0.1) client.putPixels(0, brightnessFactor*pixels.getArrayForDisplay()) frameCount+=1
def beatDetection(brightnessFactor): # always here client = fastopc.FastOPC('localhost:7890') pixels = lib.Pixels(nStrips, lStrip, 0) theo = np.zeros([lStrip, 3]) stream = micStream.Stream(fps=30, nBuffers=4) powerSmooth1 = lib.ExpFilter(val=1.0, alpha_rise=0.05, alpha_decay=0.05) powerMinFreqIndex1 = int(0 / stream.dFreq) powerMaxFreqIndex1 = int(250 / stream.dFreq) beatObj1 = music.Beat() powerSmooth2 = lib.ExpFilter(val=1.0, alpha_rise=0.1, alpha_decay=0.1) powerMinFreqIndex2 = int(9000 / stream.dFreq) powerMaxFreqIndex2 = int(10000 / stream.dFreq) beatObj2 = music.Beat(thresh=2.5, waitFrames=2) while True: success = stream.readAndCalc() if success: power1 = np.sum( stream.freqSpectrum[powerMinFreqIndex1:powerMaxFreqIndex1]) powerSmooth1.update(power1) powerNorm1 = power1 / powerSmooth1.value beatObj1.update(powerNorm1) power2 = np.sum( stream.freqSpectrum[powerMinFreqIndex2:powerMaxFreqIndex2]) powerSmooth2.update(power2) powerNorm2 = power2 / powerSmooth2.value beatObj2.update(powerNorm2) theo[0, :] = 0 theo = np.roll(theo, -1, axis=0) if beatObj1.getBeatStatus() == True: theo[-1, 0] = 255 print('BEAT ' * 21) if beatObj2.getBeatStatus() == True: theo[-1, 2] = 255 #print('BEAT '*21) lib.clDisplay(powerNorm2) pixels.update(theo, 1.0, 0.3) client.putPixels(0, brightnessFactor * pixels.getArrayForDisplay())
def __init__(self, noteList, alpha=0.001): self.noteSums = lib.ExpFilter(np.ones(12), alpha_rise=alpha, alpha_decay=alpha) self.matrix = getNotesToKeyMatrix( noteList, [1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]) self.newNoteSums = np.zeros(12) self.noteStringList = [ 'c ', 'cs ', 'd ', 'ef ', 'e ', 'f ', 'fs ', 'g ', 'af ', 'a ', 'bf ', 'b ' ]
def __init__( self, noteList, # 1 2 3 4 5 6 7 weights=[3., -1., 1., -1., 1., 2., -5., 3., -1., 2., -5., 1.], alpha=0.00025): self.keySums = lib.ExpFilter(np.ones(12), alpha_rise=alpha, alpha_decay=alpha) self.matrix = getNotesToKeyMatrix(noteList, weights) self.keyStringList = [ 'c ', 'cs ', 'd ', 'ef ', 'e ', 'f ', 'fs ', 'g ', 'af ', 'a ', 'bf ', 'b ' ] self.currentKeyNum = 0
def bpm(brightnessFactor): # always here global nStrips, lStrip #client = fastopc.FastOPC('localhost:7890') # setup #pixels = lib.Pixels(nStrips, lStrip, 20) #theoStrip = np.zeros([lStrip//2, 3]) stream = micStream.Stream(fps=30, nBuffers=4) powerMinFreqIndex1 = int(0 / stream.dFreq) powerMaxFreqIndex1 = int(200 / stream.dFreq) powerSmooth = lib.ExpFilter(val=1.0, alpha_rise=0.01, alpha_decay=0.01) #frameCount = 0 bpm = music.BPM() # loop while True: success = stream.readAndCalc() if success: power = np.sum( stream.freqSpectrum[powerMinFreqIndex1:powerMaxFreqIndex1]) powerSmooth.update(power) bpm.update(power)
def bouncers_ar(brightnessFactor): # always here global nStrips, lStrip client = fastopc.FastOPC('localhost:7890') # setup stream = micStream.Stream(fps=30, nBuffers=4) powerSmooth = lib.ExpFilter(val=0.05, alpha_rise=0.05, alpha_decay=0.05) powerMinFreqIndex = int(0 / stream.dFreq) powerMaxFreqIndex = int(250 / stream.dFreq) nBouncers = 16 pixels = lib.Pixels(nStrips, lStrip, 0) theoStrip = np.zeros([nStrips * lStrip, 3]) bouncerList = [] for i in range(nBouncers): bouncerList.append( lib.Bouncer(np.random.randint(1, high=8), np.random.rand() * 0.3 + 0.05, np.random.rand(3), lStrip)) # loop while True: success = stream.readAndCalc() if success: power = np.sum( stream.freqSpectrum[powerMinFreqIndex:powerMaxFreqIndex]) powerSmooth.update(power) displayPower = int(122 * np.power(power / powerSmooth.value, 1.5)) for i in range(0, nBouncers): bouncerList[i].update() for i in range(0, nBouncers // 2): stripNum = i base = stripNum * lStrip theoStrip[base:base + lStrip] = ( 0.5 + (float(displayPower) / 255.0)) * ( bouncerList[i].getFullOutArray() + bouncerList[i + nBouncers // 2].getFullOutArray()) pixels.update(theoStrip, 0.5, 0.5) client.putPixels(0, brightnessFactor * pixels.getArrayForDisplay())
import micStream if len(sys.argv) == 1: brightnessFactor = 0.7 else: brightnessFactor = float(sys.argv[1]) nStrips = 16 lStrip = 64 client = fastopc.FastOPC('localhost:7890') pixels = lib.Pixels(nStrips, lStrip, 0) theo = np.zeros([nStrips * lStrip, 3]) stream = micStream.Stream(fps=30, nBuffers=4) powerSmooth = lib.ExpFilter(val=0.05, alpha_rise=0.05, alpha_decay=0.05) nColorWheel = 300 nOnOneStrip = 30 colorWheel = lib.getColorWheel(nColorWheel) frameCount = 0 while True: success = stream.readAndCalc() if success: frameNumEff = np.mod(frameCount, nColorWheel) stripNum = np.mod(np.floor(frameCount / nOnOneStrip), nStrips // 2) power = np.sum(stream.freqSpectrum[20 // 7:250 // 7]) powerSmooth.update(power) displayPower = int(122 * np.power(power / powerSmooth.value, 1.5)) theo = np.roll(theo, 1, axis=0)