mirror of
https://github.com/RPCS3/rpcs3.git
synced 2024-11-22 18:53:28 +01:00
cellAudio: simplify sound mixer
There was no need to treat the first mix differently if all it did was init the buffer anyway. Let's just always memset to zero.
This commit is contained in:
parent
7530b3c971
commit
fd8931c87e
@ -892,10 +892,11 @@ void cell_audio_thread::mix(float *out_buffer, s32 offset)
|
||||
constexpr u32 channels = static_cast<u32>(downmix);
|
||||
constexpr u32 out_buffer_sz = channels * AUDIO_BUFFER_SAMPLES;
|
||||
|
||||
bool first_mix = true;
|
||||
|
||||
const float master_volume = g_cfg.audio.volume / 100.0f;
|
||||
|
||||
// Reset out_buffer
|
||||
std::memset(out_buffer, 0, out_buffer_sz * sizeof(float));
|
||||
|
||||
// mixing
|
||||
for (auto& port : ports)
|
||||
{
|
||||
@ -928,36 +929,6 @@ void cell_audio_thread::mix(float *out_buffer, s32 offset)
|
||||
};
|
||||
|
||||
if (port.num_channels == 2)
|
||||
{
|
||||
if (first_mix)
|
||||
{
|
||||
for (u32 out = 0, in = 0; out < out_buffer_sz; out += channels, in += 2)
|
||||
{
|
||||
step_volume(port);
|
||||
|
||||
const float left = buf[in + 0] * m;
|
||||
const float right = buf[in + 1] * m;
|
||||
|
||||
out_buffer[out + 0] = left;
|
||||
out_buffer[out + 1] = right;
|
||||
|
||||
if constexpr (downmix != AudioChannelCnt::STEREO)
|
||||
{
|
||||
out_buffer[out + 2] = 0.0f;
|
||||
out_buffer[out + 3] = 0.0f;
|
||||
out_buffer[out + 4] = 0.0f;
|
||||
out_buffer[out + 5] = 0.0f;
|
||||
|
||||
if constexpr (downmix != AudioChannelCnt::SURROUND_5_1)
|
||||
{
|
||||
out_buffer[out + 6] = 0.0f;
|
||||
out_buffer[out + 7] = 0.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
first_mix = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (u32 out = 0, in = 0; out < out_buffer_sz; out += channels, in += 2)
|
||||
{
|
||||
@ -970,56 +941,7 @@ void cell_audio_thread::mix(float *out_buffer, s32 offset)
|
||||
out_buffer[out + 1] += right;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (port.num_channels == 8)
|
||||
{
|
||||
if (first_mix)
|
||||
{
|
||||
for (u32 out = 0, in = 0; out < out_buffer_sz; out += channels, in += 8)
|
||||
{
|
||||
step_volume(port);
|
||||
|
||||
const float left = buf[in + 0] * m;
|
||||
const float right = buf[in + 1] * m;
|
||||
const float center = buf[in + 2] * m;
|
||||
[[maybe_unused]]
|
||||
const float low_freq = buf[in + 3] * m;
|
||||
const float side_left = buf[in + 4] * m;
|
||||
const float side_right = buf[in + 5] * m;
|
||||
const float rear_left = buf[in + 6] * m;
|
||||
const float rear_right = buf[in + 7] * m;
|
||||
|
||||
if constexpr (downmix == AudioChannelCnt::STEREO)
|
||||
{
|
||||
// Don't mix in the lfe as per dolby specification and based on documentation
|
||||
const float mid = center * 0.5f;
|
||||
out_buffer[out + 0] = left * minus_3db + mid + side_left * 0.5f + rear_left * 0.5f;
|
||||
out_buffer[out + 1] = right * minus_3db + mid + side_right * 0.5f + rear_right * 0.5f;
|
||||
}
|
||||
else if constexpr (downmix == AudioChannelCnt::SURROUND_5_1)
|
||||
{
|
||||
out_buffer[out + 0] = left;
|
||||
out_buffer[out + 1] = right;
|
||||
out_buffer[out + 2] = center;
|
||||
out_buffer[out + 3] = low_freq;
|
||||
out_buffer[out + 4] = side_left + rear_left;
|
||||
out_buffer[out + 5] = side_right + rear_right;
|
||||
}
|
||||
else
|
||||
{
|
||||
out_buffer[out + 0] = left;
|
||||
out_buffer[out + 1] = right;
|
||||
out_buffer[out + 2] = center;
|
||||
out_buffer[out + 3] = low_freq;
|
||||
out_buffer[out + 4] = rear_left;
|
||||
out_buffer[out + 5] = rear_right;
|
||||
out_buffer[out + 6] = side_left;
|
||||
out_buffer[out + 7] = side_right;
|
||||
}
|
||||
}
|
||||
first_mix = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (u32 out = 0, in = 0; out < out_buffer_sz; out += channels, in += 8)
|
||||
{
|
||||
@ -1063,18 +985,11 @@ void cell_audio_thread::mix(float *out_buffer, s32 offset)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fmt::throw_exception("Unknown channel count (port=%u, channel=%d)", port.number, port.num_channels);
|
||||
}
|
||||
}
|
||||
|
||||
// Nothing was mixed, memset out_buffer to 0
|
||||
if (first_mix)
|
||||
{
|
||||
std::memset(out_buffer, 0, out_buffer_sz * sizeof(float));
|
||||
}
|
||||
}
|
||||
|
||||
void cell_audio_thread::finish_port_volume_stepping()
|
||||
|
Loading…
Reference in New Issue
Block a user