cellAudioOut: apply review fixes, add some comments

This commit is contained in:
Megamouse 2022-05-29 13:14:27 +02:00
parent 911d37e4d7
commit 3402835c8e
5 changed files with 28 additions and 26 deletions

View File

@ -100,12 +100,12 @@ void AudioBackend::normalize(u32 sample_cnt, const f32* src, f32* dst)
}
}
AudioChannelCnt AudioBackend::get_channel_count()
AudioChannelCnt AudioBackend::get_channel_count(u32 device_index)
{
audio_out_configuration& audio_out = g_fxo->get<audio_out_configuration>();
std::lock_guard lock(audio_out.mtx);
ensure(!audio_out.out.empty());
audio_out_configuration::audio_out& out = audio_out.out.at(CELL_AUDIO_OUT_PRIMARY);
audio_out_configuration& audio_out_cfg = g_fxo->get<audio_out_configuration>();
std::lock_guard lock(audio_out_cfg.mtx);
ensure(device_index < audio_out_cfg.out.size());
const audio_out_configuration::audio_out& out = audio_out_cfg.out.at(device_index);
switch (out.downmixer)
{

View File

@ -138,7 +138,7 @@ public:
/*
* Returns the channel count based on the downmix mode.
*/
static AudioChannelCnt get_channel_count();
static AudioChannelCnt get_channel_count(u32 device_index);
/*
* Downmix audio stream.

View File

@ -66,7 +66,7 @@ void cell_audio_config::reset(bool backend_changed)
const AudioFreq freq = AudioFreq::FREQ_48K;
const AudioSampleSize sample_size = raw.convert_to_s16 ? AudioSampleSize::S16 : AudioSampleSize::FLOAT;
const AudioChannelCnt ch_cnt = AudioBackend::get_channel_count();
const AudioChannelCnt ch_cnt = AudioBackend::get_channel_count(0); // CELL_AUDIO_OUT_PRIMARY
const f64 cb_frame_len = backend->Open(freq, sample_size, ch_cnt) ? backend->GetCallbackFrameLen() : 0.0;
audio_channels = static_cast<u32>(ch_cnt);

View File

@ -240,6 +240,7 @@ error_code cellAudioOutGetSoundAvailability(u32 audioOut, u32 type, u32 fs, u32
switch (audioOut)
{
case CELL_AUDIO_OUT_PRIMARY: break;
// case CELL_AUDIO_OUT_SECONDARY: break; // TODO: enable if we ever actually support peripheral output
default: return not_an_error(0);
}
@ -248,7 +249,7 @@ error_code cellAudioOutGetSoundAvailability(u32 audioOut, u32 type, u32 fs, u32
// Check if the requested audio parameters are available and find the max supported channel count
audio_out_configuration& cfg = g_fxo->get<audio_out_configuration>();
std::lock_guard lock(cfg.mtx);
audio_out_configuration::audio_out& out = cfg.out.at(audioOut);
const audio_out_configuration::audio_out& out = cfg.out.at(audioOut);
for (const CellAudioOutSoundMode& mode : out.sound_modes)
{
@ -268,13 +269,14 @@ error_code cellAudioOutGetSoundAvailability2(u32 audioOut, u32 type, u32 fs, u32
switch (audioOut)
{
case CELL_AUDIO_OUT_PRIMARY: break;
// case CELL_AUDIO_OUT_SECONDARY: break; // TODO: enable if we ever actually support peripheral output
default: return not_an_error(0);
}
// Check if the requested audio parameters are available
audio_out_configuration& cfg = g_fxo->get<audio_out_configuration>();
std::lock_guard lock(cfg.mtx);
audio_out_configuration::audio_out& out = cfg.out.at(audioOut);
const audio_out_configuration::audio_out& out = cfg.out.at(audioOut);
for (const CellAudioOutSoundMode& mode : out.sound_modes)
{
@ -327,11 +329,11 @@ error_code cellAudioOutGetState(u32 audioOut, u32 deviceIndex, vm::ptr<CellAudio
case CELL_AUDIO_OUT_PRIMARY:
case CELL_AUDIO_OUT_SECONDARY:
{
const AudioChannelCnt channels = AudioBackend::get_channel_count();
const AudioChannelCnt channels = AudioBackend::get_channel_count(audioOut);
audio_out_configuration& cfg = g_fxo->get<audio_out_configuration>();
std::lock_guard lock(cfg.mtx);
audio_out_configuration::audio_out& out = cfg.out.at(audioOut);
const audio_out_configuration::audio_out& out = cfg.out.at(audioOut);
const auto it = std::find_if(out.sound_modes.cbegin(), out.sound_modes.cend(), [&channels, &out](const CellAudioOutSoundMode& mode)
{
@ -368,13 +370,12 @@ error_code cellAudioOutConfigure(u32 audioOut, vm::ptr<CellAudioOutConfiguration
case CELL_AUDIO_OUT_PRIMARY:
break;
case CELL_AUDIO_OUT_SECONDARY:
return CELL_AUDIO_OUT_ERROR_UNSUPPORTED_AUDIO_OUT;
return CELL_AUDIO_OUT_ERROR_UNSUPPORTED_AUDIO_OUT; // TODO: enable if we ever actually support peripheral output
default:
return CELL_AUDIO_OUT_ERROR_ILLEGAL_PARAMETER;
}
audio_out_configuration::audio_out out_old;
audio_out_configuration::audio_out out_new;
bool needs_reset = false;
audio_out_configuration& cfg = g_fxo->get<audio_out_configuration>();
{
@ -390,16 +391,17 @@ error_code cellAudioOutConfigure(u32 audioOut, vm::ptr<CellAudioOutConfiguration
return CELL_AUDIO_OUT_ERROR_ILLEGAL_CONFIGURATION; // TODO: confirm
}
out_old = out;
if (out.channels != config->channel || out.encoder != config->encoder || out.downmixer != config->downMixer)
{
out.channels = config->channel;
out.encoder = config->encoder;
out.downmixer = config->downMixer;
out.channels = config->channel;
out.encoder = config->encoder;
out.downmixer = config->downMixer;
out_new = out;
needs_reset = true;
}
}
if (std::memcmp(&out_old, &out_new, sizeof(audio_out_configuration::audio_out)) != 0)
if (needs_reset)
{
const auto reset_audio = [audioOut]() -> void
{
@ -447,7 +449,7 @@ error_code cellAudioOutGetConfiguration(u32 audioOut, vm::ptr<CellAudioOutConfig
case CELL_AUDIO_OUT_PRIMARY:
break;
case CELL_AUDIO_OUT_SECONDARY:
return CELL_AUDIO_OUT_ERROR_UNSUPPORTED_AUDIO_OUT;
return CELL_AUDIO_OUT_ERROR_UNSUPPORTED_AUDIO_OUT; // TODO: enable if we ever actually support peripheral output
default:
return CELL_AUDIO_OUT_ERROR_ILLEGAL_PARAMETER;
}
@ -457,7 +459,7 @@ error_code cellAudioOutGetConfiguration(u32 audioOut, vm::ptr<CellAudioOutConfig
CellAudioOutConfiguration _config{};
audio_out_configuration::audio_out& out = cfg.out.at(audioOut);
const audio_out_configuration::audio_out& out = cfg.out.at(audioOut);
_config.channel = out.channels;
_config.encoder = out.encoder;
_config.downMixer = out.downmixer;
@ -514,7 +516,7 @@ error_code cellAudioOutGetDeviceInfo(u32 audioOut, u32 deviceIndex, vm::ptr<Cell
audio_out_configuration& cfg = g_fxo->get<audio_out_configuration>();
std::lock_guard lock(cfg.mtx);
ensure(audioOut < cfg.out.size());
audio_out_configuration::audio_out& out = cfg.out.at(audioOut);
const audio_out_configuration::audio_out& out = cfg.out.at(audioOut);
ensure(out.sound_modes.size() <= 16);
CellAudioOutDeviceInfo _info{};
@ -547,7 +549,7 @@ error_code cellAudioOutSetCopyControl(u32 audioOut, u32 control)
case CELL_AUDIO_OUT_PRIMARY:
break;
case CELL_AUDIO_OUT_SECONDARY:
return CELL_AUDIO_OUT_ERROR_UNSUPPORTED_AUDIO_OUT;
return CELL_AUDIO_OUT_ERROR_UNSUPPORTED_AUDIO_OUT; // TODO: enable if we ever actually support peripheral output
default:
return CELL_AUDIO_OUT_ERROR_ILLEGAL_PARAMETER;
}

View File

@ -1322,7 +1322,7 @@ void rsxaudio_backend_thread::update_emu_cfg()
rsxaudio_backend_thread::emu_audio_cfg rsxaudio_backend_thread::get_emu_cfg()
{
const AudioChannelCnt out_ch_cnt = AudioBackend::get_channel_count();
const AudioChannelCnt out_ch_cnt = AudioBackend::get_channel_count(0); // CELL_AUDIO_OUT_PRIMARY
emu_audio_cfg cfg =
{