41 |
41 |
42 |
42 |
43 #include <QAudioDeviceInfo> |
43 #include <QAudioDeviceInfo> |
44 |
44 |
45 #include "audiodevices.h" |
45 #include "audiodevices.h" |
|
46 |
|
47 // Utility functions for converting QAudioFormat fields into text |
|
48 |
|
49 QString toString(QAudioFormat::SampleType sampleType) |
|
50 { |
|
51 QString result("Unknown"); |
|
52 switch (sampleType) { |
|
53 case QAudioFormat::SignedInt: |
|
54 result = "SignedInt"; |
|
55 break; |
|
56 case QAudioFormat::UnSignedInt: |
|
57 result = "UnSignedInt"; |
|
58 break; |
|
59 case QAudioFormat::Float: |
|
60 result = "Float"; |
|
61 break; |
|
62 } |
|
63 return result; |
|
64 } |
|
65 |
|
66 QString toString(QAudioFormat::Endian endian) |
|
67 { |
|
68 QString result("Unknown"); |
|
69 switch (endian) { |
|
70 case QAudioFormat::LittleEndian: |
|
71 result = "LittleEndian"; |
|
72 break; |
|
73 case QAudioFormat::BigEndian: |
|
74 result = "BigEndian"; |
|
75 break; |
|
76 } |
|
77 return result; |
|
78 } |
|
79 |
46 |
80 |
47 AudioDevicesBase::AudioDevicesBase(QWidget *parent, Qt::WFlags f) |
81 AudioDevicesBase::AudioDevicesBase(QWidget *parent, Qt::WFlags f) |
48 : QMainWindow(parent, f) |
82 : QMainWindow(parent, f) |
49 { |
83 { |
50 setupUi(this); |
84 setupUi(this); |
65 connect(channelsBox, SIGNAL(activated(int)), SLOT(channelChanged(int))); |
99 connect(channelsBox, SIGNAL(activated(int)), SLOT(channelChanged(int))); |
66 connect(codecsBox, SIGNAL(activated(int)), SLOT(codecChanged(int))); |
100 connect(codecsBox, SIGNAL(activated(int)), SLOT(codecChanged(int))); |
67 connect(sampleSizesBox, SIGNAL(activated(int)), SLOT(sampleSizeChanged(int))); |
101 connect(sampleSizesBox, SIGNAL(activated(int)), SLOT(sampleSizeChanged(int))); |
68 connect(sampleTypesBox, SIGNAL(activated(int)), SLOT(sampleTypeChanged(int))); |
102 connect(sampleTypesBox, SIGNAL(activated(int)), SLOT(sampleTypeChanged(int))); |
69 connect(endianBox, SIGNAL(activated(int)), SLOT(endianChanged(int))); |
103 connect(endianBox, SIGNAL(activated(int)), SLOT(endianChanged(int))); |
|
104 connect(populateTableButton, SIGNAL(clicked()), SLOT(populateTable())); |
70 |
105 |
71 modeBox->setCurrentIndex(0); |
106 modeBox->setCurrentIndex(0); |
72 modeChanged(0); |
107 modeChanged(0); |
73 deviceBox->setCurrentIndex(0); |
108 deviceBox->setCurrentIndex(0); |
74 deviceChanged(0); |
109 deviceChanged(0); |
79 } |
114 } |
80 |
115 |
81 void AudioTest::test() |
116 void AudioTest::test() |
82 { |
117 { |
83 // tries to set all the settings picked. |
118 // tries to set all the settings picked. |
84 logOutput->clear(); |
119 testResult->clear(); |
85 logOutput->append("NOTE: an invalid codec audio/test exists for testing, to get a fail condition."); |
|
86 |
120 |
87 if (!deviceInfo.isNull()) { |
121 if (!deviceInfo.isNull()) { |
88 if (deviceInfo.isFormatSupported(settings)) { |
122 if (deviceInfo.isFormatSupported(settings)) { |
89 logOutput->append(tr("Success")); |
123 testResult->setText(tr("Success")); |
90 nearestFreq->setText(""); |
124 nearestFreq->setText(""); |
91 nearestChannel->setText(""); |
125 nearestChannel->setText(""); |
92 nearestCodec->setText(""); |
126 nearestCodec->setText(""); |
93 nearestSampleSize->setText(""); |
127 nearestSampleSize->setText(""); |
94 nearestSampleType->setText(""); |
128 nearestSampleType->setText(""); |
95 nearestEndian->setText(""); |
129 nearestEndian->setText(""); |
96 } else { |
130 } else { |
97 QAudioFormat nearest = deviceInfo.nearestFormat(settings); |
131 QAudioFormat nearest = deviceInfo.nearestFormat(settings); |
98 logOutput->append(tr("Failed")); |
132 testResult->setText(tr("Failed")); |
99 nearestFreq->setText(QString("%1").arg(nearest.frequency())); |
133 nearestFreq->setText(QString("%1").arg(nearest.frequency())); |
100 nearestChannel->setText(QString("%1").arg(nearest.channels())); |
134 nearestChannel->setText(QString("%1").arg(nearest.channels())); |
101 nearestCodec->setText(nearest.codec()); |
135 nearestCodec->setText(nearest.codec()); |
102 nearestSampleSize->setText(QString("%1").arg(nearest.sampleSize())); |
136 nearestSampleSize->setText(QString("%1").arg(nearest.sampleSize())); |
103 |
137 nearestSampleType->setText(toString(nearest.sampleType())); |
104 switch(nearest.sampleType()) { |
138 nearestEndian->setText(toString(nearest.byteOrder())); |
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 } |
139 } |
125 } |
140 } |
126 else |
141 else |
127 logOutput->append(tr("No Device")); |
142 testResult->setText(tr("No Device")); |
128 } |
143 } |
129 |
144 |
130 void AudioTest::modeChanged(int idx) |
145 void AudioTest::modeChanged(int idx) |
131 { |
146 { |
|
147 testResult->clear(); |
|
148 |
132 // mode has changed |
149 // mode has changed |
133 if (idx == 0) |
150 if (idx == 0) |
134 mode = QAudio::AudioInput; |
151 mode = QAudio::AudioInput; |
135 else |
152 else |
136 mode = QAudio::AudioOutput; |
153 mode = QAudio::AudioOutput; |
137 |
154 |
138 deviceBox->clear(); |
155 deviceBox->clear(); |
139 foreach (const QAudioDeviceInfo &deviceInfo, QAudioDeviceInfo::availableDevices(mode)) |
156 foreach (const QAudioDeviceInfo &deviceInfo, QAudioDeviceInfo::availableDevices(mode)) |
140 deviceBox->addItem(deviceInfo.deviceName(), qVariantFromValue(deviceInfo)); |
157 deviceBox->addItem(deviceInfo.deviceName(), qVariantFromValue(deviceInfo)); |
|
158 |
|
159 deviceBox->setCurrentIndex(0); |
|
160 deviceChanged(0); |
141 } |
161 } |
142 |
162 |
143 void AudioTest::deviceChanged(int idx) |
163 void AudioTest::deviceChanged(int idx) |
144 { |
164 { |
|
165 testResult->clear(); |
|
166 |
145 if (deviceBox->count() == 0) |
167 if (deviceBox->count() == 0) |
146 return; |
168 return; |
147 |
169 |
148 // device has changed |
170 // device has changed |
149 deviceInfo = deviceBox->itemData(idx).value<QAudioDeviceInfo>(); |
171 deviceInfo = deviceBox->itemData(idx).value<QAudioDeviceInfo>(); |
178 if (sampleSizez.size()) |
200 if (sampleSizez.size()) |
179 settings.setSampleSize(sampleSizez.at(0)); |
201 settings.setSampleSize(sampleSizez.at(0)); |
180 |
202 |
181 sampleTypesBox->clear(); |
203 sampleTypesBox->clear(); |
182 QList<QAudioFormat::SampleType> sampleTypez = deviceInfo.supportedSampleTypes(); |
204 QList<QAudioFormat::SampleType> sampleTypez = deviceInfo.supportedSampleTypes(); |
183 for (int i = 0; i < sampleTypez.size(); ++i) { |
205 |
184 switch(sampleTypez.at(i)) { |
206 for (int i = 0; i < sampleTypez.size(); ++i) |
185 case QAudioFormat::SignedInt: |
207 sampleTypesBox->addItem(toString(sampleTypez.at(i))); |
186 sampleTypesBox->addItem("SignedInt"); |
208 if (sampleTypez.size()) |
187 break; |
209 settings.setSampleType(sampleTypez.at(0)); |
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 |
210 |
201 endianBox->clear(); |
211 endianBox->clear(); |
202 QList<QAudioFormat::Endian> endianz = deviceInfo.supportedByteOrders(); |
212 QList<QAudioFormat::Endian> endianz = deviceInfo.supportedByteOrders(); |
203 for (int i = 0; i < endianz.size(); ++i) { |
213 for (int i = 0; i < endianz.size(); ++i) |
204 switch (endianz.at(i)) { |
214 endianBox->addItem(toString(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()) |
215 if (endianz.size()) |
214 settings.setByteOrder(endianz.at(0)); |
216 settings.setByteOrder(endianz.at(0)); |
|
217 |
|
218 allFormatsTable->clearContents(); |
|
219 } |
|
220 |
|
221 void AudioTest::populateTable() |
|
222 { |
|
223 int row = 0; |
|
224 |
|
225 QAudioFormat format; |
|
226 foreach (QString codec, deviceInfo.supportedCodecs()) { |
|
227 format.setCodec(codec); |
|
228 foreach (int frequency, deviceInfo.supportedFrequencies()) { |
|
229 format.setFrequency(frequency); |
|
230 foreach (int channels, deviceInfo.supportedChannels()) { |
|
231 format.setChannels(channels); |
|
232 foreach (QAudioFormat::SampleType sampleType, deviceInfo.supportedSampleTypes()) { |
|
233 format.setSampleType(sampleType); |
|
234 foreach (int sampleSize, deviceInfo.supportedSampleSizes()) { |
|
235 format.setSampleSize(sampleSize); |
|
236 foreach (QAudioFormat::Endian endian, deviceInfo.supportedByteOrders()) { |
|
237 format.setByteOrder(endian); |
|
238 if (deviceInfo.isFormatSupported(format)) { |
|
239 allFormatsTable->setRowCount(row + 1); |
|
240 |
|
241 QTableWidgetItem *codecItem = new QTableWidgetItem(format.codec()); |
|
242 allFormatsTable->setItem(row, 0, codecItem); |
|
243 |
|
244 QTableWidgetItem *frequencyItem = new QTableWidgetItem(QString("%1").arg(format.frequency())); |
|
245 allFormatsTable->setItem(row, 1, frequencyItem); |
|
246 |
|
247 QTableWidgetItem *channelsItem = new QTableWidgetItem(QString("%1").arg(format.channels())); |
|
248 allFormatsTable->setItem(row, 2, channelsItem); |
|
249 |
|
250 QTableWidgetItem *sampleTypeItem = new QTableWidgetItem(toString(format.sampleType())); |
|
251 allFormatsTable->setItem(row, 3, sampleTypeItem); |
|
252 |
|
253 QTableWidgetItem *sampleSizeItem = new QTableWidgetItem(QString("%1").arg(format.sampleSize())); |
|
254 allFormatsTable->setItem(row, 4, sampleSizeItem); |
|
255 |
|
256 QTableWidgetItem *byteOrderItem = new QTableWidgetItem(toString(format.byteOrder())); |
|
257 allFormatsTable->setItem(row, 5, byteOrderItem); |
|
258 |
|
259 ++row; |
|
260 } |
|
261 } |
|
262 } |
|
263 } |
|
264 } |
|
265 } |
|
266 } |
215 } |
267 } |
216 |
268 |
217 void AudioTest::freqChanged(int idx) |
269 void AudioTest::freqChanged(int idx) |
218 { |
270 { |
219 // freq has changed |
271 // freq has changed |