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