diff options
author | David Marcec <dmarcecguzman@gmail.com> | 2020-08-16 17:23:55 +0200 |
---|---|---|
committer | David Marcec <dmarcecguzman@gmail.com> | 2020-08-16 17:23:55 +0200 |
commit | 80ac1331b545d993aa7c205dc24f8b20a4d6d44e (patch) | |
tree | f0b1138935e239ff7c5766fc26bc259b375ae712 /src/audio_core/effect_context.h | |
parent | Disable biquad filter (diff) | |
download | yuzu-80ac1331b545d993aa7c205dc24f8b20a4d6d44e.tar yuzu-80ac1331b545d993aa7c205dc24f8b20a4d6d44e.tar.gz yuzu-80ac1331b545d993aa7c205dc24f8b20a4d6d44e.tar.bz2 yuzu-80ac1331b545d993aa7c205dc24f8b20a4d6d44e.tar.lz yuzu-80ac1331b545d993aa7c205dc24f8b20a4d6d44e.tar.xz yuzu-80ac1331b545d993aa7c205dc24f8b20a4d6d44e.tar.zst yuzu-80ac1331b545d993aa7c205dc24f8b20a4d6d44e.zip |
Diffstat (limited to 'src/audio_core/effect_context.h')
-rw-r--r-- | src/audio_core/effect_context.h | 215 |
1 files changed, 211 insertions, 4 deletions
diff --git a/src/audio_core/effect_context.h b/src/audio_core/effect_context.h index e3c367296..2f2da72dd 100644 --- a/src/audio_core/effect_context.h +++ b/src/audio_core/effect_context.h @@ -31,6 +31,19 @@ enum class UsageStatus : u8 { Removed = 4, }; +enum class UsageState { + Invalid = 0, + Initialized = 1, + Running = 2, + Stopped = 3, +}; + +enum class ParameterStatus : u8 { + Initialized = 0, + Updating = 1, + Updated = 2, +}; + struct BufferMixerParams { std::array<s8, AudioCommon::MAX_MIX_BUFFERS> input{}; std::array<s8, AudioCommon::MAX_MIX_BUFFERS> output{}; @@ -39,6 +52,14 @@ struct BufferMixerParams { }; static_assert(sizeof(BufferMixerParams) == 0x94, "BufferMixerParams is an invalid size"); +struct AuxInfoDSP { + u32_le read_offset{}; + u32_le write_offset{}; + u32_le remaining{}; + INSERT_PADDING_WORDS(13); +}; +static_assert(sizeof(AuxInfoDSP) == 0x40, "AuxInfoDSP is an invalid size"); + struct AuxInfo { std::array<s8, AudioCommon::MAX_MIX_BUFFERS> input_mix_buffers{}; std::array<s8, AudioCommon::MAX_MIX_BUFFERS> output_mix_buffers{}; @@ -54,6 +75,81 @@ struct AuxInfo { }; static_assert(sizeof(AuxInfo) == 0x60, "AuxInfo is an invalid size"); +struct I3dl2ReverbParams { + std::array<s8, AudioCommon::MAX_CHANNEL_COUNT> input{}; + std::array<s8, AudioCommon::MAX_CHANNEL_COUNT> output{}; + u16_le max_channels{}; + u16_le channel_count{}; + INSERT_PADDING_BYTES(1); + u32_le sample_rate{}; + f32 room_hf{}; + f32 hf_reference{}; + f32 decay_time{}; + f32 hf_decay_ratio{}; + f32 room{}; + f32 reflection{}; + f32 reverb{}; + f32 diffusion{}; + f32 reflection_delay{}; + f32 reverb_delay{}; + f32 density{}; + f32 dry_gain{}; + ParameterStatus status{}; + INSERT_PADDING_BYTES(3); +}; +static_assert(sizeof(I3dl2ReverbParams) == 0x4c, "I3dl2ReverbParams is an invalid size"); + +struct BiquadFilterParams { + std::array<s8, AudioCommon::MAX_CHANNEL_COUNT> input{}; + std::array<s8, AudioCommon::MAX_CHANNEL_COUNT> output{}; + std::array<s16_le, 3> numerator; + std::array<s16_le, 2> denominator; + s8 channel_count{}; + ParameterStatus status{}; +}; +static_assert(sizeof(BiquadFilterParams) == 0x18, "BiquadFilterParams is an invalid size"); + +struct DelayParams { + std::array<s8, AudioCommon::MAX_CHANNEL_COUNT> input{}; + std::array<s8, AudioCommon::MAX_CHANNEL_COUNT> output{}; + u16_le max_channels{}; + u16_le channels{}; + s32_le max_delay{}; + s32_le delay{}; + s32_le sample_rate{}; + s32_le gain{}; + s32_le feedback_gain{}; + s32_le out_gain{}; + s32_le dry_gain{}; + s32_le channel_spread{}; + s32_le low_pass{}; + ParameterStatus status{}; + INSERT_PADDING_BYTES(3); +}; +static_assert(sizeof(DelayParams) == 0x38, "DelayParams is an invalid size"); + +struct ReverbParams { + std::array<s8, AudioCommon::MAX_CHANNEL_COUNT> input{}; + std::array<s8, AudioCommon::MAX_CHANNEL_COUNT> output{}; + u16_le max_channels{}; + u16_le channels{}; + s32_le sample_rate{}; + s32_le mode0{}; + s32_le mode0_gain{}; + s32_le pre_delay{}; + s32_le mode1{}; + s32_le mode1_gain{}; + s32_le decay{}; + s32_le hf_decay_ratio{}; + s32_le coloration{}; + s32_le reverb_gain{}; + s32_le out_gain{}; + s32_le dry_gain{}; + ParameterStatus status{}; + INSERT_PADDING_BYTES(3); +}; +static_assert(sizeof(ReverbParams) == 0x44, "ReverbParams is an invalid size"); + class EffectInfo { public: struct InParams { @@ -64,7 +160,7 @@ public: s32_le mix_id{}; u64_le buffer_address{}; u64_le buffer_size{}; - s32_le priority{}; + s32_le processing_order{}; INSERT_PADDING_BYTES(4); union { std::array<u8, 0xa0> raw; @@ -79,16 +175,50 @@ public: static_assert(sizeof(EffectInfo::OutParams) == 0x10, "OutParams is an invalid size"); }; +struct AuxAddress { + VAddr send_dsp_info{}; + VAddr send_buffer_base{}; + VAddr return_dsp_info{}; + VAddr return_buffer_base{}; +}; + class EffectBase { public: - EffectBase(); + EffectBase(EffectType effect_type); ~EffectBase(); virtual void Update(EffectInfo::InParams& in_params) = 0; - UsageStatus GetUsage() const; + virtual void UpdateForCommandGeneration() = 0; + UsageState GetUsage() const; + EffectType GetType() const; + bool IsEnabled() const; + s32 GetMixID() const; + s32 GetProcessingOrder() const; protected: - UsageStatus usage{UsageStatus::Invalid}; + UsageState usage{UsageState::Invalid}; + EffectType effect_type{}; + s32 mix_id{}; + s32 processing_order{}; + bool enabled = false; +}; + +template <typename T> +class EffectGeneric : public EffectBase { +public: + EffectGeneric(EffectType effect_type) : EffectBase::EffectBase(effect_type) {} + ~EffectGeneric() = default; + + T& GetParams() { + return internal_params; + } + + const I3dl2ReverbParams& GetParams() const { + return internal_params; + } + +private: + T internal_params{}; }; class EffectStubbed : public EffectBase { @@ -97,6 +227,82 @@ public: ~EffectStubbed(); void Update(EffectInfo::InParams& in_params) override; + void UpdateForCommandGeneration() override; +}; + +class EffectI3dl2Reverb : public EffectGeneric<I3dl2ReverbParams> { +public: + explicit EffectI3dl2Reverb(); + ~EffectI3dl2Reverb(); + + void Update(EffectInfo::InParams& in_params) override; + void UpdateForCommandGeneration() override; + +private: + bool skipped = false; +}; + +class EffectBiquadFilter : public EffectGeneric<BiquadFilterParams> { +public: + explicit EffectBiquadFilter(); + ~EffectBiquadFilter(); + + void Update(EffectInfo::InParams& in_params) override; + void UpdateForCommandGeneration() override; +}; + +class EffectAuxInfo : public EffectGeneric<AuxInfo> { +public: + explicit EffectAuxInfo(); + ~EffectAuxInfo(); + + void Update(EffectInfo::InParams& in_params) override; + void UpdateForCommandGeneration() override; + const VAddr GetSendInfo() const; + const VAddr GetSendBuffer() const; + const VAddr GetRecvInfo() const; + const VAddr GetRecvBuffer() const; + +private: + VAddr send_info{}; + VAddr send_buffer{}; + VAddr recv_info{}; + VAddr recv_buffer{}; + bool skipped = false; + AuxAddress addresses{}; +}; + +class EffectDelay : public EffectGeneric<DelayParams> { +public: + explicit EffectDelay(); + ~EffectDelay(); + + void Update(EffectInfo::InParams& in_params) override; + void UpdateForCommandGeneration() override; + +private: + bool skipped = false; +}; + +class EffectBufferMixer : public EffectGeneric<BufferMixerParams> { +public: + explicit EffectBufferMixer(); + ~EffectBufferMixer(); + + void Update(EffectInfo::InParams& in_params) override; + void UpdateForCommandGeneration() override; +}; + +class EffectReverb : public EffectGeneric<ReverbParams> { +public: + explicit EffectReverb(); + ~EffectReverb(); + + void Update(EffectInfo::InParams& in_params) override; + void UpdateForCommandGeneration() override; + +private: + bool skipped = false; }; class EffectContext { @@ -106,6 +312,7 @@ public: std::size_t GetCount() const; EffectBase* GetInfo(std::size_t i); + EffectBase* RetargetEffect(std::size_t i, EffectType effect); const EffectBase* GetInfo(std::size_t i) const; private: |