-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaudiooutput.h
119 lines (96 loc) · 2.72 KB
/
audiooutput.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
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
#ifndef AUDIOOUTPUT_H
#define AUDIOOUTPUT_H
#include <QObject>
#include <QFile>
#include <QAudioOutput>
#include <QTimer>
#include <QMutex>
#include "marks.h"
class RingBuffer
{
public:
RingBuffer();
virtual ~RingBuffer();
public:
virtual void Initialize(int inBufferByteSize);
virtual void Uninitialize();
virtual int GetBufferByteSize() const;
virtual int GetDataAvailable() const;
virtual int GetSpaceAvailable() const;
int In(const void* data, int ioBytes);
int Out(void* data, int ioBytes);
protected:
qint8 * mBuffer;
QMutex mutex;
int mBStart;
int mBEnd;
int mBSize;
bool mBWrapped;
};
class WaveOutIODevice : public QIODevice
{
Q_OBJECT
public:
WaveOutIODevice(QFile *file, QObject *parent);
~WaveOutIODevice();
void start(const qint64 newPos) { setPos(newPos); start(); }
void start();
void stop();
qint64 readData(char *data, qint64 maxlen);
qint64 writeData(const char *data, qint64 len);
qint64 bytesAvailable() const;
void setPos(const qint64 newPos);
qint64 len() { return ofile->size() - m_headersize; }
public slots:
void VolChange(int newVol) { vol = newVol; }
private slots:
void readFile();
private:
QFile *ofile;
qint64 m_headersize;
qint64 m_pos;
qint64 c_pos;
QByteArray m_buffer;
int m_sizebuffer;
int vol;
RingBuffer ring;
QTimer readTimer;
};
class AudioOutput : public QObject
{
Q_OBJECT
public:
explicit AudioOutput(QObject *parent = 0);
qint64 Pos() const;
bool isPlaying() { return firstrun ? false : audio->state() == QAudio::ActiveState; }
void setMarks(Marks* newMarks) { marks = newMarks; }
QStringList DeviceList();
signals:
void PosChanged(qint64 pos);
void VolChanged(int newVol);
void Debug( QString text );
public slots:
void startPlaying(qint64 newpos);
void finishedPlaying(QAudio::State state);
//void setFile(QString Filename) { inputFile.setFileName(Filename); inputFile.open(QIODevice::ReadOnly); }
//void setFilePos(qint64 pos) { if (startpos == -1) { inputFile.seek(pos); startpos = pos; } }
void setFile(QString Filename) { inputFile.setFileName(Filename); }
void setFilePos(qint64 newpos);
void stop() { audio->stop(); }
void VolChange(int newVol) { emit VolChanged(newVol); startvol = newVol; }
void setHardware( int newHardware ) { oldhardware = hardware; hardware = newHardware; }
private slots:
void notify();
private:
Marks *marks;
qint64 startpos;
QFile inputFile;
QAudioOutput* audio;
bool convert;
WaveOutIODevice *out;
QFile *outfile = NULL;
bool firstrun;
int hardware, oldhardware;
int startvol;
};
#endif // AUDIOOUTPUT_H