blob: 138ab2773d1922eb4b2f26dd06b0765cd27e7a57 (
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <span>
#include "audio_core/renderer/voice/voice_channel_resource.h"
#include "audio_core/renderer/voice/voice_info.h"
#include "audio_core/renderer/voice/voice_state.h"
#include "common/common_types.h"
namespace AudioCore::Renderer {
/**
* Contains all voices, with utility functions for managing them.
*/
class VoiceContext {
public:
/**
* Get the AudioRenderer state for a given index
*
* @param index - State index to get.
* @return The requested voice state.
*/
VoiceState& GetDspSharedState(u32 index);
/**
* Get the channel resource for a given index
*
* @param index - Resource index to get.
* @return The requested voice resource.
*/
VoiceChannelResource& GetChannelResource(u32 index);
/**
* Initialize the voice context.
*
* @param sorted_voice_infos - Workbuffer for the sorted voices.
* @param voice_infos - Workbuffer for the voices.
* @param voice_channel_resources - Workbuffer for the voice channel resources.
* @param cpu_states - Workbuffer for the host-side voice states.
* @param dsp_states - Workbuffer for the AudioRenderer-side voice states.
* @param voice_count - The number of voices in each workbuffer.
*/
void Initialize(std::span<VoiceInfo*> sorted_voice_infos, std::span<VoiceInfo> voice_infos,
std::span<VoiceChannelResource> voice_channel_resources,
std::span<VoiceState> cpu_states, std::span<VoiceState> dsp_states,
u32 voice_count);
/**
* Get a sorted voice with the given index.
*
* @param index - The sorted voice index to get.
* @return The sorted voice.
*/
VoiceInfo* GetSortedInfo(u32 index);
/**
* Get a voice with the given index.
*
* @param index - The voice index to get.
* @return The voice.
*/
VoiceInfo& GetInfo(u32 index);
/**
* Get a host voice state with the given index.
*
* @param index - The host voice state index to get.
* @return The voice state.
*/
VoiceState& GetState(u32 index);
/**
* Get the maximum number of voices.
* Not all voices in the buffers may be in use, see GetActiveCount.
*
* @return The maximum number of voices.
*/
u32 GetCount() const;
/**
* Get the number of active voices.
* Can be less than or equal to the maximum number of voices.
*
* @return The number of active voices.
*/
u32 GetActiveCount() const;
/**
* Set the number of active voices.
* Can be less than or equal to the maximum number of voices.
*
* @param active_count - The new number of active voices.
*/
void SetActiveCount(u32 active_count);
/**
* Sort all voices. Results are available via GetSortedInfo.
* Voices are sorted descendingly, according to priority, and then sort order.
*/
void SortInfo();
/**
* Update all voice states, copying AudioRenderer-side states to host-side states.
*/
void UpdateStateByDspShared();
private:
/// Sorted voices
std::span<VoiceInfo*> sorted_voice_info{};
/// Voices
std::span<VoiceInfo> voices{};
/// Channel resources
std::span<VoiceChannelResource> channel_resources{};
/// Host-side voice states
std::span<VoiceState> cpu_states{};
/// AudioRenderer-side voice states
std::span<VoiceState> dsp_states{};
/// Maximum number of voices
u32 voice_count{};
/// Number of active voices
u32 active_count{};
};
} // namespace AudioCore::Renderer
|