summaryrefslogtreecommitdiff
path: root/noncore/multimedia/opierec
authorllornkcor <llornkcor>2004-08-06 19:03:36 (UTC)
committer llornkcor <llornkcor>2004-08-06 19:03:36 (UTC)
commit5e10278e748608766245ff9f59a54d1ae8ff6f7e (patch) (unidiff)
treeca01e05ff77f7b80209deba47c93be48d20d8df2 /noncore/multimedia/opierec
parent75675815cb051e14bf8ad50c4069338bfa83eed1 (diff)
downloadopie-5e10278e748608766245ff9f59a54d1ae8ff6f7e.zip
opie-5e10278e748608766245ff9f59a54d1ae8ff6f7e.tar.gz
opie-5e10278e748608766245ff9f59a54d1ae8ff6f7e.tar.bz2
no warnings
Diffstat (limited to 'noncore/multimedia/opierec') (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
@@ -2,11 +2,8 @@
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>
@@ -32,10 +29,10 @@ Device::Device( QObject * parent, const char * dsp, const char * mixr, bool reco
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
@@ -52,6 +49,89 @@ bool Device::openDsp() {
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 );
@@ -96,7 +176,7 @@ void Device::changedOutVolume(int vol) {
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}
@@ -111,7 +191,7 @@ void Device::changedInVolume(int vol ) {
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}
@@ -134,88 +214,6 @@ bool Device::selectMicInput() {
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) {
@@ -230,12 +228,12 @@ bool Device::closeDevice( bool) {
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;
@@ -245,7 +243,7 @@ bool Device::setDeviceFormat( int form) {
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;
@@ -255,7 +253,7 @@ bool Device::setDeviceChannels( int ch) {
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;
@@ -318,9 +316,9 @@ int 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}
@@ -344,13 +342,15 @@ bool Device::reset() {
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}