Files
Xenia-Canary/src/xenia/apu/conversion.h
Joel Linn cd631fc447 [APU, SDL] Refactor sample submission
- Move sample conversion to SDL callback thread
- Add early channel down-conversion
2021-06-12 18:57:39 +03:00

54 lines
2.1 KiB
C++

/**
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2021 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#ifndef XENIA_APU_CONVERSION_H_
#define XENIA_APU_CONVERSION_H_
#include <cstdint>
#include "xenia/base/byte_order.h"
namespace xe {
namespace apu {
namespace conversion {
inline void sequential_6_BE_to_interleaved_6_LE(float* output,
const float* input,
size_t ch_sample_count) {
for (size_t sample = 0; sample < ch_sample_count; sample++) {
for (size_t channel = 0; channel < 6; channel++) {
output[sample * 6 + channel] =
xe::byte_swap(input[channel * ch_sample_count + sample]);
}
}
}
inline void sequential_6_BE_to_interleaved_2_LE(float* output,
const float* input,
size_t ch_sample_count) {
// Default 5.1 channel mapping is fl, fr, fc, lf, bl, br
// https://docs.microsoft.com/en-us/windows/win32/xaudio2/xaudio2-default-channel-mapping
for (size_t sample = 0; sample < ch_sample_count; sample++) {
// put center on left and right, discard low frequency
float fl = xe::byte_swap(input[0 * ch_sample_count + sample]);
float fr = xe::byte_swap(input[1 * ch_sample_count + sample]);
float fc = xe::byte_swap(input[2 * ch_sample_count + sample]);
float br = xe::byte_swap(input[4 * ch_sample_count + sample]);
float bl = xe::byte_swap(input[5 * ch_sample_count + sample]);
float center_halved = fc * 0.5f;
output[sample * 2] = (fl + bl + center_halved) * (1.0f / 2.5f);
output[sample * 2 + 1] = (fr + br + center_halved) * (1.0f / 2.5f);
}
}
} // namespace conversion
} // namespace apu
} // namespace xe
#endif