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

AudioRenderer.h « src - github.com/mpc-hc/sanear.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6e9e07da842af1a8f27c122cac128358008032c3 (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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#pragma once

#include "AudioDevice.h"
#include "AudioDeviceManager.h"
#include "DspBalance.h"
#include "DspCrossfeed.h"
#include "DspDither.h"
#include "DspLimiter.h"
#include "DspMatrix.h"
#include "DspRate.h"
#include "DspTempo.h"
#include "DspTempo2.h"
#include "DspVolume.h"
#include "Interfaces.h"
#include "SampleCorrection.h"

namespace SaneAudioRenderer
{
    class MyClock;

    class AudioRenderer final
        : public CCritSec
    {
    public:

        AudioRenderer(ISettings* pSettings, MyClock& clock, HRESULT& result);
        AudioRenderer(const AudioRenderer&) = delete;
        AudioRenderer& operator=(const AudioRenderer&) = delete;
        ~AudioRenderer();

        void SetClock(IReferenceClock* pClock);

        bool Push(IMediaSample* pSample, AM_SAMPLE2_PROPERTIES& sampleProps, CAMEvent* pFilledEvent);
        bool Finish(bool blockUntilEnd, CAMEvent* pFilledEvent);

        void BeginFlush();
        void EndFlush();

        bool CheckFormat(SharedWaveFormat inputFormat, bool live);
        void SetFormat(SharedWaveFormat inputFormat, bool live);

        void NewSegment(double rate);

        void Play(REFERENCE_TIME startTime);
        void Pause();
        void Stop();

        float GetVolume() const { return m_volume; }
        void SetVolume(float volume) { m_volume = volume; }
        float GetBalance() const { return m_balance; }
        void SetBalance(float balance) { m_balance = balance; }

        SharedWaveFormat GetInputFormat();
        const AudioDevice* GetAudioDevice();
        std::vector<std::wstring> GetActiveProcessors();

        void TakeGuidedReclock(REFERENCE_TIME offset) { m_guidedReclockOffset += offset; }

        bool OnExternalClock() const { return m_externalClock; }
        bool IsLive()          const { return m_live; }
        bool IsBitstreaming()  const { return m_bitstreaming; }

        bool OnGuidedReclock();

    private:

        void CheckDeviceSettings();
        void StartDevice();
        void CreateDevice();
        void ClearDevice();

        void PushReslavingJitter();

        void ApplyClockCorrection();

        void ApplyRateCorrection(DspChunk& chunk);

        void InitializeProcessors();

        template <typename F>
        void EnumerateProcessors(F f)
        {
            f(&m_dspMatrix);
            f(&m_dspRate);
            f(&m_dspTempo1);
            f(&m_dspTempo2);
            f(&m_dspCrossfeed);
            f(&m_dspVolume);
            f(&m_dspBalance);
            f(&m_dspLimiter);
            f(&m_dspDither);
        }

        bool PushToDevice(DspChunk& chunk, CAMEvent* pFilledEvent);

        AudioDeviceManager m_deviceManager;
        std::unique_ptr<AudioDevice> m_device;

        FILTER_STATE m_state = State_Stopped;

        SampleCorrection m_sampleCorrection;
        REFERENCE_TIME m_clockCorrection = 0;

        MyClock& m_myClock;
        IReferenceClockPtr m_graphClock;

        std::atomic<bool> m_externalClock = false;
        std::atomic<bool> m_live = false;
        std::atomic<bool> m_bitstreaming = false;

        SharedWaveFormat m_inputFormat;

        REFERENCE_TIME m_startClockOffset = 0;
        REFERENCE_TIME m_startTime = 0;

        CAMEvent m_flush;

        DspMatrix m_dspMatrix;
        DspRate m_dspRate;
        DspTempo m_dspTempo1;
        DspTempo2 m_dspTempo2;
        DspCrossfeed m_dspCrossfeed;
        DspVolume m_dspVolume;
        DspBalance m_dspBalance;
        DspLimiter m_dspLimiter;
        DspDither m_dspDither;

        ISettingsPtr m_settings;
        UINT32 m_deviceSettingsSerial = 0;

        uint32_t m_defaultDeviceSerial = 0;

        std::atomic<float> m_volume = 1.0f;
        std::atomic<float> m_balance = 0.0f;
        double m_rate = 1.0;

        std::atomic<REFERENCE_TIME> m_guidedReclockOffset = 0;
        bool m_guidedReclockActive = false;
    };
}