0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
** All rights reserved.
|
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
6 |
**
|
|
7 |
** This file is part of the examples of the Qt Toolkit.
|
|
8 |
**
|
|
9 |
** $QT_BEGIN_LICENSE:LGPL$
|
|
10 |
** No Commercial Usage
|
|
11 |
** This file contains pre-release code and may not be distributed.
|
|
12 |
** You may use this file in accordance with the terms and conditions
|
|
13 |
** contained in the Technology Preview License Agreement accompanying
|
|
14 |
** this package.
|
|
15 |
**
|
|
16 |
** GNU Lesser General Public License Usage
|
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
18 |
** General Public License version 2.1 as published by the Free Software
|
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
20 |
** packaging of this file. Please review the following information to
|
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
23 |
**
|
|
24 |
** In addition, as a special exception, Nokia gives you certain additional
|
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
27 |
**
|
|
28 |
** If you have questions regarding the use of this file, please contact
|
|
29 |
** Nokia at qt-info@nokia.com.
|
|
30 |
**
|
|
31 |
**
|
|
32 |
**
|
|
33 |
**
|
|
34 |
**
|
|
35 |
**
|
|
36 |
**
|
|
37 |
**
|
|
38 |
** $QT_END_LICENSE$
|
|
39 |
**
|
|
40 |
****************************************************************************/
|
|
41 |
|
|
42 |
|
|
43 |
#include <QDebug>
|
|
44 |
#include <QAudioDeviceInfo>
|
|
45 |
|
|
46 |
#include "audiodevices.h"
|
|
47 |
|
|
48 |
AudioDevicesBase::AudioDevicesBase( QMainWindow *parent, Qt::WFlags f )
|
|
49 |
{
|
|
50 |
Q_UNUSED(parent)
|
|
51 |
Q_UNUSED(f)
|
|
52 |
setupUi( this );
|
|
53 |
}
|
|
54 |
|
|
55 |
AudioDevicesBase::~AudioDevicesBase() {}
|
|
56 |
|
|
57 |
|
|
58 |
AudioTest::AudioTest( QMainWindow *parent, Qt::WFlags f )
|
|
59 |
: AudioDevicesBase( parent, f )
|
|
60 |
{
|
|
61 |
nearestFreq->setDisabled(true);
|
|
62 |
nearestChannel->setDisabled(true);
|
|
63 |
nearestCodec->setDisabled(true);
|
|
64 |
nearestSampleSize->setDisabled(true);
|
|
65 |
nearestSampleType->setDisabled(true);
|
|
66 |
nearestEndian->setDisabled(true);
|
|
67 |
logOutput->setDisabled(true);
|
|
68 |
|
|
69 |
mode = QAudio::AudioOutput;
|
|
70 |
modeBox->addItem("Input");
|
|
71 |
modeBox->addItem("Output");
|
|
72 |
|
|
73 |
connect(testButton,SIGNAL(clicked()),SLOT(test()));
|
|
74 |
connect(modeBox,SIGNAL(activated(int)),SLOT(modeChanged(int)));
|
|
75 |
connect(deviceBox,SIGNAL(activated(int)),SLOT(deviceChanged(int)));
|
|
76 |
connect(frequencyBox,SIGNAL(activated(int)),SLOT(freqChanged(int)));
|
|
77 |
connect(channelsBox,SIGNAL(activated(int)),SLOT(channelChanged(int)));
|
|
78 |
connect(codecsBox,SIGNAL(activated(int)),SLOT(codecChanged(int)));
|
|
79 |
connect(sampleSizesBox,SIGNAL(activated(int)),SLOT(sampleSizeChanged(int)));
|
|
80 |
connect(sampleTypesBox,SIGNAL(activated(int)),SLOT(sampleTypeChanged(int)));
|
|
81 |
connect(endianBox,SIGNAL(activated(int)),SLOT(endianChanged(int)));
|
|
82 |
|
|
83 |
modeBox->setCurrentIndex(0);
|
|
84 |
modeChanged(0);
|
|
85 |
deviceBox->setCurrentIndex(0);
|
|
86 |
deviceChanged(0);
|
|
87 |
}
|
|
88 |
|
|
89 |
AudioTest::~AudioTest()
|
|
90 |
{
|
|
91 |
}
|
|
92 |
|
|
93 |
void AudioTest::test()
|
|
94 |
{
|
|
95 |
// tries to set all the settings picked.
|
|
96 |
logOutput->clear();
|
|
97 |
logOutput->append("NOTE: an invalid codec audio/test exists for testing, to get a fail condition.");
|
|
98 |
|
|
99 |
if (!deviceInfo.isNull()) {
|
|
100 |
if (deviceInfo.isFormatSupported(settings)) {
|
|
101 |
logOutput->append("Success");
|
|
102 |
nearestFreq->setText("");
|
|
103 |
nearestChannel->setText("");
|
|
104 |
nearestCodec->setText("");
|
|
105 |
nearestSampleSize->setText("");
|
|
106 |
nearestSampleType->setText("");
|
|
107 |
nearestEndian->setText("");
|
|
108 |
} else {
|
|
109 |
QAudioFormat nearest = deviceInfo.nearestFormat(settings);
|
|
110 |
logOutput->append(tr("Failed"));
|
|
111 |
nearestFreq->setText(QString("%1").arg(nearest.frequency()));
|
|
112 |
nearestChannel->setText(QString("%1").arg(nearest.channels()));
|
|
113 |
nearestCodec->setText(nearest.codec());
|
|
114 |
nearestSampleSize->setText(QString("%1").arg(nearest.sampleSize()));
|
|
115 |
|
|
116 |
switch(nearest.sampleType()) {
|
|
117 |
case QAudioFormat::SignedInt:
|
|
118 |
nearestSampleType->setText("SignedInt");
|
|
119 |
break;
|
|
120 |
case QAudioFormat::UnSignedInt:
|
|
121 |
nearestSampleType->setText("UnSignedInt");
|
|
122 |
break;
|
|
123 |
case QAudioFormat::Float:
|
|
124 |
nearestSampleType->setText("Float");
|
|
125 |
break;
|
|
126 |
case QAudioFormat::Unknown:
|
|
127 |
nearestSampleType->setText("Unknown");
|
|
128 |
}
|
|
129 |
switch(nearest.byteOrder()) {
|
|
130 |
case QAudioFormat::LittleEndian:
|
|
131 |
nearestEndian->setText("LittleEndian");
|
|
132 |
break;
|
|
133 |
case QAudioFormat::BigEndian:
|
|
134 |
nearestEndian->setText("BigEndian");
|
|
135 |
}
|
|
136 |
}
|
|
137 |
}
|
|
138 |
else
|
|
139 |
logOutput->append("No Device");
|
|
140 |
}
|
|
141 |
|
|
142 |
void AudioTest::modeChanged(int idx)
|
|
143 |
{
|
|
144 |
// mode has changed
|
|
145 |
if(idx == 0)
|
|
146 |
mode=QAudio::AudioInput;
|
|
147 |
else
|
|
148 |
mode=QAudio::AudioOutput;
|
|
149 |
|
|
150 |
deviceBox->clear();
|
|
151 |
foreach (const QAudioDeviceInfo &deviceInfo, QAudioDeviceInfo::deviceList(mode))
|
|
152 |
deviceBox->addItem(deviceInfo.deviceName(), qVariantFromValue(deviceInfo));
|
|
153 |
}
|
|
154 |
|
|
155 |
void AudioTest::deviceChanged(int idx)
|
|
156 |
{
|
|
157 |
if (deviceBox->count() == 0)
|
|
158 |
return;
|
|
159 |
|
|
160 |
// device has changed
|
|
161 |
deviceInfo = deviceBox->itemData(idx).value<QAudioDeviceInfo>();
|
|
162 |
|
|
163 |
frequencyBox->clear();
|
|
164 |
QList<int> freqz = deviceInfo.supportedFrequencies();
|
|
165 |
for(int i = 0; i < freqz.size(); ++i)
|
|
166 |
frequencyBox->addItem(QString("%1").arg(freqz.at(i)));
|
|
167 |
if(freqz.size())
|
|
168 |
settings.setFrequency(freqz.at(0));
|
|
169 |
|
|
170 |
channelsBox->clear();
|
|
171 |
QList<int> chz = deviceInfo.supportedChannels();
|
|
172 |
for(int i = 0; i < chz.size(); ++i)
|
|
173 |
channelsBox->addItem(QString("%1").arg(chz.at(i)));
|
|
174 |
if(chz.size())
|
|
175 |
settings.setChannels(chz.at(0));
|
|
176 |
|
|
177 |
codecsBox->clear();
|
|
178 |
QStringList codecz = deviceInfo.supportedCodecs();
|
|
179 |
for(int i = 0; i < codecz.size(); ++i)
|
|
180 |
codecsBox->addItem(QString("%1").arg(codecz.at(i)));
|
|
181 |
if(codecz.size())
|
|
182 |
settings.setCodec(codecz.at(0));
|
|
183 |
// Add false to create failed condition!
|
|
184 |
codecsBox->addItem("audio/test");
|
|
185 |
|
|
186 |
sampleSizesBox->clear();
|
|
187 |
QList<int> sampleSizez = deviceInfo.supportedSampleSizes();
|
|
188 |
for(int i = 0; i < sampleSizez.size(); ++i)
|
|
189 |
sampleSizesBox->addItem(QString("%1").arg(sampleSizez.at(i)));
|
|
190 |
if(sampleSizez.size())
|
|
191 |
settings.setSampleSize(sampleSizez.at(0));
|
|
192 |
|
|
193 |
sampleTypesBox->clear();
|
|
194 |
QList<QAudioFormat::SampleType> sampleTypez = deviceInfo.supportedSampleTypes();
|
|
195 |
for(int i = 0; i < sampleTypez.size(); ++i) {
|
|
196 |
switch(sampleTypez.at(i)) {
|
|
197 |
case QAudioFormat::SignedInt:
|
|
198 |
sampleTypesBox->addItem("SignedInt");
|
|
199 |
break;
|
|
200 |
case QAudioFormat::UnSignedInt:
|
|
201 |
sampleTypesBox->addItem("UnSignedInt");
|
|
202 |
break;
|
|
203 |
case QAudioFormat::Float:
|
|
204 |
sampleTypesBox->addItem("Float");
|
|
205 |
break;
|
|
206 |
case QAudioFormat::Unknown:
|
|
207 |
sampleTypesBox->addItem("Unknown");
|
|
208 |
}
|
|
209 |
if(sampleTypez.size())
|
|
210 |
settings.setSampleType(sampleTypez.at(0));
|
|
211 |
}
|
|
212 |
|
|
213 |
endianBox->clear();
|
|
214 |
QList<QAudioFormat::Endian> endianz = deviceInfo.supportedByteOrders();
|
|
215 |
for(int i = 0; i < endianz.size(); ++i) {
|
|
216 |
switch(endianz.at(i)) {
|
|
217 |
case QAudioFormat::LittleEndian:
|
|
218 |
endianBox->addItem("Little Endian");
|
|
219 |
break;
|
|
220 |
case QAudioFormat::BigEndian:
|
|
221 |
endianBox->addItem("Big Endian");
|
|
222 |
break;
|
|
223 |
}
|
|
224 |
}
|
|
225 |
if(endianz.size())
|
|
226 |
settings.setByteOrder(endianz.at(0));
|
|
227 |
}
|
|
228 |
|
|
229 |
void AudioTest::freqChanged(int idx)
|
|
230 |
{
|
|
231 |
// freq has changed
|
|
232 |
settings.setFrequency(frequencyBox->itemText(idx).toInt());
|
|
233 |
}
|
|
234 |
|
|
235 |
void AudioTest::channelChanged(int idx)
|
|
236 |
{
|
|
237 |
settings.setChannels(channelsBox->itemText(idx).toInt());
|
|
238 |
}
|
|
239 |
|
|
240 |
void AudioTest::codecChanged(int idx)
|
|
241 |
{
|
|
242 |
settings.setCodec(codecsBox->itemText(idx));
|
|
243 |
}
|
|
244 |
|
|
245 |
void AudioTest::sampleSizeChanged(int idx)
|
|
246 |
{
|
|
247 |
settings.setSampleSize(sampleSizesBox->itemText(idx).toInt());
|
|
248 |
}
|
|
249 |
|
|
250 |
void AudioTest::sampleTypeChanged(int idx)
|
|
251 |
{
|
|
252 |
switch(sampleTypesBox->itemText(idx).toInt()) {
|
|
253 |
case QAudioFormat::SignedInt:
|
|
254 |
settings.setSampleType(QAudioFormat::SignedInt);
|
|
255 |
break;
|
|
256 |
case QAudioFormat::UnSignedInt:
|
|
257 |
settings.setSampleType(QAudioFormat::UnSignedInt);
|
|
258 |
break;
|
|
259 |
case QAudioFormat::Float:
|
|
260 |
settings.setSampleType(QAudioFormat::Float);
|
|
261 |
}
|
|
262 |
}
|
|
263 |
|
|
264 |
void AudioTest::endianChanged(int idx)
|
|
265 |
{
|
|
266 |
switch(endianBox->itemText(idx).toInt()) {
|
|
267 |
case QAudioFormat::LittleEndian:
|
|
268 |
settings.setByteOrder(QAudioFormat::LittleEndian);
|
|
269 |
break;
|
|
270 |
case QAudioFormat::BigEndian:
|
|
271 |
settings.setByteOrder(QAudioFormat::BigEndian);
|
|
272 |
}
|
|
273 |
}
|
|
274 |
|