|
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/. */ |
|
6 |
|
7 #include "mozilla/dom/ChannelSplitterNode.h" |
|
8 #include "mozilla/dom/ChannelSplitterNodeBinding.h" |
|
9 #include "AudioNodeEngine.h" |
|
10 #include "AudioNodeStream.h" |
|
11 |
|
12 namespace mozilla { |
|
13 namespace dom { |
|
14 |
|
15 NS_IMPL_ISUPPORTS_INHERITED0(ChannelSplitterNode, AudioNode) |
|
16 |
|
17 class ChannelSplitterNodeEngine : public AudioNodeEngine |
|
18 { |
|
19 public: |
|
20 ChannelSplitterNodeEngine(ChannelSplitterNode* aNode) |
|
21 : AudioNodeEngine(aNode) |
|
22 { |
|
23 MOZ_ASSERT(NS_IsMainThread()); |
|
24 } |
|
25 |
|
26 virtual void ProcessBlocksOnPorts(AudioNodeStream* aStream, |
|
27 const OutputChunks& aInput, |
|
28 OutputChunks& aOutput, |
|
29 bool* aFinished) MOZ_OVERRIDE |
|
30 { |
|
31 MOZ_ASSERT(aInput.Length() == 1, "Should only have one input port"); |
|
32 |
|
33 aOutput.SetLength(OutputCount()); |
|
34 for (uint16_t i = 0; i < OutputCount(); ++i) { |
|
35 if (i < aInput[0].mChannelData.Length()) { |
|
36 // Split out existing channels |
|
37 AllocateAudioBlock(1, &aOutput[i]); |
|
38 AudioBlockCopyChannelWithScale( |
|
39 static_cast<const float*>(aInput[0].mChannelData[i]), |
|
40 aInput[0].mVolume, |
|
41 static_cast<float*>(const_cast<void*>(aOutput[i].mChannelData[0]))); |
|
42 } else { |
|
43 // Pad with silent channels if needed |
|
44 aOutput[i].SetNull(WEBAUDIO_BLOCK_SIZE); |
|
45 } |
|
46 } |
|
47 } |
|
48 |
|
49 virtual size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const MOZ_OVERRIDE |
|
50 { |
|
51 return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf); |
|
52 } |
|
53 }; |
|
54 |
|
55 ChannelSplitterNode::ChannelSplitterNode(AudioContext* aContext, |
|
56 uint16_t aOutputCount) |
|
57 : AudioNode(aContext, |
|
58 2, |
|
59 ChannelCountMode::Max, |
|
60 ChannelInterpretation::Speakers) |
|
61 , mOutputCount(aOutputCount) |
|
62 { |
|
63 mStream = aContext->Graph()->CreateAudioNodeStream(new ChannelSplitterNodeEngine(this), |
|
64 MediaStreamGraph::INTERNAL_STREAM); |
|
65 } |
|
66 |
|
67 JSObject* |
|
68 ChannelSplitterNode::WrapObject(JSContext* aCx) |
|
69 { |
|
70 return ChannelSplitterNodeBinding::Wrap(aCx, this); |
|
71 } |
|
72 |
|
73 } |
|
74 } |
|
75 |