Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: third_party/WebKit/Source/modules/webaudio/AudioParam.h

Issue 1803153002: Add min/max values for AudioParams (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 // dies. 74 // dies.
75 class AudioParamHandler final : public ThreadSafeRefCounted<AudioParamHandler>, public AudioSummingJunction { 75 class AudioParamHandler final : public ThreadSafeRefCounted<AudioParamHandler>, public AudioSummingJunction {
76 public: 76 public:
77 AudioParamType getParamType() const { return m_paramType; } 77 AudioParamType getParamType() const { return m_paramType; }
78 // Return a nice name for the AudioParam. 78 // Return a nice name for the AudioParam.
79 String getParamName() const; 79 String getParamName() const;
80 80
81 static const double DefaultSmoothingConstant; 81 static const double DefaultSmoothingConstant;
82 static const double SnapThreshold; 82 static const double SnapThreshold;
83 83
84 static PassRefPtr<AudioParamHandler> create(AbstractAudioContext& context, A udioParamType paramType, double defaultValue) 84 static PassRefPtr<AudioParamHandler> create(
85 AbstractAudioContext& context,
86 AudioParamType paramType,
87 double defaultValue,
88 float min,
89 float max)
hongchan 2016/05/13 01:30:15 Even for internal variables - I suggest we should
Raymond Toy 2016/05/13 18:40:32 Done.
85 { 90 {
86 return adoptRef(new AudioParamHandler(context, paramType, defaultValue)) ; 91 return adoptRef(new AudioParamHandler(context, paramType, defaultValue, min, max));
hongchan 2016/05/13 01:30:15 Ditto.
Raymond Toy 2016/05/13 18:40:32 Done.
87 } 92 }
88 93
89 // This should be used only in audio rendering thread. 94 // This should be used only in audio rendering thread.
90 AudioDestinationHandler& destinationHandler() const; 95 AudioDestinationHandler& destinationHandler() const;
91 96
92 // AudioSummingJunction 97 // AudioSummingJunction
93 void didUpdate() override { } 98 void didUpdate() override { }
94 99
95 AudioParamTimeline& timeline() { return m_timeline; } 100 AudioParamTimeline& timeline() { return m_timeline; }
96 101
97 // Intrinsic value. 102 // Intrinsic value.
98 float value(); 103 float value();
99 void setValue(float); 104 void setValue(float);
100 105
101 // Final value for k-rate parameters, otherwise use calculateSampleAccurateV alues() for a-rate. 106 // Final value for k-rate parameters, otherwise use calculateSampleAccurateV alues() for a-rate.
102 // Must be called in the audio thread. 107 // Must be called in the audio thread.
103 float finalValue(); 108 float finalValue();
104 109
105 float defaultValue() const { return static_cast<float>(m_defaultValue); } 110 float defaultValue() const { return static_cast<float>(m_defaultValue); }
111 float minValue() const { return m_minValue; }
112 float maxValue() const { return m_maxValue; }
106 113
107 // Value smoothing: 114 // Value smoothing:
108 115
109 // When a new value is set with setValue(), in our internal use of the param eter we don't immediately jump to it. 116 // When a new value is set with setValue(), in our internal use of the param eter we don't immediately jump to it.
110 // Instead we smoothly approach this value to avoid glitching. 117 // Instead we smoothly approach this value to avoid glitching.
111 float smoothedValue(); 118 float smoothedValue();
112 119
113 // Smoothly exponentially approaches to (de-zippers) the desired value. 120 // Smoothly exponentially approaches to (de-zippers) the desired value.
114 // Returns true if smoothed value has already snapped exactly to value. 121 // Returns true if smoothed value has already snapped exactly to value.
115 bool smooth(); 122 bool smooth();
116 123
117 void resetSmoothedValue() { m_smoothedValue = intrinsicValue(); } 124 void resetSmoothedValue() { m_smoothedValue = intrinsicValue(); }
118 125
119 bool hasSampleAccurateValues() { return m_timeline.hasValues() || numberOfRe nderingConnections(); } 126 bool hasSampleAccurateValues() { return m_timeline.hasValues() || numberOfRe nderingConnections(); }
120 127
121 // Calculates numberOfValues parameter values starting at the context's curr ent time. 128 // Calculates numberOfValues parameter values starting at the context's curr ent time.
122 // Must be called in the context's render thread. 129 // Must be called in the context's render thread.
123 void calculateSampleAccurateValues(float* values, unsigned numberOfValues); 130 void calculateSampleAccurateValues(float* values, unsigned numberOfValues);
124 131
125 // Connect an audio-rate signal to control this parameter. 132 // Connect an audio-rate signal to control this parameter.
126 void connect(AudioNodeOutput&); 133 void connect(AudioNodeOutput&);
127 void disconnect(AudioNodeOutput&); 134 void disconnect(AudioNodeOutput&);
128 135
129 float intrinsicValue() const { return noBarrierLoad(&m_intrinsicValue); } 136 float intrinsicValue() const { return noBarrierLoad(&m_intrinsicValue); }
130 private: 137 private:
131 AudioParamHandler(AbstractAudioContext&, AudioParamType, double defaultValue ); 138 AudioParamHandler(AbstractAudioContext&, AudioParamType, double defaultValue , float min, float max);
139
140 void warnIfOutsideRange(float value, float minValue, float maxValue);
132 141
133 // sampleAccurate corresponds to a-rate (audio rate) vs. k-rate in the Web A udio specification. 142 // sampleAccurate corresponds to a-rate (audio rate) vs. k-rate in the Web A udio specification.
134 void calculateFinalValues(float* values, unsigned numberOfValues, bool sampl eAccurate); 143 void calculateFinalValues(float* values, unsigned numberOfValues, bool sampl eAccurate);
135 void calculateTimelineValues(float* values, unsigned numberOfValues); 144 void calculateTimelineValues(float* values, unsigned numberOfValues);
136 145
137 // The type of AudioParam, indicating what this AudioParam represents and wh at node it belongs 146 // The type of AudioParam, indicating what this AudioParam represents and wh at node it belongs
138 // to. Mostly for informational purposes and doesn't affect implementation. 147 // to. Mostly for informational purposes and doesn't affect implementation.
139 AudioParamType m_paramType; 148 AudioParamType m_paramType;
140 149
141 // Intrinsic value 150 // Intrinsic value
142 float m_intrinsicValue; 151 float m_intrinsicValue;
143 void setIntrinsicValue(float newValue) { noBarrierStore(&m_intrinsicValue, n ewValue); } 152 void setIntrinsicValue(float newValue);
144 153
145 float m_defaultValue; 154 float m_defaultValue;
146 155
156 // Nominal range for the value
157 float m_minValue;
158 float m_maxValue;
159
147 // Smoothing (de-zippering) 160 // Smoothing (de-zippering)
148 float m_smoothedValue; 161 float m_smoothedValue;
149 162
150 AudioParamTimeline m_timeline; 163 AudioParamTimeline m_timeline;
151 164
152 // The destination node used to get necessary information like the smaple ra te and context time. 165 // The destination node used to get necessary information like the smaple ra te and context time.
153 RefPtr<AudioDestinationHandler> m_destinationHandler; 166 RefPtr<AudioDestinationHandler> m_destinationHandler;
154 }; 167 };
155 168
156 // AudioParam class represents web-exposed AudioParam interface. 169 // AudioParam class represents web-exposed AudioParam interface.
157 class AudioParam final : public GarbageCollectedFinalized<AudioParam>, public Sc riptWrappable { 170 class AudioParam final : public GarbageCollectedFinalized<AudioParam>, public Sc riptWrappable {
158 DEFINE_WRAPPERTYPEINFO(); 171 DEFINE_WRAPPERTYPEINFO();
159 public: 172 public:
160 static AudioParam* create(AbstractAudioContext&, AudioParamType, double defa ultValue); 173 static AudioParam* create(AbstractAudioContext&, AudioParamType, double defa ultValue);
174 static AudioParam* create(AbstractAudioContext&, AudioParamType, double defa ultValue, float min, float max);
hongchan 2016/05/13 01:30:15 Here as well.
Raymond Toy 2016/05/13 18:40:32 Done.
175
161 DECLARE_TRACE(); 176 DECLARE_TRACE();
162 // |handler| always returns a valid object. 177 // |handler| always returns a valid object.
163 AudioParamHandler& handler() const { return *m_handler; } 178 AudioParamHandler& handler() const { return *m_handler; }
164 // |context| always returns a valid object. 179 // |context| always returns a valid object.
165 AbstractAudioContext* context() const { return m_context; } 180 AbstractAudioContext* context() const { return m_context; }
166 181
167 AudioParamType getParamType() const { return handler().getParamType(); } 182 AudioParamType getParamType() const { return handler().getParamType(); }
168 String getParamName() const; 183 String getParamName() const;
169 184
170 float value() const; 185 float value() const;
171 void setValue(float); 186 void setValue(float);
172 float defaultValue() const; 187 float defaultValue() const;
188
189 float minValue() const;
190 float maxValue() const;
191
173 AudioParam* setValueAtTime(float value, double time, ExceptionState&); 192 AudioParam* setValueAtTime(float value, double time, ExceptionState&);
174 AudioParam* linearRampToValueAtTime(float value, double time, ExceptionState &); 193 AudioParam* linearRampToValueAtTime(float value, double time, ExceptionState &);
175 AudioParam* exponentialRampToValueAtTime(float value, double time, Exception State&); 194 AudioParam* exponentialRampToValueAtTime(float value, double time, Exception State&);
176 AudioParam* setTargetAtTime(float target, double time, double timeConstant, ExceptionState&); 195 AudioParam* setTargetAtTime(float target, double time, double timeConstant, ExceptionState&);
177 AudioParam* setValueCurveAtTime(DOMFloat32Array* curve, double time, double duration, ExceptionState&); 196 AudioParam* setValueCurveAtTime(DOMFloat32Array* curve, double time, double duration, ExceptionState&);
178 AudioParam* cancelScheduledValues(double startTime, ExceptionState&); 197 AudioParam* cancelScheduledValues(double startTime, ExceptionState&);
179 198
180 private: 199 private:
181 AudioParam(AbstractAudioContext&, AudioParamType, double defaultValue); 200 AudioParam(AbstractAudioContext&, AudioParamType, double defaultValue, float min, float max);
hongchan 2016/05/13 01:30:15 Ditto.
Raymond Toy 2016/05/13 18:40:32 Done.
201
202 void warnIfOutsideRange(float value, float minValue, float maxValue);
182 203
183 RefPtr<AudioParamHandler> m_handler; 204 RefPtr<AudioParamHandler> m_handler;
184 Member<AbstractAudioContext> m_context; 205 Member<AbstractAudioContext> m_context;
185 }; 206 };
186 207
187 } // namespace blink 208 } // namespace blink
188 209
189 #endif // AudioParam_h 210 #endif // AudioParam_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698