|
@@ -5,20 +5,21 @@ import time
|
|
|
import math
|
|
|
import sys, getopt
|
|
|
|
|
|
-framerate = 60 #Hz
|
|
|
+framerate = 40 #Hz
|
|
|
dataTime = 1/30
|
|
|
+agcTime = 10
|
|
|
graphs = True
|
|
|
outDev = True
|
|
|
port = None
|
|
|
|
|
|
try:
|
|
|
- opts, args = getopt.getopt(sys.argv[1:],"hsif:t:b:w:",["shadow=","input=","framerate=","time=","port="])
|
|
|
+ opts, args = getopt.getopt(sys.argv[1:],"hsif:t:a:w:",["shadow=","input=","framerate=","time=","agc=","port="])
|
|
|
except getopt.GetoptError:
|
|
|
- print('main.py -s (shadow) -i (use input) -f --framerate <n=40>\n -t --time <t=0.033> -p --port <COM3>')
|
|
|
+ print('main.py -s (shadow) -i (use input) -f --framerate <f=40>\n -t --time <t=0.033> -a --agc <a=10> -p --port <COM3>')
|
|
|
sys.exit(2)
|
|
|
for opt, arg in opts:
|
|
|
if opt == '-h':
|
|
|
- print('main.py -s (shadow) -i (use input) -f --framerate <n=40>\n -t --time <t=0.033> -p --port <COM3>')
|
|
|
+ print('main.py -s (shadow) -i (use input) -f --framerate <f=40>\n -t --time <t=0.033> -a --agc <a=10> -p --port <COM3>')
|
|
|
sys.exit()
|
|
|
elif opt in ("-s", "--shadow"):
|
|
|
graphs = False
|
|
@@ -26,6 +27,8 @@ for opt, arg in opts:
|
|
|
outDev = False
|
|
|
elif opt in ("-f", "--framerate"):
|
|
|
framerate = float(arg)
|
|
|
+ elif opt in ("-a", "--agc"):
|
|
|
+ agcTime = float(arg)
|
|
|
elif opt in ("-t", "--time"):
|
|
|
dataTime = float(arg)
|
|
|
elif opt in ("-p", "--port"):
|
|
@@ -35,13 +38,14 @@ matrix = SerialConnection()
|
|
|
matrix.open(port)
|
|
|
|
|
|
pitches = [(2**(1/12))**(n/11*12*7-30) * 220 for n in range(11)]
|
|
|
-audio = Listener(dataTime, 30, not outDev)
|
|
|
+audio = Listener(dataTime, agcTime, not outDev)
|
|
|
audio.start()
|
|
|
|
|
|
nFFT = audio.buffersize
|
|
|
audio.fftSetLimits(nFFT, min(pitches), max(pitches))
|
|
|
audio.agcFftSetLimits(60/60, 300/60)
|
|
|
|
|
|
+curVal = [0] * N_COLS
|
|
|
maxVolRow = [0] * N_COLS
|
|
|
maxVolAge = [0] * N_COLS
|
|
|
intervalTime = time.time()
|
|
@@ -53,12 +57,12 @@ while True:
|
|
|
sums = audio.fftGroup(fft, pitches)
|
|
|
data = [0] * 50
|
|
|
for col in range(N_COLS):
|
|
|
- curVal = sums[col] * len(sums) * 1.1**col
|
|
|
- curRow = max(N_ROWS - int(curVal), 0)
|
|
|
+ curVal[col] = max(sums[col] * len(sums) * 1.5 * 1.1**col, curVal[col]*0.80)
|
|
|
+ curRow = max(N_ROWS - int(curVal[col]), 0)
|
|
|
|
|
|
if curRow <= maxVolRow[col]:
|
|
|
maxVolRow[col] = curRow
|
|
|
- maxVolAge[col] = 30
|
|
|
+ maxVolAge[col] = 60
|
|
|
elif maxVolAge[col] > 0:
|
|
|
maxVolAge[col] -= 1
|
|
|
else:
|
|
@@ -73,7 +77,7 @@ while True:
|
|
|
data[49] = int(data[49]/2)
|
|
|
|
|
|
matrix.send(b'A' + bytes(data))
|
|
|
- time.sleep(1/30)
|
|
|
+ time.sleep(1/framerate)
|
|
|
|
|
|
if time.time() - intervalTime > 60:
|
|
|
if not matrix.isConnected():
|