| 106 | |
| 107 | |
| 108 | class re_block(nn.Module): |
| 109 | |
| 110 | def __init__( |
| 111 | self, |
| 112 | width=48, |
| 113 | win_len=512, |
| 114 | win_inc=256, |
| 115 | fft_len=512, |
| 116 | win_type='hanning', |
| 117 | masking_mode='C', |
| 118 | ): |
| 119 | |
| 120 | super(re_block, self).__init__() |
| 121 | |
| 122 | # for fft |
| 123 | self.win_len = win_len |
| 124 | self.win_inc = win_inc |
| 125 | self.fft_len = fft_len |
| 126 | self.win_type = win_type |
| 127 | |
| 128 | input_dim = win_len |
| 129 | output_dim = win_len |
| 130 | self.input_dim = input_dim |
| 131 | self.output_dim = output_dim |
| 132 | self.freq_dim = 128 |
| 133 | self.masking_mode = masking_mode |
| 134 | |
| 135 | fix=True |
| 136 | self.fix = fix |
| 137 | self.stft = ConvSTFT(self.win_len, self.win_inc, fft_len, self.win_type, 'complex', fix=fix) |
| 138 | self.istft = ConviSTFT(self.win_len, self.win_inc, fft_len, self.win_type, 'complex', fix=fix) |
| 139 | #self.cln = InstantLayerNorm(2, 256, elementwise_affine=True) |
| 140 | |
| 141 | #self.enh_block = DFNet(width=width,input_channel_rate=2) |
| 142 | |
| 143 | self.enh_block = DPCRN(feat_dim=self.freq_dim,input_channel_rate=2) |
| 144 | |
| 145 | def forward(self, x1, x2,lens=None): |
| 146 | |
| 147 | specs1 = self.stft(x1) |
| 148 | real1 = specs1[:,:self.fft_len//2+1] |
| 149 | imag1 = specs1[:,self.fft_len//2+1:] |
| 150 | spec_mags1 = torch.sqrt(real1**2+imag1**2+1e-8) |
| 151 | spec_phase1 = torch.atan2(imag1, real1) |
| 152 | |
| 153 | specs2 = self.stft(x2) |
| 154 | real2 = specs2[:,:self.fft_len//2+1] |
| 155 | imag2 = specs2[:,self.fft_len//2+1:] |
| 156 | spec_mags2 = torch.sqrt(real2**2+imag2**2+1e-8) |
| 157 | spec_phase2 = torch.atan2(imag2, real2) |
| 158 | |
| 159 | real = torch.stack([real1,real2],1) |
| 160 | imag = torch.stack([imag1,imag2],1) |
| 161 | cspecs = torch.cat([real,imag],1) |
| 162 | cspecs = cspecs[:,:,1:self.freq_dim+1] |
| 163 | |
| 164 | |
| 165 | out = cspecs#self.cln(cspecs) |