| 11 | |
| 12 | |
| 13 | class ds_block(nn.Module): |
| 14 | |
| 15 | def __init__( |
| 16 | self, |
| 17 | width=48, |
| 18 | win_len=512, |
| 19 | win_inc=256, |
| 20 | fft_len=512, |
| 21 | win_type='hanning', |
| 22 | masking_mode='E', |
| 23 | ): |
| 24 | |
| 25 | |
| 26 | super(ds_block, self).__init__() |
| 27 | |
| 28 | # for fft |
| 29 | self.win_len = win_len |
| 30 | self.win_inc = win_inc |
| 31 | self.fft_len = fft_len |
| 32 | self.win_type = win_type |
| 33 | |
| 34 | input_dim = win_len |
| 35 | output_dim = win_len |
| 36 | |
| 37 | self.input_dim = input_dim |
| 38 | self.output_dim = output_dim |
| 39 | self.masking_mode = masking_mode |
| 40 | self.freq_dim = 512 |
| 41 | self.ds_dim = 64 |
| 42 | self.groups = self.ds_dim // 2 |
| 43 | |
| 44 | fix = True |
| 45 | self.fix = fix |
| 46 | self.stft = ConvSTFT(self.win_len, self.win_inc, fft_len, self.win_type, 'complex', fix=fix) |
| 47 | self.istft = ConviSTFT(self.win_len, self.win_inc, fft_len, self.win_type, 'complex', fix=fix) |
| 48 | #self.cln = InstantLayerNorm(2, 256, elementwise_affine=True) |
| 49 | self.ana_conv = ComplexConv2d(self.freq_dim, self.ds_dim, (1,1), (1,1), (0,0), (1,1), self.groups) |
| 50 | self.sys_conv = ComplexConv2d(self.ds_dim, self.freq_dim, (1,1), (1,1), (0,0), (1,1), self.groups) |
| 51 | #self.ana_conv = ComplexConv2d(self.freq_dim, self.ds_dim, (1,1), (1,1), (0,0), (1,1)) |
| 52 | #self.sys_conv = ComplexConv2d(self.ds_dim, self.freq_dim, (1,1), (1,1), (0,0), (1,1)) |
| 53 | |
| 54 | self.enh_block = DFNet(width=width) |
| 55 | #self.enh_block = DPCRN(feat_dim=self.ds_dim//2) |
| 56 | |
| 57 | |
| 58 | |
| 59 | def forward(self, inputs, lens=None): |
| 60 | specs = self.stft(inputs) |
| 61 | real = specs[:,:self.fft_len//2+1] |
| 62 | imag = specs[:,self.fft_len//2+1:] |
| 63 | spec_mags = torch.sqrt(real**2+imag**2+1e-8) |
| 64 | spec_mags = spec_mags |
| 65 | spec_phase = torch.atan2(imag, real) |
| 66 | spec_phase = spec_phase |
| 67 | |
| 68 | |
| 69 | cspecs = torch.cat([real[:,1:,:],imag[:,1:,:]],1) |
| 70 | #print(cspecs.unsqueeze(-1).shape) |