From f9fac746ae7cb6c240aaf70b5ac44d020fbaac61 Mon Sep 17 00:00:00 2001 From: billypom on debian Date: Sun, 30 Mar 2025 18:48:49 -0400 Subject: [PATCH] a --- components/AudioVisualizer.py | 5 +++-- main.py | 25 ++++++++++++++++++------- utils/fft_analyser.py | 7 ++++--- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/components/AudioVisualizer.py b/components/AudioVisualizer.py index 118a0b4..375f991 100644 --- a/components/AudioVisualizer.py +++ b/components/AudioVisualizer.py @@ -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([]) diff --git a/main.py b/main.py index 50b3dad..e306bba 100644 --- a/main.py +++ b/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() diff --git a/utils/fft_analyser.py b/utils/fft_analyser.py index 4ca752a..699dd87 100644 --- a/utils/fft_analyser.py +++ b/utils/fft_analyser.py @@ -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."""