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

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

Issue 1361233004: Implement IIRFilter node for WebAudio. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update histograms.xml Created 5 years, 2 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) 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 #include "modules/webaudio/AudioNodeInput.h" 46 #include "modules/webaudio/AudioNodeInput.h"
47 #include "modules/webaudio/AudioNodeOutput.h" 47 #include "modules/webaudio/AudioNodeOutput.h"
48 #include "modules/webaudio/BiquadFilterNode.h" 48 #include "modules/webaudio/BiquadFilterNode.h"
49 #include "modules/webaudio/ChannelMergerNode.h" 49 #include "modules/webaudio/ChannelMergerNode.h"
50 #include "modules/webaudio/ChannelSplitterNode.h" 50 #include "modules/webaudio/ChannelSplitterNode.h"
51 #include "modules/webaudio/ConvolverNode.h" 51 #include "modules/webaudio/ConvolverNode.h"
52 #include "modules/webaudio/DefaultAudioDestinationNode.h" 52 #include "modules/webaudio/DefaultAudioDestinationNode.h"
53 #include "modules/webaudio/DelayNode.h" 53 #include "modules/webaudio/DelayNode.h"
54 #include "modules/webaudio/DynamicsCompressorNode.h" 54 #include "modules/webaudio/DynamicsCompressorNode.h"
55 #include "modules/webaudio/GainNode.h" 55 #include "modules/webaudio/GainNode.h"
56 #include "modules/webaudio/IIRFilterNode.h"
56 #include "modules/webaudio/MediaElementAudioSourceNode.h" 57 #include "modules/webaudio/MediaElementAudioSourceNode.h"
57 #include "modules/webaudio/MediaStreamAudioDestinationNode.h" 58 #include "modules/webaudio/MediaStreamAudioDestinationNode.h"
58 #include "modules/webaudio/MediaStreamAudioSourceNode.h" 59 #include "modules/webaudio/MediaStreamAudioSourceNode.h"
59 #include "modules/webaudio/OfflineAudioCompletionEvent.h" 60 #include "modules/webaudio/OfflineAudioCompletionEvent.h"
60 #include "modules/webaudio/OfflineAudioContext.h" 61 #include "modules/webaudio/OfflineAudioContext.h"
61 #include "modules/webaudio/OfflineAudioDestinationNode.h" 62 #include "modules/webaudio/OfflineAudioDestinationNode.h"
62 #include "modules/webaudio/OscillatorNode.h" 63 #include "modules/webaudio/OscillatorNode.h"
63 #include "modules/webaudio/PannerNode.h" 64 #include "modules/webaudio/PannerNode.h"
64 #include "modules/webaudio/PeriodicWave.h" 65 #include "modules/webaudio/PeriodicWave.h"
65 #include "modules/webaudio/ScriptProcessorNode.h" 66 #include "modules/webaudio/ScriptProcessorNode.h"
66 #include "modules/webaudio/StereoPannerNode.h" 67 #include "modules/webaudio/StereoPannerNode.h"
67 #include "modules/webaudio/WaveShaperNode.h" 68 #include "modules/webaudio/WaveShaperNode.h"
68 #include "platform/ThreadSafeFunctional.h" 69 #include "platform/ThreadSafeFunctional.h"
70 #include "platform/audio/IIRFilter.h"
69 #include "public/platform/Platform.h" 71 #include "public/platform/Platform.h"
70 #include "wtf/text/WTFString.h" 72 #include "wtf/text/WTFString.h"
71 73
72 namespace blink { 74 namespace blink {
73 75
74 AbstractAudioContext* AbstractAudioContext::create(Document& document, Exception State& exceptionState) 76 AbstractAudioContext* AbstractAudioContext::create(Document& document, Exception State& exceptionState)
75 { 77 {
76 return AudioContext::create(document, exceptionState); 78 return AudioContext::create(document, exceptionState);
77 } 79 }
78 80
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 + ") must match."); 588 + ") must match.");
587 return nullptr; 589 return nullptr;
588 } 590 }
589 591
590 bool isNormalizationDisabled = false; 592 bool isNormalizationDisabled = false;
591 DictionaryHelper::getWithUndefinedOrNullCheck(options, "disableNormalization ", isNormalizationDisabled); 593 DictionaryHelper::getWithUndefinedOrNullCheck(options, "disableNormalization ", isNormalizationDisabled);
592 594
593 return PeriodicWave::create(sampleRate(), real, imag, isNormalizationDisable d); 595 return PeriodicWave::create(sampleRate(), real, imag, isNormalizationDisable d);
594 } 596 }
595 597
598 IIRFilterNode* AbstractAudioContext::createIIRFilter(Vector<float> feedforwardCo ef, Vector<float> feedbackCoef, ExceptionState& exceptionState)
599 {
600 ASSERT(isMainThread());
601
602 if (isContextClosed()) {
603 throwExceptionForClosedState(exceptionState);
604 return nullptr;
605 }
606
607 if (!feedbackCoef.size() || (feedbackCoef.size() >= IIRFilter::kMaxOrder + 1 )) {
608 exceptionState.throwDOMException(
609 NotSupportedError,
610 ExceptionMessages::indexOutsideRange<size_t>(
611 "number of feedback coefficients",
612 feedbackCoef.size(),
613 1,
614 ExceptionMessages::InclusiveBound,
615 IIRFilter::kMaxOrder + 1,
616 ExceptionMessages::InclusiveBound));
617 return nullptr;
618 }
619
620 if (!feedforwardCoef.size() || (feedforwardCoef.size() >= IIRFilter::kMaxOrd er + 1)) {
621 exceptionState.throwDOMException(
622 NotSupportedError,
623 ExceptionMessages::indexOutsideRange<size_t>(
624 "number of feedforward coefficients",
625 feedforwardCoef.size(),
626 1,
627 ExceptionMessages::InclusiveBound,
628 IIRFilter::kMaxOrder + 1,
629 ExceptionMessages::InclusiveBound));
630 return nullptr;
631 }
632
633 if (!feedbackCoef[0]) {
634 exceptionState.throwDOMException(
635 InvalidStateError,
636 "First feedback coefficient cannot be zero.");
637 return nullptr;
638 }
639
640 bool hasNonZeroCoef = false;
641
642 for (size_t k = 0; k < feedforwardCoef.size(); ++k) {
643 if (feedforwardCoef[k]) {
644 hasNonZeroCoef = true;
645 break;
646 }
647 }
648
649 if (!hasNonZeroCoef) {
650 exceptionState.throwDOMException(
651 InvalidStateError,
652 "At least one feedforward coefficient must be non-zero.");
653 return nullptr;
654 }
655
656 // Make sure all coefficents are finite.
657 for (size_t k = 0; k < feedforwardCoef.size(); ++k) {
658 double c = feedforwardCoef[k];
659 if (!std::isfinite(c)) {
660 String name = "feedforward coefficient " + String::number(k);
661 exceptionState.throwDOMException(
662 InvalidStateError,
663 ExceptionMessages::notAFiniteNumber(c, name.ascii().data()));
664 return nullptr;
665 }
666 }
667
668 for (size_t k = 0; k < feedbackCoef.size(); ++k) {
669 double c = feedbackCoef[k];
670 if (!std::isfinite(c)) {
671 String name = "feedback coefficient " + String::number(k);
672 exceptionState.throwDOMException(
673 InvalidStateError,
674 ExceptionMessages::notAFiniteNumber(c, name.ascii().data()));
675 return nullptr;
676 }
677 }
678
679 return IIRFilterNode::create(*this, sampleRate(), feedforwardCoef, feedbackC oef);
680 }
681
596 String AbstractAudioContext::state() const 682 String AbstractAudioContext::state() const
597 { 683 {
598 // These strings had better match the strings for AudioContextState in Audio Context.idl. 684 // These strings had better match the strings for AudioContextState in Audio Context.idl.
599 switch (m_contextState) { 685 switch (m_contextState) {
600 case Suspended: 686 case Suspended:
601 return "suspended"; 687 return "suspended";
602 case Running: 688 case Running:
603 return "running"; 689 return "running";
604 case Closed: 690 case Closed:
605 return "closed"; 691 return "closed";
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 { 937 {
852 if (executionContext()) 938 if (executionContext())
853 return executionContext()->securityOrigin(); 939 return executionContext()->securityOrigin();
854 940
855 return nullptr; 941 return nullptr;
856 } 942 }
857 943
858 } // namespace blink 944 } // namespace blink
859 945
860 #endif // ENABLE(WEB_AUDIO) 946 #endif // ENABLE(WEB_AUDIO)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698