tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

PanningUtils.h (2338B)


      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 #ifndef PANNING_UTILS_H
      8 #define PANNING_UTILS_H
      9 
     10 #include "AudioNodeEngine.h"
     11 #include "AudioSegment.h"
     12 
     13 namespace mozilla::dom {
     14 
     15 template <typename T>
     16 void GainMonoToStereo(const AudioBlock& aInput, AudioBlock* aOutput, T aGainL,
     17                      T aGainR) {
     18  float* outputL = aOutput->ChannelFloatsForWrite(0);
     19  float* outputR = aOutput->ChannelFloatsForWrite(1);
     20  const float* input = static_cast<const float*>(aInput.mChannelData[0]);
     21 
     22  MOZ_ASSERT(aInput.ChannelCount() == 1);
     23  MOZ_ASSERT(aOutput->ChannelCount() == 2);
     24 
     25  AudioBlockPanMonoToStereo(input, aGainL, aGainR, outputL, outputR);
     26 }
     27 
     28 // T can be float or an array of float, and  U can be bool or an array of bool,
     29 // depending if the value of the parameters are constant for this block.
     30 template <typename T, typename U>
     31 void GainStereoToStereo(const AudioBlock& aInput, AudioBlock* aOutput, T aGainL,
     32                        T aGainR, U aOnLeft) {
     33  float* outputL = aOutput->ChannelFloatsForWrite(0);
     34  float* outputR = aOutput->ChannelFloatsForWrite(1);
     35  const float* inputL = static_cast<const float*>(aInput.mChannelData[0]);
     36  const float* inputR = static_cast<const float*>(aInput.mChannelData[1]);
     37 
     38  MOZ_ASSERT(aInput.ChannelCount() == 2);
     39  MOZ_ASSERT(aOutput->ChannelCount() == 2);
     40 
     41  AudioBlockPanStereoToStereo(inputL, inputR, aGainL, aGainR, aOnLeft, outputL,
     42                              outputR);
     43 }
     44 
     45 // T can be float or an array of float, and  U can be bool or an array of bool,
     46 // depending if the value of the parameters are constant for this block.
     47 template <typename T, typename U>
     48 void ApplyStereoPanning(const AudioBlock& aInput, AudioBlock* aOutput, T aGainL,
     49                        T aGainR, U aOnLeft) {
     50  aOutput->AllocateChannels(2);
     51 
     52  if (aInput.ChannelCount() == 1) {
     53    GainMonoToStereo(aInput, aOutput, aGainL, aGainR);
     54  } else {
     55    GainStereoToStereo(aInput, aOutput, aGainL, aGainR, aOnLeft);
     56  }
     57  aOutput->mVolume = aInput.mVolume;
     58 }
     59 
     60 }  // namespace mozilla::dom
     61 
     62 #endif  // PANNING_UTILS_H