OpenShot Audio Library | OpenShotAudio 0.4.0
 
Loading...
Searching...
No Matches
juce_Panner.h
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce::dsp
27{
28
29enum class PannerRule
30{
31 linear, // regular 6 dB or linear panning rule, allows the panned sound to be
32 // perceived as having a constant level when summed to mono
33 balanced, // both left and right are 1 when pan value is 0, with left decreasing
34 // to 0 above this value and right decreasing to 0 below it
35 sin3dB, // alternate version of the regular 3 dB panning rule with a sine curve
36 sin4p5dB, // alternate version of the regular 4.5 dB panning rule with a sine curve
37 sin6dB, // alternate version of the regular 6 dB panning rule with a sine curve
38 squareRoot3dB, // regular 3 dB or constant power panning rule, allows the panned sound
39 // to be perceived as having a constant level regardless of the pan position
40 squareRoot4p5dB // regular 4.5 dB panning rule, a compromise option between 3 dB and 6 dB panning rules
41};
42
48template <typename SampleType>
49class Panner
50{
51public:
52 //==============================================================================
53 using Rule = PannerRule;
54
55 //==============================================================================
57 Panner();
58
59 //==============================================================================
61 void setRule (Rule newRule);
62
64 void setPan (SampleType newPan);
65
66 //==============================================================================
68 void prepare (const ProcessSpec& spec);
69
71 void reset();
72
73 //==============================================================================
75 template <typename ProcessContext>
76 void process (const ProcessContext& context) noexcept
77 {
78 const auto& inputBlock = context.getInputBlock();
79 auto& outputBlock = context.getOutputBlock();
80
81 const auto numInputChannels = inputBlock.getNumChannels();
82 const auto numOutputChannels = outputBlock.getNumChannels();
83 [[maybe_unused]] const auto numSamples = outputBlock.getNumSamples();
84
85 jassert (inputBlock.getNumSamples() == numSamples);
86
87 if (numOutputChannels != 2 || numInputChannels == 0 || numInputChannels > 2)
88 return;
89
90 if (numInputChannels == 2)
91 {
92 outputBlock.copyFrom (inputBlock);
93 }
94 else
95 {
96 outputBlock.getSingleChannelBlock (0).copyFrom (inputBlock);
97 outputBlock.getSingleChannelBlock (1).copyFrom (inputBlock);
98 }
99
100 if (context.isBypassed)
101 return;
102
103 outputBlock.getSingleChannelBlock (0).multiplyBy (leftVolume);
104 outputBlock.getSingleChannelBlock (1).multiplyBy (rightVolume);
105 }
106
107private:
108 //==============================================================================
109 void update();
110
111 //==============================================================================
112 Rule currentRule = Rule::balanced;
113 SampleType pan = 0.0;
114 SmoothedValue<SampleType> leftVolume, rightVolume;
115 double sampleRate = 44100.0;
116};
117
118} // namespace juce::dsp
void process(const ProcessContext &context) noexcept
Definition juce_Panner.h:76
void prepare(const ProcessSpec &spec)
void setPan(SampleType newPan)
void setRule(Rule newRule)