summaryrefslogtreecommitdiff
path: root/core/multimedia/opieplayer
authorllornkcor <llornkcor>2002-06-17 23:09:38 (UTC)
committer llornkcor <llornkcor>2002-06-17 23:09:38 (UTC)
commit554f88d0e8839bd6112fa42139a967712552e519 (patch) (unidiff)
treed90788c9247f35ee10a1cdd8df0408b1df2a7e57 /core/multimedia/opieplayer
parent28400a31238af793fe235a0c8d13131eb823037d (diff)
downloadopie-554f88d0e8839bd6112fa42139a967712552e519.zip
opie-554f88d0e8839bd6112fa42139a967712552e519.tar.gz
opie-554f88d0e8839bd6112fa42139a967712552e519.tar.bz2
fixed volume fix
Diffstat (limited to 'core/multimedia/opieplayer') (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:
77 static unsigned int leftVolume; 77 static unsigned int leftVolume;
78 static unsigned int rightVolume; 78 static unsigned int rightVolume;
79}; 79};
80 80
81 81
82#ifdef Q_WS_QWS 82#ifdef Q_WS_QWS
83// This is for keeping the device open in-between playing files when 83// This is for keeping the device open in-between playing files when
84// the device makes clicks and it starts to drive you insane! :) 84// the device makes clicks and it starts to drive you insane! :)
85// Best to have the device not open when not using it though 85// Best to have the device not open when not using it though
86//#define KEEP_DEVICE_OPEN 86//#define KEEP_DEVICE_OPEN
87#endif 87#endif
88 88
89 89
90int AudioDevicePrivate::dspFd = 0; 90int AudioDevicePrivate::dspFd = 0;
91bool AudioDevicePrivate::muted = FALSE; 91bool AudioDevicePrivate::muted = FALSE;
92unsigned int AudioDevicePrivate::leftVolume = 0; 92unsigned int AudioDevicePrivate::leftVolume = 0;
93unsigned int AudioDevicePrivate::rightVolume = 0; 93unsigned int AudioDevicePrivate::rightVolume = 0;
94 94
95 95
96void AudioDevice::getVolume( unsigned int& leftVolume, unsigned int& rightVolume, bool &muted ) { 96void AudioDevice::getVolume( unsigned int& leftVolume, unsigned int& rightVolume, bool &muted ) {
97 muted = AudioDevicePrivate::muted; 97 muted = AudioDevicePrivate::muted;
98 unsigned int volume; 98 unsigned int volume;
99// #ifdef Q_OS_WIN32 99// #ifdef Q_OS_WIN32
100// HWAVEOUT handle; 100// HWAVEOUT handle;
101// WAVEFORMATEX formatData; 101// WAVEFORMATEX formatData;
102// formatData.cbSize = sizeof(WAVEFORMATEX); 102// formatData.cbSize = sizeof(WAVEFORMATEX);
103// formatData.wFormatTag = WAVE_FORMAT_PCM; 103// formatData.wFormatTag = WAVE_FORMAT_PCM;
104// formatData.nAvgBytesPerSec = 4 * 44000; 104// formatData.nAvgBytesPerSec = 4 * 44000;
105// formatData.nBlockAlign = 4; 105// formatData.nBlockAlign = 4;
106// formatData.nChannels = 2; 106// formatData.nChannels = 2;
107// formatData.nSamplesPerSec = 44000; 107// formatData.nSamplesPerSec = 44000;
108// formatData.wBitsPerSample = 16; 108// formatData.wBitsPerSample = 16;
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
129void AudioDevice::setVolume( unsigned int leftVolume, unsigned int rightVolume, bool muted ) { 129void 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
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 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];
240 d->unwritten = 0; 240 d->unwritten = 0;
241 d->can_GETOSPACE = TRUE; // until we find otherwise 241 d->can_GETOSPACE = TRUE; // until we find otherwise
242 242
243 //if ( chs != d->channels ) qDebug( "Wanted %d, got %d channels", chs, d->channels ); 243 //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 ); 244 //if ( f != d->frequency ) qDebug( "wanted %dHz, got %dHz", f, d->frequency );
245 //if ( capabilities & DSP_CAP_BATCH ) qDebug( "Sound card has local buffer" ); 245 //if ( capabilities & DSP_CAP_BATCH ) qDebug( "Sound card has local buffer" );
246 //if ( capabilities & DSP_CAP_REALTIME )qDebug( "Sound card has realtime sync" ); 246 //if ( capabilities & DSP_CAP_REALTIME )qDebug( "Sound card has realtime sync" );
247 //if ( capabilities & DSP_CAP_TRIGGER ) qDebug( "Sound card has precise trigger" ); 247 //if ( capabilities & DSP_CAP_TRIGGER ) qDebug( "Sound card has precise trigger" );
248 //if ( capabilities & DSP_CAP_MMAP ) qDebug( "Sound card can mmap" ); 248 //if ( capabilities & DSP_CAP_MMAP ) qDebug( "Sound card can mmap" );
249 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; 249 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE;
250 250
251} 251}
252 252
253 253
254AudioDevice::~AudioDevice() { 254AudioDevice::~AudioDevice() {
255 qDebug("destryo audiodevice"); 255 qDebug("destryo audiodevice");
256 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; 256 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE;
257 257
258// #ifdef Q_OS_WIN32 258// #ifdef Q_OS_WIN32
259// waveOutClose( (HWAVEOUT)d->handle ); 259// waveOutClose( (HWAVEOUT)d->handle );
260// #else 260// #else
261# ifndef KEEP_DEVICE_OPEN 261# ifndef KEEP_DEVICE_OPEN
262 close( d->handle ); // Now it should be safe to shut the handle 262 close( d->handle ); // Now it should be safe to shut the handle
263# endif 263# endif
264 delete d->unwrittenBuffer; 264 delete d->unwrittenBuffer;
265 delete d; 265 delete d;
266//#endif 266//#endif
267 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; 267 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE;
268 268
269} 269}
270 270
271 271