summaryrefslogtreecommitdiff
path: root/noncore/multimedia/opierec/device.cpp
Unidiff
Diffstat (limited to 'noncore/multimedia/opierec/device.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/multimedia/opierec/device.cpp220
1 files changed, 61 insertions, 159 deletions
diff --git a/noncore/multimedia/opierec/device.cpp b/noncore/multimedia/opierec/device.cpp
index cb47b77..e7e0f4b 100644
--- a/noncore/multimedia/opierec/device.cpp
+++ b/noncore/multimedia/opierec/device.cpp
@@ -5,6 +5,8 @@
5#include <qpe/config.h> 5#include <qpe/config.h>
6#include <qpe/qcopenvelope_qws.h> 6#include <qpe/qcopenvelope_qws.h>
7 7
8#include <opie2/odebug.h>
9
8/* STD */ 10/* STD */
9#include <fcntl.h> 11#include <fcntl.h>
10#include <stdio.h> 12#include <stdio.h>
@@ -17,27 +19,52 @@
17#include <errno.h> 19#include <errno.h>
18 20
19//extern QtRec *qperec; 21//extern QtRec *qperec;
22#if defined(QT_QWS_SL5XXX)
23///#if defined(QT_QWS_EBX)
24
25#define DSPSTROUT "/dev/dsp"
26#define DSPSTRMIXEROUT "/dev/mixer"
27
28#ifdef SHARP
29#define DSPSTRIN "/dev/dsp1"
30#define DSPSTRMIXERIN "/dev/mixer1"
31#else
32#define DSPSTRIN "/dev/dsp"
33#define DSPSTRMIXERIN "/dev/mixer"
34#endif
35
36#else
37
38#ifdef QT_QWS_DEVFS
39#define DSPSTROUT "/dev/sound/dsp"
40#define DSPSTRIN "/dev/sound/dsp"
41#define DSPSTRMIXERIN "/dev/sound/mixer"
42#define DSPSTRMIXEROUT "/dev/sound/mixer"
43#else
44#define DSPSTROUT "/dev/dsp"
45#define DSPSTRIN "/dev/dsp"
46#define DSPSTRMIXERIN "/dev/mixer"
47#define DSPSTRMIXEROUT "/dev/mixer"
48#endif
49
50#endif
20 51
21Device::Device( QObject * parent, const char * dsp, const char * mixr, bool record ) 52Device::Device( QObject * parent, bool record )
22 : QObject( parent) 53 : QObject( parent)
23{ 54{
24 dspstr = (char *)dsp; 55// dspstr = dsp;
25 mixstr = (char *)mixr;
26
27 devForm=-1; 56 devForm=-1;
28 devCh=-1; 57 devCh=-1;
29 devRate=-1; 58 devRate=-1;
30 59
31 if( !record){ //playing 60 if( !record){ //playing
32 qDebug( "setting up DSP for playing" ); 61 owarn << "setting up DSP for playing" << oendl;
33 flags = O_WRONLY; 62 flags = O_WRONLY;
34 } else { //recording 63 } else { //recording
35 qDebug( "setting up DSP for recording" ); 64 owarn << "setting up DSP for recording" << oendl;
36 flags = O_RDWR; 65 flags = O_RDWR;
37// flags = O_RDONLY; 66// flags = O_RDONLY;
38 67 selectMicInput();
39// selectMicInput();
40
41 } 68 }
42} 69}
43 70
@@ -50,22 +77,9 @@ bool Device::openDsp() {
50} 77}
51 78
52int Device::openDevice( int flags) { 79int Device::openDevice( int flags) {
53/* pid_t pid; 80 owarn << "Opening"<< dspstr;
54 int status; 81
55 int pipefd[2]; 82 if (( sd = ::open( DSPSTROUT, flags)) == -1) {
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\")"); 83 perror("open(\"/dev/dsp\")");
70 QString errorMsg="Could not open audio device\n /dev/dsp\n" 84 QString errorMsg="Could not open audio device\n /dev/dsp\n"
71 +(QString)strerror(errno); 85 +(QString)strerror(errno);
@@ -73,153 +87,58 @@ qDebug( "Opening %s",dspstr);
73 return -1; 87 return -1;
74 } 88 }
75 89
76qDebug( "Opening mixer" );
77 int mixerHandle=0;
78#ifdef QT_QWS_DEVFS
79 if (( mixerHandle = open("/dev/sound/mixer",O_RDWR))<0) {
80#else
81 if (( mixerHandle = open("/dev/mixer",O_RDWR))<0) {
82#endif
83 perror("open(\"/dev/mixer\")");
84 QString errorMsg="Could not open audio device\n /dev/dsp\n"
85 +(QString)strerror(errno);
86 qDebug( "XXXXXXXXXXXXXXXXXXXXXX "+errorMsg );
87 }
88
89 if(ioctl(sd,SNDCTL_DSP_RESET,0)<0){ 90 if(ioctl(sd,SNDCTL_DSP_RESET,0)<0){
90 perror("ioctl RESET"); 91 perror("ioctl RESET");
91 } 92 }
92// sprintf(message, "%d", sd);
93
94/* QFile f1("/pid");
95 f1.open(IO_WriteOnly );
96 f1.writeBlock(message, strlen(message));
97 f1.close();
98 */
99 /* close(pipefd[0]);
100 write(pipefd[1], message, sizeof(message));
101 close(pipefd[1]);
102 // qDebug( "" + soundDevice->sd );
103 _exit(0);
104 }
105 default:
106 // pid greater than zero is parent getting the child's pid
107 printf("Child's pid is %d\n",pid);
108 QString s;
109 close(pipefd[1]);
110 read(pipefd[0], message, sizeof(message));
111 s = message;
112 close(pipefd[0]);
113
114// while(wait(NULL)!=pid)
115 // ;
116 printf("child %ld terminated normally, return status is zero\n", (long) pid);
117 */
118 // filePara.sd=(long) pid;
119 /* QFile f2("/pid");
120 f2.open(IO_ReadOnly);
121 QTextStream t(&f2);
122 // for(int f=0; f < t.atEnd() ;f++) {
123 s = t.readLine();
124 // }
125 */
126// bool ok;
127// sd = s.toInt(&ok, 10);
128// qDebug( "<<<<<<<<<<<<<>>>>>>>>>>>>"+s );
129
130// f2.close();
131// }
132::close(mixerHandle );
133// qDebug( "open device " + dspstr );
134// qDebug( "success! " + sd );
135 return sd; 93 return sd;
136} 94}
137 95
96int Device::getInVolume() {
97 unsigned int volume = 0;
98 Config cfg("qpe");
99 cfg.setGroup("Volume");
100
101 return cfg.readNumEntry("Mic");
102}
138 103
139int Device::getOutVolume( ) { 104int Device::getOutVolume( ) {
140 unsigned int volume; 105 unsigned int volume;
141 int mixerHandle = open( mixstr, O_RDWR );
142 if ( mixerHandle >= 0 ) {
143 if(ioctl( mixerHandle, MIXER_READ(SOUND_MIXER_VOLUME), &volume )==-1)
144 perror("<<<<<<<<<<<<<<ioctl(\"MIXER_READ\")");
145 ::close( mixerHandle );
146 } else
147 perror("open(\"/dev/mixer\")");
148 printf("<<<<<<<<<<<<<<<<<<<<output volume %d\n",volume);
149
150 Config cfg("qpe"); 106 Config cfg("qpe");
151 cfg.setGroup("Volume"); 107 cfg.setGroup("Volume");
152 108
153 return cfg.readNumEntry("VolumePercent"); 109 return cfg.readNumEntry("VolumePercent");
154} 110}
155 111
156int Device::getInVolume() { 112
157 unsigned int volume=0; 113void Device::changedInVolume(int vol ) {
158 int mixerHandle = ::open( mixstr, O_RDWR );
159 if ( mixerHandle >= 0 ) {
160 if(ioctl( mixerHandle, MIXER_READ(SOUND_MIXER_MIC), &volume )==-1)
161 perror("<<<<<<<<<<<<<<<ioctl(\"MIXER_READ\")");
162 ::close( mixerHandle );
163 } else
164 perror("open(\"/dev/mixer\")");
165 printf("<<<<<<<<<<<<<<input volume %d\n", volume );
166 Config cfg("qpe"); 114 Config cfg("qpe");
167 cfg.setGroup("Volume"); 115 cfg.setGroup("Volume");
168 116 cfg.writeEntry("Mic", QString::number(vol ));
169 return cfg.readNumEntry("Mic"); 117 QCopEnvelope( "QPE/System", "micChange(bool)" ) << false;
170} 118}
171 119
172void Device::changedOutVolume(int vol) { 120void Device::changedOutVolume(int vol) {
173 int level = (vol << 8) + vol;
174 int fd = 0;
175#ifdef QT_QWS_DEVFS
176 if ((fd = open("/dev/sound/mixer", O_RDWR))>=0) {
177#else
178 if ((fd = open("/dev/mixer", O_RDWR))>=0) {
179#endif
180 if(ioctl(fd, MIXER_WRITE(SOUND_MIXER_VOLUME), &level) == -1)
181 perror("ioctl(\"MIXER_IN_WRITE\")");
182
183 Config cfg("qpe"); 121 Config cfg("qpe");
184 cfg.setGroup("Volume"); 122 cfg.setGroup("Volume");
185 cfg.writeEntry("VolumePercent", QString::number( vol )); 123 cfg.writeEntry("VolumePercent", QString::number( vol ));
124
186 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << false; 125 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << false;
187 qDebug("changing output vol %d" ,vol );
188 }
189 ::close(fd);
190}
191 126
192void Device::changedInVolume(int vol ) { 127 owarn << "changing output vol " << vol << oendl;
193 int level = (vol << 8) + vol;
194 int fd = 0;
195#ifdef QT_QWS_DEVFS
196 if ((fd = open("/dev/sound/mixer", O_RDWR))>=0) {
197#else
198 if ((fd = open("/dev/mixer", O_RDWR))>=0) {
199#endif
200 if(ioctl(fd, MIXER_WRITE(SOUND_MIXER_MIC), &level) == -1)
201 perror("ioctl(\"MIXER_IN_WRITE\")");
202 Config cfg("qpe");
203 cfg.setGroup("Volume");
204 cfg.writeEntry("Mic", QString::number(vol ));
205 QCopEnvelope( "QPE/System", "micChange(bool)" ) << false;
206 qDebug("changing input volume %d",vol);
207 }
208 ::close(fd);
209} 128}
210 129
211bool Device::selectMicInput() { 130bool Device::selectMicInput() {
212 131
213 int md=0; 132 int md=0;
214 int info=MIXER_WRITE(SOUND_MIXER_MIC); 133 int info = SOUND_MASK_MIC;//MIXER_WRITE(SOUND_MIXER_MIC);
215#ifdef QT_QWS_DEVFS 134 owarn << "sectMicInput" << oendl;
216 md = ::open( "/dev/sound/mixer", O_RDWR ); 135 md = ::open( DSPSTRMIXEROUT, O_RDWR );
217#else 136
218 md = ::open( "/dev/mixer", O_RDWR ); 137 if ( md <= 0) {
219#endif 138 QString err;
220 if ( md == -1) 139 err.sprintf("open %s", DSPSTRMIXEROUT);
221 perror("open(\"/dev/mixer\")"); 140 perror(err.latin1());
222 else { 141 } else {
223 if( ioctl( md, SOUND_MIXER_WRITE_RECSRC, &info) == -1) 142 if( ioctl( md, SOUND_MIXER_WRITE_RECSRC, &info) == -1)
224 perror("ioctl(\"SOUND_MIXER_WRITE_RECSRC\")"); 143 perror("ioctl(\"SOUND_MIXER_WRITE_RECSRC\")");
225 ::close(md); 144 ::close(md);
@@ -231,20 +150,7 @@ bool Device::selectMicInput() {
231} 150}
232 151
233bool Device::closeDevice( bool) { 152bool Device::closeDevice( bool) {
234// if(b) {//close now
235// if (ioctl( sd, SNDCTL_DSP_RESET, 0) == -1) {
236// perror("ioctl(\"SNDCTL_DSP_RESET\")");
237// }
238// } else { //let play
239// if (ioctl( sd, SNDCTL_DSP_SYNC, 0) == -1) {
240// perror("ioctl(\"SNDCTL_DSP_SYNC\")");
241// }
242// }
243
244 ::close( sd); //close sound device 153 ::close( sd); //close sound device
245// sdfd=0;
246 // sd=0;
247// qDebug( "closed dsp" );
248 return true; 154 return true;
249} 155}
250 156
@@ -312,11 +218,9 @@ int Device::getDeviceRate() {
312 218
313int Device::getDeviceBits() { 219int Device::getDeviceBits() {
314 int dBits=0; 220 int dBits=0;
315#ifndef QT_QWS_EBX // zaurus doesnt have this
316 if (ioctl( sd, SOUND_PCM_READ_BITS, &dBits) == -1) { 221 if (ioctl( sd, SOUND_PCM_READ_BITS, &dBits) == -1) {
317 perror("ioctl(\"SNDCTL_PCM_READ_BITS\")"); 222 perror("ioctl(\"SNDCTL_PCM_READ_BITS\")");
318 } 223 }
319#endif
320 return dBits; 224 return dBits;
321} 225}
322 226
@@ -370,5 +274,3 @@ int Device::devWrite(int soundDescriptor, short * buf, int size) {
370 bytesWritten = ::write( sd /*soundDescriptor*/, buf, size); 274 bytesWritten = ::write( sd /*soundDescriptor*/, buf, size);
371 return bytesWritten; 275 return bytesWritten;
372} 276}
373
374