summaryrefslogtreecommitdiffstats
path: root/src/audio_core/hle/mixers.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/audio_core/hle/mixers.cpp')
-rw-r--r--src/audio_core/hle/mixers.cpp65
1 files changed, 38 insertions, 27 deletions
diff --git a/src/audio_core/hle/mixers.cpp b/src/audio_core/hle/mixers.cpp
index 18335f7f0..a661a7b27 100644
--- a/src/audio_core/hle/mixers.cpp
+++ b/src/audio_core/hle/mixers.cpp
@@ -20,11 +20,9 @@ void Mixers::Reset() {
state = {};
}
-DspStatus Mixers::Tick(DspConfiguration& config,
- const IntermediateMixSamples& read_samples,
- IntermediateMixSamples& write_samples,
- const std::array<QuadFrame32, 3>& input)
-{
+DspStatus Mixers::Tick(DspConfiguration& config, const IntermediateMixSamples& read_samples,
+ IntermediateMixSamples& write_samples,
+ const std::array<QuadFrame32, 3>& input) {
ParseConfig(config);
AuxReturn(read_samples);
@@ -73,13 +71,15 @@ void Mixers::ParseConfig(DspConfiguration& config) {
if (config.output_format_dirty) {
config.output_format_dirty.Assign(0);
state.output_format = config.output_format;
- LOG_TRACE(Audio_DSP, "mixers output_format = %zu", static_cast<size_t>(config.output_format));
+ LOG_TRACE(Audio_DSP, "mixers output_format = %zu",
+ static_cast<size_t>(config.output_format));
}
if (config.headphones_connected_dirty) {
config.headphones_connected_dirty.Assign(0);
// Do nothing.
- // (Note: Whether headphones are connected does affect coefficients used for surround sound.)
+ // (Note: Whether headphones are connected does affect coefficients used for surround
+ // sound.)
LOG_TRACE(Audio_DSP, "mixers headphones_connected=%hu", config.headphones_connected);
}
@@ -94,11 +94,10 @@ static s16 ClampToS16(s32 value) {
return static_cast<s16>(MathUtil::Clamp(value, -32768, 32767));
}
-static std::array<s16, 2> AddAndClampToS16(const std::array<s16, 2>& a, const std::array<s16, 2>& b) {
- return {
- ClampToS16(static_cast<s32>(a[0]) + static_cast<s32>(b[0])),
- ClampToS16(static_cast<s32>(a[1]) + static_cast<s32>(b[1]))
- };
+static std::array<s16, 2> AddAndClampToS16(const std::array<s16, 2>& a,
+ const std::array<s16, 2>& b) {
+ return {ClampToS16(static_cast<s32>(a[0]) + static_cast<s32>(b[0])),
+ ClampToS16(static_cast<s32>(a[1]) + static_cast<s32>(b[1]))};
}
void Mixers::DownmixAndMixIntoCurrentFrame(float gain, const QuadFrame32& samples) {
@@ -106,27 +105,33 @@ void Mixers::DownmixAndMixIntoCurrentFrame(float gain, const QuadFrame32& sample
switch (state.output_format) {
case OutputFormat::Mono:
- std::transform(current_frame.begin(), current_frame.end(), samples.begin(), current_frame.begin(),
- [gain](const std::array<s16, 2>& accumulator, const std::array<s32, 4>& sample) -> std::array<s16, 2> {
+ std::transform(
+ current_frame.begin(), current_frame.end(), samples.begin(), current_frame.begin(),
+ [gain](const std::array<s16, 2>& accumulator,
+ const std::array<s32, 4>& sample) -> std::array<s16, 2> {
// Downmix to mono
- s16 mono = ClampToS16(static_cast<s32>((gain * sample[0] + gain * sample[1] + gain * sample[2] + gain * sample[3]) / 2));
+ s16 mono = ClampToS16(static_cast<s32>(
+ (gain * sample[0] + gain * sample[1] + gain * sample[2] + gain * sample[3]) /
+ 2));
// Mix into current frame
- return AddAndClampToS16(accumulator, { mono, mono });
+ return AddAndClampToS16(accumulator, {mono, mono});
});
return;
case OutputFormat::Surround:
- // TODO(merry): Implement surround sound.
- // fallthrough
+ // TODO(merry): Implement surround sound.
+ // fallthrough
case OutputFormat::Stereo:
- std::transform(current_frame.begin(), current_frame.end(), samples.begin(), current_frame.begin(),
- [gain](const std::array<s16, 2>& accumulator, const std::array<s32, 4>& sample) -> std::array<s16, 2> {
+ std::transform(
+ current_frame.begin(), current_frame.end(), samples.begin(), current_frame.begin(),
+ [gain](const std::array<s16, 2>& accumulator,
+ const std::array<s32, 4>& sample) -> std::array<s16, 2> {
// Downmix to stereo
s16 left = ClampToS16(static_cast<s32>(gain * sample[0] + gain * sample[2]));
s16 right = ClampToS16(static_cast<s32>(gain * sample[1] + gain * sample[3]));
// Mix into current frame
- return AddAndClampToS16(accumulator, { left, right });
+ return AddAndClampToS16(accumulator, {left, right});
});
return;
}
@@ -135,12 +140,14 @@ void Mixers::DownmixAndMixIntoCurrentFrame(float gain, const QuadFrame32& sample
}
void Mixers::AuxReturn(const IntermediateMixSamples& read_samples) {
- // NOTE: read_samples.mix{1,2}.pcm32 annoyingly have their dimensions in reverse order to QuadFrame32.
+ // NOTE: read_samples.mix{1,2}.pcm32 annoyingly have their dimensions in reverse order to
+ // QuadFrame32.
if (state.mixer1_enabled) {
for (size_t sample = 0; sample < samples_per_frame; sample++) {
for (size_t channel = 0; channel < 4; channel++) {
- state.intermediate_mix_buffer[1][sample][channel] = read_samples.mix1.pcm32[channel][sample];
+ state.intermediate_mix_buffer[1][sample][channel] =
+ read_samples.mix1.pcm32[channel][sample];
}
}
}
@@ -148,14 +155,17 @@ void Mixers::AuxReturn(const IntermediateMixSamples& read_samples) {
if (state.mixer2_enabled) {
for (size_t sample = 0; sample < samples_per_frame; sample++) {
for (size_t channel = 0; channel < 4; channel++) {
- state.intermediate_mix_buffer[2][sample][channel] = read_samples.mix2.pcm32[channel][sample];
+ state.intermediate_mix_buffer[2][sample][channel] =
+ read_samples.mix2.pcm32[channel][sample];
}
}
}
}
-void Mixers::AuxSend(IntermediateMixSamples& write_samples, const std::array<QuadFrame32, 3>& input) {
- // NOTE: read_samples.mix{1,2}.pcm32 annoyingly have their dimensions in reverse order to QuadFrame32.
+void Mixers::AuxSend(IntermediateMixSamples& write_samples,
+ const std::array<QuadFrame32, 3>& input) {
+ // NOTE: read_samples.mix{1,2}.pcm32 annoyingly have their dimensions in reverse order to
+ // QuadFrame32.
state.intermediate_mix_buffer[0] = input[0];
@@ -184,7 +194,8 @@ void Mixers::MixCurrentFrame() {
current_frame.fill({});
for (size_t mix = 0; mix < 3; mix++) {
- DownmixAndMixIntoCurrentFrame(state.intermediate_mixer_volume[mix], state.intermediate_mix_buffer[mix]);
+ DownmixAndMixIntoCurrentFrame(state.intermediate_mixer_volume[mix],
+ state.intermediate_mix_buffer[mix]);
}
// TODO(merry): Compressor. (We currently assume a disabled compressor.)