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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 public: | 48 public: |
49 // bufferSize must be one of the following values: 256, 512, 1024, 2048, 409
6, 8192, 16384. | 49 // bufferSize must be one of the following values: 256, 512, 1024, 2048, 409
6, 8192, 16384. |
50 // This value controls how frequently the onaudioprocess event handler is ca
lled and how many sample-frames need to be processed each call. | 50 // This value controls how frequently the onaudioprocess event handler is ca
lled and how many sample-frames need to be processed each call. |
51 // Lower numbers for bufferSize will result in a lower (better) latency. Hig
her numbers will be necessary to avoid audio breakup and glitches. | 51 // Lower numbers for bufferSize will result in a lower (better) latency. Hig
her numbers will be necessary to avoid audio breakup and glitches. |
52 // The value chosen must carefully balance between latency and audio quality
. | 52 // The value chosen must carefully balance between latency and audio quality
. |
53 static PassRefPtrWillBeRawPtr<ScriptProcessorNode> create(AudioContext*, flo
at sampleRate, size_t bufferSize, unsigned numberOfInputChannels, unsigned numbe
rOfOutputChannels); | 53 static ScriptProcessorNode* create(AudioContext*, float sampleRate, size_t b
ufferSize, unsigned numberOfInputChannels, unsigned numberOfOutputChannels); |
54 | 54 |
55 virtual ~ScriptProcessorNode(); | 55 virtual ~ScriptProcessorNode(); |
56 | 56 |
57 // AudioNode | 57 // AudioNode |
58 virtual void dispose() OVERRIDE; | 58 virtual void dispose() OVERRIDE; |
59 virtual void process(size_t framesToProcess) OVERRIDE; | 59 virtual void process(size_t framesToProcess) OVERRIDE; |
60 virtual void initialize() OVERRIDE; | 60 virtual void initialize() OVERRIDE; |
61 virtual void uninitialize() OVERRIDE; | 61 virtual void uninitialize() OVERRIDE; |
62 | 62 |
63 size_t bufferSize() const { return m_bufferSize; } | 63 size_t bufferSize() const { return m_bufferSize; } |
64 | 64 |
65 DEFINE_ATTRIBUTE_EVENT_LISTENER(audioprocess); | 65 DEFINE_ATTRIBUTE_EVENT_LISTENER(audioprocess); |
66 | 66 |
67 void trace(Visitor*); | 67 void trace(Visitor*); |
68 | 68 |
69 private: | 69 private: |
70 virtual double tailTime() const OVERRIDE; | 70 virtual double tailTime() const OVERRIDE; |
71 virtual double latencyTime() const OVERRIDE; | 71 virtual double latencyTime() const OVERRIDE; |
72 | 72 |
73 ScriptProcessorNode(AudioContext*, float sampleRate, size_t bufferSize, unsi
gned numberOfInputChannels, unsigned numberOfOutputChannels); | 73 ScriptProcessorNode(AudioContext*, float sampleRate, size_t bufferSize, unsi
gned numberOfInputChannels, unsigned numberOfOutputChannels); |
74 | 74 |
75 void fireProcessEvent(); | 75 void fireProcessEvent(); |
76 | 76 |
77 // Double buffering | 77 // Double buffering |
78 unsigned doubleBufferIndex() const { return m_doubleBufferIndex; } | 78 unsigned doubleBufferIndex() const { return m_doubleBufferIndex; } |
79 void swapBuffers() { m_doubleBufferIndex = 1 - m_doubleBufferIndex; } | 79 void swapBuffers() { m_doubleBufferIndex = 1 - m_doubleBufferIndex; } |
80 unsigned m_doubleBufferIndex; | 80 unsigned m_doubleBufferIndex; |
81 unsigned m_doubleBufferIndexForEvent; | 81 unsigned m_doubleBufferIndexForEvent; |
82 WillBeHeapVector<RefPtrWillBeMember<AudioBuffer> > m_inputBuffers; | 82 HeapVector<Member<AudioBuffer> > m_inputBuffers; |
83 WillBeHeapVector<RefPtrWillBeMember<AudioBuffer> > m_outputBuffers; | 83 HeapVector<Member<AudioBuffer> > m_outputBuffers; |
84 | 84 |
85 size_t m_bufferSize; | 85 size_t m_bufferSize; |
86 unsigned m_bufferReadWriteIndex; | 86 unsigned m_bufferReadWriteIndex; |
87 | 87 |
88 unsigned m_numberOfInputChannels; | 88 unsigned m_numberOfInputChannels; |
89 unsigned m_numberOfOutputChannels; | 89 unsigned m_numberOfOutputChannels; |
90 | 90 |
91 RefPtr<AudioBus> m_internalInputBus; | 91 RefPtr<AudioBus> m_internalInputBus; |
92 // Synchronize process() with fireProcessEvent(). | 92 // Synchronize process() with fireProcessEvent(). |
93 mutable Mutex m_processEventLock; | 93 mutable Mutex m_processEventLock; |
94 }; | 94 }; |
95 | 95 |
96 } // namespace blink | 96 } // namespace blink |
97 | 97 |
98 #endif // ScriptProcessorNode_h | 98 #endif // ScriptProcessorNode_h |
OLD | NEW |