def run_once(self):
        """Entry point of this test."""

        # Multitone wav file lasts 10 seconds
        wav_path = os.path.join(self.bindir, '10SEC.wav')

        noise_file = os.path.join(self.resultsdir, 'cras_noise.wav')
        recorded_file = os.path.join(self.resultsdir, 'cras_recorded.wav')

        # Record a sample of "silence" to use as a noise profile.
        cras_utils.capture(noise_file, duration=1)

        self.wait_for_active_stream_count(0)
        p = cmd_utils.popen(cras_utils.playback_cmd(wav_path))
        try:
            self.wait_for_active_stream_count(1)
            cras_utils.capture(recorded_file, duration=TEST_DURATION)

            # Make sure the audio is still playing.
            if p.poll() != None:
                raise error.TestError('playback stopped')
        finally:
            cmd_utils.kill_or_log_returncode(p)

        rms_value = audio_helper.reduce_noise_and_get_rms(
            recorded_file, noise_file)[0]
        self.write_perf_keyval({'rms_value': rms_value})
    def run_once(self):
        """Entry point of this test."""

        # Generate sine raw file that lasts 5 seconds.
        raw_path = os.path.join(self.bindir, '5SEC.raw')
        data_format = dict(file_type='raw', sample_format='S16_LE',
                channel=2, rate=48000)
        raw_file = audio_test_data.GenerateAudioTestData(
            path=raw_path,
            data_format=data_format,
            duration_secs=5,
            frequencies=[440, 440],
            volume_scale=0.9)

        recorded_file = os.path.join(self.resultsdir, 'cras_recorded.raw')

        self.wait_for_active_stream_count(0)
        p = cmd_utils.popen(cras_utils.playback_cmd(raw_file.path))
        try:
            self.wait_for_active_stream_count(1)
            cras_utils.capture(recorded_file, duration=TEST_DURATION)

            # Make sure the audio is still playing.
            if p.poll() != None:
                raise error.TestError('playback stopped')
        finally:
            cmd_utils.kill_or_log_returncode(p)
            raw_file.delete()

        rms_value = audio_helper.get_rms(recorded_file)[0]
        self.write_perf_keyval({'rms_value': rms_value})
예제 #3
0
    def run_once(self, test_sample_rates):
        """Runs the format conversion test.
        """

        rms_values = {}

        # Record silence to use as the noise profile.
        noise_file = os.path.join(self.resultsdir, "noise.wav")
        noise_profile = tempfile.NamedTemporaryFile()
        cras_utils.capture(noise_file, duration=1)
        sox_utils.noise_profile(noise_file, noise_profile.name)

        # Try all sample rate pairs.
        for primary in test_sample_rates:
            for secondary in test_sample_rates:
                key = 'rms_value_%d_%d' % (primary, secondary)
                rms_values[key] = self.loopback(noise_profile.name, primary,
                                                secondary)

        # Record at all sample rates
        record_file = tempfile.NamedTemporaryFile()
        for rate in test_sample_rates:
            cras_utils.capture(record_file.name, duration=1, rate=rate)

        # Add min_rms_value to the result
        rms_values['min_rms_value'] = min(rms_values.values())

        self.write_perf_keyval(rms_values)
