working through what ffts doing
This commit is contained in:
parent
f9fac746ae
commit
ba5a015495
3
main.py
3
main.py
@ -160,7 +160,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 = 100
|
||||||
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
|
||||||
@ -563,7 +563,6 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
|
|||||||
|
|
||||||
def process_probe(self, buff) -> None:
|
def process_probe(self, buff) -> None:
|
||||||
"""Audio visualizer buffer processing"""
|
"""Audio visualizer buffer processing"""
|
||||||
print('probe')
|
|
||||||
buff.startTime()
|
buff.startTime()
|
||||||
self.update_audio_visualization()
|
self.update_audio_visualization()
|
||||||
|
|
||||||
|
|||||||
@ -21,6 +21,7 @@ class FFTAnalyser(QtCore.QThread):
|
|||||||
self.player.currentMediaChanged.connect(self.reset_media)
|
self.player.currentMediaChanged.connect(self.reset_media)
|
||||||
|
|
||||||
self.resolution = x_resolution
|
self.resolution = x_resolution
|
||||||
|
self.sampling_window_length = 0.05
|
||||||
self.visual_delta_threshold = 1000
|
self.visual_delta_threshold = 1000
|
||||||
self.sensitivity = 10
|
self.sensitivity = 10
|
||||||
|
|
||||||
@ -46,17 +47,25 @@ class FFTAnalyser(QtCore.QThread):
|
|||||||
def calculate_amps(self):
|
def calculate_amps(self):
|
||||||
"""Calculates the amplitudes used for visualising the media."""
|
"""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)
|
start_index = int((self.player.position() / 1000) * self.song.frame_rate)
|
||||||
v_sample = self.samples[
|
v_sample = self.samples[
|
||||||
start_index : start_index + sample_count
|
start_index : start_index + sample_count
|
||||||
] # samples to analyse
|
] # samples to analyse
|
||||||
|
|
||||||
|
|
||||||
# use FFTs to analyse frequency and amplitudes
|
# use FFTs to analyse frequency and amplitudes
|
||||||
fourier = np.fft.fft(v_sample)
|
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)
|
amps = 2 / v_sample.size * np.abs(fourier)
|
||||||
data = np.array([freq, amps]).T
|
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_range = 1 / self.resolution
|
||||||
point_samples = []
|
point_samples = []
|
||||||
@ -97,7 +106,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=4)
|
rs = gaussian_filter1d(self.points, sigma=2)
|
||||||
|
|
||||||
# Mirror the amplitudes, these are renamed to 'rs' because we are using them
|
# 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
|
# 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
|
# they are divided 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
|
||||||
self.calculated_visual.emit(rs / self.max_sample)
|
self.calculated_visual.emit(rs / self.max_sample)
|
||||||
print(rs/self.max_sample)
|
# print(rs/self.max_sample)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
"""Runs the animate function depending on the song."""
|
"""Runs the animate function depending on the song."""
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user