Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* |
michael@0 | 2 | * Copyright (C) 2011 Google Inc. All rights reserved. |
michael@0 | 3 | * |
michael@0 | 4 | * Redistribution and use in source and binary forms, with or without |
michael@0 | 5 | * modification, are permitted provided that the following conditions |
michael@0 | 6 | * are met: |
michael@0 | 7 | * |
michael@0 | 8 | * 1. Redistributions of source code must retain the above copyright |
michael@0 | 9 | * notice, this list of conditions and the following disclaimer. |
michael@0 | 10 | * 2. Redistributions in binary form must reproduce the above copyright |
michael@0 | 11 | * notice, this list of conditions and the following disclaimer in the |
michael@0 | 12 | * documentation and/or other materials provided with the distribution. |
michael@0 | 13 | * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of |
michael@0 | 14 | * its contributors may be used to endorse or promote products derived |
michael@0 | 15 | * from this software without specific prior written permission. |
michael@0 | 16 | * |
michael@0 | 17 | * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
michael@0 | 18 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
michael@0 | 19 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
michael@0 | 20 | * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
michael@0 | 21 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
michael@0 | 22 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
michael@0 | 23 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
michael@0 | 24 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
michael@0 | 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
michael@0 | 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
michael@0 | 27 | */ |
michael@0 | 28 | |
michael@0 | 29 | #include "ZeroPole.h" |
michael@0 | 30 | |
michael@0 | 31 | #include <cmath> |
michael@0 | 32 | #include <float.h> |
michael@0 | 33 | |
michael@0 | 34 | namespace WebCore { |
michael@0 | 35 | |
michael@0 | 36 | void ZeroPole::process(const float *source, float *destination, int framesToProcess) |
michael@0 | 37 | { |
michael@0 | 38 | float zero = m_zero; |
michael@0 | 39 | float pole = m_pole; |
michael@0 | 40 | |
michael@0 | 41 | // Gain compensation to make 0dB @ 0Hz |
michael@0 | 42 | const float k1 = 1 / (1 - zero); |
michael@0 | 43 | const float k2 = 1 - pole; |
michael@0 | 44 | |
michael@0 | 45 | // Member variables to locals. |
michael@0 | 46 | float lastX = m_lastX; |
michael@0 | 47 | float lastY = m_lastY; |
michael@0 | 48 | |
michael@0 | 49 | for (int i = 0; i < framesToProcess; ++i) { |
michael@0 | 50 | float input = source[i]; |
michael@0 | 51 | |
michael@0 | 52 | // Zero |
michael@0 | 53 | float output1 = k1 * (input - zero * lastX); |
michael@0 | 54 | lastX = input; |
michael@0 | 55 | |
michael@0 | 56 | // Pole |
michael@0 | 57 | float output2 = k2 * output1 + pole * lastY; |
michael@0 | 58 | lastY = output2; |
michael@0 | 59 | |
michael@0 | 60 | destination[i] = output2; |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | // Locals to member variables. Flush denormals here so we don't |
michael@0 | 64 | // slow down the inner loop above. |
michael@0 | 65 | if (lastX == 0.0f && lastY != 0.0f && fabsf(lastY) < FLT_MIN) { |
michael@0 | 66 | // Flush future values to zero (until there is new input). |
michael@0 | 67 | lastY = 0.0; |
michael@0 | 68 | // Flush calculated values. |
michael@0 | 69 | for (int i = framesToProcess; i-- && fabsf(destination[i]) < FLT_MIN; ) { |
michael@0 | 70 | destination[i] = 0.0f; |
michael@0 | 71 | } |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | m_lastX = lastX; |
michael@0 | 75 | m_lastY = lastY; |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | } // namespace WebCore |