aboutsummaryrefslogtreecommitdiffstats
path: root/alc/buffer_storage.h
blob: 60770184db6e1a37385ed74bd9b5a85bbdbd76c3 (plain)
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
#ifndef ALC_BUFFER_STORAGE_H
#define ALC_BUFFER_STORAGE_H

#include <atomic>

#include "albyte.h"
#include "almalloc.h"
#include "vector.h"


using uint = unsigned int;

/* Storable formats */
enum FmtType : unsigned char {
    FmtUByte,
    FmtShort,
    FmtFloat,
    FmtDouble,
    FmtMulaw,
    FmtAlaw,
};
enum FmtChannels : unsigned char {
    FmtMono,
    FmtStereo,
    FmtRear,
    FmtQuad,
    FmtX51, /* (WFX order) */
    FmtX61, /* (WFX order) */
    FmtX71, /* (WFX order) */
    FmtBFormat2D,
    FmtBFormat3D,
};

enum class AmbiLayout : unsigned char {
    FuMa,
    ACN,
};
enum class AmbiScaling : unsigned char {
    FuMa,
    SN3D,
    N3D,
};

uint BytesFromFmt(FmtType type) noexcept;
uint ChannelsFromFmt(FmtChannels chans, uint ambiorder) noexcept;
inline uint FrameSizeFromFmt(FmtChannels chans, FmtType type, uint ambiorder) noexcept
{ return ChannelsFromFmt(chans, ambiorder) * BytesFromFmt(type); }


using CallbackType = int(*)(void*, void*, int);

struct BufferStorage {
    al::vector<al::byte,16> mData;

    CallbackType mCallback{nullptr};
    void *mUserData{nullptr};

    uint mSampleRate{0u};
    FmtChannels mChannels{};
    FmtType mType{};
    uint mSampleLen{0u};

    AmbiLayout mAmbiLayout{AmbiLayout::FuMa};
    AmbiScaling mAmbiScaling{AmbiScaling::FuMa};
    uint mAmbiOrder{0u};

    uint mLoopStart{0u};
    uint mLoopEnd{0u};

    inline uint bytesFromFmt() const noexcept { return BytesFromFmt(mType); }
    inline uint channelsFromFmt() const noexcept
    { return ChannelsFromFmt(mChannels, mAmbiOrder); }
    inline uint frameSizeFromFmt() const noexcept { return channelsFromFmt() * bytesFromFmt(); }

    inline bool isBFormat() const noexcept
    { return mChannels == FmtBFormat2D || mChannels == FmtBFormat3D; }
};


struct BufferlistItem {
    std::atomic<BufferlistItem*> mNext{nullptr};
    uint mSampleLen{0u};
    BufferStorage *mBuffer{nullptr};

    DEF_NEWDEL(BufferlistItem)
};

#endif /* ALC_BUFFER_STORAGE_H */