kopia lustrzana https://github.com/corrscope/corrscope
Improve Wave.get_around() parameter naming
return_nsamp is unambiguous. region_nsamp was ambiguous.pull/357/head
rodzic
96edbdd2c4
commit
fbb6bf0883
|
@ -5,7 +5,6 @@ import warnings
|
|||
import attr
|
||||
import corrscope.utils.scipy_wavfile as wavfile
|
||||
|
||||
|
||||
from corrscope.config import CorrError, CorrWarning
|
||||
|
||||
|
||||
|
@ -122,11 +121,14 @@ class Wave:
|
|||
|
||||
return out
|
||||
|
||||
def get_around(self, sample: int, region_nsamp: int, stride: int):
|
||||
""" Copies self.data[...] """
|
||||
region_nsamp *= stride
|
||||
end = sample + region_nsamp // 2
|
||||
begin = end - region_nsamp
|
||||
def get_around(self, sample: int, return_nsamp: int, stride: int):
|
||||
""" Returns `return_nsamp` samples, centered around `sample`,
|
||||
sampled with spacing `stride`.
|
||||
|
||||
Copies self.data[...] """
|
||||
distance = return_nsamp * stride
|
||||
end = sample + distance // 2
|
||||
begin = end - distance
|
||||
return self._get(begin, end, stride)
|
||||
|
||||
def get_s(self) -> float:
|
||||
|
|
|
@ -67,8 +67,8 @@ def test_config_channel_width_stride(
|
|||
Wave = mocker.patch.object(corrscope.channel, "Wave")
|
||||
wave = Wave.return_value
|
||||
|
||||
def get_around(sample: int, region_nsamp: int, stride: int):
|
||||
return np.zeros(region_nsamp)
|
||||
def get_around(sample: int, return_nsamp: int, stride: int):
|
||||
return np.zeros(return_nsamp)
|
||||
|
||||
wave.get_around.side_effect = get_around
|
||||
wave.nsamp = 10000
|
||||
|
@ -134,8 +134,8 @@ def test_config_channel_width_stride(
|
|||
corr.play()
|
||||
|
||||
# Only render (not NullTrigger) calls wave.get_around().
|
||||
(_sample, _region_nsamp, _subsampling), kwargs = wave.get_around.call_args
|
||||
assert _region_nsamp == channel.render_samp
|
||||
(_sample, _return_nsamp, _subsampling), kwargs = wave.get_around.call_args
|
||||
assert _return_nsamp == channel.render_samp
|
||||
assert _subsampling == channel.render_stride
|
||||
|
||||
# Inspect arguments to renderer.render_frame()
|
||||
|
|
|
@ -80,7 +80,7 @@ def test_wave_subsampling():
|
|||
wave = Wave(None, "tests/sine440.wav")
|
||||
# period = 48000 / 440 = 109.(09)*
|
||||
|
||||
wave.get_around(1000, region_nsamp=501, stride=4)
|
||||
wave.get_around(1000, return_nsamp=501, stride=4)
|
||||
# len([:region_len:subsampling]) == ceil(region_len / subsampling)
|
||||
# If region_len % subsampling != 0, len() != region_len // subsampling.
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue