summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2004-08-06 19:03:36 (UTC)
committer llornkcor <llornkcor>2004-08-06 19:03:36 (UTC)
commit5e10278e748608766245ff9f59a54d1ae8ff6f7e (patch) (unidiff)
treeca01e05ff77f7b80209deba47c93be48d20d8df2
parent75675815cb051e14bf8ad50c4069338bfa83eed1 (diff)
downloadopie-5e10278e748608766245ff9f59a54d1ae8ff6f7e.zip
opie-5e10278e748608766245ff9f59a54d1ae8ff6f7e.tar.gz
opie-5e10278e748608766245ff9f59a54d1ae8ff6f7e.tar.bz2
no warnings
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opierec/device.cpp192
1 files changed, 96 insertions, 96 deletions
diff --git a/noncore/multimedia/opierec/device.cpp b/noncore/multimedia/opierec/device.cpp
index db2d63f..683f0a5 100644
--- a/noncore/multimedia/opierec/device.cpp
+++ b/noncore/multimedia/opierec/device.cpp
@@ -1,15 +1,12 @@
1// device.cpp 1// device.cpp
2 2
3#include "device.h" 3#include "device.h"
4 4
5/* OPIE */
6#include <opie2/odebug.h>
7#include <qpe/config.h> 5#include <qpe/config.h>
8#include <qpe/qcopenvelope_qws.h> 6#include <qpe/qcopenvelope_qws.h>
9using namespace Opie::Core;
10 7
11/* STD */ 8/* STD */
12#include <fcntl.h> 9#include <fcntl.h>
13#include <stdio.h> 10#include <stdio.h>
14#include <stdlib.h> 11#include <stdlib.h>
15#include <sys/ioctl.h> 12#include <sys/ioctl.h>
@@ -29,16 +26,16 @@ Device::Device( QObject * parent, const char * dsp, const char * mixr, bool reco
29 26
30 devForm=-1; 27 devForm=-1;
31 devCh=-1; 28 devCh=-1;
32 devRate=-1; 29 devRate=-1;
33 30
34 if( !record){ //playing 31 if( !record){ //playing
35 odebug << "setting up DSP for playing" << oendl; 32 qDebug( "setting up DSP for playing" );
36 flags = O_WRONLY; 33 flags = O_WRONLY;
37 } else { //recording 34 } else { //recording
38 odebug << "setting up DSP for recording" << oendl; 35 qDebug( "setting up DSP for recording" );
39 flags = O_RDWR; 36 flags = O_RDWR;
40// flags = O_RDONLY; 37// flags = O_RDONLY;
41 38
42// selectMicInput(); 39// selectMicInput();
43 40
44 } 41 }
@@ -49,12 +46,95 @@ bool Device::openDsp() {
49 perror("<<<<<<<<<<<<<<ioctl(\"Open device\")"); 46 perror("<<<<<<<<<<<<<<ioctl(\"Open device\")");
50 return false; 47 return false;
51 } 48 }
52 return true; 49 return true;
53} 50}
54 51
52int Device::openDevice( int flags) {
53/* pid_t pid;
54 int status;
55 int pipefd[2];
56 char message[20];
57 if (pipe(pipefd) == -1){
58 perror ("Error creating pipe");
59exit(1);
60 }
61 switch (pid = fork()) {
62 case -1:
63 perror("The fork failed!");
64 break;
65 case 0: {
66 */
67qDebug( "Opening %s",dspstr);
68 if (( sd = ::open( dspstr, flags)) == -1) {
69 perror("open(\"/dev/dsp\")");
70 QString errorMsg="Could not open audio device\n /dev/dsp\n"
71 +(QString)strerror(errno);
72 qDebug( "XXXXXXXXXXXXXXXXXXXXXXX "+errorMsg );
73 return -1;
74 }
75
76qDebug( "Opening mixer" );
77 int mixerHandle=0;
78 if (( mixerHandle = open("/dev/mixer",O_RDWR))<0) {
79 perror("open(\"/dev/mixer\")");
80 QString errorMsg="Could not open audio device\n /dev/dsp\n"
81 +(QString)strerror(errno);
82 qDebug( "XXXXXXXXXXXXXXXXXXXXXX "+errorMsg );
83 }
84
85 if(ioctl(sd,SNDCTL_DSP_RESET,0)<0){
86 perror("ioctl RESET");
87 }
88// sprintf(message, "%d", sd);
89
90/* QFile f1("/pid");
91 f1.open(IO_WriteOnly );
92 f1.writeBlock(message, strlen(message));
93 f1.close();
94 */
95 /* close(pipefd[0]);
96 write(pipefd[1], message, sizeof(message));
97 close(pipefd[1]);
98 // qDebug( "" + soundDevice->sd );
99 _exit(0);
100 }
101 default:
102 // pid greater than zero is parent getting the child's pid
103 printf("Child's pid is %d\n",pid);
104 QString s;
105 close(pipefd[1]);
106 read(pipefd[0], message, sizeof(message));
107 s = message;
108 close(pipefd[0]);
109
110// while(wait(NULL)!=pid)
111 // ;
112 printf("child %ld terminated normally, return status is zero\n", (long) pid);
113 */
114 // filePara.sd=(long) pid;
115 /* QFile f2("/pid");
116 f2.open(IO_ReadOnly);
117 QTextStream t(&f2);
118 // for(int f=0; f < t.atEnd() ;f++) {
119 s = t.readLine();
120 // }
121 */
122// bool ok;
123// sd = s.toInt(&ok, 10);
124// qDebug( "<<<<<<<<<<<<<>>>>>>>>>>>>"+s );
125
126// f2.close();
127// }
128::close(mixerHandle );
129// qDebug( "open device " + dspstr );
130// qDebug( "success! " + sd );
131 return sd;
132}
133
134
55int Device::getOutVolume( ) { 135int Device::getOutVolume( ) {
56 unsigned int volume; 136 unsigned int volume;
57 int mixerHandle = open( mixstr, O_RDWR ); 137 int mixerHandle = open( mixstr, O_RDWR );
58 if ( mixerHandle >= 0 ) { 138 if ( mixerHandle >= 0 ) {
59 if(ioctl( mixerHandle, MIXER_READ(SOUND_MIXER_VOLUME), &volume )==-1) 139 if(ioctl( mixerHandle, MIXER_READ(SOUND_MIXER_VOLUME), &volume )==-1)
60 perror("<<<<<<<<<<<<<<ioctl(\"MIXER_READ\")"); 140 perror("<<<<<<<<<<<<<<ioctl(\"MIXER_READ\")");
@@ -93,13 +173,13 @@ void Device::changedOutVolume(int vol) {
93 perror("ioctl(\"MIXER_IN_WRITE\")"); 173 perror("ioctl(\"MIXER_IN_WRITE\")");
94 174
95 Config cfg("qpe"); 175 Config cfg("qpe");
96 cfg.setGroup("Volume"); 176 cfg.setGroup("Volume");
97 cfg.writeEntry("VolumePercent", QString::number( vol )); 177 cfg.writeEntry("VolumePercent", QString::number( vol ));
98 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << false; 178 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << false;
99 owarn << "changing output vol " << vol << "" << oendl; 179 qDebug("changing output vol %d" ,vol );
100 } 180 }
101 ::close(fd); 181 ::close(fd);
102} 182}
103 183
104void Device::changedInVolume(int vol ) { 184void Device::changedInVolume(int vol ) {
105 int level = (vol << 8) + vol; 185 int level = (vol << 8) + vol;
@@ -108,13 +188,13 @@ void Device::changedInVolume(int vol ) {
108 if(ioctl(fd, MIXER_WRITE(SOUND_MIXER_MIC), &level) == -1) 188 if(ioctl(fd, MIXER_WRITE(SOUND_MIXER_MIC), &level) == -1)
109 perror("ioctl(\"MIXER_IN_WRITE\")"); 189 perror("ioctl(\"MIXER_IN_WRITE\")");
110 Config cfg("qpe"); 190 Config cfg("qpe");
111 cfg.setGroup("Volume"); 191 cfg.setGroup("Volume");
112 cfg.writeEntry("Mic", QString::number(vol )); 192 cfg.writeEntry("Mic", QString::number(vol ));
113 QCopEnvelope( "QPE/System", "micChange(bool)" ) << false; 193 QCopEnvelope( "QPE/System", "micChange(bool)" ) << false;
114 owarn << "changing input volume " << vol << "" << oendl; 194 qDebug("changing input volume %d",vol);
115 } 195 }
116 ::close(fd); 196 ::close(fd);
117} 197}
118 198
119bool Device::selectMicInput() { 199bool Device::selectMicInput() {
120 200
@@ -131,94 +211,12 @@ bool Device::selectMicInput() {
131 } 211 }
132 ::close(md); 212 ::close(md);
133 213
134 return true; 214 return true;
135} 215}
136 216
137int Device::openDevice( int flags) {
138/* pid_t pid;
139 int status;
140 int pipefd[2];
141 char message[20];
142 if (pipe(pipefd) == -1){
143 perror ("Error creating pipe");
144exit(1);
145 }
146 switch (pid = fork()) {
147 case -1:
148 perror("The fork failed!");
149 break;
150 case 0: {
151 */
152odebug << "Opening " << dspstr << "" << oendl;
153 if (( sd = ::open( dspstr, flags)) == -1) {
154 perror("open(\"/dev/dsp\")");
155 QString errorMsg="Could not open audio device\n /dev/dsp\n"
156 +(QString)strerror(errno);
157 odebug << "XXXXXXXXXXXXXXXXXXXXXXX "+errorMsg << oendl;
158 return -1;
159 }
160
161odebug << "Opening mixer" << oendl;
162 int mixerHandle=0;
163 if (( mixerHandle = open("/dev/mixer",O_RDWR))<0) {
164 perror("open(\"/dev/mixer\")");
165 QString errorMsg="Could not open audio device\n /dev/dsp\n"
166 +(QString)strerror(errno);
167 odebug << "XXXXXXXXXXXXXXXXXXXXXX "+errorMsg << oendl;
168 }
169
170 if(ioctl(sd,SNDCTL_DSP_RESET,0)<0){
171 perror("ioctl RESET");
172 }
173// sprintf(message, "%d", sd);
174
175/* QFile f1("/pid");
176 f1.open(IO_WriteOnly );
177 f1.writeBlock(message, strlen(message));
178 f1.close();
179 */
180 /* close(pipefd[0]);
181 write(pipefd[1], message, sizeof(message));
182 close(pipefd[1]);
183 // odebug << "" << soundDevice->sd << "" << oendl;
184 _exit(0);
185 }
186 default:
187 // pid greater than zero is parent getting the child's pid
188 printf("Child's pid is %d\n",pid);
189 QString s;
190 close(pipefd[1]);
191 read(pipefd[0], message, sizeof(message));
192 s = message;
193 close(pipefd[0]);
194
195// while(wait(NULL)!=pid)
196 // ;
197 printf("child %ld terminated normally, return status is zero\n", (long) pid);
198 */
199 // filePara.sd=(long) pid;
200 /* QFile f2("/pid");
201 f2.open(IO_ReadOnly);
202 QTextStream t(&f2);
203 // for(int f=0; f < t.atEnd() ;f++) {
204 s = t.readLine();
205 // }
206 */
207// bool ok;
208// sd = s.toInt(&ok, 10);
209// odebug << "<<<<<<<<<<<<<>>>>>>>>>>>>"+s << oendl;
210
211// f2.close();
212// }
213::close(mixerHandle );
214// odebug << "open device " << dspstr << "" << oendl;
215// odebug << "success! " << sd << "" << oendl;
216 return sd;
217}
218
219bool Device::closeDevice( bool) { 217bool Device::closeDevice( bool) {
220// if(b) {//close now 218// if(b) {//close now
221// if (ioctl( sd, SNDCTL_DSP_RESET, 0) == -1) { 219// if (ioctl( sd, SNDCTL_DSP_RESET, 0) == -1) {
222// perror("ioctl(\"SNDCTL_DSP_RESET\")"); 220// perror("ioctl(\"SNDCTL_DSP_RESET\")");
223// } 221// }
224// } else { //let play 222// } else { //let play
@@ -227,38 +225,38 @@ bool Device::closeDevice( bool) {
227// } 225// }
228// } 226// }
229 227
230 ::close( sd); //close sound device 228 ::close( sd); //close sound device
231// sdfd=0; 229// sdfd=0;
232 // sd=0; 230 // sd=0;
233// odebug << "closed dsp" << oendl; 231// qDebug( "closed dsp" );
234 return true; 232 return true;
235} 233}
236 234
237bool Device::setDeviceFormat( int form) { 235bool Device::setDeviceFormat( int form) {
238 odebug << "set device res " << form << " " << sd << "" << oendl; 236 qDebug( "set device res %d: %d ",form, sd );
239 if (ioctl( sd, SNDCTL_DSP_SETFMT, &form)==-1) { //set format 237 if (ioctl( sd, SNDCTL_DSP_SETFMT, &form)==-1) { //set format
240 perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); 238 perror("ioctl(\"SNDCTL_DSP_SETFMT\")");
241 return false; 239 return false;
242 } 240 }
243 devRes=form; 241 devRes=form;
244 return true; 242 return true;
245} 243}
246 244
247bool Device::setDeviceChannels( int ch) { 245bool Device::setDeviceChannels( int ch) {
248 odebug << "set channels " << ch << " " << sd << "" << oendl; 246 qDebug( "set channels %d: %d",ch ,sd);
249 if (ioctl( sd, SNDCTL_DSP_CHANNELS, &ch)==-1) { 247 if (ioctl( sd, SNDCTL_DSP_CHANNELS, &ch)==-1) {
250 perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); 248 perror("ioctl(\"SNDCTL_DSP_CHANNELS\")");
251 return false; 249 return false;
252 } 250 }
253 devCh=ch; 251 devCh=ch;
254 return true; 252 return true;
255} 253}
256 254
257bool Device::setDeviceRate( int rate) { 255bool Device::setDeviceRate( int rate) {
258 odebug << "set rate " << rate << " " << sd << "" << oendl; 256 qDebug( "set rate %d: %d",rate,sd);
259 if (ioctl( sd, SNDCTL_DSP_SPEED, &rate) == -1) { 257 if (ioctl( sd, SNDCTL_DSP_SPEED, &rate) == -1) {
260 perror("ioctl(\"SNDCTL_DSP_SPEED\")"); 258 perror("ioctl(\"SNDCTL_DSP_SPEED\")");
261 return false; 259 return false;
262 } 260 }
263 261
264 devRate=rate; 262 devRate=rate;
@@ -315,15 +313,15 @@ int Device::getDeviceChannels() {
315} 313}
316 314
317int Device::getDeviceFragSize() { 315int Device::getDeviceFragSize() {
318 int frag_size; 316 int frag_size;
319 317
320 if (ioctl( sd, SNDCTL_DSP_GETBLKSIZE, &frag_size) == -1) { 318 if (ioctl( sd, SNDCTL_DSP_GETBLKSIZE, &frag_size) == -1) {
321 odebug << "no fragsize" << oendl; 319 qDebug( "no fragsize" );
322 } else { 320 } else {
323 odebug << "driver says frag size is " << frag_size << "" << oendl; 321 qDebug( "driver says frag size is %d",frag_size);
324 } 322 }
325 return frag_size; 323 return frag_size;
326} 324}
327 325
328bool Device::setFragSize(int frag) { 326bool Device::setFragSize(int frag) {
329 if (ioctl(sd, SNDCTL_DSP_SETFRAGMENT, &frag)) { 327 if (ioctl(sd, SNDCTL_DSP_SETFRAGMENT, &frag)) {
@@ -341,18 +339,20 @@ bool Device::reset() {
341 return false; 339 return false;
342 } 340 }
343 return true; 341 return true;
344} 342}
345 343
346int Device::devRead(int soundDescriptor, short *buf, int size) { 344int Device::devRead(int soundDescriptor, short *buf, int size) {
345 Q_UNUSED(soundDescriptor);
347 int number = 0; 346 int number = 0;
348 number = ::read( sd /*soundDescriptor*/, (char *)buf, size); 347 number = ::read( sd /*soundDescriptor*/, (char *)buf, size);
349 return number; 348 return number;
350} 349}
351 350
352int Device::devWrite(int soundDescriptor, short * buf, int size) { 351int Device::devWrite(int soundDescriptor, short * buf, int size) {
353 int bytesWritten = 0; 352 Q_UNUSED(soundDescriptor);
353 int bytesWritten = 0;
354 bytesWritten = ::write( sd /*soundDescriptor*/, buf, size); 354 bytesWritten = ::write( sd /*soundDescriptor*/, buf, size);
355 return bytesWritten; 355 return bytesWritten;
356} 356}
357 357
358 358