Skip to content

AsymmetricWindowSelector

AsymmetricWindowSelector(scheme, analysis_segment_size, hop_size, synthesis_segment_size)

Designs an asymmetric Hann window pair based on the given parameters.

This function retrieves a window function based on the window type, applies an adaptation based on scheme, and returns the corresponding Window object.

Parameters:

Name Type Description Default
scheme str

The adaptation scheme to use. Supported values: [ ola, wola, ]

required
analysis_segment_size int

The size of the segment / analysis_window.

required
hop_size int

The hop size used for segmentation.

required
synthesis_segment_size int

The non-zero size of the systhesis_window.

required

Returns:

Name Type Description
Window Window

A Window object containing the selected window function and its corresponding hop size.

Raises:

Type Description
ValueError

If an unknown window type or scheme is provided.

Source code in src/libsegmenter/AsymmetricWindowSelector.py
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
def AsymmetricWindowSelector(
    scheme: str,
    analysis_segment_size: int,
    hop_size: int,
    synthesis_segment_size: int,
) -> Window:
    """
    Designs an asymmetric Hann window pair based on the given parameters.

    This function retrieves a window function based on the `window` type, applies
    an adaptation based on `scheme`, and returns the corresponding `Window` object.

    Args:
        scheme (str): The adaptation scheme to use. Supported values:
            [
             `ola`,
             `wola`,
            ]
        analysis_segment_size (int): The size of the segment / analysis_window.
        hop_size (int): The hop size used for segmentation.
        synthesis_segment_size (int): The non-zero size of the systhesis_window.

    Returns:
        Window: A `Window` object containing the selected window function and its
            corresponding hop size.

    Raises:
        ValueError: If an unknown window type or scheme is provided.

    """
    if analysis_segment_size % hop_size != 0:
        raise ValueError(
            "The analysis_segment_size must be integer divisible by hop_size."
            + f" Received analysis_segment_size = '{analysis_segment_size}' "
            + f" and hop_size = '{hop_size}'."
        )
    if synthesis_segment_size % hop_size != 0:
        raise ValueError(
            "The synthesis_segment_size must be integer divisible by hop_size."
            + f" Received synthesis_segment_size = '{synthesis_segment_size}' "
            + f" and hop_size = '{hop_size}'."
        )
    if scheme != "ola" and scheme != "wola":
        raise ValueError(f"The '{scheme}' scheme is not supported.")

    elif scheme == "ola":
        from libsegmenter.windows.hann import asymmetricHannOla

        windows = asymmetricHannOla(
            analysis_segment_size, hop_size, synthesis_segment_size
        )

    else:  # WOLA
        from libsegmenter.windows.hann import asymmetricHannWola

        windows = asymmetricHannWola(
            analysis_segment_size, hop_size, synthesis_segment_size
        )

    analysis_window = windows[0]
    synthesis_window = windows[1]
    window = np.multiply(analysis_window, synthesis_window)

    is_cola, normalization, e = check_cola(window, hop_size)
    assert is_cola, f"specified window failed cola check with error {e}"

    synthesis_window = np.divide(synthesis_window, normalization)

    return Window(hop_size, analysis_window, synthesis_window)