예제 #4
0
    def run_once(self):
        """Entry point of this test."""
        self.chrome.browser.platform.SetHTTPServerDirectories(self.bindir)

        video_url = self.chrome.browser.platform.http_server.UrlOf(
            os.path.join(self.bindir, 'youtube.html'))
        logging.info('Playing back youtube media file %s.', video_url)
        noise_file = os.path.join(self.resultsdir, "noise.wav")
        recorded_file = os.path.join(self.resultsdir, "recorded.wav")
        loopback_file = os.path.join(self.resultsdir, "loopback.wav")

        # Record a sample of "silence" to use as a noise profile.
        cras_utils.capture(noise_file, duration=3)

        # Play a video and record the audio output
        self.play_video(self.chrome.browser.tabs[0], video_url)

        p1 = cmd_utils.popen(
            cras_utils.capture_cmd(recorded_file, duration=TEST_DURATION))
        p2 = cmd_utils.popen(
            cras_utils.loopback_cmd(loopback_file, duration=TEST_DURATION))

        cmd_utils.wait_and_check_returncode(p1, p2)

        # See if we recorded something
        loopback_stats = [
            audio_helper.get_channel_sox_stat(loopback_file, i) for i in (1, 2)
        ]
        logging.info('loopback stats: %s', [str(s) for s in loopback_stats])
        rms_value = audio_helper.reduce_noise_and_get_rms(
            recorded_file, noise_file)[0]

        self.write_perf_keyval({'rms_value': rms_value})
예제 #5
0
    def _test_audio_disabled(self, policy_value):
        """
        Verify the AudioOutputAllowed policy behaves as expected.

        Generate and play a sample audio file. When enabled, the difference
        between the muted and unmuted RMS should be greater than 0.75. When
        disabled, the RMS difference should be less than 0.05.

        @param policy_value: policy value for this case.

        @raises error.TestFail: In the case where the audio behavior
            does not match the policy value.

        """
        audio_allowed = policy_value or policy_value is None

        RAW_FILE = os.path.join(self.enterprise_dir, 'test_audio.raw')
        noise_file = os.path.join(self.resultsdir, 'noise.wav')
        recorded_file = os.path.join(self.resultsdir, 'recorded-cras.raw')
        recorded_rms = []

        # Record a sample of silence to use as a noise profile.
        cras_utils.capture(noise_file, duration=2)
        logging.info('NOISE: %s', audio_helper.get_rms(noise_file))

        # Get two RMS samples: one when muted and one when not
        for muted in [False, True]:
            cras_utils.set_system_mute(muted)

            # Play the audio file and capture the output
            self.wait_for_active_stream_count(0)
            p = cmd_utils.popen(cras_utils.playback_cmd(RAW_FILE))
            try:
                self.wait_for_active_stream_count(1)
                cras_utils.capture(recorded_file,
                                   duration=self.SAMPLE_DURATION)

                if p.poll() is not None:
                    raise error.TestError('Audio playback stopped prematurely')
            finally:
                cmd_utils.kill_or_log_returncode(p)

            rms_value = audio_helper.reduce_noise_and_get_rms(
                recorded_file, noise_file)[0]

            logging.info('muted (%s): %s' % (muted, rms_value))
            recorded_rms.append(rms_value)

        rms_diff = recorded_rms[0] - recorded_rms[1]
        self.write_perf_keyval({'rms_diff': rms_diff})

        if audio_allowed:
            if rms_diff < 0.4:
                raise error.TestFail('RMS difference not large enough between '
                                     'mute and ummute: %s' % rms_diff)
        else:
            if abs(rms_diff) > 0.05:
                raise error.TestFail('RMS difference too wide while audio '
                                     'disabled: %s' % rms_diff)
 def verify_cras_capture(self, channels, rate):
     recorded_file = tempfile.NamedTemporaryFile()
     cras_utils.capture(recorded_file.name,
                        duration=DURATION,
                        channels=channels,
                        rate=rate)
     self.check_recorded_filesize(os.path.getsize(recorded_file.name),
                                  DURATION, channels, rate)
