-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaudioplayer.h
More file actions
66 lines (49 loc) · 1.71 KB
/
audioplayer.h
File metadata and controls
66 lines (49 loc) · 1.71 KB
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
#pragma once
#include <atomic>
#include <optional>
#include <QObject>
#include <QAudioBuffer>
#include <QtGlobal>
#include <QDateTime>
struct frame_t;
class AudioPlayer : public QObject
{
Q_OBJECT
public:
explicit AudioPlayer(QObject *parent = nullptr);
explicit AudioPlayer(const QAudioBuffer &buffer, QObject *parent = nullptr);
void writeSamples(frame_t *begin, frame_t *end);
bool playing() const { return m_playing; }
void setPlaying(bool playing);
double position() const { return m_position; }
void setPosition(double position);
float speed() const { return m_speed; }
void setSpeed(float speed);
float volume() const { return m_volume; }
void setVolume(float volume);
bool stopOnEnd() { return m_stopOnEnd; }
void setStopOnEnd(bool stopOnEnd) { m_stopOnEnd = stopOnEnd; emit stopOnEndChanged(m_stopOnEnd); }
const QAudioBuffer &buffer() const { return m_buffer; }
void setBuffer(const QAudioBuffer &buffer);
const std::optional<std::pair<double, double>> &loop() const { return m_loop; }
void setLoop(const std::optional<std::pair<double, double>> &loop) { m_loop = loop; }
void togglePlaying();
void restart();
void stop();
signals:
void playingChanged(bool playing);
void positionChanged(double position);
void speedChanged(float speed);
void volumeChanged(float volume);
void stopOnEndChanged(bool stopOnEnd);
void bufferChanged(const QAudioBuffer &buffer);
private:
bool m_playing{false};
double m_position{};
float m_speed{1.f};
float m_volume{1.f};
bool m_stopOnEnd{true};
QAudioBuffer m_buffer;
std::optional<std::pair<double, double>> m_loop;
QDateTime m_lastPositionUpdate;
};