MCPcopy Create free account
hub / github.com/MoonInTheRiver/DiffSinger / __init__

Method __init__

modules/parallel_wavegan/layers/pqmf.py:61–103  ·  view source on GitHub ↗

Initilize PQMF module. Args: subbands (int): The number of subbands. taps (int): The number of filter taps. cutoff_ratio (float): Cut-off frequency ratio. beta (float): Beta coefficient for kaiser window.

(self, subbands=4, taps=62, cutoff_ratio=0.15, beta=9.0)

Source from the content-addressed store, hash-verified

59 """
60
61 def __init__(self, subbands=4, taps=62, cutoff_ratio=0.15, beta=9.0):
62 """Initilize PQMF module.
63
64 Args:
65 subbands (int): The number of subbands.
66 taps (int): The number of filter taps.
67 cutoff_ratio (float): Cut-off frequency ratio.
68 beta (float): Beta coefficient for kaiser window.
69
70 """
71 super(PQMF, self).__init__()
72
73 # define filter coefficient
74 h_proto = design_prototype_filter(taps, cutoff_ratio, beta)
75 h_analysis = np.zeros((subbands, len(h_proto)))
76 h_synthesis = np.zeros((subbands, len(h_proto)))
77 for k in range(subbands):
78 h_analysis[k] = 2 * h_proto * np.cos(
79 (2 * k + 1) * (np.pi / (2 * subbands)) *
80 (np.arange(taps + 1) - ((taps - 1) / 2)) +
81 (-1) ** k * np.pi / 4)
82 h_synthesis[k] = 2 * h_proto * np.cos(
83 (2 * k + 1) * (np.pi / (2 * subbands)) *
84 (np.arange(taps + 1) - ((taps - 1) / 2)) -
85 (-1) ** k * np.pi / 4)
86
87 # convert to tensor
88 analysis_filter = torch.from_numpy(h_analysis).float().unsqueeze(1)
89 synthesis_filter = torch.from_numpy(h_synthesis).float().unsqueeze(0)
90
91 # register coefficients as beffer
92 self.register_buffer("analysis_filter", analysis_filter)
93 self.register_buffer("synthesis_filter", synthesis_filter)
94
95 # filter for downsampling & upsampling
96 updown_filter = torch.zeros((subbands, subbands, subbands)).float()
97 for k in range(subbands):
98 updown_filter[k, k, 0] = 1.0
99 self.register_buffer("updown_filter", updown_filter)
100 self.subbands = subbands
101
102 # keep padding info
103 self.pad_fn = torch.nn.ConstantPad1d(taps // 2, 0.0)
104
105 def analysis(self, x):
106 """Analysis with PQMF.

Callers

nothing calls this directly

Calls 1

design_prototype_filterFunction · 0.85

Tested by

no test coverage detected