1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/modules/webaudio/stereo_panner_node.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_stereo_panner_options.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/modules/webaudio/audio_graph_tracer.h"
#include "third_party/blink/renderer/modules/webaudio/audio_node_input.h"
#include "third_party/blink/renderer/modules/webaudio/audio_node_output.h"
#include "third_party/blink/renderer/modules/webaudio/base_audio_context.h"
#include "third_party/blink/renderer/platform/audio/stereo_panner.h"
#include "third_party/blink/renderer/platform/bindings/exception_messages.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/wtf/math_extras.h"
namespace blink {
namespace {
constexpr double kDefaultPanValue = 0.0;
constexpr float kMinPanValue = -1.0f;
constexpr float kMaxPanValue = 1.0f;
} // namespace
StereoPannerNode::StereoPannerNode(BaseAudioContext& context)
: AudioNode(context),
pan_(AudioParam::Create(
context,
Uuid(),
AudioParamHandler::AudioParamType::kParamTypeStereoPannerPan,
kDefaultPanValue,
AudioParamHandler::AutomationRate::kAudio,
AudioParamHandler::AutomationRateMode::kVariable,
kMinPanValue,
kMaxPanValue)) {
SetHandler(StereoPannerHandler::Create(*this, context.sampleRate(),
pan_->Handler()));
}
StereoPannerNode* StereoPannerNode::Create(BaseAudioContext& context,
ExceptionState& exception_state) {
DCHECK(IsMainThread());
return MakeGarbageCollected<StereoPannerNode>(context);
}
StereoPannerNode* StereoPannerNode::Create(BaseAudioContext* context,
const StereoPannerOptions* options,
ExceptionState& exception_state) {
StereoPannerNode* node = Create(*context, exception_state);
if (!node) {
return nullptr;
}
node->HandleChannelOptions(options, exception_state);
node->pan()->setValue(options->pan());
return node;
}
void StereoPannerNode::Trace(Visitor* visitor) const {
visitor->Trace(pan_);
AudioNode::Trace(visitor);
}
AudioParam* StereoPannerNode::pan() const {
return pan_.Get();
}
void StereoPannerNode::ReportDidCreate() {
GraphTracer().DidCreateAudioNode(this);
GraphTracer().DidCreateAudioParam(pan_);
}
void StereoPannerNode::ReportWillBeDestroyed() {
GraphTracer().WillDestroyAudioParam(pan_);
GraphTracer().WillDestroyAudioNode(this);
}
} // namespace blink
|