-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
AudioInputQt5.cpp
63 lines (51 loc) · 971 Bytes
/
AudioInputQt5.cpp
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
#include "Audio.h"
#include "AudioInputQt5.h"
#include <QAudioInput>
#include <memory>
// AudioInput
struct AudioInput::Private {
QString description;
std::shared_ptr<QAudioInput> input;
QIODevice *reader = nullptr;
};
AudioInput::AudioInput()
: m(new Private)
{
}
AudioInput::~AudioInput()
{
stop();
delete m;
}
QString AudioInput::description()
{
return m->description;
}
void AudioInput::start(const AudioDevice &dev, QAudioFormat const &format)
{
stop();
m->description = dev.device_.deviceName();
m->input = std::shared_ptr<QAudioInput>(new QAudioInput(format));
m->reader = m->input->start();
}
void AudioInput::stop()
{
m->reader = nullptr;
m->input.reset();
}
int AudioInput::bytesAvailable() const
{
return m->input->bytesReady();
}
int AudioInput::read(char *data, int maxlen)
{
return m->reader->read(data, maxlen);
}
QByteArray AudioInput::readAll()
{
QByteArray ba;
if (m->reader) {
ba = m->reader->readAll();
}
return ba;
}