author | llornkcor <llornkcor> | 2004-08-06 19:03:36 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2004-08-06 19:03:36 (UTC) |
commit | 5e10278e748608766245ff9f59a54d1ae8ff6f7e (patch) (unidiff) | |
tree | ca01e05ff77f7b80209deba47c93be48d20d8df2 | |
parent | 75675815cb051e14bf8ad50c4069338bfa83eed1 (diff) | |
download | opie-5e10278e748608766245ff9f59a54d1ae8ff6f7e.zip opie-5e10278e748608766245ff9f59a54d1ae8ff6f7e.tar.gz opie-5e10278e748608766245ff9f59a54d1ae8ff6f7e.tar.bz2 |
no warnings
-rw-r--r-- | noncore/multimedia/opierec/device.cpp | 192 |
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,282 +1,280 @@ | |||
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> |
9 | using 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> |
16 | #include <sys/soundcard.h> | 13 | #include <sys/soundcard.h> |
17 | #include <unistd.h> | 14 | #include <unistd.h> |
18 | #include <sys/wait.h> | 15 | #include <sys/wait.h> |
19 | #include <unistd.h> | 16 | #include <unistd.h> |
20 | #include <errno.h> | 17 | #include <errno.h> |
21 | 18 | ||
22 | //extern QtRec *qperec; | 19 | //extern QtRec *qperec; |
23 | 20 | ||
24 | Device::Device( QObject * parent, const char * dsp, const char * mixr, bool record ) | 21 | Device::Device( QObject * parent, const char * dsp, const char * mixr, bool record ) |
25 | : QObject( parent) | 22 | : QObject( parent) |
26 | { | 23 | { |
27 | dspstr = (char *)dsp; | 24 | dspstr = (char *)dsp; |
28 | mixstr = (char *)mixr; | 25 | mixstr = (char *)mixr; |
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 | } |
45 | } | 42 | } |
46 | 43 | ||
47 | bool Device::openDsp() { | 44 | bool Device::openDsp() { |
48 | if( openDevice( flags) == -1) { | 45 | if( openDevice( flags) == -1) { |
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 | ||
52 | int 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"); | ||
59 | exit(1); | ||
60 | } | ||
61 | switch (pid = fork()) { | ||
62 | case -1: | ||
63 | perror("The fork failed!"); | ||
64 | break; | ||
65 | case 0: { | ||
66 | */ | ||
67 | qDebug( "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 | |||
76 | qDebug( "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 | |||
55 | int Device::getOutVolume( ) { | 135 | int 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\")"); |
61 | ::close( mixerHandle ); | 141 | ::close( mixerHandle ); |
62 | } else | 142 | } else |
63 | perror("open(\"/dev/mixer\")"); | 143 | perror("open(\"/dev/mixer\")"); |
64 | printf("<<<<<<<<<<<<<<<<<<<<output volume %d\n",volume); | 144 | printf("<<<<<<<<<<<<<<<<<<<<output volume %d\n",volume); |
65 | 145 | ||
66 | Config cfg("qpe"); | 146 | Config cfg("qpe"); |
67 | cfg.setGroup("Volume"); | 147 | cfg.setGroup("Volume"); |
68 | 148 | ||
69 | return cfg.readNumEntry("VolumePercent"); | 149 | return cfg.readNumEntry("VolumePercent"); |
70 | } | 150 | } |
71 | 151 | ||
72 | int Device::getInVolume() { | 152 | int Device::getInVolume() { |
73 | unsigned int volume=0; | 153 | unsigned int volume=0; |
74 | int mixerHandle = ::open( mixstr, O_RDWR ); | 154 | int mixerHandle = ::open( mixstr, O_RDWR ); |
75 | if ( mixerHandle >= 0 ) { | 155 | if ( mixerHandle >= 0 ) { |
76 | if(ioctl( mixerHandle, MIXER_READ(SOUND_MIXER_MIC), &volume )==-1) | 156 | if(ioctl( mixerHandle, MIXER_READ(SOUND_MIXER_MIC), &volume )==-1) |
77 | perror("<<<<<<<<<<<<<<<ioctl(\"MIXER_READ\")"); | 157 | perror("<<<<<<<<<<<<<<<ioctl(\"MIXER_READ\")"); |
78 | ::close( mixerHandle ); | 158 | ::close( mixerHandle ); |
79 | } else | 159 | } else |
80 | perror("open(\"/dev/mixer\")"); | 160 | perror("open(\"/dev/mixer\")"); |
81 | printf("<<<<<<<<<<<<<<input volume %d\n", volume ); | 161 | printf("<<<<<<<<<<<<<<input volume %d\n", volume ); |
82 | Config cfg("qpe"); | 162 | Config cfg("qpe"); |
83 | cfg.setGroup("Volume"); | 163 | cfg.setGroup("Volume"); |
84 | 164 | ||
85 | return cfg.readNumEntry("Mic"); | 165 | return cfg.readNumEntry("Mic"); |
86 | } | 166 | } |
87 | 167 | ||
88 | void Device::changedOutVolume(int vol) { | 168 | void Device::changedOutVolume(int vol) { |
89 | int level = (vol << 8) + vol; | 169 | int level = (vol << 8) + vol; |
90 | int fd = 0; | 170 | int fd = 0; |
91 | if ((fd = open("/dev/mixer", O_RDWR))>=0) { | 171 | if ((fd = open("/dev/mixer", O_RDWR))>=0) { |
92 | if(ioctl(fd, MIXER_WRITE(SOUND_MIXER_VOLUME), &level) == -1) | 172 | if(ioctl(fd, MIXER_WRITE(SOUND_MIXER_VOLUME), &level) == -1) |
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 | ||
104 | void Device::changedInVolume(int vol ) { | 184 | void Device::changedInVolume(int vol ) { |
105 | int level = (vol << 8) + vol; | 185 | int level = (vol << 8) + vol; |
106 | int fd = 0; | 186 | int fd = 0; |
107 | if ((fd = open("/dev/mixer", O_RDWR))>=0) { | 187 | if ((fd = open("/dev/mixer", O_RDWR))>=0) { |
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 | ||
119 | bool Device::selectMicInput() { | 199 | bool Device::selectMicInput() { |
120 | 200 | ||
121 | int md=0; | 201 | int md=0; |
122 | int info=MIXER_WRITE(SOUND_MIXER_MIC); | 202 | int info=MIXER_WRITE(SOUND_MIXER_MIC); |
123 | md = ::open( "/dev/mixer", O_RDWR ); | 203 | md = ::open( "/dev/mixer", O_RDWR ); |
124 | if ( md == -1) | 204 | if ( md == -1) |
125 | perror("open(\"/dev/mixer\")"); | 205 | perror("open(\"/dev/mixer\")"); |
126 | else { | 206 | else { |
127 | if( ioctl( md, SOUND_MIXER_WRITE_RECSRC, &info) == -1) | 207 | if( ioctl( md, SOUND_MIXER_WRITE_RECSRC, &info) == -1) |
128 | perror("ioctl(\"SOUND_MIXER_WRITE_RECSRC\")"); | 208 | perror("ioctl(\"SOUND_MIXER_WRITE_RECSRC\")"); |
129 | ::close(md); | 209 | ::close(md); |
130 | return false; | 210 | return false; |
131 | } | 211 | } |
132 | ::close(md); | 212 | ::close(md); |
133 | 213 | ||
134 | return true; | 214 | return true; |
135 | } | 215 | } |
136 | 216 | ||
137 | int 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"); | ||
144 | exit(1); | ||
145 | } | ||
146 | switch (pid = fork()) { | ||
147 | case -1: | ||
148 | perror("The fork failed!"); | ||
149 | break; | ||
150 | case 0: { | ||
151 | */ | ||
152 | odebug << "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 | |||
161 | odebug << "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 | |||
219 | bool Device::closeDevice( bool) { | 217 | bool 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 |
225 | // if (ioctl( sd, SNDCTL_DSP_SYNC, 0) == -1) { | 223 | // if (ioctl( sd, SNDCTL_DSP_SYNC, 0) == -1) { |
226 | // perror("ioctl(\"SNDCTL_DSP_SYNC\")"); | 224 | // perror("ioctl(\"SNDCTL_DSP_SYNC\")"); |
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 | ||
237 | bool Device::setDeviceFormat( int form) { | 235 | bool 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 | ||
247 | bool Device::setDeviceChannels( int ch) { | 245 | bool 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 | ||
257 | bool Device::setDeviceRate( int rate) { | 255 | bool 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; |
265 | 263 | ||
266 | return true; | 264 | return true; |
267 | } | 265 | } |
268 | 266 | ||
269 | int Device::getRes() { | 267 | int Device::getRes() { |
270 | return devRes; | 268 | return devRes; |
271 | } | 269 | } |
272 | 270 | ||
273 | int Device::getFormat() { | 271 | int Device::getFormat() { |
274 | return devForm; | 272 | return devForm; |
275 | } | 273 | } |
276 | 274 | ||
277 | int Device::getRate() { | 275 | int Device::getRate() { |
278 | return devRate; | 276 | return devRate; |
279 | } | 277 | } |
280 | 278 | ||
281 | int Device::getChannels() { | 279 | int Device::getChannels() { |
282 | return devCh; | 280 | return devCh; |
@@ -297,62 +295,64 @@ int Device::getDeviceRate() { | |||
297 | } | 295 | } |
298 | 296 | ||
299 | int Device::getDeviceBits() { | 297 | int Device::getDeviceBits() { |
300 | int dBits=0; | 298 | int dBits=0; |
301 | #ifndef QT_QWS_EBX // zaurus doesnt have this | 299 | #ifndef QT_QWS_EBX // zaurus doesnt have this |
302 | if (ioctl( sd, SOUND_PCM_READ_BITS, &dBits) == -1) { | 300 | if (ioctl( sd, SOUND_PCM_READ_BITS, &dBits) == -1) { |
303 | perror("ioctl(\"SNDCTL_PCM_READ_BITS\")"); | 301 | perror("ioctl(\"SNDCTL_PCM_READ_BITS\")"); |
304 | } | 302 | } |
305 | #endif | 303 | #endif |
306 | return dBits; | 304 | return dBits; |
307 | } | 305 | } |
308 | 306 | ||
309 | int Device::getDeviceChannels() { | 307 | int Device::getDeviceChannels() { |
310 | int dCh=0; | 308 | int dCh=0; |
311 | if (ioctl( sd, SOUND_PCM_READ_CHANNELS, &dCh) == -1) { | 309 | if (ioctl( sd, SOUND_PCM_READ_CHANNELS, &dCh) == -1) { |
312 | perror("ioctl(\"SNDCTL_PCM_READ_CHANNELS\")"); | 310 | perror("ioctl(\"SNDCTL_PCM_READ_CHANNELS\")"); |
313 | } | 311 | } |
314 | return dCh; | 312 | return dCh; |
315 | } | 313 | } |
316 | 314 | ||
317 | int Device::getDeviceFragSize() { | 315 | 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 | } |
327 | 325 | ||
328 | bool Device::setFragSize(int frag) { | 326 | bool Device::setFragSize(int frag) { |
329 | if (ioctl(sd, SNDCTL_DSP_SETFRAGMENT, &frag)) { | 327 | if (ioctl(sd, SNDCTL_DSP_SETFRAGMENT, &frag)) { |
330 | perror("ioctl(\"SNDCTL_DSP_SETFRAGMENT\")"); | 328 | perror("ioctl(\"SNDCTL_DSP_SETFRAGMENT\")"); |
331 | return false; | 329 | return false; |
332 | } | 330 | } |
333 | return true; | 331 | return true; |
334 | } | 332 | } |
335 | 333 | ||
336 | bool Device::reset() { | 334 | bool Device::reset() { |
337 | closeDevice(true); | 335 | closeDevice(true); |
338 | openDsp(); | 336 | openDsp(); |
339 | if (ioctl( sd, SNDCTL_DSP_RESET, 0) == -1) { | 337 | if (ioctl( sd, SNDCTL_DSP_RESET, 0) == -1) { |
340 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); | 338 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); |
341 | return false; | 339 | return false; |
342 | } | 340 | } |
343 | return true; | 341 | return true; |
344 | } | 342 | } |
345 | 343 | ||
346 | int Device::devRead(int soundDescriptor, short *buf, int size) { | 344 | int 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 | ||
352 | int Device::devWrite(int soundDescriptor, short * buf, int size) { | 351 | int 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 | ||