@@ -279,13 +279,13 @@ class AudioBuffer
279279 constexpr void sumAll (const AudioBuffer& b, int framesToCopy, int srcOffset, int destOffset,
280280 float gain = 1 .0f )
281281 {
282- mergeAll<Operation::SUM>(b, framesToCopy, srcOffset, destOffset, gain);
282+ mergeAll<Operation::SUM>(b, framesToCopy, srcOffset, destOffset, gain, std::array< float , 0 >{} );
283283 }
284284
285285 constexpr void setAll (const AudioBuffer& b, int framesToCopy, int srcOffset, int destOffset,
286286 float gain = 1 .0f )
287287 {
288- mergeAll<Operation::SET>(b, framesToCopy, srcOffset, destOffset, gain);
288+ mergeAll<Operation::SET>(b, framesToCopy, srcOffset, destOffset, gain, std::array< float , 0 >{} );
289289 }
290290
291291 /* ---------------------------------------------------------------------- */
@@ -296,12 +296,31 @@ class AudioBuffer
296296
297297 constexpr void sumAll (const AudioBuffer& b, float gain = 1 .0f )
298298 {
299- mergeAll<Operation::SUM>(b, b.countFrames (), 0 , 0 , gain);
299+ mergeAll<Operation::SUM>(b, b.countFrames (), 0 , 0 , gain, std::array< float , 0 >{} );
300300 }
301301
302302 constexpr void setAll (const AudioBuffer& b, float gain = 1 .0f )
303303 {
304- mergeAll<Operation::SET>(b, b.countFrames (), 0 , 0 , gain);
304+ mergeAll<Operation::SET>(b, b.countFrames (), 0 , 0 , gain, std::array<float , 0 >{});
305+ }
306+
307+ /* ---------------------------------------------------------------------- */
308+
309+ /* sumAll, setAll (2)
310+ Same as sumAll, setAll (2) with an extra 'pan' parameter, to apply panning
311+ to the destination buffer (aka this one) while merging data. Note: the
312+ pan array must have exactly countChannels() element in it. */
313+
314+ template <std::size_t panSize>
315+ constexpr void sumAll (const AudioBuffer& b, std::array<float , panSize> pan, float gain = 1 .0f )
316+ {
317+ mergeAll<Operation::SUM>(b, b.countFrames (), 0 , 0 , gain, pan);
318+ }
319+
320+ template <std::size_t panSize>
321+ constexpr void setAll (const AudioBuffer& b, std::array<float , panSize> pan, float gain = 1 .0f )
322+ {
323+ mergeAll<Operation::SET>(b, b.countFrames (), 0 , 0 , gain, pan);
305324 }
306325
307326 /* ---------------------------------------------------------------------- */
@@ -409,18 +428,22 @@ class AudioBuffer
409428
410429 /* ---------------------------------------------------------------------- */
411430
412- template <Operation O>
431+ template <Operation O, std:: size_t PanSize >
413432 constexpr void mergeAll (const AudioBuffer& b, int framesToCopy, int srcOffset, int destOffset,
414- float gain)
433+ float gain, std::array< float , PanSize> pan )
415434 {
435+ if constexpr (PanSize > 0 )
436+ assert (pan.size () == countChannels ());
437+
416438 for (int destCh = 0 , srcCh = 0 ; destCh < countChannels (); destCh++, srcCh++)
417439 {
418440 if (srcCh == b.countChannels ())
419441 srcCh = 0 ;
442+ const float chanGain = pan.size () == 0 ? gain : gain * pan[destCh];
420443 if constexpr (O == Operation::SUM)
421- sum (b, framesToCopy, srcOffset, destOffset, srcCh, destCh, gain );
444+ sum (b, framesToCopy, srcOffset, destOffset, srcCh, destCh, chanGain );
422445 else
423- set (b, framesToCopy, srcOffset, destOffset, srcCh, destCh, gain );
446+ set (b, framesToCopy, srcOffset, destOffset, srcCh, destCh, chanGain );
424447 }
425448 }
426449
0 commit comments