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

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

Issue 1911133002: Remove connection from AudioParamHandler to AudioContext. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments 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 17 matching lines...) Expand all
28 #include "modules/webaudio/AudioNodeOutput.h" 28 #include "modules/webaudio/AudioNodeOutput.h"
29 #include "platform/FloatConversion.h" 29 #include "platform/FloatConversion.h"
30 #include "platform/audio/AudioUtilities.h" 30 #include "platform/audio/AudioUtilities.h"
31 #include "wtf/MathExtras.h" 31 #include "wtf/MathExtras.h"
32 32
33 namespace blink { 33 namespace blink {
34 34
35 const double AudioParamHandler::DefaultSmoothingConstant = 0.05; 35 const double AudioParamHandler::DefaultSmoothingConstant = 0.05;
36 const double AudioParamHandler::SnapThreshold = 0.001; 36 const double AudioParamHandler::SnapThreshold = 0.001;
37 37
38 AbstractAudioContext* AudioParamHandler::context() const 38 AudioDestinationHandler& AudioParamHandler::audioDestination() const
39 { 39 {
40 // TODO(tkent): We can remove this dangerous function by removing 40 return *m_destination;
hongchan 2016/04/26 17:04:00 Perhaps: audioDestination() => destinationHandler(
41 // AbstractAudioContext dependency from AudioParamTimeline.
42 ASSERT_WITH_SECURITY_IMPLICATION(deferredTaskHandler().isAudioThread());
43 return m_context;
44 } 41 }
45 42
46 float AudioParamHandler::value() 43 float AudioParamHandler::value()
47 { 44 {
48 // Update value for timeline. 45 // Update value for timeline.
49 float v = intrinsicValue(); 46 float v = intrinsicValue();
50 if (deferredTaskHandler().isAudioThread()) { 47 if (deferredTaskHandler().isAudioThread()) {
51 bool hasValue; 48 bool hasValue;
52 float timelineValue = m_timeline.valueForContextTime(context(), v, hasVa lue); 49 float timelineValue = m_timeline.valueForContextTime(audioDestination(), v, hasValue);
53 50
54 if (hasValue) 51 if (hasValue)
55 v = timelineValue; 52 v = timelineValue;
56 } 53 }
57 54
58 setIntrinsicValue(v); 55 setIntrinsicValue(v);
59 return v; 56 return v;
60 } 57 }
61 58
62 void AudioParamHandler::setValue(float value) 59 void AudioParamHandler::setValue(float value)
63 { 60 {
64 setIntrinsicValue(value); 61 setIntrinsicValue(value);
65 } 62 }
66 63
67 float AudioParamHandler::smoothedValue() 64 float AudioParamHandler::smoothedValue()
68 { 65 {
69 return m_smoothedValue; 66 return m_smoothedValue;
70 } 67 }
71 68
72 bool AudioParamHandler::smooth() 69 bool AudioParamHandler::smooth()
73 { 70 {
74 // If values have been explicitly scheduled on the timeline, then use the ex act value. 71 // If values have been explicitly scheduled on the timeline, then use the ex act value.
75 // Smoothing effectively is performed by the timeline. 72 // Smoothing effectively is performed by the timeline.
76 bool useTimelineValue = false; 73 bool useTimelineValue = false;
77 float value = intrinsicValue(); 74 float value = m_timeline.valueForContextTime(audioDestination(), intrinsicVa lue(), useTimelineValue);
78 if (context())
79 value = m_timeline.valueForContextTime(context(), value, useTimelineValu e);
80 75
81 if (m_smoothedValue == value) { 76 if (m_smoothedValue == value) {
82 // Smoothed value has already approached and snapped to value. 77 // Smoothed value has already approached and snapped to value.
83 setIntrinsicValue(value); 78 setIntrinsicValue(value);
84 return true; 79 return true;
85 } 80 }
86 81
87 if (useTimelineValue) { 82 if (useTimelineValue) {
88 m_smoothedValue = value; 83 m_smoothedValue = value;
89 } else { 84 } else {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 122
128 // The calculated result will be the "intrinsic" value summed with all audio -rate connections. 123 // The calculated result will be the "intrinsic" value summed with all audio -rate connections.
129 124
130 if (sampleAccurate) { 125 if (sampleAccurate) {
131 // Calculate sample-accurate (a-rate) intrinsic values. 126 // Calculate sample-accurate (a-rate) intrinsic values.
132 calculateTimelineValues(values, numberOfValues); 127 calculateTimelineValues(values, numberOfValues);
133 } else { 128 } else {
134 // Calculate control-rate (k-rate) intrinsic value. 129 // Calculate control-rate (k-rate) intrinsic value.
135 bool hasValue; 130 bool hasValue;
136 float value = intrinsicValue(); 131 float value = intrinsicValue();
137 float timelineValue = m_timeline.valueForContextTime(context(), value, h asValue); 132 float timelineValue = m_timeline.valueForContextTime(audioDestination(), value, hasValue);
138 133
139 if (hasValue) 134 if (hasValue)
140 value = timelineValue; 135 value = timelineValue;
141 136
142 values[0] = value; 137 values[0] = value;
143 setIntrinsicValue(value); 138 setIntrinsicValue(value);
144 } 139 }
145 140
146 // Now sum all of the audio-rate connections together (unity-gain summing ju nction). 141 // Now sum all of the audio-rate connections together (unity-gain summing ju nction).
147 // Note that connections would normally be mono, but we mix down to mono if necessary. 142 // Note that connections would normally be mono, but we mix down to mono if necessary.
148 RefPtr<AudioBus> summingBus = AudioBus::create(1, numberOfValues, false); 143 RefPtr<AudioBus> summingBus = AudioBus::create(1, numberOfValues, false);
149 summingBus->setChannelMemory(0, values, numberOfValues); 144 summingBus->setChannelMemory(0, values, numberOfValues);
150 145
151 for (unsigned i = 0; i < numberOfRenderingConnections(); ++i) { 146 for (unsigned i = 0; i < numberOfRenderingConnections(); ++i) {
152 AudioNodeOutput* output = renderingOutput(i); 147 AudioNodeOutput* output = renderingOutput(i);
153 ASSERT(output); 148 ASSERT(output);
154 149
155 // Render audio from this output. 150 // Render audio from this output.
156 AudioBus* connectionBus = output->pull(0, AudioHandler::ProcessingSizeIn Frames); 151 AudioBus* connectionBus = output->pull(0, AudioHandler::ProcessingSizeIn Frames);
157 152
158 // Sum, with unity-gain. 153 // Sum, with unity-gain.
159 summingBus->sumFrom(*connectionBus); 154 summingBus->sumFrom(*connectionBus);
160 } 155 }
161 } 156 }
162 157
163 void AudioParamHandler::calculateTimelineValues(float* values, unsigned numberOf Values) 158 void AudioParamHandler::calculateTimelineValues(float* values, unsigned numberOf Values)
164 { 159 {
165 // Calculate values for this render quantum. Normally numberOfValues will 160 // Calculate values for this render quantum. Normally numberOfValues will
166 // equal to AudioHandler::ProcessingSizeInFrames (the render quantum size). 161 // equal to AudioHandler::ProcessingSizeInFrames (the render quantum size).
167 double sampleRate = context()->sampleRate(); 162 double sampleRate = audioDestination().sampleRate();
168 size_t startFrame = context()->currentSampleFrame(); 163 size_t startFrame = audioDestination().currentSampleFrame();
169 size_t endFrame = startFrame + numberOfValues; 164 size_t endFrame = startFrame + numberOfValues;
170 165
171 // Note we're running control rate at the sample-rate. 166 // Note we're running control rate at the sample-rate.
172 // Pass in the current value as default value. 167 // Pass in the current value as default value.
173 setIntrinsicValue(m_timeline.valuesForFrameRange(startFrame, endFrame, intri nsicValue(), values, numberOfValues, sampleRate, sampleRate)); 168 setIntrinsicValue(m_timeline.valuesForFrameRange(startFrame, endFrame, intri nsicValue(), values, numberOfValues, sampleRate, sampleRate));
174 } 169 }
175 170
176 void AudioParamHandler::connect(AudioNodeOutput& output) 171 void AudioParamHandler::connect(AudioNodeOutput& output)
177 { 172 {
178 ASSERT(deferredTaskHandler().isGraphOwner()); 173 ASSERT(deferredTaskHandler().isGraphOwner());
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 } 256 }
262 257
263 AudioParam* AudioParam::cancelScheduledValues(double startTime, ExceptionState& exceptionState) 258 AudioParam* AudioParam::cancelScheduledValues(double startTime, ExceptionState& exceptionState)
264 { 259 {
265 handler().timeline().cancelScheduledValues(startTime, exceptionState); 260 handler().timeline().cancelScheduledValues(startTime, exceptionState);
266 return this; 261 return this;
267 } 262 }
268 263
269 } // namespace blink 264 } // namespace blink
270 265
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698