-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaudiocontroller.cpp
59 lines (48 loc) · 1.7 KB
/
audiocontroller.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
/*
* Copyright (C) 2020 - 2023 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/sndscope.git
*/
#include "audiocontroller.h"
#include <QDebug>
#include <QMessageBox>
AudioController::AudioController(QObject *parent) : QObject(parent)
{
}
void AudioController::initializeAudio(const QAudioFormat &format, const QAudioDeviceInfo &deviceInfo)
{
static const QMap<QAudioFormat::SampleType, QString> sampleTypeMap
{
{QAudioFormat::Unknown, "Unknown"},
{QAudioFormat::SignedInt, "Signed Int"},
{QAudioFormat::UnSignedInt, "Unsigned Int"},
{QAudioFormat::Float, "Floating Point"}
};
if (!deviceInfo.isFormatSupported(format)) {
const QString msg = QStringLiteral("Audio Format Not Supported: %1Hz %2bit %3")
.arg(QString::number(format.sampleRate()),
QString::number(format.sampleSize()),
sampleTypeMap.value(format.sampleType(), "Unknown"));
QMessageBox::warning(nullptr, "Audio Format Not Supported", msg);
return;
}
audioOutput.reset(new QAudioOutput(deviceInfo, format));
emit outputVolume(audioOutput->volume());
audioOutput->setBufferSize(2 * format.sampleRate() * format.bytesPerFrame());
connect(audioOutput.get(), &QAudioOutput::stateChanged, this, [this]{
qDebug().noquote() << "Audio Status:" << audioOutput->state();
});
}
void AudioController::setOutputVolume(qreal linearVolume)
{
if(audioOutput != nullptr) {
audioOutput->setVolume(linearVolume);
}
}
QIODevice* AudioController::start()
{
return audioOutput->start();
}