Пример #1
0
 def test_fft_convolve_checks_number_of_frames(self, n_frames):
     """Tests fft_convolve() raises error for invalid number of framess."""
     # Create random signals to convolve with same batch sizes.
     impulse_response = th.randn([1, n_frames, self.audio_size],
                                 dtype=th.float32)
     with pytest.raises(ValueError):
         _ = core.fft_convolve(self.audio, impulse_response)
Пример #2
0
    def test_fft_convolve_checks_batch_size(self):
        """Tests fft_convolve() raises error for mismatched batch sizes."""
        # Create random signals to convolve with different batch sizes.
        impulse_response = np.concatenate([self.audio, self.audio], 0)

        with pytest.raises(ValueError):
            _ = core.fft_convolve(self.audio, impulse_response)
Пример #3
0
    def test_delay_compensation_corrects_group_delay(self, gain):
        """Test automatically compensating for group delay of linear phase
        filter.

        Genearate filters to shift entire signal by a constant gain. Test that
        filtered signal is in phase with original signal.

        Args:
            gain: Amount to scale the input signal.
        """
        # Create random signal to filter.
        output_np = gain * self.audio[0]
        n_frequencies = 1025
        window_size = 257

        magnitudes = gain * th.ones([1, n_frequencies], dtype=th.float32)
        impulse_response = core.frequency_impulse_response(
            magnitudes, window_size)
        output_th = core.fft_convolve(self.audio,
                                      impulse_response,
                                      padding="same")[0]

        difference = output_np - output_th.numpy()
        total_difference = np.abs(difference).mean()
        threshold = 1e-3
        assert np.all(total_difference <= threshold)
Пример #4
0
    def test_fft_convolve_is_accurate(self, audio_size, impulse_response_size):
        """Tests convolving signals using fast fourier transform (fft).

        Generate random signals and convolve using fft. Compare outputs to the
        implementation in scipy.signal.

        Args:
            audio_size: Size of the audio to convolve.
            impulse_response_size: Size of the impulse response to convolve.
        """

        # Create random signals to convolve.
        audio = np.ones([1, audio_size]).astype(np.float32)
        impulse_response = np.ones([1,
                                    impulse_response_size]).astype(np.float32)

        output_th = core.fft_convolve(audio,
                                      impulse_response,
                                      padding="valid",
                                      delay_compensation=0)[0]

        output_np = signal.fftconvolve(audio[0], impulse_response[0])

        difference = output_np - output_th.numpy()
        total_difference = np.abs(difference).mean()
        threshold = 1e-3
        assert np.all(total_difference <= threshold)
Пример #5
0
    def get_signal(self, audio, ir):
        """Apply impulse response.

        Args:
            audio: Dry audio, 2-D Tensor of shape [batch_size, n_samples].
            ir: 3-D Tensor of shape [batch_size, ir_size, 1] or 2-D Tensor of shape
                [batch_size, ir_size].

        Returns:
            tensor of shape [batch_size, n_samples]
        """
        audio, ir = f32(audio, ir)
        ir = self._mask_dry_ir(ir)
        wet = core.fft_convolve(audio,
                                ir,
                                padding="same",
                                delay_compensation=0)
        return (wet + audio) if self._add_dry else wet
Пример #6
0
 def test_fft_convolve_disallows_invalid_padding_arguments(self, padding):
     """Tests fft_convolve() raises error for wrong padding name."""
     with pytest.raises(ValueError):
         _ = core.fft_convolve(self.audio, self.audio, padding=padding)
Пример #7
0
 def test_fft_convolve_allows_valid_padding_arguments(self, padding):
     """Tests fft_convolve() runs for valid padding names."""
     result = core.fft_convolve(self.audio, self.audio, padding=padding)
     assert result.shape[0] == 1