2018-07-28 11:06:27 +00:00
|
|
|
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
|
2018-07-28 11:06:27 +00:00
|
|
|
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:
|
2018-07-28 11:06:27 +00:00
|
|
|
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:
|
2018-07-28 11:06:27 +00:00
|
|
|
wav_path: str
|
2018-07-27 04:31:46 +00:00
|
|
|
|
2018-07-28 11:06:27 +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
|
|
|
|
|
2018-07-28 11:06:27 +00:00
|
|
|
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
|
|
|
|
|
2018-07-28 11:06:27 +00:00
|
|
|
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-07-28 11:06:27 +00:00
|
|
|
|
2018-08-24 06:52:11 +00:00
|
|
|
# Create a Wave object.
|
2018-07-28 11:06:27 +00:00
|
|
|
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-25 10:21:53 +00:00
|
|
|
|
2018-08-26 01:50:57 +00:00
|
|
|
# Compute window_samp and tsamp_frame.
|
2018-08-25 10:21:53 +00:00
|
|
|
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-25 10:21:53 +00:00
|
|
|
|
2018-08-24 06:52:11 +00:00
|
|
|
del subsampling
|
2018-08-25 10:21:53 +00:00
|
|
|
del nsamp
|
|
|
|
|
2018-07-28 11:06:27 +00:00
|
|
|
# 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,
|
2018-08-25 10:21:53 +00:00
|
|
|
subsampling=self.trigger_subsampling,
|
2018-08-26 01:18:47 +00:00
|
|
|
fps=ovgen_cfg.fps
|
2018-07-28 11:06:27 +00:00
|
|
|
)
|
|
|
|
|