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.start()
|
||||
self.amps = np.array([])
|
||||
self._plot_item = None
|
||||
self._x_data = np.arange(self.x_resolution)
|
||||
|
||||
def get_amplitudes(self):
|
||||
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.player: QMediaPlayer = QMediaPlayer() # Audio player object
|
||||
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.timer = QTimer(self) # Audio timing things
|
||||
self.clipboard = clipboard
|
||||
@ -187,6 +187,10 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
|
||||
self.PlotWidget.setYRange(0, 1, padding=0) # y axis range
|
||||
self.PlotWidget.setLogMode(False, 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
|
||||
# ticks = ['20', '31.25', '62.5', '125', '250', '500', '1000', '2000', '4000', '10000', '20000']
|
||||
# self.PlotWidget.getAxis("bottom").setTicks([])
|
||||
@ -421,15 +425,25 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
|
||||
|
||||
def update_audio_visualization(self) -> None:
|
||||
"""Handles upading points on the pyqtgraph visual"""
|
||||
self.clear_audio_visualization()
|
||||
y = self.audio_visualizer.get_amplitudes()
|
||||
x = [i for i in range(len(y))]
|
||||
# x = nparray([0, 31.25, 62.5, 125, 250, 500, 1000, 2000, 4000, 8000, 15000, 20000])
|
||||
self.PlotWidget.plot(x, y, fillLevel=0, fillBrush=mkBrush("b"))
|
||||
self.PlotWidget.show()
|
||||
if len(y) == 0:
|
||||
return
|
||||
|
||||
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:
|
||||
self.PlotWidget.clear()
|
||||
self.audio_visualizer._plot_item = None
|
||||
|
||||
def move_slider(self) -> None:
|
||||
"""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.hLayoutSongDetails = QtWidgets.QHBoxLayout()
|
||||
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)
|
||||
font = QtGui.QFont()
|
||||
font.setPointSize(24)
|
||||
@ -171,6 +165,12 @@ class Ui_MainWindow(object):
|
||||
self.artistLabel.setFont(font)
|
||||
self.artistLabel.setObjectName("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)
|
||||
font = QtGui.QFont()
|
||||
font.setPointSize(16)
|
||||
@ -251,8 +251,6 @@ class Ui_MainWindow(object):
|
||||
self.playButton.setText(_translate("MainWindow", "▶️"))
|
||||
self.nextButton.setText(_translate("MainWindow", "⏭️"))
|
||||
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.menuFile.setTitle(_translate("MainWindow", "File"))
|
||||
self.menuEdit.setTitle(_translate("MainWindow", "Edit"))
|
||||
|
||||
22
ui.ui
22
ui.ui
@ -264,15 +264,6 @@
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="hLayoutSongDetails">
|
||||
<item>
|
||||
<widget class="QLabel" name="titleLabel">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>18</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="artistLabel">
|
||||
<property name="font">
|
||||
@ -282,8 +273,14 @@
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>artist</string>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="titleLabel">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>18</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -297,9 +294,6 @@
|
||||
<bold>false</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>album</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</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
|
||||
# of the audio at a specific 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.sensitivity = 10
|
||||
|
||||
@ -124,7 +124,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=1.5)
|
||||
|
||||
# divide by the highest sample in the song to normalise the
|
||||
# amps in terms of decimals from 0 -> 1
|
||||
@ -142,4 +142,4 @@ class FFTAnalyser(QtCore.QThread):
|
||||
except ValueError:
|
||||
self.calculated_visual.emit(np.zeros(self.resolution))
|
||||
self.start_animate = False
|
||||
time.sleep(0.025)
|
||||
time.sleep(0.033)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user