summaryrefslogtreecommitdiffstats
path: root/src/audio_core/out/audio_out.cpp
blob: d3ee4f0ebc9f0fb053218d667a080f8dc7d61cbc (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
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#include "audio_core/audio_out_manager.h"
#include "audio_core/out/audio_out.h"
#include "core/hle/kernel/k_event.h"

namespace AudioCore::AudioOut {

Out::Out(Core::System& system_, Manager& manager_, Kernel::KEvent* event_, size_t session_id_)
    : manager{manager_}, parent_mutex{manager.mutex}, event{event_}, system{system_, event,
                                                                            session_id_} {}

void Out::Free() {
    std::scoped_lock l{parent_mutex};
    manager.ReleaseSessionId(system.GetSessionId());
}

System& Out::GetSystem() {
    return system;
}

AudioOut::State Out::GetState() {
    std::scoped_lock l{parent_mutex};
    return system.GetState();
}

Result Out::StartSystem() {
    std::scoped_lock l{parent_mutex};
    return system.Start();
}

void Out::StartSession() {
    std::scoped_lock l{parent_mutex};
    system.StartSession();
}

Result Out::StopSystem() {
    std::scoped_lock l{parent_mutex};
    return system.Stop();
}

Result Out::AppendBuffer(const AudioOutBuffer& buffer, const u64 tag) {
    std::scoped_lock l{parent_mutex};

    if (system.AppendBuffer(buffer, tag)) {
        return ResultSuccess;
    }
    return Service::Audio::ERR_BUFFER_COUNT_EXCEEDED;
}

void Out::ReleaseAndRegisterBuffers() {
    std::scoped_lock l{parent_mutex};
    if (system.GetState() == State::Started) {
        system.ReleaseBuffers();
        system.RegisterBuffers();
    }
}

bool Out::FlushAudioOutBuffers() {
    std::scoped_lock l{parent_mutex};
    return system.FlushAudioOutBuffers();
}

u32 Out::GetReleasedBuffers(std::span<u64> tags) {
    std::scoped_lock l{parent_mutex};
    return system.GetReleasedBuffers(tags);
}

Kernel::KReadableEvent& Out::GetBufferEvent() {
    std::scoped_lock l{parent_mutex};
    return event->GetReadableEvent();
}

f32 Out::GetVolume() const {
    std::scoped_lock l{parent_mutex};
    return system.GetVolume();
}

void Out::SetVolume(const f32 volume) {
    std::scoped_lock l{parent_mutex};
    system.SetVolume(volume);
}

bool Out::ContainsAudioBuffer(const u64 tag) const {
    std::scoped_lock l{parent_mutex};
    return system.ContainsAudioBuffer(tag);
}

u32 Out::GetBufferCount() const {
    std::scoped_lock l{parent_mutex};
    return system.GetBufferCount();
}

u64 Out::GetPlayedSampleCount() const {
    std::scoped_lock l{parent_mutex};
    return system.GetPlayedSampleCount();
}

} // namespace AudioCore::AudioOut