~aleteoryx/muditaos

ref: a3e512a89b698b4d8a8f8046521c327ab2eec147 muditaos/module-audio/Audio/Profiles/Profile.hpp -rw-r--r-- 3.4 KiB
a3e512a8 — Marcin Smoczyński [EGD-6674] Change negotiation of audio block size 4 years ago
                                                                                
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
127
128
129
130
131
132
133
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include "Audio/AudioDevice.hpp"

#include <memory>
#include <functional>
#include <string>

namespace audio
{
    using Volume      = uint32_t;
    using Gain        = uint32_t;
    using Position    = float;
    using Vibrate     = bool;
    using EnableSound = bool;

    class Profile
    {
      public:
        enum class Type
        {
            // Profiles used only during call
            RoutingLoudspeaker,
            RoutingHeadphones,
            RoutingEarspeaker,
            RoutingBluetoothHSP,

            // Recording profiles
            RecordingBuiltInMic,
            RecordingHeadphones,
            RecordingBluetoothHSP,

            // Profiles used by music player
            PlaybackLoudspeaker,
            PlaybackHeadphones,
            PlaybackBluetoothA2DP,

            Idle,

        };

        static std::unique_ptr<Profile> Create(const Type t,
                                               std::optional<Volume> vol = 0,
                                               std::optional<Gain> gain  = 0);

        void SetOutputVolume(Volume vol);

        void SetInputGain(Gain gain);

        void SetInOutFlags(uint32_t flags);

        void SetSampleRate(uint32_t samplerate);

        void SetOutputPath(AudioDevice::OutputPath path);

        void SetInputPath(AudioDevice::InputPath path);

        Volume GetOutputVolume() const
        {
            return audioConfiguration.outputVolume;
        }

        Gain GetInputGain() const
        {
            return audioConfiguration.inputGain;
        }

        uint32_t GetSampleRate()
        {
            return audioConfiguration.sampleRate_Hz;
        }

        uint32_t GetInOutFlags()
        {
            return audioConfiguration.flags;
        }

        AudioDevice::OutputPath GetOutputPath() const
        {
            return audioConfiguration.outputPath;
        }

        AudioDevice::InputPath GetInputPath() const
        {
            return audioConfiguration.inputPath;
        }

        AudioDevice::Type GetAudioDeviceType() const
        {
            return audioDeviceType;
        }

        [[deprecated]] AudioDevice::Configuration GetAudioConfiguration()
        {
            return audioConfiguration;
        }

        auto getAudioFormat() const noexcept
        {
            auto isStereo = (audioConfiguration.flags & static_cast<uint32_t>(AudioDevice::Flags::OutputStereo)) != 0 ||
                            (audioConfiguration.flags & static_cast<uint32_t>(AudioDevice::Flags::InputStereo)) != 0;
            auto channels = isStereo ? 2U : 1U;
            return AudioFormat(audioConfiguration.sampleRate_Hz, audioConfiguration.bitWidth, channels);
        }

        const std::string &GetName() const
        {
            return name;
        }

        Type GetType() const
        {
            return type;
        }

      protected:
        Profile(const std::string &name,
                const Type type,
                const AudioDevice::Configuration &fmt,
                AudioDevice::Type devType);

        AudioDevice::Configuration audioConfiguration{};
        AudioDevice::Type audioDeviceType = AudioDevice::Type::Audiocodec;

        std::string name;
        Type type = Type::Idle;
    };

    [[nodiscard]] const std::string str(const Profile::Type &profileType);
} // namespace audio