output = forward(signal, system_ir) signal: (batchsize, length1, dim) system_ir: (length2, dim) output: (batchsize, length1, dim)
(self, signal, system_ir)
| 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 | |
| 246 | class CyclicNoiseGen_v1(torch.nn.Module): |