Bug 878875 - Import PannerNode tests from Blink. r=ehsan
[gecko.git] / content / media / webaudio / ChannelSplitterNode.cpp
blob5bee0038ef4b68e9f33d3b4cb086e6d7a2663347
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "mozilla/dom/ChannelSplitterNode.h"
8 #include "mozilla/dom/ChannelSplitterNodeBinding.h"
9 #include "AudioNodeEngine.h"
10 #include "AudioNodeStream.h"
11 #include "mozilla/PodOperations.h"
13 namespace mozilla {
14 namespace dom {
16 NS_IMPL_ISUPPORTS_INHERITED0(ChannelSplitterNode, AudioNode)
18 class ChannelSplitterNodeEngine : public AudioNodeEngine
20 public:
21 ChannelSplitterNodeEngine(ChannelSplitterNode* aNode)
22 : AudioNodeEngine(aNode)
24 MOZ_ASSERT(NS_IsMainThread());
27 virtual void ProduceAudioBlocksOnPorts(AudioNodeStream* aStream,
28 const OutputChunks& aInput,
29 OutputChunks& aOutput,
30 bool* aFinished) MOZ_OVERRIDE
32 MOZ_ASSERT(aInput.Length() == 1, "Should only have one input port");
34 aOutput.SetLength(OutputCount());
35 for (uint16_t i = 0; i < OutputCount(); ++i) {
36 if (i < aInput[0].mChannelData.Length()) {
37 // Split out existing channels
38 AllocateAudioBlock(1, &aOutput[i]);
39 AudioBlockCopyChannelWithScale(
40 static_cast<const float*>(aInput[0].mChannelData[i]),
41 aInput[0].mVolume,
42 static_cast<float*>(const_cast<void*>(aOutput[i].mChannelData[0])));
43 } else {
44 // Pad with silent channels if needed
45 aOutput[i].SetNull(WEBAUDIO_BLOCK_SIZE);
51 ChannelSplitterNode::ChannelSplitterNode(AudioContext* aContext,
52 uint16_t aOutputCount)
53 : AudioNode(aContext,
55 ChannelCountMode::Max,
56 ChannelInterpretation::Speakers)
57 , mOutputCount(aOutputCount)
59 mStream = aContext->Graph()->CreateAudioNodeStream(new ChannelSplitterNodeEngine(this),
60 MediaStreamGraph::INTERNAL_STREAM);
63 JSObject*
64 ChannelSplitterNode::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
66 return ChannelSplitterNodeBinding::Wrap(aCx, aScope, this);