aboutsummaryrefslogtreecommitdiffstats
path: root/alc/converter.h
blob: d8fe7ba9eba25e3569d8fb0563a5c8183180eed9 (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
#ifndef CONVERTER_H
#define CONVERTER_H

#include <cstddef>
#include <memory>

#include "AL/al.h"

#include "alcmain.h"
#include "almalloc.h"
#include "alnumeric.h"
#include "alu.h"
#include "devformat.h"


struct SampleConverter {
    DevFmtType mSrcType{};
    DevFmtType mDstType{};
    ALuint mSrcTypeSize{};
    ALuint mDstTypeSize{};

    ALint mSrcPrepCount{};

    ALuint mFracOffset{};
    ALuint mIncrement{};
    InterpState mState{};
    ResamplerFunc mResample{};

    alignas(16) ALfloat mSrcSamples[BUFFERSIZE]{};
    alignas(16) ALfloat mDstSamples[BUFFERSIZE]{};

    struct ChanSamples {
        alignas(16) ALfloat PrevSamples[MAX_RESAMPLER_PADDING];
    };
    al::FlexArray<ChanSamples> mChan;

    SampleConverter(size_t numchans) : mChan{numchans} { }

    ALuint convert(const ALvoid **src, ALuint *srcframes, ALvoid *dst, ALuint dstframes);
    ALuint availableOut(ALuint srcframes) const;

    DEF_FAM_NEWDEL(SampleConverter, mChan)
};
using SampleConverterPtr = std::unique_ptr<SampleConverter>;

SampleConverterPtr CreateSampleConverter(DevFmtType srcType, DevFmtType dstType, size_t numchans,
    ALuint srcRate, ALuint dstRate, Resampler resampler);


struct ChannelConverter {
    DevFmtType mSrcType;
    DevFmtChannels mSrcChans;
    DevFmtChannels mDstChans;

    bool is_active() const noexcept { return mSrcChans != mDstChans; }

    void convert(const ALvoid *src, ALfloat *dst, ALuint frames) const;
};

#endif /* CONVERTER_H */