AudioParamTimeline.h [plain text]
#ifndef AudioParamTimeline_h
#define AudioParamTimeline_h
#include "AudioContext.h"
#include <wtf/Float32Array.h>
#include <wtf/PassRefPtr.h>
#include <wtf/RefCounted.h>
#include <wtf/Threading.h>
#include <wtf/Vector.h>
namespace WebCore {
class AudioParamTimeline {
public:
AudioParamTimeline()
: m_currentEventIndex(0)
, m_value(0)
{
}
void setValueAtTime(float value, float time);
void linearRampToValueAtTime(float value, float time);
void exponentialRampToValueAtTime(float value, float time);
void setTargetValueAtTime(float targetValue, float time, float timeConstant);
void setValueCurveAtTime(Float32Array* curve, float time, float duration);
void cancelScheduledValues(float startTime);
float valueForContextTime(AudioContext*, float defaultValue, bool& hasValue);
float valuesForTimeRange(float startTime, float endTime, float defaultValue, float* values, unsigned numberOfValues, float sampleRate, float controlRate);
bool hasValues() { return m_events.size(); }
private:
class ParamEvent {
public:
enum Type {
SetValue,
LinearRampToValue,
ExponentialRampToValue,
SetTargetValue,
SetValueCurve,
LastType
};
ParamEvent(Type type, float value, float time, float timeConstant, float duration, PassRefPtr<Float32Array> curve)
: m_type(type)
, m_value(value)
, m_time(time)
, m_timeConstant(timeConstant)
, m_duration(duration)
, m_curve(curve)
{
}
unsigned type() const { return m_type; }
float value() const { return m_value; }
float time() const { return m_time; }
float timeConstant() const { return m_timeConstant; }
float duration() const { return m_duration; }
Float32Array* curve() { return m_curve.get(); }
private:
unsigned m_type;
float m_value;
float m_time;
float m_timeConstant;
float m_duration;
RefPtr<Float32Array> m_curve;
};
void insertEvent(const ParamEvent&);
float valuesForTimeRangeImpl(float startTime, float endTime, float defaultValue, float* values, unsigned numberOfValues, float sampleRate, float controlRate);
Vector<ParamEvent> m_events;
unsigned m_currentEventIndex;
float m_value;
Mutex m_eventsLock;
};
}
#endif // AudioParamTimeline_h