author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 19 Feb 2010 23:40:16 +0200 | |
branch | RCL_3 |
changeset 4 | 3b1da2848fc7 |
parent 3 | 41300fa6a67c |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 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 <QAudioDeviceInfo> |
|
44 |
||
45 |
#include "audiodevices.h" |
|
46 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
47 |
AudioDevicesBase::AudioDevicesBase(QWidget *parent, Qt::WFlags f) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
48 |
: QMainWindow(parent, f) |
0 | 49 |
{ |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
50 |
setupUi(this); |
0 | 51 |
} |
52 |
||
53 |
AudioDevicesBase::~AudioDevicesBase() {} |
|
54 |
||
55 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
56 |
AudioTest::AudioTest(QWidget *parent, Qt::WFlags f) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
57 |
: AudioDevicesBase(parent, f) |
0 | 58 |
{ |
59 |
mode = QAudio::AudioOutput; |
|
60 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
61 |
connect(testButton, SIGNAL(clicked()), SLOT(test())); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
62 |
connect(modeBox, SIGNAL(activated(int)), SLOT(modeChanged(int))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
63 |
connect(deviceBox, SIGNAL(activated(int)), SLOT(deviceChanged(int))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
64 |
connect(frequencyBox, SIGNAL(activated(int)), SLOT(freqChanged(int))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
65 |
connect(channelsBox, SIGNAL(activated(int)), SLOT(channelChanged(int))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
66 |
connect(codecsBox, SIGNAL(activated(int)), SLOT(codecChanged(int))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
67 |
connect(sampleSizesBox, SIGNAL(activated(int)), SLOT(sampleSizeChanged(int))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
68 |
connect(sampleTypesBox, SIGNAL(activated(int)), SLOT(sampleTypeChanged(int))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
69 |
connect(endianBox, SIGNAL(activated(int)), SLOT(endianChanged(int))); |
0 | 70 |
|
71 |
modeBox->setCurrentIndex(0); |
|
72 |
modeChanged(0); |
|
73 |
deviceBox->setCurrentIndex(0); |
|
74 |
deviceChanged(0); |
|
75 |
} |
|
76 |
||
77 |
AudioTest::~AudioTest() |
|
78 |
{ |
|
79 |
} |
|
80 |
||
81 |
void AudioTest::test() |
|
82 |
{ |
|
83 |
// tries to set all the settings picked. |
|
84 |
logOutput->clear(); |
|
85 |
logOutput->append("NOTE: an invalid codec audio/test exists for testing, to get a fail condition."); |
|
86 |
||
87 |
if (!deviceInfo.isNull()) { |
|
88 |
if (deviceInfo.isFormatSupported(settings)) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
89 |
logOutput->append(tr("Success")); |
0 | 90 |
nearestFreq->setText(""); |
91 |
nearestChannel->setText(""); |
|
92 |
nearestCodec->setText(""); |
|
93 |
nearestSampleSize->setText(""); |
|
94 |
nearestSampleType->setText(""); |
|
95 |
nearestEndian->setText(""); |
|
96 |
} else { |
|
97 |
QAudioFormat nearest = deviceInfo.nearestFormat(settings); |
|
98 |
logOutput->append(tr("Failed")); |
|
99 |
nearestFreq->setText(QString("%1").arg(nearest.frequency())); |
|
100 |
nearestChannel->setText(QString("%1").arg(nearest.channels())); |
|
101 |
nearestCodec->setText(nearest.codec()); |
|
102 |
nearestSampleSize->setText(QString("%1").arg(nearest.sampleSize())); |
|
103 |
||
104 |
switch(nearest.sampleType()) { |
|
105 |
case QAudioFormat::SignedInt: |
|
106 |
nearestSampleType->setText("SignedInt"); |
|
107 |
break; |
|
108 |
case QAudioFormat::UnSignedInt: |
|
109 |
nearestSampleType->setText("UnSignedInt"); |
|
110 |
break; |
|
111 |
case QAudioFormat::Float: |
|
112 |
nearestSampleType->setText("Float"); |
|
113 |
break; |
|
114 |
case QAudioFormat::Unknown: |
|
115 |
nearestSampleType->setText("Unknown"); |
|
116 |
} |
|
117 |
switch(nearest.byteOrder()) { |
|
118 |
case QAudioFormat::LittleEndian: |
|
119 |
nearestEndian->setText("LittleEndian"); |
|
120 |
break; |
|
121 |
case QAudioFormat::BigEndian: |
|
122 |
nearestEndian->setText("BigEndian"); |
|
123 |
} |
|
124 |
} |
|
125 |
} |
|
126 |
else |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
127 |
logOutput->append(tr("No Device")); |
0 | 128 |
} |
129 |
||
130 |
void AudioTest::modeChanged(int idx) |
|
131 |
{ |
|
132 |
// mode has changed |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
133 |
if (idx == 0) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
134 |
mode = QAudio::AudioInput; |
0 | 135 |
else |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
136 |
mode = QAudio::AudioOutput; |
0 | 137 |
|
138 |
deviceBox->clear(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
139 |
foreach (const QAudioDeviceInfo &deviceInfo, QAudioDeviceInfo::availableDevices(mode)) |
0 | 140 |
deviceBox->addItem(deviceInfo.deviceName(), qVariantFromValue(deviceInfo)); |
141 |
} |
|
142 |
||
143 |
void AudioTest::deviceChanged(int idx) |
|
144 |
{ |
|
145 |
if (deviceBox->count() == 0) |
|
146 |
return; |
|
147 |
||
148 |
// device has changed |
|
149 |
deviceInfo = deviceBox->itemData(idx).value<QAudioDeviceInfo>(); |
|
150 |
||
151 |
frequencyBox->clear(); |
|
152 |
QList<int> freqz = deviceInfo.supportedFrequencies(); |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
153 |
for(int i = 0; i < freqz.size(); ++i) |
0 | 154 |
frequencyBox->addItem(QString("%1").arg(freqz.at(i))); |
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
155 |
if(freqz.size()) |
0 | 156 |
settings.setFrequency(freqz.at(0)); |
157 |
||
158 |
channelsBox->clear(); |
|
159 |
QList<int> chz = deviceInfo.supportedChannels(); |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
160 |
for(int i = 0; i < chz.size(); ++i) |
0 | 161 |
channelsBox->addItem(QString("%1").arg(chz.at(i))); |
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
162 |
if(chz.size()) |
0 | 163 |
settings.setChannels(chz.at(0)); |
164 |
||
165 |
codecsBox->clear(); |
|
166 |
QStringList codecz = deviceInfo.supportedCodecs(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
167 |
for (int i = 0; i < codecz.size(); ++i) |
0 | 168 |
codecsBox->addItem(QString("%1").arg(codecz.at(i))); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
169 |
if (codecz.size()) |
0 | 170 |
settings.setCodec(codecz.at(0)); |
171 |
// Add false to create failed condition! |
|
172 |
codecsBox->addItem("audio/test"); |
|
173 |
||
174 |
sampleSizesBox->clear(); |
|
175 |
QList<int> sampleSizez = deviceInfo.supportedSampleSizes(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
176 |
for (int i = 0; i < sampleSizez.size(); ++i) |
0 | 177 |
sampleSizesBox->addItem(QString("%1").arg(sampleSizez.at(i))); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
178 |
if (sampleSizez.size()) |
0 | 179 |
settings.setSampleSize(sampleSizez.at(0)); |
180 |
||
181 |
sampleTypesBox->clear(); |
|
182 |
QList<QAudioFormat::SampleType> sampleTypez = deviceInfo.supportedSampleTypes(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
183 |
for (int i = 0; i < sampleTypez.size(); ++i) { |
0 | 184 |
switch(sampleTypez.at(i)) { |
185 |
case QAudioFormat::SignedInt: |
|
186 |
sampleTypesBox->addItem("SignedInt"); |
|
187 |
break; |
|
188 |
case QAudioFormat::UnSignedInt: |
|
189 |
sampleTypesBox->addItem("UnSignedInt"); |
|
190 |
break; |
|
191 |
case QAudioFormat::Float: |
|
192 |
sampleTypesBox->addItem("Float"); |
|
193 |
break; |
|
194 |
case QAudioFormat::Unknown: |
|
195 |
sampleTypesBox->addItem("Unknown"); |
|
196 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
197 |
if (sampleTypez.size()) |
0 | 198 |
settings.setSampleType(sampleTypez.at(0)); |
199 |
} |
|
200 |
||
201 |
endianBox->clear(); |
|
202 |
QList<QAudioFormat::Endian> endianz = deviceInfo.supportedByteOrders(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
203 |
for (int i = 0; i < endianz.size(); ++i) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
204 |
switch (endianz.at(i)) { |
0 | 205 |
case QAudioFormat::LittleEndian: |
206 |
endianBox->addItem("Little Endian"); |
|
207 |
break; |
|
208 |
case QAudioFormat::BigEndian: |
|
209 |
endianBox->addItem("Big Endian"); |
|
210 |
break; |
|
211 |
} |
|
212 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
213 |
if (endianz.size()) |
0 | 214 |
settings.setByteOrder(endianz.at(0)); |
215 |
} |
|
216 |
||
217 |
void AudioTest::freqChanged(int idx) |
|
218 |
{ |
|
219 |
// freq has changed |
|
220 |
settings.setFrequency(frequencyBox->itemText(idx).toInt()); |
|
221 |
} |
|
222 |
||
223 |
void AudioTest::channelChanged(int idx) |
|
224 |
{ |
|
225 |
settings.setChannels(channelsBox->itemText(idx).toInt()); |
|
226 |
} |
|
227 |
||
228 |
void AudioTest::codecChanged(int idx) |
|
229 |
{ |
|
230 |
settings.setCodec(codecsBox->itemText(idx)); |
|
231 |
} |
|
232 |
||
233 |
void AudioTest::sampleSizeChanged(int idx) |
|
234 |
{ |
|
235 |
settings.setSampleSize(sampleSizesBox->itemText(idx).toInt()); |
|
236 |
} |
|
237 |
||
238 |
void AudioTest::sampleTypeChanged(int idx) |
|
239 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
240 |
switch (sampleTypesBox->itemText(idx).toInt()) { |
0 | 241 |
case QAudioFormat::SignedInt: |
242 |
settings.setSampleType(QAudioFormat::SignedInt); |
|
243 |
break; |
|
244 |
case QAudioFormat::UnSignedInt: |
|
245 |
settings.setSampleType(QAudioFormat::UnSignedInt); |
|
246 |
break; |
|
247 |
case QAudioFormat::Float: |
|
248 |
settings.setSampleType(QAudioFormat::Float); |
|
249 |
} |
|
250 |
} |
|
251 |
||
252 |
void AudioTest::endianChanged(int idx) |
|
253 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
254 |
switch (endianBox->itemText(idx).toInt()) { |
0 | 255 |
case QAudioFormat::LittleEndian: |
256 |
settings.setByteOrder(QAudioFormat::LittleEndian); |
|
257 |
break; |
|
258 |
case QAudioFormat::BigEndian: |
|
259 |
settings.setByteOrder(QAudioFormat::BigEndian); |
|
260 |
} |
|
261 |
} |