blob: 29ec37e51f53a7e0fef3c8fe5700566663ed831e (
plain)
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include <QtGui>
#include <QAudioOutput>
#include <QAudioDeviceInfo>
#include <QAudioInput>
class Window2 : public QWidget
{
Q_OBJECT
public slots:
//![0]
void stateChanged(QAudio::State newState)
{
switch(newState) {
case QAudio::StopState:
if (input->error() != QAudio::NoError) {
// Error handling
} else {
}
break;
//![0]
default:
;
}
}
private:
QAudioInput *input;
};
class Window : public QWidget
{
Q_OBJECT
public:
Window()
{
output = new QAudioOutput;
connect(output, SIGNAL(stateChanged(QAudio::State)),
this, SLOT(stateChanged(QAudio::State)));
}
private:
void setupFormat()
{
//![1]
QAudioFormat format;
format.setFrequency(44100);
//![1]
format.setChannels(2);
format.setSampleSize(16);
format.setCodec("audio/pcm");
format.setByteOrder(QAudioFormat::LittleEndian);
//![2]
format.setSampleType(QAudioFormat::SignedInt);
QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());
if (!info.isFormatSupported(format))
format = info.nearestFormat(format);
//![2]
}
public slots:
//![3]
void stateChanged(QAudio::State newState)
{
switch (newState) {
case QAudio::StopState:
if (output->error() != QAudio::NoError) {
// Perform error handling
} else {
// Normal stop
}
break;
//![3]
// Handle
case QAudio::ActiveState:
// Handle active state...
break;
break;
default:
;
}
}
private:
QAudioOutput *output;
};
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Window window;
window.show();
return app.exec();
}
#include "main.moc"
|