kopia lustrzana https://github.com/corrscope/corrscope
Add iround(x) = int(round(x)) (because round(np.float32) is not int)
rodzic
bbb4b1e7a6
commit
0dc8f8bbca
|
@ -44,7 +44,7 @@ from corrscope.triggers import (
|
|||
SpectrumConfig,
|
||||
ZeroCrossingTriggerConfig,
|
||||
)
|
||||
from corrscope.util import obj_name
|
||||
from corrscope.util import obj_name, iround
|
||||
from corrscope.wave import Flatten
|
||||
|
||||
FILTER_WAV_FILES = ["WAV files (*.wav)"]
|
||||
|
@ -514,7 +514,7 @@ class CorrProgressDialog(qw.QProgressDialog):
|
|||
|
||||
@qc.pyqtSlot(float, float)
|
||||
def on_begin(self, begin_time, end_time):
|
||||
self.setRange(int(round(begin_time)), int(round(end_time)))
|
||||
self.setRange(iround(begin_time), iround(end_time))
|
||||
# self.setValue is called by CorrScope, on the first frame.
|
||||
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ import numpy as np
|
|||
import corrscope.utils.scipy.signal as signal
|
||||
import corrscope.utils.scipy.windows as windows
|
||||
from corrscope.config import KeywordAttrs, CorrError, Alias, with_units
|
||||
from corrscope.util import find, obj_name
|
||||
from corrscope.util import find, obj_name, iround
|
||||
from corrscope.utils.windows import midpad, leftpad
|
||||
from corrscope.wave import FLOAT
|
||||
|
||||
|
@ -599,7 +599,7 @@ class CorrelationTrigger(MainTrigger):
|
|||
# Find spectral correlation peak,
|
||||
# but prioritize "changing pitch by ???".
|
||||
if peak_semitones is not None:
|
||||
boost_x = int(round(peak_semitones / 12 * scfg.notes_per_octave))
|
||||
boost_x = iround(peak_semitones / 12 * scfg.notes_per_octave)
|
||||
boost_y: float = scfg.pitch_estimate_boost
|
||||
else:
|
||||
boost_x = 0
|
||||
|
@ -615,7 +615,7 @@ class CorrelationTrigger(MainTrigger):
|
|||
)
|
||||
if resample_notes != 0:
|
||||
# we must divide sampling rate by 2.
|
||||
new_len = int(round(N / 2 ** (resample_notes / scfg.notes_per_octave)))
|
||||
new_len = iround(N / 2 ** (resample_notes / scfg.notes_per_octave))
|
||||
|
||||
# Copy+resample self._buffer.
|
||||
self._buffer = np.interp(
|
||||
|
|
|
@ -3,11 +3,28 @@ import sys
|
|||
from contextlib import contextmanager
|
||||
from itertools import chain
|
||||
from pathlib import Path
|
||||
from typing import Callable, Tuple, TypeVar, Iterator, Union, Optional, Any, cast
|
||||
from typing import (
|
||||
Callable,
|
||||
Tuple,
|
||||
TypeVar,
|
||||
Iterator,
|
||||
Union,
|
||||
Optional,
|
||||
Any,
|
||||
cast,
|
||||
SupportsRound,
|
||||
)
|
||||
|
||||
import numpy as np
|
||||
|
||||
|
||||
def iround(x: SupportsRound) -> int:
|
||||
"""Rounds x and converts to int.
|
||||
Because round(np.float32) returns np.float32 instead of int.
|
||||
"""
|
||||
return int(round(x))
|
||||
|
||||
|
||||
def ceildiv(n: int, d: int) -> int:
|
||||
return -(-n // d)
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue