diff options
| author | schneefux <schneefux+commit@schneefux.xyz> | 2017-10-15 19:00:33 +0200 |
|---|---|---|
| committer | schneefux <schneefux+commit@schneefux.xyz> | 2017-10-15 19:00:33 +0200 |
| commit | 66a127b2c94f4a27b9ce54594a7a88b69b81d131 (patch) | |
| tree | a3eb479b49f0a61d881fba9cfacb0e2dc7aacfa1 | |
| parent | ca34afc190cee987b52318551d039e2c607874b7 (diff) | |
| download | mpd-rgb-vis-master.tar.gz mpd-rgb-vis-master.zip | |
| -rw-r--r-- | mpdvis.py | 13 |
1 files changed, 7 insertions, 6 deletions
@@ -1,8 +1,9 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 import hyperion import array import colorsys import numpy +from past.builtins import map DEBUG_MODE = False FIFO = '/tmp/mpd.fifo' @@ -51,7 +52,7 @@ class SoundToColorProcessor: return magnitudes def getFrequencyIndex(self, freq): - return freq/(self.RATE/self.CHUNK) + return int(freq/(self.RATE/self.CHUNK)) def convertPercentToColorValue(self, percent): return int(round(percent*255)) @@ -77,7 +78,7 @@ class SoundToColorProcessor: import matplotlib.pyplot as plt # open the audio stream on the sound card - stream = open(FIFO) + stream = open(FIFO, 'rb') if DEBUG_MODE: # Plots and canvas initialization @@ -98,8 +99,8 @@ class SoundToColorProcessor: results = numpy.fft.fft(nums) freq_bins = numpy.fft.fftfreq(len(nums), 1.0/self.RATE) - results = results[0:(len(results)/2 - 1)] - freq_bins = 2 * freq_bins[0:(len(freq_bins)/2 - 1)] + results = results[0:(len(results)//2 - 1)] + freq_bins = 2 * freq_bins[0:(len(freq_bins)//2 - 1)] mags = self.calculateMagnitude(results.real, results.imag) @@ -116,7 +117,7 @@ class SoundToColorProcessor: rms = numpy.sqrt(numpy.mean(numpy.square(nums))) value = val_iir.update(rms) / self.MAX_LOUDNESS - if value > 1.0: + if value > 1.0 or numpy.isnan(value): value = 1.0 averaged_frequency = hue_iir.update(new_frequency) hue = self.mapFrequencyToHue(averaged_frequency) |
