summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/examples/opiemm/osoundsystemdemo/osoundsystemdemo.cpp3
-rw-r--r--libopie2/opiemm/osoundsystem.cpp25
-rw-r--r--libopie2/opiemm/osoundsystem.h6
3 files changed, 30 insertions, 4 deletions
diff --git a/libopie2/examples/opiemm/osoundsystemdemo/osoundsystemdemo.cpp b/libopie2/examples/opiemm/osoundsystemdemo/osoundsystemdemo.cpp
index b522441..f74a1b9 100644
--- a/libopie2/examples/opiemm/osoundsystemdemo/osoundsystemdemo.cpp
+++ b/libopie2/examples/opiemm/osoundsystemdemo/osoundsystemdemo.cpp
@@ -46,20 +46,21 @@ int main( int argc, char** argv )
++it;
}
*/
OSoundCard* card = it.current();
OMixerInterface* mixer = card->mixer();
QStringList channels = mixer->allChannels();
for ( QStringList::Iterator it = channels.begin(); it != channels.end(); ++it )
{
- odebug << "OSSDEMO: Mixer has channel " << *it << "" << oendl;
+ bool stereo = mixer->isStereo( *it );
+ odebug << "OSSDEMO: Mixer has channel " << *it << ( stereo ? "[stereo]" : "[mono]" ) << oendl;
odebug << "OSSDEMO: +--- volume " << ( mixer->volume( *it ) & 0xff )
<< " (left) | " << ( mixer->volume( *it ) >> 8 ) << " (right)" << oendl;
}
return 0;
}
diff --git a/libopie2/opiemm/osoundsystem.cpp b/libopie2/opiemm/osoundsystem.cpp
index 13b26e6..09fd28f 100644
--- a/libopie2/opiemm/osoundsystem.cpp
+++ b/libopie2/opiemm/osoundsystem.cpp
@@ -185,25 +185,25 @@ OMixerInterface::OMixerInterface( QObject* parent, const char* name )
OMixerInterface::~OMixerInterface()
{
}
void OMixerInterface::init()
{
// open the device
_fd = ::open( name(), O_RDWR );
if ( _fd == -1 )
{
- owarn << "OMixerInterface::init(): Can't open mixer." << oendl;
+ owarn << "OMixerInterface::init(): Can't open mixer " << name() << oendl;
return;
}
// construct the device capabilities
int devmask = 0;
if ( ioctl( _fd, SOUND_MIXER_READ_DEVMASK, &devmask ) != -1 )
{
if ( devmask & ( 1 << SOUND_MIXER_VOLUME ) ) _channels.insert( "PlayVolume", SOUND_MIXER_VOLUME );
if ( devmask & ( 1 << SOUND_MIXER_BASS ) ) _channels.insert( "PlayBass", SOUND_MIXER_BASS );
if ( devmask & ( 1 << SOUND_MIXER_TREBLE ) ) _channels.insert( "PlayTreble", SOUND_MIXER_TREBLE );
if ( devmask & ( 1 << SOUND_MIXER_SYNTH ) ) _channels.insert( "PlaySynth", SOUND_MIXER_SYNTH );
if ( devmask & ( 1 << SOUND_MIXER_PCM ) ) _channels.insert( "PlayPCM", SOUND_MIXER_PCM );
@@ -230,24 +230,30 @@ void OMixerInterface::init()
if ( devmask & ( 1 << SOUND_MIXER_SPEAKER ) ) _channels.insert( "RecSpeaker", SOUND_MIXER_SPEAKER );
if ( devmask & ( 1 << SOUND_MIXER_LINE ) ) _channels.insert( "RecLine", SOUND_MIXER_LINE );
if ( devmask & ( 1 << SOUND_MIXER_MIC ) ) _channels.insert( "RecMic", SOUND_MIXER_MIC );
if ( devmask & ( 1 << SOUND_MIXER_CD ) ) _channels.insert( "RecCD", SOUND_MIXER_CD );
if ( devmask & ( 1 << SOUND_MIXER_IMIX ) ) _channels.insert( "RecInputMix", SOUND_MIXER_IMIX );
if ( devmask & ( 1 << SOUND_MIXER_ALTPCM ) ) _channels.insert( "RecAltPCM", SOUND_MIXER_ALTPCM );
if ( devmask & ( 1 << SOUND_MIXER_RECLEV ) ) _channels.insert( "RecRecord", SOUND_MIXER_RECLEV );
if ( devmask & ( 1 << SOUND_MIXER_IGAIN ) ) _channels.insert( "RecInputGain", SOUND_MIXER_IGAIN );
if ( devmask & ( 1 << SOUND_MIXER_OGAIN ) ) _channels.insert( "RecOutputGain", SOUND_MIXER_OGAIN );
//odebug << "recmask available and constructed." << oendl;
}
+ devmask = 0;
+ if ( ioctl( _fd, SOUND_MIXER_READ_STEREODEVS, &devmask ) != -1 )
+ {
+ odebug << "stereomask = " << devmask << oendl;
+ }
+
/* ChannelIterator it;
for ( it = _channels.begin(); it != _channels.end(); ++it )
{
odebug << "Channel " << it.key() << " available (bit " << it.data() << ")" << oendl;
odebug << " +--- Volume: " << volume( it.key() ) & 0xff << " | " << volume( it.key() ) >> 8 << "" << oendl;
}
*/
}
QStringList OMixerInterface::allChannels() const
{
ChannelIterator it = _channels.begin();
@@ -266,30 +272,45 @@ QStringList OMixerInterface::recChannels() const
owarn << "NYI" << oendl;
return QStringList();
}
QStringList OMixerInterface::playChannels() const
{
owarn << "NYI" << oendl;
return QStringList();
}
-bool OMixerInterface::hasChannel( const QString& channel )
+bool OMixerInterface::hasChannel( const QString& channel ) const
{
return _channels.contains( channel );
}
+bool OMixerInterface::isStereo( const QString& channel ) const
+{
+ bool result = false;
+ if ( _channels.contains( channel ) )
+ {
+ int devmask = 0;
+ if ( ioctl( _fd, SOUND_MIXER_READ_STEREODEVS, &devmask ) != -1 )
+ {
+ result = devmask & ( 1 << _channels[channel] );
+ }
+ }
+ return result;
+}
+
+
void OMixerInterface::setVolume( const QString& channel, int left, int right )
{
int volume = left;
volume |= ( right == -1 ) ? left << 8 : right << 8;
if ( _channels.contains( channel ) )
{
int result = ioctl( _fd, MIXER_WRITE( _channels[channel] ), &volume );
if ( result == -1 )
{
owarn << "Can't set volume: " << strerror( errno ) << oendl;
}
diff --git a/libopie2/opiemm/osoundsystem.h b/libopie2/opiemm/osoundsystem.h
index bd69114..ac7a5a7 100644
--- a/libopie2/opiemm/osoundsystem.h
+++ b/libopie2/opiemm/osoundsystem.h
@@ -193,25 +193,29 @@ class OMixerInterface : public QObject
/**
* @returns recordable channels.
*/
QStringList recChannels() const;
/**
* @returns playable channels.
*/
QStringList playChannels() const;
/**
* @returns true, if @a channel exists.
*/
- bool hasChannel( const QString& channel );
+ bool hasChannel( const QString& channel ) const;
+ /**
+ * @returns true, if @a channel is stereo.
+ */
+ bool isStereo( const QString& channel ) const;
/**
* Set the @a left and @a right volumes for @a channel.
* If no value for right is given, the value for left is taken for that.
*/
void setVolume( const QString& channel, int left, int right = -1 );
/**
* @returns the volume of @a channel or -1, if the channel doesn't exist.
* @note You might want to use @ref hasChannel() to check if a channel exists.
*/
int volume( const QString& channel ) const;