-
Notifications
You must be signed in to change notification settings - Fork 0
/
pcmcache.h
92 lines (61 loc) · 1.71 KB
/
pcmcache.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
This file is part of Waver
Copyright (C) 2021 Peter Papp
Please visit https://launchpad.net/waver for details
*/
#ifndef PCMCACHE_H
#define PCMCACHE_H
#include <QAudioBuffer>
#include <QAudioFormat>
#include <QByteArray>
#include <QFile>
#include <QMutex>
#include <QObject>
#include <QRegExp>
#include <QStandardPaths>
#include <QtGlobal>
#include <QTimer>
#include <QUuid>
#include <QVector>
#include <QThread>
#ifdef Q_OS_WIN
#include "windows.h"
#endif
#ifdef QT_DEBUG
#include <QDebug>
#endif
class PCMCache : public QObject
{
Q_OBJECT
public:
static const qint32 BUFFER_CREATE_MILLISECONDS = 50;
static const long DEFAULT_PCM_MEMORY = 50 * 1024 * 1024;
static const long MAX_PCM_MEMORY = 500 * 1024 * 1024;
explicit PCMCache(QAudioFormat format, long lengthMilliseconds, bool radioStation, QObject *parent = nullptr);
~PCMCache();
void storeBuffer(QAudioBuffer *buffer);
qint64 size();
qint64 mostSize();
bool isFile();
private:
QAudioFormat format;
qint64 lengthMilliseconds;
bool radioStation;
QMutex mutex;
QByteArray *memory;
QFile *file;
qint64 memoryRealSize;
qint64 maxSize;
qint64 readPosition;
qint64 radioFakeReadPosition;
bool unfullfilledRequest;
long availableMemory();
public slots:
void run();
void requestNextPCMChunk();
void requestTimestampPCMChunk(long milliseconds);
signals:
void pcmChunk(QByteArray PCM, qint64 startMicroseconds);
void error(QString info, QString error);
};
#endif // PCMCACHE_H