Mixing buffers of varying sample rates into an output buffer

I want to mix:

  • an arbitrary number of (arbitrarily sized) input buffers of (possibly) different sample rates
  • into an output buffer with a set target sample rate (the global one).
    (Doesn’t need to meet real-time requirements, so I would prefer quality over performance.)

My idea was to…

  • find the highest sample rate among all available buffers
  • find the highest sample count
  • calculate the required size of the output buffer
    (highestNumSamples / highestSampleRate * targetSampleRate?)
  • loop over my list of input buffers and add each one to the output buffer

But I’m unsure about the order, when resampling and sample addition should happen… :thinking:

  • upsample each input buffer (if needed) to the highest sample rate first, then add them to the output buffer, and then (if needed) resample the whole output buffer to the target sample rate?
  • OR immediately resample the input buffer to the target sample rate first, and then add its samples to the output buffer?

Which approach is better in avoiding phase issues and aliasing?

If resampling is required, I would just apply that IIR Halfband Lowpass (only if downsampling?) and use one of JUCE’s Interpolators (Windowed Sinc / Lagrange / CatmullRom / Linear / ZeroOrderHold ?).

Would this work? Or do you know a better way?
Preferably a quick&easy approach without external libraries.