-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathAudioOutputQt5.cpp
52 lines (40 loc) · 899 Bytes
/
AudioOutputQt5.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
#include "AudioOutputQt5.h"
#include "Audio.h"
#include <QAudioFormat>
#include <QAudioOutput>
#include <memory>
// AudioOutput
struct AudioOutput::Private {
QString description;
std::shared_ptr<QAudioOutput> output;
};
AudioOutput::AudioOutput()
: m(new Private)
{
}
AudioOutput::~AudioOutput()
{
delete m;
}
QString AudioOutput::description()
{
return m->description;
}
void AudioOutput::start(AudioDevice const &dev, QAudioFormat const &format, QIODevice *out)
{
stop();
RECOMMENDED_BUFFER_SIZE = format.bytesForFrames(1) * format.sampleRate() / 20;
m->description = dev.device_.deviceName();
m->output = std::make_shared<QAudioOutput>(format);
m->output->setBufferSize(RECOMMENDED_BUFFER_SIZE);
m->output->start(out);
}
void AudioOutput::stop()
{
m->output.reset();
}
int AudioOutput::bytesFree(OutputBuffer *out) const
{
(void)out;
return m->output->bytesFree();
}