Exemple #1
0
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
Exemple #2
0
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
Exemple #3
0
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
Exemple #5
0
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
Exemple #6
0
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
Exemple #7
0
def oneNote(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)

    keyObj       = music.Key(stream.notes)
    noteSumsObj  = music.NoteSums(stream.notes)
    noteSumsObj2 = music.NoteSums(stream.notes, alpha=0.5)
    #chordObj    = music.Chord(stream.notes)

    while True:
        success = stream.readAndCalc()
        if success:
            keyObj      .update(stream.noteSpectrum)
            noteSumsObj .update(stream.noteSpectrum)
            noteSumsObj2.update(stream.noteSpectrum)
            #chordObj    .update(stream.noteSpectrum, keyObj.currentKeyNum)

            #keyObj.printKey()
            #chordObj.printChord()
            noteSumsObj2.printNoteSums()
Exemple #8
0
 def __init__(self, m, n):
     PanelPattern.__init__(self, m, n)
     self.call_name = 'arBeat'
     self.frameCount = 0
     self.frame_sleep_time = 0.0
     self.pix_np = np.zeros([3, self.m, self.n])
     self.stream = micStream.Stream(fps=60, nBuffers=6)
     self.beat = music.Beat(self.stream.freqs)
Exemple #9
0
 def __init__(self, m, n):
     PanelPattern.__init__(self, m, n)
     self.call_name = 'arTheoryDemo'
     self.frameCount = 0
     self.frame_sleep_time = 0.0
     self.pix_np = np.zeros([3, self.m, self.n])
     self.stream = micStream.Stream()
     self.volume = music.ExpFilter(0.0, alpha_rise=0.8, alpha_decay=0.3)
     self.keyObj = music.Key(self.stream.notes)
     self.noteSumsObj = music.NoteSums(self.stream.notes)
     self.chordObj = music.Chord(self.stream.notes)
Exemple #10
0
 def __init__(self, m, n):
     PanelPattern.__init__(self, m, n)
     self.call_name = 'arSpectrum'
     self.frameCount = 0
     self.frame_sleep_time = 0.0
     self.pix_np = np.zeros([3, self.m, self.n])
     self.volThresh = 0.1
     self.stream = micStream.Stream(fps=40, nBuffers=8)
     self.volumeFilter = music.ExpFilter(0.01,
                                         alpha_rise=0.1,
                                         alpha_decay=0.1)
     self.spectrumFilter = music.ExpFilter(np.zeros_like(self.stream.notes),
                                           alpha_rise=0.3,
                                           alpha_decay=0.3)
Exemple #11
0
 def __init__(self, m, n):
     PanelPattern.__init__(self, m, n)
     self.call_name = 'arScroll'
     self.frameCount = 0
     self.frame_sleep_time = 0.0
     self.pix_np = np.zeros([3, self.m, self.n])
     self.stream = micStream.Stream(fps=40, nBuffers=8)
     self.volumeFilter = music.ExpFilter(0.01,
                                         alpha_rise=0.1,
                                         alpha_decay=0.1)
     self.spectrumFilter = music.ExpFilter(np.zeros_like(self.stream.notes),
                                           alpha_rise=0.5,
                                           alpha_decay=0.5)
     self.colorWheel = patternHelpers.getColorWheel(300)
Exemple #12
0
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)
Exemple #13
0
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())
Exemple #14
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)
Exemple #15
0
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())
Exemple #16
0
#!/usr/bin/env python

import fastopc, time
import numpy as np
#import functionLib as lib
import micStream
import pyaudio

stream = micStream.Stream(fps=30, nBuffers=1)
#print(stream.fps)
#print(stream.framesPerBuffer)

for i in range(0, 10):
    print("i=" + str(i))
    stream.readNewData()
    #stream.stream.read(2*stream.framesPerBuffer)
    print("marker1")
'''
# audio setup
CHUNK = 8192    # input buffer size in frames
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATES = [96000, 88200, 48000, 44100, 32000, 24000]
RATES = [44100]
# open sound card data stream
npoints = 1000000
for rate in RATES:
    p = pyaudio.PyAudio()
    stream = p.open(format=FORMAT,
        channels=CHANNELS,
        rate=rate,
#!/usr/bin/env python

import fastopc, time
import numpy as np
import functionLib as lib
import micStream

nStrips = 16
lStrip = 64
client = fastopc.FastOPC('localhost:7890')

pixels = lib.Pixels(nStrips, lStrip, 0)
theoStrip = np.zeros([lStrip, 3])

stream = micStream.Stream(fps=40, nBuffers=4)

while True:
    success = stream.readAndCalc()
    if success:
        power = np.sum(stream.freqSpectrum[30 // 5:300 // 5])
        print(power)
        print(stream.freqs)
        print(stream.notes)
        theoStrip[:, 0] = power / 1.0
        pixels.update(theoStrip, 0.9, 0.2)
        client.putPixels(0, pixels.getArrayForDisplay())