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

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

Issue 2666063003: Continue to process AnalyserNode if inputs are silent. (Closed)
Patch Set: Adjust comment per review. Created 3 years, 10 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 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 return adoptRef(new AnalyserHandler(node, sampleRate)); 43 return adoptRef(new AnalyserHandler(node, sampleRate));
44 } 44 }
45 45
46 AnalyserHandler::~AnalyserHandler() { 46 AnalyserHandler::~AnalyserHandler() {
47 uninitialize(); 47 uninitialize();
48 } 48 }
49 49
50 void AnalyserHandler::process(size_t framesToProcess) { 50 void AnalyserHandler::process(size_t framesToProcess) {
51 AudioBus* outputBus = output(0).bus(); 51 AudioBus* outputBus = output(0).bus();
52 52
53 if (!isInitialized() || !input(0).isConnected()) { 53 if (!isInitialized()) {
54 outputBus->zero(); 54 outputBus->zero();
55 return; 55 return;
56 } 56 }
57 57
58 AudioBus* inputBus = input(0).bus(); 58 AudioBus* inputBus = input(0).bus();
59 59
60 // Give the analyser the audio which is passing through this AudioNode. 60 // Give the analyser the audio which is passing through this
61 // AudioNode. This must always be done so that the state of the
62 // Analyser reflects the current input.
61 m_analyser.writeInput(inputBus, framesToProcess); 63 m_analyser.writeInput(inputBus, framesToProcess);
62 64
65 if (!input(0).isConnected()) {
66 // No inputs, so clear the output, and propagate the silence hint.
67 outputBus->zero();
68 return;
69 }
70
63 // For in-place processing, our override of pullInputs() will just pass the 71 // For in-place processing, our override of pullInputs() will just pass the
64 // audio data through unchanged if the channel count matches from input to 72 // audio data through unchanged if the channel count matches from input to
65 // output (resulting in inputBus == outputBus). Otherwise, do an up-mix to 73 // output (resulting in inputBus == outputBus). Otherwise, do an up-mix to
66 // stereo. 74 // stereo.
67 if (inputBus != outputBus) 75 if (inputBus != outputBus)
68 outputBus->copyFrom(*inputBus); 76 outputBus->copyFrom(*inputBus);
69 } 77 }
70 78
71 void AnalyserHandler::setFftSize(unsigned size, 79 void AnalyserHandler::setFftSize(unsigned size,
72 ExceptionState& exceptionState) { 80 ExceptionState& exceptionState) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 m_analyser.setSmoothingTimeConstant(k); 133 m_analyser.setSmoothingTimeConstant(k);
126 } else { 134 } else {
127 exceptionState.throwDOMException( 135 exceptionState.throwDOMException(
128 IndexSizeError, 136 IndexSizeError,
129 ExceptionMessages::indexOutsideRange( 137 ExceptionMessages::indexOutsideRange(
130 "smoothing value", k, 0.0, ExceptionMessages::InclusiveBound, 1.0, 138 "smoothing value", k, 0.0, ExceptionMessages::InclusiveBound, 1.0,
131 ExceptionMessages::InclusiveBound)); 139 ExceptionMessages::InclusiveBound));
132 } 140 }
133 } 141 }
134 142
143 void AnalyserHandler::updatePullStatus() {
144 #if DCHECK_IS_ON()
145 DCHECK(context()->isGraphOwner());
146 #endif
147
148 if (output(0).isConnected()) {
149 // When an AudioBasicInspectorNode is connected to a downstream node, it
150 // will get pulled by the downstream node, thus remove it from the context's
151 // automatic pull list.
152 if (m_needAutomaticPull) {
153 context()->deferredTaskHandler().removeAutomaticPullNode(this);
154 m_needAutomaticPull = false;
155 }
156 } else {
157 unsigned numberOfInputConnections = input(0).numberOfRenderingConnections();
158 // When an AnalyserNode is not connected to any downstream node
159 // while still connected from upstream node(s), add it to the context's
160 // automatic pull list.
161 //
162 // But don't remove the AnalyserNode if there are no inputs
163 // connected to the node. The node needs to be pulled so that the
164 // internal state is updated with the correct input signal (of
165 // zeroes).
166 if (numberOfInputConnections && !m_needAutomaticPull) {
167 context()->deferredTaskHandler().addAutomaticPullNode(this);
168 m_needAutomaticPull = true;
169 }
170 }
171 }
135 // ---------------------------------------------------------------- 172 // ----------------------------------------------------------------
136 173
137 AnalyserNode::AnalyserNode(BaseAudioContext& context) 174 AnalyserNode::AnalyserNode(BaseAudioContext& context)
138 : AudioBasicInspectorNode(context) { 175 : AudioBasicInspectorNode(context) {
139 setHandler(AnalyserHandler::create(*this, context.sampleRate())); 176 setHandler(AnalyserHandler::create(*this, context.sampleRate()));
140 } 177 }
141 178
142 AnalyserNode* AnalyserNode::create(BaseAudioContext& context, 179 AnalyserNode* AnalyserNode::create(BaseAudioContext& context,
143 ExceptionState& exceptionState) { 180 ExceptionState& exceptionState) {
144 DCHECK(isMainThread()); 181 DCHECK(isMainThread());
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 272
236 void AnalyserNode::getFloatTimeDomainData(DOMFloat32Array* array) { 273 void AnalyserNode::getFloatTimeDomainData(DOMFloat32Array* array) {
237 analyserHandler().getFloatTimeDomainData(array); 274 analyserHandler().getFloatTimeDomainData(array);
238 } 275 }
239 276
240 void AnalyserNode::getByteTimeDomainData(DOMUint8Array* array) { 277 void AnalyserNode::getByteTimeDomainData(DOMUint8Array* array) {
241 analyserHandler().getByteTimeDomainData(array); 278 analyserHandler().getByteTimeDomainData(array);
242 } 279 }
243 280
244 } // namespace blink 281 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698