2828import math as m
2929import numpy as np
3030
31- from scipy .interpolate import interp1d , CubicSpline
3231from PyQt5 import QtWidgets
3332from PyQt5 .QtCore import pyqtSignal , pyqtProperty # type: ignore
3433from PyQt5 .QtCore import QObject , QSettings , Qt
@@ -168,7 +167,6 @@ def calcKernel(f, freqList):
168167 return k
169168
170169
171-
172170class PitchTrackerWidget (QtWidgets .QWidget ):
173171 def __init__ (self , parent : QtWidgets .QWidget , engine : QQmlEngine ):
174172 super ().__init__ (parent )
@@ -445,11 +443,9 @@ def estimate_pitch(self, frame: np.ndarray) -> Optional[float]:
445443 freq_lin = np .arange (len (spectrum ), dtype = 'float64' )
446444 freq_lin *= float (self .sample_rate ) / float (self .fft_size )
447445
448- # Create a spline mapping from linear frequency to amplitude
449- spline_lin_to_log = interp1d (freq_lin , spectrum )
450-
446+ # Create spline mapping from linear frequency to amplitude
451447 # Apply this spline to the log-spaced frequencies and normalize
452- specLog = spline_lin_to_log (self .logSpacedFreqs )
448+ specLog = np . interp (self .logSpacedFreqs , freq_lin , spectrum )
453449 specLogRMS = np .sqrt (np .mean (specLog ** 2 ))
454450 specLogNorm = specLog / specLogRMS
455451
@@ -474,10 +470,8 @@ def estimate_pitch(self, frame: np.ndarray) -> Optional[float]:
474470 idxShift = 0
475471
476472 # Create a mapping from indices to frequencies
477- spline_idx_to_freq = CubicSpline (np .arange (len (self .logSpacedFreqs )),self .logSpacedFreqs )
478-
479473 # Apply spline to idxMax with a slight index shift
480- f0 = spline_idx_to_freq (idxMax + idxShift )
474+ f0 = np . interp (idxMax + idxShift , np . arange ( len ( self . logSpacedFreqs )), self . logSpacedFreqs )
481475
482476 # Check decibal value and confidence before output
483477 db = 10 * np .log10 (specLog [idxMax ] ** 2 / self .fft_size ** 2 )
0 commit comments