smst.models.harmonic module¶
Functions that implement analysis and synthesis of sounds using the Harmonic Model.
-
smst.models.harmonic.
find_fundamental_freq
(x, fs, w, N, H, t, minf0, maxf0, f0et)¶ Finds fundamental frequencies of a sound using the TWM (Two-Way Mismatch) algorithm.
Parameters: - x – input sound
- fs – sampling rate
- w – analysis window
- N – FFT size
- t – threshold in negative dB
- minf0 – minimum f0 frequency in Hz
- maxf0 – maximum f0 frequency in Hz
- f0et – error threshold in the f0 detection (ex: 5)
Returns: f0: fundamental frequency
-
smst.models.harmonic.
find_harmonics
(pfreq, pmag, pphase, f0, nH, hfreqp, fs, harmDevSlope=0.01)¶ Finds harmonics of a frame from a set of spectral peaks using f0 to the ideal harmonic series built on top of a fundamental frequency.
Parameters: - pfreq – peak frequencies
- pmag – peak magnitudes
- pphase – peak phases
- f0 – fundamental frequency
- nH – number of harmonics
- hfreqp – harmonic frequencies of previous frame
- fs – sampling rate
- harmDevSlope – slope of change of the deviation allowed to perfect harmonic
Returns: hfreq, hmag, hphase: harmonic frequencies, magnitudes, phases
-
smst.models.harmonic.
find_peaks
(N, fs, t, w, x_frame)¶
-
smst.models.harmonic.
from_audio
(x, fs, w, N, H, t, nH, minf0, maxf0, f0et, harmDevSlope=0.01, minSineDur=0.02)¶ Analyzes a sound using the sinusoidal harmonic model.
Parameters: - x – input sound
- fs – sampling rate
- w – analysis window
- N – FFT size (minimum 512)
- t – threshold in negative dB
- nH – maximum number of harmonics
- minf0 – minimum f0 frequency in Hz
- maxf0 – maximum f0 frequency in Hz
- f0et – error threshold in the f0 detection (ex: 5)
- harmDevSlope – slope of harmonic deviation
- minSineDur – minimum length of harmonics
Returns: xhfreq, xhmag, xhphase: harmonic frequencies, magnitudes and phases
-
smst.models.harmonic.
is_f0_stable
(f0, f0_prev)¶ Indicates whether a fundamental frequency in this frame is stable (if it does not deviate much from the previous one).
Parameters: - f0 – fundamental frequency in this frame (0 if not stable)
- f0_prev – fundamental frequency in previous frame (0 if not stable)
-
smst.models.harmonic.
scale_frequencies
(hfreq, hmag, freqScaling, freqStretching, timbrePreservation, fs)¶ Scales the frequencies of the harmonics of a sound.
Parameters: - hfreq – frequencies of input harmonics
- hmag – magnitudes of input harmonics
- freqScaling – scaling factors, in time-value pairs (value of 1 no scaling)
- freqStretching – stretching factors, in time-value pairs (value of 1 no stretching)
- timbrePreservation – 0 no timbre preservation, 1 timbre preservation
- fs – sampling rate of input sound
Returns: yhfreq, yhmag: frequencies and magnitudes of output harmonics