Welcome to mirror list, hosted at ThFree Co, Russian Federation.

DspRate.h « src - github.com/mpc-hc/sanear.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 48e77fb6d7e972f99416a838ec6632afaca2cf4c (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
#pragma once

#include "DspBase.h"

#include <soxr.h>

namespace SaneAudioRenderer
{
    class DspRate final
        : public DspBase
    {
    public:

        DspRate() = default;
        DspRate(const DspRate&) = delete;
        DspRate& operator=(const DspRate&) = delete;
        ~DspRate();

        void Initialize(bool variable, uint32_t inputRate, uint32_t outputRate, uint32_t channels);

        std::wstring Name() override { return L"Rate"; }

        bool Active() override;

        void Process(DspChunk& chunk) override;
        void Finish(DspChunk& chunk) override;

        void Adjust(REFERENCE_TIME time);

    private:

        enum class State
        {
            Passthrough,
            Constant,
            Variable,
        };

        DspChunk ProcessChunk(soxr_t soxr, DspChunk& chunk);
        DspChunk ProcessEosChunk(soxr_t soxr, DspChunk& chunk);

        void FinishStateTransition(DspChunk& processedChunk, DspChunk& unprocessedChunk, bool eos);

        void CreateBackend();
        soxr_t GetBackend();
        void DestroyBackends();

        soxr_t m_soxrc = nullptr;
        soxr_t m_soxrv = nullptr;

        State m_state = State::Passthrough;

        bool m_inStateTransition = false;
        std::pair<bool, size_t> m_transitionCorrelation;
        std::pair<DspChunk, DspChunk> m_transitionChunks;

        uint32_t m_inputRate = 0;
        uint32_t m_outputRate = 0;
        uint32_t m_channels = 0;

        uint64_t m_variableInputFrames = 0;
        uint64_t m_variableOutputFrames = 0;
        uint64_t m_variableDelay = 0; // In input samples.

        REFERENCE_TIME m_adjustTime = 0; // Negative time - less samples, positive time - more samples.
    };
}