-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathoscilloscope.h
71 lines (59 loc) · 1.67 KB
/
oscilloscope.h
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
#ifndef OSCILLOSCOPE_H
#define OSCILLOSCOPE_H
#include <QThread>
#include <QCoreApplication>
#include <QVector>
#include <QByteArray>
#include <QtEndian>
#include <QAudioOutput>
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
#include <QAudioDevice>
#else
#include <QAudioDeviceInfo>
using QAudioDevice = QAudioDeviceInfo;
#endif
#include <QAudioFormat>
struct Point {
quint8 x = 0;
quint8 y = 0;
};
class Oscilloscope : public QThread
{
Q_OBJECT
public:
explicit Oscilloscope(QObject *parent = nullptr);
~Oscilloscope();
int set(QAudioDevice audioDevice, int sampleRate, int channelCount, int channelX, int channelY, int fps);
int setAudioDevice(const QAudioDevice audioDevice);
int setSampleRate(int sampleRate);
int setChannelCount(int channelCount);
void setChannelX(int channelX);
void setChannelY(int channelY);
void setFPS(int fps);
void setPoints(const QVector<Point> points);
void run();
int stop(int time = 0);
bool state();
signals:
public slots:
private:
void setBuffer(); //根据参数重新分配buffer内存
int isFormatSupported();
bool stopMe = false;
bool stateStart = false;
QAudioDevice audioDevice;
int sampleRate;
int channelCount;
int channelX;
int channelY;
int fps;
QAudioFormat format;
int bufferMaxSize = 0;
char* buffer = nullptr;
int bufferLen = 0;
char* bufferRefresh = nullptr;
int bufferRefreshLen = 0;
QAtomicInteger<bool> refresh = false; //当 refresh == true 时候,线程将会用 bufferRefresh 的 bufferRefreshLen 长度内容复制到 buffer 中去
//QByteArray bufferFrame; //框
};
#endif // OSCILLOSCOPE_H