| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 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 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 const double AudioParamHandler::DefaultSmoothingConstant = 0.05; | 40 const double AudioParamHandler::DefaultSmoothingConstant = 0.05; |
| 41 const double AudioParamHandler::SnapThreshold = 0.001; | 41 const double AudioParamHandler::SnapThreshold = 0.001; |
| 42 | 42 |
| 43 AudioParamHandler::AudioParamHandler(AbstractAudioContext& context, AudioParamTy
pe paramType, double defaultValue, float minValue, float maxValue) | 43 AudioParamHandler::AudioParamHandler(AbstractAudioContext& context, AudioParamTy
pe paramType, double defaultValue, float minValue, float maxValue) |
| 44 : AudioSummingJunction(context.deferredTaskHandler()) | 44 : AudioSummingJunction(context.deferredTaskHandler()) |
| 45 , m_paramType(paramType) | 45 , m_paramType(paramType) |
| 46 , m_intrinsicValue(defaultValue) | 46 , m_intrinsicValue(defaultValue) |
| 47 , m_defaultValue(defaultValue) | 47 , m_defaultValue(defaultValue) |
| 48 , m_minValue(minValue) | 48 , m_minValue(minValue) |
| 49 , m_maxValue(maxValue) | 49 , m_maxValue(maxValue) |
| 50 , m_smoothedValue(defaultValue) | |
| 51 { | 50 { |
| 52 // The destination MUST exist because we need the destination handler for th
e AudioParam. | 51 // The destination MUST exist because we need the destination handler for th
e AudioParam. |
| 53 RELEASE_ASSERT(context.destination()); | 52 RELEASE_ASSERT(context.destination()); |
| 54 | 53 |
| 55 m_destinationHandler = &context.destination()->audioDestinationHandler(); | 54 m_destinationHandler = &context.destination()->audioDestinationHandler(); |
| 55 m_timeline.setSmoothedValue(defaultValue); |
| 56 } | 56 } |
| 57 | 57 |
| 58 AudioDestinationHandler& AudioParamHandler::destinationHandler() const | 58 AudioDestinationHandler& AudioParamHandler::destinationHandler() const |
| 59 { | 59 { |
| 60 return *m_destinationHandler; | 60 return *m_destinationHandler; |
| 61 } | 61 } |
| 62 | 62 |
| 63 void AudioParamHandler::setParamType(AudioParamType paramType) | 63 void AudioParamHandler::setParamType(AudioParamType paramType) |
| 64 { | 64 { |
| 65 m_paramType = paramType; | 65 m_paramType = paramType; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 } | 165 } |
| 166 | 166 |
| 167 void AudioParamHandler::setValue(float value) | 167 void AudioParamHandler::setValue(float value) |
| 168 { | 168 { |
| 169 setIntrinsicValue(value); | 169 setIntrinsicValue(value); |
| 170 updateHistograms(value); | 170 updateHistograms(value); |
| 171 } | 171 } |
| 172 | 172 |
| 173 float AudioParamHandler::smoothedValue() | 173 float AudioParamHandler::smoothedValue() |
| 174 { | 174 { |
| 175 return m_smoothedValue; | 175 return m_timeline.smoothedValue(); |
| 176 } | 176 } |
| 177 | 177 |
| 178 bool AudioParamHandler::smooth() | 178 bool AudioParamHandler::smooth() |
| 179 { | 179 { |
| 180 // If values have been explicitly scheduled on the timeline, then use the ex
act value. | 180 // If values have been explicitly scheduled on the timeline, then use the ex
act value. |
| 181 // Smoothing effectively is performed by the timeline. | 181 // Smoothing effectively is performed by the timeline. |
| 182 bool useTimelineValue = false; | 182 bool useTimelineValue = false; |
| 183 float value = m_timeline.valueForContextTime(destinationHandler(), intrinsic
Value(), useTimelineValue, minValue(), maxValue()); | 183 float value = m_timeline.valueForContextTime(destinationHandler(), intrinsic
Value(), useTimelineValue, minValue(), maxValue()); |
| 184 | 184 |
| 185 if (m_smoothedValue == value) { | 185 |
| 186 float smoothedValue = m_timeline.smoothedValue(); |
| 187 if (smoothedValue == value) { |
| 186 // Smoothed value has already approached and snapped to value. | 188 // Smoothed value has already approached and snapped to value. |
| 187 setIntrinsicValue(value); | 189 setIntrinsicValue(value); |
| 188 return true; | 190 return true; |
| 189 } | 191 } |
| 190 | 192 |
| 191 if (useTimelineValue) { | 193 if (useTimelineValue) { |
| 192 m_smoothedValue = value; | 194 m_timeline.setSmoothedValue(value); |
| 193 } else { | 195 } else { |
| 194 // Dezipper - exponential approach. | 196 // Dezipper - exponential approach. |
| 195 m_smoothedValue += (value - m_smoothedValue) * DefaultSmoothingConstant; | 197 smoothedValue += (value - smoothedValue) * DefaultSmoothingConstant; |
| 196 | 198 |
| 197 // If we get close enough then snap to actual value. | 199 // If we get close enough then snap to actual value. |
| 198 // FIXME: the threshold needs to be adjustable depending on range - but | 200 // FIXME: the threshold needs to be adjustable depending on range - but |
| 199 // this is OK general purpose value. | 201 // this is OK general purpose value. |
| 200 if (fabs(m_smoothedValue - value) < SnapThreshold) | 202 if (fabs(smoothedValue - value) < SnapThreshold) |
| 201 m_smoothedValue = value; | 203 smoothedValue = value; |
| 204 m_timeline.setSmoothedValue(smoothedValue); |
| 202 } | 205 } |
| 203 | 206 |
| 204 setIntrinsicValue(value); | 207 setIntrinsicValue(value); |
| 205 return false; | 208 return false; |
| 206 } | 209 } |
| 207 | 210 |
| 208 float AudioParamHandler::finalValue() | 211 float AudioParamHandler::finalValue() |
| 209 { | 212 { |
| 210 float value = intrinsicValue(); | 213 float value = intrinsicValue(); |
| 211 calculateFinalValues(&value, 1, false); | 214 calculateFinalValues(&value, 1, false); |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 } | 499 } |
| 497 | 500 |
| 498 AudioParam* AudioParam::cancelScheduledValues(double startTime, ExceptionState&
exceptionState) | 501 AudioParam* AudioParam::cancelScheduledValues(double startTime, ExceptionState&
exceptionState) |
| 499 { | 502 { |
| 500 handler().timeline().cancelScheduledValues(startTime, exceptionState); | 503 handler().timeline().cancelScheduledValues(startTime, exceptionState); |
| 501 return this; | 504 return this; |
| 502 } | 505 } |
| 503 | 506 |
| 504 } // namespace blink | 507 } // namespace blink |
| 505 | 508 |
| OLD | NEW |