Disable unreliable parabolic interpolation when pitch tracking (#286)

pull/357/head
nyanpasu64 2019-05-09 03:21:42 -07:00 zatwierdzone przez GitHub
rodzic 3a5bb2a001
commit 86e55b006c
2 zmienionych plików z 11 dodań i 26 usunięć

Wyświetl plik

@ -603,7 +603,6 @@ class InterpolatedCorrelationResult:
corr: np.ndarray corr: np.ndarray
# TODO use parabolic() for added precision when trigger subsampling enabled
def correlate_data( def correlate_data(
data: np.ndarray, prev_buffer: np.ndarray, radius: Optional[int] data: np.ndarray, prev_buffer: np.ndarray, radius: Optional[int]
) -> CorrelationResult: ) -> CorrelationResult:
@ -642,29 +641,16 @@ def correlate_data(
def correlate_spectrum( def correlate_spectrum(
data: np.ndarray, prev_buffer: np.ndarray, radius: Optional[int] data: np.ndarray, prev_buffer: np.ndarray, radius: Optional[int]
) -> InterpolatedCorrelationResult: ) -> CorrelationResult:
N = len(data) """
corr = signal.correlate(data, prev_buffer) # returns double, not single/FLOAT I used to use parabolic() on the return value,
Ncorr = 2 * N - 1 but unfortunately it was unreliable and caused Plok Beach bass to jitter,
assert len(corr) == Ncorr so I turned it off (resulting in the same code as correlate_data).
"""
# Find optimal offset return correlate_data(data, prev_buffer, radius)
mid = N - 1
if radius is not None:
left = max(mid - radius, 0)
right = min(mid + radius + 1, Ncorr)
corr = corr[left:right]
mid = mid - left
# argmax(corr) == mid + peak_offset == (data >> peak_offset)
# peak_offset == argmax(corr) - mid
peak_offset = parabolic(corr, np.argmax(corr)) - mid # type: float
return InterpolatedCorrelationResult(peak_offset, corr)
def parabolic(ys: np.ndarray, xint: int) -> float: def parabolic(xint: int, ys: np.ndarray) -> float:
""" """
Quadratic interpolation for estimating the true position of an inter-sample maximum Quadratic interpolation for estimating the true position of an inter-sample maximum
when nearby samples are known. when nearby samples are known.

Wyświetl plik

@ -243,11 +243,10 @@ def test_correlate_offset(correlate):
""" """
Catches bug where writing N instead of Ncorr Catches bug where writing N instead of Ncorr
prevented function from returning positive numbers. prevented function from returning positive numbers.
Right now, correlate_spectrum() is identical to correlate_data().
""" """
if correlate == correlate_spectrum: approx = lambda x: x
approx = lambda x: pytest.approx(x, rel=0.5)
else:
approx = lambda x: x
np.random.seed(31337) np.random.seed(31337)