aboutsummaryrefslogtreecommitdiffstats
path: root/core/buffer_storage.cpp
blob: 6ffab124de367b15e6010349575afce70c472809 (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

#include "config.h"

#include "buffer_storage.h"

#include <stdint.h>


const char *NameFromFormat(FmtType type) noexcept
{
    switch(type)
    {
    case FmtUByte: return "UInt8";
    case FmtShort: return "Int16";
    case FmtInt: return "Int32";
    case FmtFloat: return "Float";
    case FmtDouble: return "Double";
    case FmtMulaw: return "muLaw";
    case FmtAlaw: return "aLaw";
    case FmtIMA4: return "IMA4 ADPCM";
    case FmtMSADPCM: return "MS ADPCM";
    }
    return "<internal error>";
}

const char *NameFromFormat(FmtChannels channels) noexcept
{
    switch(channels)
    {
    case FmtMono: return "Mono";
    case FmtStereo: return "Stereo";
    case FmtRear: return "Rear";
    case FmtQuad: return "Quadraphonic";
    case FmtX51: return "Surround 5.1";
    case FmtX61: return "Surround 6.1";
    case FmtX71: return "Surround 7.1";
    case FmtBFormat2D: return "B-Format 2D";
    case FmtBFormat3D: return "B-Format 3D";
    case FmtUHJ2: return "UHJ2";
    case FmtUHJ3: return "UHJ3";
    case FmtUHJ4: return "UHJ4";
    case FmtSuperStereo: return "Super Stereo";
    }
    return "<internal error>";
}

uint BytesFromFmt(FmtType type) noexcept
{
    switch(type)
    {
    case FmtUByte: return sizeof(uint8_t);
    case FmtShort: return sizeof(int16_t);
    case FmtInt: return sizeof(int32_t);
    case FmtFloat: return sizeof(float);
    case FmtDouble: return sizeof(double);
    case FmtMulaw: return sizeof(uint8_t);
    case FmtAlaw: return sizeof(uint8_t);
    case FmtIMA4: break;
    case FmtMSADPCM: break;
    }
    return 0;
}

uint ChannelsFromFmt(FmtChannels chans, uint ambiorder) noexcept
{
    switch(chans)
    {
    case FmtMono: return 1;
    case FmtStereo: return 2;
    case FmtRear: return 2;
    case FmtQuad: return 4;
    case FmtX51: return 6;
    case FmtX61: return 7;
    case FmtX71: return 8;
    case FmtBFormat2D: return (ambiorder*2) + 1;
    case FmtBFormat3D: return (ambiorder+1) * (ambiorder+1);
    case FmtUHJ2: return 2;
    case FmtUHJ3: return 3;
    case FmtUHJ4: return 4;
    case FmtSuperStereo: return 2;
    }
    return 0;
}