summaryrefslogtreecommitdiff
path: root/plugin/src/Caelestia/audioprovider.hpp
blob: 51ee930fab12fded0715f6b9305b5098e705432d (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
#pragma once

#include "service.hpp"
#include <QAudioSource>
#include <QIODevice>
#include <QMutex>
#include <QObject>
#include <QQueue>
#include <QThread>
#include <QTimer>
#include <QVector>
#include <cstdint>
#include <qqmlintegration.h>

namespace caelestia {

class AudioProcessor : public QObject {
    Q_OBJECT

public:
    explicit AudioProcessor(QObject* parent = nullptr);
    ~AudioProcessor();

    void init();

protected:
    uint32_t m_sampleRate;
    uint32_t m_chunkSize;
    uint32_t m_bufferSize;

private:
    QTimer* m_timer;

    Q_INVOKABLE void start();
    Q_INVOKABLE void stop();

    virtual void process() = 0;
};

class AudioProvider : public Service {
    Q_OBJECT

public:
    explicit AudioProvider(QObject* parent = nullptr);
    ~AudioProvider();

protected:
    AudioProcessor* m_processor;

    void init();

private:
    QThread* m_thread;

    void start() override;
    void stop() override;
};

} // namespace caelestia