author | llornkcor <llornkcor> | 2002-06-17 23:09:38 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-06-17 23:09:38 (UTC) |
commit | 554f88d0e8839bd6112fa42139a967712552e519 (patch) (unidiff) | |
tree | d90788c9247f35ee10a1cdd8df0408b1df2a7e57 | |
parent | 28400a31238af793fe235a0c8d13131eb823037d (diff) | |
download | opie-554f88d0e8839bd6112fa42139a967712552e519.zip opie-554f88d0e8839bd6112fa42139a967712552e519.tar.gz opie-554f88d0e8839bd6112fa42139a967712552e519.tar.bz2 |
fixed volume fix
-rw-r--r-- | core/multimedia/opieplayer/audiodevice.cpp | 6 |
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 | |||
@@ -109,131 +109,131 @@ void AudioDevice::getVolume( unsigned int& leftVolume, unsigned int& rightVolume | |||
109 | // waveOutOpen(&handle, WAVE_MAPPER, &formatData, 0L, 0L, CALLBACK_NULL); | 109 | // waveOutOpen(&handle, WAVE_MAPPER, &formatData, 0L, 0L, CALLBACK_NULL); |
110 | // if ( waveOutGetVolume( handle, (LPDWORD)&volume ) ) | 110 | // if ( waveOutGetVolume( handle, (LPDWORD)&volume ) ) |
111 | // // qDebug( "get volume of audio device failed" ); | 111 | // // qDebug( "get volume of audio device failed" ); |
112 | // waveOutClose( handle ); | 112 | // waveOutClose( handle ); |
113 | // leftVolume = volume & 0xFFFF; | 113 | // leftVolume = volume & 0xFFFF; |
114 | // rightVolume = volume >> 16; | 114 | // rightVolume = volume >> 16; |
115 | // #else | 115 | // #else |
116 | int mixerHandle = open( "/dev/mixer", O_RDWR ); | 116 | int mixerHandle = open( "/dev/mixer", O_RDWR ); |
117 | if ( mixerHandle >= 0 ) { | 117 | if ( mixerHandle >= 0 ) { |
118 | if(ioctl( mixerHandle, MIXER_READ(0), &volume )==-1) | 118 | if(ioctl( mixerHandle, MIXER_READ(0), &volume )==-1) |
119 | perror("ioctl(\"MIXER_READ\")"); | 119 | perror("ioctl(\"MIXER_READ\")"); |
120 | close( mixerHandle ); | 120 | close( mixerHandle ); |
121 | } else | 121 | } else |
122 | perror("open(\"/dev/mixer\")"); | 122 | perror("open(\"/dev/mixer\")"); |
123 | leftVolume = ((volume & 0x00FF) << 16) / 101; | 123 | leftVolume = ((volume & 0x00FF) << 16) / 101; |
124 | rightVolume = ((volume & 0xFF00) << 8) / 101; | 124 | rightVolume = ((volume & 0xFF00) << 8) / 101; |
125 | //#endif | 125 | //#endif |
126 | } | 126 | } |
127 | 127 | ||
128 | 128 | ||
129 | void AudioDevice::setVolume( unsigned int leftVolume, unsigned int rightVolume, bool muted ) { | 129 | void AudioDevice::setVolume( unsigned int leftVolume, unsigned int rightVolume, bool muted ) { |
130 | AudioDevicePrivate::muted = muted; | 130 | AudioDevicePrivate::muted = muted; |
131 | if ( muted ) { | 131 | if ( muted ) { |
132 | AudioDevicePrivate::leftVolume = leftVolume; | 132 | AudioDevicePrivate::leftVolume = leftVolume; |
133 | AudioDevicePrivate::rightVolume = rightVolume; | 133 | AudioDevicePrivate::rightVolume = rightVolume; |
134 | leftVolume = 0; | 134 | leftVolume = 0; |
135 | rightVolume = 0; | 135 | rightVolume = 0; |
136 | } else { | 136 | } else { |
137 | leftVolume = ( (int) leftVolume < 0 ) ? 0 : (( leftVolume > 0xFFFF ) ? 0xFFFF : leftVolume ); | 137 | leftVolume = ( (int) leftVolume < 0 ) ? 0 : (( leftVolume > 0xFFFF ) ? 0xFFFF : leftVolume ); |
138 | rightVolume = ( (int)rightVolume < 0 ) ? 0 : (( rightVolume > 0xFFFF ) ? 0xFFFF : rightVolume ); | 138 | rightVolume = ( (int)rightVolume < 0 ) ? 0 : (( rightVolume > 0xFFFF ) ? 0xFFFF : rightVolume ); |
139 | } | 139 | } |
140 | // #ifdef Q_OS_WIN32 | 140 | // #ifdef Q_OS_WIN32 |
141 | // HWAVEOUT handle; | 141 | // HWAVEOUT handle; |
142 | // WAVEFORMATEX formatData; | 142 | // WAVEFORMATEX formatData; |
143 | // formatData.cbSize = sizeof(WAVEFORMATEX); | 143 | // formatData.cbSize = sizeof(WAVEFORMATEX); |
144 | // formatData.wFormatTag = WAVE_FORMAT_PCM; | 144 | // formatData.wFormatTag = WAVE_FORMAT_PCM; |
145 | // formatData.nAvgBytesPerSec = 4 * 44000; | 145 | // formatData.nAvgBytesPerSec = 4 * 44000; |
146 | // formatData.nBlockAlign = 4; | 146 | // formatData.nBlockAlign = 4; |
147 | // formatData.nChannels = 2; | 147 | // formatData.nChannels = 2; |
148 | // formatData.nSamplesPerSec = 44000; | 148 | // formatData.nSamplesPerSec = 44000; |
149 | // formatData.wBitsPerSample = 16; | 149 | // formatData.wBitsPerSample = 16; |
150 | // waveOutOpen(&handle, WAVE_MAPPER, &formatData, 0L, 0L, CALLBACK_NULL); | 150 | // waveOutOpen(&handle, WAVE_MAPPER, &formatData, 0L, 0L, CALLBACK_NULL); |
151 | // unsigned int volume = (rightVolume << 16) | leftVolume; | 151 | // unsigned int volume = (rightVolume << 16) | leftVolume; |
152 | // if ( waveOutSetVolume( handle, volume ) ) | 152 | // if ( waveOutSetVolume( handle, volume ) ) |
153 | // // qDebug( "set volume of audio device failed" ); | 153 | // // qDebug( "set volume of audio device failed" ); |
154 | // waveOutClose( handle ); | 154 | // waveOutClose( handle ); |
155 | // #else | 155 | // #else |
156 | // Volume can be from 0 to 100 which is 101 distinct values | 156 | // Volume can be from 0 to 100 which is 101 distinct values |
157 | unsigned int rV = (rightVolume * 101) >> 16; | 157 | unsigned int rV = (rightVolume * 101) >> 16; |
158 | 158 | ||
159 | # if 0 | 159 | # if 0 |
160 | unsigned int lV = (leftVolume * 101) >> 16; | 160 | unsigned int lV = (leftVolume * 101) >> 16; |
161 | unsigned int volume = ((rV << 8) & 0xFF00) | (lV & 0x00FF); | 161 | unsigned int volume = ((rV << 8) & 0xFF00) | (lV & 0x00FF); |
162 | int mixerHandle = 0; | 162 | int mixerHandle = 0; |
163 | if ( ( mixerHandle = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { | 163 | if ( ( mixerHandle = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { |
164 | if(ioctl( mixerHandle, MIXER_WRITE(0), &volume ) ==-1) | 164 | if(ioctl( mixerHandle, MIXER_WRITE(0), &volume ) ==-1) |
165 | perror("ioctl(\"MIXER_WRITE\")"); | 165 | perror("ioctl(\"MIXER_WRITE\")"); |
166 | close( mixerHandle ); | 166 | close( mixerHandle ); |
167 | } else | 167 | } else |
168 | perror("open(\"/dev/mixer\")"); | 168 | perror("open(\"/dev/mixer\")"); |
169 | 169 | ||
170 | # else | 170 | # else |
171 | // This is the way this has to be done now I guess, doesn't allow for | 171 | // This is the way this has to be done now I guess, doesn't allow for |
172 | // independant right and left channel setting, or setting for different outputs | 172 | // independant right and left channel setting, or setting for different outputs |
173 | Config cfg("Sound"); | 173 | Config cfg("qpe"); // qtopia is "Sound" |
174 | cfg.setGroup("System"); | 174 | cfg.setGroup("Volume"); // qtopia is "Settings" |
175 | cfg.writeEntry("Volume",(int)rV); | 175 | cfg.writeEntry("VolumePercent",(int)rV); //qtopia is Volume |
176 | # endif | 176 | # endif |
177 | 177 | ||
178 | //#endif | 178 | //#endif |
179 | // qDebug( "setting volume to: 0x%x", volume ); | 179 | // qDebug( "setting volume to: 0x%x", volume ); |
180 | #if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) | 180 | #if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) |
181 | // Send notification that the volume has changed | 181 | // Send notification that the volume has changed |
182 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << muted; | 182 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << muted; |
183 | #endif | 183 | #endif |
184 | } | 184 | } |
185 | 185 | ||
186 | 186 | ||
187 | 187 | ||
188 | 188 | ||
189 | AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) { | 189 | AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) { |
190 | qDebug("creating new audio device"); | 190 | qDebug("creating new audio device"); |
191 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; | 191 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; |
192 | d = new AudioDevicePrivate; | 192 | d = new AudioDevicePrivate; |
193 | d->frequency = f; | 193 | d->frequency = f; |
194 | d->channels = chs; | 194 | d->channels = chs; |
195 | d->bytesPerSample = bps; | 195 | d->bytesPerSample = bps; |
196 | qDebug("%d",bps); | 196 | qDebug("%d",bps); |
197 | int format=0; | 197 | int format=0; |
198 | if( bps == 8) format = AFMT_U8; | 198 | if( bps == 8) format = AFMT_U8; |
199 | else if( bps <= 0) format = AFMT_S16_LE; | 199 | else if( bps <= 0) format = AFMT_S16_LE; |
200 | else format = AFMT_S16_LE; | 200 | else format = AFMT_S16_LE; |
201 | qDebug("AD- freq %d, channels %d, b/sample %d, bitrate %d",f,chs,bps,format); | 201 | qDebug("AD- freq %d, channels %d, b/sample %d, bitrate %d",f,chs,bps,format); |
202 | connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( volumeChanged(bool) ) ); | 202 | connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( volumeChanged(bool) ) ); |
203 | 203 | ||
204 | int fragments = 0x10000 * 8 + sound_fragment_shift; | 204 | int fragments = 0x10000 * 8 + sound_fragment_shift; |
205 | int capabilities = 0; | 205 | int capabilities = 0; |
206 | 206 | ||
207 | 207 | ||
208 | #ifdef KEEP_DEVICE_OPEN | 208 | #ifdef KEEP_DEVICE_OPEN |
209 | if ( AudioDevicePrivate::dspFd == 0 ) { | 209 | if ( AudioDevicePrivate::dspFd == 0 ) { |
210 | #endif | 210 | #endif |
211 | if ( ( d->handle = ::open( "/dev/dsp", O_WRONLY ) ) < 0 ) { | 211 | if ( ( d->handle = ::open( "/dev/dsp", O_WRONLY ) ) < 0 ) { |
212 | perror("open(\"/dev/dsp\") sending to /dev/null instead"); | 212 | perror("open(\"/dev/dsp\") sending to /dev/null instead"); |
213 | d->handle = ::open( "/dev/null", O_WRONLY ); | 213 | d->handle = ::open( "/dev/null", O_WRONLY ); |
214 | } | 214 | } |
215 | #ifdef KEEP_DEVICE_OPEN | 215 | #ifdef KEEP_DEVICE_OPEN |
216 | AudioDevicePrivate::dspFd = d->handle; | 216 | AudioDevicePrivate::dspFd = d->handle; |
217 | } else { | 217 | } else { |
218 | d->handle = AudioDevicePrivate::dspFd; | 218 | d->handle = AudioDevicePrivate::dspFd; |
219 | } | 219 | } |
220 | #endif | 220 | #endif |
221 | 221 | ||
222 | if(ioctl( d->handle, SNDCTL_DSP_GETCAPS, &capabilities )==-1) | 222 | if(ioctl( d->handle, SNDCTL_DSP_GETCAPS, &capabilities )==-1) |
223 | perror("ioctl(\"SNDCTL_DSP_GETCAPS\")"); | 223 | perror("ioctl(\"SNDCTL_DSP_GETCAPS\")"); |
224 | if(ioctl( d->handle, SNDCTL_DSP_SETFRAGMENT, &fragments )==-1) | 224 | if(ioctl( d->handle, SNDCTL_DSP_SETFRAGMENT, &fragments )==-1) |
225 | perror("ioctl(\"SNDCTL_DSP_SETFRAGMENT\")"); | 225 | perror("ioctl(\"SNDCTL_DSP_SETFRAGMENT\")"); |
226 | if(ioctl( d->handle, SNDCTL_DSP_SETFMT, & format )==-1) | 226 | if(ioctl( d->handle, SNDCTL_DSP_SETFMT, & format )==-1) |
227 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); | 227 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); |
228 | qDebug("freq %d", d->frequency); | 228 | qDebug("freq %d", d->frequency); |
229 | if(ioctl( d->handle, SNDCTL_DSP_SPEED, &d->frequency )==-1) | 229 | if(ioctl( d->handle, SNDCTL_DSP_SPEED, &d->frequency )==-1) |
230 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); | 230 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); |
231 | qDebug("channels %d",d->channels); | 231 | qDebug("channels %d",d->channels); |
232 | if ( ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels ) == -1 ) { | 232 | if ( ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels ) == -1 ) { |
233 | d->channels = ( d->channels == 1 ) ? 2 : d->channels; | 233 | d->channels = ( d->channels == 1 ) ? 2 : d->channels; |
234 | if(ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels )==-1) | 234 | if(ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels )==-1) |
235 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); | 235 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); |
236 | } | 236 | } |
237 | 237 | ||
238 | d->bufferSize = sound_fragment_bytes; | 238 | d->bufferSize = sound_fragment_bytes; |
239 | d->unwrittenBuffer = new char[d->bufferSize]; | 239 | d->unwrittenBuffer = new char[d->bufferSize]; |