Changeset 769 for trunk/examples/multimedia/audiodevices/audiodevices.cpp
- Timestamp:
- Aug 2, 2010, 9:27:30 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.6.3 (added) merged: 768 /branches/vendor/nokia/qt/current merged: 767 /branches/vendor/nokia/qt/4.6.2 removed
- Property svn:mergeinfo changed
-
trunk/examples/multimedia/audiodevices/audiodevices.cpp
r651 r769 44 44 45 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 81 AudioDevicesBase::AudioDevicesBase(QWidget *parent, Qt::WFlags f) … … 68 102 connect(sampleTypesBox, SIGNAL(activated(int)), SLOT(sampleTypeChanged(int))); 69 103 connect(endianBox, SIGNAL(activated(int)), SLOT(endianChanged(int))); 104 connect(populateTableButton, SIGNAL(clicked()), SLOT(populateTable())); 70 105 71 106 modeBox->setCurrentIndex(0); … … 82 117 { 83 118 // 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."); 119 testResult->clear(); 86 120 87 121 if (!deviceInfo.isNull()) { 88 122 if (deviceInfo.isFormatSupported(settings)) { 89 logOutput->append(tr("Success"));123 testResult->setText(tr("Success")); 90 124 nearestFreq->setText(""); 91 125 nearestChannel->setText(""); … … 96 130 } else { 97 131 QAudioFormat nearest = deviceInfo.nearestFormat(settings); 98 logOutput->append(tr("Failed"));132 testResult->setText(tr("Failed")); 99 133 nearestFreq->setText(QString("%1").arg(nearest.frequency())); 100 134 nearestChannel->setText(QString("%1").arg(nearest.channels())); 101 135 nearestCodec->setText(nearest.codec()); 102 136 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 } 137 nearestSampleType->setText(toString(nearest.sampleType())); 138 nearestEndian->setText(toString(nearest.byteOrder())); 124 139 } 125 140 } 126 141 else 127 logOutput->append(tr("No Device"));142 testResult->setText(tr("No Device")); 128 143 } 129 144 130 145 void AudioTest::modeChanged(int idx) 131 146 { 147 testResult->clear(); 148 132 149 // mode has changed 133 150 if (idx == 0) … … 139 156 foreach (const QAudioDeviceInfo &deviceInfo, QAudioDeviceInfo::availableDevices(mode)) 140 157 deviceBox->addItem(deviceInfo.deviceName(), qVariantFromValue(deviceInfo)); 158 159 deviceBox->setCurrentIndex(0); 160 deviceChanged(0); 141 161 } 142 162 143 163 void AudioTest::deviceChanged(int idx) 144 164 { 165 testResult->clear(); 166 145 167 if (deviceBox->count() == 0) 146 168 return; … … 181 203 sampleTypesBox->clear(); 182 204 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 } 205 206 for (int i = 0; i < sampleTypez.size(); ++i) 207 sampleTypesBox->addItem(toString(sampleTypez.at(i))); 208 if (sampleTypez.size()) 209 settings.setSampleType(sampleTypez.at(0)); 200 210 201 211 endianBox->clear(); 202 212 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 for (int i = 0; i < endianz.size(); ++i) 214 endianBox->addItem(toString(endianz.at(i))); 213 215 if (endianz.size()) 214 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
Note:
See TracChangeset
for help on using the changeset viewer.