OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012, Google Inc. All rights reserved. | 2 * Copyright (C) 2012, 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 23 matching lines...) Expand all Loading... |
34 #include "modules/webaudio/AudioNodeOutput.h" | 34 #include "modules/webaudio/AudioNodeOutput.h" |
35 #include "modules/webaudio/PeriodicWave.h" | 35 #include "modules/webaudio/PeriodicWave.h" |
36 #include "wtf/MathExtras.h" | 36 #include "wtf/MathExtras.h" |
37 #include "wtf/StdLibExtras.h" | 37 #include "wtf/StdLibExtras.h" |
38 #include <algorithm> | 38 #include <algorithm> |
39 | 39 |
40 namespace blink { | 40 namespace blink { |
41 | 41 |
42 using namespace VectorMath; | 42 using namespace VectorMath; |
43 | 43 |
44 PassRefPtrWillBeRawPtr<OscillatorNode> OscillatorNode::create(AudioContext* cont
ext, float sampleRate) | 44 OscillatorNode* OscillatorNode::create(AudioContext* context, float sampleRate) |
45 { | 45 { |
46 return adoptRefWillBeNoop(new OscillatorNode(context, sampleRate)); | 46 return adoptRefCountedGarbageCollectedWillBeNoop(new OscillatorNode(context,
sampleRate)); |
47 } | 47 } |
48 | 48 |
49 OscillatorNode::OscillatorNode(AudioContext* context, float sampleRate) | 49 OscillatorNode::OscillatorNode(AudioContext* context, float sampleRate) |
50 : AudioScheduledSourceNode(context, sampleRate) | 50 : AudioScheduledSourceNode(context, sampleRate) |
51 , m_type(SINE) | 51 , m_type(SINE) |
52 , m_firstRender(true) | 52 , m_firstRender(true) |
53 , m_virtualReadIndex(0) | 53 , m_virtualReadIndex(0) |
54 , m_phaseIncrements(AudioNode::ProcessingSizeInFrames) | 54 , m_phaseIncrements(AudioNode::ProcessingSizeInFrames) |
55 , m_detuneValues(AudioNode::ProcessingSizeInFrames) | 55 , m_detuneValues(AudioNode::ProcessingSizeInFrames) |
56 { | 56 { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 setType(TRIANGLE); | 113 setType(TRIANGLE); |
114 } | 114 } |
115 | 115 |
116 bool OscillatorNode::setType(unsigned type) | 116 bool OscillatorNode::setType(unsigned type) |
117 { | 117 { |
118 PeriodicWave* periodicWave = 0; | 118 PeriodicWave* periodicWave = 0; |
119 float sampleRate = this->sampleRate(); | 119 float sampleRate = this->sampleRate(); |
120 | 120 |
121 switch (type) { | 121 switch (type) { |
122 case SINE: { | 122 case SINE: { |
123 DEFINE_STATIC_REF_WILL_BE_PERSISTENT(PeriodicWave, periodicWaveSine, (Pe
riodicWave::createSine(sampleRate))); | 123 DEFINE_STATIC_LOCAL(Persistent<PeriodicWave>, periodicWaveSine, (Periodi
cWave::createSine(sampleRate))); |
124 periodicWave = periodicWaveSine; | 124 periodicWave = periodicWaveSine; |
125 break; | 125 break; |
126 } | 126 } |
127 case SQUARE: { | 127 case SQUARE: { |
128 DEFINE_STATIC_REF_WILL_BE_PERSISTENT(PeriodicWave, periodicWaveSquare, (
PeriodicWave::createSquare(sampleRate))); | 128 DEFINE_STATIC_LOCAL(Persistent<PeriodicWave>, periodicWaveSquare, (Perio
dicWave::createSquare(sampleRate))); |
129 periodicWave = periodicWaveSquare; | 129 periodicWave = periodicWaveSquare; |
130 break; | 130 break; |
131 } | 131 } |
132 case SAWTOOTH: { | 132 case SAWTOOTH: { |
133 DEFINE_STATIC_REF_WILL_BE_PERSISTENT(PeriodicWave, periodicWaveSawtooth,
(PeriodicWave::createSawtooth(sampleRate))); | 133 DEFINE_STATIC_LOCAL(Persistent<PeriodicWave>, periodicWaveSawtooth, (Per
iodicWave::createSawtooth(sampleRate))); |
134 periodicWave = periodicWaveSawtooth; | 134 periodicWave = periodicWaveSawtooth; |
135 break; | 135 break; |
136 } | 136 } |
137 case TRIANGLE: { | 137 case TRIANGLE: { |
138 DEFINE_STATIC_REF_WILL_BE_PERSISTENT(PeriodicWave, periodicWaveTriangle,
(PeriodicWave::createTriangle(sampleRate))); | 138 DEFINE_STATIC_LOCAL(Persistent<PeriodicWave>, periodicWaveTriangle, (Per
iodicWave::createTriangle(sampleRate))); |
139 periodicWave = periodicWaveTriangle; | 139 periodicWave = periodicWaveTriangle; |
140 break; | 140 break; |
141 } | 141 } |
142 case CUSTOM: | 142 case CUSTOM: |
143 default: | 143 default: |
144 // Return error for invalid types, including CUSTOM since setPeriodicWav
e() method must be | 144 // Return error for invalid types, including CUSTOM since setPeriodicWav
e() method must be |
145 // called explicitly. | 145 // called explicitly. |
146 return false; | 146 return false; |
147 } | 147 } |
148 | 148 |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 { | 349 { |
350 visitor->trace(m_frequency); | 350 visitor->trace(m_frequency); |
351 visitor->trace(m_detune); | 351 visitor->trace(m_detune); |
352 visitor->trace(m_periodicWave); | 352 visitor->trace(m_periodicWave); |
353 AudioScheduledSourceNode::trace(visitor); | 353 AudioScheduledSourceNode::trace(visitor); |
354 } | 354 } |
355 | 355 |
356 } // namespace blink | 356 } // namespace blink |
357 | 357 |
358 #endif // ENABLE(WEB_AUDIO) | 358 #endif // ENABLE(WEB_AUDIO) |
OLD | NEW |