cellAudio: make master volume dynamic

This commit is contained in:
Megamouse 2020-05-30 12:43:00 +02:00
parent 3e2aede85c
commit 99895471ae
2 changed files with 11 additions and 11 deletions

View file

@ -775,6 +775,8 @@ void cell_audio_thread::mix(float *out_buffer, s32 offset)
bool first_mix = true; bool first_mix = true;
const float master_volume = g_cfg.audio.volume / 100.0f;
// mixing // mixing
for (auto& port : ports) for (auto& port : ports)
{ {
@ -782,13 +784,12 @@ void cell_audio_thread::mix(float *out_buffer, s32 offset)
auto buf = port.get_vm_ptr(offset); auto buf = port.get_vm_ptr(offset);
static const float k = 1.f; static const float k = 1.f;
static const float minus_3db = 0.707f; /* value taken from static const float minus_3db = 0.707f; // value taken from https://www.dolby.com/us/en/technologies/a-guide-to-dolby-metadata.pdf
https://www.dolby.com/us/en/technologies/a-guide-to-dolby-metadata.pdf */ float m = master_volume;
float& m = port.level;
// part of cellAudioSetPortLevel functionality // part of cellAudioSetPortLevel functionality
// spread port volume changes over 13ms // spread port volume changes over 13ms
auto step_volume = [](audio_port& port) auto step_volume = [master_volume, &m](audio_port& port)
{ {
const auto param = port.level_set.load(); const auto param = port.level_set.load();
@ -803,6 +804,8 @@ void cell_audio_thread::mix(float *out_buffer, s32 offset)
port.level_set.compare_and_swap(param, { param.value, 0.0f }); port.level_set.compare_and_swap(param, { param.value, 0.0f });
} }
} }
m = port.level * master_volume;
}; };
if (port.num_channels == 2) if (port.num_channels == 2)
@ -864,8 +867,7 @@ void cell_audio_thread::mix(float *out_buffer, s32 offset)
if constexpr (DownmixToStereo) if constexpr (DownmixToStereo)
{ {
const float mid = center * minus_3db; /* don't mix in the lfe as per const float mid = center * minus_3db; // don't mix in the lfe as per dolby specification
dolby specification */
out_buffer[out + 0] = (left + rear_left + (side_left * minus_3db) + mid) * k; out_buffer[out + 0] = (left + rear_left + (side_left * minus_3db) + mid) * k;
out_buffer[out + 1] = (right + rear_right + (side_right * minus_3db) + mid) * k; out_buffer[out + 1] = (right + rear_right + (side_right * minus_3db) + mid) * k;
} }
@ -1104,11 +1106,11 @@ error_code cellAudioPortOpen(vm::ptr<CellAudioPortParam> audioParam, vm::ptr<u32
if (attr & CELL_AUDIO_PORTATTR_INITLEVEL) if (attr & CELL_AUDIO_PORTATTR_INITLEVEL)
{ {
port->level = audioParam->level * g_cfg.audio.volume / 100.0f; port->level = audioParam->level;
} }
else else
{ {
port->level = g_cfg.audio.volume / 100.0f; port->level = 1.0f;
} }
port->level_set.store({ port->level, 0.0f }); port->level_set.store({ port->level, 0.0f });
@ -1333,8 +1335,6 @@ error_code cellAudioSetPortLevel(u32 portNum, float level)
return CELL_AUDIO_ERROR_PORT_NOT_OPEN; return CELL_AUDIO_ERROR_PORT_NOT_OPEN;
} }
level *= g_cfg.audio.volume / 100.0f;
if (level >= 0.0f) if (level >= 0.0f)
{ {
port.level_set.exchange({ level, (port.level - level) / 624.0f }); port.level_set.exchange({ level, (port.level - level) / 624.0f });

View file

@ -219,7 +219,7 @@ struct cfg_root : cfg::node
cfg::_bool convert_to_u16{ this, "Convert to 16 bit" }; cfg::_bool convert_to_u16{ this, "Convert to 16 bit" };
cfg::_bool downmix_to_2ch{ this, "Downmix to Stereo", true }; cfg::_bool downmix_to_2ch{ this, "Downmix to Stereo", true };
cfg::_int<1, 128> startt{ this, "Start Threshold", 1 }; // TODO: used only by ALSA, should probably be removed once ALSA is upgraded cfg::_int<1, 128> startt{ this, "Start Threshold", 1 }; // TODO: used only by ALSA, should probably be removed once ALSA is upgraded
cfg::_int<0, 200> volume{ this, "Master Volume", 100 }; cfg::_int<0, 200> volume{ this, "Master Volume", 100, true };
cfg::_bool enable_buffering{ this, "Enable Buffering", true }; cfg::_bool enable_buffering{ this, "Enable Buffering", true };
cfg::_int <4, 250> desired_buffer_duration{ this, "Desired Audio Buffer Duration", 100 }; cfg::_int <4, 250> desired_buffer_duration{ this, "Desired Audio Buffer Duration", 100 };
cfg::_int<1, 1000> sampling_period_multiplier{ this, "Sampling Period Multiplier", 100 }; cfg::_int<1, 1000> sampling_period_multiplier{ this, "Sampling Period Multiplier", 100 };