예제 #7
0
    def loopback(self, noise_profile, primary, secondary):
        """Gets the rms value of the recorded audio of playing two different
        tones (the 440 and 523 Hz sine wave) at the specified sampling rate.

        @param noise_profile: The noise profile which is used to reduce the
                              noise of the recored audio.
        @param primary: The first sample rate, HW will be set to this.
        @param secondary: The second sample rate, will be SRC'd to the first.
        """
        popens = []

        record_file = os.path.join(self.resultsdir,
                                   'record-%s-%s.wav' % (primary, secondary))

        # There should be no other active streams.
        self.wait_for_active_stream_count(0)

        # Start with the primary sample rate, then add the secondary.  This
        # causes the secondary to be SRC'd to the primary rate.
        try:
            # Play the first audio stream and make sure it has been played
            popens += self.play_sine_tone(_TEST_TONE_ONE, primary)
            self.wait_for_active_stream_count(1)

            # Play the second audio stream and make sure it has been played
            popens += self.play_sine_tone(_TEST_TONE_TWO, secondary)
            self.wait_for_active_stream_count(2)

            cras_utils.capture(record_file, duration=1, rate=44100)

            # Make sure the playback is still in good shape
            if any(p.poll() is not None for p in popens):
                # We will log more details later in finally.
                raise error.TestFail('process unexpectly stopped')

            reduced_file = tempfile.NamedTemporaryFile()
            sox_utils.noise_reduce(record_file,
                                   reduced_file.name,
                                   noise_profile,
                                   rate=44100)

            sox_stat = sox_utils.get_stat(reduced_file.name, rate=44100)

            logging.info('The sox stat of (%d, %d) is %s', primary, secondary,
                         str(sox_stat))

            return sox_stat.rms

        finally:
            cmd_utils.kill_or_log_returncode(*popens)
예제 #8
0
    def run_once(self):
        """Runs the audio_WebRtcAudioLoopback test."""
        # Record a sample of "silence" to use as a noise profile.
        noise_file = os.path.join(self.resultsdir, 'cras_noise.wav')
        cras_utils.capture(noise_file, duration=1)

        # Create a file for the audio recording.
        recorded_file = os.path.join(self.resultsdir, 'cras_recorded.wav')

        self.wait_for_active_stream_count(0)
        with chrome.Chrome(extra_browser_args=EXTRA_BROWSER_ARGS +\
                            [helper_logger.chrome_vmodule_flag()],
                           init_network_controller=True) as cr:
            self.start_test(cr, recorded_file)
            self.wait_test_completed(TIMEOUT)
            self.print_result(recorded_file, noise_file)
예제 #9
0
    def start_test(self, cr, recorded_file):
        """Opens the WebRTC audio loopback page and records audio output.

        @param cr: Autotest Chrome instance.
        @param recorded_file: File to recorder the audio output to.
        """
        cr.browser.platform.SetHTTPServerDirectories(self.bindir)

        self.tab = cr.browser.tabs[0]
        self.tab.Navigate(
            cr.browser.platform.http_server.UrlOf(
                os.path.join(self.bindir, AUDIO_LOOPBACK_PAGE)))
        self.tab.WaitForDocumentReadyStateToBeComplete()
        self.tab.EvaluateJavaScript(
            "run(%d, %d)" % (TEST_RUNTIME_SECONDS, NUM_PEER_CONNECTIONS))
        self.wait_for_active_stream_count(1)
        cras_utils.capture(recorded_file, duration=TEST_RUNTIME_SECONDS)
    def run_once(self, test_files, test_duration):
        self._rms_values = {}
        noise_file = os.path.join(self.resultsdir, 'noise.wav')
        noiseprof_file = tempfile.NamedTemporaryFile()

        # Record a sample of "silence" to use as a noise profile.
        cras_utils.capture(noise_file, duration=2)
        sox_utils.noise_profile(noise_file, noiseprof_file.name)

        # Open the test page
        self.chrome.browser.platform.SetHTTPServerDirectories(self.bindir)
        tab = self.chrome.browser.tabs[0]
        tab.Navigate(
            self.chrome.browser.platform.http_server.UrlOf(
                os.path.join(self.bindir, 'play.html')))
        tab.WaitForDocumentReadyStateToBeComplete()

        # Test each media file for all channels.
        for media_file in test_files:
            self.rms_test(tab, media_file, noiseprof_file.name, test_duration)
        self.write_perf_keyval(self._rms_values)