#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "third_party/blink/renderer/modules/webaudio/audio_param_timeline.h"
#include <algorithm>
#include <limits>
#include <memory>
#include "base/memory/ptr_util.h"
#include "build/build_config.h"
#include "third_party/blink/renderer/core/inspector/console_message.h"
#include "third_party/blink/renderer/platform/audio/audio_utilities.h"
#include "third_party/blink/renderer/platform/audio/vector_math.h"
#include "third_party/blink/renderer/platform/bindings/exception_messages.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/instrumentation/tracing/trace_event.h"
#include "third_party/blink/renderer/platform/wtf/math_extras.h"
#include "third_party/blink/renderer/platform/wtf/std_lib_extras.h"
#include "third_party/fdlibm/ieee754.h"
#if defined(ARCH_CPU_X86_FAMILY)
#include <emmintrin.h>
#endif
namespace blink {
namespace {
constexpr float kTimeConstantsToConverge = …;
constexpr float kSetTargetThreshold = …;
bool IsNonNegativeAudioParamTime(double time,
ExceptionState& exception_state,
String message = "Time") { … }
bool IsPositiveAudioParamTime(double time,
ExceptionState& exception_state,
String message) { … }
bool HasSetTargetConverged(float value,
float target,
double current_time,
double start_time,
double time_constant) { … }
}
String AudioParamTimeline::EventToString(const ParamEvent& event) const { … }
float AudioParamTimeline::LinearRampAtTime(double t,
float value1,
double time1,
float value2,
double time2) { … }
float AudioParamTimeline::ExponentialRampAtTime(double t,
float value1,
double time1,
float value2,
double time2) { … }
float AudioParamTimeline::TargetValueAtTime(double t,
float value1,
double time1,
float value2,
float time_constant) { … }
float AudioParamTimeline::ValueCurveAtTime(double t,
double time1,
double duration,
const float* curve_data,
unsigned curve_length) { … }
std::unique_ptr<AudioParamTimeline::ParamEvent>
AudioParamTimeline::ParamEvent::CreateSetValueEvent(float value, double time) { … }
std::unique_ptr<AudioParamTimeline::ParamEvent>
AudioParamTimeline::ParamEvent::CreateLinearRampEvent(float value,
double time,
float initial_value,
double call_time) { … }
std::unique_ptr<AudioParamTimeline::ParamEvent>
AudioParamTimeline::ParamEvent::CreateExponentialRampEvent(float value,
double time,
float initial_value,
double call_time) { … }
std::unique_ptr<AudioParamTimeline::ParamEvent>
AudioParamTimeline::ParamEvent::CreateSetTargetEvent(float value,
double time,
double time_constant) { … }
std::unique_ptr<AudioParamTimeline::ParamEvent>
AudioParamTimeline::ParamEvent::CreateSetValueCurveEvent(
const Vector<float>& curve,
double time,
double duration) { … }
std::unique_ptr<AudioParamTimeline::ParamEvent>
AudioParamTimeline::ParamEvent::CreateSetValueCurveEndEvent(float value,
double time) { … }
std::unique_ptr<AudioParamTimeline::ParamEvent>
AudioParamTimeline::ParamEvent::CreateCancelValuesEvent(
double time,
std::unique_ptr<ParamEvent> saved_event) { … }
std::unique_ptr<AudioParamTimeline::ParamEvent>
AudioParamTimeline::ParamEvent::CreateGeneralEvent(
Type type,
float value,
double time,
float initial_value,
double call_time,
double time_constant,
double duration,
Vector<float>& curve,
double curve_points_per_second,
float curve_end_value,
std::unique_ptr<ParamEvent> saved_event) { … }
AudioParamTimeline::ParamEvent* AudioParamTimeline::ParamEvent::SavedEvent()
const { … }
bool AudioParamTimeline::ParamEvent::HasDefaultCancelledValue() const { … }
void AudioParamTimeline::ParamEvent::SetCancelledValue(float value) { … }
AudioParamTimeline::ParamEvent::ParamEvent(
ParamEvent::Type type,
float value,
double time,
float initial_value,
double call_time,
double time_constant,
double duration,
Vector<float>& curve,
double curve_points_per_second,
float curve_end_value,
std::unique_ptr<ParamEvent> saved_event)
: … { … }
AudioParamTimeline::ParamEvent::ParamEvent(ParamEvent::Type type,
float value,
double time)
: … { … }
AudioParamTimeline::ParamEvent::ParamEvent(ParamEvent::Type type,
float value,
double time,
float initial_value,
double call_time)
: … { … }
AudioParamTimeline::ParamEvent::ParamEvent(ParamEvent::Type type,
float value,
double time,
double time_constant)
: … { … }
AudioParamTimeline::ParamEvent::ParamEvent(ParamEvent::Type type,
double time,
double duration,
const Vector<float>& curve,
double curve_points_per_second,
float curve_end_value)
: … { … }
AudioParamTimeline::ParamEvent::ParamEvent(
ParamEvent::Type type,
double time,
std::unique_ptr<ParamEvent> saved_event)
: … { … }
void AudioParamTimeline::SetValueAtTime(float value,
double time,
ExceptionState& exception_state) { … }
void AudioParamTimeline::LinearRampToValueAtTime(
float value,
double time,
float initial_value,
double call_time,
ExceptionState& exception_state) { … }
void AudioParamTimeline::ExponentialRampToValueAtTime(
float value,
double time,
float initial_value,
double call_time,
ExceptionState& exception_state) { … }
void AudioParamTimeline::SetTargetAtTime(float target,
double time,
double time_constant,
ExceptionState& exception_state) { … }
void AudioParamTimeline::SetValueCurveAtTime(const Vector<float>& curve,
double time,
double duration,
ExceptionState& exception_state) { … }
void AudioParamTimeline::InsertEvent(std::unique_ptr<ParamEvent> event,
ExceptionState& exception_state) { … }
bool AudioParamTimeline::HasValues(size_t current_frame,
double sample_rate,
unsigned render_quantum_frames) const { … }
void AudioParamTimeline::CancelScheduledValues(
double cancel_time,
ExceptionState& exception_state) { … }
void AudioParamTimeline::CancelAndHoldAtTime(double cancel_time,
ExceptionState& exception_state) { … }
std::tuple<bool, float> AudioParamTimeline::ValueForContextTime(
AudioDestinationHandler& audio_destination,
float default_value,
float min_value,
float max_value,
unsigned render_quantum_frames) { … }
float AudioParamTimeline::ValuesForFrameRange(size_t start_frame,
size_t end_frame,
float default_value,
float* values,
unsigned number_of_values,
double sample_rate,
double control_rate,
float min_value,
float max_value,
unsigned render_quantum_frames) { … }
float AudioParamTimeline::ValuesForFrameRangeImpl(
size_t start_frame,
size_t end_frame,
float default_value,
float* values,
unsigned number_of_values,
double sample_rate,
double control_rate,
unsigned render_quantum_frames) { … }
std::tuple<size_t, unsigned> AudioParamTimeline::HandleFirstEvent(
float* values,
float default_value,
unsigned number_of_values,
size_t start_frame,
size_t end_frame,
double sample_rate,
size_t current_frame,
unsigned write_index) { … }
bool AudioParamTimeline::IsEventCurrent(const ParamEvent* event,
const ParamEvent* next_event,
size_t current_frame,
double sample_rate) const { … }
void AudioParamTimeline::ClampNewEventsToCurrentTime(double current_time) { … }
bool AudioParamTimeline::HandleAllEventsInThePast(
double current_time,
double sample_rate,
float& default_value,
unsigned number_of_values,
float* values,
unsigned render_quantum_frames) { … }
void AudioParamTimeline::ProcessSetTargetFollowedByRamp(
int event_index,
ParamEvent*& event,
ParamEvent::Type next_event_type,
size_t current_frame,
double sample_rate,
double control_rate,
float& value) { … }
std::tuple<float, double, AudioParamTimeline::ParamEvent::Type>
AudioParamTimeline::HandleCancelValues(const ParamEvent* current_event,
ParamEvent* next_event,
float value2,
double time2) { … }
std::tuple<size_t, float, unsigned> AudioParamTimeline::ProcessLinearRamp(
const AutomationState& current_state,
float* values,
size_t current_frame,
float value,
unsigned write_index) { … }
std::tuple<size_t, float, unsigned> AudioParamTimeline::ProcessExponentialRamp(
const AutomationState& current_state,
float* values,
size_t current_frame,
float value,
unsigned write_index) { … }
std::tuple<size_t, float, unsigned> AudioParamTimeline::ProcessSetTarget(
const AutomationState& current_state,
float* values,
size_t current_frame,
float value,
unsigned write_index) { … }
std::tuple<size_t, float, unsigned> AudioParamTimeline::ProcessSetValueCurve(
const AutomationState& current_state,
float* values,
size_t current_frame,
float value,
unsigned write_index) { … }
std::tuple<size_t, float, unsigned> AudioParamTimeline::ProcessCancelValues(
const AutomationState& current_state,
float* values,
size_t current_frame,
float value,
unsigned write_index) { … }
uint32_t AudioParamTimeline::FillWithDefault(float* values,
float default_value,
uint32_t end_frame,
uint32_t write_index) { … }
void AudioParamTimeline::RemoveCancelledEvents(
wtf_size_t first_event_to_remove) { … }
void AudioParamTimeline::RemoveOldEvents(wtf_size_t event_count) { … }
}