From ba5a015495a2b8cee8088cb24405aeb03bbcc3ea Mon Sep 17 00:00:00 2001 From: billypom on debian Date: Sun, 30 Mar 2025 20:49:05 -0400 Subject: [PATCH] working through what ffts doing --- main.py | 3 +-- utils/fft_analyser.py | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index e306bba..1810a84 100644 --- a/main.py +++ b/main.py @@ -160,7 +160,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 = 100 self.audio_visualizer: AudioVisualizer = AudioVisualizer(self.player, self.analyzer_x_resolution) self.timer = QTimer(self) # Audio timing things self.clipboard = clipboard @@ -563,7 +563,6 @@ 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 699dd87..c3de6a4 100644 --- a/utils/fft_analyser.py +++ b/utils/fft_analyser.py @@ -21,6 +21,7 @@ class FFTAnalyser(QtCore.QThread): self.player.currentMediaChanged.connect(self.reset_media) self.resolution = x_resolution + self.sampling_window_length = 0.05 self.visual_delta_threshold = 1000 self.sensitivity = 10 @@ -46,17 +47,25 @@ class FFTAnalyser(QtCore.QThread): def calculate_amps(self): """Calculates the amplitudes used for visualising the media.""" - sample_count = int(self.song.frame_rate * 0.05) + sample_count = int(self.song.frame_rate * self.sampling_window_length) start_index = int((self.player.position() / 1000) * self.song.frame_rate) v_sample = self.samples[ start_index : start_index + sample_count ] # samples to analyse + # use FFTs to analyse frequency and amplitudes fourier = np.fft.fft(v_sample) - freq = np.fft.fftfreq(fourier.size, d=0.05) + 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 + print(freq * .05 * self.song.frame_rate) + + # given 520 hz sine wave + # np.argmax(fourier) = 2374 + # freq[2374] * .05 * self.song.frame_rate = 520 + + # x values = freq * self.song.frame_rate * .05 point_range = 1 / self.resolution point_samples = [] @@ -97,7 +106,7 @@ class FFTAnalyser(QtCore.QThread): self.points[n] = 1e-5 # interpolate points - rs = gaussian_filter1d(self.points, sigma=4) + rs = gaussian_filter1d(self.points, sigma=2) # 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,7 +116,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) + # print(rs/self.max_sample) def run(self): """Runs the animate function depending on the song."""