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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 m_isLooping = looping; | 72 m_isLooping = looping; |
73 m_didSetLooping = m_didSetLooping || looping; | 73 m_didSetLooping = m_didSetLooping || looping; |
74 } | 74 } |
75 | 75 |
76 // Loop times in seconds. | 76 // Loop times in seconds. |
77 double loopStart() const { return m_loopStart; } | 77 double loopStart() const { return m_loopStart; } |
78 double loopEnd() const { return m_loopEnd; } | 78 double loopEnd() const { return m_loopEnd; } |
79 void setLoopStart(double loopStart) { m_loopStart = loopStart; } | 79 void setLoopStart(double loopStart) { m_loopStart = loopStart; } |
80 void setLoopEnd(double loopEnd) { m_loopEnd = loopEnd; } | 80 void setLoopEnd(double loopEnd) { m_loopEnd = loopEnd; } |
81 | 81 |
82 // If a panner node is set, then we can incorporate doppler shift into the p
layback pitch rate. | |
83 void setPannerNode(PannerHandler*); | |
84 void clearPannerNode(); | |
85 | |
86 // If we are no longer playing, propogate silence ahead to downstream nodes. | 82 // If we are no longer playing, propogate silence ahead to downstream nodes. |
87 bool propagatesSilence() const override; | 83 bool propagatesSilence() const override; |
88 | 84 |
89 // AudioScheduledSourceNode | |
90 void finish() override; | |
91 | |
92 void handleStoppableSourceNode(); | 85 void handleStoppableSourceNode(); |
93 | 86 |
94 private: | 87 private: |
95 AudioBufferSourceHandler(AudioNode&, float sampleRate, AudioParamHandler& pl
aybackRate, AudioParamHandler& detune); | 88 AudioBufferSourceHandler(AudioNode&, float sampleRate, AudioParamHandler& pl
aybackRate, AudioParamHandler& detune); |
96 void startSource(double when, double grainOffset, double grainDuration, bool
isDurationGiven, ExceptionState&); | 89 void startSource(double when, double grainOffset, double grainDuration, bool
isDurationGiven, ExceptionState&); |
97 | 90 |
98 // Returns true on success. | 91 // Returns true on success. |
99 bool renderFromBuffer(AudioBus*, unsigned destinationFrameOffset, size_t num
berOfFrames); | 92 bool renderFromBuffer(AudioBus*, unsigned destinationFrameOffset, size_t num
berOfFrames); |
100 | 93 |
101 // Render silence starting from "index" frame in AudioBus. | 94 // Render silence starting from "index" frame in AudioBus. |
(...skipping 28 matching lines...) Expand all Loading... |
130 // Since it's floating-point, it has sub-sample accuracy. | 123 // Since it's floating-point, it has sub-sample accuracy. |
131 double m_virtualReadIndex; | 124 double m_virtualReadIndex; |
132 | 125 |
133 // Granular playback | 126 // Granular playback |
134 bool m_isGrain; | 127 bool m_isGrain; |
135 double m_grainOffset; // in seconds | 128 double m_grainOffset; // in seconds |
136 double m_grainDuration; // in seconds | 129 double m_grainDuration; // in seconds |
137 // True if grainDuration is given explicitly (via 3 arg start method). | 130 // True if grainDuration is given explicitly (via 3 arg start method). |
138 bool m_isDurationGiven; | 131 bool m_isDurationGiven; |
139 | 132 |
140 // Compute playback rate (k-rate) by incorporating the sample rate conversio
n | 133 // Compute playback rate (k-rate) by incorporating the sample rate |
141 // factor, the doppler shift from the associated panner node, and the value | 134 // conversion factor, and the value of playbackRate and detune AudioParams. |
142 // of playbackRate and detune AudioParams. | |
143 double computePlaybackRate(); | 135 double computePlaybackRate(); |
144 | 136 |
145 // We optionally keep track of a panner node which has a doppler shift that | 137 // The minimum playbackRate value ever used for this source. |
146 // is incorporated into the pitch rate. | |
147 // This RefPtr is connection reference. We must call AudioHandler:: | |
148 // makeConnection() after ref(), and call AudioHandler::breakConnection() | |
149 // before deref(). | |
150 // TODO(tkent): This is always null because setPannerNode is never | |
151 // called. If we revive setPannerNode, this should be a raw pointer and | |
152 // AudioBufferSourceNode should have Member<PannerNode>. | |
153 RefPtr<PannerHandler> m_pannerNode; | |
154 | |
155 // The minimum playbackRate value ever used for this source. This includes
any adjustments | |
156 // caused by doppler too. | |
157 double m_minPlaybackRate; | 138 double m_minPlaybackRate; |
158 }; | 139 }; |
159 | 140 |
160 class AudioBufferSourceNode final : public AudioScheduledSourceNode { | 141 class AudioBufferSourceNode final : public AudioScheduledSourceNode { |
161 DEFINE_WRAPPERTYPEINFO(); | 142 DEFINE_WRAPPERTYPEINFO(); |
162 public: | 143 public: |
163 static AudioBufferSourceNode* create(AbstractAudioContext&, float sampleRate
); | 144 static AudioBufferSourceNode* create(AbstractAudioContext&, float sampleRate
); |
164 DECLARE_VIRTUAL_TRACE(); | 145 DECLARE_VIRTUAL_TRACE(); |
165 AudioBufferSourceHandler& audioBufferSourceHandler() const; | 146 AudioBufferSourceHandler& audioBufferSourceHandler() const; |
166 | 147 |
(...skipping 16 matching lines...) Expand all Loading... |
183 private: | 164 private: |
184 AudioBufferSourceNode(AbstractAudioContext&, float sampleRate); | 165 AudioBufferSourceNode(AbstractAudioContext&, float sampleRate); |
185 | 166 |
186 Member<AudioParam> m_playbackRate; | 167 Member<AudioParam> m_playbackRate; |
187 Member<AudioParam> m_detune; | 168 Member<AudioParam> m_detune; |
188 }; | 169 }; |
189 | 170 |
190 } // namespace blink | 171 } // namespace blink |
191 | 172 |
192 #endif // AudioBufferSourceNode_h | 173 #endif // AudioBufferSourceNode_h |
OLD | NEW |