@@ -98,19 +98,19 @@ class Voice {
9898 // /
9999 // / @tparam kOscMode Oscillator mode.
100100 // / @tparam kSliceMode Slice mode.
101+ // / @param kIsSidechainSend Denotes whether the sidechain frame is for send or receive.
101102 // / @param voice Voice.
102103 // / @param params Instrument parameters.
103104 // / @param delay_frame Delay send frame.
104105 // / @param sidechain_frame Sidechain send frame.
105- // / @param is_sidechain_send Denotes whether the sidechain frame is for send or receive.
106106 // / @param output_frame Output frame.
107- template <OscMode kOscMode , SliceMode kSliceMode >
107+ template <OscMode kOscMode , SliceMode kSliceMode , bool kIsSidechainSend >
108108 static void Process (Voice& voice, const InstrumentParams& params,
109109 float delay_frame[kStereoChannelCount ],
110- float sidechain_frame[kStereoChannelCount ], bool is_sidechain_send,
110+ float sidechain_frame[kStereoChannelCount ],
111111 float output_frame[kStereoChannelCount ]) noexcept {
112- voice.Process <kOscMode , kSliceMode >(params, delay_frame, sidechain_frame, is_sidechain_send ,
113- output_frame);
112+ voice.Process <kOscMode , kSliceMode , kIsSidechainSend >(params, delay_frame, sidechain_frame,
113+ output_frame);
114114 }
115115
116116 // / Returns whether the voice is currently active (i.e., playing).
@@ -161,15 +161,24 @@ class Voice {
161161 void set_slice (const Slice* slice) noexcept { slice_ = slice; }
162162
163163 private:
164- template <OscMode kOscMode , SliceMode kSliceMode >
164+ template <OscMode kOscMode , SliceMode kSliceMode , bool kIsSidechainSend >
165165 void Process (const InstrumentParams& params, float delay_frame[kStereoChannelCount ],
166- float sidechain_frame[kStereoChannelCount ], bool is_sidechain_send,
166+ float sidechain_frame[kStereoChannelCount ],
167167 float output_frame[kStereoChannelCount ]) noexcept {
168- if (!IsActive () || ((is_sidechain_send && params_.sidechain_send <= 0 .0f ) ||
169- (!is_sidechain_send && params_.sidechain_send > 0 .0f ))) {
168+ if (!IsActive ()) {
170169 return ;
171170 }
172171
172+ if constexpr (kIsSidechainSend ) {
173+ if (params_.sidechain_send <= 0 .0f ) {
174+ return ;
175+ }
176+ } else {
177+ if (params_.sidechain_send > 0 .0f ) {
178+ return ;
179+ }
180+ }
181+
173182 if constexpr (kSliceMode == SliceMode::kOnce ) {
174183 if (!IsSliceActive ()) {
175184 envelope_.Stop ();
@@ -234,13 +243,15 @@ class Voice {
234243 float left_output = left_gain * output;
235244 float right_output = right_gain * output;
236245
237- if (is_sidechain_send ) {
246+ if constexpr ( kIsSidechainSend ) {
238247 sidechain_frame[0 ] += params_.sidechain_send * left_output;
239248 sidechain_frame[1 ] += params_.sidechain_send * right_output;
240- } else if (params_.sidechain_send < 0 .0f ) {
241- const float sidechain_send = -params_.sidechain_send ;
242- left_output = std::lerp (left_output, sidechain_frame[0 ] * left_output, sidechain_send);
243- right_output = std::lerp (right_output, sidechain_frame[1 ] * right_output, sidechain_send);
249+ } else {
250+ if (params_.sidechain_send < 0 .0f ) {
251+ const float sidechain_send = -params_.sidechain_send ;
252+ left_output = std::lerp (left_output, sidechain_frame[0 ] * left_output, sidechain_send);
253+ right_output = std::lerp (right_output, sidechain_frame[1 ] * right_output, sidechain_send);
254+ }
244255 }
245256
246257 delay_frame[0 ] += params_.delay_send * left_output;
@@ -296,11 +307,10 @@ class Voice {
296307// / @param params Instrument parameters.
297308// / @param delay_frame Delay send frame.
298309// / @param sidechain_frame Sidechain send frame.
299- // / @param is_sidechain_send Denotes whether the sidechain frame is for send or receive.
300310// / @param output_frame Output frame.
301311using VoiceCallback = void (*)(Voice& voice, const InstrumentParams& params,
302312 float delay_frame[kStereoChannelCount ],
303- float sidechain_frame[kStereoChannelCount ], bool is_sidechain_send,
313+ float sidechain_frame[kStereoChannelCount ],
304314 float output_frame[kStereoChannelCount ]);
305315
306316} // namespace barely
0 commit comments