| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011, Google Inc. All rights reserved. | 2 * Copyright (C) 2011, 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 15 matching lines...) Expand all Loading... |
| 26 #include "modules/webaudio/AudioNodeInput.h" | 26 #include "modules/webaudio/AudioNodeInput.h" |
| 27 #include "modules/webaudio/AudioNodeOutput.h" | 27 #include "modules/webaudio/AudioNodeOutput.h" |
| 28 #include "platform/audio/DynamicsCompressor.h" | 28 #include "platform/audio/DynamicsCompressor.h" |
| 29 | 29 |
| 30 // Set output to stereo by default. | 30 // Set output to stereo by default. |
| 31 static const unsigned defaultNumberOfOutputChannels = 2; | 31 static const unsigned defaultNumberOfOutputChannels = 2; |
| 32 | 32 |
| 33 namespace blink { | 33 namespace blink { |
| 34 | 34 |
| 35 DynamicsCompressorHandler::DynamicsCompressorHandler( | 35 DynamicsCompressorHandler::DynamicsCompressorHandler( |
| 36 AudioNode& node, float sampleRate, | 36 AudioNode& node, |
| 37 AudioParamHandler& threshold, AudioParamHandler& knee, | 37 float sampleRate, |
| 38 AudioParamHandler& ratio, AudioParamHandler& reduction, | 38 AudioParamHandler& threshold, |
| 39 AudioParamHandler& attack, AudioParamHandler& release) | 39 AudioParamHandler& knee, |
| 40 AudioParamHandler& ratio, |
| 41 AudioParamHandler& attack, |
| 42 AudioParamHandler& release) |
| 40 : AudioHandler(NodeTypeDynamicsCompressor, node, sampleRate) | 43 : AudioHandler(NodeTypeDynamicsCompressor, node, sampleRate) |
| 41 , m_threshold(threshold) | 44 , m_threshold(threshold) |
| 42 , m_knee(knee) | 45 , m_knee(knee) |
| 43 , m_ratio(ratio) | 46 , m_ratio(ratio) |
| 44 , m_reduction(reduction) | 47 , m_reduction(0) |
| 45 , m_attack(attack) | 48 , m_attack(attack) |
| 46 , m_release(release) | 49 , m_release(release) |
| 47 { | 50 { |
| 48 addInput(); | 51 addInput(); |
| 49 addOutput(defaultNumberOfOutputChannels); | 52 addOutput(defaultNumberOfOutputChannels); |
| 50 initialize(); | 53 initialize(); |
| 51 } | 54 } |
| 52 | 55 |
| 53 PassRefPtr<DynamicsCompressorHandler> DynamicsCompressorHandler::create( | 56 PassRefPtr<DynamicsCompressorHandler> DynamicsCompressorHandler::create( |
| 54 AudioNode& node, float sampleRate, | 57 AudioNode& node, |
| 55 AudioParamHandler& threshold, AudioParamHandler& knee, | 58 float sampleRate, |
| 56 AudioParamHandler& ratio, AudioParamHandler& reduction, | 59 AudioParamHandler& threshold, |
| 57 AudioParamHandler& attack, AudioParamHandler& release) | 60 AudioParamHandler& knee, |
| 61 AudioParamHandler& ratio, |
| 62 AudioParamHandler& attack, |
| 63 AudioParamHandler& release) |
| 58 { | 64 { |
| 59 return adoptRef(new DynamicsCompressorHandler(node, sampleRate, threshold, k
nee, ratio, reduction, attack, release)); | 65 return adoptRef(new DynamicsCompressorHandler( |
| 66 node, |
| 67 sampleRate, |
| 68 threshold, |
| 69 knee, |
| 70 ratio, |
| 71 attack, |
| 72 release)); |
| 60 } | 73 } |
| 61 | 74 |
| 62 DynamicsCompressorHandler::~DynamicsCompressorHandler() | 75 DynamicsCompressorHandler::~DynamicsCompressorHandler() |
| 63 { | 76 { |
| 64 uninitialize(); | 77 uninitialize(); |
| 65 } | 78 } |
| 66 | 79 |
| 67 void DynamicsCompressorHandler::process(size_t framesToProcess) | 80 void DynamicsCompressorHandler::process(size_t framesToProcess) |
| 68 { | 81 { |
| 69 AudioBus* outputBus = output(0).bus(); | 82 AudioBus* outputBus = output(0).bus(); |
| 70 ASSERT(outputBus); | 83 ASSERT(outputBus); |
| 71 | 84 |
| 72 float threshold = m_threshold->value(); | 85 float threshold = m_threshold->value(); |
| 73 float knee = m_knee->value(); | 86 float knee = m_knee->value(); |
| 74 float ratio = m_ratio->value(); | 87 float ratio = m_ratio->value(); |
| 75 float attack = m_attack->value(); | 88 float attack = m_attack->value(); |
| 76 float release = m_release->value(); | 89 float release = m_release->value(); |
| 77 | 90 |
| 78 m_dynamicsCompressor->setParameterValue(DynamicsCompressor::ParamThreshold,
threshold); | 91 m_dynamicsCompressor->setParameterValue(DynamicsCompressor::ParamThreshold,
threshold); |
| 79 m_dynamicsCompressor->setParameterValue(DynamicsCompressor::ParamKnee, knee)
; | 92 m_dynamicsCompressor->setParameterValue(DynamicsCompressor::ParamKnee, knee)
; |
| 80 m_dynamicsCompressor->setParameterValue(DynamicsCompressor::ParamRatio, rati
o); | 93 m_dynamicsCompressor->setParameterValue(DynamicsCompressor::ParamRatio, rati
o); |
| 81 m_dynamicsCompressor->setParameterValue(DynamicsCompressor::ParamAttack, att
ack); | 94 m_dynamicsCompressor->setParameterValue(DynamicsCompressor::ParamAttack, att
ack); |
| 82 m_dynamicsCompressor->setParameterValue(DynamicsCompressor::ParamRelease, re
lease); | 95 m_dynamicsCompressor->setParameterValue(DynamicsCompressor::ParamRelease, re
lease); |
| 83 | 96 |
| 84 m_dynamicsCompressor->process(input(0).bus(), outputBus, framesToProcess); | 97 m_dynamicsCompressor->process(input(0).bus(), outputBus, framesToProcess); |
| 85 | 98 |
| 86 float reduction = m_dynamicsCompressor->parameterValue(DynamicsCompressor::P
aramReduction); | 99 m_reduction = m_dynamicsCompressor->parameterValue(DynamicsCompressor::Param
Reduction); |
| 87 m_reduction->setValue(reduction); | |
| 88 } | 100 } |
| 89 | 101 |
| 90 void DynamicsCompressorHandler::initialize() | 102 void DynamicsCompressorHandler::initialize() |
| 91 { | 103 { |
| 92 if (isInitialized()) | 104 if (isInitialized()) |
| 93 return; | 105 return; |
| 94 | 106 |
| 95 AudioHandler::initialize(); | 107 AudioHandler::initialize(); |
| 96 m_dynamicsCompressor = adoptPtr(new DynamicsCompressor(sampleRate(), default
NumberOfOutputChannels)); | 108 m_dynamicsCompressor = adoptPtr(new DynamicsCompressor(sampleRate(), default
NumberOfOutputChannels)); |
| 97 } | 109 } |
| 98 | 110 |
| 99 void DynamicsCompressorHandler::clearInternalStateWhenDisabled() | 111 void DynamicsCompressorHandler::clearInternalStateWhenDisabled() |
| 100 { | 112 { |
| 101 m_reduction->setValue(0); | 113 m_reduction = 0; |
| 102 } | 114 } |
| 103 | 115 |
| 104 double DynamicsCompressorHandler::tailTime() const | 116 double DynamicsCompressorHandler::tailTime() const |
| 105 { | 117 { |
| 106 return m_dynamicsCompressor->tailTime(); | 118 return m_dynamicsCompressor->tailTime(); |
| 107 } | 119 } |
| 108 | 120 |
| 109 double DynamicsCompressorHandler::latencyTime() const | 121 double DynamicsCompressorHandler::latencyTime() const |
| 110 { | 122 { |
| 111 return m_dynamicsCompressor->latencyTime(); | 123 return m_dynamicsCompressor->latencyTime(); |
| 112 } | 124 } |
| 113 | 125 |
| 114 // ---------------------------------------------------------------- | 126 // ---------------------------------------------------------------- |
| 115 | 127 |
| 116 DynamicsCompressorNode::DynamicsCompressorNode(AbstractAudioContext& context, fl
oat sampleRate) | 128 DynamicsCompressorNode::DynamicsCompressorNode(AbstractAudioContext& context, fl
oat sampleRate) |
| 117 : AudioNode(context) | 129 : AudioNode(context) |
| 118 , m_threshold(AudioParam::create(context, -24)) | 130 , m_threshold(AudioParam::create(context, -24)) |
| 119 , m_knee(AudioParam::create(context, 30)) | 131 , m_knee(AudioParam::create(context, 30)) |
| 120 , m_ratio(AudioParam::create(context, 12)) | 132 , m_ratio(AudioParam::create(context, 12)) |
| 121 , m_reduction(AudioParam::create(context, 0)) | |
| 122 , m_attack(AudioParam::create(context, 0.003)) | 133 , m_attack(AudioParam::create(context, 0.003)) |
| 123 , m_release(AudioParam::create(context, 0.250)) | 134 , m_release(AudioParam::create(context, 0.250)) |
| 124 { | 135 { |
| 125 setHandler(DynamicsCompressorHandler::create(*this, sampleRate, m_threshold-
>handler(), m_knee->handler(), m_ratio->handler(), m_reduction->handler(), m_att
ack->handler(), m_release->handler())); | 136 setHandler(DynamicsCompressorHandler::create( |
| 137 *this, |
| 138 sampleRate, |
| 139 m_threshold->handler(), |
| 140 m_knee->handler(), |
| 141 m_ratio->handler(), |
| 142 m_attack->handler(), |
| 143 m_release->handler())); |
| 126 } | 144 } |
| 127 | 145 |
| 128 DynamicsCompressorNode* DynamicsCompressorNode::create(AbstractAudioContext& con
text, float sampleRate) | 146 DynamicsCompressorNode* DynamicsCompressorNode::create(AbstractAudioContext& con
text, float sampleRate) |
| 129 { | 147 { |
| 130 return new DynamicsCompressorNode(context, sampleRate); | 148 return new DynamicsCompressorNode(context, sampleRate); |
| 131 } | 149 } |
| 132 | 150 |
| 133 DEFINE_TRACE(DynamicsCompressorNode) | 151 DEFINE_TRACE(DynamicsCompressorNode) |
| 134 { | 152 { |
| 135 visitor->trace(m_threshold); | 153 visitor->trace(m_threshold); |
| 136 visitor->trace(m_knee); | 154 visitor->trace(m_knee); |
| 137 visitor->trace(m_ratio); | 155 visitor->trace(m_ratio); |
| 138 visitor->trace(m_reduction); | |
| 139 visitor->trace(m_attack); | 156 visitor->trace(m_attack); |
| 140 visitor->trace(m_release); | 157 visitor->trace(m_release); |
| 141 AudioNode::trace(visitor); | 158 AudioNode::trace(visitor); |
| 142 } | 159 } |
| 143 | 160 |
| 144 DynamicsCompressorHandler& DynamicsCompressorNode::dynamicsCompressorHandler() c
onst | 161 DynamicsCompressorHandler& DynamicsCompressorNode::dynamicsCompressorHandler() c
onst |
| 145 { | 162 { |
| 146 return static_cast<DynamicsCompressorHandler&>(handler()); | 163 return static_cast<DynamicsCompressorHandler&>(handler()); |
| 147 } | 164 } |
| 148 | 165 |
| 149 AudioParam* DynamicsCompressorNode::threshold() const | 166 AudioParam* DynamicsCompressorNode::threshold() const |
| 150 { | 167 { |
| 151 return m_threshold; | 168 return m_threshold; |
| 152 } | 169 } |
| 153 | 170 |
| 154 AudioParam* DynamicsCompressorNode::knee() const | 171 AudioParam* DynamicsCompressorNode::knee() const |
| 155 { | 172 { |
| 156 return m_knee; | 173 return m_knee; |
| 157 } | 174 } |
| 158 | 175 |
| 159 AudioParam* DynamicsCompressorNode::ratio() const | 176 AudioParam* DynamicsCompressorNode::ratio() const |
| 160 { | 177 { |
| 161 return m_ratio; | 178 return m_ratio; |
| 162 } | 179 } |
| 163 | 180 |
| 164 AudioParam* DynamicsCompressorNode::reduction() const | 181 float DynamicsCompressorNode::reduction() const |
| 165 { | 182 { |
| 166 return m_reduction; | 183 return dynamicsCompressorHandler().reductionValue(); |
| 167 } | 184 } |
| 168 | 185 |
| 169 AudioParam* DynamicsCompressorNode::attack() const | 186 AudioParam* DynamicsCompressorNode::attack() const |
| 170 { | 187 { |
| 171 return m_attack; | 188 return m_attack; |
| 172 } | 189 } |
| 173 | 190 |
| 174 AudioParam* DynamicsCompressorNode::release() const | 191 AudioParam* DynamicsCompressorNode::release() const |
| 175 { | 192 { |
| 176 return m_release; | 193 return m_release; |
| 177 } | 194 } |
| 178 | 195 |
| 179 } // namespace blink | 196 } // namespace blink |
| 180 | 197 |
| OLD | NEW |