Esempio n. 1
0
class ChannelConfig(DumpableAttrs):
    wav_path: str
    label: str = ""

    # Supplying a dict inherits attributes from global trigger.
    # TODO test channel-specific triggers
    trigger: Union[MainTriggerConfig, Dict[str, Any], None] = attr.Factory(dict)

    # Multiplies how wide the window is, in milliseconds.
    trigger_width: int = 1
    render_width: int = 1

    # Overrides global amplification.
    amplification: Optional[float] = None

    # Stereo config
    trigger_stereo: Optional[FlattenOrStr] = None
    render_stereo: Optional[FlattenOrStr] = None

    line_color: Optional[str] = None
    color_by_pitch: Optional[bool] = None

    # region Legacy Fields
    trigger_width_ratio = Alias("trigger_width")
    render_width_ratio = Alias("render_width")
Esempio n. 2
0
class CorrelationTriggerConfig(
        MainTriggerConfig,
        always_dump="""
    pitch_tracking
    slope_strength slope_width
    """

        # deprecated
        " buffer_falloff ",
):
    # get_trigger()
    # Edge/area finding
    sign_strength: float = 0
    edge_strength: float

    # Slope detection
    slope_strength: float = 0
    slope_width: float = with_units("period", default=0.07)

    # Correlation detection (meow~ =^_^=)
    buffer_strength: float = 1

    # Both data and buffer uses Gaussian windows. std = wave_period * falloff.
    # get_trigger()
    data_falloff: float = 1.5

    # _update_buffer()
    buffer_falloff: float = 0.5

    # Maximum distance to move
    trigger_diameter: Optional[float] = 0.5

    recalc_semitones: float = 1.0
    lag_prevention: LagPrevention = attr.ib(factory=LagPrevention)

    # _update_buffer
    responsiveness: float

    # Period/frequency estimation (not in GUI)
    max_freq: float = with_units("Hz", default=4000)

    # Pitch tracking = compute spectrum.
    pitch_tracking: Optional["SpectrumConfig"] = None

    # region Legacy Aliases
    trigger_strength = Alias("edge_strength")
    falloff_width = Alias("buffer_falloff")

    # endregion

    def __attrs_post_init__(self) -> None:
        MainTriggerConfig.__attrs_post_init__(self)

        validate_param(self, "slope_width", 0, 0.5)

        validate_param(self, "responsiveness", 0, 1)
        # TODO trigger_falloff >= 0
        validate_param(self, "buffer_falloff", 0, np.inf)
Esempio n. 3
0
class CorrelationTriggerConfig(ITriggerConfig):
    # get_trigger
    edge_strength: float
    trigger_diameter: float = 0.5

    trigger_falloff: Tuple[float, float] = (4.0, 1.0)
    recalc_semitones: float = 1.0
    lag_prevention: float = 0.25

    # _update_buffer
    responsiveness: float
    buffer_falloff: float  # Gaussian std = wave_period * buffer_falloff

    # region Legacy Aliases
    trigger_strength = Alias("edge_strength")
    falloff_width = Alias("buffer_falloff")
    use_edge_trigger: bool

    # endregion

    def __attrs_post_init__(self) -> None:
        self._validate_param("lag_prevention", 0, 1)
        self._validate_param("responsiveness", 0, 1)
        # TODO trigger_falloff >= 0
        self._validate_param("buffer_falloff", 0, np.inf)

        if self.use_edge_trigger:
            if self.post:
                warnings.warn(
                    "Ignoring old `CorrelationTriggerConfig.use_edge_trigger` flag, "
                    "overriden by newer `post` flag.",
                    CorrWarning,
                )
            else:
                self.post = ZeroCrossingTriggerConfig()

    def _validate_param(self, key: str, begin: float, end: float) -> None:
        value = getattr(self, key)
        if not begin <= value <= end:
            raise CorrError(
                f"Invalid {key}={value} (should be within [{begin}, {end}])")
Esempio n. 4
0
 class Config(DumpableAttrs, kw_only=False):
     x: int
     xx = Alias("x")
Esempio n. 5
0
class CorrelationTriggerConfig(
        MainTriggerConfig,
        always_dump="""
    mean_responsiveness
    pitch_tracking
    slope_width
    """

        # deprecated
        " buffer_falloff ",
):
    # get_trigger()
    # Edge/area finding
    sign_strength: float = 0
    mean_responsiveness: float = 1.0
    edge_strength: float

    # Slope detection
    slope_width: float = with_units("period", default=0.25)

    # Correlation detection
    buffer_strength: float = 1

    # Below a specific correlation quality, discard the buffer entirely.
    reset_below: float = 0

    # _update_buffer() (not in GUI)
    buffer_falloff: float = 0.5

    # Maximum distance to move (in terms of trigger_ms/trigger_samp) (not in GUI)
    trigger_diameter: float = 0.5

    # Maximum distance to move (in terms of estimated wave period) (not in GUI)
    trigger_radius_periods: Optional[float] = 1.5

    # (not in GUI)
    recalc_semitones: float = 1.0

    # _update_buffer
    responsiveness: float

    # Period/frequency estimation (not in GUI)
    max_freq: float = with_units("Hz", default=4000)

    # Pitch tracking = compute spectrum. (GUI only has a checkbox)
    pitch_tracking: Optional[SpectrumConfig] = None

    # region Legacy Aliases
    trigger_strength = Alias("edge_strength")
    falloff_width = Alias("buffer_falloff")
    data_falloff = Alias("trigger_radius_periods")

    # endregion

    def __attrs_post_init__(self) -> None:
        MainTriggerConfig.__attrs_post_init__(self)

        # Don't validate slope_width.

        validate_param(self, "responsiveness", 0, 1)
        # TODO trigger_falloff >= 0
        validate_param(self, "buffer_falloff", 0, np.inf)