source: trunk/examples/multimedia/audiodevices/audiodevices.cpp@ 641

Last change on this file since 641 was 561, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.1 sources.

  • Property svn:eol-style set to native
File size: 8.9 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the examples of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
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** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42
43#include <QAudioDeviceInfo>
44
45#include "audiodevices.h"
46
47AudioDevicesBase::AudioDevicesBase(QWidget *parent, Qt::WFlags f)
48 : QMainWindow(parent, f)
49{
50 setupUi(this);
51}
52
53AudioDevicesBase::~AudioDevicesBase() {}
54
55
56AudioTest::AudioTest(QWidget *parent, Qt::WFlags f)
57 : AudioDevicesBase(parent, f)
58{
59 mode = QAudio::AudioOutput;
60
61 connect(testButton, SIGNAL(clicked()), SLOT(test()));
62 connect(modeBox, SIGNAL(activated(int)), SLOT(modeChanged(int)));
63 connect(deviceBox, SIGNAL(activated(int)), SLOT(deviceChanged(int)));
64 connect(frequencyBox, SIGNAL(activated(int)), SLOT(freqChanged(int)));
65 connect(channelsBox, SIGNAL(activated(int)), SLOT(channelChanged(int)));
66 connect(codecsBox, SIGNAL(activated(int)), SLOT(codecChanged(int)));
67 connect(sampleSizesBox, SIGNAL(activated(int)), SLOT(sampleSizeChanged(int)));
68 connect(sampleTypesBox, SIGNAL(activated(int)), SLOT(sampleTypeChanged(int)));
69 connect(endianBox, SIGNAL(activated(int)), SLOT(endianChanged(int)));
70
71 modeBox->setCurrentIndex(0);
72 modeChanged(0);
73 deviceBox->setCurrentIndex(0);
74 deviceChanged(0);
75}
76
77AudioTest::~AudioTest()
78{
79}
80
81void 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)) {
89 logOutput->append(tr("Success"));
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
127 logOutput->append(tr("No Device"));
128}
129
130void AudioTest::modeChanged(int idx)
131{
132 // mode has changed
133 if (idx == 0)
134 mode = QAudio::AudioInput;
135 else
136 mode = QAudio::AudioOutput;
137
138 deviceBox->clear();
139 foreach (const QAudioDeviceInfo &deviceInfo, QAudioDeviceInfo::availableDevices(mode))
140 deviceBox->addItem(deviceInfo.deviceName(), qVariantFromValue(deviceInfo));
141}
142
143void 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();
153 for (int i = 0; i < freqz.size(); ++i)
154 frequencyBox->addItem(QString("%1").arg(freqz.at(i)));
155 if (freqz.size())
156 settings.setFrequency(freqz.at(0));
157
158 channelsBox->clear();
159 QList<int> chz = deviceInfo.supportedChannels();
160 for (int i = 0; i < chz.size(); ++i)
161 channelsBox->addItem(QString("%1").arg(chz.at(i)));
162 if (chz.size())
163 settings.setChannels(chz.at(0));
164
165 codecsBox->clear();
166 QStringList codecz = deviceInfo.supportedCodecs();
167 for (int i = 0; i < codecz.size(); ++i)
168 codecsBox->addItem(QString("%1").arg(codecz.at(i)));
169 if (codecz.size())
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();
176 for (int i = 0; i < sampleSizez.size(); ++i)
177 sampleSizesBox->addItem(QString("%1").arg(sampleSizez.at(i)));
178 if (sampleSizez.size())
179 settings.setSampleSize(sampleSizez.at(0));
180
181 sampleTypesBox->clear();
182 QList<QAudioFormat::SampleType> sampleTypez = deviceInfo.supportedSampleTypes();
183 for (int i = 0; i < sampleTypez.size(); ++i) {
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 }
197 if (sampleTypez.size())
198 settings.setSampleType(sampleTypez.at(0));
199 }
200
201 endianBox->clear();
202 QList<QAudioFormat::Endian> endianz = deviceInfo.supportedByteOrders();
203 for (int i = 0; i < endianz.size(); ++i) {
204 switch (endianz.at(i)) {
205 case QAudioFormat::LittleEndian:
206 endianBox->addItem("Little Endian");
207 break;
208 case QAudioFormat::BigEndian:
209 endianBox->addItem("Big Endian");
210 break;
211 }
212 }
213 if (endianz.size())
214 settings.setByteOrder(endianz.at(0));
215}
216
217void AudioTest::freqChanged(int idx)
218{
219 // freq has changed
220 settings.setFrequency(frequencyBox->itemText(idx).toInt());
221}
222
223void AudioTest::channelChanged(int idx)
224{
225 settings.setChannels(channelsBox->itemText(idx).toInt());
226}
227
228void AudioTest::codecChanged(int idx)
229{
230 settings.setCodec(codecsBox->itemText(idx));
231}
232
233void AudioTest::sampleSizeChanged(int idx)
234{
235 settings.setSampleSize(sampleSizesBox->itemText(idx).toInt());
236}
237
238void AudioTest::sampleTypeChanged(int idx)
239{
240 switch (sampleTypesBox->itemText(idx).toInt()) {
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
252void AudioTest::endianChanged(int idx)
253{
254 switch (endianBox->itemText(idx).toInt()) {
255 case QAudioFormat::LittleEndian:
256 settings.setByteOrder(QAudioFormat::LittleEndian);
257 break;
258 case QAudioFormat::BigEndian:
259 settings.setByteOrder(QAudioFormat::BigEndian);
260 }
261}
Note: See TracBrowser for help on using the repository browser.