mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 06:11:37 +00:00
Bug 864091 - Part 2: Add the Blink Dynamics Compressor implementation to the build system; r=padenot,glandium
This commit is contained in:
parent
6d48241e2c
commit
bc6410c3a7
@ -60,6 +60,14 @@ struct WebAudioUtils {
|
||||
return aLinearValue ? 20.0f * std::log10(aLinearValue) : aMinDecibels;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a decibel value to a linear value.
|
||||
*/
|
||||
static float ConvertDecibelsToLinear(float aDecibels)
|
||||
{
|
||||
return std::pow(10.0f, 0.05f * aDecibels);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a decibel to a linear value.
|
||||
*/
|
||||
@ -75,6 +83,11 @@ struct WebAudioUtils {
|
||||
}
|
||||
}
|
||||
|
||||
static double DiscreteTimeConstantForSampleRate(double timeConstant, double sampleRate)
|
||||
{
|
||||
return 1.0 - std::exp(-1.0 / (sampleRate * timeConstant));
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a stream position into the time coordinate of the destination
|
||||
* stream.
|
||||
|
@ -25,14 +25,16 @@
|
||||
#ifndef DenormalDisabler_h
|
||||
#define DenormalDisabler_h
|
||||
|
||||
#include <wtf/MathExtras.h>
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <cmath>
|
||||
|
||||
namespace WebCore {
|
||||
|
||||
// Deal with denormals. They can very seriously impact performance on x86.
|
||||
|
||||
// Define HAVE_DENORMAL if we support flushing denormals to zero.
|
||||
#if OS(WINDOWS) && COMPILER(MSVC)
|
||||
#if defined(XP_WIN) && defined(_MSC_VER)
|
||||
#include <float.h>
|
||||
#define HAVE_DENORMAL
|
||||
#endif
|
||||
|
||||
@ -46,7 +48,7 @@ public:
|
||||
DenormalDisabler()
|
||||
: m_savedCSR(0)
|
||||
{
|
||||
#if OS(WINDOWS) && COMPILER(MSVC)
|
||||
#if defined(XP_WIN) && defined(_MSC_VER)
|
||||
// Save the current state, and set mode to flush denormals.
|
||||
//
|
||||
// http://stackoverflow.com/questions/637175/possible-bug-in-controlfp-s-may-not-restore-control-word-correctly
|
||||
@ -61,7 +63,7 @@ public:
|
||||
|
||||
~DenormalDisabler()
|
||||
{
|
||||
#if OS(WINDOWS) && COMPILER(MSVC)
|
||||
#if defined(XP_WIN) && defined(_MSC_VER)
|
||||
unsigned int unused;
|
||||
_controlfp_s(&unused, m_savedCSR, _MCW_DN);
|
||||
#else
|
||||
@ -72,7 +74,7 @@ public:
|
||||
// This is a nop if we can flush denormals to zero in hardware.
|
||||
static inline float flushDenormalFloatToZero(float f)
|
||||
{
|
||||
#if OS(WINDOWS) && COMPILER(MSVC) && (!_M_IX86_FP)
|
||||
#if defined(XP_WIN) && defined(_MSC_VER) && _M_IX86_FP
|
||||
// For systems using x87 instead of sse, there's no hardware support
|
||||
// to flush denormals automatically. Hence, we need to flush
|
||||
// denormals to zero manually.
|
||||
|
@ -26,20 +26,17 @@
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#if ENABLE(WEB_AUDIO)
|
||||
|
||||
#include "DynamicsCompressor.h"
|
||||
#include "AudioSegment.h"
|
||||
|
||||
#include "AudioBus.h"
|
||||
#include "AudioUtilities.h"
|
||||
#include <wtf/MathExtras.h>
|
||||
#include <cmath>
|
||||
#include "AudioNodeEngine.h"
|
||||
#include "nsDebug.h"
|
||||
|
||||
using mozilla::WEBAUDIO_BLOCK_SIZE;
|
||||
|
||||
namespace WebCore {
|
||||
|
||||
using namespace AudioUtilities;
|
||||
|
||||
DynamicsCompressor::DynamicsCompressor(float sampleRate, unsigned numberOfChannels)
|
||||
: m_numberOfChannels(numberOfChannels)
|
||||
, m_sampleRate(sampleRate)
|
||||
@ -56,7 +53,7 @@ DynamicsCompressor::DynamicsCompressor(float sampleRate, unsigned numberOfChanne
|
||||
|
||||
void DynamicsCompressor::setParameterValue(unsigned parameterID, float value)
|
||||
{
|
||||
ASSERT(parameterID < ParamLast);
|
||||
MOZ_ASSERT(parameterID < ParamLast);
|
||||
if (parameterID < ParamLast)
|
||||
m_parameters[parameterID] = value;
|
||||
}
|
||||
@ -91,7 +88,7 @@ void DynamicsCompressor::initializeParameters()
|
||||
|
||||
float DynamicsCompressor::parameterValue(unsigned parameterID)
|
||||
{
|
||||
ASSERT(parameterID < ParamLast);
|
||||
MOZ_ASSERT(parameterID < ParamLast);
|
||||
return m_parameters[parameterID];
|
||||
}
|
||||
|
||||
@ -100,10 +97,10 @@ void DynamicsCompressor::setEmphasisStageParameters(unsigned stageIndex, float g
|
||||
float gk = 1 - gain / 20;
|
||||
float f1 = normalizedFrequency * gk;
|
||||
float f2 = normalizedFrequency / gk;
|
||||
float r1 = expf(-f1 * piFloat);
|
||||
float r2 = expf(-f2 * piFloat);
|
||||
float r1 = expf(-f1 * M_PI);
|
||||
float r2 = expf(-f2 * M_PI);
|
||||
|
||||
ASSERT(m_numberOfChannels == m_preFilterPacks.size());
|
||||
MOZ_ASSERT(m_numberOfChannels == m_preFilterPacks.Length());
|
||||
|
||||
for (unsigned i = 0; i < m_numberOfChannels; ++i) {
|
||||
// Set pre-filter zero and pole to create an emphasis filter.
|
||||
@ -127,28 +124,28 @@ void DynamicsCompressor::setEmphasisParameters(float gain, float anchorFreq, flo
|
||||
setEmphasisStageParameters(3, gain, anchorFreq / (filterStageRatio * filterStageRatio * filterStageRatio));
|
||||
}
|
||||
|
||||
void DynamicsCompressor::process(const AudioBus* sourceBus, AudioBus* destinationBus, unsigned framesToProcess)
|
||||
void DynamicsCompressor::process(const AudioChunk* sourceChunk, AudioChunk* destinationChunk, unsigned framesToProcess)
|
||||
{
|
||||
// Though numberOfChannels is retrived from destinationBus, we still name it numberOfChannels instead of numberOfDestinationChannels.
|
||||
// It's because we internally match sourceChannels's size to destinationBus by channel up/down mix. Thus we need numberOfChannels
|
||||
// to do the loop work for both m_sourceChannels and m_destinationChannels.
|
||||
|
||||
unsigned numberOfChannels = destinationBus->numberOfChannels();
|
||||
unsigned numberOfSourceChannels = sourceBus->numberOfChannels();
|
||||
unsigned numberOfChannels = destinationChunk->mChannelData.Length();
|
||||
unsigned numberOfSourceChannels = sourceChunk->mChannelData.Length();
|
||||
|
||||
ASSERT(numberOfChannels == m_numberOfChannels && numberOfSourceChannels);
|
||||
MOZ_ASSERT(numberOfChannels == m_numberOfChannels && numberOfSourceChannels);
|
||||
|
||||
if (numberOfChannels != m_numberOfChannels || !numberOfSourceChannels) {
|
||||
destinationBus->zero();
|
||||
destinationChunk->SetNull(WEBAUDIO_BLOCK_SIZE);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (numberOfChannels) {
|
||||
case 2: // stereo
|
||||
m_sourceChannels[0] = sourceBus->channel(0)->data();
|
||||
m_sourceChannels[0] = static_cast<const float*>(sourceChunk->mChannelData[0]);
|
||||
|
||||
if (numberOfSourceChannels > 1)
|
||||
m_sourceChannels[1] = sourceBus->channel(1)->data();
|
||||
m_sourceChannels[1] = static_cast<const float*>(sourceChunk->mChannelData[1]);
|
||||
else
|
||||
// Simply duplicate mono channel input data to right channel for stereo processing.
|
||||
m_sourceChannels[1] = m_sourceChannels[0];
|
||||
@ -156,13 +153,14 @@ void DynamicsCompressor::process(const AudioBus* sourceBus, AudioBus* destinatio
|
||||
break;
|
||||
default:
|
||||
// FIXME : support other number of channels.
|
||||
ASSERT_NOT_REACHED();
|
||||
destinationBus->zero();
|
||||
NS_NOTREACHED("Support other number of channels");
|
||||
destinationChunk->SetNull(WEBAUDIO_BLOCK_SIZE);
|
||||
return;
|
||||
}
|
||||
|
||||
for (unsigned i = 0; i < numberOfChannels; ++i)
|
||||
m_destinationChannels[i] = destinationBus->channel(i)->mutableData();
|
||||
m_destinationChannels[i] = const_cast<float*>(static_cast<const float*>(
|
||||
destinationChunk->mChannelData[i]));
|
||||
|
||||
float filterStageGain = parameterValue(ParamFilterStageGain);
|
||||
float filterStageRatio = parameterValue(ParamFilterStageRatio);
|
||||
@ -264,23 +262,21 @@ void DynamicsCompressor::reset()
|
||||
|
||||
void DynamicsCompressor::setNumberOfChannels(unsigned numberOfChannels)
|
||||
{
|
||||
if (m_preFilterPacks.size() == numberOfChannels)
|
||||
if (m_preFilterPacks.Length() == numberOfChannels)
|
||||
return;
|
||||
|
||||
m_preFilterPacks.clear();
|
||||
m_postFilterPacks.clear();
|
||||
m_preFilterPacks.Clear();
|
||||
m_postFilterPacks.Clear();
|
||||
for (unsigned i = 0; i < numberOfChannels; ++i) {
|
||||
m_preFilterPacks.append(adoptPtr(new ZeroPoleFilterPack4()));
|
||||
m_postFilterPacks.append(adoptPtr(new ZeroPoleFilterPack4()));
|
||||
m_preFilterPacks.AppendElement(new ZeroPoleFilterPack4());
|
||||
m_postFilterPacks.AppendElement(new ZeroPoleFilterPack4());
|
||||
}
|
||||
|
||||
m_sourceChannels = adoptArrayPtr(new const float* [numberOfChannels]);
|
||||
m_destinationChannels = adoptArrayPtr(new float* [numberOfChannels]);
|
||||
m_sourceChannels = new const float* [numberOfChannels];
|
||||
m_destinationChannels = new float* [numberOfChannels];
|
||||
|
||||
m_compressor.setNumberOfChannels(numberOfChannels);
|
||||
m_numberOfChannels = numberOfChannels;
|
||||
}
|
||||
|
||||
} // namespace WebCore
|
||||
|
||||
#endif // ENABLE(WEB_AUDIO)
|
||||
|
@ -29,15 +29,19 @@
|
||||
#ifndef DynamicsCompressor_h
|
||||
#define DynamicsCompressor_h
|
||||
|
||||
#include "AudioArray.h"
|
||||
#include "DynamicsCompressorKernel.h"
|
||||
#include "ZeroPole.h"
|
||||
|
||||
#include <wtf/OwnArrayPtr.h>
|
||||
#include "nsTArray.h"
|
||||
#include "nsAutoPtr.h"
|
||||
|
||||
namespace mozilla {
|
||||
struct AudioChunk;
|
||||
}
|
||||
|
||||
namespace WebCore {
|
||||
|
||||
class AudioBus;
|
||||
using mozilla::AudioChunk;
|
||||
|
||||
// DynamicsCompressor implements a flexible audio dynamics compression effect such as
|
||||
// is commonly used in musical production and game audio. It lowers the volume
|
||||
@ -68,7 +72,7 @@ public:
|
||||
|
||||
DynamicsCompressor(float sampleRate, unsigned numberOfChannels);
|
||||
|
||||
void process(const AudioBus* sourceBus, AudioBus* destinationBus, unsigned framesToProcess);
|
||||
void process(const AudioChunk* sourceChunk, AudioChunk* destinationChunk, unsigned framesToProcess);
|
||||
void reset();
|
||||
void setNumberOfChannels(unsigned);
|
||||
|
||||
@ -100,11 +104,11 @@ protected:
|
||||
} ZeroPoleFilterPack4;
|
||||
|
||||
// Per-channel emphasis filters.
|
||||
Vector<OwnPtr<ZeroPoleFilterPack4> > m_preFilterPacks;
|
||||
Vector<OwnPtr<ZeroPoleFilterPack4> > m_postFilterPacks;
|
||||
nsTArray<nsAutoPtr<ZeroPoleFilterPack4> > m_preFilterPacks;
|
||||
nsTArray<nsAutoPtr<ZeroPoleFilterPack4> > m_postFilterPacks;
|
||||
|
||||
OwnArrayPtr<const float*> m_sourceChannels;
|
||||
OwnArrayPtr<float*> m_destinationChannels;
|
||||
nsAutoArrayPtr<const float*> m_sourceChannels;
|
||||
nsAutoArrayPtr<float*> m_destinationChannels;
|
||||
|
||||
void setEmphasisStageParameters(unsigned stageIndex, float gain, float normalizedFrequency /* 0 -> 1 */);
|
||||
void setEmphasisParameters(float gain, float anchorFreq, float filterStageRatio);
|
||||
|
@ -26,22 +26,20 @@
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#if ENABLE(WEB_AUDIO)
|
||||
|
||||
#include "DynamicsCompressorKernel.h"
|
||||
|
||||
#include "AudioUtilities.h"
|
||||
#include "DenormalDisabler.h"
|
||||
#include <algorithm>
|
||||
#include <wtf/MathExtras.h>
|
||||
|
||||
#include "mozilla/FloatingPoint.h"
|
||||
#include "WebAudioUtils.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
using mozilla::dom::WebAudioUtils;
|
||||
|
||||
namespace WebCore {
|
||||
|
||||
using namespace AudioUtilities;
|
||||
|
||||
// Metering hits peaks instantly, but releases this fast (in seconds).
|
||||
const float meteringReleaseTimeConstant = 0.325f;
|
||||
@ -68,17 +66,18 @@ DynamicsCompressorKernel::DynamicsCompressorKernel(float sampleRate, unsigned nu
|
||||
// Initializes most member variables
|
||||
reset();
|
||||
|
||||
m_meteringReleaseK = static_cast<float>(discreteTimeConstantForSampleRate(meteringReleaseTimeConstant, sampleRate));
|
||||
m_meteringReleaseK =
|
||||
static_cast<float>(WebAudioUtils::DiscreteTimeConstantForSampleRate(meteringReleaseTimeConstant, sampleRate));
|
||||
}
|
||||
|
||||
void DynamicsCompressorKernel::setNumberOfChannels(unsigned numberOfChannels)
|
||||
{
|
||||
if (m_preDelayBuffers.size() == numberOfChannels)
|
||||
if (m_preDelayBuffers.Length() == numberOfChannels)
|
||||
return;
|
||||
|
||||
m_preDelayBuffers.clear();
|
||||
m_preDelayBuffers.Clear();
|
||||
for (unsigned i = 0; i < numberOfChannels; ++i)
|
||||
m_preDelayBuffers.append(adoptPtr(new AudioFloatArray(MaxPreDelayFrames)));
|
||||
m_preDelayBuffers.AppendElement(new float[MaxPreDelayFrames]);
|
||||
}
|
||||
|
||||
void DynamicsCompressorKernel::setPreDelayTime(float preDelayTime)
|
||||
@ -90,8 +89,8 @@ void DynamicsCompressorKernel::setPreDelayTime(float preDelayTime)
|
||||
|
||||
if (m_lastPreDelayFrames != preDelayFrames) {
|
||||
m_lastPreDelayFrames = preDelayFrames;
|
||||
for (unsigned i = 0; i < m_preDelayBuffers.size(); ++i)
|
||||
m_preDelayBuffers[i]->zero();
|
||||
for (unsigned i = 0; i < m_preDelayBuffers.Length(); ++i)
|
||||
memset(m_preDelayBuffers[i], 0, sizeof(float) * MaxPreDelayFrames);
|
||||
|
||||
m_preDelayReadIndex = 0;
|
||||
m_preDelayWriteIndex = preDelayFrames;
|
||||
@ -118,10 +117,10 @@ float DynamicsCompressorKernel::saturate(float x, float k)
|
||||
y = kneeCurve(x, k);
|
||||
else {
|
||||
// Constant ratio after knee.
|
||||
float xDb = linearToDecibels(x);
|
||||
float xDb = WebAudioUtils::ConvertLinearToDecibels(x, -1000.0f);
|
||||
float yDb = m_ykneeThresholdDb + m_slope * (xDb - m_kneeThresholdDb);
|
||||
|
||||
y = decibelsToLinear(yDb);
|
||||
y = WebAudioUtils::ConvertDecibelsToLinear(yDb);
|
||||
}
|
||||
|
||||
return y;
|
||||
@ -137,11 +136,11 @@ float DynamicsCompressorKernel::slopeAt(float x, float k)
|
||||
|
||||
float x2 = x * 1.001;
|
||||
|
||||
float xDb = linearToDecibels(x);
|
||||
float x2Db = linearToDecibels(x2);
|
||||
float xDb = WebAudioUtils::ConvertLinearToDecibels(x, -1000.0f);
|
||||
float x2Db = WebAudioUtils::ConvertLinearToDecibels(x2, -1000.0f);
|
||||
|
||||
float yDb = linearToDecibels(kneeCurve(x, k));
|
||||
float y2Db = linearToDecibels(kneeCurve(x2, k));
|
||||
float yDb = WebAudioUtils::ConvertLinearToDecibels(kneeCurve(x, k), -1000.0f);
|
||||
float y2Db = WebAudioUtils::ConvertLinearToDecibels(kneeCurve(x2, k), -1000.0f);
|
||||
|
||||
float m = (y2Db - yDb) / (x2Db - xDb);
|
||||
|
||||
@ -151,7 +150,7 @@ float DynamicsCompressorKernel::slopeAt(float x, float k)
|
||||
float DynamicsCompressorKernel::kAtSlope(float desiredSlope)
|
||||
{
|
||||
float xDb = m_dbThreshold + m_dbKnee;
|
||||
float x = decibelsToLinear(xDb);
|
||||
float x = WebAudioUtils::ConvertDecibelsToLinear(xDb);
|
||||
|
||||
// Approximate k given initial values.
|
||||
float minK = 0.1;
|
||||
@ -182,7 +181,7 @@ float DynamicsCompressorKernel::updateStaticCurveParameters(float dbThreshold, f
|
||||
if (dbThreshold != m_dbThreshold || dbKnee != m_dbKnee || ratio != m_ratio) {
|
||||
// Threshold and knee.
|
||||
m_dbThreshold = dbThreshold;
|
||||
m_linearThreshold = decibelsToLinear(dbThreshold);
|
||||
m_linearThreshold = WebAudioUtils::ConvertDecibelsToLinear(dbThreshold);
|
||||
m_dbKnee = dbKnee;
|
||||
|
||||
// Compute knee parameters.
|
||||
@ -192,9 +191,9 @@ float DynamicsCompressorKernel::updateStaticCurveParameters(float dbThreshold, f
|
||||
float k = kAtSlope(1 / m_ratio);
|
||||
|
||||
m_kneeThresholdDb = dbThreshold + dbKnee;
|
||||
m_kneeThreshold = decibelsToLinear(m_kneeThresholdDb);
|
||||
m_kneeThreshold = WebAudioUtils::ConvertDecibelsToLinear(m_kneeThresholdDb);
|
||||
|
||||
m_ykneeThresholdDb = linearToDecibels(kneeCurve(m_kneeThreshold, k));
|
||||
m_ykneeThresholdDb = WebAudioUtils::ConvertLinearToDecibels(kneeCurve(m_kneeThreshold, k), -1000.0f);
|
||||
|
||||
m_K = k;
|
||||
}
|
||||
@ -221,7 +220,7 @@ void DynamicsCompressorKernel::process(float* sourceChannels[],
|
||||
float releaseZone4
|
||||
)
|
||||
{
|
||||
ASSERT(m_preDelayBuffers.size() == numberOfChannels);
|
||||
MOZ_ASSERT(m_preDelayBuffers.Length() == numberOfChannels);
|
||||
|
||||
float sampleRate = this->sampleRate();
|
||||
|
||||
@ -237,7 +236,7 @@ void DynamicsCompressorKernel::process(float* sourceChannels[],
|
||||
// Empirical/perceptual tuning.
|
||||
fullRangeMakeupGain = powf(fullRangeMakeupGain, 0.6f);
|
||||
|
||||
float masterLinearGain = decibelsToLinear(dbPostGain) * fullRangeMakeupGain;
|
||||
float masterLinearGain = WebAudioUtils::ConvertDecibelsToLinear(dbPostGain) * fullRangeMakeupGain;
|
||||
|
||||
// Attack parameters.
|
||||
attackTime = max(0.001f, attackTime);
|
||||
@ -286,15 +285,15 @@ void DynamicsCompressorKernel::process(float* sourceChannels[],
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
// Fix gremlins.
|
||||
if (std::isnan(m_detectorAverage))
|
||||
if (MOZ_DOUBLE_IS_NaN(m_detectorAverage))
|
||||
m_detectorAverage = 1;
|
||||
if (std::isinf(m_detectorAverage))
|
||||
if (MOZ_DOUBLE_IS_INFINITE(m_detectorAverage))
|
||||
m_detectorAverage = 1;
|
||||
|
||||
float desiredGain = m_detectorAverage;
|
||||
|
||||
// Pre-warp so we get desiredGain after sin() warp below.
|
||||
float scaledDesiredGain = asinf(desiredGain) / (0.5f * piFloat);
|
||||
float scaledDesiredGain = asinf(desiredGain) / (0.5f * M_PI);
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// Deal with envelopes
|
||||
@ -307,16 +306,16 @@ void DynamicsCompressorKernel::process(float* sourceChannels[],
|
||||
bool isReleasing = scaledDesiredGain > m_compressorGain;
|
||||
|
||||
// compressionDiffDb is the difference between current compression level and the desired level.
|
||||
float compressionDiffDb = linearToDecibels(m_compressorGain / scaledDesiredGain);
|
||||
float compressionDiffDb = WebAudioUtils::ConvertLinearToDecibels(m_compressorGain / scaledDesiredGain, -1000.0f);
|
||||
|
||||
if (isReleasing) {
|
||||
// Release mode - compressionDiffDb should be negative dB
|
||||
m_maxAttackCompressionDiffDb = -1;
|
||||
|
||||
// Fix gremlins.
|
||||
if (std::isnan(compressionDiffDb))
|
||||
if (MOZ_DOUBLE_IS_NaN(compressionDiffDb))
|
||||
compressionDiffDb = -1;
|
||||
if (std::isinf(compressionDiffDb))
|
||||
if (MOZ_DOUBLE_IS_INFINITE(compressionDiffDb))
|
||||
compressionDiffDb = -1;
|
||||
|
||||
// Adaptive release - higher compression (lower compressionDiffDb) releases faster.
|
||||
@ -337,14 +336,14 @@ void DynamicsCompressorKernel::process(float* sourceChannels[],
|
||||
#define kSpacingDb 5
|
||||
float dbPerFrame = kSpacingDb / releaseFrames;
|
||||
|
||||
envelopeRate = decibelsToLinear(dbPerFrame);
|
||||
envelopeRate = WebAudioUtils::ConvertDecibelsToLinear(dbPerFrame);
|
||||
} else {
|
||||
// Attack mode - compressionDiffDb should be positive dB
|
||||
|
||||
// Fix gremlins.
|
||||
if (std::isnan(compressionDiffDb))
|
||||
if (MOZ_DOUBLE_IS_NaN(compressionDiffDb))
|
||||
compressionDiffDb = 1;
|
||||
if (std::isinf(compressionDiffDb))
|
||||
if (MOZ_DOUBLE_IS_INFINITE(compressionDiffDb))
|
||||
compressionDiffDb = 1;
|
||||
|
||||
// As long as we're still in attack mode, use a rate based off
|
||||
@ -374,7 +373,7 @@ void DynamicsCompressorKernel::process(float* sourceChannels[],
|
||||
|
||||
// Predelay signal, computing compression amount from un-delayed version.
|
||||
for (unsigned i = 0; i < numberOfChannels; ++i) {
|
||||
float* delayBuffer = m_preDelayBuffers[i]->data();
|
||||
float* delayBuffer = m_preDelayBuffers[i];
|
||||
float undelayedSource = sourceChannels[i][frameIndex];
|
||||
delayBuffer[preDelayWriteIndex] = undelayedSource;
|
||||
|
||||
@ -396,12 +395,12 @@ void DynamicsCompressorKernel::process(float* sourceChannels[],
|
||||
|
||||
float attenuation = absInput <= 0.0001f ? 1 : shapedInput / absInput;
|
||||
|
||||
float attenuationDb = -linearToDecibels(attenuation);
|
||||
float attenuationDb = -WebAudioUtils::ConvertLinearToDecibels(attenuation, -1000.0f);
|
||||
attenuationDb = max(2.0f, attenuationDb);
|
||||
|
||||
float dbPerFrame = attenuationDb / satReleaseFrames;
|
||||
|
||||
float satReleaseRate = decibelsToLinear(dbPerFrame) - 1;
|
||||
float satReleaseRate = WebAudioUtils::ConvertDecibelsToLinear(dbPerFrame) - 1;
|
||||
|
||||
bool isRelease = (attenuation > detectorAverage);
|
||||
float rate = isRelease ? satReleaseRate : 1;
|
||||
@ -410,9 +409,9 @@ void DynamicsCompressorKernel::process(float* sourceChannels[],
|
||||
detectorAverage = min(1.0f, detectorAverage);
|
||||
|
||||
// Fix gremlins.
|
||||
if (std::isnan(detectorAverage))
|
||||
if (MOZ_DOUBLE_IS_NaN(detectorAverage))
|
||||
detectorAverage = 1;
|
||||
if (std::isinf(detectorAverage))
|
||||
if (MOZ_DOUBLE_IS_INFINITE(detectorAverage))
|
||||
detectorAverage = 1;
|
||||
|
||||
// Exponential approach to desired gain.
|
||||
@ -426,7 +425,7 @@ void DynamicsCompressorKernel::process(float* sourceChannels[],
|
||||
}
|
||||
|
||||
// Warp pre-compression gain to smooth out sharp exponential transition points.
|
||||
float postWarpCompressorGain = sinf(0.5f * piFloat * compressorGain);
|
||||
float postWarpCompressorGain = sinf(0.5f * M_PI * compressorGain);
|
||||
|
||||
// Calculate total gain using master gain and effect blend.
|
||||
float totalGain = dryMix + wetMix * masterLinearGain * postWarpCompressorGain;
|
||||
@ -440,7 +439,7 @@ void DynamicsCompressorKernel::process(float* sourceChannels[],
|
||||
|
||||
// Apply final gain.
|
||||
for (unsigned i = 0; i < numberOfChannels; ++i) {
|
||||
float* delayBuffer = m_preDelayBuffers[i]->data();
|
||||
float* delayBuffer = m_preDelayBuffers[i];
|
||||
destinationChannels[i][frameIndex] = delayBuffer[preDelayReadIndex] * totalGain;
|
||||
}
|
||||
|
||||
@ -465,8 +464,8 @@ void DynamicsCompressorKernel::reset()
|
||||
m_meteringGain = 1;
|
||||
|
||||
// Predelay section.
|
||||
for (unsigned i = 0; i < m_preDelayBuffers.size(); ++i)
|
||||
m_preDelayBuffers[i]->zero();
|
||||
for (unsigned i = 0; i < m_preDelayBuffers.Length(); ++i)
|
||||
memset(m_preDelayBuffers[i], 0, sizeof(float) * MaxPreDelayFrames);
|
||||
|
||||
m_preDelayReadIndex = 0;
|
||||
m_preDelayWriteIndex = DefaultPreDelayFrames;
|
||||
@ -475,5 +474,3 @@ void DynamicsCompressorKernel::reset()
|
||||
}
|
||||
|
||||
} // namespace WebCore
|
||||
|
||||
#endif // ENABLE(WEB_AUDIO)
|
||||
|
@ -29,10 +29,8 @@
|
||||
#ifndef DynamicsCompressorKernel_h
|
||||
#define DynamicsCompressorKernel_h
|
||||
|
||||
#include "AudioArray.h"
|
||||
|
||||
#include <wtf/OwnPtr.h>
|
||||
#include <wtf/PassOwnPtr.h>
|
||||
#include "nsTArray.h"
|
||||
#include "nsAutoPtr.h"
|
||||
|
||||
namespace WebCore {
|
||||
|
||||
@ -88,7 +86,7 @@ protected:
|
||||
unsigned m_lastPreDelayFrames;
|
||||
void setPreDelayTime(float);
|
||||
|
||||
Vector<OwnPtr<AudioFloatArray> > m_preDelayBuffers;
|
||||
nsTArray<nsAutoArrayPtr<float> > m_preDelayBuffers;
|
||||
int m_preDelayReadIndex;
|
||||
int m_preDelayWriteIndex;
|
||||
|
||||
|
23
content/media/webaudio/blink/Makefile.in
Normal file
23
content/media/webaudio/blink/Makefile.in
Normal file
@ -0,0 +1,23 @@
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
DEPTH := @DEPTH@
|
||||
topsrcdir := @top_srcdir@
|
||||
srcdir := @srcdir@
|
||||
VPATH := @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
LIBRARY_NAME := gkconwebaudio_blink_s
|
||||
LIBXUL_LIBRARY := 1
|
||||
|
||||
CPPSRCS := \
|
||||
DynamicsCompressor.cpp \
|
||||
DynamicsCompressorKernel.cpp \
|
||||
ZeroPole.cpp \
|
||||
$(NULL)
|
||||
|
||||
FORCE_STATIC_LIB := 1
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
@ -26,10 +26,6 @@
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#if ENABLE(WEB_AUDIO)
|
||||
|
||||
#include "ZeroPole.h"
|
||||
|
||||
#include "DenormalDisabler.h"
|
||||
@ -70,5 +66,3 @@ void ZeroPole::process(const float *source, float *destination, unsigned framesT
|
||||
}
|
||||
|
||||
} // namespace WebCore
|
||||
|
||||
#endif // ENABLE(WEB_AUDIO)
|
||||
|
8
content/media/webaudio/blink/moz.build
Normal file
8
content/media/webaudio/blink/moz.build
Normal file
@ -0,0 +1,8 @@
|
||||
# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
|
||||
# vim: set filetype=python:
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
MODULE = 'content'
|
||||
|
@ -4,7 +4,7 @@
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
PARALLEL_DIRS += ['test']
|
||||
PARALLEL_DIRS += ['blink', 'test']
|
||||
|
||||
TEST_TOOL_DIRS += ['compiledtest']
|
||||
|
||||
|
@ -45,6 +45,7 @@ SHARED_LIBRARY_LIBS = \
|
||||
$(DEPTH)/content/html/document/src/$(LIB_PREFIX)gkconhtmldoc_s.$(LIB_SUFFIX) \
|
||||
$(DEPTH)/content/media/$(LIB_PREFIX)gkconmedia_s.$(LIB_SUFFIX) \
|
||||
$(DEPTH)/content/media/webaudio/$(LIB_PREFIX)gkconwebaudio_s.$(LIB_SUFFIX) \
|
||||
$(DEPTH)/content/media/webaudio/blink/$(LIB_PREFIX)gkconwebaudio_blink_s.$(LIB_SUFFIX) \
|
||||
$(DEPTH)/content/media/webrtc/$(LIB_PREFIX)gkconwebrtc_s.$(LIB_SUFFIX) \
|
||||
$(DEPTH)/content/xml/content/src/$(LIB_PREFIX)gkconxmlcon_s.$(LIB_SUFFIX) \
|
||||
$(DEPTH)/content/xml/document/src/$(LIB_PREFIX)gkconxmldoc_s.$(LIB_SUFFIX) \
|
||||
|
Loading…
Reference in New Issue
Block a user