| 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 | 37 |
| 38 namespace WebCore { | 38 namespace WebCore { |
| 39 | 39 |
| 40 class AudioContext; | 40 class AudioContext; |
| 41 | 41 |
| 42 // AudioBufferSourceNode is an AudioNode representing an audio source from an in
-memory audio asset represented by an AudioBuffer. | 42 // AudioBufferSourceNode is an AudioNode representing an audio source from an in
-memory audio asset represented by an AudioBuffer. |
| 43 // It generally will be used for short sounds which require a high degree of sch
eduling flexibility (can playback in rhythmically perfect ways). | 43 // It generally will be used for short sounds which require a high degree of sch
eduling flexibility (can playback in rhythmically perfect ways). |
| 44 | 44 |
| 45 class AudioBufferSourceNode FINAL : public AudioScheduledSourceNode { | 45 class AudioBufferSourceNode FINAL : public AudioScheduledSourceNode { |
| 46 public: | 46 public: |
| 47 static PassRefPtr<AudioBufferSourceNode> create(AudioContext*, float sampleR
ate); | 47 static PassRefPtrWillBeRawPtr<AudioBufferSourceNode> create(AudioContext*, f
loat sampleRate); |
| 48 | 48 |
| 49 virtual ~AudioBufferSourceNode(); | 49 virtual ~AudioBufferSourceNode(); |
| 50 | 50 |
| 51 // AudioNode | 51 // AudioNode |
| 52 virtual void process(size_t framesToProcess) OVERRIDE; | 52 virtual void process(size_t framesToProcess) OVERRIDE; |
| 53 | 53 |
| 54 // setBuffer() is called on the main thread. This is the buffer we use for p
layback. | 54 // setBuffer() is called on the main thread. This is the buffer we use for p
layback. |
| 55 void setBuffer(AudioBuffer*, ExceptionState&); | 55 void setBuffer(AudioBuffer*, ExceptionState&); |
| 56 AudioBuffer* buffer() { return m_buffer.get(); } | 56 AudioBuffer* buffer() { return m_buffer.get(); } |
| 57 | 57 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 82 // If a panner node is set, then we can incorporate doppler shift into the p
layback pitch rate. | 82 // If a panner node is set, then we can incorporate doppler shift into the p
layback pitch rate. |
| 83 void setPannerNode(PannerNode*); | 83 void setPannerNode(PannerNode*); |
| 84 void clearPannerNode(); | 84 void clearPannerNode(); |
| 85 | 85 |
| 86 // If we are no longer playing, propogate silence ahead to downstream nodes. | 86 // If we are no longer playing, propogate silence ahead to downstream nodes. |
| 87 virtual bool propagatesSilence() const OVERRIDE; | 87 virtual bool propagatesSilence() const OVERRIDE; |
| 88 | 88 |
| 89 // AudioScheduledSourceNode | 89 // AudioScheduledSourceNode |
| 90 virtual void finish() OVERRIDE; | 90 virtual void finish() OVERRIDE; |
| 91 | 91 |
| 92 virtual void trace(Visitor*) OVERRIDE; |
| 93 |
| 92 private: | 94 private: |
| 93 AudioBufferSourceNode(AudioContext*, float sampleRate); | 95 AudioBufferSourceNode(AudioContext*, float sampleRate); |
| 94 | 96 |
| 95 // Returns true on success. | 97 // Returns true on success. |
| 96 bool renderFromBuffer(AudioBus*, unsigned destinationFrameOffset, size_t num
berOfFrames); | 98 bool renderFromBuffer(AudioBus*, unsigned destinationFrameOffset, size_t num
berOfFrames); |
| 97 | 99 |
| 98 // Render silence starting from "index" frame in AudioBus. | 100 // Render silence starting from "index" frame in AudioBus. |
| 99 inline bool renderSilenceAndFinishIfNotLooping(AudioBus*, unsigned index, si
ze_t framesToProcess); | 101 inline bool renderSilenceAndFinishIfNotLooping(AudioBus*, unsigned index, si
ze_t framesToProcess); |
| 100 | 102 |
| 101 // m_buffer holds the sample data which this node outputs. | 103 // m_buffer holds the sample data which this node outputs. |
| 102 RefPtr<AudioBuffer> m_buffer; | 104 RefPtrWillBeMember<AudioBuffer> m_buffer; |
| 103 | 105 |
| 104 // Pointers for the buffer and destination. | 106 // Pointers for the buffer and destination. |
| 105 OwnPtr<const float*[]> m_sourceChannels; | 107 OwnPtr<const float*[]> m_sourceChannels; |
| 106 OwnPtr<float*[]> m_destinationChannels; | 108 OwnPtr<float*[]> m_destinationChannels; |
| 107 | 109 |
| 108 // Used for the "playbackRate" attributes. | 110 // Used for the "playbackRate" attributes. |
| 109 RefPtr<AudioParam> m_playbackRate; | 111 RefPtrWillBeMember<AudioParam> m_playbackRate; |
| 110 | 112 |
| 111 // If m_isLooping is false, then this node will be done playing and become i
nactive after it reaches the end of the sample data in the buffer. | 113 // If m_isLooping is false, then this node will be done playing and become i
nactive after it reaches the end of the sample data in the buffer. |
| 112 // If true, it will wrap around to the start of the buffer each time it reac
hes the end. | 114 // If true, it will wrap around to the start of the buffer each time it reac
hes the end. |
| 113 bool m_isLooping; | 115 bool m_isLooping; |
| 114 | 116 |
| 115 double m_loopStart; | 117 double m_loopStart; |
| 116 double m_loopEnd; | 118 double m_loopEnd; |
| 117 | 119 |
| 118 // m_virtualReadIndex is a sample-frame index into our buffer representing t
he current playback position. | 120 // m_virtualReadIndex is a sample-frame index into our buffer representing t
he current playback position. |
| 119 // Since it's floating-point, it has sub-sample accuracy. | 121 // Since it's floating-point, it has sub-sample accuracy. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 132 // the pitch rate. We manually manage ref-counting because we want to use Re
fTypeConnection. | 134 // the pitch rate. We manually manage ref-counting because we want to use Re
fTypeConnection. |
| 133 PannerNode* m_pannerNode; | 135 PannerNode* m_pannerNode; |
| 134 | 136 |
| 135 // This synchronizes process() with setBuffer() which can cause dynamic chan
nel count changes. | 137 // This synchronizes process() with setBuffer() which can cause dynamic chan
nel count changes. |
| 136 mutable Mutex m_processLock; | 138 mutable Mutex m_processLock; |
| 137 }; | 139 }; |
| 138 | 140 |
| 139 } // namespace WebCore | 141 } // namespace WebCore |
| 140 | 142 |
| 141 #endif // AudioBufferSourceNode_h | 143 #endif // AudioBufferSourceNode_h |
| OLD | NEW |