summaryrefslogtreecommitdiffstats
path: root/src/audio_core/command_generator.h
blob: 6cba70ae3d1592e92210bf070efe9b9438fec69b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Copyright 2020 yuzu Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.

#pragma once

#include <array>
#include "audio_core/common.h"
#include "audio_core/voice_context.h"
#include "common/common_types.h"

namespace Core::Memory {
class Memory;
}

namespace AudioCore {
class MixContext;
class SplitterContext;
class ServerSplitterDestinationData;
class ServerMixInfo;
class EffectContext;
class EffectBase;
struct AuxInfoDSP;
using MixVolumeBuffer = std::array<float, AudioCommon::MAX_MIX_BUFFERS>;

class CommandGenerator {
public:
    explicit CommandGenerator(AudioCommon::AudioRendererParameter& worker_params,
                              VoiceContext& voice_context, MixContext& mix_context,
                              SplitterContext& splitter_context, EffectContext& effect_context,
                              Core::Memory::Memory& memory);
    ~CommandGenerator();

    void ClearMixBuffers();
    void GenerateVoiceCommands();
    void GenerateVoiceCommand(ServerVoiceInfo& voice_info);
    void GenerateSubMixCommands();
    void GenerateFinalMixCommands();
    void PreCommand();
    void PostCommand();

    s32* GetChannelMixBuffer(s32 channel);
    const s32* GetChannelMixBuffer(s32 channel) const;
    s32* GetMixBuffer(std::size_t index);
    const s32* GetMixBuffer(std::size_t index) const;
    std::size_t GetMixChannelBufferOffset(s32 channel) const;

    std::size_t GetTotalMixBufferCount() const;

private:
    void GenerateDataSourceCommand(ServerVoiceInfo& voice_info, VoiceState& dsp_state, s32 channel);
    void GenerateBiquadFilterCommandForVoice(ServerVoiceInfo& voice_info, VoiceState& dsp_state,
                                             u32 mix_buffer_count, s32 channel);
    void GenerateVolumeRampCommand(float last_volume, float current_volume, s32 channel,
                                   s32 node_id);
    void GenerateVoiceMixCommand(const MixVolumeBuffer& mix_volumes,
                                 const MixVolumeBuffer& last_mix_volumes, VoiceState& dsp_state,
                                 u32 mix_buffer_offset, u32 mix_buffer_count, u32 voice_index,
                                 s32 node_id);
    void GenerateSubMixCommand(ServerMixInfo& mix_info);
    void GenerateMixCommands(ServerMixInfo& mix_info);
    void GenerateMixCommand(std::size_t output_offset, std::size_t input_offset, float volume,
                            s32 node_id);
    void GenerateFinalMixCommand();
    void GenerateBiquadFilterCommand(s32 mix_buffer, const BiquadFilterParameter& params,
                                     std::array<s64, 2>& state, std::size_t input_offset,
                                     std::size_t output_offset, s32 sample_count, s32 node_id);
    void GenerateDepopPrepareCommand(VoiceState& dsp_state, std::size_t mix_buffer_count,
                                     std::size_t mix_buffer_offset);
    void GenerateDepopForMixBuffersCommand(std::size_t mix_buffer_count,
                                           std::size_t mix_buffer_offset, s32 sample_rate);
    void GenerateEffectCommand(ServerMixInfo& mix_info);
    void GenerateI3dl2ReverbEffectCommand(s32 mix_buffer_offset, EffectBase* info, bool enabled);
    void GenerateBiquadFilterEffectCommand(s32 mix_buffer_offset, EffectBase* info, bool enabled);
    void GenerateAuxCommand(s32 mix_buffer_offset, EffectBase* info, bool enabled);
    ServerSplitterDestinationData* GetDestinationData(s32 splitter_id, s32 index);

    s32 WriteAuxBuffer(AuxInfoDSP& dsp_info, VAddr send_buffer, u32 max_samples, const s32* data,
                       u32 sample_count, u32 write_offset, u32 write_count);
    s32 ReadAuxBuffer(AuxInfoDSP& recv_info, VAddr recv_buffer, u32 max_samples, s32* out_data,
                      u32 sample_count, u32 read_offset, u32 read_count);

    // DSP Code
    s32 DecodePcm16(ServerVoiceInfo& voice_info, VoiceState& dsp_state, s32 sample_count,
                    s32 channel, std::size_t mix_offset);
    s32 DecodeAdpcm(ServerVoiceInfo& voice_info, VoiceState& dsp_state, s32 sample_count,
                    s32 channel, std::size_t mix_offset);
    void DecodeFromWaveBuffers(ServerVoiceInfo& voice_info, s32* output, VoiceState& dsp_state,
                               s32 channel, s32 target_sample_rate, s32 sample_count, s32 node_id);

    AudioCommon::AudioRendererParameter& worker_params;
    VoiceContext& voice_context;
    MixContext& mix_context;
    SplitterContext& splitter_context;
    EffectContext& effect_context;
    Core::Memory::Memory& memory;
    std::vector<s32> mix_buffer{};
    std::vector<s32> sample_buffer{};
    std::vector<s32> depop_buffer{};
    bool dumping_frame{false};
};
} // namespace AudioCore