2020-07-12 11:59:14 +00:00
|
|
|
// Copyright 2020 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2020-07-25 02:32:05 +00:00
|
|
|
#include <algorithm>
|
2020-07-12 11:59:14 +00:00
|
|
|
#include "audio_core/effect_context.h"
|
|
|
|
|
|
|
|
namespace AudioCore {
|
2020-08-16 15:23:55 +00:00
|
|
|
namespace {
|
|
|
|
bool ValidChannelCountForEffect(s32 channel_count) {
|
|
|
|
return channel_count == 1 || channel_count == 2 || channel_count == 4 || channel_count == 6;
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2020-11-25 20:21:03 +00:00
|
|
|
EffectContext::EffectContext(std::size_t effect_count_) : effect_count(effect_count_) {
|
2020-07-25 02:32:05 +00:00
|
|
|
effects.reserve(effect_count);
|
|
|
|
std::generate_n(std::back_inserter(effects), effect_count,
|
|
|
|
[] { return std::make_unique<EffectStubbed>(); });
|
2020-07-12 11:59:14 +00:00
|
|
|
}
|
|
|
|
EffectContext::~EffectContext() = default;
|
|
|
|
|
|
|
|
std::size_t EffectContext::GetCount() const {
|
|
|
|
return effect_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
EffectBase* EffectContext::GetInfo(std::size_t i) {
|
|
|
|
return effects.at(i).get();
|
|
|
|
}
|
|
|
|
|
2020-08-16 15:23:55 +00:00
|
|
|
EffectBase* EffectContext::RetargetEffect(std::size_t i, EffectType effect) {
|
|
|
|
switch (effect) {
|
|
|
|
case EffectType::Invalid:
|
|
|
|
effects[i] = std::make_unique<EffectStubbed>();
|
|
|
|
break;
|
|
|
|
case EffectType::BufferMixer:
|
|
|
|
effects[i] = std::make_unique<EffectBufferMixer>();
|
|
|
|
break;
|
|
|
|
case EffectType::Aux:
|
|
|
|
effects[i] = std::make_unique<EffectAuxInfo>();
|
|
|
|
break;
|
|
|
|
case EffectType::Delay:
|
|
|
|
effects[i] = std::make_unique<EffectDelay>();
|
|
|
|
break;
|
|
|
|
case EffectType::Reverb:
|
|
|
|
effects[i] = std::make_unique<EffectReverb>();
|
|
|
|
break;
|
|
|
|
case EffectType::I3dl2Reverb:
|
|
|
|
effects[i] = std::make_unique<EffectI3dl2Reverb>();
|
|
|
|
break;
|
|
|
|
case EffectType::BiquadFilter:
|
|
|
|
effects[i] = std::make_unique<EffectBiquadFilter>();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
UNREACHABLE_MSG("Unimplemented effect {}", effect);
|
|
|
|
effects[i] = std::make_unique<EffectStubbed>();
|
|
|
|
}
|
|
|
|
return GetInfo(i);
|
|
|
|
}
|
|
|
|
|
2020-07-25 02:32:05 +00:00
|
|
|
const EffectBase* EffectContext::GetInfo(std::size_t i) const {
|
|
|
|
return effects.at(i).get();
|
|
|
|
}
|
|
|
|
|
2020-11-25 20:21:03 +00:00
|
|
|
EffectStubbed::EffectStubbed() : EffectBase(EffectType::Invalid) {}
|
2020-07-12 11:59:14 +00:00
|
|
|
EffectStubbed::~EffectStubbed() = default;
|
|
|
|
|
2020-11-25 20:21:03 +00:00
|
|
|
void EffectStubbed::Update([[maybe_unused]] EffectInfo::InParams& in_params) {}
|
2020-08-16 15:23:55 +00:00
|
|
|
void EffectStubbed::UpdateForCommandGeneration() {}
|
2020-07-12 11:59:14 +00:00
|
|
|
|
2020-11-25 20:21:03 +00:00
|
|
|
EffectBase::EffectBase(EffectType effect_type_) : effect_type(effect_type_) {}
|
2020-07-12 11:59:14 +00:00
|
|
|
EffectBase::~EffectBase() = default;
|
|
|
|
|
2020-08-16 15:23:55 +00:00
|
|
|
UsageState EffectBase::GetUsage() const {
|
2020-07-12 11:59:14 +00:00
|
|
|
return usage;
|
|
|
|
}
|
|
|
|
|
2020-08-16 15:23:55 +00:00
|
|
|
EffectType EffectBase::GetType() const {
|
|
|
|
return effect_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EffectBase::IsEnabled() const {
|
|
|
|
return enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
s32 EffectBase::GetMixID() const {
|
|
|
|
return mix_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
s32 EffectBase::GetProcessingOrder() const {
|
|
|
|
return processing_order;
|
|
|
|
}
|
|
|
|
|
2020-11-25 20:21:03 +00:00
|
|
|
EffectI3dl2Reverb::EffectI3dl2Reverb() : EffectGeneric(EffectType::I3dl2Reverb) {}
|
2020-08-16 15:23:55 +00:00
|
|
|
EffectI3dl2Reverb::~EffectI3dl2Reverb() = default;
|
|
|
|
|
|
|
|
void EffectI3dl2Reverb::Update(EffectInfo::InParams& in_params) {
|
2020-11-25 20:21:03 +00:00
|
|
|
auto& params = GetParams();
|
2020-08-16 15:23:55 +00:00
|
|
|
const auto* reverb_params = reinterpret_cast<I3dl2ReverbParams*>(in_params.raw.data());
|
|
|
|
if (!ValidChannelCountForEffect(reverb_params->max_channels)) {
|
|
|
|
UNREACHABLE_MSG("Invalid reverb max channel count {}", reverb_params->max_channels);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-11-25 20:21:03 +00:00
|
|
|
const auto last_status = params.status;
|
2020-08-16 15:23:55 +00:00
|
|
|
mix_id = in_params.mix_id;
|
|
|
|
processing_order = in_params.processing_order;
|
2020-11-25 20:21:03 +00:00
|
|
|
params = *reverb_params;
|
2020-08-16 15:23:55 +00:00
|
|
|
if (!ValidChannelCountForEffect(reverb_params->channel_count)) {
|
2020-11-25 20:21:03 +00:00
|
|
|
params.channel_count = params.max_channels;
|
2020-08-16 15:23:55 +00:00
|
|
|
}
|
|
|
|
enabled = in_params.is_enabled;
|
|
|
|
if (last_status != ParameterStatus::Updated) {
|
2020-11-25 20:21:03 +00:00
|
|
|
params.status = last_status;
|
2020-08-16 15:23:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (in_params.is_new || skipped) {
|
|
|
|
usage = UsageState::Initialized;
|
2020-11-25 20:21:03 +00:00
|
|
|
params.status = ParameterStatus::Initialized;
|
2020-08-16 15:23:55 +00:00
|
|
|
skipped = in_params.buffer_address == 0 || in_params.buffer_size == 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EffectI3dl2Reverb::UpdateForCommandGeneration() {
|
|
|
|
if (enabled) {
|
|
|
|
usage = UsageState::Running;
|
|
|
|
} else {
|
|
|
|
usage = UsageState::Stopped;
|
|
|
|
}
|
|
|
|
GetParams().status = ParameterStatus::Updated;
|
|
|
|
}
|
|
|
|
|
2020-11-25 20:21:03 +00:00
|
|
|
EffectBiquadFilter::EffectBiquadFilter() : EffectGeneric(EffectType::BiquadFilter) {}
|
2020-08-16 15:23:55 +00:00
|
|
|
EffectBiquadFilter::~EffectBiquadFilter() = default;
|
|
|
|
|
|
|
|
void EffectBiquadFilter::Update(EffectInfo::InParams& in_params) {
|
2020-11-25 20:21:03 +00:00
|
|
|
auto& params = GetParams();
|
2020-08-16 15:23:55 +00:00
|
|
|
const auto* biquad_params = reinterpret_cast<BiquadFilterParams*>(in_params.raw.data());
|
|
|
|
mix_id = in_params.mix_id;
|
|
|
|
processing_order = in_params.processing_order;
|
2020-11-25 20:21:03 +00:00
|
|
|
params = *biquad_params;
|
2020-08-16 15:23:55 +00:00
|
|
|
enabled = in_params.is_enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EffectBiquadFilter::UpdateForCommandGeneration() {
|
|
|
|
if (enabled) {
|
|
|
|
usage = UsageState::Running;
|
|
|
|
} else {
|
|
|
|
usage = UsageState::Stopped;
|
|
|
|
}
|
|
|
|
GetParams().status = ParameterStatus::Updated;
|
|
|
|
}
|
|
|
|
|
2020-11-25 20:21:03 +00:00
|
|
|
EffectAuxInfo::EffectAuxInfo() : EffectGeneric(EffectType::Aux) {}
|
2020-08-16 15:23:55 +00:00
|
|
|
EffectAuxInfo::~EffectAuxInfo() = default;
|
|
|
|
|
|
|
|
void EffectAuxInfo::Update(EffectInfo::InParams& in_params) {
|
|
|
|
const auto* aux_params = reinterpret_cast<AuxInfo*>(in_params.raw.data());
|
|
|
|
mix_id = in_params.mix_id;
|
|
|
|
processing_order = in_params.processing_order;
|
|
|
|
GetParams() = *aux_params;
|
|
|
|
enabled = in_params.is_enabled;
|
|
|
|
|
|
|
|
if (in_params.is_new || skipped) {
|
|
|
|
skipped = aux_params->send_buffer_info == 0 || aux_params->return_buffer_info == 0;
|
|
|
|
if (skipped) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// There's two AuxInfos which are an identical size, the first one is managed by the cpu,
|
|
|
|
// the second is managed by the dsp. All we care about is managing the DSP one
|
|
|
|
send_info = aux_params->send_buffer_info + sizeof(AuxInfoDSP);
|
|
|
|
send_buffer = aux_params->send_buffer_info + (sizeof(AuxInfoDSP) * 2);
|
|
|
|
|
|
|
|
recv_info = aux_params->return_buffer_info + sizeof(AuxInfoDSP);
|
|
|
|
recv_buffer = aux_params->return_buffer_info + (sizeof(AuxInfoDSP) * 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EffectAuxInfo::UpdateForCommandGeneration() {
|
|
|
|
if (enabled) {
|
|
|
|
usage = UsageState::Running;
|
|
|
|
} else {
|
|
|
|
usage = UsageState::Stopped;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-25 04:28:35 +00:00
|
|
|
VAddr EffectAuxInfo::GetSendInfo() const {
|
2020-08-16 15:23:55 +00:00
|
|
|
return send_info;
|
|
|
|
}
|
|
|
|
|
2020-09-25 04:28:35 +00:00
|
|
|
VAddr EffectAuxInfo::GetSendBuffer() const {
|
2020-08-16 15:23:55 +00:00
|
|
|
return send_buffer;
|
|
|
|
}
|
|
|
|
|
2020-09-25 04:28:35 +00:00
|
|
|
VAddr EffectAuxInfo::GetRecvInfo() const {
|
2020-08-16 15:23:55 +00:00
|
|
|
return recv_info;
|
|
|
|
}
|
|
|
|
|
2020-09-25 04:28:35 +00:00
|
|
|
VAddr EffectAuxInfo::GetRecvBuffer() const {
|
2020-08-16 15:23:55 +00:00
|
|
|
return recv_buffer;
|
|
|
|
}
|
|
|
|
|
2020-11-25 20:21:03 +00:00
|
|
|
EffectDelay::EffectDelay() : EffectGeneric(EffectType::Delay) {}
|
2020-08-16 15:23:55 +00:00
|
|
|
EffectDelay::~EffectDelay() = default;
|
|
|
|
|
|
|
|
void EffectDelay::Update(EffectInfo::InParams& in_params) {
|
|
|
|
const auto* delay_params = reinterpret_cast<DelayParams*>(in_params.raw.data());
|
2020-11-25 20:21:03 +00:00
|
|
|
auto& params = GetParams();
|
2020-08-16 15:23:55 +00:00
|
|
|
if (!ValidChannelCountForEffect(delay_params->max_channels)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-11-25 20:21:03 +00:00
|
|
|
const auto last_status = params.status;
|
2020-08-16 15:23:55 +00:00
|
|
|
mix_id = in_params.mix_id;
|
|
|
|
processing_order = in_params.processing_order;
|
2020-11-25 20:21:03 +00:00
|
|
|
params = *delay_params;
|
2020-08-16 15:23:55 +00:00
|
|
|
if (!ValidChannelCountForEffect(delay_params->channels)) {
|
2020-11-25 20:21:03 +00:00
|
|
|
params.channels = params.max_channels;
|
2020-08-16 15:23:55 +00:00
|
|
|
}
|
|
|
|
enabled = in_params.is_enabled;
|
|
|
|
|
|
|
|
if (last_status != ParameterStatus::Updated) {
|
2020-11-25 20:21:03 +00:00
|
|
|
params.status = last_status;
|
2020-08-16 15:23:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (in_params.is_new || skipped) {
|
|
|
|
usage = UsageState::Initialized;
|
2020-11-25 20:21:03 +00:00
|
|
|
params.status = ParameterStatus::Initialized;
|
2020-08-16 15:23:55 +00:00
|
|
|
skipped = in_params.buffer_address == 0 || in_params.buffer_size == 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EffectDelay::UpdateForCommandGeneration() {
|
|
|
|
if (enabled) {
|
|
|
|
usage = UsageState::Running;
|
|
|
|
} else {
|
|
|
|
usage = UsageState::Stopped;
|
|
|
|
}
|
|
|
|
GetParams().status = ParameterStatus::Updated;
|
|
|
|
}
|
|
|
|
|
2020-11-25 20:21:03 +00:00
|
|
|
EffectBufferMixer::EffectBufferMixer() : EffectGeneric(EffectType::BufferMixer) {}
|
2020-08-16 15:23:55 +00:00
|
|
|
EffectBufferMixer::~EffectBufferMixer() = default;
|
|
|
|
|
|
|
|
void EffectBufferMixer::Update(EffectInfo::InParams& in_params) {
|
|
|
|
mix_id = in_params.mix_id;
|
|
|
|
processing_order = in_params.processing_order;
|
|
|
|
GetParams() = *reinterpret_cast<BufferMixerParams*>(in_params.raw.data());
|
|
|
|
enabled = in_params.is_enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EffectBufferMixer::UpdateForCommandGeneration() {
|
|
|
|
if (enabled) {
|
|
|
|
usage = UsageState::Running;
|
|
|
|
} else {
|
|
|
|
usage = UsageState::Stopped;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-25 20:21:03 +00:00
|
|
|
EffectReverb::EffectReverb() : EffectGeneric(EffectType::Reverb) {}
|
2020-08-16 15:23:55 +00:00
|
|
|
EffectReverb::~EffectReverb() = default;
|
|
|
|
|
|
|
|
void EffectReverb::Update(EffectInfo::InParams& in_params) {
|
|
|
|
const auto* reverb_params = reinterpret_cast<ReverbParams*>(in_params.raw.data());
|
2020-11-25 20:21:03 +00:00
|
|
|
auto& params = GetParams();
|
2020-08-16 15:23:55 +00:00
|
|
|
if (!ValidChannelCountForEffect(reverb_params->max_channels)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-11-25 20:21:03 +00:00
|
|
|
const auto last_status = params.status;
|
2020-08-16 15:23:55 +00:00
|
|
|
mix_id = in_params.mix_id;
|
|
|
|
processing_order = in_params.processing_order;
|
2020-11-25 20:21:03 +00:00
|
|
|
params = *reverb_params;
|
2020-08-16 15:23:55 +00:00
|
|
|
if (!ValidChannelCountForEffect(reverb_params->channels)) {
|
2020-11-25 20:21:03 +00:00
|
|
|
params.channels = params.max_channels;
|
2020-08-16 15:23:55 +00:00
|
|
|
}
|
|
|
|
enabled = in_params.is_enabled;
|
|
|
|
|
|
|
|
if (last_status != ParameterStatus::Updated) {
|
2020-11-25 20:21:03 +00:00
|
|
|
params.status = last_status;
|
2020-08-16 15:23:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (in_params.is_new || skipped) {
|
|
|
|
usage = UsageState::Initialized;
|
2020-11-25 20:21:03 +00:00
|
|
|
params.status = ParameterStatus::Initialized;
|
2020-08-16 15:23:55 +00:00
|
|
|
skipped = in_params.buffer_address == 0 || in_params.buffer_size == 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EffectReverb::UpdateForCommandGeneration() {
|
|
|
|
if (enabled) {
|
|
|
|
usage = UsageState::Running;
|
|
|
|
} else {
|
|
|
|
usage = UsageState::Stopped;
|
|
|
|
}
|
|
|
|
GetParams().status = ParameterStatus::Updated;
|
|
|
|
}
|
|
|
|
|
2020-07-12 11:59:14 +00:00
|
|
|
} // namespace AudioCore
|