kopia lustrzana https://github.com/corrscope/corrscope
Remove class _WaveConfig, replace with kwargs
rodzic
4c60a240c7
commit
269f9b2acc
|
@ -6,7 +6,7 @@ from ruamel.yaml.comments import CommentedMap
|
|||
|
||||
from corrscope.config import DumpableAttrs, Alias, CorrError
|
||||
from corrscope.triggers import ITriggerConfig
|
||||
from corrscope.wave import _WaveConfig, Wave
|
||||
from corrscope.wave import Wave
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from corrscope.corrscope import Config
|
||||
|
@ -46,8 +46,9 @@ class Channel:
|
|||
self.cfg = cfg
|
||||
|
||||
# Create a Wave object.
|
||||
wcfg = _WaveConfig(amplification=corr_cfg.amplification * cfg.ampl_ratio)
|
||||
self.wave = Wave(wcfg, abspath(cfg.wav_path))
|
||||
self.wave = Wave(
|
||||
abspath(cfg.wav_path), amplification=corr_cfg.amplification * cfg.ampl_ratio
|
||||
)
|
||||
|
||||
# `subsampling` increases `stride` and decreases `nsamp`.
|
||||
# `width` increases `stride` without changing `nsamp`.
|
||||
|
|
|
@ -43,14 +43,6 @@ _rejected_modes = {Flatten.Mono, Flatten.IsAvg}
|
|||
Flatten.modes = [f for f in Flatten.__members__.values() if f not in _rejected_modes]
|
||||
|
||||
|
||||
@attr.dataclass(kw_only=True)
|
||||
class _WaveConfig:
|
||||
"""Internal class, not exposed via YAML"""
|
||||
|
||||
amplification: float = 1
|
||||
_flatten: Flatten = Flatten.SumAvg
|
||||
|
||||
|
||||
class Wave:
|
||||
__slots__ = """
|
||||
wave_path
|
||||
|
@ -94,15 +86,19 @@ class Wave:
|
|||
f"Cannot initialize stereo file {self.wave_path} with flatten=Mono"
|
||||
)
|
||||
|
||||
def __init__(self, cfg: Optional[_WaveConfig], wave_path: str):
|
||||
def __init__(
|
||||
self,
|
||||
wave_path: str,
|
||||
amplification: float = 1.0,
|
||||
flatten: Flatten = Flatten.SumAvg,
|
||||
):
|
||||
self.wave_path = wave_path
|
||||
cfg = cfg or _WaveConfig()
|
||||
self.amplification = cfg.amplification
|
||||
self.amplification = amplification
|
||||
self.smp_s, self.data = wavfile.read(wave_path, mmap=True)
|
||||
|
||||
assert self.data.ndim in [1, 2]
|
||||
self.is_mono = self.data.ndim == 1
|
||||
self.flatten = cfg._flatten
|
||||
self.flatten = flatten
|
||||
|
||||
# Cast self.data to stereo (nsamp, nchan)
|
||||
if self.is_mono:
|
||||
|
|
|
@ -147,7 +147,7 @@ def test_load_yaml_another_dir(mocker, Popen):
|
|||
|
||||
# Test `wave_path`
|
||||
args, kwargs = Wave.call_args
|
||||
cfg, wave_path = args
|
||||
(wave_path,) = args
|
||||
assert wave_path == wav_abs
|
||||
|
||||
# Test output `master_audio` and video `path`
|
||||
|
|
|
@ -46,7 +46,7 @@ FPS = 60
|
|||
|
||||
|
||||
def test_trigger(cfg: CorrelationTriggerConfig):
|
||||
wave = Wave(None, "tests/impulse24000.wav")
|
||||
wave = Wave("tests/impulse24000.wav")
|
||||
|
||||
iters = 5
|
||||
plot = False
|
||||
|
@ -78,7 +78,7 @@ def test_trigger(cfg: CorrelationTriggerConfig):
|
|||
|
||||
|
||||
def test_trigger_stride(cfg: CorrelationTriggerConfig):
|
||||
wave = Wave(None, "tests/sine440.wav")
|
||||
wave = Wave("tests/sine440.wav")
|
||||
# period = 48000 / 440 = 109.(09)*
|
||||
|
||||
iters = 5
|
||||
|
@ -120,7 +120,7 @@ def test_trigger_stride(cfg: CorrelationTriggerConfig):
|
|||
def test_post_trigger_stride(post_cfg: CorrelationTriggerConfig):
|
||||
cfg = post_cfg
|
||||
|
||||
wave = Wave(None, "tests/sine440.wav")
|
||||
wave = Wave("tests/sine440.wav")
|
||||
iters = 5
|
||||
x0 = 24000
|
||||
stride = 4
|
||||
|
@ -141,7 +141,7 @@ def test_post_trigger_stride(post_cfg: CorrelationTriggerConfig):
|
|||
|
||||
|
||||
def test_trigger_stride_edges(cfg: CorrelationTriggerConfig):
|
||||
wave = Wave(None, "tests/sine440.wav")
|
||||
wave = Wave("tests/sine440.wav")
|
||||
# period = 48000 / 440 = 109.(09)*
|
||||
|
||||
stride = 4
|
||||
|
@ -156,7 +156,7 @@ def test_trigger_stride_edges(cfg: CorrelationTriggerConfig):
|
|||
|
||||
def test_trigger_should_recalc_window():
|
||||
cfg = cfg_template(recalc_semitones=1.0)
|
||||
wave = Wave(None, "tests/sine440.wav")
|
||||
wave = Wave("tests/sine440.wav")
|
||||
trigger: CorrelationTrigger = cfg(wave, tsamp=1000, stride=1, fps=FPS)
|
||||
|
||||
for x in [0, 1, 1000]:
|
||||
|
|
|
@ -28,7 +28,7 @@ def test_wave(wave_path):
|
|||
# Cause all warnings to always be triggered.
|
||||
warnings.simplefilter("always")
|
||||
|
||||
wave = Wave(None, prefix + wave_path)
|
||||
wave = Wave(prefix + wave_path)
|
||||
data = wave[:]
|
||||
|
||||
# Audacity dithers <=16-bit WAV files upon export, creating a few bits of noise.
|
||||
|
@ -49,7 +49,7 @@ def test_stereo_merge():
|
|||
|
||||
# Contains a full-scale sine wave in left channel, and silence in right.
|
||||
# λ=100, nsamp=2000
|
||||
wave = Wave(None, prefix + "stereo-sine-left-2000.wav")
|
||||
wave = Wave(prefix + "stereo-sine-left-2000.wav")
|
||||
period = 100
|
||||
nsamp = 2000
|
||||
|
||||
|
@ -84,7 +84,7 @@ ValidFlattens = hs.sampled_from(Flatten.modes)
|
|||
def test_stereo_flatten_modes(flatten: Flatten):
|
||||
"""Ensures all Flatten modes are handled properly
|
||||
for stereo and mono signals."""
|
||||
wave = Wave(None, "tests/stereo in-phase.wav")
|
||||
wave = Wave("tests/stereo in-phase.wav")
|
||||
|
||||
if flatten not in Flatten.modes:
|
||||
with pytest.raises(CorrError):
|
||||
|
@ -110,7 +110,7 @@ def test_stereo_flatten_modes(flatten: Flatten):
|
|||
|
||||
|
||||
def test_stereo_mmap():
|
||||
wave = Wave(None, prefix + "stereo-sine-left-2000.wav")
|
||||
wave = Wave(prefix + "stereo-sine-left-2000.wav")
|
||||
assert isinstance(wave.data, np.memmap)
|
||||
|
||||
|
||||
|
@ -118,7 +118,7 @@ def test_stereo_mmap():
|
|||
|
||||
|
||||
def test_wave_subsampling():
|
||||
wave = Wave(None, "tests/sine440.wav")
|
||||
wave = Wave("tests/sine440.wav")
|
||||
# period = 48000 / 440 = 109.(09)*
|
||||
|
||||
wave.get_around(1000, return_nsamp=501, stride=4)
|
||||
|
@ -134,7 +134,7 @@ def test_wave_subsampling():
|
|||
|
||||
def test_stereo_doesnt_overflow():
|
||||
""" Ensure loud stereo tracks do not overflow. """
|
||||
wave = Wave(None, "tests/stereo in-phase.wav")
|
||||
wave = Wave("tests/stereo in-phase.wav")
|
||||
|
||||
samp = 100
|
||||
stride = 1
|
||||
|
@ -159,5 +159,5 @@ def test_header_larger_than_filesize():
|
|||
My version instead accepts such files (but warns WavFileWarning).
|
||||
"""
|
||||
with pytest.warns(WavFileWarning):
|
||||
wave = Wave(None, "tests/header larger than filesize.wav")
|
||||
wave = Wave("tests/header larger than filesize.wav")
|
||||
assert wave
|
||||
|
|
Ładowanie…
Reference in New Issue