From 66a127b2c94f4a27b9ce54594a7a88b69b81d131 Mon Sep 17 00:00:00 2001 From: schneefux Date: Sun, 15 Oct 2017 19:00:33 +0200 Subject: port to python3 --- mpdvis.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/mpdvis.py b/mpdvis.py index df1f525..34a8f78 100644 --- a/mpdvis.py +++ b/mpdvis.py @@ -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) -- cgit v1.3.1