cursor suggested performance improvement lol
This commit is contained in:
parent
bd9070b1c8
commit
dcdfeac607
@ -21,6 +21,8 @@ class AudioVisualizer(QtWidgets.QWidget):
|
|||||||
self.fft_analyser.calculated_visual.connect(self.set_amplitudes)
|
self.fft_analyser.calculated_visual.connect(self.set_amplitudes)
|
||||||
self.fft_analyser.start()
|
self.fft_analyser.start()
|
||||||
self.amps = np.array([])
|
self.amps = np.array([])
|
||||||
|
self._plot_item = None
|
||||||
|
self._x_data = np.arange(self.x_resolution)
|
||||||
|
|
||||||
def get_amplitudes(self):
|
def get_amplitudes(self):
|
||||||
return self.amps
|
return self.amps
|
||||||
|
|||||||
26
main.py
26
main.py
@ -162,7 +162,7 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
|
|||||||
self.config.read(self.cfg_file)
|
self.config.read(self.cfg_file)
|
||||||
self.player: QMediaPlayer = QMediaPlayer() # Audio player object
|
self.player: QMediaPlayer = QMediaPlayer() # Audio player object
|
||||||
self.probe: QAudioProbe = QAudioProbe() # Gets audio data
|
self.probe: QAudioProbe = QAudioProbe() # Gets audio data
|
||||||
self.analyzer_x_resolution = 200
|
self.analyzer_x_resolution = 150
|
||||||
self.audio_visualizer: AudioVisualizer = AudioVisualizer(self.player, self.analyzer_x_resolution)
|
self.audio_visualizer: AudioVisualizer = AudioVisualizer(self.player, self.analyzer_x_resolution)
|
||||||
self.timer = QTimer(self) # Audio timing things
|
self.timer = QTimer(self) # Audio timing things
|
||||||
self.clipboard = clipboard
|
self.clipboard = clipboard
|
||||||
@ -187,6 +187,10 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
|
|||||||
self.PlotWidget.setYRange(0, 1, padding=0) # y axis range
|
self.PlotWidget.setYRange(0, 1, padding=0) # y axis range
|
||||||
self.PlotWidget.setLogMode(False, False)
|
self.PlotWidget.setLogMode(False, False)
|
||||||
self.PlotWidget.setMouseEnabled(x=False, y=False)
|
self.PlotWidget.setMouseEnabled(x=False, y=False)
|
||||||
|
# Performance optimizations
|
||||||
|
self.PlotWidget.setAntialiasing(False)
|
||||||
|
self.PlotWidget.setDownsampling(auto=True, mode='peak')
|
||||||
|
self.PlotWidget.setClipToView(True)
|
||||||
# Remove x-axis ticks
|
# Remove x-axis ticks
|
||||||
# ticks = ['20', '31.25', '62.5', '125', '250', '500', '1000', '2000', '4000', '10000', '20000']
|
# ticks = ['20', '31.25', '62.5', '125', '250', '500', '1000', '2000', '4000', '10000', '20000']
|
||||||
# self.PlotWidget.getAxis("bottom").setTicks([])
|
# self.PlotWidget.getAxis("bottom").setTicks([])
|
||||||
@ -421,15 +425,25 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
|
|||||||
|
|
||||||
def update_audio_visualization(self) -> None:
|
def update_audio_visualization(self) -> None:
|
||||||
"""Handles upading points on the pyqtgraph visual"""
|
"""Handles upading points on the pyqtgraph visual"""
|
||||||
self.clear_audio_visualization()
|
|
||||||
y = self.audio_visualizer.get_amplitudes()
|
y = self.audio_visualizer.get_amplitudes()
|
||||||
x = [i for i in range(len(y))]
|
if len(y) == 0:
|
||||||
# x = nparray([0, 31.25, 62.5, 125, 250, 500, 1000, 2000, 4000, 8000, 15000, 20000])
|
return
|
||||||
self.PlotWidget.plot(x, y, fillLevel=0, fillBrush=mkBrush("b"))
|
|
||||||
self.PlotWidget.show()
|
if self.audio_visualizer._plot_item is None:
|
||||||
|
self.PlotWidget.clear()
|
||||||
|
self.audio_visualizer._plot_item = self.PlotWidget.plot(
|
||||||
|
self.audio_visualizer._x_data,
|
||||||
|
y,
|
||||||
|
pen='b', # Use pen instead of fill for better performance
|
||||||
|
fillLevel=0,
|
||||||
|
fillBrush=mkBrush("b")
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
self.audio_visualizer._plot_item.setData(self.audio_visualizer._x_data, y)
|
||||||
|
|
||||||
def clear_audio_visualization(self) -> None:
|
def clear_audio_visualization(self) -> None:
|
||||||
self.PlotWidget.clear()
|
self.PlotWidget.clear()
|
||||||
|
self.audio_visualizer._plot_item = None
|
||||||
|
|
||||||
def move_slider(self) -> None:
|
def move_slider(self) -> None:
|
||||||
"""Handles moving the playback slider"""
|
"""Handles moving the playback slider"""
|
||||||
|
|||||||
14
ui.py
14
ui.py
@ -157,12 +157,6 @@ class Ui_MainWindow(object):
|
|||||||
self.hLayoutControls2.addWidget(self.volumeLabel)
|
self.hLayoutControls2.addWidget(self.volumeLabel)
|
||||||
self.hLayoutSongDetails = QtWidgets.QHBoxLayout()
|
self.hLayoutSongDetails = QtWidgets.QHBoxLayout()
|
||||||
self.hLayoutSongDetails.setObjectName("hLayoutSongDetails")
|
self.hLayoutSongDetails.setObjectName("hLayoutSongDetails")
|
||||||
self.titleLabel = QtWidgets.QLabel(self.centralwidget)
|
|
||||||
font = QtGui.QFont()
|
|
||||||
font.setPointSize(18)
|
|
||||||
self.titleLabel.setFont(font)
|
|
||||||
self.titleLabel.setObjectName("titleLabel")
|
|
||||||
self.hLayoutSongDetails.addWidget(self.titleLabel)
|
|
||||||
self.artistLabel = QtWidgets.QLabel(self.centralwidget)
|
self.artistLabel = QtWidgets.QLabel(self.centralwidget)
|
||||||
font = QtGui.QFont()
|
font = QtGui.QFont()
|
||||||
font.setPointSize(24)
|
font.setPointSize(24)
|
||||||
@ -171,6 +165,12 @@ class Ui_MainWindow(object):
|
|||||||
self.artistLabel.setFont(font)
|
self.artistLabel.setFont(font)
|
||||||
self.artistLabel.setObjectName("artistLabel")
|
self.artistLabel.setObjectName("artistLabel")
|
||||||
self.hLayoutSongDetails.addWidget(self.artistLabel)
|
self.hLayoutSongDetails.addWidget(self.artistLabel)
|
||||||
|
self.titleLabel = QtWidgets.QLabel(self.centralwidget)
|
||||||
|
font = QtGui.QFont()
|
||||||
|
font.setPointSize(18)
|
||||||
|
self.titleLabel.setFont(font)
|
||||||
|
self.titleLabel.setObjectName("titleLabel")
|
||||||
|
self.hLayoutSongDetails.addWidget(self.titleLabel)
|
||||||
self.albumLabel = QtWidgets.QLabel(self.centralwidget)
|
self.albumLabel = QtWidgets.QLabel(self.centralwidget)
|
||||||
font = QtGui.QFont()
|
font = QtGui.QFont()
|
||||||
font.setPointSize(16)
|
font.setPointSize(16)
|
||||||
@ -251,8 +251,6 @@ class Ui_MainWindow(object):
|
|||||||
self.playButton.setText(_translate("MainWindow", "▶️"))
|
self.playButton.setText(_translate("MainWindow", "▶️"))
|
||||||
self.nextButton.setText(_translate("MainWindow", "⏭️"))
|
self.nextButton.setText(_translate("MainWindow", "⏭️"))
|
||||||
self.volumeLabel.setText(_translate("MainWindow", "50"))
|
self.volumeLabel.setText(_translate("MainWindow", "50"))
|
||||||
self.artistLabel.setText(_translate("MainWindow", "artist"))
|
|
||||||
self.albumLabel.setText(_translate("MainWindow", "album"))
|
|
||||||
self.pushButton.setText(_translate("MainWindow", "nothing"))
|
self.pushButton.setText(_translate("MainWindow", "nothing"))
|
||||||
self.menuFile.setTitle(_translate("MainWindow", "File"))
|
self.menuFile.setTitle(_translate("MainWindow", "File"))
|
||||||
self.menuEdit.setTitle(_translate("MainWindow", "Edit"))
|
self.menuEdit.setTitle(_translate("MainWindow", "Edit"))
|
||||||
|
|||||||
22
ui.ui
22
ui.ui
@ -264,15 +264,6 @@
|
|||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="hLayoutSongDetails">
|
<layout class="QHBoxLayout" name="hLayoutSongDetails">
|
||||||
<item>
|
|
||||||
<widget class="QLabel" name="titleLabel">
|
|
||||||
<property name="font">
|
|
||||||
<font>
|
|
||||||
<pointsize>18</pointsize>
|
|
||||||
</font>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="artistLabel">
|
<widget class="QLabel" name="artistLabel">
|
||||||
<property name="font">
|
<property name="font">
|
||||||
@ -282,8 +273,14 @@
|
|||||||
<bold>true</bold>
|
<bold>true</bold>
|
||||||
</font>
|
</font>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
</widget>
|
||||||
<string>artist</string>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="titleLabel">
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<pointsize>18</pointsize>
|
||||||
|
</font>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@ -297,9 +294,6 @@
|
|||||||
<bold>false</bold>
|
<bold>false</bold>
|
||||||
</font>
|
</font>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
|
||||||
<string>album</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
|
|||||||
@ -24,7 +24,7 @@ class FFTAnalyser(QtCore.QThread):
|
|||||||
# this length is a number, in seconds, of how much audio is sampled to determine the frequencies
|
# this length is a number, in seconds, of how much audio is sampled to determine the frequencies
|
||||||
# of the audio at a specific point in time
|
# of the audio at a specific point in time
|
||||||
# in this case, it takes 5% of the samples at some point in time
|
# in this case, it takes 5% of the samples at some point in time
|
||||||
self.sampling_window_length = 0.09
|
self.sampling_window_length = 0.05
|
||||||
self.visual_delta_threshold = 1000
|
self.visual_delta_threshold = 1000
|
||||||
self.sensitivity = 10
|
self.sensitivity = 10
|
||||||
|
|
||||||
@ -124,7 +124,7 @@ class FFTAnalyser(QtCore.QThread):
|
|||||||
self.points[n] = 1e-5
|
self.points[n] = 1e-5
|
||||||
|
|
||||||
# interpolate points
|
# interpolate points
|
||||||
rs = gaussian_filter1d(self.points, sigma=2)
|
rs = gaussian_filter1d(self.points, sigma=1.5)
|
||||||
|
|
||||||
# divide by the highest sample in the song to normalise the
|
# divide by the highest sample in the song to normalise the
|
||||||
# amps in terms of decimals from 0 -> 1
|
# amps in terms of decimals from 0 -> 1
|
||||||
@ -142,4 +142,4 @@ class FFTAnalyser(QtCore.QThread):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
self.calculated_visual.emit(np.zeros(self.resolution))
|
self.calculated_visual.emit(np.zeros(self.resolution))
|
||||||
self.start_animate = False
|
self.start_animate = False
|
||||||
time.sleep(0.025)
|
time.sleep(0.033)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user