Commit 1e42b591 authored by Raymond Toy's avatar Raymond Toy Committed by Commit Bot

Optimize for automations that haven't started yet

If automations are scheduled to start in the future, the slow
automation path is run instead of the fast path where the AudioParam
value is known to be constant.  For most nodes this doesn't matter,
but for BiquadFilters that have a complicated relationship between the
AudioParam values and the filter coefficients, this is a significant
performance hit.

So, if there are no automations scheduled to run in the current render
quantum, we can still use the fast path.

Bug: 795051
Change-Id: Iad144c5ce0bcea4af1921ba879c6c55f210fcb16
Reviewed-on: https://chromium-review.googlesource.com/830033
Commit-Queue: Raymond Toy <rtoy@chromium.org>
Reviewed-by: default avatarHongchan Choi <hongchan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#527041}
parent 885b62ed
......@@ -147,7 +147,11 @@ class AudioParamHandler final : public ThreadSafeRefCounted<AudioParamHandler>,
void ResetSmoothedValue() { timeline_.SetSmoothedValue(IntrinsicValue()); }
bool HasSampleAccurateValues() {
return timeline_.HasValues() || NumberOfRenderingConnections();
bool has_values =
timeline_.HasValues(destination_handler_->CurrentSampleFrame(),
destination_handler_->SampleRate());
return has_values || NumberOfRenderingConnections();
}
// Calculates numberOfValues parameter values starting at the context's
......
......@@ -586,11 +586,29 @@ void AudioParamTimeline::InsertEvent(std::unique_ptr<ParamEvent> event,
new_events_.insert(events_[i].get());
}
bool AudioParamTimeline::HasValues() const {
bool AudioParamTimeline::HasValues(size_t current_frame,
double sample_rate) const {
MutexTryLocker try_locker(events_lock_);
if (try_locker.Locked())
return events_.size();
if (try_locker.Locked()) {
if (events_.size() == 0)
return false;
switch (events_[0]->GetType()) {
case ParamEvent::kSetValue:
case ParamEvent::kSetValueCurve:
case ParamEvent::kSetTarget:
// Need automation if the event starts somewhere before the
// end of the current render quantum.
return events_[0]->Time() <=
(current_frame + AudioUtilities::kRenderQuantumFrames) /
sample_rate;
default:
// Otherwise, there's some kind of other event running, so we
// need to do automation.
return true;
}
}
// Can't get the lock so that means the main thread is trying to insert an
// event. Just return true then. If the main thread releases the lock before
......
......@@ -93,8 +93,10 @@ class AudioParamTimeline {
float min_value,
float max_value);
// Returns true if this AudioParam has any events on it.
bool HasValues() const;
// Returns true if the AudioParam timeline needs to run in this
// rendering quantum. This means some automation is already running
// or is scheduled to run in the current rendering quantuym.
bool HasValues(size_t current_frame, double sample_rate) const;
float SmoothedValue() { return smoothed_value_; }
void SetSmoothedValue(float v) { smoothed_value_ = v; }
......
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