LMMS
Loading...
Searching...
No Matches
juce_Panner.h
Go to the documentation of this file.
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
27{
28namespace dsp
29{
30
31enum class PannerRule
32{
33 linear, // regular 6 dB or linear panning rule, allows the panned sound to be
34 // perceived as having a constant level when summed to mono
35 balanced, // both left and right are 1 when pan value is 0, with left decreasing
36 // to 0 above this value and right decreasing to 0 below it
37 sin3dB, // alternate version of the regular 3 dB panning rule with a sine curve
38 sin4p5dB, // alternate version of the regular 4.5 dB panning rule with a sine curve
39 sin6dB, // alternate version of the regular 6 dB panning rule with a sine curve
40 squareRoot3dB, // regular 3 dB or constant power panning rule, allows the panned sound
41 // to be perceived as having a constant level regardless of the pan position
42 squareRoot4p5dB // regular 4.5 dB panning rule, a compromise option between 3 dB and 6 dB panning rules
43};
44
50template <typename SampleType>
51class Panner
52{
53public:
54 //==============================================================================
56
57 //==============================================================================
59 Panner();
60
61 //==============================================================================
63 void setRule (Rule newRule);
64
66 void setPan (SampleType newPan);
67
68 //==============================================================================
70 void prepare (const ProcessSpec& spec);
71
73 void reset();
74
75 //==============================================================================
77 template <typename ProcessContext>
78 void process (const ProcessContext& context) noexcept
79 {
80 const auto& inputBlock = context.getInputBlock();
81 auto& outputBlock = context.getOutputBlock();
82
83 const auto numInputChannels = inputBlock.getNumChannels();
84 const auto numOutputChannels = outputBlock.getNumChannels();
85 const auto numSamples = outputBlock.getNumSamples();
86
87 jassertquiet (inputBlock.getNumSamples() == numSamples);
88
89 if (numOutputChannels != 2 || numInputChannels == 0 || numInputChannels > 2)
90 return;
91
92 if (numInputChannels == 2)
93 {
94 outputBlock.copyFrom (inputBlock);
95 }
96 else
97 {
98 outputBlock.getSingleChannelBlock (0).copyFrom (inputBlock);
99 outputBlock.getSingleChannelBlock (1).copyFrom (inputBlock);
100 }
101
102 if (context.isBypassed)
103 return;
104
105 outputBlock.getSingleChannelBlock (0).multiplyBy (leftVolume);
106 outputBlock.getSingleChannelBlock (1).multiplyBy (rightVolume);
107 }
108
109private:
110 //==============================================================================
111 void update();
112
113 //==============================================================================
114 Rule currentRule = Rule::balanced;
115 SampleType pan = 0.0;
117 double sampleRate = 44100.0;
118};
119
120} // namespace dsp
121} // namespace juce
Definition juce_SmoothedValue.h:227
Rule currentRule
Definition juce_Panner.h:114
void process(const ProcessContext &context) noexcept
Definition juce_Panner.h:78
PannerRule Rule
Definition juce_Panner.h:55
SmoothedValue< SampleType > leftVolume
Definition juce_Panner.h:116
void prepare(const ProcessSpec &spec)
Definition juce_Panner.cpp:58
void setPan(SampleType newPan)
Definition juce_Panner.cpp:48
void reset()
Definition juce_Panner.cpp:69
void setRule(Rule newRule)
Definition juce_Panner.cpp:41
Panner()
Definition juce_Panner.cpp:33
SmoothedValue< SampleType > rightVolume
Definition juce_Panner.h:116
SampleType pan
Definition juce_Panner.h:115
double sampleRate
Definition juce_Panner.h:117
#define jassertquiet(expression)
Definition juce_AudioBlock.h:29
@ squareRoot4p5dB
Definition juce_DryWetMixer.h:40
@ squareRoot3dB
Definition juce_DryWetMixer.h:39
@ sin3dB
Definition juce_DryWetMixer.h:36
@ sin6dB
Definition juce_DryWetMixer.h:38
@ linear
Definition juce_DryWetMixer.h:33
@ sin4p5dB
Definition juce_DryWetMixer.h:37
@ balanced
Definition juce_DryWetMixer.h:34
PannerRule
Definition juce_Panner.h:32
Definition carla_juce.cpp:31
Definition juce_ProcessContext.h:38