summaryrefslogtreecommitdiff
path: root/noncore/multimedia/opierec/device.cpp
Unidiff
Diffstat (limited to 'noncore/multimedia/opierec/device.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opierec/device.cpp46
1 files changed, 23 insertions, 23 deletions
diff --git a/noncore/multimedia/opierec/device.cpp b/noncore/multimedia/opierec/device.cpp
index ce49e96..5319d97 100644
--- a/noncore/multimedia/opierec/device.cpp
+++ b/noncore/multimedia/opierec/device.cpp
@@ -1,24 +1,24 @@
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>
5#include <qpe/config.h> 7#include <qpe/config.h>
6#include <qpe/qcopenvelope_qws.h> 8#include <qpe/qcopenvelope_qws.h>
9using namespace Opie::Core;
7 10
8 11/* STD */
9#include <fcntl.h> 12#include <fcntl.h>
10#include <stdio.h> 13#include <stdio.h>
11#include <stdlib.h> 14#include <stdlib.h>
12#include <sys/ioctl.h> 15#include <sys/ioctl.h>
13#include <sys/soundcard.h> 16#include <sys/soundcard.h>
14#include <unistd.h> 17#include <unistd.h>
15#include<sys/wait.h> 18#include <sys/wait.h>
16// #include <sys/stat.h>
17// #include <sys/time.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 )
@@ -29,16 +29,16 @@ Device::Device( QObject * parent, const char * dsp, const char * mixr, bool reco
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 odebug << "setting up DSP for playing" << oendl;
36 flags = O_WRONLY; 36 flags = O_WRONLY;
37 } else { //recording 37 } else { //recording
38 qDebug("setting up DSP for recording"); 38 odebug << "setting up DSP for recording" << oendl;
39 flags = O_RDWR; 39 flags = O_RDWR;
40// flags = O_RDONLY; 40// flags = O_RDONLY;
41 41
42// selectMicInput(); 42// selectMicInput();
43 43
44 } 44 }
@@ -93,13 +93,13 @@ void Device::changedOutVolume(int vol) {
93 perror("ioctl(\"MIXER_IN_WRITE\")"); 93 perror("ioctl(\"MIXER_IN_WRITE\")");
94 94
95 Config cfg("qpe"); 95 Config cfg("qpe");
96 cfg.setGroup("Volume"); 96 cfg.setGroup("Volume");
97 cfg.writeEntry("VolumePercent", QString::number( vol )); 97 cfg.writeEntry("VolumePercent", QString::number( vol ));
98 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << false; 98 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << false;
99 qWarning("changing output vol %d", vol); 99 owarn << "changing output vol " << vol << "" << oendl;
100 } 100 }
101 ::close(fd); 101 ::close(fd);
102} 102}
103 103
104void Device::changedInVolume(int vol ) { 104void Device::changedInVolume(int vol ) {
105 int level = (vol << 8) + vol; 105 int level = (vol << 8) + vol;
@@ -108,13 +108,13 @@ void Device::changedInVolume(int vol ) {
108 if(ioctl(fd, MIXER_WRITE(SOUND_MIXER_MIC), &level) == -1) 108 if(ioctl(fd, MIXER_WRITE(SOUND_MIXER_MIC), &level) == -1)
109 perror("ioctl(\"MIXER_IN_WRITE\")"); 109 perror("ioctl(\"MIXER_IN_WRITE\")");
110 Config cfg("qpe"); 110 Config cfg("qpe");
111 cfg.setGroup("Volume"); 111 cfg.setGroup("Volume");
112 cfg.writeEntry("Mic", QString::number(vol )); 112 cfg.writeEntry("Mic", QString::number(vol ));
113 QCopEnvelope( "QPE/System", "micChange(bool)" ) << false; 113 QCopEnvelope( "QPE/System", "micChange(bool)" ) << false;
114 qWarning("changing input volume %d", vol); 114 owarn << "changing input volume " << vol << "" << oendl;
115 } 115 }
116 ::close(fd); 116 ::close(fd);
117} 117}
118 118
119bool Device::selectMicInput() { 119bool Device::selectMicInput() {
120 120
@@ -146,28 +146,28 @@ exit(1);
146 switch (pid = fork()) { 146 switch (pid = fork()) {
147 case -1: 147 case -1:
148 perror("The fork failed!"); 148 perror("The fork failed!");
149 break; 149 break;
150 case 0: { 150 case 0: {
151 */ 151 */
152qDebug("Opening %s",dspstr); 152odebug << "Opening " << dspstr << "" << oendl;
153 if (( sd = ::open( dspstr, flags)) == -1) { 153 if (( sd = ::open( dspstr, flags)) == -1) {
154 perror("open(\"/dev/dsp\")"); 154 perror("open(\"/dev/dsp\")");
155 QString errorMsg="Could not open audio device\n /dev/dsp\n" 155 QString errorMsg="Could not open audio device\n /dev/dsp\n"
156 +(QString)strerror(errno); 156 +(QString)strerror(errno);
157 qDebug("XXXXXXXXXXXXXXXXXXXXXXX "+errorMsg); 157 odebug << "XXXXXXXXXXXXXXXXXXXXXXX "+errorMsg << oendl;
158 return -1; 158 return -1;
159 } 159 }
160 160
161qDebug("Opening mixer"); 161odebug << "Opening mixer" << oendl;
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 perror("open(\"/dev/mixer\")"); 164 perror("open(\"/dev/mixer\")");
165 QString errorMsg="Could not open audio device\n /dev/dsp\n" 165 QString errorMsg="Could not open audio device\n /dev/dsp\n"
166 +(QString)strerror(errno); 166 +(QString)strerror(errno);
167 qDebug("XXXXXXXXXXXXXXXXXXXXXX "+errorMsg); 167 odebug << "XXXXXXXXXXXXXXXXXXXXXX "+errorMsg << oendl;
168 } 168 }
169 169
170 if(ioctl(sd,SNDCTL_DSP_RESET,0)<0){ 170 if(ioctl(sd,SNDCTL_DSP_RESET,0)<0){
171 perror("ioctl RESET"); 171 perror("ioctl RESET");
172 } 172 }
173// sprintf(message, "%d", sd); 173// sprintf(message, "%d", sd);
@@ -177,13 +177,13 @@ qDebug("Opening mixer");
177 f1.writeBlock(message, strlen(message)); 177 f1.writeBlock(message, strlen(message));
178 f1.close(); 178 f1.close();
179 */ 179 */
180 /* close(pipefd[0]); 180 /* close(pipefd[0]);
181 write(pipefd[1], message, sizeof(message)); 181 write(pipefd[1], message, sizeof(message));
182 close(pipefd[1]); 182 close(pipefd[1]);
183 // qDebug("%d",soundDevice->sd ); 183 // odebug << "" << soundDevice->sd << "" << oendl;
184 _exit(0); 184 _exit(0);
185 } 185 }
186 default: 186 default:
187 // pid greater than zero is parent getting the child's pid 187 // pid greater than zero is parent getting the child's pid
188 printf("Child's pid is %d\n",pid); 188 printf("Child's pid is %d\n",pid);
189 QString s; 189 QString s;
@@ -203,19 +203,19 @@ qDebug("Opening mixer");
203 // for(int f=0; f < t.atEnd() ;f++) { 203 // for(int f=0; f < t.atEnd() ;f++) {
204 s = t.readLine(); 204 s = t.readLine();
205 // } 205 // }
206 */ 206 */
207// bool ok; 207// bool ok;
208// sd = s.toInt(&ok, 10); 208// sd = s.toInt(&ok, 10);
209// qDebug("<<<<<<<<<<<<<>>>>>>>>>>>>"+s); 209// odebug << "<<<<<<<<<<<<<>>>>>>>>>>>>"+s << oendl;
210 210
211// f2.close(); 211// f2.close();
212// } 212// }
213::close(mixerHandle ); 213::close(mixerHandle );
214// qDebug("open device %s", dspstr); 214// odebug << "open device " << dspstr << "" << oendl;
215// qDebug("success! %d",sd); 215// odebug << "success! " << sd << "" << oendl;
216 return sd; 216 return sd;
217} 217}
218 218
219bool Device::closeDevice( bool) { 219bool Device::closeDevice( bool) {
220// if(b) {//close now 220// if(b) {//close now
221// if (ioctl( sd, SNDCTL_DSP_RESET, 0) == -1) { 221// if (ioctl( sd, SNDCTL_DSP_RESET, 0) == -1) {
@@ -227,38 +227,38 @@ bool Device::closeDevice( bool) {
227// } 227// }
228// } 228// }
229 229
230 ::close( sd); //close sound device 230 ::close( sd); //close sound device
231// sdfd=0; 231// sdfd=0;
232 // sd=0; 232 // sd=0;
233// qDebug("closed dsp"); 233// odebug << "closed dsp" << oendl;
234 return true; 234 return true;
235} 235}
236 236
237bool Device::setDeviceFormat( int form) { 237bool Device::setDeviceFormat( int form) {
238 qDebug("set device res %d %d", form, sd); 238 odebug << "set device res " << form << " " << sd << "" << oendl;
239 if (ioctl( sd, SNDCTL_DSP_SETFMT, &form)==-1) { //set format 239 if (ioctl( sd, SNDCTL_DSP_SETFMT, &form)==-1) { //set format
240 perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); 240 perror("ioctl(\"SNDCTL_DSP_SETFMT\")");
241 return false; 241 return false;
242 } 242 }
243 devRes=form; 243 devRes=form;
244 return true; 244 return true;
245} 245}
246 246
247bool Device::setDeviceChannels( int ch) { 247bool Device::setDeviceChannels( int ch) {
248 qDebug("set channels %d %d", ch, sd); 248 odebug << "set channels " << ch << " " << sd << "" << oendl;
249 if (ioctl( sd, SNDCTL_DSP_CHANNELS, &ch)==-1) { 249 if (ioctl( sd, SNDCTL_DSP_CHANNELS, &ch)==-1) {
250 perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); 250 perror("ioctl(\"SNDCTL_DSP_CHANNELS\")");
251 return false; 251 return false;
252 } 252 }
253 devCh=ch; 253 devCh=ch;
254 return true; 254 return true;
255} 255}
256 256
257bool Device::setDeviceRate( int rate) { 257bool Device::setDeviceRate( int rate) {
258 qDebug("set rate %d %d", rate, sd); 258 odebug << "set rate " << rate << " " << sd << "" << oendl;
259 if (ioctl( sd, SNDCTL_DSP_SPEED, &rate) == -1) { 259 if (ioctl( sd, SNDCTL_DSP_SPEED, &rate) == -1) {
260 perror("ioctl(\"SNDCTL_DSP_SPEED\")"); 260 perror("ioctl(\"SNDCTL_DSP_SPEED\")");
261 return false; 261 return false;
262 } 262 }
263 263
264 devRate=rate; 264 devRate=rate;
@@ -315,15 +315,15 @@ int Device::getDeviceChannels() {
315} 315}
316 316
317int Device::getDeviceFragSize() { 317int Device::getDeviceFragSize() {
318 int frag_size; 318 int frag_size;
319 319
320 if (ioctl( sd, SNDCTL_DSP_GETBLKSIZE, &frag_size) == -1) { 320 if (ioctl( sd, SNDCTL_DSP_GETBLKSIZE, &frag_size) == -1) {
321 qDebug("no fragsize"); 321 odebug << "no fragsize" << oendl;
322 } else { 322 } else {
323 qDebug("driver says frag size is %d", frag_size); 323 odebug << "driver says frag size is " << frag_size << "" << oendl;
324 } 324 }
325 return frag_size; 325 return frag_size;
326} 326}
327 327
328bool Device::setFragSize(int frag) { 328bool Device::setFragSize(int frag) {
329 if (ioctl(sd, SNDCTL_DSP_SETFRAGMENT, &frag)) { 329 if (ioctl(sd, SNDCTL_DSP_SETFRAGMENT, &frag)) {