| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 size_t bufferSize = 1 << static_cast<unsigned>(log2(4 * hardwareBufferSize)
+ 0.5); | 49 size_t bufferSize = 1 << static_cast<unsigned>(log2(4 * hardwareBufferSize)
+ 0.5); |
| 50 | 50 |
| 51 if (bufferSize < 256) | 51 if (bufferSize < 256) |
| 52 return 256; | 52 return 256; |
| 53 if (bufferSize > 16384) | 53 if (bufferSize > 16384) |
| 54 return 16384; | 54 return 16384; |
| 55 | 55 |
| 56 return bufferSize; | 56 return bufferSize; |
| 57 } | 57 } |
| 58 | 58 |
| 59 PassRefPtr<ScriptProcessorNode> ScriptProcessorNode::create(AudioContext* contex
t, float sampleRate, size_t bufferSize, unsigned numberOfInputChannels, unsigned
numberOfOutputChannels) | 59 PassRefPtrWillBeRawPtr<ScriptProcessorNode> ScriptProcessorNode::create(AudioCon
text* context, float sampleRate, size_t bufferSize, unsigned numberOfInputChanne
ls, unsigned numberOfOutputChannels) |
| 60 { | 60 { |
| 61 // Check for valid buffer size. | 61 // Check for valid buffer size. |
| 62 switch (bufferSize) { | 62 switch (bufferSize) { |
| 63 case 0: | 63 case 0: |
| 64 bufferSize = chooseBufferSize(); | 64 bufferSize = chooseBufferSize(); |
| 65 break; | 65 break; |
| 66 case 256: | 66 case 256: |
| 67 case 512: | 67 case 512: |
| 68 case 1024: | 68 case 1024: |
| 69 case 2048: | 69 case 2048: |
| 70 case 4096: | 70 case 4096: |
| 71 case 8192: | 71 case 8192: |
| 72 case 16384: | 72 case 16384: |
| 73 break; | 73 break; |
| 74 default: | 74 default: |
| 75 return nullptr; | 75 return nullptr; |
| 76 } | 76 } |
| 77 | 77 |
| 78 if (!numberOfInputChannels && !numberOfOutputChannels) | 78 if (!numberOfInputChannels && !numberOfOutputChannels) |
| 79 return nullptr; | 79 return nullptr; |
| 80 | 80 |
| 81 if (numberOfInputChannels > AudioContext::maxNumberOfChannels()) | 81 if (numberOfInputChannels > AudioContext::maxNumberOfChannels()) |
| 82 return nullptr; | 82 return nullptr; |
| 83 | 83 |
| 84 if (numberOfOutputChannels > AudioContext::maxNumberOfChannels()) | 84 if (numberOfOutputChannels > AudioContext::maxNumberOfChannels()) |
| 85 return nullptr; | 85 return nullptr; |
| 86 | 86 |
| 87 return adoptRef(new ScriptProcessorNode(context, sampleRate, bufferSize, num
berOfInputChannels, numberOfOutputChannels)); | 87 return adoptRefWillBeRefCountedGarbageCollected(new ScriptProcessorNode(cont
ext, sampleRate, bufferSize, numberOfInputChannels, numberOfOutputChannels)); |
| 88 } | 88 } |
| 89 | 89 |
| 90 ScriptProcessorNode::ScriptProcessorNode(AudioContext* context, float sampleRate
, size_t bufferSize, unsigned numberOfInputChannels, unsigned numberOfOutputChan
nels) | 90 ScriptProcessorNode::ScriptProcessorNode(AudioContext* context, float sampleRate
, size_t bufferSize, unsigned numberOfInputChannels, unsigned numberOfOutputChan
nels) |
| 91 : AudioNode(context, sampleRate) | 91 : AudioNode(context, sampleRate) |
| 92 , m_doubleBufferIndex(0) | 92 , m_doubleBufferIndex(0) |
| 93 , m_doubleBufferIndexForEvent(0) | 93 , m_doubleBufferIndexForEvent(0) |
| 94 , m_bufferSize(bufferSize) | 94 , m_bufferSize(bufferSize) |
| 95 , m_bufferReadWriteIndex(0) | 95 , m_bufferReadWriteIndex(0) |
| 96 , m_numberOfInputChannels(numberOfInputChannels) | 96 , m_numberOfInputChannels(numberOfInputChannels) |
| 97 , m_numberOfOutputChannels(numberOfOutputChannels) | 97 , m_numberOfOutputChannels(numberOfOutputChannels) |
| 98 , m_internalInputBus(AudioBus::create(numberOfInputChannels, AudioNode::Proc
essingSizeInFrames, false)) | 98 , m_internalInputBus(AudioBus::create(numberOfInputChannels, AudioNode::Proc
essingSizeInFrames, false)) |
| 99 #if ENABLE(OILPAN) |
| 100 , m_keepAlive(adoptPtr(new Persistent<AudioNode>(this))) |
| 101 #endif |
| 99 { | 102 { |
| 100 ScriptWrappable::init(this); | 103 ScriptWrappable::init(this); |
| 101 // Regardless of the allowed buffer sizes, we still need to process at the g
ranularity of the AudioNode. | 104 // Regardless of the allowed buffer sizes, we still need to process at the g
ranularity of the AudioNode. |
| 102 if (m_bufferSize < AudioNode::ProcessingSizeInFrames) | 105 if (m_bufferSize < AudioNode::ProcessingSizeInFrames) |
| 103 m_bufferSize = AudioNode::ProcessingSizeInFrames; | 106 m_bufferSize = AudioNode::ProcessingSizeInFrames; |
| 104 | 107 |
| 105 ASSERT(numberOfInputChannels <= AudioContext::maxNumberOfChannels()); | 108 ASSERT(numberOfInputChannels <= AudioContext::maxNumberOfChannels()); |
| 106 | 109 |
| 107 addInput(adoptPtr(new AudioNodeInput(this))); | 110 addInput(adoptPtr(new AudioNodeInput(this))); |
| 108 addOutput(adoptPtr(new AudioNodeOutput(this, numberOfOutputChannels))); | 111 addOutput(adoptPtr(new AudioNodeOutput(this, numberOfOutputChannels))); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 120 void ScriptProcessorNode::initialize() | 123 void ScriptProcessorNode::initialize() |
| 121 { | 124 { |
| 122 if (isInitialized()) | 125 if (isInitialized()) |
| 123 return; | 126 return; |
| 124 | 127 |
| 125 float sampleRate = context()->sampleRate(); | 128 float sampleRate = context()->sampleRate(); |
| 126 | 129 |
| 127 // Create double buffers on both the input and output sides. | 130 // Create double buffers on both the input and output sides. |
| 128 // These AudioBuffers will be directly accessed in the main thread by JavaSc
ript. | 131 // These AudioBuffers will be directly accessed in the main thread by JavaSc
ript. |
| 129 for (unsigned i = 0; i < 2; ++i) { | 132 for (unsigned i = 0; i < 2; ++i) { |
| 130 RefPtr<AudioBuffer> inputBuffer = m_numberOfInputChannels ? AudioBuffer:
:create(m_numberOfInputChannels, bufferSize(), sampleRate) : nullptr; | 133 RefPtrWillBeRawPtr<AudioBuffer> inputBuffer = m_numberOfInputChannels ?
AudioBuffer::create(m_numberOfInputChannels, bufferSize(), sampleRate) : nullptr
; |
| 131 RefPtr<AudioBuffer> outputBuffer = m_numberOfOutputChannels ? AudioBuffe
r::create(m_numberOfOutputChannels, bufferSize(), sampleRate) : nullptr; | 134 RefPtrWillBeRawPtr<AudioBuffer> outputBuffer = m_numberOfOutputChannels
? AudioBuffer::create(m_numberOfOutputChannels, bufferSize(), sampleRate) : null
ptr; |
| 132 | 135 |
| 133 m_inputBuffers.append(inputBuffer); | 136 m_inputBuffers.append(inputBuffer); |
| 134 m_outputBuffers.append(outputBuffer); | 137 m_outputBuffers.append(outputBuffer); |
| 135 } | 138 } |
| 136 | 139 |
| 137 AudioNode::initialize(); | 140 AudioNode::initialize(); |
| 138 } | 141 } |
| 139 | 142 |
| 140 void ScriptProcessorNode::uninitialize() | 143 void ScriptProcessorNode::uninitialize() |
| 141 { | 144 { |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 double ScriptProcessorNode::tailTime() const | 276 double ScriptProcessorNode::tailTime() const |
| 274 { | 277 { |
| 275 return std::numeric_limits<double>::infinity(); | 278 return std::numeric_limits<double>::infinity(); |
| 276 } | 279 } |
| 277 | 280 |
| 278 double ScriptProcessorNode::latencyTime() const | 281 double ScriptProcessorNode::latencyTime() const |
| 279 { | 282 { |
| 280 return std::numeric_limits<double>::infinity(); | 283 return std::numeric_limits<double>::infinity(); |
| 281 } | 284 } |
| 282 | 285 |
| 286 #if ENABLE(OILPAN) |
| 287 void ScriptProcessorNode::clearKeepAlive() |
| 288 { |
| 289 ASSERT(m_keepAlive); |
| 290 m_keepAlive = nullptr; |
| 291 } |
| 292 #endif |
| 293 |
| 294 void ScriptProcessorNode::trace(Visitor* visitor) |
| 295 { |
| 296 visitor->trace(m_inputBuffers); |
| 297 visitor->trace(m_outputBuffers); |
| 298 AudioNode::trace(visitor); |
| 299 } |
| 300 |
| 283 } // namespace WebCore | 301 } // namespace WebCore |
| 284 | 302 |
| 285 #endif // ENABLE(WEB_AUDIO) | 303 #endif // ENABLE(WEB_AUDIO) |
| OLD | NEW |