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.cpp2
1 files changed, 0 insertions, 2 deletions
diff --git a/core/multimedia/opieplayer/audiodevice.cpp b/core/multimedia/opieplayer/audiodevice.cpp
index 5fef792..2087c7f 100644
--- a/core/multimedia/opieplayer/audiodevice.cpp
+++ b/core/multimedia/opieplayer/audiodevice.cpp
@@ -152,101 +152,99 @@ void AudioDevice::setVolume( unsigned int leftVolume, unsigned int rightVolume,
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("Sound");
174 cfg.setGroup("System"); 174 cfg.setGroup("System");
175 cfg.writeEntry("Volume",(int)rV); 175 cfg.writeEntry("Volume",(int)rV);
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
189AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) { 189AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) {
190 qDebug("creating new audio device"); 190 qDebug("creating new audio device");
191 d = new AudioDevicePrivate; 191 d = new AudioDevicePrivate;
192 d->frequency = f; 192 d->frequency = f;
193 d->channels = chs; 193 d->channels = chs;
194 d->bytesPerSample = bps; 194 d->bytesPerSample = bps;
195 qDebug("%d",bps); 195 qDebug("%d",bps);
196 int format=0; 196 int format=0;
197 if( bps == 8) format = AFMT_U8; 197 if( bps == 8) format = AFMT_U8;
198 else if( bps <= 0) format = AFMT_S16_LE; 198 else if( bps <= 0) format = AFMT_S16_LE;
199 else format = AFMT_S16_LE; 199 else format = AFMT_S16_LE;
200
201 qDebug("AD- freq %d, channels %d, b/sample %d, bitrate %d",f,chs,bps,format); 200 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) ) ); 201 connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( volumeChanged(bool) ) );
203 202
204
205 int fragments = 0x10000 * 8 + sound_fragment_shift; 203 int fragments = 0x10000 * 8 + sound_fragment_shift;
206 int capabilities = 0; 204 int capabilities = 0;
207 205
208#ifdef KEEP_DEVICE_OPEN 206#ifdef KEEP_DEVICE_OPEN
209 if ( AudioDevicePrivate::dspFd == 0 ) { 207 if ( AudioDevicePrivate::dspFd == 0 ) {
210#endif 208#endif
211 if ( ( d->handle = ::open( "/dev/dsp", O_WRONLY ) ) < 0 ) { 209 if ( ( d->handle = ::open( "/dev/dsp", O_WRONLY ) ) < 0 ) {
212 perror("open(\"/dev/dsp\") sending to /dev/null instead"); 210 perror("open(\"/dev/dsp\") sending to /dev/null instead");
213 d->handle = ::open( "/dev/null", O_WRONLY ); 211 d->handle = ::open( "/dev/null", O_WRONLY );
214 } 212 }
215#ifdef KEEP_DEVICE_OPEN 213#ifdef KEEP_DEVICE_OPEN
216 AudioDevicePrivate::dspFd = d->handle; 214 AudioDevicePrivate::dspFd = d->handle;
217 } else { 215 } else {
218 d->handle = AudioDevicePrivate::dspFd; 216 d->handle = AudioDevicePrivate::dspFd;
219 } 217 }
220#endif 218#endif
221 219
222 if(ioctl( d->handle, SNDCTL_DSP_GETCAPS, &capabilities )==-1) 220 if(ioctl( d->handle, SNDCTL_DSP_GETCAPS, &capabilities )==-1)
223 perror("ioctl(\"SNDCTL_DSP_GETCAPS\")"); 221 perror("ioctl(\"SNDCTL_DSP_GETCAPS\")");
224 if(ioctl( d->handle, SNDCTL_DSP_SETFRAGMENT, &fragments )==-1) 222 if(ioctl( d->handle, SNDCTL_DSP_SETFRAGMENT, &fragments )==-1)
225 perror("ioctl(\"SNDCTL_DSP_SETFRAGMENT\")"); 223 perror("ioctl(\"SNDCTL_DSP_SETFRAGMENT\")");
226 if(ioctl( d->handle, SNDCTL_DSP_SETFMT, & format )==-1) 224 if(ioctl( d->handle, SNDCTL_DSP_SETFMT, & format )==-1)
227 perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); 225 perror("ioctl(\"SNDCTL_DSP_SETFMT\")");
228 qDebug("freq %d", d->frequency); 226 qDebug("freq %d", d->frequency);
229 if(ioctl( d->handle, SNDCTL_DSP_SPEED, &d->frequency )==-1) 227 if(ioctl( d->handle, SNDCTL_DSP_SPEED, &d->frequency )==-1)
230 perror("ioctl(\"SNDCTL_DSP_SPEED\")"); 228 perror("ioctl(\"SNDCTL_DSP_SPEED\")");
231 qDebug("channels %d",d->channels); 229 qDebug("channels %d",d->channels);
232 if ( ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels ) == -1 ) { 230 if ( ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels ) == -1 ) {
233 d->channels = ( d->channels == 1 ) ? 2 : d->channels; 231 d->channels = ( d->channels == 1 ) ? 2 : d->channels;
234 if(ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels )==-1) 232 if(ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels )==-1)
235 perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); 233 perror("ioctl(\"SNDCTL_DSP_CHANNELS\")");
236 } 234 }
237 235
238 d->bufferSize = sound_fragment_bytes; 236 d->bufferSize = sound_fragment_bytes;
239 d->unwrittenBuffer = new char[d->bufferSize]; 237 d->unwrittenBuffer = new char[d->bufferSize];
240 d->unwritten = 0; 238 d->unwritten = 0;
241 d->can_GETOSPACE = TRUE; // until we find otherwise 239 d->can_GETOSPACE = TRUE; // until we find otherwise
242 240
243 //if ( chs != d->channels ) qDebug( "Wanted %d, got %d channels", chs, d->channels ); 241 //if ( chs != d->channels ) qDebug( "Wanted %d, got %d channels", chs, d->channels );
244 //if ( f != d->frequency ) qDebug( "wanted %dHz, got %dHz", f, d->frequency ); 242 //if ( f != d->frequency ) qDebug( "wanted %dHz, got %dHz", f, d->frequency );
245 //if ( capabilities & DSP_CAP_BATCH ) qDebug( "Sound card has local buffer" ); 243 //if ( capabilities & DSP_CAP_BATCH ) qDebug( "Sound card has local buffer" );
246 //if ( capabilities & DSP_CAP_REALTIME )qDebug( "Sound card has realtime sync" ); 244 //if ( capabilities & DSP_CAP_REALTIME )qDebug( "Sound card has realtime sync" );
247 //if ( capabilities & DSP_CAP_TRIGGER ) qDebug( "Sound card has precise trigger" ); 245 //if ( capabilities & DSP_CAP_TRIGGER ) qDebug( "Sound card has precise trigger" );
248 //if ( capabilities & DSP_CAP_MMAP ) qDebug( "Sound card can mmap" ); 246 //if ( capabilities & DSP_CAP_MMAP ) qDebug( "Sound card can mmap" );
249} 247}
250 248
251 249
252AudioDevice::~AudioDevice() { 250AudioDevice::~AudioDevice() {