summaryrefslogtreecommitdiffstats
path: root/src/audio_core/renderer/splitter/splitter_info.h
blob: c1e4c2df1bd4a4db1088811ba18e19d44a364496 (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
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include "audio_core/renderer/splitter/splitter_destinations_data.h"
#include "common/common_types.h"

namespace AudioCore::Renderer {
/**
 * Represents a splitter, wraps multiple output destinations to split an input mix into.
 */
class SplitterInfo {
public:
    struct InParameter {
        /* 0x00 */ u32 magic; // 'SNDI'
        /* 0x04 */ s32 id;
        /* 0x08 */ u32 sample_rate;
        /* 0x0C */ u32 destination_count;
    };
    static_assert(sizeof(InParameter) == 0x10, "SplitterInfo::InParameter has the wrong size!");

    explicit SplitterInfo(s32 id);

    /**
     * Initialize the given splitters.
     *
     * @param splitters - Splitters to initialize.
     * @param count     - Number of splitters given.
     */
    static void InitializeInfos(SplitterInfo* splitters, u32 count);

    /**
     * Update this splitter.
     *
     * @param params - Input parameters to update with.
     * @return The size in bytes of this splitter.
     */
    u32 Update(const InParameter* params);

    /**
     * Get a destination in this splitter.
     *
     * @param id - Destination id to get.
     * @return Pointer to the destination, may be nullptr.
     */
    SplitterDestinationData* GetData(u32 id);

    /**
     * Get the number of destinations in this splitter.
     *
     * @return The number of destinations.
     */
    u32 GetDestinationCount() const;

    /**
     * Set the number of destinations in this splitter.
     *
     * @param count - The new number of destinations.
     */
    void SetDestinationCount(u32 count);

    /**
     * Check if the splitter has a new connection.
     *
     * @return True if there is a new connection, otherwise false.
     */
    bool HasNewConnection() const;

    /**
     * Reset the new connection flag.
     */
    void ClearNewConnectionFlag();

    /**
     * Mark as having a new connection.
     */
    void SetNewConnectionFlag();

    /**
     * Update the state of all destinations.
     */
    void UpdateInternalState();

    /**
     * Set this splitter's destinations.
     *
     * @param destinations - The new destination list for this splitter.
     */
    void SetDestinations(SplitterDestinationData* destinations);

private:
    /// Id of this splitter
    s32 id;
    /// Sample rate of this splitter
    u32 sample_rate{};
    /// Number of destinations in this splitter
    u32 destination_count{};
    /// Does this splitter have a new connection?
    bool has_new_connection{true};
    /// Pointer to the destinations of this splitter
    SplitterDestinationData* destinations{};
    /// Number of channels this splitter manages
    u32 channel_count{};
};

} // namespace AudioCore::Renderer