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 * 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 19 matching lines...) Expand all Loading... |
30 #include "modules/EventTargetModules.h" | 30 #include "modules/EventTargetModules.h" |
31 #include "modules/ModulesExport.h" | 31 #include "modules/ModulesExport.h" |
32 #include "platform/audio/AudioBus.h" | 32 #include "platform/audio/AudioBus.h" |
33 #include "platform/audio/AudioUtilities.h" | 33 #include "platform/audio/AudioUtilities.h" |
34 #include "platform/wtf/Forward.h" | 34 #include "platform/wtf/Forward.h" |
35 #include "platform/wtf/RefPtr.h" | 35 #include "platform/wtf/RefPtr.h" |
36 #include "platform/wtf/ThreadSafeRefCounted.h" | 36 #include "platform/wtf/ThreadSafeRefCounted.h" |
37 #include "platform/wtf/Vector.h" | 37 #include "platform/wtf/Vector.h" |
38 #include "platform/wtf/build_config.h" | 38 #include "platform/wtf/build_config.h" |
39 | 39 |
| 40 // Higher values produce more debugging output. |
40 #define DEBUG_AUDIONODE_REFERENCES 0 | 41 #define DEBUG_AUDIONODE_REFERENCES 0 |
41 | 42 |
42 namespace blink { | 43 namespace blink { |
43 | 44 |
44 class BaseAudioContext; | 45 class BaseAudioContext; |
45 class AudioNode; | 46 class AudioNode; |
46 class AudioNodeOptions; | 47 class AudioNodeOptions; |
47 class AudioNodeInput; | 48 class AudioNodeInput; |
48 class AudioNodeOutput; | 49 class AudioNodeOutput; |
49 class AudioParam; | 50 class AudioParam; |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 // Like process(), but only causes the automations to process; the | 146 // Like process(), but only causes the automations to process; the |
146 // normal processing of the node is bypassed. By default, we assume | 147 // normal processing of the node is bypassed. By default, we assume |
147 // no AudioParams need to be updated. | 148 // no AudioParams need to be updated. |
148 virtual void ProcessOnlyAudioParams(size_t frames_to_process){}; | 149 virtual void ProcessOnlyAudioParams(size_t frames_to_process){}; |
149 | 150 |
150 // No significant resources should be allocated until initialize() is called. | 151 // No significant resources should be allocated until initialize() is called. |
151 // Processing may not occur until a node is initialized. | 152 // Processing may not occur until a node is initialized. |
152 virtual void Initialize(); | 153 virtual void Initialize(); |
153 virtual void Uninitialize(); | 154 virtual void Uninitialize(); |
154 | 155 |
155 // Clear internal state when the node is disabled. When a node is disabled, | |
156 // it is no longer pulled so any internal state is never updated. But some | |
157 // nodes (DynamicsCompressorNode) have internal state that is still | |
158 // accessible by the user. Update the internal state as if the node were | |
159 // still connected but processing all zeroes. This gives a consistent view | |
160 // to the user. | |
161 virtual void ClearInternalStateWhenDisabled(); | |
162 | |
163 bool IsInitialized() const { return is_initialized_; } | 156 bool IsInitialized() const { return is_initialized_; } |
164 | 157 |
165 unsigned NumberOfInputs() const { return inputs_.size(); } | 158 unsigned NumberOfInputs() const { return inputs_.size(); } |
166 unsigned NumberOfOutputs() const { return outputs_.size(); } | 159 unsigned NumberOfOutputs() const { return outputs_.size(); } |
167 | 160 |
168 // Number of output channels. This only matters for ScriptProcessorNodes. | 161 // Number of output channels. This only matters for ScriptProcessorNodes. |
169 virtual unsigned NumberOfOutputChannels() const; | 162 virtual unsigned NumberOfOutputChannels() const; |
170 | 163 |
171 // The argument must be less than numberOfInputs(). | 164 // The argument must be less than numberOfInputs(). |
172 AudioNodeInput& Input(unsigned); | 165 AudioNodeInput& Input(unsigned); |
173 // The argument must be less than numberOfOutputs(). | 166 // The argument must be less than numberOfOutputs(). |
174 AudioNodeOutput& Output(unsigned); | 167 AudioNodeOutput& Output(unsigned); |
175 | 168 |
176 // processIfNecessary() is called by our output(s) when the rendering graph | 169 // processIfNecessary() is called by our output(s) when the rendering graph |
177 // needs this AudioNode to process. This method ensures that the AudioNode | 170 // needs this AudioNode to process. This method ensures that the AudioNode |
178 // will only process once per rendering time quantum even if it's called | 171 // will only process once per rendering time quantum even if it's called |
179 // repeatedly. This handles the case of "fanout" where an output is connected | 172 // repeatedly. This handles the case of "fanout" where an output is connected |
180 // to multiple AudioNode inputs. Called from context's audio thread. | 173 // to multiple AudioNode inputs. Called from context's audio thread. |
181 void ProcessIfNecessary(size_t frames_to_process); | 174 void ProcessIfNecessary(size_t frames_to_process); |
182 | 175 |
183 // Called when a new connection has been made to one of our inputs or the | 176 // Called when a new connection has been made to one of our inputs or the |
184 // connection number of channels has changed. This potentially gives us | 177 // connection number of channels has changed. This potentially gives us |
185 // enough information to perform a lazy initialization or, if necessary, a | 178 // enough information to perform a lazy initialization or, if necessary, a |
186 // re-initialization. Called from main thread. | 179 // re-initialization. Called from main thread. |
187 virtual void CheckNumberOfChannelsForInput(AudioNodeInput*); | 180 virtual void CheckNumberOfChannelsForInput(AudioNodeInput*); |
188 | 181 |
189 #if DEBUG_AUDIONODE_REFERENCES | 182 #if DEBUG_AUDIONODE_REFERENCES |
190 static void PrintNodeCounts(); | 183 static void PrintNodeCounts(); |
191 #endif | 184 #endif |
| 185 #if DEBUG_AUDIONODE_REFERENCES > 1 |
| 186 void TailProcessingDebug(const char* note); |
| 187 void AddTailProcessingDebug(); |
| 188 void RemoveTailProcessingDebug(); |
| 189 #endif |
| 190 |
| 191 // True if the node has a tail time or latency time that requires |
| 192 // special tail processing to behave properly. Ideally, this can be |
| 193 // checked using TailTime and LatencyTime, but these aren't |
| 194 // available on the main thread, and the tail processing check can |
| 195 // happen on the main thread. |
| 196 virtual bool RequiresTailProcessing() const = 0; |
192 | 197 |
193 // TailTime() is the length of time (not counting latency time) where | 198 // TailTime() is the length of time (not counting latency time) where |
194 // non-zero output may occur after continuous silent input. | 199 // non-zero output may occur after continuous silent input. |
195 virtual double TailTime() const = 0; | 200 virtual double TailTime() const = 0; |
196 | 201 |
197 // LatencyTime() is the length of time it takes for non-zero output to | 202 // LatencyTime() is the length of time it takes for non-zero output to |
198 // appear after non-zero input is provided. This only applies to processing | 203 // appear after non-zero input is provided. This only applies to processing |
199 // delay which is an artifact of the processing algorithm chosen and is | 204 // delay which is an artifact of the processing algorithm chosen and is |
200 // *not* part of the intrinsic desired effect. For example, a "delay" effect | 205 // *not* part of the intrinsic desired effect. For example, a "delay" effect |
201 // is expected to delay the signal, and thus would not be considered | 206 // is expected to delay the signal, and thus would not be considered |
202 // latency. | 207 // latency. |
203 virtual double LatencyTime() const = 0; | 208 virtual double LatencyTime() const = 0; |
204 | 209 |
205 // PropagatesSilence() should return true if the node will generate silent | 210 // PropagatesSilence() should return true if the node will generate silent |
206 // output when given silent input. By default, AudioNode will take TailTime() | 211 // output when given silent input. By default, AudioNode will take TailTime() |
207 // and LatencyTime() into account when determining whether the node will | 212 // and LatencyTime() into account when determining whether the node will |
208 // propagate silence. | 213 // propagate silence. |
209 virtual bool PropagatesSilence() const; | 214 virtual bool PropagatesSilence() const; |
210 bool InputsAreSilent(); | 215 bool InputsAreSilent(); |
211 void SilenceOutputs(); | 216 void SilenceOutputs(); |
212 void UnsilenceOutputs(); | 217 void UnsilenceOutputs(); |
213 | 218 |
214 void EnableOutputsIfNecessary(); | 219 void EnableOutputsIfNecessary(); |
215 void DisableOutputsIfNecessary(); | 220 void DisableOutputsIfNecessary(); |
| 221 void ReallyDisableOutputs(); |
216 | 222 |
217 unsigned long ChannelCount(); | 223 unsigned long ChannelCount(); |
218 virtual void SetChannelCount(unsigned long, ExceptionState&); | 224 virtual void SetChannelCount(unsigned long, ExceptionState&); |
219 | 225 |
220 String GetChannelCountMode(); | 226 String GetChannelCountMode(); |
221 virtual void SetChannelCountMode(const String&, ExceptionState&); | 227 virtual void SetChannelCountMode(const String&, ExceptionState&); |
222 | 228 |
223 String ChannelInterpretation(); | 229 String ChannelInterpretation(); |
224 void SetChannelInterpretation(const String&, ExceptionState&); | 230 void SetChannelInterpretation(const String&, ExceptionState&); |
225 | 231 |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 HeapVector<Member<HeapHashSet<Member<AudioNode>>>> connected_nodes_; | 379 HeapVector<Member<HeapHashSet<Member<AudioNode>>>> connected_nodes_; |
374 // Represents audio node graph with Oilpan references. N-th HeapHashSet | 380 // Represents audio node graph with Oilpan references. N-th HeapHashSet |
375 // represents a set of AudioParam objects connected to this AudioNode's N-th | 381 // represents a set of AudioParam objects connected to this AudioNode's N-th |
376 // output. | 382 // output. |
377 HeapVector<Member<HeapHashSet<Member<AudioParam>>>> connected_params_; | 383 HeapVector<Member<HeapHashSet<Member<AudioParam>>>> connected_params_; |
378 }; | 384 }; |
379 | 385 |
380 } // namespace blink | 386 } // namespace blink |
381 | 387 |
382 #endif // AudioNode_h | 388 #endif // AudioNode_h |
OLD | NEW |