| 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 26 matching lines...) Expand all Loading... |
| 37 class AudioBuffer; | 37 class AudioBuffer; |
| 38 class AudioContext; | 38 class AudioContext; |
| 39 class AudioProcessingEvent; | 39 class AudioProcessingEvent; |
| 40 | 40 |
| 41 // ScriptProcessorNode is an AudioNode which allows for arbitrary synthesis or p
rocessing directly using JavaScript. | 41 // ScriptProcessorNode is an AudioNode which allows for arbitrary synthesis or p
rocessing directly using JavaScript. |
| 42 // The API allows for a variable number of inputs and outputs, although it must
have at least one input or output. | 42 // The API allows for a variable number of inputs and outputs, although it must
have at least one input or output. |
| 43 // This basic implementation supports no more than one input and output. | 43 // This basic implementation supports no more than one input and output. |
| 44 // The "onaudioprocess" attribute is an event listener which will get called per
iodically with an AudioProcessingEvent which has | 44 // The "onaudioprocess" attribute is an event listener which will get called per
iodically with an AudioProcessingEvent which has |
| 45 // AudioBuffers for each input and output. | 45 // AudioBuffers for each input and output. |
| 46 | 46 |
| 47 class ScriptProcessorNode FINAL : public AudioNode { | 47 class ScriptProcessorNode final : public AudioNode { |
| 48 DEFINE_WRAPPERTYPEINFO(); | 48 DEFINE_WRAPPERTYPEINFO(); |
| 49 public: | 49 public: |
| 50 // bufferSize must be one of the following values: 256, 512, 1024, 2048, 409
6, 8192, 16384. | 50 // bufferSize must be one of the following values: 256, 512, 1024, 2048, 409
6, 8192, 16384. |
| 51 // This value controls how frequently the onaudioprocess event handler is ca
lled and how many sample-frames need to be processed each call. | 51 // This value controls how frequently the onaudioprocess event handler is ca
lled and how many sample-frames need to be processed each call. |
| 52 // Lower numbers for bufferSize will result in a lower (better) latency. Hig
her numbers will be necessary to avoid audio breakup and glitches. | 52 // Lower numbers for bufferSize will result in a lower (better) latency. Hig
her numbers will be necessary to avoid audio breakup and glitches. |
| 53 // The value chosen must carefully balance between latency and audio quality
. | 53 // The value chosen must carefully balance between latency and audio quality
. |
| 54 static ScriptProcessorNode* create(AudioContext*, float sampleRate, size_t b
ufferSize, unsigned numberOfInputChannels, unsigned numberOfOutputChannels); | 54 static ScriptProcessorNode* create(AudioContext*, float sampleRate, size_t b
ufferSize, unsigned numberOfInputChannels, unsigned numberOfOutputChannels); |
| 55 | 55 |
| 56 virtual ~ScriptProcessorNode(); | 56 virtual ~ScriptProcessorNode(); |
| 57 | 57 |
| 58 // AudioNode | 58 // AudioNode |
| 59 virtual void dispose() OVERRIDE; | 59 virtual void dispose() override; |
| 60 virtual void process(size_t framesToProcess) OVERRIDE; | 60 virtual void process(size_t framesToProcess) override; |
| 61 virtual void initialize() OVERRIDE; | 61 virtual void initialize() override; |
| 62 virtual void uninitialize() OVERRIDE; | 62 virtual void uninitialize() override; |
| 63 | 63 |
| 64 size_t bufferSize() const { return m_bufferSize; } | 64 size_t bufferSize() const { return m_bufferSize; } |
| 65 | 65 |
| 66 virtual void setChannelCount(unsigned long, ExceptionState&) OVERRIDE; | 66 virtual void setChannelCount(unsigned long, ExceptionState&) override; |
| 67 virtual void setChannelCountMode(const String&, ExceptionState&) OVERRIDE; | 67 virtual void setChannelCountMode(const String&, ExceptionState&) override; |
| 68 | 68 |
| 69 DEFINE_ATTRIBUTE_EVENT_LISTENER(audioprocess); | 69 DEFINE_ATTRIBUTE_EVENT_LISTENER(audioprocess); |
| 70 | 70 |
| 71 void trace(Visitor*); | 71 void trace(Visitor*); |
| 72 | 72 |
| 73 private: | 73 private: |
| 74 virtual double tailTime() const OVERRIDE; | 74 virtual double tailTime() const override; |
| 75 virtual double latencyTime() const OVERRIDE; | 75 virtual double latencyTime() const override; |
| 76 | 76 |
| 77 ScriptProcessorNode(AudioContext*, float sampleRate, size_t bufferSize, unsi
gned numberOfInputChannels, unsigned numberOfOutputChannels); | 77 ScriptProcessorNode(AudioContext*, float sampleRate, size_t bufferSize, unsi
gned numberOfInputChannels, unsigned numberOfOutputChannels); |
| 78 | 78 |
| 79 void fireProcessEvent(); | 79 void fireProcessEvent(); |
| 80 | 80 |
| 81 // Double buffering | 81 // Double buffering |
| 82 unsigned doubleBufferIndex() const { return m_doubleBufferIndex; } | 82 unsigned doubleBufferIndex() const { return m_doubleBufferIndex; } |
| 83 void swapBuffers() { m_doubleBufferIndex = 1 - m_doubleBufferIndex; } | 83 void swapBuffers() { m_doubleBufferIndex = 1 - m_doubleBufferIndex; } |
| 84 unsigned m_doubleBufferIndex; | 84 unsigned m_doubleBufferIndex; |
| 85 unsigned m_doubleBufferIndexForEvent; | 85 unsigned m_doubleBufferIndexForEvent; |
| 86 HeapVector<Member<AudioBuffer> > m_inputBuffers; | 86 HeapVector<Member<AudioBuffer> > m_inputBuffers; |
| 87 HeapVector<Member<AudioBuffer> > m_outputBuffers; | 87 HeapVector<Member<AudioBuffer> > m_outputBuffers; |
| 88 | 88 |
| 89 size_t m_bufferSize; | 89 size_t m_bufferSize; |
| 90 unsigned m_bufferReadWriteIndex; | 90 unsigned m_bufferReadWriteIndex; |
| 91 | 91 |
| 92 unsigned m_numberOfInputChannels; | 92 unsigned m_numberOfInputChannels; |
| 93 unsigned m_numberOfOutputChannels; | 93 unsigned m_numberOfOutputChannels; |
| 94 | 94 |
| 95 RefPtr<AudioBus> m_internalInputBus; | 95 RefPtr<AudioBus> m_internalInputBus; |
| 96 // Synchronize process() with fireProcessEvent(). | 96 // Synchronize process() with fireProcessEvent(). |
| 97 mutable Mutex m_processEventLock; | 97 mutable Mutex m_processEventLock; |
| 98 }; | 98 }; |
| 99 | 99 |
| 100 } // namespace blink | 100 } // namespace blink |
| 101 | 101 |
| 102 #endif // ScriptProcessorNode_h | 102 #endif // ScriptProcessorNode_h |
| OLD | NEW |