diff options
author | Kurt Korbatits <kurt.korbatits@nokia.com> | 2009-09-14 02:33:37 (GMT) |
---|---|---|
committer | Kurt Korbatits <kurt.korbatits@nokia.com> | 2009-09-14 02:33:37 (GMT) |
commit | f3e2ccf63de242feeba10e75fd00ffd43fc038b0 (patch) | |
tree | e202fecb0507aafc837ef169605c3389f4649526 /src/multimedia | |
parent | 9fe43c999d3d9b21836345522bb67bab38e661af (diff) | |
download | Qt-f3e2ccf63de242feeba10e75fd00ffd43fc038b0.zip Qt-f3e2ccf63de242feeba10e75fd00ffd43fc038b0.tar.gz Qt-f3e2ccf63de242feeba10e75fd00ffd43fc038b0.tar.bz2 |
AudioDevices demo doesn't do anything on Windows
-put example audiodevices in layout.
-added more checking to testSettings() in win32 implementation.
-disabled objects in example audiodevices that are not editable.
-added more checking to alsa implementation for preferredFormat().
-changed internal strings from tr to QLatin1String.
Reviewed-by:Justin Mcpherson
Diffstat (limited to 'src/multimedia')
-rw-r--r-- | src/multimedia/audio/qaudiodeviceinfo_alsa_p.cpp | 67 | ||||
-rw-r--r-- | src/multimedia/audio/qaudiodeviceinfo_win32_p.cpp | 36 | ||||
-rw-r--r-- | src/multimedia/audio/qaudioinput_alsa_p.cpp | 8 | ||||
-rw-r--r-- | src/multimedia/audio/qaudioinput_win32_p.cpp | 2 | ||||
-rw-r--r-- | src/multimedia/audio/qaudiooutput_alsa_p.cpp | 8 | ||||
-rw-r--r-- | src/multimedia/audio/qaudiooutput_win32_p.cpp | 2 |
6 files changed, 81 insertions, 42 deletions
diff --git a/src/multimedia/audio/qaudiodeviceinfo_alsa_p.cpp b/src/multimedia/audio/qaudiodeviceinfo_alsa_p.cpp index 4ed1b41..c944cf0 100644 --- a/src/multimedia/audio/qaudiodeviceinfo_alsa_p.cpp +++ b/src/multimedia/audio/qaudiodeviceinfo_alsa_p.cpp @@ -81,13 +81,18 @@ QAudioFormat QAudioDeviceInfoPrivate::preferredFormat() const nearest.setByteOrder(QAudioFormat::LittleEndian); nearest.setSampleType(QAudioFormat::SignedInt); nearest.setSampleSize(16); - nearest.setCodec(tr("audio/pcm")); + nearest.setCodec(QLatin1String("audio/pcm")); } else { nearest.setFrequency(8000); nearest.setChannels(1); - nearest.setSampleType(QAudioFormat::SignedInt); + nearest.setSampleType(QAudioFormat::UnSignedInt); nearest.setSampleSize(8); - nearest.setCodec(tr("audio/pcm")); + nearest.setCodec(QLatin1String("audio/pcm")); + if(!testSettings(nearest)) { + nearest.setChannels(2); + nearest.setSampleSize(16); + nearest.setSampleType(QAudioFormat::SignedInt); + } } return nearest; } @@ -145,9 +150,9 @@ bool QAudioDeviceInfoPrivate::open() { int err = 0; QString dev = device; - if(!dev.contains(tr("default"))) { + if(!dev.contains(QLatin1String("default"))) { int idx = snd_card_get_index(dev.toLocal8Bit().constData()); - dev = QString(tr("hw:%1,0")).arg(idx); + dev = QString(QLatin1String("hw:%1,0")).arg(idx); } if(mode == QAudio::AudioOutput) { err=snd_pcm_open( &handle,dev.toLocal8Bit().constData(),SND_PCM_STREAM_PLAYBACK,0); @@ -172,16 +177,15 @@ bool QAudioDeviceInfoPrivate::testSettings(const QAudioFormat& format) const { // Set nearest to closest settings that do work. // See if what is in settings will work (return value). - int err = 0; snd_pcm_t* handle; snd_pcm_hw_params_t *params; QString dev = device; // open() - if(!dev.contains(tr("default"))) { + if(!dev.contains(QLatin1String("default"))) { int idx = snd_card_get_index(dev.toLocal8Bit().constData()); - dev = QString(tr("hw:%1,0")).arg(idx); + dev = QString(QLatin1String("hw:%1,0")).arg(idx); } if(mode == QAudio::AudioOutput) { err=snd_pcm_open( &handle,dev.toLocal8Bit().constData(),SND_PCM_STREAM_PLAYBACK,0); @@ -205,8 +209,45 @@ bool QAudioDeviceInfoPrivate::testSettings(const QAudioFormat& format) const snd_pcm_hw_params_alloca( ¶ms ); snd_pcm_hw_params_any( handle, params ); + // set the values! + snd_pcm_hw_params_set_channels(handle,params,format.channels()); + snd_pcm_hw_params_set_rate(handle,params,format.frequency(),dir); + switch(format.sampleSize()) { + case 8: + if(format.sampleType() == QAudioFormat::SignedInt) + snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S8); + else if(format.sampleType() == QAudioFormat::UnSignedInt) + snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U8); + break; + case 16: + if(format.sampleType() == QAudioFormat::SignedInt) { + if(format.byteOrder() == QAudioFormat::LittleEndian) + snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S16_LE); + else if(format.byteOrder() == QAudioFormat::BigEndian) + snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S16_BE); + } else if(format.sampleType() == QAudioFormat::UnSignedInt) { + if(format.byteOrder() == QAudioFormat::LittleEndian) + snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U16_LE); + else if(format.byteOrder() == QAudioFormat::BigEndian) + snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U16_BE); + } + break; + case 32: + if(format.sampleType() == QAudioFormat::SignedInt) { + if(format.byteOrder() == QAudioFormat::LittleEndian) + snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S32_LE); + else if(format.byteOrder() == QAudioFormat::BigEndian) + snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S32_BE); + } else if(format.sampleType() == QAudioFormat::UnSignedInt) { + if(format.byteOrder() == QAudioFormat::LittleEndian) + snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U32_LE); + else if(format.byteOrder() == QAudioFormat::BigEndian) + snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U32_BE); + } + } + // For now, just accept only audio/pcm codec - if(!format.codec().startsWith(tr("audio/pcm"))) { + if(!format.codec().startsWith(QLatin1String("audio/pcm"))) { err=-1; } else testCodec = true; @@ -313,7 +354,7 @@ void QAudioDeviceInfoPrivate::updateLists() typez.append(QAudioFormat::SignedInt); typez.append(QAudioFormat::UnSignedInt); typez.append(QAudioFormat::Float); - codecz.append(tr("audio/pcm")); + codecz.append(QLatin1String("audio/pcm")); close(); } @@ -346,10 +387,10 @@ QList<QByteArray> QAudioDeviceInfoPrivate::deviceList(QAudio::Mode mode) if(io == NULL) _m = mode; - QString str = tr(name); + QString str = QLatin1String(name); - if(str.contains(tr("default"))) { - int pos = str.indexOf(tr("="),0); + if(str.contains(QLatin1String("default"))) { + int pos = str.indexOf(QLatin1String("="),0); devices.append(str.mid(pos+1).toLocal8Bit().constData()); } } diff --git a/src/multimedia/audio/qaudiodeviceinfo_win32_p.cpp b/src/multimedia/audio/qaudiodeviceinfo_win32_p.cpp index 371f442..ba9f5e2 100644 --- a/src/multimedia/audio/qaudiodeviceinfo_win32_p.cpp +++ b/src/multimedia/audio/qaudiodeviceinfo_win32_p.cpp @@ -99,13 +99,13 @@ QAudioFormat QAudioDeviceInfoPrivate::preferredFormat() const nearest.setByteOrder(QAudioFormat::LittleEndian); nearest.setSampleType(QAudioFormat::SignedInt); nearest.setSampleSize(16); - nearest.setCodec(tr("audio/pcm")); + nearest.setCodec(QLatin1String("audio/pcm")); } else { nearest.setFrequency(11025); nearest.setChannels(1); nearest.setSampleType(QAudioFormat::SignedInt); nearest.setSampleSize(8); - nearest.setCodec(tr("audio/pcm")); + nearest.setCodec(QLatin1String("audio/pcm")); } return nearest; } @@ -174,27 +174,25 @@ bool QAudioDeviceInfoPrivate::testSettings(const QAudioFormat& format) const // Set nearest to closest settings that do work. // See if what is in settings will work (return value). - bool testChannel = false; - bool testCodec = false; - bool testFreq = false; - - int err = 0; + bool failed = false; // For now, just accept only audio/pcm codec - if(!format.codec().startsWith(tr("audio/pcm"))) { - err=-1; - } else - testCodec = true; + if(!format.codec().startsWith(QLatin1String("audio/pcm"))) + failed = true; - if(err>=0 && format.channels() != -1) { - testChannel = true; - } + if(!failed && !(format.channels() == 1 || format.channels() == 2)) + failed = true; - if(err>=0 && format.frequency() != -1) { - testFreq = true; + if(!failed) { + if(!(format.frequency() == 8000 || format.frequency() == 11025 || format.frequency() == 22050 || + format.frequency() == 44100 || format.frequency() == 48000 || format.frequency() == 96000)) + failed = true; } - if(err == 0) { + if(!failed && !(format.sampleSize() == 8 || format.sampleSize() == 16)) + failed = true; + + if(!failed) { // settings work return true; } @@ -209,7 +207,7 @@ void QAudioDeviceInfoPrivate::updateLists() DWORD fmt = NULL; QString tmp; - if(device.compare(tr("default")) == 0) + if(device.compare(QLatin1String("default")) == 0) base = true; if(mode == QAudio::AudioOutput) { @@ -331,7 +329,7 @@ void QAudioDeviceInfoPrivate::updateLists() typez.append(QAudioFormat::SignedInt); typez.append(QAudioFormat::UnSignedInt); - codecz.append(tr("audio/pcm")); + codecz.append(QLatin1String("audio/pcm")); } } diff --git a/src/multimedia/audio/qaudioinput_alsa_p.cpp b/src/multimedia/audio/qaudioinput_alsa_p.cpp index c98102c..f36ffc8 100644 --- a/src/multimedia/audio/qaudioinput_alsa_p.cpp +++ b/src/multimedia/audio/qaudioinput_alsa_p.cpp @@ -78,7 +78,7 @@ QAudioInputPrivate::QAudioInputPrivate(const QByteArray &device, const QAudioFor pullMode = true; resuming = false; - QStringList list1 = QString(tr(device)).split(tr(":")); + QStringList list1 = QString(QLatin1String(device)).split(QLatin1String(":")); m_device = QByteArray(list1.at(0).toLocal8Bit().constData()); timer = new QTimer(this); @@ -254,9 +254,9 @@ bool QAudioInputPrivate::open() int count=0; unsigned int freakuency=settings.frequency(); - QString dev = QString(tr(m_device.constData())); - if(!dev.contains(tr("default"))) { - dev = QString(tr("default:CARD=%1")).arg(tr(m_device.constData())); + QString dev = QString(QLatin1String(m_device.constData())); + if(!dev.contains(QLatin1String("default"))) { + dev = QString(QLatin1String("default:CARD=%1")).arg(QLatin1String(m_device.constData())); } // Step 1: try and open the device diff --git a/src/multimedia/audio/qaudioinput_win32_p.cpp b/src/multimedia/audio/qaudioinput_win32_p.cpp index 315a59b..31441ae 100644 --- a/src/multimedia/audio/qaudioinput_win32_p.cpp +++ b/src/multimedia/audio/qaudioinput_win32_p.cpp @@ -245,7 +245,7 @@ bool QAudioInputPrivate::open() == MMSYSERR_NOERROR) { QString tmp; tmp = QString::fromUtf16((const unsigned short*)wic.szPname); - if(tmp.compare(tr(m_device)) == 0) { + if(tmp.compare(QLatin1String(m_device)) == 0) { devId = ii; break; } diff --git a/src/multimedia/audio/qaudiooutput_alsa_p.cpp b/src/multimedia/audio/qaudiooutput_alsa_p.cpp index 45ff115..e8a3f5c 100644 --- a/src/multimedia/audio/qaudiooutput_alsa_p.cpp +++ b/src/multimedia/audio/qaudiooutput_alsa_p.cpp @@ -81,7 +81,7 @@ QAudioOutputPrivate::QAudioOutputPrivate(const QByteArray &device, const QAudioF resuming = false; opened = false; - QStringList list1 = QString(tr(device)).split(tr(":")); + QStringList list1 = QString(QLatin1String(device)).split(QLatin1String(":")); m_device = QByteArray(list1.at(0).toLocal8Bit().constData()); timer = new QTimer(this); @@ -277,9 +277,9 @@ bool QAudioOutputPrivate::open() int count=0; unsigned int freakuency=settings.frequency(); - QString dev = tr(m_device.constData()); - if(!dev.contains(tr("default"))) { - dev = QString(tr("default:CARD=%1")).arg(tr(m_device.constData())); + QString dev = QLatin1String(m_device.constData()); + if(!dev.contains(QLatin1String("default"))) { + dev = QString(QLatin1String("default:CARD=%1")).arg(QLatin1String(m_device.constData())); } // Step 1: try and open the device while((count < 5) && (err < 0)) { diff --git a/src/multimedia/audio/qaudiooutput_win32_p.cpp b/src/multimedia/audio/qaudiooutput_win32_p.cpp index fae680c..aea3a3f 100644 --- a/src/multimedia/audio/qaudiooutput_win32_p.cpp +++ b/src/multimedia/audio/qaudiooutput_win32_p.cpp @@ -241,7 +241,7 @@ bool QAudioOutputPrivate::open() == MMSYSERR_NOERROR) { QString tmp; tmp = QString::fromUtf16((const unsigned short*)woc.szPname); - if(tmp.compare(tr(m_device)) == 0) { + if(tmp.compare(QLatin1String(m_device)) == 0) { devId = ii; break; } |