MCPcopy Create free account
hub / github.com/LabSound/LabSound / panWithSampleAccurateValues

Method panWithSampleAccurateValues

src/core/StereoPannerNode.cpp:46–124  ·  view source on GitHub ↗

Handle sample-accurate panning by AudioParam automation.

Source from the content-addressed store, hash-verified

44
45 // Handle sample-accurate panning by AudioParam automation.
46 virtual void panWithSampleAccurateValues(const AudioBus * inputBus, AudioBus * outputBus, const float * panValues, int framesToProcess)
47 {
48 size_t numberOfInputChannels = inputBus->numberOfChannels();
49
50 bool isInputSafe = inputBus && (inputBus->numberOfChannels() == Channels::Mono ||
51 inputBus->numberOfChannels() == Channels::Stereo) && framesToProcess <= inputBus->length();
52
53 ASSERT(isInputSafe);
54
55 if (!isInputSafe)
56 return;
57
58 bool isOutputSafe = outputBus && outputBus->numberOfChannels() == Channels::Stereo && framesToProcess <= outputBus->length();
59
60 ASSERT(isOutputSafe);
61
62 if (!isOutputSafe)
63 return;
64
65 const float * sourceL = inputBus->channel(0)->data();
66 const float * sourceR = numberOfInputChannels > Channels::Mono ? inputBus->channel(1)->data() : sourceL;
67
68 float * destinationL = outputBus->channelByType(Channel::Left)->mutableData();
69 float * destinationR = outputBus->channelByType(Channel::Right)->mutableData();
70
71 if (!sourceL || !sourceR || !destinationL || !destinationR)
72 return;
73
74 double gainL, gainR, panRadian;
75 size_t n = framesToProcess;
76
77 // For mono source case.
78 if (numberOfInputChannels == Channels::Mono)
79 {
80 while (n--)
81 {
82 float inputL = *sourceL++;
83
84 m_pan = clampTo(*panValues++, -1.0, 1.0);
85
86 // Pan from left to right [-1; 1] will be normalized as [0; 1].
87 panRadian = (m_pan * 0.5 + 0.5) * LAB_HALF_PI;
88
89 gainL = std::cos(panRadian);
90 gainR = std::sin(panRadian);
91
92 *destinationL++ = static_cast<float>(inputL * gainL);
93 *destinationR++ = static_cast<float>(inputL * gainR);
94 }
95 }
96 // For stereo source case.
97 else
98 {
99 while (n--)
100 {
101 float inputL = *sourceL++;
102 float inputR = *sourceR++;
103

Callers 1

processMethod · 0.80

Calls 7

clampToFunction · 0.85
channelMethod · 0.80
mutableDataMethod · 0.80
channelByTypeMethod · 0.80
numberOfChannelsMethod · 0.45
lengthMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected