a
This commit is contained in:
parent
da7d679248
commit
f9fac746ae
@ -13,10 +13,11 @@ class AudioVisualizer(QtWidgets.QWidget):
|
||||
_type_: _description_
|
||||
"""
|
||||
|
||||
def __init__(self, media_player):
|
||||
def __init__(self, media_player, x_resolution):
|
||||
super().__init__()
|
||||
self.media_player = media_player
|
||||
self.fft_analyser = FFTAnalyser(self.media_player)
|
||||
self.x_resolution = x_resolution
|
||||
self.fft_analyser = FFTAnalyser(self.media_player, self.x_resolution)
|
||||
self.fft_analyser.calculated_visual.connect(self.set_amplitudes)
|
||||
self.fft_analyser.start()
|
||||
self.amps = np.array([])
|
||||
|
||||
25
main.py
25
main.py
@ -160,14 +160,19 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
|
||||
self.config.read(self.cfg_file)
|
||||
self.player: QMediaPlayer = QMediaPlayer() # Audio player object
|
||||
self.probe: QAudioProbe = QAudioProbe() # Gets audio data
|
||||
self.audio_visualizer: AudioVisualizer = AudioVisualizer(self.player)
|
||||
self.current_volume: int = 50
|
||||
self.analyzer_x_resolution = 200
|
||||
self.audio_visualizer: AudioVisualizer = AudioVisualizer(self.player, self.analyzer_x_resolution)
|
||||
self.timer = QTimer(self) # Audio timing things
|
||||
self.clipboard = clipboard
|
||||
self.tableView.load_qapp(self)
|
||||
self.albumGraphicsView.load_qapp(self)
|
||||
# Initialization
|
||||
self.timer = QTimer(self) # Audio timing things
|
||||
|
||||
# Settings init
|
||||
self.current_volume: int = int(self.config["settings"]["volume"])
|
||||
self.player.setVolume(self.current_volume)
|
||||
self.volumeLabel.setText(str(self.current_volume))
|
||||
self.volumeSlider.setValue(self.current_volume)
|
||||
|
||||
# Audio probe for processing audio signal in real time
|
||||
self.probe.setSource(self.player)
|
||||
self.probe.audioBufferProbed.connect(self.process_probe)
|
||||
@ -176,14 +181,18 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
|
||||
self.timer.timeout.connect(self.move_slider)
|
||||
|
||||
# Graphics plot
|
||||
self.PlotWidget.setXRange(0, 100, padding=0) # x axis range
|
||||
self.PlotWidget.setXRange(0, self.analyzer_x_resolution, padding=0) # x axis range
|
||||
self.PlotWidget.setYRange(0, 1, padding=0) # y axis range
|
||||
self.PlotWidget.setLogMode(False, False)
|
||||
self.PlotWidget.setMouseEnabled(x=False, y=False)
|
||||
self.PlotWidget.getAxis("bottom").setTicks([]) # Remove x-axis ticks
|
||||
# Remove x-axis ticks
|
||||
ticks = ['20', '31.25', '62.5', '125', '250', '500', '1000', '2000', '4000', '10000', '20000']
|
||||
self.PlotWidget.getAxis("bottom").setTicks([])
|
||||
self.PlotWidget.getAxis("bottom").setLabel("") # Remove x-axis label
|
||||
# x = nparray([0, 31.25, 62.5, 125, 250, 500, 1000, 2000, 4000, 8000, 15000, 20000])
|
||||
# Remove y-axis labels and decorations
|
||||
self.PlotWidget.getAxis("left").setTicks([]) # Remove y-axis ticks
|
||||
# self.PlotWidget.getAxis("left").setTicks([[(str(tick), tick) for tick in ticks]])
|
||||
self.PlotWidget.getAxis("left").setTicks([])
|
||||
self.PlotWidget.getAxis("left").setLabel("") # Remove y-axis label
|
||||
|
||||
# Connections
|
||||
@ -273,6 +282,7 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
|
||||
list_of_column_widths.append(str(self.tableView.columnWidth(i)))
|
||||
column_widths_as_string = ",".join(list_of_column_widths)
|
||||
self.config["table"]["column_widths"] = column_widths_as_string
|
||||
self.config["settings"]["volume"] = str(self.current_volume)
|
||||
|
||||
# Save the config
|
||||
with open(self.cfg_file, "w") as configfile:
|
||||
@ -553,6 +563,7 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
|
||||
|
||||
def process_probe(self, buff) -> None:
|
||||
"""Audio visualizer buffer processing"""
|
||||
print('probe')
|
||||
buff.startTime()
|
||||
self.update_audio_visualization()
|
||||
|
||||
|
||||
@ -14,13 +14,13 @@ class FFTAnalyser(QtCore.QThread):
|
||||
|
||||
calculated_visual = QtCore.pyqtSignal(np.ndarray)
|
||||
|
||||
def __init__(self, player): # noqa: F821
|
||||
def __init__(self, player, x_resolution): # noqa: F821
|
||||
super().__init__()
|
||||
self.player = player
|
||||
self.reset_media()
|
||||
self.player.currentMediaChanged.connect(self.reset_media)
|
||||
|
||||
self.resolution = 100
|
||||
self.resolution = x_resolution
|
||||
self.visual_delta_threshold = 1000
|
||||
self.sensitivity = 10
|
||||
|
||||
@ -97,7 +97,7 @@ class FFTAnalyser(QtCore.QThread):
|
||||
self.points[n] = 1e-5
|
||||
|
||||
# interpolate points
|
||||
rs = gaussian_filter1d(self.points, sigma=2)
|
||||
rs = gaussian_filter1d(self.points, sigma=4)
|
||||
|
||||
# Mirror the amplitudes, these are renamed to 'rs' because we are using them
|
||||
# for polar plotting, which is plotted in terms of r and theta
|
||||
@ -107,6 +107,7 @@ class FFTAnalyser(QtCore.QThread):
|
||||
# they are divided by the highest sample in the song to normalise the
|
||||
# amps in terms of decimals from 0 -> 1
|
||||
self.calculated_visual.emit(rs / self.max_sample)
|
||||
print(rs/self.max_sample)
|
||||
|
||||
def run(self):
|
||||
"""Runs the animate function depending on the song."""
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user