Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(937)

Unified Diff: third_party/WebKit/Source/modules/webaudio/AudioParam.cpp

Issue 1803153002: Add min/max values for AudioParams (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/webaudio/AudioParam.cpp
diff --git a/third_party/WebKit/Source/modules/webaudio/AudioParam.cpp b/third_party/WebKit/Source/modules/webaudio/AudioParam.cpp
index c36bee42e9a534d50fe987adcd0c6aa22df81e6f..f524c7c15493021894939d5bc0ee6ee211df8600 100644
--- a/third_party/WebKit/Source/modules/webaudio/AudioParam.cpp
+++ b/third_party/WebKit/Source/modules/webaudio/AudioParam.cpp
@@ -24,10 +24,13 @@
*/
#include "modules/webaudio/AudioParam.h"
+
+#include "core/inspector/ConsoleMessage.h"
#include "modules/webaudio/AudioNode.h"
#include "modules/webaudio/AudioNodeOutput.h"
#include "platform/FloatConversion.h"
#include "platform/audio/AudioUtilities.h"
+#include "platform/v8_inspector/public/ConsoleTypes.h"
#include "wtf/MathExtras.h"
namespace blink {
@@ -35,11 +38,13 @@ namespace blink {
const double AudioParamHandler::DefaultSmoothingConstant = 0.05;
const double AudioParamHandler::SnapThreshold = 0.001;
-AudioParamHandler::AudioParamHandler(AbstractAudioContext& context, AudioParamType paramType, double defaultValue)
+AudioParamHandler::AudioParamHandler(AbstractAudioContext& context, AudioParamType paramType, double defaultValue, float minValue, float maxValue)
: AudioSummingJunction(context.deferredTaskHandler())
, m_paramType(paramType)
, m_intrinsicValue(defaultValue)
, m_defaultValue(defaultValue)
+ , m_minValue(minValue)
+ , m_maxValue(maxValue)
, m_smoothedValue(defaultValue)
{
// The destination MUST exist because we need the destination handler for the AudioParam.
@@ -112,6 +117,12 @@ float AudioParamHandler::value()
return v;
}
+void AudioParamHandler::setIntrinsicValue(float newValue)
+{
+ newValue = clampTo(newValue, m_minValue, m_maxValue);
+ noBarrierStore(&m_intrinsicValue, newValue);
+}
+
void AudioParamHandler::setValue(float value)
{
setIntrinsicValue(value);
@@ -249,15 +260,25 @@ void AudioParamHandler::disconnect(AudioNodeOutput& output)
// ----------------------------------------------------------------
-AudioParam::AudioParam(AbstractAudioContext& context, AudioParamType paramType, double defaultValue)
- : m_handler(AudioParamHandler::create(context, paramType, defaultValue))
+AudioParam::AudioParam(AbstractAudioContext& context, AudioParamType paramType, double defaultValue, float minValue, float maxValue)
+ : m_handler(AudioParamHandler::create(context, paramType, defaultValue, minValue, maxValue))
, m_context(context)
{
}
AudioParam* AudioParam::create(AbstractAudioContext& context, AudioParamType paramType, double defaultValue)
{
- return new AudioParam(context, paramType, defaultValue);
+ // Default nominal range is most negative float to most positive. This basically means any
+ // value is valid, except that floating-point infinities are excluded.
+ float limit = std::numeric_limits<float>::max();
+ return new AudioParam(context, paramType, defaultValue, -limit, limit);
+}
+
+AudioParam* AudioParam::create(AbstractAudioContext& context, AudioParamType paramType, double defaultValue,
+ float min, float max)
hongchan 2016/05/13 01:30:15 Here as well.
Raymond Toy 2016/05/13 18:40:32 Done.
+{
+ DCHECK(min <= max);
+ return new AudioParam(context, paramType, defaultValue, min, max);
}
DEFINE_TRACE(AudioParam)
@@ -270,8 +291,25 @@ float AudioParam::value() const
return handler().value();
}
+void AudioParam::warnIfOutsideRange(float value, float minValue, float maxValue)
+{
+ if (value < minValue || value > maxValue) {
+ context()->getExecutionContext()->addConsoleMessage(
+ ConsoleMessage::create(
+ JSMessageSource,
+ WarningMessageLevel,
+ handler().getParamName()
+ + " value "
+ + String::number(value)
+ + " outside nominal range ["
+ + String::number(minValue) + ", " + String::number(maxValue)
+ + "]; value will be clamped."));
+ }
+}
+
void AudioParam::setValue(float value)
{
+ warnIfOutsideRange(value, minValue(), maxValue());
handler().setValue(value);
}
@@ -280,6 +318,16 @@ float AudioParam::defaultValue() const
return handler().defaultValue();
}
+float AudioParam::minValue() const
+{
+ return handler().minValue();
+}
+
+float AudioParam::maxValue() const
+{
+ return handler().maxValue();
+}
+
AudioParam* AudioParam::setValueAtTime(float value, double time, ExceptionState& exceptionState)
{
handler().timeline().setValueAtTime(value, time, exceptionState);

Powered by Google App Engine
This is Rietveld 408576698