content/media/webaudio/blink/DynamicsCompressorKernel.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/media/webaudio/blink/DynamicsCompressorKernel.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,130 @@
     1.4 +/*
     1.5 + * Copyright (C) 2011 Google Inc. All rights reserved.
     1.6 + *
     1.7 + * Redistribution and use in source and binary forms, with or without
     1.8 + * modification, are permitted provided that the following conditions
     1.9 + * are met:
    1.10 + *
    1.11 + * 1.  Redistributions of source code must retain the above copyright
    1.12 + *     notice, this list of conditions and the following disclaimer.
    1.13 + * 2.  Redistributions in binary form must reproduce the above copyright
    1.14 + *     notice, this list of conditions and the following disclaimer in the
    1.15 + *     documentation and/or other materials provided with the distribution.
    1.16 + * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
    1.17 + *     its contributors may be used to endorse or promote products derived
    1.18 + *     from this software without specific prior written permission.
    1.19 + *
    1.20 + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
    1.21 + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    1.22 + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    1.23 + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
    1.24 + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    1.25 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
    1.26 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
    1.27 + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    1.28 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
    1.29 + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    1.30 + */
    1.31 +
    1.32 +#ifndef DynamicsCompressorKernel_h
    1.33 +#define DynamicsCompressorKernel_h
    1.34 +
    1.35 +#include "nsTArray.h"
    1.36 +#include "nsAutoPtr.h"
    1.37 +#include "mozilla/MemoryReporting.h"
    1.38 +
    1.39 +namespace WebCore {
    1.40 +
    1.41 +class DynamicsCompressorKernel {
    1.42 +public:
    1.43 +    DynamicsCompressorKernel(float sampleRate, unsigned numberOfChannels);
    1.44 +
    1.45 +    void setNumberOfChannels(unsigned);
    1.46 +
    1.47 +    // Performs stereo-linked compression.
    1.48 +    void process(float* sourceChannels[],
    1.49 +                 float* destinationChannels[],
    1.50 +                 unsigned numberOfChannels,
    1.51 +                 unsigned framesToProcess,
    1.52 +
    1.53 +                 float dbThreshold,
    1.54 +                 float dbKnee,
    1.55 +                 float ratio,
    1.56 +                 float attackTime,
    1.57 +                 float releaseTime,
    1.58 +                 float preDelayTime,
    1.59 +                 float dbPostGain,
    1.60 +                 float effectBlend,
    1.61 +
    1.62 +                 float releaseZone1,
    1.63 +                 float releaseZone2,
    1.64 +                 float releaseZone3,
    1.65 +                 float releaseZone4
    1.66 +                 );
    1.67 +
    1.68 +    void reset();
    1.69 +
    1.70 +    unsigned latencyFrames() const { return m_lastPreDelayFrames; }
    1.71 +
    1.72 +    float sampleRate() const { return m_sampleRate; }
    1.73 +
    1.74 +    float meteringGain() const { return m_meteringGain; }
    1.75 +
    1.76 +    size_t sizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
    1.77 +
    1.78 +protected:
    1.79 +    float m_sampleRate;
    1.80 +
    1.81 +    float m_detectorAverage;
    1.82 +    float m_compressorGain;
    1.83 +
    1.84 +    // Metering
    1.85 +    float m_meteringReleaseK;
    1.86 +    float m_meteringGain;
    1.87 +
    1.88 +    // Lookahead section.
    1.89 +    enum { MaxPreDelayFrames = 1024 };
    1.90 +    enum { MaxPreDelayFramesMask = MaxPreDelayFrames - 1 };
    1.91 +    enum { DefaultPreDelayFrames = 256 }; // setPreDelayTime() will override this initial value
    1.92 +    unsigned m_lastPreDelayFrames;
    1.93 +    void setPreDelayTime(float);
    1.94 +
    1.95 +    nsTArray<nsAutoArrayPtr<float> > m_preDelayBuffers;
    1.96 +    int m_preDelayReadIndex;
    1.97 +    int m_preDelayWriteIndex;
    1.98 +
    1.99 +    float m_maxAttackCompressionDiffDb;
   1.100 +
   1.101 +    // Static compression curve.
   1.102 +    float kneeCurve(float x, float k);
   1.103 +    float saturate(float x, float k);
   1.104 +    float slopeAt(float x, float k);
   1.105 +    float kAtSlope(float desiredSlope);
   1.106 +
   1.107 +    float updateStaticCurveParameters(float dbThreshold, float dbKnee, float ratio);
   1.108 +
   1.109 +    // Amount of input change in dB required for 1 dB of output change.
   1.110 +    // This applies to the portion of the curve above m_kneeThresholdDb (see below).
   1.111 +    float m_ratio;
   1.112 +    float m_slope; // Inverse ratio.
   1.113 +
   1.114 +    // The input to output change below the threshold is linear 1:1.
   1.115 +    float m_linearThreshold;
   1.116 +    float m_dbThreshold;
   1.117 +
   1.118 +    // m_dbKnee is the number of dB above the threshold before we enter the "ratio" portion of the curve.
   1.119 +    // m_kneeThresholdDb = m_dbThreshold + m_dbKnee
   1.120 +    // The portion between m_dbThreshold and m_kneeThresholdDb is the "soft knee" portion of the curve
   1.121 +    // which transitions smoothly from the linear portion to the ratio portion.
   1.122 +    float m_dbKnee;
   1.123 +    float m_kneeThreshold;
   1.124 +    float m_kneeThresholdDb;
   1.125 +    float m_ykneeThresholdDb;
   1.126 +
   1.127 +    // Internal parameter for the knee portion of the curve.
   1.128 +    float m_K;
   1.129 +};
   1.130 +
   1.131 +} // namespace WebCore
   1.132 +
   1.133 +#endif // DynamicsCompressorKernel_h

mercurial