diff --git a/libraries/audio/src/AudioSRC.cpp b/libraries/audio/src/AudioSRC.cpp index 625f45e9aec..84cc72622d1 100644 --- a/libraries/audio/src/AudioSRC.cpp +++ b/libraries/audio/src/AudioSRC.cpp @@ -963,6 +963,8 @@ void AudioSRC::convertOutput(float** inputs, int16_t* output, int numFrames) { } else if (_numChannels == 2) { + __m128 d8 = _mm_set1_ps(8.0f); + __m128 m7 = _mm_set1_ps(7.0f / 8.0f); int i = 0; for (; i < numFrames - 3; i += 4) { __m128 f0 = _mm_mul_ps(_mm_loadu_ps(&inputs[0][i]), scale); @@ -972,6 +974,10 @@ void AudioSRC::convertOutput(float** inputs, int16_t* output, int numFrames) { f0 = _mm_add_ps(f0, d0); f1 = _mm_add_ps(f1, d0); + // blend left and right slightly to make headphones less painful to use + f0 = _mm_add_ps(_mm_mul_ps(f0, m7), _mm_div_ps(f1, d8)); + f1 = _mm_add_ps(_mm_mul_ps(f1, m7), _mm_div_ps(f0, d8)); + // round and saturate __m128i a0 = _mm_cvtps_epi32(f0); __m128i a1 = _mm_cvtps_epi32(f1); @@ -1243,6 +1249,10 @@ void AudioSRC::convertOutput(float** inputs, int16_t* output, int numFrames) { f0 += d; f1 += d; + // blend left and right slightly to make headphones less painful to use + f0 = f0 * (7.0f / 8.0f) + f1 / 8.0f; + f1 = f1 * (7.0f / 8.0f) + f0 / 8.0f; + // round and saturate f0 += (f0 < 0.0f ? -0.5f : +0.5f); f1 += (f1 < 0.0f ? -0.5f : +0.5f);