Skip to content
Snippets Groups Projects
Commit 5db537c4 authored by Loic-Lenof's avatar Loic-Lenof
Browse files

bug fixing

+ improved wave_to_spectrogram
+ fixed entry fields not updating at file change
parent 60f5ae3a
No related branches found
No related tags found
No related merge requests found
......@@ -59,7 +59,7 @@ def load_waveform(wavefile_name, sr_resample):
return wavefile_dec
def wave_to_spectrogram(waveform, SR, n_fft, w_size, clip, as_pcen=False):
def wave_to_spectrogram(waveform, SR, n_fft, w_size, clip, as_pcen=False, top_db=160):
"""
A function that transforms any given waveform to a spectrogram.
......@@ -83,6 +83,9 @@ def wave_to_spectrogram(waveform, SR, n_fft, w_size, clip, as_pcen=False):
Whether the returned image should be a PCEN or not.
Aka : spectrogram with enhanced contrast.
Default is False.
top_db : float, optional.
Thresholds the output at top_db for amplitude_to_db function.
Default is 80.
Returns
-------
......@@ -91,21 +94,21 @@ def wave_to_spectrogram(waveform, SR, n_fft, w_size, clip, as_pcen=False):
audio_length : float
Duration of the audio in seconds.
"""
base = np.abs(stft(
spectrum = np.abs(stft(
waveform,
n_fft=n_fft,
hop_length=w_size))
spectro_pcen = pcen(base * (2**31), bias=10)
spectro_og = amplitude_to_db(base)
if as_pcen:
spectro_pcen = pcen(spectrum * (2**31), bias=10)
spectro_og = amplitude_to_db(spectrum, top_db=top_db)
spectro_og = spectro_og - (np.max(spectro_og))
spectro_og[spectro_og < clip] = np.nan
if as_pcen:
spectro_pcen[np.isnan(spectro_og)] = np.nan
spectro_pcen[spectro_og < clip] = np.min(spectro_pcen)
spectro = spectro_pcen
else:
spectro_og[spectro_og < clip] = clip
spectro = spectro_og
audio_length = len(waveform)/SR
......
......@@ -559,6 +559,7 @@ class App(object):
self.canvas.get_tk_widget().destroy()
# load new data
self.setup()
self.load_audio()
self.create_canvas()
self.NAME0 = 0
......@@ -581,8 +582,6 @@ class App(object):
def setup(self):
"""
A function to create variables based on default values
This is a security to avoid mixing default values with new values
during use... But it could be removed.
"""
self.NFFT = self._default_nfft
self.HOP_LENGTH = self._default_hop_length
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment