summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-06-17 23:09:38 (UTC)
committer llornkcor <llornkcor>2002-06-17 23:09:38 (UTC)
commit554f88d0e8839bd6112fa42139a967712552e519 (patch) (side-by-side diff)
treed90788c9247f35ee10a1cdd8df0408b1df2a7e57
parent28400a31238af793fe235a0c8d13131eb823037d (diff)
downloadopie-554f88d0e8839bd6112fa42139a967712552e519.zip
opie-554f88d0e8839bd6112fa42139a967712552e519.tar.gz
opie-554f88d0e8839bd6112fa42139a967712552e519.tar.bz2
fixed volume fix
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/multimedia/opieplayer/audiodevice.cpp6
1 files changed, 3 insertions, 3 deletions
diff --git a/core/multimedia/opieplayer/audiodevice.cpp b/core/multimedia/opieplayer/audiodevice.cpp
index 4c5f12d..faadd72 100644
--- a/core/multimedia/opieplayer/audiodevice.cpp
+++ b/core/multimedia/opieplayer/audiodevice.cpp
@@ -77,195 +77,195 @@ public:
static unsigned int leftVolume;
static unsigned int rightVolume;
};
#ifdef Q_WS_QWS
// This is for keeping the device open in-between playing files when
// the device makes clicks and it starts to drive you insane! :)
// Best to have the device not open when not using it though
//#define KEEP_DEVICE_OPEN
#endif
int AudioDevicePrivate::dspFd = 0;
bool AudioDevicePrivate::muted = FALSE;
unsigned int AudioDevicePrivate::leftVolume = 0;
unsigned int AudioDevicePrivate::rightVolume = 0;
void AudioDevice::getVolume( unsigned int& leftVolume, unsigned int& rightVolume, bool &muted ) {
muted = AudioDevicePrivate::muted;
unsigned int volume;
// #ifdef Q_OS_WIN32
// HWAVEOUT handle;
// WAVEFORMATEX formatData;
// formatData.cbSize = sizeof(WAVEFORMATEX);
// formatData.wFormatTag = WAVE_FORMAT_PCM;
// formatData.nAvgBytesPerSec = 4 * 44000;
// formatData.nBlockAlign = 4;
// formatData.nChannels = 2;
// formatData.nSamplesPerSec = 44000;
// formatData.wBitsPerSample = 16;
// waveOutOpen(&handle, WAVE_MAPPER, &formatData, 0L, 0L, CALLBACK_NULL);
// if ( waveOutGetVolume( handle, (LPDWORD)&volume ) )
// // qDebug( "get volume of audio device failed" );
// waveOutClose( handle );
// leftVolume = volume & 0xFFFF;
// rightVolume = volume >> 16;
// #else
int mixerHandle = open( "/dev/mixer", O_RDWR );
if ( mixerHandle >= 0 ) {
if(ioctl( mixerHandle, MIXER_READ(0), &volume )==-1)
perror("ioctl(\"MIXER_READ\")");
close( mixerHandle );
} else
perror("open(\"/dev/mixer\")");
leftVolume = ((volume & 0x00FF) << 16) / 101;
rightVolume = ((volume & 0xFF00) << 8) / 101;
//#endif
}
void AudioDevice::setVolume( unsigned int leftVolume, unsigned int rightVolume, bool muted ) {
AudioDevicePrivate::muted = muted;
if ( muted ) {
AudioDevicePrivate::leftVolume = leftVolume;
AudioDevicePrivate::rightVolume = rightVolume;
leftVolume = 0;
rightVolume = 0;
} else {
leftVolume = ( (int) leftVolume < 0 ) ? 0 : (( leftVolume > 0xFFFF ) ? 0xFFFF : leftVolume );
rightVolume = ( (int)rightVolume < 0 ) ? 0 : (( rightVolume > 0xFFFF ) ? 0xFFFF : rightVolume );
}
// #ifdef Q_OS_WIN32
// HWAVEOUT handle;
// WAVEFORMATEX formatData;
// formatData.cbSize = sizeof(WAVEFORMATEX);
// formatData.wFormatTag = WAVE_FORMAT_PCM;
// formatData.nAvgBytesPerSec = 4 * 44000;
// formatData.nBlockAlign = 4;
// formatData.nChannels = 2;
// formatData.nSamplesPerSec = 44000;
// formatData.wBitsPerSample = 16;
// waveOutOpen(&handle, WAVE_MAPPER, &formatData, 0L, 0L, CALLBACK_NULL);
// unsigned int volume = (rightVolume << 16) | leftVolume;
// if ( waveOutSetVolume( handle, volume ) )
// // qDebug( "set volume of audio device failed" );
// waveOutClose( handle );
// #else
// Volume can be from 0 to 100 which is 101 distinct values
unsigned int rV = (rightVolume * 101) >> 16;
# if 0
unsigned int lV = (leftVolume * 101) >> 16;
unsigned int volume = ((rV << 8) & 0xFF00) | (lV & 0x00FF);
int mixerHandle = 0;
if ( ( mixerHandle = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
if(ioctl( mixerHandle, MIXER_WRITE(0), &volume ) ==-1)
perror("ioctl(\"MIXER_WRITE\")");
close( mixerHandle );
} else
perror("open(\"/dev/mixer\")");
# else
// This is the way this has to be done now I guess, doesn't allow for
// independant right and left channel setting, or setting for different outputs
- Config cfg("Sound");
- cfg.setGroup("System");
- cfg.writeEntry("Volume",(int)rV);
+ Config cfg("qpe"); // qtopia is "Sound"
+ cfg.setGroup("Volume"); // qtopia is "Settings"
+ cfg.writeEntry("VolumePercent",(int)rV); //qtopia is Volume
# endif
//#endif
// qDebug( "setting volume to: 0x%x", volume );
#if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP)
// Send notification that the volume has changed
QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << muted;
#endif
}
AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) {
qDebug("creating new audio device");
QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE;
d = new AudioDevicePrivate;
d->frequency = f;
d->channels = chs;
d->bytesPerSample = bps;
qDebug("%d",bps);
int format=0;
if( bps == 8) format = AFMT_U8;
else if( bps <= 0) format = AFMT_S16_LE;
else format = AFMT_S16_LE;
qDebug("AD- freq %d, channels %d, b/sample %d, bitrate %d",f,chs,bps,format);
connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( volumeChanged(bool) ) );
int fragments = 0x10000 * 8 + sound_fragment_shift;
int capabilities = 0;
#ifdef KEEP_DEVICE_OPEN
if ( AudioDevicePrivate::dspFd == 0 ) {
#endif
if ( ( d->handle = ::open( "/dev/dsp", O_WRONLY ) ) < 0 ) {
perror("open(\"/dev/dsp\") sending to /dev/null instead");
d->handle = ::open( "/dev/null", O_WRONLY );
}
#ifdef KEEP_DEVICE_OPEN
AudioDevicePrivate::dspFd = d->handle;
} else {
d->handle = AudioDevicePrivate::dspFd;
}
#endif
if(ioctl( d->handle, SNDCTL_DSP_GETCAPS, &capabilities )==-1)
perror("ioctl(\"SNDCTL_DSP_GETCAPS\")");
if(ioctl( d->handle, SNDCTL_DSP_SETFRAGMENT, &fragments )==-1)
perror("ioctl(\"SNDCTL_DSP_SETFRAGMENT\")");
if(ioctl( d->handle, SNDCTL_DSP_SETFMT, & format )==-1)
perror("ioctl(\"SNDCTL_DSP_SETFMT\")");
qDebug("freq %d", d->frequency);
if(ioctl( d->handle, SNDCTL_DSP_SPEED, &d->frequency )==-1)
perror("ioctl(\"SNDCTL_DSP_SPEED\")");
qDebug("channels %d",d->channels);
if ( ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels ) == -1 ) {
d->channels = ( d->channels == 1 ) ? 2 : d->channels;
if(ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels )==-1)
perror("ioctl(\"SNDCTL_DSP_CHANNELS\")");
}
d->bufferSize = sound_fragment_bytes;
d->unwrittenBuffer = new char[d->bufferSize];
d->unwritten = 0;
d->can_GETOSPACE = TRUE; // until we find otherwise
//if ( chs != d->channels ) qDebug( "Wanted %d, got %d channels", chs, d->channels );
//if ( f != d->frequency ) qDebug( "wanted %dHz, got %dHz", f, d->frequency );
//if ( capabilities & DSP_CAP_BATCH ) qDebug( "Sound card has local buffer" );
//if ( capabilities & DSP_CAP_REALTIME )qDebug( "Sound card has realtime sync" );
//if ( capabilities & DSP_CAP_TRIGGER ) qDebug( "Sound card has precise trigger" );
//if ( capabilities & DSP_CAP_MMAP ) qDebug( "Sound card can mmap" );
QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE;
}
AudioDevice::~AudioDevice() {
qDebug("destryo audiodevice");
QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE;
// #ifdef Q_OS_WIN32
// waveOutClose( (HWAVEOUT)d->handle );
// #else
# ifndef KEEP_DEVICE_OPEN
close( d->handle ); // Now it should be safe to shut the handle
# endif
delete d->unwrittenBuffer;
delete d;
//#endif
QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE;
}