This source file includes following definitions.
- process
- setFftSize
- setMinDecibels
- setMaxDecibels
- setSmoothingTimeConstant
#include "config.h"
#if ENABLE(WEB_AUDIO)
#include "modules/webaudio/AnalyserNode.h"
#include "bindings/v8/ExceptionMessages.h"
#include "bindings/v8/ExceptionState.h"
#include "core/dom/ExceptionCode.h"
#include "modules/webaudio/AudioNodeInput.h"
#include "modules/webaudio/AudioNodeOutput.h"
namespace WebCore {
AnalyserNode::AnalyserNode(AudioContext* context, float sampleRate)
: AudioBasicInspectorNode(context, sampleRate, 2)
{
ScriptWrappable::init(this);
setNodeType(NodeTypeAnalyser);
initialize();
}
AnalyserNode::~AnalyserNode()
{
uninitialize();
}
void AnalyserNode::process(size_t framesToProcess)
{
AudioBus* outputBus = output(0)->bus();
if (!isInitialized() || !input(0)->isConnected()) {
outputBus->zero();
return;
}
AudioBus* inputBus = input(0)->bus();
m_analyser.writeInput(inputBus, framesToProcess);
if (inputBus != outputBus)
outputBus->copyFrom(*inputBus);
}
void AnalyserNode::setFftSize(unsigned size, ExceptionState& exceptionState)
{
if (!m_analyser.setFftSize(size)) {
exceptionState.throwDOMException(
IndexSizeError,
(size < RealtimeAnalyser::MinFFTSize || size > RealtimeAnalyser::MaxFFTSize) ?
ExceptionMessages::indexOutsideRange("FFT size", size, RealtimeAnalyser::MinFFTSize, ExceptionMessages::InclusiveBound, RealtimeAnalyser::MaxFFTSize, ExceptionMessages::InclusiveBound)
: ("The value provided (" + String::number(size) + ") is not a power of two."));
}
}
void AnalyserNode::setMinDecibels(double k, ExceptionState& exceptionState)
{
if (k < maxDecibels()) {
m_analyser.setMinDecibels(k);
} else {
exceptionState.throwDOMException(
IndexSizeError,
ExceptionMessages::indexExceedsMaximumBound("minDecibels", k, maxDecibels()));
}
}
void AnalyserNode::setMaxDecibels(double k, ExceptionState& exceptionState)
{
if (k > minDecibels()) {
m_analyser.setMaxDecibels(k);
} else {
exceptionState.throwDOMException(
IndexSizeError,
ExceptionMessages::indexExceedsMinimumBound("maxDecibels", k, minDecibels()));
}
}
void AnalyserNode::setSmoothingTimeConstant(double k, ExceptionState& exceptionState)
{
if (k >= 0 && k <= 1) {
m_analyser.setSmoothingTimeConstant(k);
} else {
exceptionState.throwDOMException(
IndexSizeError,
ExceptionMessages::indexOutsideRange("smoothing value", k, 0.0, ExceptionMessages::InclusiveBound, 1.0, ExceptionMessages::InclusiveBound));
}
}
}
#endif