summaryrefslogtreecommitdiff
path: root/core/multimedia/opieplayer/audiodevice.cpp
Unidiff
Diffstat (limited to 'core/multimedia/opieplayer/audiodevice.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/multimedia/opieplayer/audiodevice.cpp15
1 files changed, 12 insertions, 3 deletions
diff --git a/core/multimedia/opieplayer/audiodevice.cpp b/core/multimedia/opieplayer/audiodevice.cpp
index d01d2ba..6a38fc9 100644
--- a/core/multimedia/opieplayer/audiodevice.cpp
+++ b/core/multimedia/opieplayer/audiodevice.cpp
@@ -82,25 +82,29 @@ public:
82#endif 82#endif
83 83
84 84
85int AudioDevicePrivate::dspFd = 0; 85int AudioDevicePrivate::dspFd = 0;
86bool AudioDevicePrivate::muted = FALSE; 86bool AudioDevicePrivate::muted = FALSE;
87unsigned int AudioDevicePrivate::leftVolume = 0; 87unsigned int AudioDevicePrivate::leftVolume = 0;
88unsigned int AudioDevicePrivate::rightVolume = 0; 88unsigned int AudioDevicePrivate::rightVolume = 0;
89 89
90 90
91void AudioDevice::getVolume( unsigned int& leftVolume, unsigned int& rightVolume, bool &muted ) { 91void AudioDevice::getVolume( unsigned int& leftVolume, unsigned int& rightVolume, bool &muted ) {
92 muted = AudioDevicePrivate::muted; 92 muted = AudioDevicePrivate::muted;
93 unsigned int volume; 93 unsigned int volume;
94#ifdef QT_QWS_DEVFS
95 int mixerHandle = open( "/dev/sound/mixer", O_RDWR );
96#else
94 int mixerHandle = open( "/dev/mixer", O_RDWR ); 97 int mixerHandle = open( "/dev/mixer", O_RDWR );
98#endif
95 if ( mixerHandle >= 0 ) { 99 if ( mixerHandle >= 0 ) {
96 if(ioctl( mixerHandle, MIXER_READ(0), &volume )==-1) 100 if(ioctl( mixerHandle, MIXER_READ(0), &volume )==-1)
97 perror("ioctl(\"MIXER_READ\")"); 101 perror("ioctl(\"MIXER_READ\")");
98 close( mixerHandle ); 102 close( mixerHandle );
99 } else 103 } else
100 perror("open(\"/dev/mixer\")"); 104 perror("open(\"/dev/mixer\")");
101 leftVolume = ((volume & 0x00FF) << 16) / 101; 105 leftVolume = ((volume & 0x00FF) << 16) / 101;
102 rightVolume = ((volume & 0xFF00) << 8) / 101; 106 rightVolume = ((volume & 0xFF00) << 8) / 101;
103} 107}
104 108
105 109
106void AudioDevice::setVolume( unsigned int leftVolume, unsigned int rightVolume, bool muted ) { 110void AudioDevice::setVolume( unsigned int leftVolume, unsigned int rightVolume, bool muted ) {
@@ -112,25 +116,29 @@ void AudioDevice::setVolume( unsigned int leftVolume, unsigned int rightVolume,
112 rightVolume = 0; 116 rightVolume = 0;
113 } else { 117 } else {
114 leftVolume = ( (int) leftVolume < 0 ) ? 0 : (( leftVolume > 0xFFFF ) ? 0xFFFF : leftVolume ); 118 leftVolume = ( (int) leftVolume < 0 ) ? 0 : (( leftVolume > 0xFFFF ) ? 0xFFFF : leftVolume );
115 rightVolume = ( (int)rightVolume < 0 ) ? 0 : (( rightVolume > 0xFFFF ) ? 0xFFFF : rightVolume ); 119 rightVolume = ( (int)rightVolume < 0 ) ? 0 : (( rightVolume > 0xFFFF ) ? 0xFFFF : rightVolume );
116 } 120 }
117 // Volume can be from 0 to 100 which is 101 distinct values 121 // Volume can be from 0 to 100 which is 101 distinct values
118 unsigned int rV = (rightVolume * 101) >> 16; 122 unsigned int rV = (rightVolume * 101) >> 16;
119 123
120# if 0 124# if 0
121 unsigned int lV = (leftVolume * 101) >> 16; 125 unsigned int lV = (leftVolume * 101) >> 16;
122 unsigned int volume = ((rV << 8) & 0xFF00) | (lV & 0x00FF); 126 unsigned int volume = ((rV << 8) & 0xFF00) | (lV & 0x00FF);
123 int mixerHandle = 0; 127 int mixerHandle = 0;
128#ifdef QT_QWS_DEVFS
129 if ( ( mixerHandle = open( "/dev/sound/mixer", O_RDWR ) ) >= 0 ) {
130#else
124 if ( ( mixerHandle = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 131 if ( ( mixerHandle = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
132#endif
125 if(ioctl( mixerHandle, MIXER_WRITE(0), &volume ) ==-1) 133 if(ioctl( mixerHandle, MIXER_WRITE(0), &volume ) ==-1)
126 perror("ioctl(\"MIXER_WRITE\")"); 134 perror("ioctl(\"MIXER_WRITE\")");
127 close( mixerHandle ); 135 close( mixerHandle );
128 } else 136 } else
129 perror("open(\"/dev/mixer\")"); 137 perror("open(\"/dev/mixer\")");
130 138
131# else 139# else
132 // This is the way this has to be done now I guess, doesn't allow for 140 // This is the way this has to be done now I guess, doesn't allow for
133 // independant right and left channel setting, or setting for different outputs 141 // independant right and left channel setting, or setting for different outputs
134 Config cfg("qpe"); // qtopia is "Sound" 142 Config cfg("qpe"); // qtopia is "Sound"
135 cfg.setGroup("Volume"); // qtopia is "Settings" 143 cfg.setGroup("Volume"); // qtopia is "Settings"
136 cfg.writeEntry("VolumePercent",(int)rV); //qtopia is Volume 144 cfg.writeEntry("VolumePercent",(int)rV); //qtopia is Volume
@@ -159,33 +167,34 @@ AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) {
159 else if( bps <= 0) format = AFMT_S16_LE; 167 else if( bps <= 0) format = AFMT_S16_LE;
160 else format = AFMT_S16_LE; 168 else format = AFMT_S16_LE;
161 // qDebug("AD- freq %d, channels %d, b/sample %d, bitrate %d",f,chs,bps,format); 169 // qDebug("AD- freq %d, channels %d, b/sample %d, bitrate %d",f,chs,bps,format);
162 connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( volumeChanged(bool) ) ); 170 connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( volumeChanged(bool) ) );
163 171
164 int fragments = 0x10000 * 8 + sound_fragment_shift; 172 int fragments = 0x10000 * 8 + sound_fragment_shift;
165 int capabilities = 0; 173 int capabilities = 0;
166 174
167 175
168#ifdef KEEP_DEVICE_OPEN 176#ifdef KEEP_DEVICE_OPEN
169 if ( AudioDevicePrivate::dspFd == 0 ) { 177 if ( AudioDevicePrivate::dspFd == 0 ) {
170#endif 178#endif
179#ifdef QT_QWS_DEVFS
180 if ( ( d->handle = ::open( "/dev/sound/dsp", O_WRONLY ) ) < 0 ) {
181#else
171 if ( ( d->handle = ::open( "/dev/dsp", O_WRONLY ) ) < 0 ) { 182 if ( ( d->handle = ::open( "/dev/dsp", O_WRONLY ) ) < 0 ) {
183#endif
172 184
173// perror("open(\"/dev/dsp\") sending to /dev/null instead");
174 perror("open(\"/dev/dsp\")"); 185 perror("open(\"/dev/dsp\")");
175 QString errorMsg=tr("Somethin's wrong with\nyour sound device.\nopen(\"/dev/dsp\")\n")+(QString)strerror(errno)+tr("\n\nClosing player now."); 186 QString errorMsg=tr("Somethin's wrong with\nyour sound device.\nopen(\"/dev/dsp\")\n")+(QString)strerror(errno)+tr("\n\nClosing player now.");
176 QMessageBox::critical(0, "Vmemo", errorMsg, tr("Abort")); 187 QMessageBox::critical(0, "Vmemo", errorMsg, tr("Abort"));
177 exit(-1); //harsh? 188 exit(-1); //harsh?
178// d->handle = ::open( "/dev/null", O_WRONLY );
179 // WTF?!?!
180 } 189 }
181#ifdef KEEP_DEVICE_OPEN 190#ifdef KEEP_DEVICE_OPEN
182 AudioDevicePrivate::dspFd = d->handle; 191 AudioDevicePrivate::dspFd = d->handle;
183 } else { 192 } else {
184 d->handle = AudioDevicePrivate::dspFd; 193 d->handle = AudioDevicePrivate::dspFd;
185 } 194 }
186#endif 195#endif
187 196
188 if(ioctl( d->handle, SNDCTL_DSP_GETCAPS, &capabilities )==-1) 197 if(ioctl( d->handle, SNDCTL_DSP_GETCAPS, &capabilities )==-1)
189 perror("ioctl(\"SNDCTL_DSP_GETCAPS\")"); 198 perror("ioctl(\"SNDCTL_DSP_GETCAPS\")");
190 if(ioctl( d->handle, SNDCTL_DSP_SETFRAGMENT, &fragments )==-1) 199 if(ioctl( d->handle, SNDCTL_DSP_SETFRAGMENT, &fragments )==-1)
191 perror("ioctl(\"SNDCTL_DSP_SETFRAGMENT\")"); 200 perror("ioctl(\"SNDCTL_DSP_SETFRAGMENT\")");