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

Side by Side Diff: third_party/WebKit/Source/modules/webaudio/AudioParamTimeline.cpp

Issue 2701993002: DO NOT COMMIT: Results of running new (proposed) clang-format on Blink (Closed)
Patch Set: Created 3 years, 10 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 unified diff | Download patch
OLDNEW
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 * 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 // value (1.1754944e-38) because we normally operate with flush-to-zero enabled. 54 // value (1.1754944e-38) because we normally operate with flush-to-zero enabled.
55 const float kSetTargetZeroThreshold = 1e-20; 55 const float kSetTargetZeroThreshold = 1e-20;
56 56
57 static bool isNonNegativeAudioParamTime(double time, 57 static bool isNonNegativeAudioParamTime(double time,
58 ExceptionState& exceptionState, 58 ExceptionState& exceptionState,
59 String message = "Time") { 59 String message = "Time") {
60 if (time >= 0) 60 if (time >= 0)
61 return true; 61 return true;
62 62
63 exceptionState.throwDOMException( 63 exceptionState.throwDOMException(
64 InvalidAccessError, message + " must be a finite non-negative number: " + 64 InvalidAccessError,
65 String::number(time)); 65 message +
66 " must be a finite non-negative number: " + String::number(time));
66 return false; 67 return false;
67 } 68 }
68 69
69 static bool isPositiveAudioParamTime(double time, 70 static bool isPositiveAudioParamTime(double time,
70 ExceptionState& exceptionState, 71 ExceptionState& exceptionState,
71 String message) { 72 String message) {
72 if (time > 0) 73 if (time > 0)
73 return true; 74 return true;
74 75
75 exceptionState.throwDOMException( 76 exceptionState.throwDOMException(
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 ExceptionState& exceptionState) { 489 ExceptionState& exceptionState) {
489 DCHECK(isMainThread()); 490 DCHECK(isMainThread());
490 DCHECK(curve); 491 DCHECK(curve);
491 492
492 if (!isNonNegativeAudioParamTime(time, exceptionState) || 493 if (!isNonNegativeAudioParamTime(time, exceptionState) ||
493 !isPositiveAudioParamTime(duration, exceptionState, "Duration")) 494 !isPositiveAudioParamTime(duration, exceptionState, "Duration"))
494 return; 495 return;
495 496
496 if (curve->length() < 2) { 497 if (curve->length() < 2) {
497 exceptionState.throwDOMException( 498 exceptionState.throwDOMException(
498 InvalidStateError, ExceptionMessages::indexExceedsMinimumBound( 499 InvalidStateError,
499 "curve length", curve->length(), 2U)); 500 ExceptionMessages::indexExceedsMinimumBound("curve length",
501 curve->length(), 2U));
500 return; 502 return;
501 } 503 }
502 504
503 MutexLocker locker(m_eventsLock); 505 MutexLocker locker(m_eventsLock);
504 insertEvent(ParamEvent::createSetValueCurveEvent(curve, time, duration), 506 insertEvent(ParamEvent::createSetValueCurveEvent(curve, time, duration),
505 exceptionState); 507 exceptionState);
506 508
507 // Insert a setValueAtTime event too to establish an event so that all 509 // Insert a setValueAtTime event too to establish an event so that all
508 // following events will process from the end of the curve instead of the 510 // following events will process from the end of the curve instead of the
509 // beginning. 511 // beginning.
(...skipping 19 matching lines...) Expand all
529 return; 531 return;
530 532
531 unsigned i = 0; 533 unsigned i = 0;
532 double insertTime = event->time(); 534 double insertTime = event->time();
533 535
534 if (!m_events.size() && 536 if (!m_events.size() &&
535 (event->getType() == ParamEvent::LinearRampToValue || 537 (event->getType() == ParamEvent::LinearRampToValue ||
536 event->getType() == ParamEvent::ExponentialRampToValue)) { 538 event->getType() == ParamEvent::ExponentialRampToValue)) {
537 // There are no events preceding these ramps. Insert a new setValueAtTime 539 // There are no events preceding these ramps. Insert a new setValueAtTime
538 // event to set the starting point for these events. 540 // event to set the starting point for these events.
539 m_events.insert(0, AudioParamTimeline::ParamEvent::createSetValueEvent( 541 m_events.insert(0,
540 event->initialValue(), event->callTime())); 542 AudioParamTimeline::ParamEvent::createSetValueEvent(
543 event->initialValue(), event->callTime()));
541 } 544 }
542 545
543 for (i = 0; i < m_events.size(); ++i) { 546 for (i = 0; i < m_events.size(); ++i) {
544 if (event->getType() == ParamEvent::SetValueCurve) { 547 if (event->getType() == ParamEvent::SetValueCurve) {
545 // If this event is a SetValueCurve, make sure it doesn't overlap any 548 // If this event is a SetValueCurve, make sure it doesn't overlap any
546 // existing event. It's ok if the SetValueCurve starts at the same time as 549 // existing event. It's ok if the SetValueCurve starts at the same time as
547 // the end of some other duration. 550 // the end of some other duration.
548 double endTime = event->time() + event->duration(); 551 double endTime = event->time() + event->duration();
549 if (m_events[i]->time() > event->time() && 552 if (m_events[i]->time() > event->time() &&
550 m_events[i]->time() < endTime) { 553 m_events[i]->time() < endTime) {
551 exceptionState.throwDOMException( 554 exceptionState.throwDOMException(
552 NotSupportedError, 555 NotSupportedError,
553 eventToString(*event) + " overlaps " + eventToString(*m_events[i])); 556 eventToString(*event) + " overlaps " + eventToString(*m_events[i]));
554 return; 557 return;
555 } 558 }
556 } else { 559 } else {
557 // Otherwise, make sure this event doesn't overlap any existing 560 // Otherwise, make sure this event doesn't overlap any existing
558 // SetValueCurve event. 561 // SetValueCurve event.
559 if (m_events[i]->getType() == ParamEvent::SetValueCurve) { 562 if (m_events[i]->getType() == ParamEvent::SetValueCurve) {
560 double endTime = m_events[i]->time() + m_events[i]->duration(); 563 double endTime = m_events[i]->time() + m_events[i]->duration();
561 if (event->time() >= m_events[i]->time() && event->time() < endTime) { 564 if (event->time() >= m_events[i]->time() && event->time() < endTime) {
562 exceptionState.throwDOMException( 565 exceptionState.throwDOMException(NotSupportedError,
563 NotSupportedError, eventToString(*event) + " overlaps " + 566 eventToString(*event) +
564 eventToString(*m_events[i])); 567 " overlaps " +
568 eventToString(*m_events[i]));
565 return; 569 return;
566 } 570 }
567 } 571 }
568 } 572 }
569 573
570 // Overwrite same event type and time. 574 // Overwrite same event type and time.
571 if (m_events[i]->time() == insertTime && 575 if (m_events[i]->time() == insertTime &&
572 m_events[i]->getType() == event->getType()) { 576 m_events[i]->getType() == event->getType()) {
573 m_events[i] = std::move(event); 577 m_events[i] = std::move(event);
574 return; 578 return;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 break; 638 break;
635 } 639 }
636 } 640 }
637 641
638 // The event that is being cancelled. This is the event just past 642 // The event that is being cancelled. This is the event just past
639 // cancelTime, if any. 643 // cancelTime, if any.
640 unsigned cancelledEventIndex = i; 644 unsigned cancelledEventIndex = i;
641 645
642 // If the event just before cancelTime is a SetTarget or SetValueCurve 646 // If the event just before cancelTime is a SetTarget or SetValueCurve
643 // event, we need to handle that event specially instead of the event after. 647 // event, we need to handle that event specially instead of the event after.
644 if (i > 0 && ((m_events[i - 1]->getType() == ParamEvent::SetTarget) || 648 if (i > 0 &&
645 (m_events[i - 1]->getType() == ParamEvent::SetValueCurve))) { 649 ((m_events[i - 1]->getType() == ParamEvent::SetTarget) ||
650 (m_events[i - 1]->getType() == ParamEvent::SetValueCurve))) {
646 cancelledEventIndex = i - 1; 651 cancelledEventIndex = i - 1;
647 } else if (i >= m_events.size()) { 652 } else if (i >= m_events.size()) {
648 // If there were no events occurring after |cancelTime| (and the 653 // If there were no events occurring after |cancelTime| (and the
649 // previous event is not SetTarget or SetValueCurve, we're done. 654 // previous event is not SetTarget or SetValueCurve, we're done.
650 return; 655 return;
651 } 656 }
652 657
653 // cancelledEvent is the event that is being cancelled. 658 // cancelledEvent is the event that is being cancelled.
654 ParamEvent* cancelledEvent = m_events[cancelledEventIndex].get(); 659 ParamEvent* cancelledEvent = m_events[cancelledEventIndex].get();
655 ParamEvent::Type eventType = cancelledEvent->getType(); 660 ParamEvent::Type eventType = cancelledEvent->getType();
(...skipping 718 matching lines...) Expand 10 before | Expand all | Expand 10 after
1374 // 1379 //
1375 // v((c+k)/F) = V*m^k 1380 // v((c+k)/F) = V*m^k
1376 // 1381 //
1377 // where 1382 // where
1378 // V = v1*(v2/v1)^((c/F-t1)/(t2-t1)) 1383 // V = v1*(v2/v1)^((c/F-t1)/(t2-t1))
1379 // m = (v2/v1)^(1/(F*(t2-t1))) 1384 // m = (v2/v1)^(1/(F*(t2-t1)))
1380 1385
1381 // Compute the per-sample multiplier. 1386 // Compute the per-sample multiplier.
1382 float multiplier = powf(value2 / value1, 1 / numSampleFrames); 1387 float multiplier = powf(value2 / value1, 1 / numSampleFrames);
1383 // Set the starting value of the exponential ramp. 1388 // Set the starting value of the exponential ramp.
1384 value = value1 * powf(value2 / value1, 1389 value =
1385 (currentFrame / sampleRate - time1) / deltaTime); 1390 value1 *
1391 powf(value2 / value1, (currentFrame / sampleRate - time1) / deltaTime);
1386 1392
1387 for (; writeIndex < fillToFrame; ++writeIndex) { 1393 for (; writeIndex < fillToFrame; ++writeIndex) {
1388 values[writeIndex] = value; 1394 values[writeIndex] = value;
1389 value *= multiplier; 1395 value *= multiplier;
1390 ++currentFrame; 1396 ++currentFrame;
1391 } 1397 }
1392 // |value| got updated one extra time in the above loop. Restore it to 1398 // |value| got updated one extra time in the above loop. Restore it to
1393 // the last computed value. 1399 // the last computed value.
1394 if (writeIndex >= 1) 1400 if (writeIndex >= 1)
1395 value /= multiplier; 1401 value /= multiplier;
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
1744 unsigned writeIndex) { 1750 unsigned writeIndex) {
1745 size_t index = writeIndex; 1751 size_t index = writeIndex;
1746 1752
1747 for (; index < endFrame; ++index) 1753 for (; index < endFrame; ++index)
1748 values[index] = defaultValue; 1754 values[index] = defaultValue;
1749 1755
1750 return index; 1756 return index;
1751 } 1757 }
1752 1758
1753 } // namespace blink 1759 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698