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

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

Issue 1928163002: Add a name attribute for each AudioParam (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix compilation error 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 25 matching lines...) Expand all
36 #include "modules/webaudio/AudioSummingJunction.h" 36 #include "modules/webaudio/AudioSummingJunction.h"
37 #include "wtf/PassRefPtr.h" 37 #include "wtf/PassRefPtr.h"
38 #include "wtf/ThreadSafeRefCounted.h" 38 #include "wtf/ThreadSafeRefCounted.h"
39 #include "wtf/text/WTFString.h" 39 #include "wtf/text/WTFString.h"
40 #include <sys/types.h> 40 #include <sys/types.h>
41 41
42 namespace blink { 42 namespace blink {
43 43
44 class AudioNodeOutput; 44 class AudioNodeOutput;
45 45
46 // Each AudioParam gets an identifier here. This is mostly for instrospection i f warnings or
47 // other messages need to be printed. It's useful to know what the AudioParam re presents. The
48 // name should include the node type and the name of the AudioParam.
49 enum AudioParamType {
50 ParamTypeAudioBufferSourcePlaybackRate,
51 ParamTypeAudioBufferSourceDetune,
52 ParamTypeBiquadFilterFrequency,
53 ParamTypeBiquadFilterQ,
54 ParamTypeBiquadFilterGain,
55 ParamTypeBiquadFilterDetune,
56 ParamTypeDelayDelayTime,
57 ParamTypeDynamicsCompressorThreshold,
58 ParamTypeDynamicsCompressorKnee,
59 ParamTypeDynamicsCompressorRatio,
60 ParamTypeDynamicsCompressorAttack,
61 ParamTypeDynamicsCompressorRelease,
62 ParamTypeGainGain,
63 ParamTypeOscillatorFrequency,
64 ParamTypeOscillatorDetune,
65 ParamTypeStereoPannerPan
66 };
67
46 // AudioParamHandler is an actual implementation of web-exposed AudioParam 68 // AudioParamHandler is an actual implementation of web-exposed AudioParam
47 // interface. Each of AudioParam object creates and owns an AudioParamHandler, 69 // interface. Each of AudioParam object creates and owns an AudioParamHandler,
48 // and it is responsible for all of AudioParam tasks. An AudioParamHandler 70 // and it is responsible for all of AudioParam tasks. An AudioParamHandler
49 // object is owned by the originator AudioParam object, and some audio 71 // object is owned by the originator AudioParam object, and some audio
50 // processing classes have additional references. An AudioParamHandler can 72 // processing classes have additional references. An AudioParamHandler can
51 // outlive the owner AudioParam, and it never dies before the owner AudioParam 73 // outlive the owner AudioParam, and it never dies before the owner AudioParam
52 // dies. 74 // dies.
53 class AudioParamHandler final : public ThreadSafeRefCounted<AudioParamHandler>, public AudioSummingJunction { 75 class AudioParamHandler final : public ThreadSafeRefCounted<AudioParamHandler>, public AudioSummingJunction {
54 public: 76 public:
77 AudioParamType getParamType() const { return m_paramType; }
78 // Return a nice name for the AudioParam.
79 String getParamName() const;
80
55 static const double DefaultSmoothingConstant; 81 static const double DefaultSmoothingConstant;
56 static const double SnapThreshold; 82 static const double SnapThreshold;
57 83
58 static PassRefPtr<AudioParamHandler> create(AbstractAudioContext& context, d ouble defaultValue) 84 static PassRefPtr<AudioParamHandler> create(AbstractAudioContext& context, A udioParamType paramType, double defaultValue)
59 { 85 {
60 return adoptRef(new AudioParamHandler(context, defaultValue)); 86 return adoptRef(new AudioParamHandler(context, paramType, defaultValue)) ;
61 } 87 }
62 88
63 // This should be used only in audio rendering thread. 89 // This should be used only in audio rendering thread.
64 AudioDestinationHandler& destinationHandler() const; 90 AudioDestinationHandler& destinationHandler() const;
65 91
66 // AudioSummingJunction 92 // AudioSummingJunction
67 void didUpdate() override { } 93 void didUpdate() override { }
68 94
69 AudioParamTimeline& timeline() { return m_timeline; } 95 AudioParamTimeline& timeline() { return m_timeline; }
70 96
(...skipping 24 matching lines...) Expand all
95 // Calculates numberOfValues parameter values starting at the context's curr ent time. 121 // Calculates numberOfValues parameter values starting at the context's curr ent time.
96 // Must be called in the context's render thread. 122 // Must be called in the context's render thread.
97 void calculateSampleAccurateValues(float* values, unsigned numberOfValues); 123 void calculateSampleAccurateValues(float* values, unsigned numberOfValues);
98 124
99 // Connect an audio-rate signal to control this parameter. 125 // Connect an audio-rate signal to control this parameter.
100 void connect(AudioNodeOutput&); 126 void connect(AudioNodeOutput&);
101 void disconnect(AudioNodeOutput&); 127 void disconnect(AudioNodeOutput&);
102 128
103 float intrinsicValue() const { return noBarrierLoad(&m_intrinsicValue); } 129 float intrinsicValue() const { return noBarrierLoad(&m_intrinsicValue); }
104 private: 130 private:
105 AudioParamHandler(AbstractAudioContext& context, double defaultValue) 131 AudioParamHandler(AbstractAudioContext& context, AudioParamType paramType, d ouble defaultValue)
106 : AudioSummingJunction(context.deferredTaskHandler()) 132 : AudioSummingJunction(context.deferredTaskHandler())
133 , m_paramType(paramType)
107 , m_intrinsicValue(defaultValue) 134 , m_intrinsicValue(defaultValue)
108 , m_defaultValue(defaultValue) 135 , m_defaultValue(defaultValue)
109 , m_smoothedValue(defaultValue) 136 , m_smoothedValue(defaultValue)
110 , m_destinationHandler(context.destination()->audioDestinationHandler()) 137 , m_destinationHandler(context.destination()->audioDestinationHandler())
111 { } 138 { }
112 139
113 // sampleAccurate corresponds to a-rate (audio rate) vs. k-rate in the Web A udio specification. 140 // sampleAccurate corresponds to a-rate (audio rate) vs. k-rate in the Web A udio specification.
114 void calculateFinalValues(float* values, unsigned numberOfValues, bool sampl eAccurate); 141 void calculateFinalValues(float* values, unsigned numberOfValues, bool sampl eAccurate);
115 void calculateTimelineValues(float* values, unsigned numberOfValues); 142 void calculateTimelineValues(float* values, unsigned numberOfValues);
116 143
144 // The type of AudioParam, indicating what this AudioParam represents and wh at node it belongs
145 // to. Mostly for informational purposes and doesn't affect implementation.
146 AudioParamType m_paramType;
147
117 // Intrinsic value 148 // Intrinsic value
118 float m_intrinsicValue; 149 float m_intrinsicValue;
119 void setIntrinsicValue(float newValue) { noBarrierStore(&m_intrinsicValue, n ewValue); } 150 void setIntrinsicValue(float newValue) { noBarrierStore(&m_intrinsicValue, n ewValue); }
120 151
121 float m_defaultValue; 152 float m_defaultValue;
122 153
123 // Smoothing (de-zippering) 154 // Smoothing (de-zippering)
124 float m_smoothedValue; 155 float m_smoothedValue;
125 156
126 AudioParamTimeline m_timeline; 157 AudioParamTimeline m_timeline;
127 158
128 // The destination node used to get necessary information like the smaple ra te and context time. 159 // The destination node used to get necessary information like the smaple ra te and context time.
129 RefPtr<AudioDestinationHandler> m_destinationHandler; 160 RefPtr<AudioDestinationHandler> m_destinationHandler;
130 }; 161 };
131 162
132 // AudioParam class represents web-exposed AudioParam interface. 163 // AudioParam class represents web-exposed AudioParam interface.
133 class AudioParam final : public GarbageCollectedFinalized<AudioParam>, public Sc riptWrappable { 164 class AudioParam final : public GarbageCollectedFinalized<AudioParam>, public Sc riptWrappable {
134 DEFINE_WRAPPERTYPEINFO(); 165 DEFINE_WRAPPERTYPEINFO();
135 public: 166 public:
136 static AudioParam* create(AbstractAudioContext&, double defaultValue); 167 static AudioParam* create(AbstractAudioContext&, AudioParamType, double defa ultValue);
137 DECLARE_TRACE(); 168 DECLARE_TRACE();
138 // |handler| always returns a valid object. 169 // |handler| always returns a valid object.
139 AudioParamHandler& handler() const { return *m_handler; } 170 AudioParamHandler& handler() const { return *m_handler; }
140 // |context| always returns a valid object. 171 // |context| always returns a valid object.
141 AbstractAudioContext* context() const { return m_context; } 172 AbstractAudioContext* context() const { return m_context; }
142 173
174 AudioParamType getParamType() const { return handler().getParamType(); }
175 String getParamName() const;
176
143 float value() const; 177 float value() const;
144 void setValue(float); 178 void setValue(float);
145 float defaultValue() const; 179 float defaultValue() const;
146 AudioParam* setValueAtTime(float value, double time, ExceptionState&); 180 AudioParam* setValueAtTime(float value, double time, ExceptionState&);
147 AudioParam* linearRampToValueAtTime(float value, double time, ExceptionState &); 181 AudioParam* linearRampToValueAtTime(float value, double time, ExceptionState &);
148 AudioParam* exponentialRampToValueAtTime(float value, double time, Exception State&); 182 AudioParam* exponentialRampToValueAtTime(float value, double time, Exception State&);
149 AudioParam* setTargetAtTime(float target, double time, double timeConstant, ExceptionState&); 183 AudioParam* setTargetAtTime(float target, double time, double timeConstant, ExceptionState&);
150 AudioParam* setValueCurveAtTime(DOMFloat32Array* curve, double time, double duration, ExceptionState&); 184 AudioParam* setValueCurveAtTime(DOMFloat32Array* curve, double time, double duration, ExceptionState&);
151 AudioParam* cancelScheduledValues(double startTime, ExceptionState&); 185 AudioParam* cancelScheduledValues(double startTime, ExceptionState&);
152 186
153 private: 187 private:
154 AudioParam(AbstractAudioContext&, double defaultValue); 188 AudioParam(AbstractAudioContext&, AudioParamType, double defaultValue);
155 189
156 RefPtr<AudioParamHandler> m_handler; 190 RefPtr<AudioParamHandler> m_handler;
157 Member<AbstractAudioContext> m_context; 191 Member<AbstractAudioContext> m_context;
158 }; 192 };
159 193
160 } // namespace blink 194 } // namespace blink
161 195
162 #endif // AudioParam_h 196 #endif // AudioParam_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698