Exemplo n.º 1
0
 def test_good_signal(self):
     """Sine wave signal with no noise or artifacts."""
     result = audio_quality_measurement.quality_measurement(
         self.y, self.rate)
     self.assertTrue(len(result['artifacts']['noise_before_playback']) == 0)
     self.assertTrue(len(result['artifacts']['noise_after_playback']) == 0)
     self.assertTrue(len(result['artifacts']['delay_during_playback']) == 0)
     self.assertTrue(len(result['artifacts']['burst_during_playback']) == 0)
     self.assertTrue(len(result['volume_changes']) == 0)
     self.assertTrue(result['equivalent_noise_level'] < 0.005)
Exemplo n.º 2
0
 def test_burst_during_playback(self):
     """Sine wave with burst during playback."""
     self.generate_burst_during_playback()
     result = audio_quality_measurement.quality_measurement(
         self.y, self.rate)
     self.assertTrue(len(result['artifacts']['noise_before_playback']) == 0)
     self.assertTrue(len(result['artifacts']['noise_after_playback']) == 0)
     self.assertTrue(len(result['artifacts']['delay_during_playback']) == 0)
     self.assertTrue(len(result['artifacts']['burst_during_playback']) == 5)
     self.assertTrue(len(result['volume_changes']) == 10)
     self.assertTrue(result['equivalent_noise_level'] > 0.02)
     for i in range(len(result['artifacts']['burst_during_playback'])):
         delta = abs(self.burst_start_time[i] -
                     result['artifacts']['burst_during_playback'][i])
         self.assertTrue(delta < 0.002)
Exemplo n.º 3
0
 def test_artifacts_after_playback(self):
     """Sine wave with artifacts after playback."""
     self.generate_artifacts_after_playback()
     result = audio_quality_measurement.quality_measurement(
         self.y, self.rate)
     self.assertTrue(len(result['artifacts']['noise_before_playback']) == 0)
     self.assertTrue(len(result['artifacts']['noise_after_playback']) == 1)
     delta = abs(result['artifacts']['noise_after_playback'][0][0] - 1.95)
     self.assertTrue(delta < 0.01)
     delta = abs(result['artifacts']['noise_after_playback'][0][1] - 0.02)
     self.assertTrue(delta < 0.001)
     self.assertTrue(len(result['artifacts']['delay_during_playback']) == 0)
     self.assertTrue(len(result['artifacts']['burst_during_playback']) == 0)
     self.assertTrue(len(result['volume_changes']) == 0)
     self.assertTrue(result['equivalent_noise_level'] < 0.005)
Exemplo n.º 4
0
 def test_volume_changing(self):
     """Sine wave with volume changing during playback."""
     self.generate_volume_changing()
     result = audio_quality_measurement.quality_measurement(
         self.y, self.rate)
     self.assertTrue(len(result['artifacts']['noise_before_playback']) == 0)
     self.assertTrue(len(result['artifacts']['noise_after_playback']) == 0)
     self.assertTrue(len(result['artifacts']['delay_during_playback']) == 0)
     self.assertTrue(len(result['artifacts']['burst_during_playback']) == 0)
     self.assertTrue(result['equivalent_noise_level'] < 0.005)
     self.assertTrue(
         len(result['volume_changes']) == len(self.volume_changing))
     for i in range(len(self.volume_changing)):
         self.assertTrue(
             abs(self.volume_changing_time[i] -
                 result['volume_changes'][i][0]) < 0.01)
         self.assertTrue(
             self.volume_changing[i] == result['volume_changes'][i][1])
Exemplo n.º 5
0
    def test_delay(self):
        """Sine wave with delay during playing."""
        self.generate_delay()
        result = audio_quality_measurement.quality_measurement(
            self.y, self.rate)
        self.assertTrue(len(result['artifacts']['noise_before_playback']) == 0)
        self.assertTrue(len(result['artifacts']['noise_after_playback']) == 0)
        self.assertTrue(
            len(result['volume_changes']) == 2 * len(self.delay_start_time))
        self.assertTrue(result['equivalent_noise_level'] < 0.005)

        self.assertTrue(
            len(result['artifacts']['delay_during_playback']) == len(
                self.delay_start_time))
        for i in range(len(result['artifacts']['delay_during_playback'])):
            delta = abs(result['artifacts']['delay_during_playback'][i][0] -
                        self.delay_start_time[i])
            self.assertTrue(delta < 0.001)
            duration = self.delay_end_time[i] - self.delay_start_time[i]
            delta = abs(result['artifacts']['delay_during_playback'][i][1] -
                        duration)
            self.assertTrue(delta < 0.001)
Exemplo n.º 6
0
    def do_spectral_analysis(self, ignore_high_freq, check_quality,
                             quality_params):
        """Gets the spectral_analysis result.

        Args:
            ignore_high_freq: Ignore high frequencies above this threshold.
            check_quality: Check quality of each channel.
            quality_params: A QualityParams object for quality measurement.

        """
        self.has_data()
        for channel_idx in range(self._raw_data.channel):
            signal = self._raw_data.channel_data[channel_idx]
            max_abs = max(numpy.abs(signal))
            logging.debug('Channel %d max abs signal: %f', channel_idx,
                          max_abs)
            if max_abs == 0:
                logging.info('No data on channel %d, skip this channel',
                             channel_idx)
                continue

            saturate_value = audio_data.get_maximum_value_from_sample_format(
                self._raw_data.sample_format)
            normalized_signal = audio_analysis.normalize_signal(
                signal, saturate_value)
            logging.debug('saturate_value: %f', saturate_value)
            logging.debug('max signal after normalized: %f',
                          max(normalized_signal))
            spectral = audio_analysis.spectral_analysis(
                normalized_signal, self._rate)

            logging.debug('Channel %d spectral:\n%s', channel_idx,
                          pprint.pformat(spectral))

            # Ignore high frequencies above the threshold.
            spectral = [(f, c) for (f, c) in spectral if f < ignore_high_freq]

            logging.info(
                'Channel %d spectral after ignoring high frequencies '
                'above %f:\n%s', channel_idx, ignore_high_freq,
                pprint.pformat(spectral))

            try:
                if check_quality:
                    quality = audio_quality_measurement.quality_measurement(
                        signal=normalized_signal,
                        rate=self._rate,
                        dominant_frequency=spectral[0][0],
                        block_size_secs=quality_params.block_size_secs,
                        frequency_error_threshold=quality_params.
                        frequency_error_threshold,
                        delay_amplitude_threshold=quality_params.
                        delay_amplitude_threshold,
                        noise_amplitude_threshold=quality_params.
                        noise_amplitude_threshold,
                        burst_amplitude_threshold=quality_params.
                        burst_amplitude_threshold)

                    logging.debug('Channel %d quality:\n%s', channel_idx,
                                  pprint.pformat(quality))
                    self._quality_result.append(quality)
                self._spectrals.append(spectral)
            except Exception as error:
                logging.warning(
                    "Failed to analyze channel {} with error: {}".format(
                        channel_idx, error))