diff options
| author | DH4 | 2017-06-01 09:52:40 -0500 |
|---|---|---|
| committer | DH4 | 2017-06-01 09:52:40 -0500 |
| commit | 43073cbd429fe415be3009124bee26b12ec8d2de (patch) | |
| tree | f508a9e7717eef3267430d98c41a6e7f30a166f3 /components | |
| parent | 6620f48bfdfd998ce680a75967ca586297fa2530 (diff) | |
Fixed spectrum rendering. Fixed multiple static renders.
Diffstat (limited to 'components')
| -rw-r--r-- | components/original.py | 52 |
1 files changed, 27 insertions, 25 deletions
diff --git a/components/original.py b/components/original.py index 46e7182..045ffa0 100644 --- a/components/original.py +++ b/components/original.py @@ -4,6 +4,8 @@ from PyQt4 import uic, QtGui from PyQt4.QtGui import QColor import os, random from . import __base__ +import time +from copy import copy class Component(__base__.Component): @@ -52,9 +54,9 @@ class Component(__base__.Component): self.spectrumArray = {} for i in range(0, len(self.completeAudioArray), self.sampleSize): - spectrum = transformData(i, self.completeAudioArray, self.sampleSize, + self.lastSpectrum = self.transformData(i, self.completeAudioArray, self.sampleSize, self.smoothConstantDown, self.smoothConstantUp, self.lastSpectrum) - self.spectrumArray[i] = spectrum + self.spectrumArray[i] = copy(self.lastSpectrum) def frameRender(self, moduleNo, frameNo): width = int(self.worker.core.settings.value('outputWidth')) @@ -66,35 +68,35 @@ class Component(__base__.Component): self.page.lineEdit_visColor.setText(RGBstring) self.page.pushButton_visColor.setStyleSheet(btnStyle) -def transformData(i, completeAudioArray, sampleSize, smoothConstantDown, smoothConstantUp, lastSpectrum): - if len(completeAudioArray) < (i + sampleSize): - sampleSize = len(completeAudioArray) - i - numpy.seterr(divide='ignore') - window = numpy.hanning(sampleSize) - data = completeAudioArray[i:i+sampleSize][::1] * window - paddedSampleSize = 2048 - paddedData = numpy.pad(data, (0, paddedSampleSize - sampleSize), 'constant') - spectrum = numpy.fft.fft(paddedData) - sample_rate = 44100 - frequencies = numpy.fft.fftfreq(len(spectrum), 1./sample_rate) + def transformData(self, i, completeAudioArray, sampleSize, smoothConstantDown, smoothConstantUp, lastSpectrum): + if len(completeAudioArray) < (i + sampleSize): + sampleSize = len(completeAudioArray) - i - y = abs(spectrum[0:int(paddedSampleSize/2) - 1]) + window = numpy.hanning(sampleSize) + data = completeAudioArray[i:i+sampleSize][::1] * window + paddedSampleSize = 2048 + paddedData = numpy.pad(data, (0, paddedSampleSize - sampleSize), 'constant') + spectrum = numpy.fft.fft(paddedData) + sample_rate = 44100 + frequencies = numpy.fft.fftfreq(len(spectrum), 1./sample_rate) - # filter the noise away - # y[y<80] = 0 + y = abs(spectrum[0:int(paddedSampleSize/2) - 1]) - y = 20 * numpy.log10(y) - y[numpy.isinf(y)] = 0 + # filter the noise away + # y[y<80] = 0 - if lastSpectrum is not None: - lastSpectrum[y < lastSpectrum] = y[y < lastSpectrum] * smoothConstantDown + lastSpectrum[y < lastSpectrum] * (1 - smoothConstantDown) - lastSpectrum[y >= lastSpectrum] = y[y >= lastSpectrum] * smoothConstantUp + lastSpectrum[y >= lastSpectrum] * (1 - smoothConstantUp) - else: - lastSpectrum = y + y = 20 * numpy.log10(y) + y[numpy.isinf(y)] = 0 - x = frequencies[0:int(paddedSampleSize/2) - 1] + if lastSpectrum is not None: + lastSpectrum[y < lastSpectrum] = y[y < lastSpectrum] * smoothConstantDown + lastSpectrum[y < lastSpectrum] * (1 - smoothConstantDown) + lastSpectrum[y >= lastSpectrum] = y[y >= lastSpectrum] * smoothConstantUp + lastSpectrum[y >= lastSpectrum] * (1 - smoothConstantUp) + else: + lastSpectrum = y - return lastSpectrum + x = frequencies[0:int(paddedSampleSize/2) - 1] + + return lastSpectrum def drawBars(width, height, spectrum, color, layout): vH = height-height/8 |
