-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaudiooutput.cpp
43 lines (37 loc) · 1.15 KB
/
audiooutput.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
/*
* Copyright (C) 2020 - 2021 Judd Niemann - All Rights Reserved.
* You may use, distribute and modify this code under the
* terms of the GNU Lesser General Public License, version 2.1
*
* You should have received a copy of GNU Lesser General Public License v2.1
* with this file. If not, please refer to: https://github.com/jniemann66/ReSampler
*/
#include "audiooutput.h"
#include <QDebug>
AudioOutputQueue::AudioOutputQueue(QObject *parent) : QObject(parent), datastream(&buffer, QIODevice::WriteOnly)
{
datastream.setFloatingPointPrecision(QDataStream::SinglePrecision);
}
void AudioOutputQueue::setConfiguration(const QAudioDeviceInfo& audioDevice, const QAudioFormat& format)
{
_output.reset(new QAudioOutput(audioDevice, format));
_output->setVolume(1.0);
qDebug() << _output->state() << _output->error();
}
void AudioOutputQueue::addAudio(float val)
{
datastream << val;
}
void AudioOutputQueue::play()
{
if(_output.get() != nullptr) {
_output->start(datastream.device());
}
}
int64_t AudioOutputQueue::size() const
{
if(datastream.device() != nullptr) {
return datastream.device()->size();
}
return 0;
}