Exemplo n.º 1
0
    def num_samples(self, sr=None):
        """
        Return the number of samples.

        Args:
            sr (int): Calculate the number of samples with the given
                      sampling-rate. If None use the native sampling-rate.

        Returns:
            int: Number of samples
        """
        native_sr = self.sampling_rate
        num_samples = units.seconds_to_sample(self.duration, native_sr)

        if sr is not None:
            ratio = float(sr) / native_sr
            num_samples = int(np.ceil(num_samples * ratio))

        return num_samples
Exemplo n.º 2
0
 def test_seconds_to_sample(self):
     assert units.seconds_to_sample(0, 16000) == 0
     assert units.seconds_to_sample(4.5, 22050) == 99225