Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

equalizer.py -s: Symmetric mode (centered)

  • Loading branch information...
commit b3bdb9df2e50d3bcd06f0b91962e1067a34b6002 1 parent 5daf750
Petr Baudis pasky authored
Showing with 20 additions and 7 deletions.
  1. +20 −7 host_python/equalizer.py
27 host_python/equalizer.py
View
@@ -18,8 +18,9 @@
RATE = 44100
PIXELS = 20
-
LAZY = 0
+SYMMETRIC = 0
+
HISTORY_SIZE = 4
MIN_FREQ = 50
MAX_FREQ = 12000
@@ -28,15 +29,16 @@
def print_usage():
print '''\
USAGE:
- %s [-l] [-n number] [-h]
+ %s [-l] [-n number] [-s] [-h]
OPTIONS:
-l lazy mode
-n number number of controlled boxes
+ -s symmetric mode
-h --help show this help
''' % sys.argv[0]
try:
- opts, args = getopt.getopt(sys.argv[1:], 'n:lh', ['help'])
+ opts, args = getopt.getopt(sys.argv[1:], 'n:lsh', ['help'])
except getopt.GetOptError:
print_usage()
sys.exit(1)
@@ -51,16 +53,23 @@ def print_usage():
PIXELS = int(v)
elif k == '-l':
LAZY = 1
+ elif k == '-s':
+ SYMMETRIC = 1
elif k == '-h' or k == '--help':
print_usage()
sys.exit(0)
if LAZY == 1:
HISTORY_SIZE = 12
+if SYMMETRIC == 1:
+ EPIXELS = PIXELS / 2
+else:
+ EPIXELS = PIXELS
+# EPIXELS: Effective pixels (for spectrum display)
SAMPLE_SIZE = CHUNK_SIZE*HISTORY_SIZE
FREQ_STEP = float(RATE) / (CHUNK_SIZE * HISTORY_SIZE)
-PIXEL_FREQ_RANGE = math.pow(float(MAX_FREQ) / MIN_FREQ, 1.0/PIXELS)
+PIXEL_FREQ_RANGE = math.pow(float(MAX_FREQ) / MIN_FREQ, 1.0/EPIXELS)
p = pyaudio.PyAudio()
@@ -118,7 +127,7 @@ def get_color(volume):
pixel = 0
count = 0
volumes = []
- while pixel < PIXELS:
+ while pixel < EPIXELS:
total = 0.0
while freq < freq_limit:
total += abs(fft[i])**2
@@ -129,9 +138,13 @@ def get_color(volume):
freq_limit *= PIXEL_FREQ_RANGE
pixel += 1
count = 0
- for pixel in xrange(PIXELS):
+ for pixel in xrange(EPIXELS):
c = get_color(volumes[pixel])
- l.set_pixel(pixel, c[0], c[1], c[2])
+ if SYMMETRIC == 1:
+ l.set_pixel(PIXELS / 2 + pixel, c[0], c[1], c[2])
+ l.set_pixel(PIXELS / 2 - (pixel + 1), c[0], c[1], c[2])
+ else:
+ l.set_pixel(pixel, c[0], c[1], c[2])
work = l.update()
# time.sleep(0.05)
finally:
Please sign in to comment.
Something went wrong with that request. Please try again.