content/media/webaudio/ChannelSplitterNode.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/media/webaudio/ChannelSplitterNode.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,75 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim:set ts=2 sw=2 sts=2 et cindent: */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#include "mozilla/dom/ChannelSplitterNode.h"
    1.11 +#include "mozilla/dom/ChannelSplitterNodeBinding.h"
    1.12 +#include "AudioNodeEngine.h"
    1.13 +#include "AudioNodeStream.h"
    1.14 +
    1.15 +namespace mozilla {
    1.16 +namespace dom {
    1.17 +
    1.18 +NS_IMPL_ISUPPORTS_INHERITED0(ChannelSplitterNode, AudioNode)
    1.19 +
    1.20 +class ChannelSplitterNodeEngine : public AudioNodeEngine
    1.21 +{
    1.22 +public:
    1.23 +  ChannelSplitterNodeEngine(ChannelSplitterNode* aNode)
    1.24 +    : AudioNodeEngine(aNode)
    1.25 +  {
    1.26 +    MOZ_ASSERT(NS_IsMainThread());
    1.27 +  }
    1.28 +
    1.29 +  virtual void ProcessBlocksOnPorts(AudioNodeStream* aStream,
    1.30 +                                    const OutputChunks& aInput,
    1.31 +                                    OutputChunks& aOutput,
    1.32 +                                    bool* aFinished) MOZ_OVERRIDE
    1.33 +  {
    1.34 +    MOZ_ASSERT(aInput.Length() == 1, "Should only have one input port");
    1.35 +
    1.36 +    aOutput.SetLength(OutputCount());
    1.37 +    for (uint16_t i = 0; i < OutputCount(); ++i) {
    1.38 +      if (i < aInput[0].mChannelData.Length()) {
    1.39 +        // Split out existing channels
    1.40 +        AllocateAudioBlock(1, &aOutput[i]);
    1.41 +        AudioBlockCopyChannelWithScale(
    1.42 +            static_cast<const float*>(aInput[0].mChannelData[i]),
    1.43 +            aInput[0].mVolume,
    1.44 +            static_cast<float*>(const_cast<void*>(aOutput[i].mChannelData[0])));
    1.45 +      } else {
    1.46 +        // Pad with silent channels if needed
    1.47 +        aOutput[i].SetNull(WEBAUDIO_BLOCK_SIZE);
    1.48 +      }
    1.49 +    }
    1.50 +  }
    1.51 +
    1.52 +  virtual size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const MOZ_OVERRIDE
    1.53 +  {
    1.54 +    return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
    1.55 +  }
    1.56 +};
    1.57 +
    1.58 +ChannelSplitterNode::ChannelSplitterNode(AudioContext* aContext,
    1.59 +                                         uint16_t aOutputCount)
    1.60 +  : AudioNode(aContext,
    1.61 +              2,
    1.62 +              ChannelCountMode::Max,
    1.63 +              ChannelInterpretation::Speakers)
    1.64 +  , mOutputCount(aOutputCount)
    1.65 +{
    1.66 +  mStream = aContext->Graph()->CreateAudioNodeStream(new ChannelSplitterNodeEngine(this),
    1.67 +                                                     MediaStreamGraph::INTERNAL_STREAM);
    1.68 +}
    1.69 +
    1.70 +JSObject*
    1.71 +ChannelSplitterNode::WrapObject(JSContext* aCx)
    1.72 +{
    1.73 +  return ChannelSplitterNodeBinding::Wrap(aCx, this);
    1.74 +}
    1.75 +
    1.76 +}
    1.77 +}
    1.78 +

mercurial