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 * 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 #include "modules/webaudio/AudioNodeInput.h" | 43 #include "modules/webaudio/AudioNodeInput.h" |
44 #include "modules/webaudio/AudioNodeOutput.h" | 44 #include "modules/webaudio/AudioNodeOutput.h" |
45 #include "modules/webaudio/BiquadFilterNode.h" | 45 #include "modules/webaudio/BiquadFilterNode.h" |
46 #include "modules/webaudio/ChannelMergerNode.h" | 46 #include "modules/webaudio/ChannelMergerNode.h" |
47 #include "modules/webaudio/ChannelSplitterNode.h" | 47 #include "modules/webaudio/ChannelSplitterNode.h" |
48 #include "modules/webaudio/ConvolverNode.h" | 48 #include "modules/webaudio/ConvolverNode.h" |
49 #include "modules/webaudio/DefaultAudioDestinationNode.h" | 49 #include "modules/webaudio/DefaultAudioDestinationNode.h" |
50 #include "modules/webaudio/DelayNode.h" | 50 #include "modules/webaudio/DelayNode.h" |
51 #include "modules/webaudio/DynamicsCompressorNode.h" | 51 #include "modules/webaudio/DynamicsCompressorNode.h" |
52 #include "modules/webaudio/GainNode.h" | 52 #include "modules/webaudio/GainNode.h" |
| 53 #include "modules/webaudio/IIRFilterNode.h" |
53 #include "modules/webaudio/MediaElementAudioSourceNode.h" | 54 #include "modules/webaudio/MediaElementAudioSourceNode.h" |
54 #include "modules/webaudio/MediaStreamAudioDestinationNode.h" | 55 #include "modules/webaudio/MediaStreamAudioDestinationNode.h" |
55 #include "modules/webaudio/MediaStreamAudioSourceNode.h" | 56 #include "modules/webaudio/MediaStreamAudioSourceNode.h" |
56 #include "modules/webaudio/OfflineAudioCompletionEvent.h" | 57 #include "modules/webaudio/OfflineAudioCompletionEvent.h" |
57 #include "modules/webaudio/OfflineAudioContext.h" | 58 #include "modules/webaudio/OfflineAudioContext.h" |
58 #include "modules/webaudio/OfflineAudioDestinationNode.h" | 59 #include "modules/webaudio/OfflineAudioDestinationNode.h" |
59 #include "modules/webaudio/OscillatorNode.h" | 60 #include "modules/webaudio/OscillatorNode.h" |
60 #include "modules/webaudio/PannerNode.h" | 61 #include "modules/webaudio/PannerNode.h" |
61 #include "modules/webaudio/PeriodicWave.h" | 62 #include "modules/webaudio/PeriodicWave.h" |
62 #include "modules/webaudio/ScriptProcessorNode.h" | 63 #include "modules/webaudio/ScriptProcessorNode.h" |
63 #include "modules/webaudio/StereoPannerNode.h" | 64 #include "modules/webaudio/StereoPannerNode.h" |
64 #include "modules/webaudio/WaveShaperNode.h" | 65 #include "modules/webaudio/WaveShaperNode.h" |
65 #include "platform/ThreadSafeFunctional.h" | 66 #include "platform/ThreadSafeFunctional.h" |
| 67 #include "platform/audio/IIRFilter.h" |
66 #include "public/platform/Platform.h" | 68 #include "public/platform/Platform.h" |
67 #include "wtf/text/WTFString.h" | 69 #include "wtf/text/WTFString.h" |
68 | 70 |
69 namespace blink { | 71 namespace blink { |
70 | 72 |
71 AbstractAudioContext* AbstractAudioContext::create(Document& document, Exception
State& exceptionState) | 73 AbstractAudioContext* AbstractAudioContext::create(Document& document, Exception
State& exceptionState) |
72 { | 74 { |
73 return AudioContext::create(document, exceptionState); | 75 return AudioContext::create(document, exceptionState); |
74 } | 76 } |
75 | 77 |
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 + ") must match."); | 585 + ") must match."); |
584 return nullptr; | 586 return nullptr; |
585 } | 587 } |
586 | 588 |
587 bool isNormalizationDisabled = false; | 589 bool isNormalizationDisabled = false; |
588 DictionaryHelper::getWithUndefinedOrNullCheck(options, "disableNormalization
", isNormalizationDisabled); | 590 DictionaryHelper::getWithUndefinedOrNullCheck(options, "disableNormalization
", isNormalizationDisabled); |
589 | 591 |
590 return PeriodicWave::create(sampleRate(), real, imag, isNormalizationDisable
d); | 592 return PeriodicWave::create(sampleRate(), real, imag, isNormalizationDisable
d); |
591 } | 593 } |
592 | 594 |
| 595 IIRFilterNode* AbstractAudioContext::createIIRFilter(Vector<double> feedforwardC
oef, Vector<double> feedbackCoef, ExceptionState& exceptionState) |
| 596 { |
| 597 ASSERT(isMainThread()); |
| 598 |
| 599 if (isContextClosed()) { |
| 600 throwExceptionForClosedState(exceptionState); |
| 601 return nullptr; |
| 602 } |
| 603 |
| 604 if (feedbackCoef.size() == 0 || (feedbackCoef.size() > IIRFilter::kMaxOrder
+ 1)) { |
| 605 exceptionState.throwDOMException( |
| 606 NotSupportedError, |
| 607 ExceptionMessages::indexOutsideRange<size_t>( |
| 608 "number of feedback coefficients", |
| 609 feedbackCoef.size(), |
| 610 1, |
| 611 ExceptionMessages::InclusiveBound, |
| 612 IIRFilter::kMaxOrder + 1, |
| 613 ExceptionMessages::InclusiveBound)); |
| 614 return nullptr; |
| 615 } |
| 616 |
| 617 if (feedforwardCoef.size() == 0 || (feedforwardCoef.size() > IIRFilter::kMax
Order + 1)) { |
| 618 exceptionState.throwDOMException( |
| 619 NotSupportedError, |
| 620 ExceptionMessages::indexOutsideRange<size_t>( |
| 621 "number of feedforward coefficients", |
| 622 feedforwardCoef.size(), |
| 623 1, |
| 624 ExceptionMessages::InclusiveBound, |
| 625 IIRFilter::kMaxOrder + 1, |
| 626 ExceptionMessages::InclusiveBound)); |
| 627 return nullptr; |
| 628 } |
| 629 |
| 630 if (feedbackCoef[0] == 0) { |
| 631 exceptionState.throwDOMException( |
| 632 InvalidStateError, |
| 633 "First feedback coefficient cannot be zero."); |
| 634 return nullptr; |
| 635 } |
| 636 |
| 637 bool hasNonZeroCoef = false; |
| 638 |
| 639 for (size_t k = 0; k < feedforwardCoef.size(); ++k) { |
| 640 if (feedforwardCoef[k] != 0) { |
| 641 hasNonZeroCoef = true; |
| 642 break; |
| 643 } |
| 644 } |
| 645 |
| 646 if (!hasNonZeroCoef) { |
| 647 exceptionState.throwDOMException( |
| 648 InvalidStateError, |
| 649 "At least one feedforward coefficient must be non-zero."); |
| 650 return nullptr; |
| 651 } |
| 652 |
| 653 // Make sure all coefficents are finite. |
| 654 for (size_t k = 0; k < feedforwardCoef.size(); ++k) { |
| 655 double c = feedforwardCoef[k]; |
| 656 if (!std::isfinite(c)) { |
| 657 String name = "feedforward coefficient " + String::number(k); |
| 658 exceptionState.throwDOMException( |
| 659 InvalidStateError, |
| 660 ExceptionMessages::notAFiniteNumber(c, name.ascii().data())); |
| 661 return nullptr; |
| 662 } |
| 663 } |
| 664 |
| 665 for (size_t k = 0; k < feedbackCoef.size(); ++k) { |
| 666 double c = feedbackCoef[k]; |
| 667 if (!std::isfinite(c)) { |
| 668 String name = "feedback coefficient " + String::number(k); |
| 669 exceptionState.throwDOMException( |
| 670 InvalidStateError, |
| 671 ExceptionMessages::notAFiniteNumber(c, name.ascii().data())); |
| 672 return nullptr; |
| 673 } |
| 674 } |
| 675 |
| 676 return IIRFilterNode::create(*this, sampleRate(), feedforwardCoef, feedbackC
oef); |
| 677 } |
| 678 |
593 PeriodicWave* AbstractAudioContext::periodicWave(int type) | 679 PeriodicWave* AbstractAudioContext::periodicWave(int type) |
594 { | 680 { |
595 switch (type) { | 681 switch (type) { |
596 case OscillatorHandler::SINE: | 682 case OscillatorHandler::SINE: |
597 // Initialize the table if necessary | 683 // Initialize the table if necessary |
598 if (!m_periodicWaveSine) | 684 if (!m_periodicWaveSine) |
599 m_periodicWaveSine = PeriodicWave::createSine(sampleRate()); | 685 m_periodicWaveSine = PeriodicWave::createSine(sampleRate()); |
600 return m_periodicWaveSine; | 686 return m_periodicWaveSine; |
601 case OscillatorHandler::SQUARE: | 687 case OscillatorHandler::SQUARE: |
602 // Initialize the table if necessary | 688 // Initialize the table if necessary |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
861 SecurityOrigin* AbstractAudioContext::securityOrigin() const | 947 SecurityOrigin* AbstractAudioContext::securityOrigin() const |
862 { | 948 { |
863 if (executionContext()) | 949 if (executionContext()) |
864 return executionContext()->securityOrigin(); | 950 return executionContext()->securityOrigin(); |
865 | 951 |
866 return nullptr; | 952 return nullptr; |
867 } | 953 } |
868 | 954 |
869 } // namespace blink | 955 } // namespace blink |
870 | 956 |
OLD | NEW |