Skip to content

Instantly share code, notes, and snippets.

@Xenakios
Created May 4, 2026 21:13
Show Gist options
  • Select an option

  • Save Xenakios/1a533c36e100be2c0058e91429c4029f to your computer and use it in GitHub Desktop.

Select an option

Save Xenakios/1a533c36e100be2c0058e91429c4029f to your computer and use it in GitHub Desktop.
#define USE_AVX2_AMBIS
#ifdef USE_AVX2_AMBIS
// Process 8 channels at a time using AVX
int chan = 0;
for (; chan <= num_outputchans - 8; chan += 8)
{
// Load 8 ambisonics coefficients for each source
__m256 coeffs0 = _mm256_load_ps(&ambcoeffs[chan]); // coeffs for outsample0
__m256 coeffs1 = _mm256_load_ps(&ambcoeffs[chan + 64]); // coeffs for outsample1
// Broadcast the scalar audio samples across all 8 lanes
__m256 sample0 = _mm256_set1_ps(outsample0);
__m256 sample1 = _mm256_set1_ps(outsample1);
// Multiply-accumulate: sample * coefficients
__m256 result =
_mm256_fmadd_ps(sample0, coeffs0, // outsample0 * coeffs0
_mm256_mul_ps(sample1, coeffs1)); // + outsample1 * coeffs1
// Store results into the output buffer
_mm256_store_ps(&outputs[i * 64 + chan], result);
}
// Scalar fallback for any remaining channels (if num_outputchans isn't a multiple of 8)
for (; chan < num_outputchans; ++chan)
{
outputs[i * 64 + chan] =
outsample0 * ambcoeffs[chan] + outsample1 * ambcoeffs[chan + 64];
}
#else
// Teemun alkuperäinen koodi
for (int chan = 0; chan < num_outputchans; ++chan)
{
outputs[i * 64 + chan] = 0.0f;
outputs[i * 64 + chan] += outsample0 * ambcoeffs[chan];
outputs[i * 64 + chan] += outsample1 * ambcoeffs[chan + 64];
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment