-
Notifications
You must be signed in to change notification settings - Fork 0
/
audiosystem.h
94 lines (74 loc) · 2.08 KB
/
audiosystem.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
#pragma once
#include <QObject>
#include <QList>
#include <QPair>
#include <portaudio.h>
#include <stdint.h>
#include "config.h"
#include <memory>
class DSP;
typedef int32_t int24_t;
namespace AudioSystem {
enum SAMPLEFORMAT {
INT8,
INT16,
INT24,
INT32,
FLOAT
};
struct Mode {
int sampleRate;
int numChannels;
SAMPLEFORMAT sampleFormat;
};
typedef QPair<QString, int> Device;
typedef QList<Device> DeviceList;
class Manager : public QObject {
Q_OBJECT
public:
enum State {
INVALID = 0,
INITIALIZED,
READY,
STREAMING
};
~Manager();
static std::unique_ptr<Manager> create();
bool init();
DeviceList getDeviceList() const;
Device getDeviceByName(const QString& name);
bool checkModeSupported(const Device& d, const Mode& m) const;
bool openDeviceStream();
void startDeviceStream();
void stopDeviceStream();
bool closeDeviceStream();
DSP* getDSP() { return _dsp; }
const DSP* getDSP() const { return _dsp; }
void setDSP(DSP* dsp) { _dsp = dsp; }
Mode& getCurrentMode() { return _streamingMode; }
State getState() const { return _state; }
signals:
void message(QString text) const;
void error(QString text) const;
void warn(QString text) const;
private:
Manager();
static int _PAcallback(const void* input,
void* output,
unsigned long frameCount,
const PaStreamCallbackTimeInfo* ti,
PaStreamCallbackFlags statusFlags,
void* user);
PaSampleFormat getSampleFormat(SAMPLEFORMAT t) const;
void convert(int8_t* input, uint32_t len, sample_t* out);
void convert(int16_t* input, uint32_t len, sample_t* out);
void convert24(int32_t* input, uint32_t len, sample_t* out);
void convert(int32_t* input, uint32_t len, sample_t* out);
void convert(float* input, uint32_t len, sample_t* out);
State _state;
static Manager* _instance;
PaStream* _stream;
Mode _streamingMode;
DSP* _dsp;
};
}