OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 class AudioParamHandler final : public ThreadSafeRefCounted<AudioParamHandler>,
public AudioSummingJunction { | 77 class AudioParamHandler final : public ThreadSafeRefCounted<AudioParamHandler>,
public AudioSummingJunction { |
78 public: | 78 public: |
79 AudioParamType getParamType() const { return m_paramType; } | 79 AudioParamType getParamType() const { return m_paramType; } |
80 void setParamType(AudioParamType); | 80 void setParamType(AudioParamType); |
81 // Return a nice name for the AudioParam. | 81 // Return a nice name for the AudioParam. |
82 String getParamName() const; | 82 String getParamName() const; |
83 | 83 |
84 static const double DefaultSmoothingConstant; | 84 static const double DefaultSmoothingConstant; |
85 static const double SnapThreshold; | 85 static const double SnapThreshold; |
86 | 86 |
87 static PassRefPtr<AudioParamHandler> create(AbstractAudioContext& context, A
udioParamType paramType, double defaultValue) | 87 static PassRefPtr<AudioParamHandler> create( |
| 88 AbstractAudioContext& context, |
| 89 AudioParamType paramType, |
| 90 double defaultValue, |
| 91 float minValue, |
| 92 float maxValue) |
88 { | 93 { |
89 return adoptRef(new AudioParamHandler(context, paramType, defaultValue))
; | 94 return adoptRef(new AudioParamHandler(context, paramType, defaultValue,
minValue, maxValue)); |
90 } | 95 } |
91 | 96 |
92 // This should be used only in audio rendering thread. | 97 // This should be used only in audio rendering thread. |
93 AudioDestinationHandler& destinationHandler() const; | 98 AudioDestinationHandler& destinationHandler() const; |
94 | 99 |
95 // AudioSummingJunction | 100 // AudioSummingJunction |
96 void didUpdate() override { } | 101 void didUpdate() override { } |
97 | 102 |
98 AudioParamTimeline& timeline() { return m_timeline; } | 103 AudioParamTimeline& timeline() { return m_timeline; } |
99 | 104 |
100 // Intrinsic value. | 105 // Intrinsic value. |
101 float value(); | 106 float value(); |
102 void setValue(float); | 107 void setValue(float); |
103 | 108 |
104 // Final value for k-rate parameters, otherwise use calculateSampleAccurateV
alues() for a-rate. | 109 // Final value for k-rate parameters, otherwise use calculateSampleAccurateV
alues() for a-rate. |
105 // Must be called in the audio thread. | 110 // Must be called in the audio thread. |
106 float finalValue(); | 111 float finalValue(); |
107 | 112 |
108 float defaultValue() const { return static_cast<float>(m_defaultValue); } | 113 float defaultValue() const { return static_cast<float>(m_defaultValue); } |
| 114 float minValue() const { return m_minValue; } |
| 115 float maxValue() const { return m_maxValue; } |
109 | 116 |
110 // Value smoothing: | 117 // Value smoothing: |
111 | 118 |
112 // When a new value is set with setValue(), in our internal use of the param
eter we don't immediately jump to it. | 119 // When a new value is set with setValue(), in our internal use of the param
eter we don't immediately jump to it. |
113 // Instead we smoothly approach this value to avoid glitching. | 120 // Instead we smoothly approach this value to avoid glitching. |
114 float smoothedValue(); | 121 float smoothedValue(); |
115 | 122 |
116 // Smoothly exponentially approaches to (de-zippers) the desired value. | 123 // Smoothly exponentially approaches to (de-zippers) the desired value. |
117 // Returns true if smoothed value has already snapped exactly to value. | 124 // Returns true if smoothed value has already snapped exactly to value. |
118 bool smooth(); | 125 bool smooth(); |
119 | 126 |
120 void resetSmoothedValue() { m_smoothedValue = intrinsicValue(); } | 127 void resetSmoothedValue() { m_smoothedValue = intrinsicValue(); } |
121 | 128 |
122 bool hasSampleAccurateValues() { return m_timeline.hasValues() || numberOfRe
nderingConnections(); } | 129 bool hasSampleAccurateValues() { return m_timeline.hasValues() || numberOfRe
nderingConnections(); } |
123 | 130 |
124 // Calculates numberOfValues parameter values starting at the context's curr
ent time. | 131 // Calculates numberOfValues parameter values starting at the context's curr
ent time. |
125 // Must be called in the context's render thread. | 132 // Must be called in the context's render thread. |
126 void calculateSampleAccurateValues(float* values, unsigned numberOfValues); | 133 void calculateSampleAccurateValues(float* values, unsigned numberOfValues); |
127 | 134 |
128 // Connect an audio-rate signal to control this parameter. | 135 // Connect an audio-rate signal to control this parameter. |
129 void connect(AudioNodeOutput&); | 136 void connect(AudioNodeOutput&); |
130 void disconnect(AudioNodeOutput&); | 137 void disconnect(AudioNodeOutput&); |
131 | 138 |
132 float intrinsicValue() const { return noBarrierLoad(&m_intrinsicValue); } | 139 float intrinsicValue() const { return noBarrierLoad(&m_intrinsicValue); } |
133 | 140 |
134 // Update any histograms with the given value. | 141 // Update any histograms with the given value. |
135 void updateHistograms(float newValue); | 142 void updateHistograms(float newValue); |
136 | 143 |
137 private: | 144 private: |
138 AudioParamHandler(AbstractAudioContext&, AudioParamType, double defaultValue
); | 145 AudioParamHandler(AbstractAudioContext&, AudioParamType, double defaultValue
, float min, float max); |
| 146 |
| 147 void warnIfOutsideRange(float value, float minValue, float maxValue); |
139 | 148 |
140 // sampleAccurate corresponds to a-rate (audio rate) vs. k-rate in the Web A
udio specification. | 149 // sampleAccurate corresponds to a-rate (audio rate) vs. k-rate in the Web A
udio specification. |
141 void calculateFinalValues(float* values, unsigned numberOfValues, bool sampl
eAccurate); | 150 void calculateFinalValues(float* values, unsigned numberOfValues, bool sampl
eAccurate); |
142 void calculateTimelineValues(float* values, unsigned numberOfValues); | 151 void calculateTimelineValues(float* values, unsigned numberOfValues); |
143 | 152 |
144 int computeQHistogramValue(float) const; | 153 int computeQHistogramValue(float) const; |
145 | 154 |
146 // The type of AudioParam, indicating what this AudioParam represents and wh
at node it belongs | 155 // The type of AudioParam, indicating what this AudioParam represents and wh
at node it belongs |
147 // to. Mostly for informational purposes and doesn't affect implementation. | 156 // to. Mostly for informational purposes and doesn't affect implementation. |
148 AudioParamType m_paramType; | 157 AudioParamType m_paramType; |
149 | 158 |
150 // Intrinsic value | 159 // Intrinsic value |
151 float m_intrinsicValue; | 160 float m_intrinsicValue; |
152 void setIntrinsicValue(float newValue) { noBarrierStore(&m_intrinsicValue, n
ewValue); } | 161 void setIntrinsicValue(float newValue); |
153 | 162 |
154 float m_defaultValue; | 163 float m_defaultValue; |
155 | 164 |
| 165 // Nominal range for the value |
| 166 float m_minValue; |
| 167 float m_maxValue; |
| 168 |
156 // Smoothing (de-zippering) | 169 // Smoothing (de-zippering) |
157 float m_smoothedValue; | 170 float m_smoothedValue; |
158 | 171 |
159 AudioParamTimeline m_timeline; | 172 AudioParamTimeline m_timeline; |
160 | 173 |
161 // The destination node used to get necessary information like the smaple ra
te and context time. | 174 // The destination node used to get necessary information like the smaple ra
te and context time. |
162 RefPtr<AudioDestinationHandler> m_destinationHandler; | 175 RefPtr<AudioDestinationHandler> m_destinationHandler; |
163 }; | 176 }; |
164 | 177 |
165 // AudioParam class represents web-exposed AudioParam interface. | 178 // AudioParam class represents web-exposed AudioParam interface. |
166 class AudioParam final : public GarbageCollectedFinalized<AudioParam>, public Sc
riptWrappable { | 179 class AudioParam final : public GarbageCollectedFinalized<AudioParam>, public Sc
riptWrappable { |
167 DEFINE_WRAPPERTYPEINFO(); | 180 DEFINE_WRAPPERTYPEINFO(); |
168 public: | 181 public: |
169 static AudioParam* create(AbstractAudioContext&, AudioParamType, double defa
ultValue); | 182 static AudioParam* create(AbstractAudioContext&, AudioParamType, double defa
ultValue); |
| 183 static AudioParam* create(AbstractAudioContext&, AudioParamType, double defa
ultValue, float minValue, float maxValue); |
| 184 |
170 DECLARE_TRACE(); | 185 DECLARE_TRACE(); |
171 // |handler| always returns a valid object. | 186 // |handler| always returns a valid object. |
172 AudioParamHandler& handler() const { return *m_handler; } | 187 AudioParamHandler& handler() const { return *m_handler; } |
173 // |context| always returns a valid object. | 188 // |context| always returns a valid object. |
174 AbstractAudioContext* context() const { return m_context; } | 189 AbstractAudioContext* context() const { return m_context; } |
175 | 190 |
176 AudioParamType getParamType() const { return handler().getParamType(); } | 191 AudioParamType getParamType() const { return handler().getParamType(); } |
177 void setParamType(AudioParamType); | 192 void setParamType(AudioParamType); |
178 String getParamName() const; | 193 String getParamName() const; |
179 | 194 |
180 float value() const; | 195 float value() const; |
181 void setValue(float); | 196 void setValue(float); |
182 float defaultValue() const; | 197 float defaultValue() const; |
| 198 |
| 199 float minValue() const; |
| 200 float maxValue() const; |
| 201 |
183 AudioParam* setValueAtTime(float value, double time, ExceptionState&); | 202 AudioParam* setValueAtTime(float value, double time, ExceptionState&); |
184 AudioParam* linearRampToValueAtTime(float value, double time, ExceptionState
&); | 203 AudioParam* linearRampToValueAtTime(float value, double time, ExceptionState
&); |
185 AudioParam* exponentialRampToValueAtTime(float value, double time, Exception
State&); | 204 AudioParam* exponentialRampToValueAtTime(float value, double time, Exception
State&); |
186 AudioParam* setTargetAtTime(float target, double time, double timeConstant,
ExceptionState&); | 205 AudioParam* setTargetAtTime(float target, double time, double timeConstant,
ExceptionState&); |
187 AudioParam* setValueCurveAtTime(DOMFloat32Array* curve, double time, double
duration, ExceptionState&); | 206 AudioParam* setValueCurveAtTime(DOMFloat32Array* curve, double time, double
duration, ExceptionState&); |
188 AudioParam* cancelScheduledValues(double startTime, ExceptionState&); | 207 AudioParam* cancelScheduledValues(double startTime, ExceptionState&); |
189 | 208 |
190 private: | 209 private: |
191 AudioParam(AbstractAudioContext&, AudioParamType, double defaultValue); | 210 AudioParam(AbstractAudioContext&, AudioParamType, double defaultValue, float
min, float max); |
| 211 |
| 212 void warnIfOutsideRange(const String& paramMethd, float value); |
192 | 213 |
193 RefPtr<AudioParamHandler> m_handler; | 214 RefPtr<AudioParamHandler> m_handler; |
194 Member<AbstractAudioContext> m_context; | 215 Member<AbstractAudioContext> m_context; |
195 }; | 216 }; |
196 | 217 |
197 } // namespace blink | 218 } // namespace blink |
198 | 219 |
199 #endif // AudioParam_h | 220 #endif // AudioParam_h |
OLD | NEW |