| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 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 are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #ifndef Animation_h | 31 #ifndef DownSampler_h |
| 32 #define Animation_h | 32 #define DownSampler_h |
| 33 | 33 |
| 34 #include "core/animation/AnimationEffect.h" | 34 #include "core/platform/audio/AudioArray.h" |
| 35 #include "core/animation/TimedItem.h" | 35 #include "core/platform/audio/DirectConvolver.h" |
| 36 #include "wtf/RefPtr.h" | |
| 37 | 36 |
| 38 namespace WebCore { | 37 namespace WebCore { |
| 39 | 38 |
| 40 class Element; | 39 // DownSampler down-samples the source stream by a factor of 2x. |
| 41 | 40 |
| 42 class Animation FINAL : public TimedItem { | 41 class DownSampler { |
| 42 public: |
| 43 DownSampler(size_t inputBlockSize); |
| 43 | 44 |
| 44 public: | 45 // The destination buffer |destP| is of size sourceFramesToProcess / 2. |
| 45 static PassRefPtr<Animation> create(PassRefPtr<Element>, PassRefPtr<Animatio
nEffect>, const Timing&); | 46 void process(const float* sourceP, float* destP, size_t sourceFramesToProces
s); |
| 46 virtual ~Animation(); | |
| 47 | 47 |
| 48 const AnimationEffect::CompositableValueMap* compositableValues() const | 48 void reset(); |
| 49 { | |
| 50 ASSERT(m_compositableValues); | |
| 51 return m_compositableValues.get(); | |
| 52 } | |
| 53 | 49 |
| 54 protected: | 50 // Latency based on the destination sample-rate. |
| 55 virtual void applyEffects(bool previouslyActiveOrInEffect); | 51 size_t latencyFrames() const; |
| 56 virtual void clearEffects(); | |
| 57 virtual void updateChildrenAndEffects(bool) const OVERRIDE FINAL; | |
| 58 | 52 |
| 59 private: | 53 private: |
| 60 Animation(PassRefPtr<Element>, PassRefPtr<AnimationEffect>, const Timing&); | 54 enum { DefaultKernelSize = 256 }; |
| 61 | 55 |
| 62 RefPtr<Element> m_target; | 56 size_t m_inputBlockSize; |
| 63 RefPtr<AnimationEffect> m_effect; | 57 |
| 64 bool m_isInTargetActiveAnimationsList; | 58 // Computes ideal band-limited half-band filter coefficients. |
| 65 OwnPtr<AnimationEffect::CompositableValueMap> m_compositableValues; | 59 // In other words, filter out all frequencies higher than 0.25 * Nyquist. |
| 60 void initializeKernel(); |
| 61 AudioFloatArray m_reducedKernel; |
| 62 |
| 63 // Half-band filter. |
| 64 DirectConvolver m_convolver; |
| 65 |
| 66 AudioFloatArray m_tempBuffer; |
| 67 |
| 68 // Used as delay-line (FIR filter history) for the input samples to account
for the 0.5 term right in the middle of the kernel. |
| 69 AudioFloatArray m_inputBuffer; |
| 66 }; | 70 }; |
| 67 | 71 |
| 68 } // namespace WebCore | 72 } // namespace WebCore |
| 69 | 73 |
| 70 #endif | 74 #endif // DownSampler_h |
| OLD | NEW |