patrick
This commit is contained in:
parent
87137bcd36
commit
87c53c3747
@ -1,5 +1,7 @@
|
||||
import numpy as np
|
||||
import math
|
||||
from PyQt5 import QtWidgets
|
||||
from numpy.lib import math
|
||||
from utils import FFTAnalyser
|
||||
|
||||
|
||||
@ -67,12 +69,12 @@ class AudioVisualizer(QtWidgets.QWidget):
|
||||
With a noise floor cutoff at around -96dB (for very small values)
|
||||
"""
|
||||
# Avoid log(0) by adding a small epsilon
|
||||
epsilon = 1e-6
|
||||
epsilon = 1e-30
|
||||
amplitudes = np.maximum(self.amps, epsilon)
|
||||
# Convert to decibels (20*log10 is the standard formula for amplitude to dB)
|
||||
db_values = 20 * np.log10(amplitudes)
|
||||
# Clip very low values to have a reasonable floor (e.g. -96dB)
|
||||
db_values = np.maximum(db_values, -96)
|
||||
db_values = np.maximum(db_values, -2000)
|
||||
return db_values
|
||||
|
||||
def set_rs(self, rs):
|
||||
@ -84,4 +86,5 @@ class AudioVisualizer(QtWidgets.QWidget):
|
||||
Amps are assigned here, based on values passed by the signal
|
||||
"""
|
||||
# self.amps = np.maximum(np.array(amps), 1e-12) # Set a very small threshold
|
||||
# print(self.amps)
|
||||
self.amps = np.array(amps)
|
||||
|
||||
@ -27,7 +27,7 @@ class FFTAnalyser(QtCore.QThread):
|
||||
# in this case, it takes 5% of the samples at some point in time
|
||||
self.sampling_window_length = 0.05
|
||||
self.visual_delta_threshold = 1000
|
||||
self.sensitivity = 1
|
||||
self.sensitivity = 10
|
||||
|
||||
def reset_media(self):
|
||||
"""Resets the media to the currently playing song."""
|
||||
@ -65,6 +65,7 @@ class FFTAnalyser(QtCore.QThread):
|
||||
freq = np.fft.fftfreq(fourier.size, d=self.sampling_window_length)
|
||||
amps = 2 / v_sample.size * np.abs(fourier)
|
||||
data = np.array([freq, amps]).T
|
||||
|
||||
# TEST:
|
||||
# print(freq * .05 * self.song.frame_rate)
|
||||
|
||||
@ -89,18 +90,18 @@ class FFTAnalyser(QtCore.QThread):
|
||||
if not data.size:
|
||||
return
|
||||
|
||||
# for i, freq in enumerate(np.arange(0, 1, point_range), start=1):
|
||||
for i, log_freq in enumerate(log_freqs):
|
||||
for i, freq in enumerate(np.arange(0, 1, point_range), start=1):
|
||||
# for i, log_freq in enumerate(log_freqs):
|
||||
# get the amps which are in between the frequency range
|
||||
# amps = data[(freq - point_range < data[:, 0]) & (data[:, 0] < freq)]
|
||||
amps = data[(log_freq - point_range < data[:, 0]) & (data[:, 0] < log_freq)]
|
||||
amps = data[(freq - point_range < data[:, 0]) & (data[:, 0] < freq)]
|
||||
# amps = data[(log_freq - point_range < data[:, 0]) & (data[:, 0] < log_freq)]
|
||||
if not amps.size:
|
||||
point_samples.append(0)
|
||||
else:
|
||||
point_samples.append(
|
||||
amps.max()
|
||||
* (
|
||||
(1 + self.sensitivity / 10 + (self.sensitivity - 1) / 10)
|
||||
((1 + self.sensitivity) / 10 + (self.sensitivity - 1) / 10)
|
||||
** (i / 50)
|
||||
)
|
||||
)
|
||||
@ -109,7 +110,7 @@ class FFTAnalyser(QtCore.QThread):
|
||||
# array (self.points) is so that we can fade out the previous amplitudes from
|
||||
# the past
|
||||
for n, amp in enumerate(point_samples):
|
||||
amp *= 2
|
||||
# amp *= 2
|
||||
if self.player.state() in (
|
||||
self.player.PausedState,
|
||||
self.player.StoppedState,
|
||||
@ -124,10 +125,11 @@ class FFTAnalyser(QtCore.QThread):
|
||||
self.points[n] = amp
|
||||
# print(f'amp > points[n] - {amp} > {self.points[n]}')
|
||||
# Set a lower threshold to properly reach zero
|
||||
if self.points[n] < 1:
|
||||
self.points[n] = 1e-5
|
||||
if self.points[n] < 1e-4:
|
||||
self.points[n] = 0
|
||||
|
||||
# print(self.points)
|
||||
|
||||
# interpolate points
|
||||
rs = gaussian_filter1d(self.points, sigma=2)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user