summaryrefslogtreecommitdiffstats
path: root/src/multimedia/audio/qaudiodeviceinfo_alsa_p.cpp
diff options
context:
space:
mode:
authorKurt Korbatits <kurt.korbatits@nokia.com>2009-09-14 12:33:37 +1000
committerKurt Korbatits <kurt.korbatits@nokia.com>2009-09-14 12:33:37 +1000
commitf3e2ccf63de242feeba10e75fd00ffd43fc038b0 (patch)
treee202fecb0507aafc837ef169605c3389f4649526 /src/multimedia/audio/qaudiodeviceinfo_alsa_p.cpp
parent9fe43c999d3d9b21836345522bb67bab38e661af (diff)
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/audio/qaudiodeviceinfo_alsa_p.cpp')
-rw-r--r--src/multimedia/audio/qaudiodeviceinfo_alsa_p.cpp67
1 files changed, 54 insertions, 13 deletions
diff --git a/src/multimedia/audio/qaudiodeviceinfo_alsa_p.cpp b/src/multimedia/audio/qaudiodeviceinfo_alsa_p.cpp
index 4ed1b41f46..c944cf0a1d 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( &params );
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());
}
}