"""Script containing the main class of the package."""

import numpy as np
from scipy.signal import resample

from distortion_tui.utils import get_cycles


def isochronous(waveform: np.ndarray) -> np.ndarray:
    """
    Make waveform isochronous.

    Args:
        waveform (np.ndarray): Input waveform.

    Returns:
        np.ndarray: Isochronous waveform.

    """
    cycles, _ = get_cycles(waveform)
    avg_cycle_length = int(np.mean([len(cycle) for cycle in cycles]))
    out = []
    for cycle in cycles:
        warped_cycle = resample(cycle, avg_cycle_length)
        out.append(warped_cycle)
    return np.concatenate(out)


def infinite_peak_clipped(waveform: np.ndarray) -> np.ndarray:
    """
    Make waveform infinite peak clipped.

    Args:
        waveform (np.ndarray): Input waveform.

    Returns:
        np.ndarray: Infinite peak clipped waveform.

    """
    return np.where(waveform >= 0, 1.0, -1.0).astype(np.float32)
