~aleteoryx/muditaos

ref: bf75470a3529d520ba378ed1574ed813faf48825 muditaos/module-bsp/board/rt1051/bsp/audio/Codec.hpp -rw-r--r-- 2.3 KiB
bf75470a — Tomasz Rybarski [BH-1354] Fix Text Duplications 3 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
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#ifndef PUREPHONE_CODEC_HPP
#define PUREPHONE_CODEC_HPP

#include <memory>
#include <optional>

class CodecParams
{
  public:
    enum class SampleRate
    {
        Rate8KHz   = 8000,
        Rate16KHz  = 16000,
        Rate44K1Hz = 44100,
        Rate48KHz  = 48000,
        Rate32KHz  = 32000,
        Rate96KHz  = 96000,
        Invalid
    };

    enum class Cmd
    {
        SetOutVolume,
        SetInGain,
        SetMute,
        SetOutput,
        SetInput,
        Reset,
        MicBiasCtrl,
        None
    };

    static SampleRate ValToSampleRate(uint32_t rate)
    {
        switch (rate) {
        case 8000:
            return SampleRate ::Rate8KHz;
        case 16000:
            return SampleRate::Rate16KHz;
        case 32000:
            return SampleRate::Rate32KHz;
        case 44100:
            return SampleRate::Rate44K1Hz;
        case 48000:
            return SampleRate::Rate48KHz;
        case 96000:
            return SampleRate::Rate96KHz;
        default:
            return SampleRate ::Invalid;
        }
    }

    uint32_t GetSampleRateVal()
    {
        switch (sampleRate) {
        case SampleRate::Rate8KHz:
            return 8000;
        case SampleRate::Rate16KHz:
            return 16000;
        case SampleRate::Rate32KHz:
            return 32000;
        case SampleRate::Rate44K1Hz:
            return 44100;
        case SampleRate::Rate48KHz:
            return 48000;
        case SampleRate::Rate96KHz:
            return 96000;
        default:
            return 0;
        }
    }

    Cmd opCmd             = Cmd::None;
    float outVolume       = 0;
    float inGain          = 0;
    SampleRate sampleRate = SampleRate ::Rate44K1Hz;
};

enum class CodecRetCode
{
    Success,
    InvalidSampleRate,
    InvalidInputPath,
    InvalidOutputPath,
    InvalidArgument
};

class Codec
{
  public:
    virtual ~Codec() = default;

    virtual std::optional<uint32_t> Probe() = 0;

    virtual CodecRetCode Start(const CodecParams &param) = 0;

    virtual CodecRetCode Pause() = 0;

    virtual CodecRetCode Resume() = 0;

    virtual CodecRetCode Stop() = 0;

    virtual CodecRetCode Ioctrl(const CodecParams &param) = 0;
};

#endif // PUREPHONE_CODEC_HPP