librosax¶
- amplitude_to_db(S: Array, *, ref: float | Callable = 1.0, amin: float = 1e-05, top_db: float | None = 80.0) floating[Any] | Array ¶
Convert an amplitude spectrogram to decibel (dB) units.
This is equivalent to
power_to_db(S**2, ref=ref**2, amin=amin**2, top_db=top_db)
, but is provided for convenience.- Parameters:
S – Input amplitude spectrogram.
ref – Reference value for scaling. If scalar, the amplitude |S| is scaled relative to ref: 20 * log10(S / ref). If callable, the reference value is computed as ref(S). Default is 1.0.
amin – Minimum threshold for input values. Default is 1e-5.
top_db – Threshold the output at top_db below the peak. Default is 80.0.
- Returns:
dB-scaled spectrogram.
- Return type:
jnp.ndarray
See also
power_to_db, db_to_amplitude
- istft(stft_matrix: Array, hop_length: int = None, win_length: int = None, n_fft: int = None, window: str = 'hann', center: bool = True, length: int = None)¶
Compute the Inverse Short-Time Fourier Transform (ISTFT).
This function reconstructs a waveform from an STFT matrix using JAX’s
scipy.signal.istft
implementation.- Parameters:
stft_matrix – The STFT matrix from which to compute the inverse.
hop_length – Number of samples between successive frames. Default is
win_length // 4
.win_length – Window size. Default is
n_fft
.n_fft – FFT size. Default is
(stft_matrix.shape[-2] - 1) * 2
.window – Window function type. Default is
"hann"
.center – If
True
, assumes the waveform was padded so that frames were centered. Default isTrue
.length – Target length for the reconstructed signal. If None, the entire signal is returned.
- Returns:
Reconstructed time-domain signal.
- Return type:
jnp.ndarray
- Raises:
AssertionError – If center is
False
because the function is only tested forcenter=True
.
- power_to_db(x: Array, amin: float = 1e-10, top_db: float | None = 80.0, ref: float = 1.0) Array ¶
Convert a power spectrogram to decibel (dB) units.
This function is a JAX implementation of
librosa.power_to_db
.- Parameters:
x – Input power spectrogram.
amin – Minimum threshold for input values. Default is 1e-10.
top_db – Threshold the output at top_db below the peak. Default is 80.0.
ref – Reference value for scaling. Default is 1.0.
- Returns:
dB-scaled spectrogram.
- Return type:
jnp.ndarray
- Raises:
librosa.util.exceptions.ParameterError – If
top_db
is negative.
- stft(waveform: Array, n_fft: int, hop_length: int = None, win_length: int = None, window: str = 'hann', center: bool = True, pad_mode: str = 'constant')¶
Compute the Short-Time Fourier Transform (STFT) of a waveform.
This function computes the STFT of the given waveform using JAX’s
scipy.signal.stft
implementation.- Parameters:
waveform – Input signal waveform.
n_fft – FFT size.
hop_length – Number of samples between successive frames. Default is
win_length // 4
.win_length – Window size. Default is
n_fft
.window – Window function type. Default is
"hann"
.center – If
True
, the waveform is padded so that frames are centered. Default isTrue
.pad_mode – Padding mode for the waveform. Must be one of
["constant", "reflect"]
. Default is"constant"
.
- Returns:
Complex STFT matrix.
- Return type:
jnp.ndarray
- Raises:
AssertionError – If pad_mode is not one of
["constant", "reflect"]
.