WaveShaperNode.cpp [plain text]
#include "config.h"
#if ENABLE(WEB_AUDIO)
#include "WaveShaperNode.h"
#include "ExceptionCode.h"
#include <wtf/MainThread.h>
namespace WebCore {
WaveShaperNode::WaveShaperNode(AudioContext* context)
: AudioBasicProcessorNode(context, context->sampleRate())
{
m_processor = std::make_unique<WaveShaperProcessor>(context->sampleRate(), 1);
setNodeType(NodeTypeWaveShaper);
initialize();
}
void WaveShaperNode::setCurve(Float32Array* curve)
{
ASSERT(isMainThread());
waveShaperProcessor()->setCurve(curve);
}
Float32Array* WaveShaperNode::curve()
{
return waveShaperProcessor()->curve();
}
void WaveShaperNode::setOversample(const String& type, ExceptionCode& ec)
{
ASSERT(isMainThread());
AudioContext::AutoLocker contextLocker(*context());
if (type == "none")
waveShaperProcessor()->setOversample(WaveShaperProcessor::OverSampleNone);
else if (type == "2x")
waveShaperProcessor()->setOversample(WaveShaperProcessor::OverSample2x);
else if (type == "4x")
waveShaperProcessor()->setOversample(WaveShaperProcessor::OverSample4x);
else
ec = INVALID_STATE_ERR;
}
String WaveShaperNode::oversample() const
{
switch (const_cast<WaveShaperNode*>(this)->waveShaperProcessor()->oversample()) {
case WaveShaperProcessor::OverSampleNone:
return "none";
case WaveShaperProcessor::OverSample2x:
return "2x";
case WaveShaperProcessor::OverSample4x:
return "4x";
default:
ASSERT_NOT_REACHED();
return "none";
}
}
}
#endif // ENABLE(WEB_AUDIO)