summaryrefslogtreecommitdiff
authorzecke <zecke>2003-10-07 13:02:55 (UTC)
committer zecke <zecke>2003-10-07 13:02:55 (UTC)
commit75f35445e9f3ec2f730f779d67f4189296bd9c5e (patch) (unidiff)
tree58d137879aefe506af087f5a75e29f60b5aaae0a
parentd72a9cfe61cbc0910373e4604220021ebbcedaeb (diff)
downloadopie-75f35445e9f3ec2f730f779d67f4189296bd9c5e.zip
opie-75f35445e9f3ec2f730f779d67f4189296bd9c5e.tar.gz
opie-75f35445e9f3ec2f730f779d67f4189296bd9c5e.tar.bz2
instead of testing for QWS_EBX we now define OPIE_NO_SOUND_PCM_READ_BITS.
If your platform does not have that ioctl define it
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opierec/device.cpp16
1 files changed, 8 insertions, 8 deletions
diff --git a/noncore/multimedia/opierec/device.cpp b/noncore/multimedia/opierec/device.cpp
index f9a80c5..11071d8 100644
--- a/noncore/multimedia/opierec/device.cpp
+++ b/noncore/multimedia/opierec/device.cpp
@@ -1,335 +1,335 @@
1// device.cpp 1// device.cpp
2 2
3#include "device.h" 3#include "device.h"
4 4
5#include <qpe/config.h> 5#include <qpe/config.h>
6#include <qpe/qcopenvelope_qws.h> 6#include <qpe/qcopenvelope_qws.h>
7 7#include <qpe/custom.h>
8 8
9#include <fcntl.h> 9#include <fcntl.h>
10#include <stdio.h> 10#include <stdio.h>
11#include <stdlib.h> 11#include <stdlib.h>
12#include <sys/ioctl.h> 12#include <sys/ioctl.h>
13#include <sys/soundcard.h> 13#include <sys/soundcard.h>
14#include <unistd.h> 14#include <unistd.h>
15#include<sys/wait.h> 15#include<sys/wait.h>
16// #include <sys/stat.h> 16// #include <sys/stat.h>
17// #include <sys/time.h> 17// #include <sys/time.h>
18// #include <sys/types.h> 18// #include <sys/types.h>
19#include <unistd.h> 19#include <unistd.h>
20#include <errno.h> 20#include <errno.h>
21 21
22//extern QtRec *qperec; 22//extern QtRec *qperec;
23 23
24Device::Device( QObject * parent, const char * dsp, const char * mixr, bool record ) 24Device::Device( QObject * parent, const char * dsp, const char * mixr, bool record )
25 : QObject( parent) 25 : QObject( parent)
26{ 26{
27 dspstr = (char *)dsp; 27 dspstr = (char *)dsp;
28 mixstr = (char *)mixr; 28 mixstr = (char *)mixr;
29 29
30 devForm=-1; 30 devForm=-1;
31 devCh=-1; 31 devCh=-1;
32 devRate=-1; 32 devRate=-1;
33 33
34 if( !record){ //playing 34 if( !record){ //playing
35 qDebug("setting up DSP for playing"); 35 qDebug("setting up DSP for playing");
36 flags = O_WRONLY; 36 flags = O_WRONLY;
37 } else { //recording 37 } else { //recording
38 qDebug("setting up DSP for recording"); 38 qDebug("setting up DSP for recording");
39 flags = O_RDWR; 39 flags = O_RDWR;
40// flags = O_RDONLY; 40// flags = O_RDONLY;
41 selectMicInput(); 41 selectMicInput();
42 } 42 }
43} 43}
44 44
45bool Device::openDsp() { 45bool Device::openDsp() {
46 if( openDevice( flags) == -1) { 46 if( openDevice( flags) == -1) {
47 perror("<<<<<<<<<<<<<<ioctl(\"Open device\")"); 47 perror("<<<<<<<<<<<<<<ioctl(\"Open device\")");
48 return false; 48 return false;
49 } 49 }
50 return true; 50 return true;
51} 51}
52 52
53int Device::getOutVolume( ) { 53int Device::getOutVolume( ) {
54 unsigned int volume; 54 unsigned int volume;
55 int mixerHandle = open( mixstr, O_RDWR ); 55 int mixerHandle = open( mixstr, O_RDWR );
56 if ( mixerHandle >= 0 ) { 56 if ( mixerHandle >= 0 ) {
57 if(ioctl( mixerHandle, MIXER_READ(SOUND_MIXER_VOLUME), &volume )==-1) 57 if(ioctl( mixerHandle, MIXER_READ(SOUND_MIXER_VOLUME), &volume )==-1)
58 perror("<<<<<<<<<<<<<<ioctl(\"MIXER_READ\")"); 58 perror("<<<<<<<<<<<<<<ioctl(\"MIXER_READ\")");
59 ::close( mixerHandle ); 59 ::close( mixerHandle );
60 } else 60 } else
61 perror("open(\"/dev/mixer\")"); 61 perror("open(\"/dev/mixer\")");
62 printf("<<<<<<<<<<<<<<<<<<<<output volume %d\n",volume); 62 printf("<<<<<<<<<<<<<<<<<<<<output volume %d\n",volume);
63 63
64 Config cfg("qpe"); 64 Config cfg("qpe");
65 cfg.setGroup("Volume"); 65 cfg.setGroup("Volume");
66 66
67 return cfg.readNumEntry("VolumePercent"); 67 return cfg.readNumEntry("VolumePercent");
68} 68}
69 69
70int Device::getInVolume() { 70int Device::getInVolume() {
71 unsigned int volume=0; 71 unsigned int volume=0;
72 int mixerHandle = ::open( mixstr, O_RDWR ); 72 int mixerHandle = ::open( mixstr, O_RDWR );
73 if ( mixerHandle >= 0 ) { 73 if ( mixerHandle >= 0 ) {
74 if(ioctl( mixerHandle, MIXER_READ(SOUND_MIXER_MIC), &volume )==-1) 74 if(ioctl( mixerHandle, MIXER_READ(SOUND_MIXER_MIC), &volume )==-1)
75 perror("<<<<<<<<<<<<<<<ioctl(\"MIXER_READ\")"); 75 perror("<<<<<<<<<<<<<<<ioctl(\"MIXER_READ\")");
76 ::close( mixerHandle ); 76 ::close( mixerHandle );
77 } else 77 } else
78 perror("open(\"/dev/mixer\")"); 78 perror("open(\"/dev/mixer\")");
79 printf("<<<<<<<<<<<<<<input volume %d\n", volume ); 79 printf("<<<<<<<<<<<<<<input volume %d\n", volume );
80 Config cfg("qpe"); 80 Config cfg("qpe");
81 cfg.setGroup("Volume"); 81 cfg.setGroup("Volume");
82 82
83 return cfg.readNumEntry("Mic"); 83 return cfg.readNumEntry("Mic");
84} 84}
85 85
86void Device::changedOutVolume(int vol) { 86void Device::changedOutVolume(int vol) {
87 int level = (vol << 8) + vol; 87 int level = (vol << 8) + vol;
88 int fd = 0; 88 int fd = 0;
89 if ((fd = open("/dev/mixer", O_RDWR))>=0) { 89 if ((fd = open("/dev/mixer", O_RDWR))>=0) {
90 if(ioctl(fd, MIXER_WRITE(SOUND_MIXER_VOLUME), &level) == -1) 90 if(ioctl(fd, MIXER_WRITE(SOUND_MIXER_VOLUME), &level) == -1)
91 perror("ioctl(\"MIXER_IN_WRITE\")"); 91 perror("ioctl(\"MIXER_IN_WRITE\")");
92 92
93 Config cfg("qpe"); 93 Config cfg("qpe");
94 cfg.setGroup("Volume"); 94 cfg.setGroup("Volume");
95 cfg.writeEntry("VolumePercent", QString::number( vol )); 95 cfg.writeEntry("VolumePercent", QString::number( vol ));
96 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << false; 96 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << false;
97 } 97 }
98 ::close(fd); 98 ::close(fd);
99} 99}
100 100
101void Device::changedInVolume(int vol ) { 101void Device::changedInVolume(int vol ) {
102 int level = (vol << 8) + vol; 102 int level = (vol << 8) + vol;
103 int fd = 0; 103 int fd = 0;
104 if ((fd = open("/dev/mixer", O_RDWR))>=0) { 104 if ((fd = open("/dev/mixer", O_RDWR))>=0) {
105 if(ioctl(fd, MIXER_WRITE(SOUND_MIXER_MIC), &level) == -1) 105 if(ioctl(fd, MIXER_WRITE(SOUND_MIXER_MIC), &level) == -1)
106 perror("ioctl(\"MIXER_IN_WRITE\")"); 106 perror("ioctl(\"MIXER_IN_WRITE\")");
107 Config cfg("qpe"); 107 Config cfg("qpe");
108 cfg.setGroup("Volume"); 108 cfg.setGroup("Volume");
109 cfg.writeEntry("Mic", QString::number(vol )); 109 cfg.writeEntry("Mic", QString::number(vol ));
110 QCopEnvelope( "QPE/System", "micChange(bool)" ) << false; 110 QCopEnvelope( "QPE/System", "micChange(bool)" ) << false;
111 } 111 }
112 ::close(fd); 112 ::close(fd);
113} 113}
114 114
115bool Device::selectMicInput() { 115bool Device::selectMicInput() {
116/* 116/*
117 int md=0; 117 int md=0;
118 int info=MIXER_WRITE(SOUND_MIXER_MIC); 118 int info=MIXER_WRITE(SOUND_MIXER_MIC);
119 md = ::open( "/dev/mixer", O_RDWR ); 119 md = ::open( "/dev/mixer", O_RDWR );
120 if ( md == -1) 120 if ( md == -1)
121 perror("open(\"/dev/mixer\")"); 121 perror("open(\"/dev/mixer\")");
122 else { 122 else {
123 if( ioctl( md, SOUND_MIXER_WRITE_RECSRC, &info) == -1) 123 if( ioctl( md, SOUND_MIXER_WRITE_RECSRC, &info) == -1)
124 perror("ioctl(\"SOUND_MIXER_WRITE_RECSRC\")"); 124 perror("ioctl(\"SOUND_MIXER_WRITE_RECSRC\")");
125 ::close(md); 125 ::close(md);
126 return false; 126 return false;
127 } 127 }
128 ::close(md); 128 ::close(md);
129*/ 129*/
130 return true; 130 return true;
131} 131}
132 132
133int Device::openDevice( int flags) { 133int Device::openDevice( int flags) {
134/* pid_t pid; 134/* pid_t pid;
135 int status; 135 int status;
136 int pipefd[2]; 136 int pipefd[2];
137 char message[20]; 137 char message[20];
138 if (pipe(pipefd) == -1){ 138 if (pipe(pipefd) == -1){
139 perror ("Error creating pipe"); 139 perror ("Error creating pipe");
140exit(1); 140exit(1);
141 } 141 }
142 switch (pid = fork()) { 142 switch (pid = fork()) {
143 case -1: 143 case -1:
144 perror("The fork failed!"); 144 perror("The fork failed!");
145 break; 145 break;
146 case 0: { 146 case 0: {
147 */ 147 */
148 if (( sd = ::open( dspstr, flags)) == -1) { 148 if (( sd = ::open( dspstr, flags)) == -1) {
149 perror("open(\"/dev/dsp\")"); 149 perror("open(\"/dev/dsp\")");
150 QString errorMsg="Could not open audio device\n /dev/dsp\n" 150 QString errorMsg="Could not open audio device\n /dev/dsp\n"
151 +(QString)strerror(errno); 151 +(QString)strerror(errno);
152 qDebug(errorMsg); 152 qDebug(errorMsg);
153 return -1; 153 return -1;
154 } 154 }
155 155
156 int mixerHandle=0; 156 int mixerHandle=0;
157 /* Set the input dsp device and its input gain the weird Zaurus way */ 157 /* Set the input dsp device and its input gain the weird Zaurus way */
158 if (( mixerHandle = open("/dev/mixer1",O_RDWR))<0) { 158 if (( mixerHandle = open("/dev/mixer1",O_RDWR))<0) {
159 perror("open(\"/dev/mixer1\")"); 159 perror("open(\"/dev/mixer1\")");
160 } 160 }
161 161
162 if(ioctl(sd,SNDCTL_DSP_RESET,0)<0){ 162 if(ioctl(sd,SNDCTL_DSP_RESET,0)<0){
163 perror("ioctl RESET"); 163 perror("ioctl RESET");
164 } 164 }
165// sprintf(message, "%d", sd); 165// sprintf(message, "%d", sd);
166 166
167/* QFile f1("/pid"); 167/* QFile f1("/pid");
168 f1.open(IO_WriteOnly ); 168 f1.open(IO_WriteOnly );
169 f1.writeBlock(message, strlen(message)); 169 f1.writeBlock(message, strlen(message));
170 f1.close(); 170 f1.close();
171 */ 171 */
172 /* close(pipefd[0]); 172 /* close(pipefd[0]);
173 write(pipefd[1], message, sizeof(message)); 173 write(pipefd[1], message, sizeof(message));
174 close(pipefd[1]); 174 close(pipefd[1]);
175 // qDebug("%d",soundDevice->sd ); 175 // qDebug("%d",soundDevice->sd );
176 _exit(0); 176 _exit(0);
177 } 177 }
178 default: 178 default:
179 // pid greater than zero is parent getting the child's pid 179 // pid greater than zero is parent getting the child's pid
180 printf("Child's pid is %d\n",pid); 180 printf("Child's pid is %d\n",pid);
181 QString s; 181 QString s;
182 close(pipefd[1]); 182 close(pipefd[1]);
183 read(pipefd[0], message, sizeof(message)); 183 read(pipefd[0], message, sizeof(message));
184 s = message; 184 s = message;
185 close(pipefd[0]); 185 close(pipefd[0]);
186 186
187// while(wait(NULL)!=pid) 187// while(wait(NULL)!=pid)
188 // ; 188 // ;
189 printf("child %ld terminated normally, return status is zero\n", (long) pid); 189 printf("child %ld terminated normally, return status is zero\n", (long) pid);
190 */ 190 */
191 // filePara.sd=(long) pid; 191 // filePara.sd=(long) pid;
192 /* QFile f2("/pid"); 192 /* QFile f2("/pid");
193 f2.open(IO_ReadOnly); 193 f2.open(IO_ReadOnly);
194 QTextStream t(&f2); 194 QTextStream t(&f2);
195 // for(int f=0; f < t.atEnd() ;f++) { 195 // for(int f=0; f < t.atEnd() ;f++) {
196 s = t.readLine(); 196 s = t.readLine();
197 // } 197 // }
198 */ 198 */
199// bool ok; 199// bool ok;
200// sd = s.toInt(&ok, 10); 200// sd = s.toInt(&ok, 10);
201// qDebug("<<<<<<<<<<<<<>>>>>>>>>>>>"+s); 201// qDebug("<<<<<<<<<<<<<>>>>>>>>>>>>"+s);
202 202
203// f2.close(); 203// f2.close();
204// } 204// }
205::close(mixerHandle ); 205::close(mixerHandle );
206 qDebug("open device %s", dspstr); 206 qDebug("open device %s", dspstr);
207 qDebug("success! %d",sd); 207 qDebug("success! %d",sd);
208 return sd; 208 return sd;
209} 209}
210 210
211bool Device::closeDevice( bool b) { 211bool Device::closeDevice( bool b) {
212// if(b) {//close now 212// if(b) {//close now
213// if (ioctl( sd, SNDCTL_DSP_RESET, 0) == -1) { 213// if (ioctl( sd, SNDCTL_DSP_RESET, 0) == -1) {
214// perror("ioctl(\"SNDCTL_DSP_RESET\")"); 214// perror("ioctl(\"SNDCTL_DSP_RESET\")");
215// } 215// }
216// } else { //let play 216// } else { //let play
217// if (ioctl( sd, SNDCTL_DSP_SYNC, 0) == -1) { 217// if (ioctl( sd, SNDCTL_DSP_SYNC, 0) == -1) {
218// perror("ioctl(\"SNDCTL_DSP_SYNC\")"); 218// perror("ioctl(\"SNDCTL_DSP_SYNC\")");
219// } 219// }
220// } 220// }
221 221
222 ::close( sd); //close sound device 222 ::close( sd); //close sound device
223// sdfd=0; 223// sdfd=0;
224 // sd=0; 224 // sd=0;
225 qDebug("closed dsp"); 225 qDebug("closed dsp");
226 return true; 226 return true;
227} 227}
228 228
229bool Device::setDeviceFormat( int form) { 229bool Device::setDeviceFormat( int form) {
230 qDebug("set device res %d %d", form, sd); 230 qDebug("set device res %d %d", form, sd);
231 if (ioctl( sd, SNDCTL_DSP_SETFMT, &form)==-1) { //set format 231 if (ioctl( sd, SNDCTL_DSP_SETFMT, &form)==-1) { //set format
232 perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); 232 perror("ioctl(\"SNDCTL_DSP_SETFMT\")");
233 return false; 233 return false;
234 } 234 }
235 devRes=form; 235 devRes=form;
236 return true; 236 return true;
237} 237}
238 238
239bool Device::setDeviceChannels( int ch) { 239bool Device::setDeviceChannels( int ch) {
240 qDebug("set channels %d %d", ch, sd); 240 qDebug("set channels %d %d", ch, sd);
241 if (ioctl( sd, SNDCTL_DSP_CHANNELS, &ch)==-1) { 241 if (ioctl( sd, SNDCTL_DSP_CHANNELS, &ch)==-1) {
242 perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); 242 perror("ioctl(\"SNDCTL_DSP_CHANNELS\")");
243 return false; 243 return false;
244 } 244 }
245 devCh=ch; 245 devCh=ch;
246 return true; 246 return true;
247} 247}
248 248
249bool Device::setDeviceRate( int rate) { 249bool Device::setDeviceRate( int rate) {
250 qDebug("set rate %d %d", rate, sd); 250 qDebug("set rate %d %d", rate, sd);
251 if (ioctl( sd, SNDCTL_DSP_SPEED, &rate) == -1) { 251 if (ioctl( sd, SNDCTL_DSP_SPEED, &rate) == -1) {
252 perror("ioctl(\"SNDCTL_DSP_SPEED\")"); 252 perror("ioctl(\"SNDCTL_DSP_SPEED\")");
253 return false; 253 return false;
254 } 254 }
255 255
256 devRate=rate; 256 devRate=rate;
257 257
258 return true; 258 return true;
259} 259}
260 260
261int Device::getRes() { 261int Device::getRes() {
262 return devRes; 262 return devRes;
263} 263}
264 264
265int Device::getFormat() { 265int Device::getFormat() {
266 return devForm; 266 return devForm;
267} 267}
268 268
269int Device::getRate() { 269int Device::getRate() {
270 return devRate; 270 return devRate;
271} 271}
272 272
273int Device::getChannels() { 273int Device::getChannels() {
274 return devCh; 274 return devCh;
275} 275}
276 276
277int Device::getDeviceFormat() { 277int Device::getDeviceFormat() {
278 return 0; 278 return 0;
279} 279}
280 280
281 281
282int Device::getDeviceRate() { 282int Device::getDeviceRate() {
283 int dRate=0; 283 int dRate=0;
284 if (ioctl( sd, SOUND_PCM_READ_RATE, &dRate) == -1) { 284 if (ioctl( sd, SOUND_PCM_READ_RATE, &dRate) == -1) {
285 perror("ioctl(\"SNDCTL_PCM_READ_RATE\")"); 285 perror("ioctl(\"SNDCTL_PCM_READ_RATE\")");
286 } 286 }
287 return dRate; 287 return dRate;
288 288
289} 289}
290 290
291int Device::getDeviceBits() { 291int Device::getDeviceBits() {
292 int dBits=0; 292 int dBits=0;
293#ifndef QT_QWS_EBX // zaurus doesnt have this 293#if !defined(OPIE_NO_SOUND_PCM_READ_BITS) // zaurus doesnt have this
294 if (ioctl( sd, SOUND_PCM_READ_BITS, &dBits) == -1) { 294 if (ioctl( sd, SOUND_PCM_READ_BITS, &dBits) == -1) {
295 perror("ioctl(\"SNDCTL_PCM_READ_BITS\")"); 295 perror("ioctl(\"SNDCTL_PCM_READ_BITS\")");
296 } 296 }
297#endif 297#endif
298 return dBits; 298 return dBits;
299} 299}
300 300
301int Device::getDeviceChannels() { 301int Device::getDeviceChannels() {
302 int dCh=0; 302 int dCh=0;
303 if (ioctl( sd, SOUND_PCM_READ_CHANNELS, &dCh) == -1) { 303 if (ioctl( sd, SOUND_PCM_READ_CHANNELS, &dCh) == -1) {
304 perror("ioctl(\"SNDCTL_PCM_READ_CHANNELS\")"); 304 perror("ioctl(\"SNDCTL_PCM_READ_CHANNELS\")");
305 } 305 }
306 return dCh; 306 return dCh;
307} 307}
308 308
309int Device::getDeviceFragSize() { 309int Device::getDeviceFragSize() {
310 int frag_size; 310 int frag_size;
311 311
312 if (ioctl( sd, SNDCTL_DSP_GETBLKSIZE, &frag_size) == -1) { 312 if (ioctl( sd, SNDCTL_DSP_GETBLKSIZE, &frag_size) == -1) {
313 qDebug("no fragsize"); 313 qDebug("no fragsize");
314 } else 314 } else
315 qDebug("driver says frag size is %d", frag_size); 315 qDebug("driver says frag size is %d", frag_size);
316 return frag_size; 316 return frag_size;
317} 317}
318 318
319bool Device::setFragSize(int frag) { 319bool Device::setFragSize(int frag) {
320 if (ioctl(sd, SNDCTL_DSP_SETFRAGMENT, &frag)) { 320 if (ioctl(sd, SNDCTL_DSP_SETFRAGMENT, &frag)) {
321 perror("ioctl(\"SNDCTL_DSP_SETFRAGMENT\")"); 321 perror("ioctl(\"SNDCTL_DSP_SETFRAGMENT\")");
322 return false; 322 return false;
323 } 323 }
324 return true; 324 return true;
325} 325}
326 326
327bool Device::reset() { 327bool Device::reset() {
328 closeDevice(true); 328 closeDevice(true);
329 openDsp(); 329 openDsp();
330 if (ioctl( sd, SNDCTL_DSP_RESET, 0) == -1) { 330 if (ioctl( sd, SNDCTL_DSP_RESET, 0) == -1) {
331 perror("ioctl(\"SNDCTL_DSP_RESET\")"); 331 perror("ioctl(\"SNDCTL_DSP_RESET\")");
332 return false; 332 return false;
333 } 333 }
334 return true; 334 return true;
335} 335}