corrscope/ovgenpy/channel.py

60 wiersze
1.7 KiB
Python
Czysty Zwykły widok Historia

from typing import TYPE_CHECKING, Any
2018-07-20 21:19:43 +00:00
2018-07-27 04:31:46 +00:00
from ovgenpy.config import register_config
from ovgenpy.wave import _WaveConfig, Wave
2018-07-27 04:31:46 +00:00
2018-07-20 21:19:43 +00:00
if TYPE_CHECKING:
from ovgenpy.triggers import ITriggerConfig
2018-07-20 21:19:43 +00:00
from ovgenpy.ovgenpy import Config
2018-07-27 04:31:46 +00:00
@register_config
class ChannelConfig:
wav_path: str
2018-07-27 04:31:46 +00:00
trigger: 'ITriggerConfig' = None # TODO test channel-specific triggers
2018-07-27 04:31:46 +00:00
trigger_width_ratio: int = 1
render_width_ratio: int = 1
ampl_ratio: float = 1.0 # TODO use amplification = None instead?
2018-07-27 04:31:46 +00:00
line_color: Any = None
2018-07-20 21:19:43 +00:00
class Channel:
2018-08-24 06:52:11 +00:00
# Shared between trigger and renderer.
2018-08-26 01:50:57 +00:00
window_samp: int
2018-08-24 06:52:11 +00:00
# Product of ovgen_cfg.subsampling and trigger/render_width_ratio.
trigger_subsampling: int
render_subsampling: int
def __init__(self, cfg: ChannelConfig, ovgen_cfg: 'Config'):
2018-07-20 21:19:43 +00:00
self.cfg = cfg
2018-08-24 06:52:11 +00:00
subsampling = ovgen_cfg.subsampling
2018-08-24 06:52:11 +00:00
# Create a Wave object.
wcfg = _WaveConfig(amplification=ovgen_cfg.amplification * cfg.ampl_ratio)
self.wave = Wave(wcfg, cfg.wav_path)
2018-08-24 06:52:11 +00:00
# Compute subsampling (array stride).
self.trigger_subsampling = subsampling * cfg.trigger_width_ratio
self.render_subsampling = subsampling * cfg.render_width_ratio
2018-08-26 01:50:57 +00:00
# Compute window_samp and tsamp_frame.
nsamp = ovgen_cfg.render_width_s * self.wave.smp_s / subsampling
2018-08-26 01:50:57 +00:00
self.window_samp = round(nsamp)
2018-08-24 06:52:11 +00:00
del subsampling
del nsamp
# Create a Trigger object.
tcfg = cfg.trigger or ovgen_cfg.trigger
self.trigger = tcfg(
wave=self.wave,
2018-08-26 01:50:57 +00:00
tsamp=self.window_samp,
subsampling=self.trigger_subsampling,
fps=ovgen_cfg.fps
)