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

Class SignalsConv1d

modules/parallel_wavegan/models/source.py:205–243  ·  view source on GitHub ↗

Filtering input signal with time invariant filter Note: FIRFilter conducted filtering given fixed FIR weight SignalsConv1d convolves two signals Note: this is based on torch.nn.functional.conv1d

Source from the content-addressed store, hash-verified

203
204
205class SignalsConv1d(torch.nn.Module):
206 """ Filtering input signal with time invariant filter
207 Note: FIRFilter conducted filtering given fixed FIR weight
208 SignalsConv1d convolves two signals
209 Note: this is based on torch.nn.functional.conv1d
210
211 """
212
213 def __init__(self):
214 super(SignalsConv1d, self).__init__()
215
216 def forward(self, signal, system_ir):
217 """ output = forward(signal, system_ir)
218
219 signal: (batchsize, length1, dim)
220 system_ir: (length2, dim)
221
222 output: (batchsize, length1, dim)
223 """
224 if signal.shape[-1] != system_ir.shape[-1]:
225 print("Error: SignalsConv1d expects shape:")
226 print("signal (batchsize, length1, dim)")
227 print("system_id (batchsize, length2, dim)")
228 print("But received signal: {:s}".format(str(signal.shape)))
229 print(" system_ir: {:s}".format(str(system_ir.shape)))
230 sys.exit(1)
231 padding_length = system_ir.shape[0] - 1
232 groups = signal.shape[-1]
233
234 # pad signal on the left
235 signal_pad = torch_nn_func.pad(signal.permute(0, 2, 1), \
236 (padding_length, 0))
237 # prepare system impulse response as (dim, 1, length2)
238 # also flip the impulse response
239 ir = torch.flip(system_ir.unsqueeze(1).permute(2, 1, 0), \
240 dims=[2])
241 # convolute
242 output = torch_nn_func.conv1d(signal_pad, ir, groups=groups)
243 return output.permute(0, 2, 1)
244
245
246class CyclicNoiseGen_v1(torch.nn.Module):

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected