Commit bf7e4982 authored by Raymond Toy's avatar Raymond Toy Committed by Commit Bot

Detect if output is audible or not

Measure the output of the destination to determine if the output
is audible or not.  Also keep track of the total duration of when
audible output was played.

Bug: 855069
Change-Id: Icec9aa3d3b853bb5b4b9287ce9350d2e16cd383e
Reviewed-on: https://chromium-review.googlesource.com/1102664
Commit-Queue: Raymond Toy <rtoy@chromium.org>
Reviewed-by: default avatarMounir Lamouri <mlamouri@chromium.org>
Reviewed-by: default avatarHongchan Choi <hongchan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#576268}
parent 52493e5b
......@@ -36,6 +36,7 @@
#include "third_party/blink/public/platform/web_audio_latency_hint.h"
#include "third_party/blink/renderer/platform/audio/audio_utilities.h"
#include "third_party/blink/renderer/platform/audio/push_pull_fifo.h"
#include "third_party/blink/renderer/platform/audio/vector_math.h"
#include "third_party/blink/renderer/platform/cross_thread_functional.h"
#include "third_party/blink/renderer/platform/histogram.h"
#include "third_party/blink/renderer/platform/instrumentation/tracing/trace_event.h"
......@@ -149,6 +150,23 @@ void AudioDestination::Render(const WebVector<float*>& destination_data,
delay_timestamp, "delay (s)", delay);
}
// Determine if the rendered data is audible.
static bool IsAudible(const AudioBus* rendered_data) {
// Compute the energy in each channel and sum up the energy in each channel
// for the total energy.
float energy = 0;
unsigned data_size = rendered_data->length();
for (unsigned k = 0; k < rendered_data->NumberOfChannels(); ++k) {
const float* data = rendered_data->Channel(k)->Data();
float channel_energy;
VectorMath::Vsvesq(data, 1, &channel_energy, data_size);
energy += channel_energy;
}
return energy > 0;
}
void AudioDestination::RequestRender(size_t frames_requested,
size_t frames_to_render,
double delay,
......@@ -185,6 +203,24 @@ void AudioDestination::RequestRender(size_t frames_requested,
// Process WebAudio graph and push the rendered output to FIFO.
callback_.Render(render_bus_.get(),
AudioUtilities::kRenderQuantumFrames, output_position);
// Detect silence (or not) for MEI
bool is_audible = IsAudible(render_bus_.get());
if (is_audible) {
++total_audible_renders_;
}
if (was_audible_) {
if (!is_audible) {
was_audible_ = false;
}
} else {
if (is_audible) {
was_audible_ = true;
}
}
fifo_->Push(render_bus_.get());
}
......
......@@ -138,6 +138,15 @@ class PLATFORM_EXPORT AudioDestination
// graph into the FIFO.
scoped_refptr<AudioBus> render_bus_;
// Keeps track if the output of this destination was audible, before the
// current rendering quantum. Used for recording "playback" time.
bool was_audible_ = false;
// Counts the number of render quanta where audible sound was played. We
// determine audibility on render quantum boundaries, so counting quanta is
// all that's needed.
size_t total_audible_renders_ = 0;
// Accessed by rendering thread: the render callback function of WebAudio
// engine. (i.e. DestinationNode)
AudioIOCallback& callback_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment