author | llornkcor <llornkcor> | 2003-04-04 03:03:38 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2003-04-04 03:03:38 (UTC) |
commit | ce6388c4f44e9e76342a338954fff598372e06f0 (patch) (unidiff) | |
tree | 895c202343fc394335e6effdb535ccb864a587d3 | |
parent | 487971af0c1b70babcc39fd549dc0d8142cd4865 (diff) | |
download | opie-ce6388c4f44e9e76342a338954fff598372e06f0.zip opie-ce6388c4f44e9e76342a338954fff598372e06f0.tar.gz opie-ce6388c4f44e9e76342a338954fff598372e06f0.tar.bz2 |
bitches owe me money. initial commit. zaurus/vercel has sound drivers that doesnt actually change samplerates, so this kinda has problems, currently
-rw-r--r-- | noncore/multimedia/opierec/adpcm.c | 252 | ||||
-rw-r--r-- | noncore/multimedia/opierec/adpcm.h | 19 | ||||
-rw-r--r-- | noncore/multimedia/opierec/device.cpp | 341 | ||||
-rw-r--r-- | noncore/multimedia/opierec/device.h | 45 | ||||
-rw-r--r-- | noncore/multimedia/opierec/helpwindow.cpp | 219 | ||||
-rw-r--r-- | noncore/multimedia/opierec/helpwindow.h | 62 | ||||
-rw-r--r-- | noncore/multimedia/opierec/main.cpp | 22 | ||||
-rw-r--r-- | noncore/multimedia/opierec/opierec-control | 10 | ||||
-rw-r--r-- | noncore/multimedia/opierec/opierec.pro | 12 | ||||
-rw-r--r-- | noncore/multimedia/opierec/pixmaps.h | 294 | ||||
-rw-r--r-- | noncore/multimedia/opierec/qtrec.cpp | 2270 | ||||
-rw-r--r-- | noncore/multimedia/opierec/qtrec.h | 185 | ||||
-rw-r--r-- | noncore/multimedia/opierec/wavFile.cpp | 303 | ||||
-rw-r--r-- | noncore/multimedia/opierec/wavFile.h | 56 |
14 files changed, 4090 insertions, 0 deletions
diff --git a/noncore/multimedia/opierec/adpcm.c b/noncore/multimedia/opierec/adpcm.c new file mode 100644 index 0000000..716fefd --- a/dev/null +++ b/noncore/multimedia/opierec/adpcm.c | |||
@@ -0,0 +1,252 @@ | |||
1 | /*********************************************************** | ||
2 | Copyright 1992 by Stichting Mathematisch Centrum, Amsterdam, The | ||
3 | Netherlands. | ||
4 | |||
5 | All Rights Reserved | ||
6 | |||
7 | Permission to use, copy, modify, and distribute this software and its | ||
8 | documentation for any purpose and without fee is hereby granted, | ||
9 | provided that the above copyright notice appear in all copies and that | ||
10 | both that copyright notice and this permission notice appear in | ||
11 | supporting documentation, and that the names of Stichting Mathematisch | ||
12 | Centrum or CWI not be used in advertising or publicity pertaining to | ||
13 | distribution of the software without specific, written prior permission. | ||
14 | |||
15 | STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO | ||
16 | THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND | ||
17 | FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE | ||
18 | FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
19 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
20 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT | ||
21 | OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
22 | |||
23 | ******************************************************************/ | ||
24 | |||
25 | /* | ||
26 | ** Intel/DVI ADPCM coder/decoder. | ||
27 | ** | ||
28 | ** The algorithm for this coder was taken from the IMA Compatability Project | ||
29 | ** proceedings, Vol 2, Number 2; May 1992. | ||
30 | ** | ||
31 | ** Version 1.2, 18-Dec-92. | ||
32 | ** | ||
33 | ** Change log: | ||
34 | ** - Fixed a stupid bug, where the delta was computed as | ||
35 | ** stepsize*code/4 in stead of stepsize*(code+0.5)/4. | ||
36 | ** - There was an off-by-one error causing it to pick | ||
37 | ** an incorrect delta once in a blue moon. | ||
38 | ** - The NODIVMUL define has been removed. Computations are now always done | ||
39 | ** using shifts, adds and subtracts. It turned out that, because the standard | ||
40 | ** is defined using shift/add/subtract, you needed bits of fixup code | ||
41 | ** (because the div/mul simulation using shift/add/sub made some rounding | ||
42 | ** errors that real div/mul don't make) and all together the resultant code | ||
43 | ** ran slower than just using the shifts all the time. | ||
44 | ** - Changed some of the variable names to be more meaningful. | ||
45 | */ | ||
46 | |||
47 | #include "adpcm.h" | ||
48 | #include <stdio.h> /*DBG*/ | ||
49 | |||
50 | #ifndef __STDC__ | ||
51 | #define signed | ||
52 | #endif | ||
53 | |||
54 | /* Intel ADPCM step variation table */ | ||
55 | static int indexTable[16] = { | ||
56 | -1, -1, -1, -1, 2, 4, 6, 8, | ||
57 | -1, -1, -1, -1, 2, 4, 6, 8, | ||
58 | }; | ||
59 | |||
60 | static int stepsizeTable[89] = { | ||
61 | 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, | ||
62 | 19, 21, 23, 25, 28, 31, 34, 37, 41, 45, | ||
63 | 50, 55, 60, 66, 73, 80, 88, 97, 107, 118, | ||
64 | 130, 143, 157, 173, 190, 209, 230, 253, 279, 307, | ||
65 | 337, 371, 408, 449, 494, 544, 598, 658, 724, 796, | ||
66 | 876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066, | ||
67 | 2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428, 4871, 5358, | ||
68 | 5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899, | ||
69 | 15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767 | ||
70 | }; | ||
71 | |||
72 | void | ||
73 | adpcm_coder(indata, outdata, len, state) | ||
74 | short indata[]; | ||
75 | char outdata[]; | ||
76 | int len; | ||
77 | struct adpcm_state *state; | ||
78 | { | ||
79 | short *inp; /* Input buffer pointer */ | ||
80 | signed char *outp; /* output buffer pointer */ | ||
81 | int val; /* Current input sample value */ | ||
82 | int sign; /* Current adpcm sign bit */ | ||
83 | int delta; /* Current adpcm output value */ | ||
84 | int diff; /* Difference between val and valprev */ | ||
85 | int step; /* Stepsize */ | ||
86 | int valpred; /* Predicted output value */ | ||
87 | int vpdiff; /* Current change to valpred */ | ||
88 | int index; /* Current step change index */ | ||
89 | int outputbuffer=0; /* place to keep previous 4-bit value */ | ||
90 | int bufferstep; /* toggle between outputbuffer/output */ | ||
91 | |||
92 | outp = (signed char *)outdata; | ||
93 | inp = indata; | ||
94 | |||
95 | valpred = state->valprev; | ||
96 | index = state->index; | ||
97 | step = stepsizeTable[index]; | ||
98 | |||
99 | bufferstep = 1; | ||
100 | |||
101 | for ( ; len > 0 ; len-- ) { | ||
102 | val = *inp++; | ||
103 | |||
104 | /* Step 1 - compute difference with previous value */ | ||
105 | diff = val - valpred; | ||
106 | sign = (diff < 0) ? 8 : 0; | ||
107 | if ( sign ) diff = (-diff); | ||
108 | |||
109 | /* Step 2 - Divide and clamp */ | ||
110 | /* Note: | ||
111 | ** This code *approximately* computes: | ||
112 | ** delta = diff*4/step; | ||
113 | ** vpdiff = (delta+0.5)*step/4; | ||
114 | ** but in shift step bits are dropped. The net result of this is | ||
115 | ** that even if you have fast mul/div hardware you cannot put it to | ||
116 | ** good use since the fixup would be too expensive. | ||
117 | */ | ||
118 | delta = 0; | ||
119 | vpdiff = (step >> 3); | ||
120 | |||
121 | if ( diff >= step ) { | ||
122 | delta = 4; | ||
123 | diff -= step; | ||
124 | vpdiff += step; | ||
125 | } | ||
126 | step >>= 1; | ||
127 | if ( diff >= step ) { | ||
128 | delta |= 2; | ||
129 | diff -= step; | ||
130 | vpdiff += step; | ||
131 | } | ||
132 | step >>= 1; | ||
133 | if ( diff >= step ) { | ||
134 | delta |= 1; | ||
135 | vpdiff += step; | ||
136 | } | ||
137 | |||
138 | /* Step 3 - Update previous value */ | ||
139 | if ( sign ) | ||
140 | valpred -= vpdiff; | ||
141 | else | ||
142 | valpred += vpdiff; | ||
143 | |||
144 | /* Step 4 - Clamp previous value to 16 bits */ | ||
145 | if ( valpred > 32767 ) | ||
146 | valpred = 32767; | ||
147 | else if ( valpred < -32768 ) | ||
148 | valpred = -32768; | ||
149 | |||
150 | /* Step 5 - Assemble value, update index and step values */ | ||
151 | delta |= sign; | ||
152 | |||
153 | index += indexTable[delta]; | ||
154 | if ( index < 0 ) index = 0; | ||
155 | if ( index > 88 ) index = 88; | ||
156 | step = stepsizeTable[index]; | ||
157 | |||
158 | /* Step 6 - Output value */ | ||
159 | if ( bufferstep ) { | ||
160 | outputbuffer = (delta << 4) & 0xf0; | ||
161 | } else { | ||
162 | *outp++ = (delta & 0x0f) | outputbuffer; | ||
163 | } | ||
164 | bufferstep = !bufferstep; | ||
165 | } | ||
166 | |||
167 | /* Output last step, if needed */ | ||
168 | if ( !bufferstep ) | ||
169 | *outp++ = outputbuffer; | ||
170 | |||
171 | state->valprev = valpred; | ||
172 | state->index = index; | ||
173 | } | ||
174 | |||
175 | void | ||
176 | adpcm_decoder(indata, outdata, len, state) | ||
177 | char indata[]; | ||
178 | short outdata[]; | ||
179 | int len; | ||
180 | struct adpcm_state *state; | ||
181 | { | ||
182 | signed char *inp; /* Input buffer pointer */ | ||
183 | short *outp; /* output buffer pointer */ | ||
184 | int sign; /* Current adpcm sign bit */ | ||
185 | int delta; /* Current adpcm output value */ | ||
186 | int step; /* Stepsize */ | ||
187 | int valpred; /* Predicted value */ | ||
188 | int vpdiff; /* Current change to valpred */ | ||
189 | int index; /* Current step change index */ | ||
190 | int inputbuffer=0; /* place to keep next 4-bit value */ | ||
191 | int bufferstep=0; /* toggle between inputbuffer/input */ | ||
192 | |||
193 | outp = outdata; | ||
194 | inp = (signed char *)indata; | ||
195 | |||
196 | valpred = state->valprev; | ||
197 | index = state->index; | ||
198 | step = stepsizeTable[index]; | ||
199 | |||
200 | bufferstep = 0; | ||
201 | |||
202 | for ( ; len > 0 ; len-- ) { | ||
203 | |||
204 | /* Step 1 - get the delta value */ | ||
205 | if ( bufferstep ) { | ||
206 | delta = inputbuffer & 0xf; | ||
207 | } else { | ||
208 | inputbuffer = *inp++; | ||
209 | delta = (inputbuffer >> 4) & 0xf; | ||
210 | } | ||
211 | bufferstep = !bufferstep; | ||
212 | |||
213 | /* Step 2 - Find new index value (for later) */ | ||
214 | index += indexTable[delta]; | ||
215 | if ( index < 0 ) index = 0; | ||
216 | if ( index > 88 ) index = 88; | ||
217 | |||
218 | /* Step 3 - Separate sign and magnitude */ | ||
219 | sign = delta & 8; | ||
220 | delta = delta & 7; | ||
221 | |||
222 | /* Step 4 - Compute difference and new predicted value */ | ||
223 | /* | ||
224 | ** Computes 'vpdiff = (delta+0.5)*step/4', but see comment | ||
225 | ** in adpcm_coder. | ||
226 | */ | ||
227 | vpdiff = step >> 3; | ||
228 | if ( delta & 4 ) vpdiff += step; | ||
229 | if ( delta & 2 ) vpdiff += step>>1; | ||
230 | if ( delta & 1 ) vpdiff += step>>2; | ||
231 | |||
232 | if ( sign ) | ||
233 | valpred -= vpdiff; | ||
234 | else | ||
235 | valpred += vpdiff; | ||
236 | |||
237 | /* Step 5 - clamp output value */ | ||
238 | if ( valpred > 32767 ) | ||
239 | valpred = 32767; | ||
240 | else if ( valpred < -32768 ) | ||
241 | valpred = -32768; | ||
242 | |||
243 | /* Step 6 - Update step value */ | ||
244 | step = stepsizeTable[index]; | ||
245 | |||
246 | /* Step 7 - Output value */ | ||
247 | *outp++ = valpred; | ||
248 | } | ||
249 | |||
250 | state->valprev = valpred; | ||
251 | state->index = index; | ||
252 | } | ||
diff --git a/noncore/multimedia/opierec/adpcm.h b/noncore/multimedia/opierec/adpcm.h new file mode 100644 index 0000000..9c17ffa --- a/dev/null +++ b/noncore/multimedia/opierec/adpcm.h | |||
@@ -0,0 +1,19 @@ | |||
1 | /* | ||
2 | ** adpcm.h - include file for adpcm coder. | ||
3 | ** | ||
4 | ** Version 1.0, 7-Jul-92. | ||
5 | */ | ||
6 | |||
7 | struct adpcm_state { | ||
8 | short valprev;/* Previous output value */ | ||
9 | char index; /* Index into stepsize table */ | ||
10 | }; | ||
11 | |||
12 | #ifdef __STDC__ | ||
13 | #define ARGS(x) x | ||
14 | #else | ||
15 | #define ARGS(x) () | ||
16 | #endif | ||
17 | |||
18 | void adpcm_coder ARGS((short [], char [], int, struct adpcm_state *)); | ||
19 | void adpcm_decoder ARGS((char [], short [], int, struct adpcm_state *)); | ||
diff --git a/noncore/multimedia/opierec/device.cpp b/noncore/multimedia/opierec/device.cpp new file mode 100644 index 0000000..c2029b7 --- a/dev/null +++ b/noncore/multimedia/opierec/device.cpp | |||
@@ -0,0 +1,341 @@ | |||
1 | // device.cpp | ||
2 | |||
3 | #include "device.h" | ||
4 | #include "qtrec.h" | ||
5 | |||
6 | #include <qpe/qpeapplication.h> | ||
7 | #include <qpe/config.h> | ||
8 | #include <qpe/qcopenvelope_qws.h> | ||
9 | |||
10 | #include <qslider.h> | ||
11 | #include <qmessagebox.h> | ||
12 | |||
13 | #include <qfile.h> | ||
14 | #include <qtextstream.h> | ||
15 | #include <fcntl.h> | ||
16 | #include <stdio.h> | ||
17 | #include <stdlib.h> | ||
18 | #include <sys/ioctl.h> | ||
19 | #include <sys/soundcard.h> | ||
20 | #include <unistd.h> | ||
21 | #include<sys/wait.h> | ||
22 | // #include <sys/stat.h> | ||
23 | // #include <sys/time.h> | ||
24 | // #include <sys/types.h> | ||
25 | #include <unistd.h> | ||
26 | #include <errno.h> | ||
27 | |||
28 | //extern QtRec *qperec; | ||
29 | |||
30 | Device::Device( QObject * parent, const char * dsp, const char * mixr, bool record ) | ||
31 | : QObject( parent) | ||
32 | { | ||
33 | dspstr = (char *)dsp; | ||
34 | mixstr = (char *)mixr; | ||
35 | |||
36 | devForm=-1; | ||
37 | devCh=-1; | ||
38 | devRate=-1; | ||
39 | |||
40 | if( !record){ //playing | ||
41 | qDebug("setting up DSP for playing"); | ||
42 | flags = O_WRONLY; | ||
43 | } else { //recording | ||
44 | qDebug("setting up DSP for recording"); | ||
45 | flags = O_RDWR; | ||
46 | // flags = O_RDONLY; | ||
47 | selectMicInput(); | ||
48 | } | ||
49 | } | ||
50 | |||
51 | bool Device::openDsp() { | ||
52 | if( openDevice( flags) == -1) { | ||
53 | perror("<<<<<<<<<<<<<<ioctl(\"Open device\")"); | ||
54 | return false; | ||
55 | } | ||
56 | return true; | ||
57 | } | ||
58 | |||
59 | int Device::getOutVolume( ) { | ||
60 | unsigned int volume; | ||
61 | int mixerHandle = open( mixstr, O_RDWR ); | ||
62 | if ( mixerHandle >= 0 ) { | ||
63 | if(ioctl( mixerHandle, MIXER_READ(SOUND_MIXER_VOLUME), &volume )==-1) | ||
64 | perror("<<<<<<<<<<<<<<ioctl(\"MIXER_READ\")"); | ||
65 | ::close( mixerHandle ); | ||
66 | } else | ||
67 | perror("open(\"/dev/mixer\")"); | ||
68 | printf("<<<<<<<<<<<<<<<<<<<<output volume %d\n",volume); | ||
69 | |||
70 | Config cfg("qpe"); | ||
71 | cfg.setGroup("Volume"); | ||
72 | |||
73 | return cfg.readNumEntry("VolumePercent"); | ||
74 | } | ||
75 | |||
76 | int Device::getInVolume() { | ||
77 | unsigned int volume=0; | ||
78 | int mixerHandle = ::open( mixstr, O_RDWR ); | ||
79 | if ( mixerHandle >= 0 ) { | ||
80 | if(ioctl( mixerHandle, MIXER_READ(SOUND_MIXER_MIC), &volume )==-1) | ||
81 | perror("<<<<<<<<<<<<<<<ioctl(\"MIXER_READ\")"); | ||
82 | ::close( mixerHandle ); | ||
83 | } else | ||
84 | perror("open(\"/dev/mixer\")"); | ||
85 | printf("<<<<<<<<<<<<<<input volume %d\n", volume ); | ||
86 | Config cfg("qpe"); | ||
87 | cfg.setGroup("Volume"); | ||
88 | |||
89 | return cfg.readNumEntry("Mic"); | ||
90 | } | ||
91 | |||
92 | void Device::changedOutVolume(int vol) { | ||
93 | int level = (vol << 8) + vol; | ||
94 | int fd = 0; | ||
95 | if ((fd = open("/dev/mixer", O_RDWR))>=0) { | ||
96 | if(ioctl(fd, MIXER_WRITE(SOUND_MIXER_VOLUME), &level) == -1) | ||
97 | perror("ioctl(\"MIXER_IN_WRITE\")"); | ||
98 | |||
99 | Config cfg("qpe"); | ||
100 | cfg.setGroup("Volume"); | ||
101 | cfg.writeEntry("VolumePercent", QString::number( vol )); | ||
102 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << false; | ||
103 | } | ||
104 | ::close(fd); | ||
105 | } | ||
106 | |||
107 | void Device::changedInVolume(int vol ) { | ||
108 | int level = (vol << 8) + vol; | ||
109 | int fd = 0; | ||
110 | if ((fd = open("/dev/mixer", O_RDWR))>=0) { | ||
111 | if(ioctl(fd, MIXER_WRITE(SOUND_MIXER_MIC), &level) == -1) | ||
112 | perror("ioctl(\"MIXER_IN_WRITE\")"); | ||
113 | Config cfg("qpe"); | ||
114 | cfg.setGroup("Volume"); | ||
115 | cfg.writeEntry("Mic", QString::number(vol )); | ||
116 | QCopEnvelope( "QPE/System", "micChange(bool)" ) << false; | ||
117 | } | ||
118 | ::close(fd); | ||
119 | } | ||
120 | |||
121 | bool Device::selectMicInput() { | ||
122 | /* | ||
123 | int md=0; | ||
124 | int info=MIXER_WRITE(SOUND_MIXER_MIC); | ||
125 | md = ::open( "/dev/mixer", O_RDWR ); | ||
126 | if ( md == -1) | ||
127 | perror("open(\"/dev/mixer\")"); | ||
128 | else { | ||
129 | if( ioctl( md, SOUND_MIXER_WRITE_RECSRC, &info) == -1) | ||
130 | perror("ioctl(\"SOUND_MIXER_WRITE_RECSRC\")"); | ||
131 | ::close(md); | ||
132 | return false; | ||
133 | } | ||
134 | ::close(md); | ||
135 | */ | ||
136 | return true; | ||
137 | } | ||
138 | |||
139 | int Device::openDevice( int flags) { | ||
140 | /* pid_t pid; | ||
141 | int status; | ||
142 | int pipefd[2]; | ||
143 | char message[20]; | ||
144 | if (pipe(pipefd) == -1){ | ||
145 | perror ("Error creating pipe"); | ||
146 | exit(1); | ||
147 | } | ||
148 | switch (pid = fork()) { | ||
149 | case -1: | ||
150 | perror("The fork failed!"); | ||
151 | break; | ||
152 | case 0: { | ||
153 | */ | ||
154 | if (( sd = ::open( dspstr, flags)) == -1) { | ||
155 | perror("open(\"/dev/dsp\")"); | ||
156 | QString errorMsg="Could not open audio device\n /dev/dsp\n" | ||
157 | +(QString)strerror(errno); | ||
158 | qDebug(errorMsg); | ||
159 | return -1; | ||
160 | } | ||
161 | |||
162 | int mixerHandle=0; | ||
163 | /* Set the input dsp device and its input gain the weird Zaurus way */ | ||
164 | if (( mixerHandle = open("/dev/mixer1",O_RDWR))<0) { | ||
165 | perror("open(\"/dev/mixer1\")"); | ||
166 | } | ||
167 | |||
168 | if(ioctl(sd,SNDCTL_DSP_RESET,0)<0){ | ||
169 | perror("ioctl RESET"); | ||
170 | } | ||
171 | // sprintf(message, "%d", sd); | ||
172 | |||
173 | /* QFile f1("/pid"); | ||
174 | f1.open(IO_WriteOnly ); | ||
175 | f1.writeBlock(message, strlen(message)); | ||
176 | f1.close(); | ||
177 | */ | ||
178 | /* close(pipefd[0]); | ||
179 | write(pipefd[1], message, sizeof(message)); | ||
180 | close(pipefd[1]); | ||
181 | // qDebug("%d",soundDevice->sd ); | ||
182 | _exit(0); | ||
183 | } | ||
184 | default: | ||
185 | // pid greater than zero is parent getting the child's pid | ||
186 | printf("Child's pid is %d\n",pid); | ||
187 | QString s; | ||
188 | close(pipefd[1]); | ||
189 | read(pipefd[0], message, sizeof(message)); | ||
190 | s = message; | ||
191 | close(pipefd[0]); | ||
192 | |||
193 | // while(wait(NULL)!=pid) | ||
194 | // ; | ||
195 | printf("child %ld terminated normally, return status is zero\n", (long) pid); | ||
196 | */ | ||
197 | // filePara.sd=(long) pid; | ||
198 | /* QFile f2("/pid"); | ||
199 | f2.open(IO_ReadOnly); | ||
200 | QTextStream t(&f2); | ||
201 | // for(int f=0; f < t.atEnd() ;f++) { | ||
202 | s = t.readLine(); | ||
203 | // } | ||
204 | */ | ||
205 | // bool ok; | ||
206 | // sd = s.toInt(&ok, 10); | ||
207 | // qDebug("<<<<<<<<<<<<<>>>>>>>>>>>>"+s); | ||
208 | |||
209 | // f2.close(); | ||
210 | // } | ||
211 | ::close(mixerHandle ); | ||
212 | qDebug("open device %s", dspstr); | ||
213 | qDebug("success! %d",sd); | ||
214 | return sd; | ||
215 | } | ||
216 | |||
217 | bool Device::closeDevice( bool b) { | ||
218 | // if(b) {//close now | ||
219 | // if (ioctl( sd, SNDCTL_DSP_RESET, 0) == -1) { | ||
220 | // perror("ioctl(\"SNDCTL_DSP_RESET\")"); | ||
221 | // } | ||
222 | // } else { //let play | ||
223 | // if (ioctl( sd, SNDCTL_DSP_SYNC, 0) == -1) { | ||
224 | // perror("ioctl(\"SNDCTL_DSP_SYNC\")"); | ||
225 | // } | ||
226 | // } | ||
227 | |||
228 | ::close( sd); //close sound device | ||
229 | // sdfd=0; | ||
230 | // sd=0; | ||
231 | qDebug("closed dsp"); | ||
232 | return true; | ||
233 | } | ||
234 | |||
235 | bool Device::setDeviceFormat( int form) { | ||
236 | qDebug("set device res %d %d", form, sd); | ||
237 | if (ioctl( sd, SNDCTL_DSP_SETFMT, &form)==-1) { //set format | ||
238 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); | ||
239 | return false; | ||
240 | } | ||
241 | devRes=form; | ||
242 | return true; | ||
243 | } | ||
244 | |||
245 | bool Device::setDeviceChannels( int ch) { | ||
246 | qDebug("set channels %d %d", ch, sd); | ||
247 | if (ioctl( sd, SNDCTL_DSP_CHANNELS, &ch)==-1) { | ||
248 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); | ||
249 | return false; | ||
250 | } | ||
251 | devCh=ch; | ||
252 | return true; | ||
253 | } | ||
254 | |||
255 | bool Device::setDeviceRate( int rate) { | ||
256 | qDebug("set rate %d %d", rate, sd); | ||
257 | if (ioctl( sd, SNDCTL_DSP_SPEED, &rate) == -1) { | ||
258 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); | ||
259 | return false; | ||
260 | } | ||
261 | |||
262 | devRate=rate; | ||
263 | |||
264 | return true; | ||
265 | } | ||
266 | |||
267 | int Device::getRes() { | ||
268 | return devRes; | ||
269 | } | ||
270 | |||
271 | int Device::getFormat() { | ||
272 | return devForm; | ||
273 | } | ||
274 | |||
275 | int Device::getRate() { | ||
276 | return devRate; | ||
277 | } | ||
278 | |||
279 | int Device::getChannels() { | ||
280 | return devCh; | ||
281 | } | ||
282 | |||
283 | int Device::getDeviceFormat() { | ||
284 | return 0; | ||
285 | } | ||
286 | |||
287 | |||
288 | int Device::getDeviceRate() { | ||
289 | int dRate=0; | ||
290 | if (ioctl( sd, SOUND_PCM_READ_RATE, &dRate) == -1) { | ||
291 | perror("ioctl(\"SNDCTL_PCM_READ_RATE\")"); | ||
292 | } | ||
293 | return dRate; | ||
294 | |||
295 | } | ||
296 | |||
297 | int Device::getDeviceBits() { | ||
298 | int dBits=0; | ||
299 | #ifndef QT_QWS_EBX // zaurus doesnt have this | ||
300 | if (ioctl( sd, SOUND_PCM_READ_BITS, &dBits) == -1) { | ||
301 | perror("ioctl(\"SNDCTL_PCM_READ_BITS\")"); | ||
302 | } | ||
303 | #endif | ||
304 | return dBits; | ||
305 | } | ||
306 | |||
307 | int Device::getDeviceChannels() { | ||
308 | int dCh=0; | ||
309 | if (ioctl( sd, SOUND_PCM_READ_CHANNELS, &dCh) == -1) { | ||
310 | perror("ioctl(\"SNDCTL_PCM_READ_CHANNELS\")"); | ||
311 | } | ||
312 | return dCh; | ||
313 | } | ||
314 | |||
315 | int Device::getDeviceFragSize() { | ||
316 | int frag_size; | ||
317 | |||
318 | if (ioctl( sd, SNDCTL_DSP_GETBLKSIZE, &frag_size) == -1) { | ||
319 | qDebug("no fragsize"); | ||
320 | } else | ||
321 | qDebug("driver says frag size is %d", frag_size); | ||
322 | return frag_size; | ||
323 | } | ||
324 | |||
325 | bool Device::setFragSize(int frag) { | ||
326 | if (ioctl(sd, SNDCTL_DSP_SETFRAGMENT, &frag)) { | ||
327 | perror("ioctl(\"SNDCTL_DSP_SETFRAGMENT\")"); | ||
328 | return false; | ||
329 | } | ||
330 | return true; | ||
331 | } | ||
332 | |||
333 | bool Device::reset() { | ||
334 | closeDevice(true); | ||
335 | openDsp(); | ||
336 | if (ioctl( sd, SNDCTL_DSP_RESET, 0) == -1) { | ||
337 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); | ||
338 | return false; | ||
339 | } | ||
340 | return true; | ||
341 | } | ||
diff --git a/noncore/multimedia/opierec/device.h b/noncore/multimedia/opierec/device.h new file mode 100644 index 0000000..c9a7491 --- a/dev/null +++ b/noncore/multimedia/opierec/device.h | |||
@@ -0,0 +1,45 @@ | |||
1 | |||
2 | #ifndef DEVICE_H | ||
3 | #define DEVICE_H | ||
4 | #include <qobject.h> | ||
5 | #include <sys/soundcard.h> | ||
6 | |||
7 | class Device : public QObject { | ||
8 | Q_OBJECT | ||
9 | public: | ||
10 | Device( QObject * parent=0, const char * dspStr=0, const char * mixerStr=0, bool record=false ); | ||
11 | ~Device() {}; | ||
12 | bool closeDevice( bool); | ||
13 | int getChannels(); | ||
14 | int getFormat(); | ||
15 | int getInVolume(); | ||
16 | int getOutVolume(); | ||
17 | int getRate(); | ||
18 | int getRes(); | ||
19 | int sd; //sound descriptor | ||
20 | void changedInVolume(int); | ||
21 | void changedOutVolume(int); | ||
22 | bool openDsp(); | ||
23 | int getDeviceFormat(); | ||
24 | int getDeviceRate(); | ||
25 | int getDeviceBits(); | ||
26 | int getDeviceChannels(); | ||
27 | int getDeviceFragSize(); | ||
28 | bool setFragSize(int); | ||
29 | bool setDeviceChannels(int); | ||
30 | bool setDeviceRate(int); | ||
31 | bool setDeviceFormat(int); | ||
32 | bool reset(); | ||
33 | |||
34 | private: | ||
35 | int devRes, devCh, devRate, devForm, flags; | ||
36 | char *dspstr, *mixstr; | ||
37 | bool selectMicInput(); | ||
38 | int openDevice( int ); | ||
39 | private slots: | ||
40 | |||
41 | protected: | ||
42 | |||
43 | }; | ||
44 | |||
45 | #endif | ||
diff --git a/noncore/multimedia/opierec/helpwindow.cpp b/noncore/multimedia/opierec/helpwindow.cpp new file mode 100644 index 0000000..0c4ac78 --- a/dev/null +++ b/noncore/multimedia/opierec/helpwindow.cpp | |||
@@ -0,0 +1,219 @@ | |||
1 | /**************************************************************************** | ||
2 | ** $Id$ | ||
3 | ** | ||
4 | ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. | ||
5 | ** | ||
6 | ** This file is part of an example program for Qt. This example | ||
7 | ** program may be used, distributed and modified without limitation. | ||
8 | ** | ||
9 | *****************************************************************************/ | ||
10 | |||
11 | #include "helpwindow.h" | ||
12 | #include <qstatusbar.h> | ||
13 | #include <qstringlist.h> | ||
14 | #include <qlayout.h> | ||
15 | |||
16 | #include <qpe/qpemenubar.h> | ||
17 | #include <qpe/qpetoolbar.h> | ||
18 | #include <qpe/resource.h> | ||
19 | |||
20 | #include <qaction.h> | ||
21 | #include <qpixmap.h> | ||
22 | #include <qpopupmenu.h> | ||
23 | #include <qmenubar.h> | ||
24 | #include <qtoolbutton.h> | ||
25 | #include <qiconset.h> | ||
26 | #include <qfile.h> | ||
27 | #include <qtextstream.h> | ||
28 | #include <qstylesheet.h> | ||
29 | #include <qmessagebox.h> | ||
30 | #include <qfiledialog.h> | ||
31 | #include <qapplication.h> | ||
32 | #include <qcombobox.h> | ||
33 | #include <qevent.h> | ||
34 | #include <qlineedit.h> | ||
35 | #include <qobjectlist.h> | ||
36 | #include <qfileinfo.h> | ||
37 | #include <qfile.h> | ||
38 | #include <qdatastream.h> | ||
39 | #include <qprinter.h> | ||
40 | #include <qsimplerichtext.h> | ||
41 | #include <qpaintdevicemetrics.h> | ||
42 | |||
43 | #include <ctype.h> | ||
44 | |||
45 | HelpWindow::HelpWindow( const QString& home_, const QString& _path, QWidget* parent, const char *name ) | ||
46 | : QMainWindow( parent, name, WDestructiveClose ), pathCombo( 0 ), selectedURL() | ||
47 | { | ||
48 | QGridLayout *layout = new QGridLayout( this ); | ||
49 | layout->setSpacing( 2); | ||
50 | layout->setMargin( 2); | ||
51 | qDebug(_path); | ||
52 | browser = new QTextBrowser( this ); | ||
53 | QStringList Strlist; | ||
54 | Strlist.append( home_); | ||
55 | browser->mimeSourceFactory()->setFilePath( Strlist ); | ||
56 | browser->setFrameStyle( QFrame::Panel | QFrame::Sunken ); | ||
57 | |||
58 | connect( browser, SIGNAL( textChanged() ), this, SLOT( textChanged() ) ); | ||
59 | |||
60 | if ( !home_.isEmpty() ) | ||
61 | browser->setSource( home_ ); | ||
62 | QPEToolBar *toolbar = new QPEToolBar( this ); | ||
63 | |||
64 | QAction *a = new QAction( tr( "Backward" ), Resource::loadPixmap( "back" ), QString::null, 0, this, 0 ); | ||
65 | connect( a, SIGNAL( activated() ), browser, SLOT( backward() ) ); | ||
66 | a->addTo( toolbar ); | ||
67 | |||
68 | a = new QAction( tr( "Forward" ), Resource::loadPixmap( "forward" ), QString::null, 0, this, 0 ); | ||
69 | connect( a, SIGNAL( activated() ), browser, SLOT( forward() ) ); | ||
70 | a->addTo( toolbar ); | ||
71 | |||
72 | |||
73 | layout->addMultiCellWidget( toolbar, 0, 0, 0, 0); | ||
74 | |||
75 | layout->addMultiCellWidget( browser, 1, 2, 0, 2); | ||
76 | |||
77 | browser->setFocus(); | ||
78 | } | ||
79 | |||
80 | |||
81 | void HelpWindow::setBackwardAvailable( bool b) | ||
82 | { | ||
83 | menuBar()->setItemEnabled( backwardId, b); | ||
84 | } | ||
85 | |||
86 | void HelpWindow::setForwardAvailable( bool b) | ||
87 | { | ||
88 | menuBar()->setItemEnabled( forwardId, b); | ||
89 | } | ||
90 | |||
91 | |||
92 | void HelpWindow::textChanged() | ||
93 | { | ||
94 | if ( browser->documentTitle().isNull() ) { | ||
95 | setCaption( "QpeRec - Helpviewer - " + browser->context() ); | ||
96 | selectedURL = browser->context(); | ||
97 | } | ||
98 | else { | ||
99 | setCaption( "QpeRec - Helpviewer - " + browser->documentTitle() ) ; | ||
100 | selectedURL = browser->documentTitle(); | ||
101 | } | ||
102 | |||
103 | // if ( !selectedURL.isEmpty() && pathCombo ) { | ||
104 | // bool exists = FALSE; | ||
105 | // int i; | ||
106 | // for ( i = 0; i < pathCombo->count(); ++i ) { | ||
107 | // if ( pathCombo->text( i ) == selectedURL ) { | ||
108 | // exists = TRUE; | ||
109 | // break; | ||
110 | // } | ||
111 | // } | ||
112 | // if ( !exists ) { | ||
113 | // pathCombo->insertItem( selectedURL, 0 ); | ||
114 | // pathCombo->setCurrentItem( 0 ); | ||
115 | // mHistory[ hist->insertItem( selectedURL ) ] = selectedURL; | ||
116 | // } else | ||
117 | // pathCombo->setCurrentItem( i ); | ||
118 | // selectedURL = QString::null; | ||
119 | // } | ||
120 | } | ||
121 | |||
122 | HelpWindow::~HelpWindow() | ||
123 | { | ||
124 | history.clear(); | ||
125 | QMap<int, QString>::Iterator it = mHistory.begin(); | ||
126 | for ( ; it != mHistory.end(); ++it ) | ||
127 | history.append( *it ); | ||
128 | |||
129 | QFile f( QDir::currentDirPath() + "/.history" ); | ||
130 | f.open( IO_WriteOnly ); | ||
131 | QDataStream s( &f ); | ||
132 | s << history; | ||
133 | f.close(); | ||
134 | |||
135 | bookmarks.clear(); | ||
136 | QMap<int, QString>::Iterator it2 = mBookmarks.begin(); | ||
137 | for ( ; it2 != mBookmarks.end(); ++it2 ) | ||
138 | bookmarks.append( *it2 ); | ||
139 | |||
140 | QFile f2( QDir::currentDirPath() + "/.bookmarks" ); | ||
141 | f2.open( IO_WriteOnly ); | ||
142 | QDataStream s2( &f2 ); | ||
143 | s2 << bookmarks; | ||
144 | f2.close(); | ||
145 | } | ||
146 | |||
147 | void HelpWindow::openFile() | ||
148 | { | ||
149 | #ifndef QT_NO_FILEDIALOG | ||
150 | #endif | ||
151 | } | ||
152 | |||
153 | void HelpWindow::newWindow() | ||
154 | { | ||
155 | ( new HelpWindow(browser->source(), "qbrowser") )->show(); | ||
156 | } | ||
157 | |||
158 | void HelpWindow::print() | ||
159 | { | ||
160 | #ifndef QT_NO_PRINTER | ||
161 | #endif | ||
162 | } | ||
163 | |||
164 | void HelpWindow::pathSelected( const QString &_path ) | ||
165 | { | ||
166 | browser->setSource( _path ); | ||
167 | QMap<int, QString>::Iterator it = mHistory.begin(); | ||
168 | bool exists = FALSE; | ||
169 | for ( ; it != mHistory.end(); ++it ) { | ||
170 | if ( *it == _path ) { | ||
171 | exists = TRUE; | ||
172 | break; | ||
173 | } | ||
174 | } | ||
175 | if ( !exists ) | ||
176 | mHistory[ hist->insertItem( _path ) ] = _path; | ||
177 | } | ||
178 | |||
179 | void HelpWindow::readHistory() | ||
180 | { | ||
181 | if ( QFile::exists( QDir::currentDirPath() + "/.history" ) ) { | ||
182 | QFile f( QDir::currentDirPath() + "/.history" ); | ||
183 | f.open( IO_ReadOnly ); | ||
184 | QDataStream s( &f ); | ||
185 | s >> history; | ||
186 | f.close(); | ||
187 | while ( history.count() > 20 ) | ||
188 | history.remove( history.begin() ); | ||
189 | } | ||
190 | } | ||
191 | |||
192 | void HelpWindow::readBookmarks() | ||
193 | { | ||
194 | if ( QFile::exists( QDir::currentDirPath() + "/.bookmarks" ) ) { | ||
195 | QFile f( QDir::currentDirPath() + "/.bookmarks" ); | ||
196 | f.open( IO_ReadOnly ); | ||
197 | QDataStream s( &f ); | ||
198 | s >> bookmarks; | ||
199 | f.close(); | ||
200 | } | ||
201 | } | ||
202 | |||
203 | void HelpWindow::histChosen( int i ) | ||
204 | { | ||
205 | if ( mHistory.contains( i ) ) | ||
206 | browser->setSource( mHistory[ i ] ); | ||
207 | } | ||
208 | |||
209 | void HelpWindow::bookmChosen( int i ) | ||
210 | { | ||
211 | if ( mBookmarks.contains( i ) ) | ||
212 | browser->setSource( mBookmarks[ i ] ); | ||
213 | } | ||
214 | |||
215 | void HelpWindow::addBookmark() | ||
216 | { | ||
217 | mBookmarks[ bookm->insertItem( caption() ) ] = caption(); | ||
218 | } | ||
219 | |||
diff --git a/noncore/multimedia/opierec/helpwindow.h b/noncore/multimedia/opierec/helpwindow.h new file mode 100644 index 0000000..76b672a --- a/dev/null +++ b/noncore/multimedia/opierec/helpwindow.h | |||
@@ -0,0 +1,62 @@ | |||
1 | /**************************************************************************** | ||
2 | ** $Id$ | ||
3 | ** | ||
4 | ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. | ||
5 | ** | ||
6 | ** This file is part of an example program for Qt. This example | ||
7 | ** program may be used, distributed and modified without limitation. | ||
8 | ** | ||
9 | *****************************************************************************/ | ||
10 | |||
11 | #ifndef HELPWINDOW_H | ||
12 | #define HELPWINDOW_H | ||
13 | |||
14 | #include <qmainwindow.h> | ||
15 | #include <qtextbrowser.h> | ||
16 | #include <qstringlist.h> | ||
17 | #include <qmap.h> | ||
18 | #include <qdir.h> | ||
19 | #include <qevent.h> | ||
20 | |||
21 | class QComboBox; | ||
22 | class QPopupMenu; | ||
23 | |||
24 | class HelpWindow : public QMainWindow | ||
25 | { | ||
26 | Q_OBJECT | ||
27 | public: | ||
28 | HelpWindow( const QString& home_, const QString& path, QWidget* parent = 0, const char *name=0 ); | ||
29 | ~HelpWindow(); | ||
30 | |||
31 | private slots: | ||
32 | |||
33 | void addBookmark(); | ||
34 | void bookmChosen( int ); | ||
35 | void histChosen( int ); | ||
36 | void newWindow(); | ||
37 | void openFile(); | ||
38 | void pathSelected( const QString & ); | ||
39 | void print(); | ||
40 | void setBackwardAvailable( bool ); | ||
41 | void setForwardAvailable( bool ); | ||
42 | void textChanged(); | ||
43 | private: | ||
44 | QTextBrowser* browser; | ||
45 | QComboBox *pathCombo; | ||
46 | int backwardId, forwardId; | ||
47 | QString selectedURL; | ||
48 | QStringList history, bookmarks; | ||
49 | QMap<int, QString> mHistory, mBookmarks; | ||
50 | QPopupMenu *hist, *bookm; | ||
51 | |||
52 | void readHistory(); | ||
53 | void readBookmarks(); | ||
54 | |||
55 | }; | ||
56 | |||
57 | |||
58 | |||
59 | |||
60 | |||
61 | #endif | ||
62 | |||
diff --git a/noncore/multimedia/opierec/main.cpp b/noncore/multimedia/opierec/main.cpp new file mode 100644 index 0000000..5f7c02f --- a/dev/null +++ b/noncore/multimedia/opierec/main.cpp | |||
@@ -0,0 +1,22 @@ | |||
1 | /*************************************************************************** | ||
2 | main.cpp - main routine | ||
3 | ***************************************************************************/ | ||
4 | //// main.cpp | ||
5 | //// copyright 2001, 2002, by L. J. Potter <ljp@llornkcor.com> | ||
6 | /*************************************************************************** | ||
7 | * This program is free software; you can redistribute it and/or modify * | ||
8 | * it under the terms of the GNU General Public License as published by * | ||
9 | * the Free Software Foundation; either version 2 of the License, or * | ||
10 | * (at your option) any later version. * | ||
11 | ***************************************************************************/ | ||
12 | #include "qtrec.h" | ||
13 | #include <qpe/qpeapplication.h> | ||
14 | |||
15 | int main(int argc, char* argv[]) { | ||
16 | QPEApplication a(argc, argv); | ||
17 | QtRec qtrec; | ||
18 | a.showMainWidget( &qtrec); | ||
19 | return a.exec(); | ||
20 | } | ||
21 | |||
22 | |||
diff --git a/noncore/multimedia/opierec/opierec-control b/noncore/multimedia/opierec/opierec-control new file mode 100644 index 0000000..e8396ae --- a/dev/null +++ b/noncore/multimedia/opierec/opierec-control | |||
@@ -0,0 +1,10 @@ | |||
1 | Package: opierec | ||
2 | Files: bin/opierec pics/opierec apps/Applications/opierec.desktop | ||
3 | Priority: optional | ||
4 | Section: multimedia/applications | ||
5 | Maintainer: L.J. Potter <ljp@llornkcor.com> | ||
6 | Architecture: arm | ||
7 | Version: 1.5-2 | ||
8 | Depends: opie ($QPE_VERSION) | ||
9 | Description: audio sampling recorder | ||
10 | A simple audio recording/playing application. | ||
diff --git a/noncore/multimedia/opierec/opierec.pro b/noncore/multimedia/opierec/opierec.pro new file mode 100644 index 0000000..1788907 --- a/dev/null +++ b/noncore/multimedia/opierec/opierec.pro | |||
@@ -0,0 +1,12 @@ | |||
1 | TEMPLATE = app | ||
2 | CONFIG = qt warn_on debug | ||
3 | #CONFIG = qt warn_on release | ||
4 | HEADERS = adpcm.h pixmaps.h helpwindow.h qtrec.h device.h wavFile.h | ||
5 | SOURCES = adpcm.c helpwindow.cpp main.cpp qtrec.cpp device.cpp wavFile.cpp | ||
6 | INCLUDEPATH += $(QPEDIR)/include | ||
7 | DEPENDPATH += $(QPEDIR)/include | ||
8 | LIBS += -lqpe -lpthread | ||
9 | INTERFACES = | ||
10 | TARGET = opierec | ||
11 | DESTDIR = $(OPIEDIR)/bin | ||
12 | #TMAKE_CXXFLAGS += -DQT_QWS_VERCEL_IDR -DQWS -fno-exceptions -fno-rtti | ||
diff --git a/noncore/multimedia/opierec/pixmaps.h b/noncore/multimedia/opierec/pixmaps.h new file mode 100644 index 0000000..eddddb9 --- a/dev/null +++ b/noncore/multimedia/opierec/pixmaps.h | |||
@@ -0,0 +1,294 @@ | |||
1 | /**************************************************************************** | ||
2 | ** Created: Thu Jan 17 11:19:45 2002 | ||
3 | copyright 2002 by L.J. Potter ljp@llornkcor.com | ||
4 | ****************************************************************************/ | ||
5 | #ifndef PIXMAPS_H | ||
6 | #define PIXMAPS_H | ||
7 | |||
8 | /* XPM */ | ||
9 | static const char * image0_data[] = { | ||
10 | |||
11 | //static char * Qperec16x16_xpm[] = { | ||
12 | "16 16 140 2", | ||
13 | " c None", | ||
14 | ". c #FF1600", | ||
15 | "+ c #FF1200", | ||
16 | "@ c #A2D100", | ||
17 | "# c #C1A400", | ||
18 | "$ c #9CDA00", | ||
19 | "% c #FF7B00", | ||
20 | "& c #FF7F00", | ||
21 | "* c #FD7E00", | ||
22 | "= c #D36600", | ||
23 | "- c #B45600", | ||
24 | "; c #FF7A00", | ||
25 | "> c #F97C00", | ||
26 | ", c #F77B00", | ||
27 | "' c #CC6200", | ||
28 | ") c #B85A00", | ||
29 | "! c #A46000", | ||
30 | "~ c #A36000", | ||
31 | "{ c #F59000", | ||
32 | "] c #E48500", | ||
33 | "^ c #AD6500", | ||
34 | "/ c #FFBA00", | ||
35 | "( c #DEA300", | ||
36 | "_ c #A97900", | ||
37 | ": c #A67600", | ||
38 | "< c #FBB700", | ||
39 | "[ c #E3A600", | ||
40 | "} c #AD7E00", | ||
41 | "| c #B48000", | ||
42 | "1 c #BE8900", | ||
43 | "2 c #907700", | ||
44 | "3 c #7F6800", | ||
45 | "4 c #7A6400", | ||
46 | "5 c #F3C700", | ||
47 | "6 c #000000", | ||
48 | "7 c #937800", | ||
49 | "8 c #5F4E00", | ||
50 | "9 c #A48600", | ||
51 | "0 c #FEF600", | ||
52 | "a c #FEF200", | ||
53 | "b c #F4E800", | ||
54 | "c c #F0E800", | ||
55 | "d c #E1DB00", | ||
56 | "e c #8F8900", | ||
57 | "f c #B0A700", | ||
58 | "g c #FCF400", | ||
59 | "h c #948B00", | ||
60 | "i c #948D00", | ||
61 | "j c #D3CD00", | ||
62 | "k c #B5B000", | ||
63 | "l c #BBB100", | ||
64 | "m c #AAA300", | ||
65 | "n c #7A8400", | ||
66 | "o c #778100", | ||
67 | "p c #656C00", | ||
68 | "q c #7B8500", | ||
69 | "r c #A5B300", | ||
70 | "s c #6E7800", | ||
71 | "t c #737D00", | ||
72 | "u c #3A3F00", | ||
73 | "v c #717B00", | ||
74 | "w c #586000", | ||
75 | "x c #919D00", | ||
76 | "y c #606900", | ||
77 | "z c #B3F700", | ||
78 | "A c #9DD900", | ||
79 | "B c #87BA00", | ||
80 | "C c #9CD800", | ||
81 | "D c #83B400", | ||
82 | "E c #A1DF00", | ||
83 | "F c #B2F700", | ||
84 | "G c #7EAE00", | ||
85 | "H c #92CA00", | ||
86 | "I c #9DD800", | ||
87 | "J c #94CC00", | ||
88 | "K c #63A600", | ||
89 | "L c #467500", | ||
90 | "M c #385E00", | ||
91 | "N c #457400", | ||
92 | "O c #365B00", | ||
93 | "P c #467400", | ||
94 | "Q c #599500", | ||
95 | "R c #457300", | ||
96 | "S c #447300", | ||
97 | "T c #315300", | ||
98 | "U c #487800", | ||
99 | "V c #335600", | ||
100 | "W c #3C6400", | ||
101 | "X c #35C678", | ||
102 | "Y c #31B86F", | ||
103 | "Z c #2DAB64", | ||
104 | "` c #2EAA67", | ||
105 | " . c #238551", | ||
106 | ".. c #2DAA66", | ||
107 | "+. c #238450", | ||
108 | "@. c #2DA865", | ||
109 | "#. c #30B46C", | ||
110 | "$. c #29985C", | ||
111 | "%. c #2A9E60", | ||
112 | "&. c #23824F", | ||
113 | "*. c #2CA461", | ||
114 | "=. c #22804D", | ||
115 | "-. c #2BA160", | ||
116 | ";. c #2A9C5E", | ||
117 | ">. c #0036EE", | ||
118 | ",. c #002EC7", | ||
119 | "'. c #0024A4", | ||
120 | "). c #002DC4", | ||
121 | "!. c #002295", | ||
122 | "~. c #002DC1", | ||
123 | "{. c #002093", | ||
124 | "]. c #002BC0", | ||
125 | "^. c #0030D4", | ||
126 | "/. c #002293", | ||
127 | "(. c #0029B5", | ||
128 | "_. c #00218E", | ||
129 | ":. c #00208C", | ||
130 | "<. c #0028B4", | ||
131 | "[. c #0028B0", | ||
132 | "}. c #4F00E8", | ||
133 | "|. c #4200C3", | ||
134 | "1. c #320093", | ||
135 | "2. c #320091", | ||
136 | "3. c #4100C3", | ||
137 | "4. c #4200C4", | ||
138 | "5. c #4600CC", | ||
139 | "6. c #330095", | ||
140 | "7. c #3C00AF", | ||
141 | "8. c #3C00B0", | ||
142 | "9. c #330096", | ||
143 | "0. c #3D00B4", | ||
144 | "a. c #5300AA", | ||
145 | "b. c #3E0080", | ||
146 | "c. c #4F00A1", | ||
147 | "d. c #4E00A0", | ||
148 | "e. c #4E00A1", | ||
149 | "f. c #5100A5", | ||
150 | "g. c #490097", | ||
151 | "h. c #4A0098", | ||
152 | "i. c #4A009A", | ||
153 | " . . + ", | ||
154 | " ", | ||
155 | "@ @ # # $ # # ", | ||
156 | " ", | ||
157 | "% % & * = - ; > , ' ) ", | ||
158 | " ! ~ { ] ^ ", | ||
159 | "/ / / ( _ : < / [ } | 1 ", | ||
160 | " 2 3 4 5 6 7 8 9 ", | ||
161 | "0 0 a b c d e f g 0 h i j k l m ", | ||
162 | " n o p q r s t u v w x y ", | ||
163 | "z z z A B C D A E F B G H G I J ", | ||
164 | " K L M N O P Q R S T U V L W ", | ||
165 | "X Y Z ` ...+.@.#.$.%.&.*.=.-.;.", | ||
166 | ">.,.'.).!.~.{.].^./.(._.(.:.<.[.", | ||
167 | "}.|.1.|.2.3.2.4.5.6.7.6.8.9.8.0.", | ||
168 | " a.b.c.b.d.b.e.f. g. h. i. "}; | ||
169 | |||
170 | |||
171 | // stop button default | ||
172 | static const char* const image3_data[] = { | ||
173 | "22 22 4 1", | ||
174 | ". c None", | ||
175 | "# c #000000", | ||
176 | "c c #7b797b", | ||
177 | "b c #ff0000", | ||
178 | "a c #ff9194", | ||
179 | "......................", | ||
180 | "......................", | ||
181 | "......................", | ||
182 | "......................", | ||
183 | "......................", | ||
184 | "........#######.......", | ||
185 | ".......#aaaabbb#......", | ||
186 | "......#aabbbbbbb#.....", | ||
187 | ".....#aabbbbbbbbb#....", | ||
188 | ".....#abbbbbbbbbb#c...", | ||
189 | ".....#abbbbbbbbbb#c...", | ||
190 | ".....#abbbbbbbbbb#c...", | ||
191 | ".....#abbbbbbbbbb#c...", | ||
192 | ".....#bbbbbbbbbbb#c...", | ||
193 | ".....#bbbbbbbbbbb#c...", | ||
194 | "......#bbbbbbbbb#cc...", | ||
195 | ".......#bbbbbbb#cc....", | ||
196 | "........#######cc.....", | ||
197 | ".........ccccccc......", | ||
198 | "......................", | ||
199 | "......................", | ||
200 | "......................"}; | ||
201 | |||
202 | // play button | ||
203 | static const char* const image4_data[] = { | ||
204 | "22 22 5 1", | ||
205 | ". c None", | ||
206 | "# c #000000", | ||
207 | "c c #838183", | ||
208 | "b c #00ff00", | ||
209 | "a c #ffffff", | ||
210 | "......................", | ||
211 | "......................", | ||
212 | "......................", | ||
213 | "......................", | ||
214 | "......................", | ||
215 | "............#.........", | ||
216 | "............##........", | ||
217 | "............#a#.......", | ||
218 | ".....########aa#......", | ||
219 | ".....#aaaaaaabaa#.....", | ||
220 | ".....#bbbbbbbbbaa#....", | ||
221 | ".....#bbbbbbbbba#.....", | ||
222 | ".....########ba#c.....", | ||
223 | ".....ccccccc#a#c......", | ||
224 | "...........c##c.......", | ||
225 | "...........c#c........", | ||
226 | "...........cc.........", | ||
227 | "...........c..........", | ||
228 | "......................", | ||
229 | "......................", | ||
230 | "......................", | ||
231 | "......................"}; | ||
232 | |||
233 | static const char* const image5_data[] = { | ||
234 | "22 22 5 1", | ||
235 | ". c None", | ||
236 | "# c #000000", | ||
237 | "c c #838183", | ||
238 | "b c #c5c2c5", | ||
239 | "a c #ffffff", | ||
240 | "......................", | ||
241 | "......................", | ||
242 | "......................", | ||
243 | "......................", | ||
244 | "......................", | ||
245 | "............#.....#...", | ||
246 | "............##....#...", | ||
247 | "............#a#...#...", | ||
248 | ".....########aa#..#...", | ||
249 | ".....#aaaaaaabaa#.#...", | ||
250 | ".....#bbbbbbbbbaa##...", | ||
251 | ".....#bbbbbbbbba#.#...", | ||
252 | ".....########ba#c.#...", | ||
253 | ".....ccccccc#a#c..#...", | ||
254 | "...........c##c...#...", | ||
255 | "...........c#c....#...", | ||
256 | "...........cc.........", | ||
257 | "...........c..........", | ||
258 | "......................", | ||
259 | "......................", | ||
260 | "......................", | ||
261 | "......................"}; | ||
262 | |||
263 | // record button default | ||
264 | static const char* const image6_data[] = { | ||
265 | "22 22 5 1", | ||
266 | ". c None", | ||
267 | "# c #000000", | ||
268 | "c c #ff0000", | ||
269 | "b c #7b797b", | ||
270 | "a c #ff9194", | ||
271 | "......................", | ||
272 | "......................", | ||
273 | "......................", | ||
274 | "......................", | ||
275 | "......................", | ||
276 | "......#########.......", | ||
277 | ".....#.aaaaaaaa#......", | ||
278 | ".....#acccccccb#b.....", | ||
279 | ".....#acccccccb#b.....", | ||
280 | ".....#acccccccb#b.....", | ||
281 | ".....#acccccccb#b.....", | ||
282 | ".....#acccccccb#b.....", | ||
283 | ".....#acccccccb#b.....", | ||
284 | ".....#acccccccb#b.....", | ||
285 | ".....#abbbbbbbb#b.....", | ||
286 | "......#########.b.....", | ||
287 | "......bbbbbbbbbb......", | ||
288 | "......................", | ||
289 | "......................", | ||
290 | "......................", | ||
291 | "......................", | ||
292 | "......................"}; | ||
293 | |||
294 | #endif | ||
diff --git a/noncore/multimedia/opierec/qtrec.cpp b/noncore/multimedia/opierec/qtrec.cpp new file mode 100644 index 0000000..4223d93 --- a/dev/null +++ b/noncore/multimedia/opierec/qtrec.cpp | |||
@@ -0,0 +1,2270 @@ | |||
1 | /**************************************************************************** | ||
2 | // qtrec.cpp | ||
3 | Created: Thu Jan 17 11:19:58 2002 | ||
4 | copyright 2002 by L.J. Potter <ljp@llornkcor.com> | ||
5 | ****************************************************************************/ | ||
6 | |||
7 | #define DEV_VERSION | ||
8 | |||
9 | #include "pixmaps.h" | ||
10 | #include "qtrec.h" | ||
11 | #include "helpwindow.h" | ||
12 | #include "device.h" | ||
13 | #include "wavFile.h" | ||
14 | |||
15 | #include <pthread.h> | ||
16 | |||
17 | extern "C" { | ||
18 | #include "adpcm.h" | ||
19 | } | ||
20 | |||
21 | #include <sys/soundcard.h> | ||
22 | |||
23 | // #if defined (QTOPIA_INTERNAL_FSLP) | ||
24 | // #include <qpe/lnkproperties.h> | ||
25 | // #endif | ||
26 | |||
27 | #include <qpe/applnk.h> | ||
28 | #include <qpe/config.h> | ||
29 | #include <qpe/ir.h> | ||
30 | #include <qpe/qcopenvelope_qws.h> | ||
31 | #include <qpe/qpeapplication.h> | ||
32 | #include <qpe/resource.h> | ||
33 | #include <qpe/storage.h> | ||
34 | |||
35 | #include <qlineedit.h> | ||
36 | #include <qbuttongroup.h> | ||
37 | #include <qcheckbox.h> | ||
38 | #include <qcombobox.h> | ||
39 | #include <qcursor.h> | ||
40 | //#include <qdatetime.h> | ||
41 | #include <qdir.h> | ||
42 | #include <qfile.h> | ||
43 | #include <qtextstream.h> | ||
44 | #include <qgroupbox.h> | ||
45 | #include <qiconview.h> | ||
46 | #include <qimage.h> | ||
47 | #include <qlabel.h> | ||
48 | #include <qlayout.h> | ||
49 | #include <qlineedit.h> | ||
50 | #include <qlistview.h> | ||
51 | #include <qmessagebox.h> | ||
52 | #include <qpixmap.h> | ||
53 | #include <qpopupmenu.h> | ||
54 | #include <qpushbutton.h> | ||
55 | #include <qregexp.h> | ||
56 | #include <qslider.h> | ||
57 | #include <qtabwidget.h> | ||
58 | #include <qtimer.h> | ||
59 | #include <qvariant.h> | ||
60 | |||
61 | #include <errno.h> | ||
62 | #include <fcntl.h> | ||
63 | #include <math.h> | ||
64 | #include <mntent.h> | ||
65 | #include <stdio.h> | ||
66 | #include <stdlib.h> | ||
67 | #include <sys/ioctl.h> | ||
68 | #include <sys/soundcard.h> | ||
69 | #include <sys/stat.h> | ||
70 | #include <sys/time.h> | ||
71 | #include <sys/types.h> | ||
72 | #include <sys/vfs.h> | ||
73 | #include <unistd.h> | ||
74 | #include<sys/wait.h> | ||
75 | #include <sys/signal.h> | ||
76 | |||
77 | //#define ZAURUS 0 | ||
78 | struct adpcm_state encoder_state; | ||
79 | struct adpcm_state decoder_state; | ||
80 | |||
81 | long findPeak(long input ); | ||
82 | //char deviceRates[]; | ||
83 | |||
84 | typedef struct { | ||
85 | int sampleRate; | ||
86 | /* int fragSize; */ | ||
87 | /* int blockSize; */ | ||
88 | int resolution; //bitrate | ||
89 | int channels; //number of channels | ||
90 | int fd; //file descriptor | ||
91 | int sd; //sound device descriptor | ||
92 | int numberSamples; //total number of samples | ||
93 | int SecondsToRecord; // number of seconds that should be recorded | ||
94 | float numberOfRecordedSeconds; //total number of samples recorded | ||
95 | int samplesToRecord; //number of samples to be recorded | ||
96 | int inVol; //input volume | ||
97 | int outVol; //output volume | ||
98 | int format; //wavfile format PCM.. ADPCM | ||
99 | const char *fileName; //name of fiel to be played/recorded | ||
100 | } fileParameters; | ||
101 | |||
102 | fileParameters filePara; | ||
103 | |||
104 | bool monitoring, recording; | ||
105 | bool stopped; | ||
106 | QLabel *timeLabel; | ||
107 | QSlider *timeSlider; | ||
108 | int sd; | ||
109 | |||
110 | #if defined(QT_QWS_EBX) | ||
111 | #define DSPSTROUT "/dev/dsp" | ||
112 | #define DSPSTRIN "/dev/dsp1" | ||
113 | #define DSPSTRMIXEROUT "/dev/mixer" | ||
114 | #define DSPSTRMIXERIN "/dev/mixer1" | ||
115 | #else | ||
116 | #define DSPSTROUT "/dev/dsp" | ||
117 | #define DSPSTRIN "/dev/dsp" | ||
118 | #define DSPSTRMIXERIN "/dev/mixer" | ||
119 | #define DSPSTRMIXEROUT "/dev/mixer" | ||
120 | #endif | ||
121 | |||
122 | // threaded recording | ||
123 | void quickRec() { | ||
124 | //void QtRec::quickRec() { | ||
125 | |||
126 | qDebug("%d", | ||
127 | filePara.numberSamples/filePara.sampleRate * filePara.channels); | ||
128 | qDebug("samples %d, rate %d, channels %d", | ||
129 | filePara.numberSamples, filePara.sampleRate, filePara.channels); | ||
130 | |||
131 | int total = 0; // Total number of bytes read in so far. | ||
132 | int bytesWritten, number; | ||
133 | |||
134 | count_info info; | ||
135 | |||
136 | bytesWritten=0; | ||
137 | number=0; | ||
138 | QString num, timeString; | ||
139 | int level=0; | ||
140 | int threshold=0; | ||
141 | // if(limit != 0) | ||
142 | // t->start( ( limit +.3) , true); | ||
143 | |||
144 | recording = true; | ||
145 | //rate=filePara.sampleRate; | ||
146 | int bits = filePara.resolution; | ||
147 | qDebug("bits %d", bits); | ||
148 | // if( filePara.format==WAVE_FORMAT_DVI_ADPCM) | ||
149 | // else | ||
150 | audio_buf_info inInfo; | ||
151 | ioctl( filePara.fd, SNDCTL_DSP_GETISPACE, &inInfo); | ||
152 | qDebug("ispace is frags %d, total %d", inInfo.fragments, inInfo.fragstotal); | ||
153 | |||
154 | if( filePara.resolution == 16 ) { //AFMT_S16_LE) | ||
155 | qDebug("AFMT_S16_LE size %d", filePara.SecondsToRecord); | ||
156 | qDebug("samples to record %d", filePara.samplesToRecord); | ||
157 | qDebug("%d", filePara.sd); | ||
158 | level=7; | ||
159 | threshold=0; | ||
160 | timeString.sprintf("%.2f", filePara.numberOfRecordedSeconds); | ||
161 | timeLabel->setText( timeString+ " seconds"); | ||
162 | |||
163 | if( filePara.format==WAVE_FORMAT_DVI_ADPCM) { | ||
164 | qDebug("start recording WAVE_FORMAT_DVI_ADPCM"); | ||
165 | // <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_DVI_ADPCM >>>>>>>>>>>>>>>>>>>>>> | ||
166 | char abuf[BUFSIZE/2]; | ||
167 | short sbuf[BUFSIZE]; | ||
168 | short sbuf2[BUFSIZE]; | ||
169 | memset( abuf,0,BUFSIZE/2); | ||
170 | memset( sbuf,0,BUFSIZE); | ||
171 | memset( sbuf2,0,BUFSIZE); | ||
172 | |||
173 | for(;;) { | ||
174 | if (stopped) { | ||
175 | qDebug("quickRec:: stopped"); | ||
176 | break; // stop if playing was set to false | ||
177 | // return; | ||
178 | } | ||
179 | |||
180 | number=::read( filePara.sd, sbuf, BUFSIZE); | ||
181 | |||
182 | if(number <= 0) { | ||
183 | perror("recording error "); | ||
184 | qDebug( "%s %d", filePara.fileName, number); | ||
185 | // errorStop(); | ||
186 | recording=stopped=false; | ||
187 | // QMessageBox::message("Note", | ||
188 | // "Error recording to file\n%s", | ||
189 | // filePara.fileName); | ||
190 | return; | ||
191 | } | ||
192 | //if(stereo == 2) { | ||
193 | // adpcm_coder( sbuf2, abuf, number/2, &encoder_state); | ||
194 | adpcm_coder( sbuf, abuf, number/2, &encoder_state); | ||
195 | |||
196 | bytesWritten = ::write( filePara.fd , abuf, number/4); | ||
197 | |||
198 | long peak; | ||
199 | for (int i = 0; i < number; i++) | ||
200 | { //since Z is mono do normally | ||
201 | peak = findPeak((long)sbuf[i]); | ||
202 | printf("peak %ld\r",peak); | ||
203 | fflush(stdout); | ||
204 | } | ||
205 | |||
206 | |||
207 | //------------->>>> out to file | ||
208 | // if(filePara.channels==1) | ||
209 | // total += bytesWritten/2; //mono | ||
210 | // else | ||
211 | total += bytesWritten; | ||
212 | filePara.numberSamples = total; | ||
213 | // if( total >= filePara.samplesToRecord) | ||
214 | // timeSlider->setValue(0); | ||
215 | // else if( filePara.SecondsToRecord !=0) | ||
216 | timeSlider->setValue( total); | ||
217 | |||
218 | filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate * (float)2; | ||
219 | |||
220 | // printf("Writing number %d, bytes %d,total %d, sample rate %d, secs %.2f \n", | ||
221 | // number, | ||
222 | // bytesWritten , | ||
223 | // total, | ||
224 | // filePara.sampleRate, | ||
225 | // filePara.numberOfRecordedSeconds); | ||
226 | // fflush(stdout); | ||
227 | ioctl( filePara.sd, SNDCTL_DSP_GETIPTR, &info); | ||
228 | // qDebug("%d, %d", info.bytes, (info.bytes / filePara.sampleRate) / 2); | ||
229 | |||
230 | timeString.sprintf("%.2f", filePara.numberOfRecordedSeconds); | ||
231 | timeLabel->setText( timeString + " seconds"); | ||
232 | |||
233 | qApp->processEvents(); | ||
234 | if( total >= filePara.samplesToRecord) | ||
235 | break; | ||
236 | } | ||
237 | } else { | ||
238 | // <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_PCM >>>>>>>>>>>>>>>>>>>>>> | ||
239 | qDebug("start recording WAVE_FORMAT_PCM"); | ||
240 | short inbuffer[BUFSIZE], outbuffer[BUFSIZE]; | ||
241 | memset( inbuffer,0,BUFSIZE); | ||
242 | memset( outbuffer,0,BUFSIZE); | ||
243 | for(;;) { | ||
244 | if (stopped) { | ||
245 | qDebug("quickRec:: stopped"); | ||
246 | break; // stop if playing was set to false | ||
247 | return; | ||
248 | } | ||
249 | |||
250 | number=::read( filePara.sd, inbuffer, BUFSIZE); | ||
251 | |||
252 | if(number <= 0) { | ||
253 | perror("recording error "); | ||
254 | qDebug( filePara.fileName); | ||
255 | recording=stopped=false; | ||
256 | // errorStop(); | ||
257 | // QMessageBox::message("Note","error recording to file\n%s",filePara.fileName); | ||
258 | return;// false; | ||
259 | } | ||
260 | /* for (int i=0;i< number;i++) { //2*i is left channel | ||
261 | |||
262 | outbuffer[i]=inbuffer[i]>>1; // no clippy, please | ||
263 | }*/ | ||
264 | bytesWritten = ::write( filePara.fd , inbuffer, number); | ||
265 | //------------->>>> out to file | ||
266 | if(bytesWritten < 0) { | ||
267 | // errorStop(); | ||
268 | perror("File writing error "); | ||
269 | return;// false; | ||
270 | } | ||
271 | |||
272 | // if(filePara.channels==1) | ||
273 | // total += bytesWritten/2; //mono | ||
274 | // else | ||
275 | total += bytesWritten; | ||
276 | long peak; | ||
277 | for (int i = 0; i < number; i++) | ||
278 | { //since Z is mono do normally | ||
279 | peak = findPeak((long)inbuffer[i]); | ||
280 | printf("peak %ld\r",peak); | ||
281 | fflush(stdout); | ||
282 | } | ||
283 | |||
284 | |||
285 | filePara.numberSamples = total; | ||
286 | if(filePara.SecondsToRecord !=0) | ||
287 | timeSlider->setValue( total); | ||
288 | // printf("Writing number %d, bytes %d,total %d\r",number, bytesWritten , total); | ||
289 | // fflush(stdout); | ||
290 | |||
291 | ioctl( filePara.sd, SNDCTL_DSP_GETIPTR, &info); | ||
292 | // qDebug("%d, %d", info.bytes, ( info.bytes / filePara.sampleRate) / 2); | ||
293 | |||
294 | filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate / (float)2; | ||
295 | |||
296 | timeString.sprintf("%.2f", filePara.numberOfRecordedSeconds); | ||
297 | timeLabel->setText( timeString + " seconds"); | ||
298 | |||
299 | qApp->processEvents(); | ||
300 | if( total >= filePara.samplesToRecord) | ||
301 | break; | ||
302 | } | ||
303 | } //end main loop | ||
304 | |||
305 | } else { // <<<<<<<<<<<<<<<<<<<<<<< format = AFMT_U8; | ||
306 | unsigned char unsigned_inbuffer[BUFSIZE], unsigned_outbuffer[BUFSIZE]; | ||
307 | memset( unsigned_inbuffer, 0, BUFSIZE); | ||
308 | memset( unsigned_outbuffer, 0, BUFSIZE); | ||
309 | |||
310 | for(;;) { | ||
311 | if (stopped) { | ||
312 | qDebug("quickRec:: stopped"); | ||
313 | break; // stop if playing was set to false | ||
314 | } | ||
315 | number=::read( filePara.sd, unsigned_inbuffer, BUFSIZE); | ||
316 | //-------------<<<< in from device | ||
317 | // val = (data ^ 0x80) << 8; | ||
318 | |||
319 | //unsigned_outbuffer = (unsigned_inbuffer ^ 0x80) << 8; | ||
320 | |||
321 | // if(number <= 0) { | ||
322 | // perror("recording error "); | ||
323 | // qDebug(filePara.fileName); | ||
324 | // // errorStop(); | ||
325 | // QMessageBox::message("Note","error recording"); | ||
326 | // return;// false; | ||
327 | // } | ||
328 | // for (int i=0;i< number;i++) { //2*i is left channel | ||
329 | // unsigned_outbuffer[i]=unsigned_inbuffer[i]>>1; // no clippy, please | ||
330 | // } | ||
331 | |||
332 | bytesWritten = ::write( filePara.fd , unsigned_inbuffer, number); | ||
333 | |||
334 | //------------->>>> out to file | ||
335 | if(bytesWritten < 0) { | ||
336 | recording=stopped=false; | ||
337 | // errorStop(); | ||
338 | QMessageBox::message("Note","There was a problem\nwriting to the file"); | ||
339 | perror("File writing error "); | ||
340 | return;// false; | ||
341 | } | ||
342 | total += bytesWritten; | ||
343 | filePara.numberSamples = total; | ||
344 | // printf("\nWriting number %d, bytes %d,total %d \r",number, bytesWritten , total); | ||
345 | // fflush(stdout); | ||
346 | if(filePara.SecondsToRecord !=0) | ||
347 | timeSlider->setValue( total); | ||
348 | |||
349 | filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate; | ||
350 | |||
351 | timeString.sprintf("%.2f",filePara.numberOfRecordedSeconds); | ||
352 | timeLabel->setText( timeString + " seconds"); | ||
353 | |||
354 | qApp->processEvents(); | ||
355 | if( total >= filePara.samplesToRecord) | ||
356 | break; | ||
357 | } //end main loop | ||
358 | } | ||
359 | // qDebug("Final %d, %d", filePara.samplesToRecord , filePara.numberOfRecordedSeconds); | ||
360 | } /// END quickRec() | ||
361 | |||
362 | // threaded play | ||
363 | void playIt() { | ||
364 | |||
365 | } | ||
366 | |||
367 | |||
368 | |||
369 | /////////////////<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>> | ||
370 | /////////////////<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>> | ||
371 | |||
372 | QtRec::QtRec( QWidget* parent, const char* name, WFlags fl ) | ||
373 | : QWidget( parent, name, fl ) { | ||
374 | // QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << true; // mute device | ||
375 | // autoMute=TRUE; | ||
376 | // QPEApplication::grabKeyboard(); | ||
377 | |||
378 | // signal(SIGPIPE, SIG_IGN); | ||
379 | |||
380 | if ( !name ) | ||
381 | setName( "QpeRec" ); | ||
382 | init(); | ||
383 | initConfig(); | ||
384 | initConnections(); | ||
385 | renameBox = 0; | ||
386 | |||
387 | // open sound device to get volumes | ||
388 | soundDevice = new Device( this, DSPSTROUT, DSPSTRMIXEROUT, false); | ||
389 | |||
390 | // soundDevice->setDeviceFormat(AFMT_S16_LE); | ||
391 | // soundDevice->setDeviceChannels(1); | ||
392 | // soundDevice->setDeviceRate( 22050); | ||
393 | |||
394 | getInVol(); | ||
395 | getOutVol(); | ||
396 | |||
397 | soundDevice->closeDevice( true); | ||
398 | soundDevice->sd=-1; | ||
399 | soundDevice=0; | ||
400 | wavFile=0; | ||
401 | |||
402 | if(soundDevice) delete soundDevice; | ||
403 | |||
404 | initIconView(); | ||
405 | |||
406 | if(autoMute) | ||
407 | doMute(true); | ||
408 | ListView1->setFocus(); | ||
409 | playing=false; | ||
410 | } | ||
411 | |||
412 | QtRec::~QtRec() { | ||
413 | |||
414 | } | ||
415 | |||
416 | void QtRec::cleanUp() { | ||
417 | |||
418 | if(!stopped) { | ||
419 | stopped=true; | ||
420 | endRecording(); | ||
421 | } | ||
422 | |||
423 | ListView1->clear(); | ||
424 | |||
425 | if(autoMute) | ||
426 | doMute(false); | ||
427 | |||
428 | if(wavFile) delete wavFile; | ||
429 | // if(soundDevice) delete soundDevice; | ||
430 | |||
431 | // QPEApplication::grabKeyboard(); | ||
432 | // QPEApplication::ungrabKeyboard(); | ||
433 | } | ||
434 | |||
435 | void QtRec::init() { | ||
436 | |||
437 | needsStereoOut=false; | ||
438 | QPixmap image3( ( const char** ) image3_data ); | ||
439 | QPixmap image4( ( const char** ) image4_data ); | ||
440 | QPixmap image6( ( const char** ) image6_data ); | ||
441 | |||
442 | stopped=true; | ||
443 | setCaption( tr( "QpeRecord " ) + QString::number(VERSION) ); | ||
444 | QGridLayout *layout = new QGridLayout( this ); | ||
445 | layout->setSpacing( 2); | ||
446 | layout->setMargin( 2); | ||
447 | |||
448 | TabWidget = new QTabWidget( this, "TabWidget" ); | ||
449 | layout->addMultiCellWidget(TabWidget, 0, 7, 0, 7); | ||
450 | // TabWidget->setTabShape(QTabWidget::Triangular); | ||
451 | |||
452 | ///**********<<<<<<<<<<<<>>>>>>>>>>>>*************** | ||
453 | tab = new QWidget( TabWidget, "tab" ); | ||
454 | |||
455 | QGridLayout *layout1 = new QGridLayout( tab); | ||
456 | layout1->setSpacing( 2); | ||
457 | layout1->setMargin( 2); | ||
458 | |||
459 | timeSlider = new QSlider( 0,100,10,0, QSlider::Horizontal, tab, (const char *) "timeSlider" ); | ||
460 | // timeSlider->setFixedWidth(150); | ||
461 | layout1->addMultiCellWidget( timeSlider, 1, 1, 0, 3); | ||
462 | // timeSlider->setTickmarks(QSlider::Above); | ||
463 | |||
464 | timeLabel = new QLabel( tab, "TimeLabel" ); | ||
465 | layout1->addMultiCellWidget( timeLabel, 0, 0, 0, 3); | ||
466 | |||
467 | playLabel2 = new QLabel(tab, "PlayLabel2" ); | ||
468 | playLabel2->setText("Play"); | ||
469 | playLabel2->setFixedHeight(18); | ||
470 | layout1->addMultiCellWidget( playLabel2, 0, 0, 4, 4); | ||
471 | |||
472 | Stop_PushButton = new QPushButton( tab, "Stop_PushButton" ); | ||
473 | layout1->addMultiCellWidget( Stop_PushButton, 1, 1, 4, 4); | ||
474 | Stop_PushButton->setFixedSize(22,22); | ||
475 | Stop_PushButton->setPixmap( image4 ); | ||
476 | |||
477 | toBeginningButton = new QPushButton( tab, "Beginning_PushButton" ); | ||
478 | layout1->addMultiCellWidget(toBeginningButton, 1, 1, 5, 5); | ||
479 | toBeginningButton->setFixedSize(22,22); | ||
480 | toBeginningButton->setPixmap( Resource::loadPixmap("fastback") ); | ||
481 | |||
482 | toEndButton = new QPushButton( tab, "End_PushButton" ); | ||
483 | layout1->addMultiCellWidget( toEndButton, 1, 1, 6, 6); | ||
484 | toEndButton->setFixedSize(22,22); | ||
485 | toEndButton->setPixmap( Resource::loadPixmap( "fastforward" ) ); | ||
486 | |||
487 | QLabel *recLabel2; | ||
488 | recLabel2 = new QLabel( tab, "recLabel2" ); | ||
489 | recLabel2->setText("Rec"); | ||
490 | recLabel2->setFixedHeight(18); | ||
491 | layout1->addMultiCellWidget( recLabel2, 0, 0, 7, 7); | ||
492 | |||
493 | Rec_PushButton = new QPushButton( tab, "Rec_PushButton" ); | ||
494 | layout1->addMultiCellWidget( Rec_PushButton, 1, 1, 7, 7); | ||
495 | Rec_PushButton->setFixedSize(22,22); | ||
496 | Rec_PushButton->setPixmap( image6 ); | ||
497 | |||
498 | t = new QTimer( this ); | ||
499 | connect( t, SIGNAL( timeout() ), SLOT( timerBreak() ) ); | ||
500 | |||
501 | rewindTimer = new QTimer( this ); | ||
502 | connect( rewindTimer, SIGNAL( timeout() ), SLOT( rewindTimerTimeout() ) ); | ||
503 | |||
504 | forwardTimer = new QTimer( this ); | ||
505 | connect( forwardTimer, SIGNAL( timeout() ), SLOT( forwardTimerTimeout() ) ); | ||
506 | |||
507 | deleteSoundButton = new QPushButton( tab, "deleteSoundButton" ); | ||
508 | layout1->addMultiCellWidget( deleteSoundButton, 1, 1, 8, 8); | ||
509 | deleteSoundButton->setText( tr( "Delete" ) ); | ||
510 | |||
511 | ListView1 = new QListView( tab, "IconView1" ); | ||
512 | layout1->addMultiCellWidget( ListView1, 2, 2, 0, 8); | ||
513 | |||
514 | ListView1->addColumn( tr( "Name" ) ); | ||
515 | ListView1->setColumnWidth(0,140); | ||
516 | ListView1->setSorting( 1, false); | ||
517 | ListView1->addColumn( tr( "Time" ) ); //in seconds | ||
518 | ListView1->setColumnWidth(1,50); | ||
519 | ListView1->addColumn( "Location"); | ||
520 | ListView1->setColumnWidth(2,50); | ||
521 | ListView1->addColumn( "Date"); | ||
522 | ListView1->setColumnWidth(3,63); | ||
523 | |||
524 | ListView1->setColumnWidthMode(0,QListView::Manual); | ||
525 | ListView1->setColumnAlignment(1,QListView::AlignCenter); | ||
526 | ListView1->setColumnAlignment(2,QListView::AlignRight); | ||
527 | ListView1->setColumnAlignment(3,QListView::AlignLeft); | ||
528 | ListView1->setAllColumnsShowFocus( true ); | ||
529 | QPEApplication::setStylusOperation( ListView1->viewport(),QPEApplication::RightOnHold); | ||
530 | |||
531 | TabWidget->insertTab( tab, tr( "Files" ) ); | ||
532 | |||
533 | ///**********<<<<<<<<<<<<>>>>>>>>>>>>*************** | ||
534 | tab_3 = new QWidget( TabWidget, "tab_3" ); | ||
535 | //////////////////////////////////// | ||
536 | |||
537 | Layout19 = new QHBoxLayout( tab_3); | ||
538 | Layout19->setSpacing( 2 ); | ||
539 | Layout19->setMargin( 0 ); | ||
540 | |||
541 | Layout18 = new QVBoxLayout(this); | ||
542 | Layout18->setSpacing( 2 ); | ||
543 | Layout18->setMargin( 0 ); | ||
544 | |||
545 | Layout17 = new QHBoxLayout(this); | ||
546 | Layout17->setSpacing( 2 ); | ||
547 | Layout17->setMargin( 0 ); | ||
548 | |||
549 | sampleGroup = new QGroupBox( tab_3, "samplegroup" ); | ||
550 | sampleGroup->setTitle( tr( "Sample Rate" ) ); | ||
551 | sampleGroup->setFixedSize( 95,50); | ||
552 | |||
553 | sampleRateComboBox = new QComboBox( false, sampleGroup, "SampleRateComboBox" ); | ||
554 | sampleRateComboBox->setGeometry( QRect( 10, 20, 80, 25 ) ); | ||
555 | //#ifndef QT_QWS_EBX | ||
556 | sampleRateComboBox->insertItem( tr( "44100")); | ||
557 | sampleRateComboBox->insertItem( tr( "32000")); | ||
558 | //#endif | ||
559 | sampleRateComboBox->insertItem( tr( "22050")); | ||
560 | //#ifndef QT_QWS_VERCEL_IDR | ||
561 | sampleRateComboBox->insertItem( tr( "16000")); | ||
562 | sampleRateComboBox->insertItem( tr( "11025")); | ||
563 | sampleRateComboBox->insertItem( tr( "8000")); | ||
564 | //#endif | ||
565 | |||
566 | Layout17->addWidget( sampleGroup ); | ||
567 | |||
568 | sizeGroup= new QGroupBox( tab_3, "sizeGroup" ); | ||
569 | sizeGroup->setTitle( tr( "Limit Size" ) ); | ||
570 | sizeGroup->setFixedSize(80,50); | ||
571 | |||
572 | sizeLimitCombo = new QComboBox( false, sizeGroup, "sizeLimitCombo" ); | ||
573 | sizeLimitCombo ->setGeometry( QRect( 5, 20, 70, 25 ) ); | ||
574 | sizeLimitCombo->insertItem(tr("Unlimited")); | ||
575 | for(int i=1;i<13; i++) { | ||
576 | sizeLimitCombo->insertItem( QString::number(i*5)); | ||
577 | } | ||
578 | |||
579 | // sizeLimitCombo->insertItem(tr("5 secs")); | ||
580 | // sizeLimitCombo->insertItem(tr("10 secs")); | ||
581 | // sizeLimitCombo->insertItem(tr("15 secs")); | ||
582 | // sizeLimitCombo->insertItem(tr("20 secs")); | ||
583 | |||
584 | // Layout18->addWidget( sizeGroup ); | ||
585 | Layout17->addWidget( sizeGroup ); | ||
586 | |||
587 | Layout18->addLayout( Layout17 ); | ||
588 | |||
589 | Layout16 = new QHBoxLayout(this); | ||
590 | Layout16->setSpacing( 2 ); | ||
591 | Layout16->setMargin( 0 ); | ||
592 | |||
593 | dirGroup = new QGroupBox( tab_3, "dirGroup" ); | ||
594 | dirGroup->setTitle( tr( "File Directory" ) ); | ||
595 | dirGroup->setFixedSize(130,50); | ||
596 | |||
597 | directoryComboBox = new QComboBox( false, dirGroup, "dirGroup" ); | ||
598 | directoryComboBox->setGeometry( QRect( 10, 15, 115, 25 ) ); | ||
599 | |||
600 | Layout18->addWidget( dirGroup ); | ||
601 | |||
602 | bitGroup = new QGroupBox( tab_3, "bitGroup" ); | ||
603 | bitGroup->setTitle( tr( "Bit Depth" ) ); | ||
604 | bitGroup->setFixedSize(65,50); | ||
605 | |||
606 | bitRateComboBox = new QComboBox( false, bitGroup, "BitRateComboBox" ); | ||
607 | bitRateComboBox->insertItem( tr( "16" ) ); | ||
608 | bitRateComboBox->insertItem( tr( "8" ) ); | ||
609 | bitRateComboBox->setGeometry( QRect( 5, 20, 50, 25 ) ); | ||
610 | |||
611 | Layout18->addWidget( bitGroup ); | ||
612 | |||
613 | compressionCheckBox = new QCheckBox ( "Wave Compression (smaller files)", tab_3 ); | ||
614 | Layout18->addWidget( compressionCheckBox ); | ||
615 | |||
616 | autoMuteCheckBox= new QCheckBox ( "auto Mute", tab_3 ); | ||
617 | Layout18->addWidget( autoMuteCheckBox ); | ||
618 | |||
619 | Layout19->addLayout( Layout18 ); | ||
620 | |||
621 | QWidget *d = QApplication::desktop(); | ||
622 | int width=d->width(); | ||
623 | int height=d->height(); | ||
624 | |||
625 | |||
626 | |||
627 | if( width < height) { | ||
628 | |||
629 | tab_5 = new QWidget( TabWidget, "tab_5" ); | ||
630 | |||
631 | QHBoxLayout *Layout19a; | ||
632 | Layout19a = new QHBoxLayout( tab_5); | ||
633 | Layout19a->setSpacing( 2 ); | ||
634 | Layout19a->setMargin( 0 ); | ||
635 | |||
636 | |||
637 | Layout15 = new QVBoxLayout(this); | ||
638 | Layout15->setSpacing( 2 ); | ||
639 | Layout15->setMargin( 0 ); | ||
640 | |||
641 | Layout15b = new QVBoxLayout(this); | ||
642 | Layout15b->setSpacing( 2 ); | ||
643 | Layout15b->setMargin( 0 ); | ||
644 | |||
645 | TextLabel2 = new QLabel( tab_5, "InputLabel" ); | ||
646 | TextLabel2->setText( tr( "In")); | ||
647 | TextLabel2->setFixedWidth(35); | ||
648 | Layout15->addWidget( TextLabel2 ); | ||
649 | |||
650 | TextLabel3 = new QLabel( tab_5, "OutputLabel" ); | ||
651 | TextLabel3->setText( tr( "Out" ) ); | ||
652 | Layout15b->addWidget( TextLabel3 ); | ||
653 | |||
654 | InputSlider = new QSlider( -100, 0, 10, 0, QSlider::Vertical, tab_5, (const char *) "InputSlider" ); | ||
655 | InputSlider->setTickmarks(QSlider::Both); | ||
656 | Layout15->addWidget( InputSlider); | ||
657 | |||
658 | OutputSlider = new QSlider( -100,0,10,0, QSlider::Vertical,tab_5,(const char *) "OutputSlider" ); | ||
659 | OutputSlider->setTickmarks(QSlider::Both); | ||
660 | |||
661 | Layout15b->addWidget( OutputSlider ); | ||
662 | |||
663 | outMuteCheckBox = new QCheckBox ( "mute", tab_5 ); | ||
664 | Layout15->addWidget( outMuteCheckBox ); | ||
665 | |||
666 | inMuteCheckBox = new QCheckBox ( "mute", tab_5 ); | ||
667 | inMuteCheckBox-> setFocusPolicy ( QWidget::NoFocus ); | ||
668 | Layout15b->addWidget( inMuteCheckBox ); | ||
669 | |||
670 | |||
671 | Layout19a->addLayout( Layout15 ); | ||
672 | Layout19a->addLayout( Layout15b ); | ||
673 | |||
674 | fillDirectoryCombo(); | ||
675 | |||
676 | TabWidget->insertTab( tab_3, tr( "Options" ) ); | ||
677 | |||
678 | TabWidget->insertTab( tab_5, tr( "Volume" ) ); | ||
679 | |||
680 | } else {// landscape | ||
681 | |||
682 | // Layout16->addWidget( dirGroup ); | ||
683 | // Layout18->addLayout( Layout16 ); | ||
684 | Layout15 = new QVBoxLayout(this); | ||
685 | Layout15->setSpacing( 2 ); | ||
686 | Layout15->setMargin( 0 ); | ||
687 | |||
688 | Layout15b = new QVBoxLayout(this); | ||
689 | Layout15b->setSpacing( 2 ); | ||
690 | Layout15b->setMargin( 0 ); | ||
691 | |||
692 | TextLabel2 = new QLabel( tab_3, "InputLabel" ); | ||
693 | TextLabel2->setText( tr( "In")); | ||
694 | TextLabel2->setFixedWidth(35); | ||
695 | Layout15->addWidget( TextLabel2 ); | ||
696 | |||
697 | TextLabel3 = new QLabel( tab_3, "OutputLabel" ); | ||
698 | TextLabel3->setText( tr( "Out" ) ); | ||
699 | Layout15b->addWidget( TextLabel3 ); | ||
700 | |||
701 | InputSlider = new QSlider( -100, 0, 10, 0, QSlider::Vertical, tab_3, (const char *) "InputSlider" ); | ||
702 | // InputSlider->setTickmarks(QSlider::Both); | ||
703 | Layout15->addWidget( InputSlider); | ||
704 | |||
705 | OutputSlider = new QSlider( -100,0,10,0, QSlider::Vertical,tab_3,(const char *) "OutputSlider" ); | ||
706 | // OutputSlider->setTickmarks(QSlider::Both); | ||
707 | |||
708 | Layout15b->addWidget( OutputSlider ); | ||
709 | |||
710 | outMuteCheckBox = new QCheckBox ( "mute", tab_3 ); | ||
711 | Layout15->addWidget( outMuteCheckBox ); | ||
712 | |||
713 | inMuteCheckBox = new QCheckBox ( "mute", tab_3 ); | ||
714 | inMuteCheckBox-> setFocusPolicy ( QWidget::NoFocus ); | ||
715 | Layout15b->addWidget( inMuteCheckBox ); | ||
716 | |||
717 | |||
718 | Layout19->addLayout( Layout15 ); | ||
719 | Layout19->addLayout( Layout15b ); | ||
720 | |||
721 | fillDirectoryCombo(); | ||
722 | |||
723 | TabWidget->insertTab( tab_3, tr( "Options" ) ); | ||
724 | |||
725 | } | ||
726 | |||
727 | |||
728 | ///**********<<<<<<<<<<<<>>>>>>>>>>>>*************** | ||
729 | |||
730 | tab_4 = new QWidget( TabWidget, "tab_4" ); | ||
731 | QGridLayout *layout4 = new QGridLayout( tab_4); | ||
732 | layout4->setSpacing( 2); | ||
733 | layout4->setMargin( 2); | ||
734 | TabWidget->insertTab( tab_4, tr( "Help")); | ||
735 | |||
736 | ///////////////////////////////////////////// FIXME change to a real helpfile path | ||
737 | QString url="/index.html"; | ||
738 | HelpWindow *help = new HelpWindow( url, ".", tab_4, "qperec_help"); | ||
739 | layout4->addMultiCellWidget( help, 0, 1, 0, 1); | ||
740 | if( !QFile(url).exists()) { | ||
741 | help->hide(); | ||
742 | //help->showMaximized(); | ||
743 | QLabel *helpLabel; | ||
744 | helpLabel = new QLabel( tab_4, "TimeLabel" ); | ||
745 | layout4->addMultiCellWidget( helpLabel, 0, 3, 0, 4 ); | ||
746 | helpLabel->setText( "<B>QpeRec</B><br>" | ||
747 | "Records files in standard wav format<br>" | ||
748 | "or a compressed version<br>" | ||
749 | "For help, please email the author<br>" | ||
750 | "<B>QpeRec</B> is copyright© 2002 by" | ||
751 | " L.J. Potter<br>llornkcor@handhelds.org<BR>" | ||
752 | "and is licensed under the <B>QPL</B>"); | ||
753 | } | ||
754 | ///**********<<<<<<<<<<<<>>>>>>>>>>>>*************** | ||
755 | |||
756 | } | ||
757 | |||
758 | void QtRec::initIconView() { | ||
759 | |||
760 | ListView1->clear(); | ||
761 | Config cfg("QpeRec"); | ||
762 | cfg.setGroup("Sounds"); | ||
763 | QString temp; | ||
764 | QPixmap image0( ( const char** ) image0_data ); | ||
765 | |||
766 | |||
767 | int nFiles = cfg.readNumEntry("NumberofFiles",0); | ||
768 | for(int i=1;i<= nFiles;i++) { | ||
769 | |||
770 | QListViewItem * item; | ||
771 | QString fileS, mediaLocation, fileDate, filePath; | ||
772 | |||
773 | // temp.sprintf("%d",i); | ||
774 | temp=cfg.readEntry(temp,""); //reads currentFile | ||
775 | filePath = cfg.readEntry(temp,""); //currentFileName | ||
776 | |||
777 | QFileInfo info(filePath); | ||
778 | fileDate = info.lastModified().toString(); | ||
779 | |||
780 | fileS = cfg.readEntry( filePath, "0" );// file length in seconds | ||
781 | mediaLocation=getStorage( filePath); | ||
782 | if(info.exists()) { | ||
783 | item = new QListViewItem( ListView1, temp, fileS, mediaLocation, fileDate); | ||
784 | item->setPixmap( 0, image0); | ||
785 | if(currentFileName == filePath) | ||
786 | ListView1->setSelected( item, true); | ||
787 | } | ||
788 | } | ||
789 | } | ||
790 | |||
791 | void QtRec::initConnections() { | ||
792 | connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); | ||
793 | |||
794 | connect( toBeginningButton, SIGNAL( pressed()), this, SLOT( rewindPressed() )); | ||
795 | connect( toBeginningButton, SIGNAL( released()), this, SLOT( rewindReleased() )); | ||
796 | connect( toEndButton, SIGNAL( pressed()), this, SLOT( FastforwardPressed() )); | ||
797 | connect( toEndButton, SIGNAL( released()), this, SLOT( FastforwardReleased() )); | ||
798 | connect( deleteSoundButton, SIGNAL(released()), this, SLOT( deleteSound() )); | ||
799 | connect( Stop_PushButton, SIGNAL(released()), this, SLOT( doPlayBtn() )); | ||
800 | connect( Rec_PushButton, SIGNAL(released()), this, SLOT( newSound() ) ); | ||
801 | connect( TabWidget, SIGNAL( currentChanged( QWidget*)),this, SLOT(thisTab(QWidget*) )); | ||
802 | connect( OutputSlider, SIGNAL(sliderReleased()), this, SLOT( changedOutVolume()) ); | ||
803 | connect( InputSlider, SIGNAL(sliderReleased()), this, SLOT( changedInVolume()) ); | ||
804 | |||
805 | // connect( OutputSlider, SIGNAL(valueChanged( int)), this, SLOT(changedOutVolume(int)) ); | ||
806 | // connect( InputSlider, SIGNAL(valueChanged( int)), this, SLOT(changedInVolume(int)) ); | ||
807 | |||
808 | connect( sampleRateComboBox, SIGNAL(activated( int)), this, SLOT( changesamplerateCombo(int)) ); | ||
809 | connect( bitRateComboBox, SIGNAL(activated( int)), this, SLOT( changebitrateCombo(int)) ); | ||
810 | connect( directoryComboBox, SIGNAL(activated( int)), this, SLOT( changeDirCombo(int)) ); | ||
811 | connect( sizeLimitCombo, SIGNAL(activated( int)), this, SLOT( changeSizeLimitCombo(int)) ); | ||
812 | connect( outMuteCheckBox, SIGNAL(toggled( bool)), this, SLOT( doVolMuting(bool)) ); | ||
813 | connect( inMuteCheckBox , SIGNAL(toggled( bool)), this, SLOT( doMicMuting(bool)) ); | ||
814 | connect( ListView1,SIGNAL(doubleClicked( QListViewItem*)),this,SLOT( itClick(QListViewItem*))); | ||
815 | connect( ListView1, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), | ||
816 | this,SLOT( listPressed(int, QListViewItem *, const QPoint&, int)) ); | ||
817 | connect( timeSlider, SIGNAL( sliderMoved( int)), this, SLOT( changeTimeSlider(int) )); | ||
818 | connect( timeSlider, SIGNAL( sliderPressed( )), this, SLOT( timeSliderPressed() )); | ||
819 | connect( timeSlider, SIGNAL( sliderReleased( )), this, SLOT( timeSliderReleased() )); | ||
820 | connect( compressionCheckBox, SIGNAL( toggled(bool)),this, SLOT( compressionSelected(bool))); | ||
821 | connect( autoMuteCheckBox, SIGNAL( toggled(bool)),this, SLOT( slotAutoMute(bool))); | ||
822 | } | ||
823 | |||
824 | void QtRec::initConfig() { | ||
825 | int index, fred, i; | ||
826 | Config cfg("QpeRec"); | ||
827 | cfg.setGroup("Settings"); | ||
828 | |||
829 | index = cfg.readNumEntry("samplerate",22050); | ||
830 | bool ok; | ||
831 | |||
832 | for(int ws=0;ws<sampleRateComboBox->count();ws++) { | ||
833 | fred = sampleRateComboBox->text(ws).toInt(&ok, 10); | ||
834 | if(index == fred) { | ||
835 | filePara.sampleRate = fred; | ||
836 | sampleRateComboBox->setCurrentItem(ws); | ||
837 | } | ||
838 | } | ||
839 | |||
840 | i=cfg.readNumEntry("bitrate",16); | ||
841 | if(i == 16) | ||
842 | bitRateComboBox->setCurrentItem( 0); | ||
843 | else | ||
844 | bitRateComboBox->setCurrentItem( 1); | ||
845 | filePara.resolution = i; | ||
846 | |||
847 | i=cfg.readNumEntry("sizeLimit", 5 ); | ||
848 | QString temp; | ||
849 | // for(int i=1;i<13; i++) { | ||
850 | // temp = sizeLimitCombo->text(i); | ||
851 | |||
852 | // sizeLimitCombo->insertItem( QString::number(i*5)+tr(" secs")); | ||
853 | // } | ||
854 | sizeLimitCombo->setCurrentItem((i/5)); | ||
855 | |||
856 | compressionCheckBox->setChecked( cfg.readBoolEntry("wavCompression",1)); | ||
857 | if( compressionCheckBox->isChecked()) { | ||
858 | bitRateComboBox->setEnabled(false); | ||
859 | bitRateComboBox->setCurrentItem(0); | ||
860 | filePara.resolution=16; | ||
861 | } | ||
862 | |||
863 | autoMuteCheckBox->setChecked( cfg.readBoolEntry("useAutoMute",0)); | ||
864 | if( autoMuteCheckBox->isChecked()) | ||
865 | slotAutoMute(true); | ||
866 | else | ||
867 | slotAutoMute(false); | ||
868 | |||
869 | Config cofg( "qpe"); | ||
870 | cofg.setGroup( "Volume"); | ||
871 | outMuteCheckBox->setChecked( cofg.readBoolEntry( "Mute",0)); | ||
872 | inMuteCheckBox->setChecked( cofg.readBoolEntry( "MicMute",0)); | ||
873 | } | ||
874 | |||
875 | //================ | ||
876 | |||
877 | void QtRec::stop() { | ||
878 | qDebug("<<<<<<<<<stop()"); | ||
879 | setRecordButton(false); | ||
880 | monitoring=false; | ||
881 | stopped=true; | ||
882 | |||
883 | if( !recording) | ||
884 | endPlaying(); | ||
885 | else | ||
886 | endRecording(); | ||
887 | timeSlider->setValue(0); | ||
888 | // QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << true; // mute device | ||
889 | } | ||
890 | |||
891 | void QtRec::doPlayBtn() { | ||
892 | |||
893 | if(!stopped) { | ||
894 | playLabel2->setText("Play"); | ||
895 | stop(); | ||
896 | } else { | ||
897 | if(ListView1->currentItem() == 0) return; | ||
898 | playLabel2->setText("Stop"); | ||
899 | currentFile = ListView1->currentItem()->text(0); | ||
900 | start(); | ||
901 | } | ||
902 | } | ||
903 | |||
904 | void QtRec::start() { //play | ||
905 | if(stopped) { | ||
906 | qDebug("start::"); | ||
907 | QPixmap image3( ( const char** ) image3_data ); | ||
908 | Stop_PushButton->setPixmap( image3 ); | ||
909 | Stop_PushButton->setDown(true); | ||
910 | stopped=false; | ||
911 | paused=false; | ||
912 | secCount=1; | ||
913 | |||
914 | if( openPlayFile()) | ||
915 | if( setupAudio( false)) //recording is false | ||
916 | doPlay(); | ||
917 | } | ||
918 | } | ||
919 | |||
920 | bool QtRec::rec() { //record | ||
921 | qDebug("rec()"); | ||
922 | if(!stopped) { | ||
923 | qDebug("rec:: !stopped"); | ||
924 | monitoring=true; | ||
925 | return false; | ||
926 | } else { | ||
927 | qDebug("go ahead and record"); | ||
928 | secCount=1; | ||
929 | playLabel2->setText("Stop"); | ||
930 | monitoring=false; | ||
931 | setRecordButton(true); | ||
932 | stopped=false; | ||
933 | |||
934 | if( setupAudio( true)) | ||
935 | if(setUpFile()) { | ||
936 | qDebug("Ok to start recording"); | ||
937 | int fileSize=0; | ||
938 | Config cfg("QpeRec"); | ||
939 | cfg.setGroup("Settings"); | ||
940 | qDebug( "<<<<<<<Device bits %d, device rate %d, device channels %d", | ||
941 | soundDevice->getDeviceBits(), | ||
942 | soundDevice->getDeviceRate(), | ||
943 | soundDevice->getDeviceChannels()); | ||
944 | |||
945 | //filePara.sampleRate = cfg.readNumEntry("samplerate", 22050); | ||
946 | qDebug("sample rate is %d", filePara.sampleRate); | ||
947 | filePara.SecondsToRecord = getCurrentSizeLimit(); | ||
948 | |||
949 | qDebug("size limit %d sec", filePara.SecondsToRecord); | ||
950 | int diskSize = checkDiskSpace( (const QString &) wavFile->trackName()); | ||
951 | |||
952 | if( filePara.SecondsToRecord == 0) { | ||
953 | fileSize = diskSize; | ||
954 | } else if( filePara.format==WAVE_FORMAT_PCM) { | ||
955 | qDebug("WAVE_FORMAT_PCM"); | ||
956 | fileSize = (filePara.SecondsToRecord ) * filePara.channels | ||
957 | * filePara.sampleRate *(filePara.resolution/8)+1000; | ||
958 | } else { | ||
959 | qDebug("WAVE_FORMAT_DVI_ADPCM"); | ||
960 | fileSize = ((filePara.SecondsToRecord) * filePara.channels | ||
961 | * filePara.sampleRate *(filePara.resolution/8) )/4+250; | ||
962 | } | ||
963 | |||
964 | filePara.samplesToRecord = fileSize; | ||
965 | qDebug("filesize should be %d, bits %d, rate %d", | ||
966 | filePara.samplesToRecord, filePara.resolution, filePara.sampleRate); | ||
967 | if(paused) { | ||
968 | paused = false; | ||
969 | } | ||
970 | // else { | ||
971 | qDebug("Setting timeslider %d", filePara.samplesToRecord); | ||
972 | // if(fileSize != 0) | ||
973 | timeSlider->setRange(0, filePara.samplesToRecord); | ||
974 | // } | ||
975 | |||
976 | if( diskSize < fileSize/1024) { | ||
977 | QMessageBox::warning(this, | ||
978 | tr("Low Disk Space"), | ||
979 | tr("You are running low of\nrecording space\n" | ||
980 | "or a card isn't being recognized")); | ||
981 | stopped = true; //we need to be stopped | ||
982 | stop(); | ||
983 | } else { | ||
984 | QString msg; | ||
985 | msg.sprintf("%d, %d, %d", filePara.sampleRate, filePara.channels, filePara.resolution); | ||
986 | #ifdef DEV_VERSION | ||
987 | setCaption( msg); | ||
988 | #endif | ||
989 | filePara.fileName=currentFile.latin1(); | ||
990 | qDebug("Start recording thread"); | ||
991 | |||
992 | pthread_t thread1; | ||
993 | pthread_create( &thread1, NULL, (void * (*)(void *))quickRec, NULL/* &*/); | ||
994 | // quickRec(); | ||
995 | toBeginningButton->setEnabled(false); | ||
996 | toEndButton->setEnabled(false); | ||
997 | |||
998 | startTimer(1000); | ||
999 | } | ||
1000 | } //end setUpFile | ||
1001 | } //end setupAudio | ||
1002 | // _exit( 0); | ||
1003 | |||
1004 | // ///* default: | ||
1005 | // // /* pid greater than zero is parent getting the child's pid */ | ||
1006 | // /* printf("Child's pid is %d\n",pid); | ||
1007 | // waitpid( pid, &status, 0); | ||
1008 | // printf("Child[%d] exited with status %d\n", pid, status);*/ | ||
1009 | // while (wait(NULL) != pid) | ||
1010 | // ; | ||
1011 | // printf("child %ld terminated normally, return status is zero\n", (long) pid); | ||
1012 | // endRecording(); | ||
1013 | /* else { //device was not opened | ||
1014 | qDebug("Audio device open failed"); | ||
1015 | return false; | ||
1016 | } | ||
1017 | }*/ | ||
1018 | // } //end fork | ||
1019 | // } | ||
1020 | // } | ||
1021 | return true; | ||
1022 | } | ||
1023 | /* | ||
1024 | This happens when a tab is selected*/ | ||
1025 | void QtRec::thisTab(QWidget* widg) { | ||
1026 | if(widg != NULL) { | ||
1027 | int index=TabWidget->currentPageIndex(); | ||
1028 | |||
1029 | if(index==0) { //file page | ||
1030 | } | ||
1031 | |||
1032 | if(index ==1) { //control page | ||
1033 | fillDirectoryCombo(); | ||
1034 | // soundDevice->getOutVol(); | ||
1035 | // soundDevice->getInVol(); | ||
1036 | } | ||
1037 | |||
1038 | if(index==2) { //help page | ||
1039 | } | ||
1040 | qApp->processEvents(); | ||
1041 | update(); | ||
1042 | } | ||
1043 | } | ||
1044 | |||
1045 | void QtRec::getOutVol( ) { | ||
1046 | filePara.outVol = soundDevice->getOutVolume(); | ||
1047 | qDebug("out vol %d", filePara.outVol); | ||
1048 | OutputSlider->setValue( -filePara.outVol); | ||
1049 | } | ||
1050 | |||
1051 | void QtRec::getInVol() { | ||
1052 | filePara.inVol = soundDevice->getInVolume(); | ||
1053 | qDebug("in vol %d", filePara.inVol); | ||
1054 | InputSlider->setValue( -filePara.inVol); | ||
1055 | } | ||
1056 | |||
1057 | void QtRec::changedOutVolume() { | ||
1058 | soundDevice->changedOutVolume(-OutputSlider->value()); | ||
1059 | } | ||
1060 | |||
1061 | void QtRec::changedInVolume( ) { | ||
1062 | soundDevice->changedInVolume( -InputSlider->value()); | ||
1063 | } | ||
1064 | |||
1065 | |||
1066 | bool QtRec::setupAudio( bool b) { | ||
1067 | bool ok; | ||
1068 | int sampleformat, stereo, flags; | ||
1069 | char * dspString, *mixerString; | ||
1070 | |||
1071 | filePara.resolution = bitRateComboBox->currentText().toInt( &ok,10); //16 | ||
1072 | |||
1073 | if( !b){ // we want to play | ||
1074 | qDebug("setting up DSP for playing"); | ||
1075 | if( filePara.resolution == 16 || compressionCheckBox->isChecked() ) { | ||
1076 | sampleformat = AFMT_S16_LE; | ||
1077 | filePara.resolution = 16; | ||
1078 | } else { | ||
1079 | sampleformat = AFMT_U8; | ||
1080 | filePara.resolution=8; | ||
1081 | } | ||
1082 | |||
1083 | stereo = filePara.channels = 1; | ||
1084 | flags= O_WRONLY; | ||
1085 | dspString = DSPSTROUT; | ||
1086 | mixerString = DSPSTRMIXEROUT; | ||
1087 | } else { // we want to record | ||
1088 | qDebug("setting up DSP for recording"); | ||
1089 | |||
1090 | if( !bitRateComboBox->isEnabled() || bitRateComboBox->currentText() == "16") | ||
1091 | sampleformat = AFMT_S16_LE; | ||
1092 | else | ||
1093 | sampleformat = AFMT_U8; | ||
1094 | |||
1095 | if( !compressionCheckBox->isChecked()) { | ||
1096 | filePara.format=WAVE_FORMAT_PCM; | ||
1097 | qDebug("WAVE_FORMAT_PCM"); | ||
1098 | } else { | ||
1099 | filePara.format=WAVE_FORMAT_DVI_ADPCM; | ||
1100 | sampleformat=AFMT_S16_LE; | ||
1101 | qDebug("WAVE_FORMAT_DVI_ADPCM"); | ||
1102 | } | ||
1103 | |||
1104 | stereo = filePara.channels = 1; | ||
1105 | // filePara.sampleRate = sampleRateComboBox->currentText().toInt( &ok,10);//44100; | ||
1106 | flags= O_RDWR; | ||
1107 | // flags= O_RDONLY; | ||
1108 | dspString = DSPSTRIN; | ||
1109 | mixerString = DSPSTRMIXEROUT; | ||
1110 | } | ||
1111 | |||
1112 | // if(soundDevice) delete soundDevice; | ||
1113 | qDebug("<<<<<<<<<<<<<<<<<<<open dsp %d %d %d", filePara.sampleRate, filePara.channels, sampleformat); | ||
1114 | soundDevice = new Device( this, dspString, mixerString, b); | ||
1115 | // soundDevice->openDsp(); | ||
1116 | soundDevice->reset(); | ||
1117 | |||
1118 | qDebug("device has been made %d", soundDevice->sd); | ||
1119 | |||
1120 | ////////////////// <<<<<<<<<<<<>>>>>>>>>>>> | ||
1121 | soundDevice->setDeviceFormat( sampleformat); | ||
1122 | soundDevice->setDeviceChannels( filePara.channels); | ||
1123 | soundDevice->setDeviceRate( filePara.sampleRate); | ||
1124 | soundDevice->getDeviceFragSize(); | ||
1125 | #ifdef QT_QWS_EBX | ||
1126 | int frag = FRAGSIZE; | ||
1127 | soundDevice->setFragSize( frag); | ||
1128 | soundDevice->getDeviceFragSize(); | ||
1129 | #endif | ||
1130 | ///////////////// | ||
1131 | filePara.sd = soundDevice->sd; | ||
1132 | |||
1133 | if ( filePara.sd == -1) { | ||
1134 | |||
1135 | monitoring=false; | ||
1136 | stopped=true; | ||
1137 | update(); | ||
1138 | setCaption( tr( "QpeRecord " ) + QString::number(VERSION) ); | ||
1139 | stopped=true; | ||
1140 | return false; | ||
1141 | } | ||
1142 | if(autoMute) | ||
1143 | doMute(false); | ||
1144 | |||
1145 | return true; | ||
1146 | } | ||
1147 | |||
1148 | |||
1149 | bool QtRec::setUpFile() { //setup file for recording | ||
1150 | qDebug("Setting up wavfile"); | ||
1151 | // if(wavFile) delete wavFile; | ||
1152 | wavFile = new WavFile( this, (const QString &)"", | ||
1153 | true, | ||
1154 | filePara.sampleRate, | ||
1155 | filePara.channels, | ||
1156 | filePara.resolution, | ||
1157 | filePara.format); | ||
1158 | |||
1159 | filePara.fd = wavFile->wavHandle(); | ||
1160 | if(filePara.fd == -1) { | ||
1161 | return false; | ||
1162 | } else { | ||
1163 | filePara.channels=1; | ||
1164 | } | ||
1165 | return true; | ||
1166 | } | ||
1167 | |||
1168 | /// <<<<<<<<<<<<<<<< PLAY >>>>>>>>>>>>>>>>>>> | ||
1169 | bool QtRec::doPlay() { | ||
1170 | |||
1171 | // pthread_t thread2; | ||
1172 | // pthread_create( &thread2, NULL, (void * (*)(void *))playIt, NULL/* &*/); | ||
1173 | |||
1174 | // qDebug("doPlay file %d", filePara.fd); | ||
1175 | int bytesWritten, number; | ||
1176 | recording = false; | ||
1177 | // int number=0; | ||
1178 | if( !paused) { | ||
1179 | qDebug("new"); | ||
1180 | total=0; | ||
1181 | bytesWritten=0; | ||
1182 | filePara.numberOfRecordedSeconds = 0; | ||
1183 | } else { | ||
1184 | paused = false; | ||
1185 | secCount = (int)filePara.numberOfRecordedSeconds; | ||
1186 | } | ||
1187 | playing=true; | ||
1188 | number=0; | ||
1189 | |||
1190 | QString num; | ||
1191 | // block=BUFSIZE; | ||
1192 | qDebug("Play number of samples %d", filePara.numberSamples); | ||
1193 | timeSlider->setRange(0, filePara.numberSamples); | ||
1194 | timeString.sprintf("%.2f", filePara.numberOfRecordedSeconds); | ||
1195 | timeLabel->setText( timeString+ tr(" seconds")); | ||
1196 | |||
1197 | if( filePara.format==WAVE_FORMAT_DVI_ADPCM) { | ||
1198 | qDebug("WAVE_FORMAT_DVI_ADPCM"); | ||
1199 | } else { | ||
1200 | qDebug("WAVE_FORMAT_PCM"); | ||
1201 | } | ||
1202 | QString msg; | ||
1203 | msg.sprintf("%d, %d, %d", filePara.sampleRate, filePara.channels, filePara.resolution); | ||
1204 | #ifdef DEV_VERSION | ||
1205 | setCaption( msg); | ||
1206 | #endif | ||
1207 | if( filePara.resolution == 16 ) { //AFMT_S16_LE) { | ||
1208 | qDebug("16 bit"); | ||
1209 | |||
1210 | startTimer(1000); | ||
1211 | |||
1212 | if( filePara.format==WAVE_FORMAT_DVI_ADPCM) { | ||
1213 | char abuf[BUFSIZE/2]; | ||
1214 | short sbuf[BUFSIZE]; | ||
1215 | short sbuf2[BUFSIZE*2]; | ||
1216 | memset( abuf, 0, BUFSIZE / 2); | ||
1217 | memset( sbuf, 0, BUFSIZE); | ||
1218 | memset( sbuf2, 0, BUFSIZE * 2); | ||
1219 | // <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_DVI_ADPCM >>>>>>>>>>>>>>>>>>>>>> | ||
1220 | for(;;) { // play loop | ||
1221 | if (stopped) | ||
1222 | break; // stop if playing was set to false | ||
1223 | |||
1224 | |||
1225 | number=::read( filePara.fd, abuf, BUFSIZE/2); | ||
1226 | adpcm_decoder( abuf, sbuf, number*2, &decoder_state); | ||
1227 | |||
1228 | // for (int i=0;i< number * 2; 2 * i++) { //2*i is left channel | ||
1229 | // sbuf2[i+1]=sbuf2[i]=sbuf[i]; | ||
1230 | // } | ||
1231 | |||
1232 | bytesWritten = write ( filePara.sd, sbuf, number*4); | ||
1233 | // if(filePara.channels==1) | ||
1234 | // total += bytesWritten/2; //mono | ||
1235 | // else | ||
1236 | total += bytesWritten; | ||
1237 | timeSlider->setValue( total / 4); | ||
1238 | |||
1239 | filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate / 2; | ||
1240 | |||
1241 | timeString.sprintf("%.2f", filePara.numberOfRecordedSeconds); | ||
1242 | // if(filePara.numberOfRecordedSeconds>1) | ||
1243 | timeLabel->setText( timeString+ tr(" seconds")); | ||
1244 | // printf("playing number %d, bytes %d, total %d\n",number, bytesWritten, total/4); | ||
1245 | // printf("playing number %d, bytes %d, total %d totalsamples %d number recorded seconds %.2f\r", | ||
1246 | // number, bytesWritten, total/4, filePara.numberSamples, filePara.numberOfRecordedSeconds); | ||
1247 | // fflush(stdout); | ||
1248 | |||
1249 | qApp->processEvents(); | ||
1250 | |||
1251 | if( bytesWritten <= 0 ){//|| secCount > filePara.numberOfRecordedSeconds ) { | ||
1252 | stopped = true; | ||
1253 | endPlaying(); | ||
1254 | } | ||
1255 | } | ||
1256 | } else { | ||
1257 | // <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_PCM >>>>>>>>>>>>>>>>>>>>>> | ||
1258 | short inbuffer[BUFSIZE], outbuffer[BUFSIZE]; | ||
1259 | memset( inbuffer, 0, BUFSIZE); | ||
1260 | memset( outbuffer, 0, BUFSIZE); | ||
1261 | |||
1262 | for(;;) { // play loop | ||
1263 | if (stopped) | ||
1264 | break; // stop if playing was set to false | ||
1265 | number=::read( filePara.fd, inbuffer, BUFSIZE); | ||
1266 | // for (int i=0;i< number * 2; 2 * i++) { //2*i is left channel | ||
1267 | // // for (int i=0;i< number ; i++) { //2*i is left channel | ||
1268 | // outbuffer[i+1]= outbuffer[i]=inbuffer[i]; | ||
1269 | // } | ||
1270 | |||
1271 | bytesWritten = ::write( filePara.sd, inbuffer, number); | ||
1272 | //-------------->>>> out to device | ||
1273 | // total+=bytesWritten; | ||
1274 | // if(filePara.channels==1) | ||
1275 | // total += bytesWritten/2; //mono | ||
1276 | // else | ||
1277 | total += bytesWritten; | ||
1278 | |||
1279 | timeSlider->setValue( total); | ||
1280 | filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate / (float)2; | ||
1281 | |||
1282 | timeString.sprintf("%.2f",filePara.numberOfRecordedSeconds); | ||
1283 | timeLabel->setText( timeString + tr(" seconds")); | ||
1284 | |||
1285 | qApp->processEvents(); | ||
1286 | |||
1287 | if( bytesWritten <= 0 && secCount > filePara.numberOfRecordedSeconds ) { | ||
1288 | stopped = true; | ||
1289 | endPlaying(); | ||
1290 | } | ||
1291 | } | ||
1292 | // printf("\nplaying number %d, bytes %d, total %d\r",number, bytesWritten, total); | ||
1293 | // fflush(stdout); | ||
1294 | } //end loop | ||
1295 | } else { /////////////////////////////// format = AFMT_U8; | ||
1296 | unsigned char unsigned_inbuffer[BUFSIZE], unsigned_outbuffer[BUFSIZE]; | ||
1297 | memset( unsigned_inbuffer,0,BUFSIZE); | ||
1298 | for(;;) { // main loop | ||
1299 | if (stopped) | ||
1300 | break; // stop if playing was set to false | ||
1301 | number=::read( filePara.fd, unsigned_inbuffer, BUFSIZE); | ||
1302 | //data = (val >> 8) ^ 0x80; | ||
1303 | // unsigned_outbuffer = (unsigned_inbuffer >> 8) ^ 0x80; | ||
1304 | bytesWritten = write ( filePara.sd, unsigned_inbuffer, number); | ||
1305 | total+=bytesWritten; | ||
1306 | |||
1307 | timeSlider->setValue( total); | ||
1308 | |||
1309 | filePara.numberOfRecordedSeconds=(float)total/(float)filePara.sampleRate; | ||
1310 | timeString.sprintf("%.2f",filePara.numberOfRecordedSeconds); | ||
1311 | timeLabel->setText( timeString + tr(" seconds")); | ||
1312 | qApp->processEvents(); | ||
1313 | |||
1314 | if( bytesWritten <= 0 && secCount > filePara.numberOfRecordedSeconds ) { | ||
1315 | stopped = true; | ||
1316 | endPlaying(); | ||
1317 | } | ||
1318 | // printf("Writing number %d, bytes %d, total %d, numberSamples %d\r",number, bytesWritten , total, filePara.numberSamples); | ||
1319 | // fflush(stdout); | ||
1320 | } | ||
1321 | } | ||
1322 | |||
1323 | // qDebug("\nstopped or paused %d", total/4); | ||
1324 | if(!paused && !stopped) { | ||
1325 | stopped = true; | ||
1326 | // endPlaying(); | ||
1327 | endPlaying(); | ||
1328 | } | ||
1329 | return true; | ||
1330 | } | ||
1331 | |||
1332 | |||
1333 | void QtRec::changebitrateCombo(int i) { | ||
1334 | Config cfg("QpeRec"); | ||
1335 | cfg.setGroup("Settings"); | ||
1336 | int bits=0; | ||
1337 | if(i==0) { bits=16; } | ||
1338 | else { bits=8; } | ||
1339 | cfg.writeEntry("bitrate", bits); | ||
1340 | filePara.resolution=bits; | ||
1341 | cfg.write(); | ||
1342 | } | ||
1343 | |||
1344 | void QtRec::changesamplerateCombo(int i) { | ||
1345 | Config cfg("QpeRec"); | ||
1346 | cfg.setGroup("Settings"); | ||
1347 | int rate=0; | ||
1348 | bool ok; | ||
1349 | rate = sampleRateComboBox->text(i).toInt(&ok, 10); | ||
1350 | cfg.writeEntry("samplerate",rate); | ||
1351 | filePara.sampleRate=rate; | ||
1352 | /* soundDevice = new Device( this, DSPSTROUT, DSPSTRMIXER, false); | ||
1353 | soundDevice->openDsp();*/ | ||
1354 | // | ||
1355 | // soundDevice->setDeviceFormat(AFMT_S16_LE); | ||
1356 | // soundDevice->setDeviceChannels(filePara.channels); | ||
1357 | // soundDevice->setDeviceRate(filePara.sampleRate); | ||
1358 | // | ||
1359 | // soundDevice->closeDevice( true); | ||
1360 | // soundDevice=0; | ||
1361 | // delete soundDevice; | ||
1362 | qDebug("Change sample rate %d", rate); | ||
1363 | cfg.write(); | ||
1364 | |||
1365 | } | ||
1366 | |||
1367 | |||
1368 | void QtRec::changeDirCombo(int index) { | ||
1369 | Config cfg("QpeRec"); | ||
1370 | cfg.setGroup("Settings"); | ||
1371 | QString sName = directoryComboBox->text(index); | ||
1372 | |||
1373 | StorageInfo storageInfo; | ||
1374 | const QList<FileSystem> &fs = storageInfo.fileSystems(); | ||
1375 | QListIterator<FileSystem> it ( fs ); | ||
1376 | QString storage; | ||
1377 | for( ; it.current(); ++it ){ | ||
1378 | if( sName == (*it)->name()+" "+ (*it)->path() || | ||
1379 | (*it)->name() == sName ) { | ||
1380 | const QString path = (*it)->path(); | ||
1381 | recDir = path; | ||
1382 | cfg.writeEntry("directory", recDir); | ||
1383 | qDebug("new rec dir "+recDir); | ||
1384 | } | ||
1385 | } | ||
1386 | cfg.write(); | ||
1387 | } | ||
1388 | |||
1389 | |||
1390 | void QtRec::changeSizeLimitCombo(int) { | ||
1391 | Config cfg("QpeRec"); | ||
1392 | cfg.setGroup("Settings"); | ||
1393 | cfg.writeEntry("sizeLimit", getCurrentSizeLimit() ); | ||
1394 | cfg.write(); | ||
1395 | } | ||
1396 | |||
1397 | void QtRec::newSound() { | ||
1398 | qDebug("<<<<<<<<<new sound"); | ||
1399 | |||
1400 | if( !rec()) { | ||
1401 | qDebug("rec() failed"); | ||
1402 | endRecording(); | ||
1403 | deleteSound(); | ||
1404 | } | ||
1405 | |||
1406 | } | ||
1407 | |||
1408 | void QtRec::itClick(QListViewItem *item) { | ||
1409 | currentFile=item->text(0); | ||
1410 | setCaption("QpeRecord "+currentFile); | ||
1411 | } | ||
1412 | |||
1413 | void QtRec::deleteSound() { | ||
1414 | Config cfg("QpeRec"); | ||
1415 | cfg.setGroup("Sounds"); | ||
1416 | if( ListView1->currentItem() == NULL) | ||
1417 | return; | ||
1418 | #ifndef DEV_VERSION | ||
1419 | switch ( QMessageBox::warning(this,tr("Delete"), | ||
1420 | tr("Do you really want to <font size=+2><B>DELETE</B></font>\nthe selected file?"), | ||
1421 | tr("Yes"),tr("No"),0,1,1) ) { | ||
1422 | case 0: | ||
1423 | #endif | ||
1424 | { | ||
1425 | QString file = ListView1->currentItem()->text(0); | ||
1426 | // qDebug("Filename to find is "+file); | ||
1427 | QString fileName; | ||
1428 | fileName = cfg.readEntry( file, ""); | ||
1429 | QFile f(fileName); | ||
1430 | // qDebug("fileName is "+fileName); | ||
1431 | if(f.exists()) | ||
1432 | if( !f.remove()) | ||
1433 | QMessageBox::message(tr("Error"),tr("Could not remove file.")); | ||
1434 | |||
1435 | int nFiles = cfg.readNumEntry("NumberofFiles",0); | ||
1436 | bool found=false; | ||
1437 | for(int i=0;i<nFiles+1;i++) { | ||
1438 | // qDebug(cfg.readEntry(QString::number(i))); | ||
1439 | |||
1440 | if( cfg.readEntry( QString::number(i),"").find( file,0,true) != -1) { | ||
1441 | found = true; | ||
1442 | // qDebug( cfg.readEntry(QString::number(i))+"\n" +cfg.readEntry(QString::number(i+1)) ); | ||
1443 | cfg.writeEntry( QString::number(i), cfg.readEntry( QString::number(i+1),"")); | ||
1444 | } | ||
1445 | if(found) | ||
1446 | cfg.writeEntry( QString::number(i), cfg.readEntry( QString::number(i+1),"")); | ||
1447 | } | ||
1448 | |||
1449 | cfg.removeEntry(cfg.readEntry(file)); | ||
1450 | cfg.removeEntry( file); | ||
1451 | // cfg.removeEntry( QString::number(nFiles)); | ||
1452 | cfg.writeEntry("NumberofFiles", nFiles-1); | ||
1453 | cfg.write(); | ||
1454 | |||
1455 | ListView1->takeItem( ListView1->currentItem() ); | ||
1456 | // ListView1->takeItem( ListView1->itemAt(nFiles) ); | ||
1457 | delete ListView1->currentItem(); | ||
1458 | |||
1459 | ListView1->clear(); | ||
1460 | ListView1->setSelected(ListView1->firstChild(), true); | ||
1461 | initIconView(); | ||
1462 | update(); | ||
1463 | } | ||
1464 | #ifndef DEV_VERSION | ||
1465 | }; | ||
1466 | #endif | ||
1467 | setCaption( tr( "QpeRecord " ) + QString::number(VERSION) ); | ||
1468 | |||
1469 | } | ||
1470 | |||
1471 | void QtRec::keyPressEvent( QKeyEvent *e) { | ||
1472 | |||
1473 | switch ( e->key() ) { | ||
1474 | /* | ||
1475 | vercel keys-> | ||
1476 | right side | ||
1477 | 0 | ||
1478 | 1 0x1030 Key_F1 | ||
1479 | 2 0x1031 Key_F2 | ||
1480 | 3 0x1032 Key_F3 | ||
1481 | 4 0x1016 Key_PageUp | ||
1482 | 5 0x1017 Key_PageDown | ||
1483 | 6 | ||
1484 | --------------- | ||
1485 | left side | ||
1486 | Up 0x1013 Key_Up | ||
1487 | Down 0x1015 Key_Down | ||
1488 | Left 0x1012 Key_Left | ||
1489 | Right 0x1014 Key_Right | ||
1490 | 0x1010 Key_Home | ||
1491 | |||
1492 | */ | ||
1493 | // case Key_F1: | ||
1494 | // if(stopped && !recording) | ||
1495 | // newSound(); | ||
1496 | // else | ||
1497 | // stop(); | ||
1498 | // break; | ||
1499 | // case Key_F2: { | ||
1500 | // if( !e->isAutoRepeat()) | ||
1501 | // rewindPressed(); | ||
1502 | // } | ||
1503 | // break; | ||
1504 | // case Key_F3: { | ||
1505 | // if( !e->isAutoRepeat()) | ||
1506 | // FastforwardPressed(); | ||
1507 | // } | ||
1508 | // break; | ||
1509 | |||
1510 | ////////////////////////////// Zaurus keys | ||
1511 | case Key_F9: //activity | ||
1512 | break; | ||
1513 | case Key_F10: //contacts | ||
1514 | break; | ||
1515 | case Key_F11: //menu | ||
1516 | break; | ||
1517 | case Key_F12: //home | ||
1518 | break; | ||
1519 | case Key_F13: //mail | ||
1520 | break; | ||
1521 | case Key_Space: | ||
1522 | break; | ||
1523 | case Key_Delete: | ||
1524 | break; | ||
1525 | case Key_Up: | ||
1526 | // stop(); | ||
1527 | break; | ||
1528 | case Key_Down: | ||
1529 | // newSound(); | ||
1530 | break; | ||
1531 | case Key_Left: { | ||
1532 | qDebug("rewinding"); | ||
1533 | if( !e->isAutoRepeat()) | ||
1534 | rewindPressed(); | ||
1535 | } | ||
1536 | break; | ||
1537 | case Key_Right: { | ||
1538 | if( !e->isAutoRepeat()) | ||
1539 | FastforwardPressed(); | ||
1540 | } | ||
1541 | break; | ||
1542 | } | ||
1543 | } | ||
1544 | |||
1545 | void QtRec::keyReleaseEvent( QKeyEvent *e) { | ||
1546 | switch ( e->key() ) { | ||
1547 | // case Key_F1: | ||
1548 | // if(stopped && !recording) | ||
1549 | // newSound(); | ||
1550 | // else | ||
1551 | // stop(); | ||
1552 | // break; | ||
1553 | // case Key_F2: | ||
1554 | // rewindReleased(); | ||
1555 | // break; | ||
1556 | // case Key_F3: | ||
1557 | // FastforwardReleased(); | ||
1558 | // break; | ||
1559 | |||
1560 | ////////////////////////////// Zaurus keys | ||
1561 | case Key_F9: //activity | ||
1562 | break; | ||
1563 | case Key_F10: //contacts | ||
1564 | break; | ||
1565 | case Key_F11: //menu | ||
1566 | break; | ||
1567 | case Key_F12: //home | ||
1568 | if(stopped) | ||
1569 | doPlayBtn(); | ||
1570 | else | ||
1571 | stop(); | ||
1572 | break; | ||
1573 | case Key_F13: //mail | ||
1574 | break; | ||
1575 | case Key_Space: | ||
1576 | if(stopped && !recording) | ||
1577 | newSound(); | ||
1578 | else | ||
1579 | stop(); | ||
1580 | break; | ||
1581 | case Key_Delete: | ||
1582 | deleteSound(); | ||
1583 | break; | ||
1584 | case Key_Up: | ||
1585 | // stop(); | ||
1586 | qDebug("Up"); | ||
1587 | break; | ||
1588 | case Key_Down: | ||
1589 | // start(); | ||
1590 | // qDebug("Down"); | ||
1591 | // newSound(); | ||
1592 | break; | ||
1593 | case Key_Left: | ||
1594 | qDebug("Left"); | ||
1595 | rewindReleased(); | ||
1596 | break; | ||
1597 | case Key_Right: | ||
1598 | qDebug("Right"); | ||
1599 | FastforwardReleased(); | ||
1600 | break; | ||
1601 | } | ||
1602 | } | ||
1603 | |||
1604 | void QtRec::endRecording() { | ||
1605 | qDebug("endRecording"); | ||
1606 | setRecordButton(false); | ||
1607 | timeSlider->setValue(0); | ||
1608 | toBeginningButton->setEnabled(true); | ||
1609 | toEndButton->setEnabled(true); | ||
1610 | |||
1611 | monitoring=false; | ||
1612 | |||
1613 | killTimers(); | ||
1614 | |||
1615 | if(autoMute) | ||
1616 | doMute(true); | ||
1617 | |||
1618 | soundDevice->closeDevice( true); | ||
1619 | |||
1620 | recording = false; | ||
1621 | stopped=true; | ||
1622 | t->stop(); | ||
1623 | |||
1624 | if( wavFile->track.isOpen()) { | ||
1625 | wavFile->adjustHeaders( filePara.fd, filePara.numberSamples); | ||
1626 | // soundDevice->sd=-1; | ||
1627 | filePara.numberSamples=0; | ||
1628 | // filePara.sd=-1; | ||
1629 | wavFile->closeFile(); | ||
1630 | filePara.fd=0; | ||
1631 | |||
1632 | if(wavFile->isTempFile()) { | ||
1633 | // move tmp file to regular file | ||
1634 | QString cmd; | ||
1635 | cmd.sprintf("mv "+ wavFile->trackName() + " " + wavFile->currentFileName); | ||
1636 | qDebug("moving tmp file to "+currentFileName); | ||
1637 | system(cmd.latin1()); | ||
1638 | } | ||
1639 | |||
1640 | qDebug("Just moved "+wavFile->currentFileName); | ||
1641 | Config cfg("QpeRec"); | ||
1642 | cfg.setGroup("Sounds"); | ||
1643 | |||
1644 | int nFiles = cfg.readNumEntry( "NumberofFiles",0); | ||
1645 | |||
1646 | currentFile = QFileInfo(wavFile->currentFileName).fileName(); | ||
1647 | currentFile=currentFile.left(currentFile.length()-4); | ||
1648 | |||
1649 | cfg.writeEntry( "NumberofFiles",nFiles+1); | ||
1650 | cfg.writeEntry( QString::number( nFiles+1), currentFile); | ||
1651 | cfg.writeEntry( currentFile, wavFile->currentFileName); | ||
1652 | |||
1653 | QString time; | ||
1654 | time.sprintf("%.2f", filePara.numberOfRecordedSeconds); | ||
1655 | cfg.writeEntry( wavFile->currentFileName, time ); | ||
1656 | qDebug("writing config numberOfRecordedSeconds "+time); | ||
1657 | |||
1658 | cfg.write(); | ||
1659 | qDebug("finished recording"); | ||
1660 | timeLabel->setText(""); | ||
1661 | } | ||
1662 | |||
1663 | if(soundDevice) delete soundDevice; | ||
1664 | |||
1665 | initIconView(); | ||
1666 | selectItemByName(currentFile); | ||
1667 | } | ||
1668 | |||
1669 | void QtRec::endPlaying() { | ||
1670 | |||
1671 | qDebug("end playing"); | ||
1672 | setRecordButton(false); | ||
1673 | |||
1674 | toBeginningButton->setEnabled(true); | ||
1675 | toEndButton->setEnabled(true); | ||
1676 | |||
1677 | if(autoMute) | ||
1678 | doMute(true); | ||
1679 | |||
1680 | soundDevice->closeDevice( false); | ||
1681 | soundDevice->sd=-1; | ||
1682 | // if(soundDevice) delete soundDevice; | ||
1683 | qDebug("file and sound device closed"); | ||
1684 | stopped=true; | ||
1685 | recording=false; | ||
1686 | playing=false; | ||
1687 | timeLabel->setText(""); | ||
1688 | monitoring=false; | ||
1689 | total = 0; | ||
1690 | filePara.numberSamples=0; | ||
1691 | filePara.sd=-1; | ||
1692 | wavFile->closeFile(); | ||
1693 | filePara.fd=0; | ||
1694 | // if(wavFile) delete wavFile; //this crashes | ||
1695 | |||
1696 | qDebug("track closed"); | ||
1697 | timeSlider->setValue(0); | ||
1698 | |||
1699 | if(soundDevice) delete soundDevice; | ||
1700 | |||
1701 | } | ||
1702 | |||
1703 | bool QtRec::openPlayFile() { | ||
1704 | |||
1705 | qApp->processEvents(); | ||
1706 | if( currentFile.isEmpty()) { | ||
1707 | QMessageBox::message(tr("Qperec"),tr("Please select file to play")); | ||
1708 | endPlaying(); | ||
1709 | return false; | ||
1710 | } | ||
1711 | QString currentFileName; | ||
1712 | Config cfg("QpeRec"); | ||
1713 | cfg.setGroup("Sounds"); | ||
1714 | int nFiles = cfg.readNumEntry("NumberofFiles",0); | ||
1715 | for(int i=0;i<nFiles+1;i++) { //look for file | ||
1716 | if( cfg.readEntry( QString::number(i),"").find( currentFile,0,true) != -1) { | ||
1717 | currentFileName=cfg.readEntry( currentFile, "" ); | ||
1718 | qDebug("opening for play: "+currentFileName); | ||
1719 | } | ||
1720 | } | ||
1721 | wavFile = new WavFile(this, | ||
1722 | currentFileName, | ||
1723 | false); | ||
1724 | filePara.fd = wavFile->wavHandle(); | ||
1725 | if(filePara.fd == -1) { | ||
1726 | // if(!track.open(IO_ReadOnly)) { | ||
1727 | QString errorMsg=(QString)strerror(errno); | ||
1728 | monitoring=false; | ||
1729 | setCaption( tr( "QpeRecord " ) + QString::number(VERSION) ); | ||
1730 | QMessageBox::message(tr("Note"),tr("Could not open audio file.\n") | ||
1731 | +errorMsg+"\n"+currentFile); | ||
1732 | return false; | ||
1733 | } else { | ||
1734 | filePara.numberSamples=wavFile->getNumberSamples(); | ||
1735 | filePara.format = wavFile->getFormat(); | ||
1736 | // qDebug("file %d, samples %f", filePara.fd, filePara.numberSamples); | ||
1737 | filePara.sampleRate= wavFile->getSampleRate(); | ||
1738 | filePara.resolution=wavFile->getResolution(); | ||
1739 | timeSlider->setPageStep(1); | ||
1740 | monitoring=true; | ||
1741 | timeSlider->setRange(0, filePara.numberSamples ); | ||
1742 | filePara.numberOfRecordedSeconds=(float) filePara.numberSamples / (float)filePara.sampleRate * (float)2; | ||
1743 | } | ||
1744 | |||
1745 | return true; | ||
1746 | } | ||
1747 | |||
1748 | void QtRec::listPressed( int mouse, QListViewItem *item, const QPoint &, int ) { | ||
1749 | if(item == NULL ) | ||
1750 | return; | ||
1751 | switch (mouse) { | ||
1752 | case 1: { | ||
1753 | if( renameBox !=0 ) //tricky | ||
1754 | cancelRename(); | ||
1755 | |||
1756 | currentFile=item->text(0); | ||
1757 | setCaption( "QpeRecord "+currentFile); | ||
1758 | } | ||
1759 | break; | ||
1760 | case 2: | ||
1761 | showListMenu(item); | ||
1762 | ListView1->clearSelection(); | ||
1763 | break; | ||
1764 | }; | ||
1765 | } | ||
1766 | |||
1767 | void QtRec::showListMenu(QListViewItem * item) { | ||
1768 | if(item == NULL) | ||
1769 | return; | ||
1770 | QPopupMenu *m = new QPopupMenu(this); | ||
1771 | m->insertItem( tr("Play"), this, SLOT( doMenuPlay() )); | ||
1772 | if(Ir::supported()) m->insertItem( tr( "Send with Ir" ), this, SLOT( doBeam() )); | ||
1773 | m->insertItem( tr( "Rename" ), this, SLOT( doRename() )); | ||
1774 | // #if defined (QTOPIA_INTERNAL_FSLP) | ||
1775 | // m->insertItem( tr( "Properties" ), this, SLOT( doProperties() )); | ||
1776 | // #endif | ||
1777 | m->insertSeparator(); | ||
1778 | m->insertItem( tr("Delete"), this, SLOT( deleteSound() ) ); | ||
1779 | m->exec( QCursor::pos() ); | ||
1780 | qApp->processEvents(); | ||
1781 | } | ||
1782 | |||
1783 | void QtRec::fileBeamFinished( Ir *ir) { | ||
1784 | if(ir) | ||
1785 | QMessageBox::message( tr("Ir Beam out"), tr("Ir sent.") ,tr("Ok") ); | ||
1786 | |||
1787 | } | ||
1788 | |||
1789 | void QtRec::doBeam() { | ||
1790 | qApp->processEvents(); | ||
1791 | if( ListView1->currentItem() == NULL) | ||
1792 | return; | ||
1793 | Ir ir; | ||
1794 | if( ir.supported()) { | ||
1795 | QString file = ListView1->currentItem()->text(0); | ||
1796 | Config cfg("QpeRec"); | ||
1797 | cfg.setGroup("Sounds"); | ||
1798 | |||
1799 | int nFiles = cfg.readNumEntry("NumberofFiles",0); | ||
1800 | |||
1801 | for(int i=0;i<nFiles+1;i++) { | ||
1802 | if( cfg.readEntry( QString::number(i),"").find(file,0,true) != -1) { | ||
1803 | QString filePath = cfg.readEntry(file,""); | ||
1804 | Ir *file = new Ir(this, "IR"); | ||
1805 | connect(file, SIGNAL(done(Ir*)), this, SLOT( fileBeamFinished( Ir * ))); | ||
1806 | file->send( filePath, "QpeRec audio file\n"+filePath ); | ||
1807 | } | ||
1808 | } | ||
1809 | } | ||
1810 | } | ||
1811 | |||
1812 | void QtRec::doMenuPlay() { | ||
1813 | qApp->processEvents(); | ||
1814 | currentFile = ListView1->currentItem()->text(0); | ||
1815 | } | ||
1816 | |||
1817 | void QtRec::doRename() { | ||
1818 | QRect r = ListView1->itemRect( ListView1->currentItem( )); | ||
1819 | r = QRect( ListView1->viewportToContents( r.topLeft() ), r.size() ); | ||
1820 | r.setX( ListView1->contentsX() ); | ||
1821 | if ( r.width() > ListView1->visibleWidth() ) | ||
1822 | r.setWidth( ListView1->visibleWidth() ); | ||
1823 | |||
1824 | renameBox = new QLineEdit( ListView1->viewport(), "qt_renamebox" ); | ||
1825 | renameBox->setFrame(true); | ||
1826 | |||
1827 | renameBox->setText( ListView1->currentItem()->text(0) ); | ||
1828 | |||
1829 | renameBox->selectAll(); | ||
1830 | renameBox->installEventFilter( this ); | ||
1831 | ListView1->addChild( renameBox, r.x(), r.y() ); | ||
1832 | renameBox->resize( r.size() ); | ||
1833 | ListView1->viewport()->setFocusProxy( renameBox ); | ||
1834 | renameBox->setFocus(); | ||
1835 | renameBox->show(); | ||
1836 | |||
1837 | } | ||
1838 | |||
1839 | void QtRec::okRename() { | ||
1840 | qDebug("okRename"); | ||
1841 | qDebug(renameBox->text()); | ||
1842 | QString filename = renameBox->text(); | ||
1843 | cancelRename(); | ||
1844 | |||
1845 | if( ListView1->currentItem() == NULL) | ||
1846 | return; | ||
1847 | |||
1848 | Config cfg("QpeRec"); | ||
1849 | cfg.setGroup("Sounds"); | ||
1850 | |||
1851 | QString file = ListView1->currentItem()->text(0); | ||
1852 | |||
1853 | qDebug("filename is " + filename); | ||
1854 | |||
1855 | int nFiles = cfg.readNumEntry("NumberofFiles",0); | ||
1856 | |||
1857 | for(int i=0;i<nFiles+1;i++) { //look for file | ||
1858 | if( cfg.readEntry( QString::number(i),"").find(file,0,true) != -1) { | ||
1859 | |||
1860 | QString filePath = cfg.readEntry(file,""); | ||
1861 | |||
1862 | cfg.writeEntry( QString::number(i), filename ); | ||
1863 | cfg.writeEntry( filename, filePath ); | ||
1864 | cfg.removeEntry(file); | ||
1865 | cfg.write(); | ||
1866 | } | ||
1867 | } | ||
1868 | |||
1869 | ListView1->takeItem( ListView1->currentItem() ); | ||
1870 | delete ListView1->currentItem(); | ||
1871 | ListView1->clear(); | ||
1872 | initIconView(); | ||
1873 | update(); | ||
1874 | } | ||
1875 | |||
1876 | void QtRec::cancelRename() { | ||
1877 | qDebug("cancel rename"); | ||
1878 | bool resetFocus = ListView1->viewport()->focusProxy() == renameBox; | ||
1879 | delete renameBox; | ||
1880 | renameBox = 0; | ||
1881 | if ( resetFocus ) { | ||
1882 | ListView1->viewport()->setFocusProxy( ListView1 ); | ||
1883 | ListView1->setFocus(); | ||
1884 | } | ||
1885 | } | ||
1886 | |||
1887 | bool QtRec::eventFilter( QObject * o, QEvent * e ) { | ||
1888 | if ( o->inherits( "QLineEdit" ) ) { | ||
1889 | if ( e->type() == QEvent::KeyPress ) { | ||
1890 | QKeyEvent *ke = (QKeyEvent*)e; | ||
1891 | if ( ke->key() == Key_Return || | ||
1892 | ke->key() == Key_Enter ) { | ||
1893 | okRename(); | ||
1894 | return true; | ||
1895 | } else if ( ke->key() == Key_Escape ) { | ||
1896 | cancelRename(); | ||
1897 | return true; | ||
1898 | } | ||
1899 | } else if ( e->type() == QEvent::FocusOut ) { | ||
1900 | cancelRename(); | ||
1901 | return true; | ||
1902 | } | ||
1903 | } | ||
1904 | return QWidget::eventFilter( o, e ); | ||
1905 | } | ||
1906 | |||
1907 | |||
1908 | int QtRec::getCurrentSizeLimit() { | ||
1909 | return sizeLimitCombo->currentItem() * 5; | ||
1910 | } | ||
1911 | |||
1912 | void QtRec::timerBreak() { | ||
1913 | qDebug("timer break"); | ||
1914 | stop(); | ||
1915 | } | ||
1916 | |||
1917 | void QtRec::doVolMuting(bool b) { | ||
1918 | Config cfg( "qpe" ); | ||
1919 | cfg. setGroup( "Volume" ); | ||
1920 | cfg.writeEntry( "Mute",b); | ||
1921 | cfg.write(); | ||
1922 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << b; | ||
1923 | } | ||
1924 | |||
1925 | void QtRec::doMicMuting(bool b) { | ||
1926 | // qDebug("mic mute"); | ||
1927 | Config cfg( "qpe" ); | ||
1928 | cfg. setGroup( "Volume" ); | ||
1929 | cfg.writeEntry( "MicMute",b); | ||
1930 | cfg.write(); | ||
1931 | QCopEnvelope( "QPE/System", "micChange(bool)" ) << b; | ||
1932 | } | ||
1933 | |||
1934 | void QtRec::compressionSelected(bool b) { | ||
1935 | Config cfg("QpeRec"); | ||
1936 | cfg.setGroup("Settings"); | ||
1937 | cfg.writeEntry("wavCompression", b); | ||
1938 | cfg.writeEntry("bitrate",16); filePara.resolution=16; | ||
1939 | cfg.write(); | ||
1940 | |||
1941 | if(b) { | ||
1942 | bitRateComboBox->setEnabled(false); | ||
1943 | bitRateComboBox->setCurrentItem(0); | ||
1944 | filePara.resolution=16; | ||
1945 | } else{ | ||
1946 | bitRateComboBox->setEnabled(true); | ||
1947 | } | ||
1948 | } | ||
1949 | |||
1950 | long QtRec::checkDiskSpace(const QString &path) { | ||
1951 | |||
1952 | struct statfs fs; | ||
1953 | |||
1954 | if ( !statfs( path.latin1(), &fs ) ) { | ||
1955 | |||
1956 | int blkSize = fs.f_bsize; | ||
1957 | int availBlks = fs.f_bavail; | ||
1958 | |||
1959 | long mult = blkSize / 1024; | ||
1960 | long div = 1024 / blkSize; | ||
1961 | |||
1962 | if ( !mult ) mult = 1; | ||
1963 | if ( !div ) div = 1; | ||
1964 | |||
1965 | return availBlks * mult / div; | ||
1966 | } | ||
1967 | return -1; | ||
1968 | } | ||
1969 | |||
1970 | // short f_fstyp; /* File system type */ | ||
1971 | // long f_bsize; /* Block size */ | ||
1972 | // long f_frsize; /* Fragment size */ | ||
1973 | // long f_blocks; /* Total number of blocks*/ | ||
1974 | // long f_bfree; /* Count of free blocks */ | ||
1975 | // long f_files; /* Total number of file nodes */ | ||
1976 | // long f_ffree; /* Count of free file nodes */ | ||
1977 | // char f_fname[6]; /* Volumename */ | ||
1978 | // char f_fpack[6]; /* Pack name */ | ||
1979 | |||
1980 | void QtRec::receive( const QCString &msg, const QByteArray & ) { | ||
1981 | qDebug("Voicerecord received message "+msg); | ||
1982 | |||
1983 | } | ||
1984 | |||
1985 | |||
1986 | ///////////////////////////// timerEvent | ||
1987 | void QtRec::timerEvent( QTimerEvent *e ) { | ||
1988 | // qDebug( "%d", secCount ); | ||
1989 | #ifdef DEV_VERSION | ||
1990 | QString msg; | ||
1991 | msg.sprintf("%d, %d, %d", filePara.sampleRate, filePara.channels, filePara.resolution); | ||
1992 | setCaption( msg +" :: "+QString::number(secCount)); | ||
1993 | #endif | ||
1994 | |||
1995 | if( !playing ) { | ||
1996 | if(!recording ){ | ||
1997 | killTimer(e->timerId()); | ||
1998 | ///* stopped=true; | ||
1999 | // recording=false; | ||
2000 | ///*/ | ||
2001 | // _exit( 0); | ||
2002 | } | ||
2003 | if(filePara.SecondsToRecord < secCount && filePara.SecondsToRecord !=0) { | ||
2004 | killTimer(e->timerId()); | ||
2005 | stop(); | ||
2006 | } | ||
2007 | } | ||
2008 | // if( stopped && !paused) { | ||
2009 | // if( filePara.numberOfRecordedSeconds < secCount) { | ||
2010 | // stopped = true; | ||
2011 | // // playing=false; | ||
2012 | // killTimer(e->timerId()); | ||
2013 | // endPlaying(); | ||
2014 | // } | ||
2015 | // } | ||
2016 | // qApp->processEvents(); | ||
2017 | secCount++; | ||
2018 | } | ||
2019 | |||
2020 | void QtRec::changeTimeSlider(int index) { | ||
2021 | if(ListView1->currentItem() == 0 || !wavFile->track.isOpen()) return; | ||
2022 | // qDebug("Slider moved to %d",index); | ||
2023 | paused = true; | ||
2024 | stopped = true; | ||
2025 | |||
2026 | sliderPos=index; | ||
2027 | |||
2028 | QString timeString; | ||
2029 | filePara.numberOfRecordedSeconds=(float)sliderPos/(float)filePara.sampleRate*(float)2; | ||
2030 | timeString.sprintf( "%.2f", filePara.numberOfRecordedSeconds); | ||
2031 | secCount = (int)filePara.numberOfRecordedSeconds; | ||
2032 | timeLabel->setText( timeString+ tr(" seconds")); | ||
2033 | } | ||
2034 | |||
2035 | void QtRec::timeSliderPressed() { | ||
2036 | if(ListView1->currentItem() == 0) return; | ||
2037 | // qDebug("slider pressed"); | ||
2038 | paused = true; | ||
2039 | stopped = true; | ||
2040 | } | ||
2041 | |||
2042 | void QtRec::timeSliderReleased() { | ||
2043 | if(ListView1->currentItem() == 0) return; | ||
2044 | sliderPos=timeSlider->value(); | ||
2045 | |||
2046 | // qDebug("slider released %d", sliderPos); | ||
2047 | stopped = false; | ||
2048 | int newPos = lseek( filePara.fd, sliderPos, SEEK_SET); | ||
2049 | total = newPos*4; | ||
2050 | filePara.numberOfRecordedSeconds=(float)sliderPos/(float)filePara.sampleRate*(float)2; | ||
2051 | |||
2052 | doPlay(); | ||
2053 | } | ||
2054 | |||
2055 | void QtRec::rewindPressed() { | ||
2056 | if(ListView1->currentItem() == 0) return; | ||
2057 | if( !wavFile->track.isOpen()) { | ||
2058 | if( !openPlayFile() ) | ||
2059 | return; | ||
2060 | else | ||
2061 | if( !setupAudio( false)) | ||
2062 | return; | ||
2063 | } else { | ||
2064 | killTimers(); | ||
2065 | paused = true; | ||
2066 | stopped = true; | ||
2067 | rewindTimer->start(50, false); | ||
2068 | } | ||
2069 | } | ||
2070 | |||
2071 | void QtRec::rewindTimerTimeout() { | ||
2072 | int sliderValue = timeSlider->value(); | ||
2073 | sliderValue = sliderValue-(filePara.numberSamples/100); | ||
2074 | // if(toBeginningButton->isDown()) | ||
2075 | timeSlider->setValue( sliderValue ) ; | ||
2076 | // qDebug("%d", sliderValue); | ||
2077 | QString timeString; | ||
2078 | filePara.numberOfRecordedSeconds=(float)sliderValue/(float)filePara.sampleRate*(float)2; | ||
2079 | timeString.sprintf( "%.2f", filePara.numberOfRecordedSeconds); | ||
2080 | timeLabel->setText( timeString+ tr(" seconds")); | ||
2081 | } | ||
2082 | |||
2083 | void QtRec::rewindReleased() { | ||
2084 | rewindTimer->stop(); | ||
2085 | if( wavFile->track.isOpen()) { | ||
2086 | sliderPos=timeSlider->value(); | ||
2087 | stopped = false; | ||
2088 | int newPos = lseek( filePara.fd, sliderPos, SEEK_SET); | ||
2089 | total = newPos*4; | ||
2090 | // qDebug("rewind released %d", total); | ||
2091 | startTimer(1000); | ||
2092 | doPlay(); | ||
2093 | } | ||
2094 | } | ||
2095 | |||
2096 | void QtRec::FastforwardPressed() { | ||
2097 | if(ListView1->currentItem() == 0) return; | ||
2098 | if( !wavFile->track.isOpen()) | ||
2099 | if( !openPlayFile() ) | ||
2100 | return; | ||
2101 | else | ||
2102 | if( !setupAudio( false)) | ||
2103 | return; | ||
2104 | killTimers(); | ||
2105 | |||
2106 | paused = true; | ||
2107 | stopped = true; | ||
2108 | forwardTimer->start(50, false); | ||
2109 | } | ||
2110 | |||
2111 | |||
2112 | void QtRec::forwardTimerTimeout() { | ||
2113 | int sliderValue = timeSlider->value(); | ||
2114 | sliderValue = sliderValue +(filePara.numberSamples/100); | ||
2115 | |||
2116 | // if(toEndButton->isDown()) | ||
2117 | timeSlider->setValue(sliderValue); | ||
2118 | |||
2119 | QString timeString; | ||
2120 | filePara.numberOfRecordedSeconds=(float)sliderValue/(float)filePara.sampleRate*(float)2; | ||
2121 | timeString.sprintf( "%.2f", filePara.numberOfRecordedSeconds); | ||
2122 | timeLabel->setText( timeString+ tr(" seconds")); | ||
2123 | } | ||
2124 | |||
2125 | void QtRec::FastforwardReleased() { | ||
2126 | forwardTimer->stop(); | ||
2127 | if( wavFile->track.isOpen()) { | ||
2128 | sliderPos=timeSlider->value(); | ||
2129 | stopped = false; | ||
2130 | int newPos = lseek( filePara.fd, sliderPos, SEEK_SET); | ||
2131 | total = newPos*4; | ||
2132 | filePara.numberOfRecordedSeconds=(float)sliderPos/(float)filePara.sampleRate*(float)2; | ||
2133 | startTimer(1000); | ||
2134 | doPlay(); | ||
2135 | } | ||
2136 | } | ||
2137 | |||
2138 | |||
2139 | QString QtRec::getStorage(const QString &fileName) { | ||
2140 | |||
2141 | StorageInfo storageInfo; | ||
2142 | const QList<FileSystem> &fs = storageInfo.fileSystems(); | ||
2143 | QListIterator<FileSystem> it ( fs ); | ||
2144 | QString storage; | ||
2145 | for( ; it.current(); ++it ){ | ||
2146 | const QString name = (*it)->name(); | ||
2147 | const QString path = (*it)->path(); | ||
2148 | const QString disk = (*it)->disk(); | ||
2149 | if( fileName.find(path,0,true) != -1) | ||
2150 | storage=name; | ||
2151 | // const QString options = (*it)->options(); | ||
2152 | // if( name.find( tr("Internal"),0,true) == -1) { | ||
2153 | // storageComboBox->insertItem( name +" -> "+disk); | ||
2154 | // qDebug(name); | ||
2155 | } | ||
2156 | return storage; | ||
2157 | // struct mntent *me; | ||
2158 | // // if(fileName == "/etc/mtab") { | ||
2159 | // FILE *mntfp = setmntent( fileName.latin1(), "r" ); | ||
2160 | // if ( mntfp ) { | ||
2161 | // while ( (me = getmntent( mntfp )) != 0 ) { | ||
2162 | // QString filesystemType = me->mnt_type; | ||
2163 | |||
2164 | // } | ||
2165 | // } | ||
2166 | // endmntent( mntfp ); | ||
2167 | } | ||
2168 | |||
2169 | void QtRec::setRecordButton(bool b) { | ||
2170 | |||
2171 | if(b) { //about to record or play | ||
2172 | |||
2173 | Rec_PushButton->setDown(true); | ||
2174 | QPixmap image3( ( const char** ) image3_data ); | ||
2175 | Stop_PushButton->setPixmap( image3 ); | ||
2176 | if(Stop_PushButton->isDown()) | ||
2177 | Stop_PushButton->setDown(true); | ||
2178 | playLabel2->setText("Stop"); | ||
2179 | |||
2180 | } else { //about to stop | ||
2181 | |||
2182 | QPixmap image4( ( const char** ) image4_data ); | ||
2183 | Stop_PushButton->setPixmap( image4); | ||
2184 | if(Stop_PushButton->isDown()) | ||
2185 | Stop_PushButton->setDown(false); | ||
2186 | playLabel2->setText("Play"); | ||
2187 | if(Rec_PushButton->isDown()) | ||
2188 | Rec_PushButton->setDown( false); | ||
2189 | } | ||
2190 | } | ||
2191 | |||
2192 | void QtRec::fillDirectoryCombo() { | ||
2193 | if( directoryComboBox->count() > 0) | ||
2194 | directoryComboBox->clear(); | ||
2195 | int index=0; | ||
2196 | Config cfg("QpeRec"); | ||
2197 | cfg.setGroup("Settings"); | ||
2198 | QString dir= cfg.readEntry("directory", "/"); | ||
2199 | StorageInfo storageInfo; | ||
2200 | const QList<FileSystem> &fs = storageInfo.fileSystems(); | ||
2201 | QListIterator<FileSystem> it ( fs ); | ||
2202 | QString storage; | ||
2203 | for( ; it.current(); ++it ){ | ||
2204 | const QString name = (*it)->name(); | ||
2205 | const QString path = (*it)->path(); | ||
2206 | // directoryComboBox->insertItem(name+" "+path); | ||
2207 | directoryComboBox->insertItem(name); | ||
2208 | if(path==dir) | ||
2209 | directoryComboBox->setCurrentItem(index); | ||
2210 | index++; | ||
2211 | } | ||
2212 | } | ||
2213 | |||
2214 | void QtRec::errorStop() { | ||
2215 | stopped = true; | ||
2216 | wavFile->closeFile(); | ||
2217 | killTimers(); | ||
2218 | } | ||
2219 | |||
2220 | void QtRec::doMute(bool b) { | ||
2221 | doVolMuting( b); | ||
2222 | doMicMuting( b); | ||
2223 | } | ||
2224 | |||
2225 | void QtRec::slotAutoMute(bool b) { | ||
2226 | autoMute=b; | ||
2227 | Config cfg("QpeRec"); | ||
2228 | cfg.setGroup("Settings"); | ||
2229 | cfg.writeEntry("useAutoMute",b); | ||
2230 | doMute(b); | ||
2231 | outMuteCheckBox->setChecked( b); | ||
2232 | inMuteCheckBox->setChecked( b); | ||
2233 | } | ||
2234 | |||
2235 | void QtRec::selectItemByName(const QString & name) { | ||
2236 | QListViewItemIterator it( ListView1 ); | ||
2237 | for ( ; it.current(); ++it ) | ||
2238 | if(name == it.current()->text(0)) | ||
2239 | ListView1->setCurrentItem(it.current()); | ||
2240 | } | ||
2241 | |||
2242 | |||
2243 | long findPeak(long input ) { | ||
2244 | |||
2245 | // halfLife = time in seconds for output to decay to half value after an impulse | ||
2246 | static float output = 0.0; | ||
2247 | int halfLife = .25; | ||
2248 | float vsf = .0025; | ||
2249 | float scalar = pow( 0.5, 1.0/(halfLife * filePara.sampleRate )); | ||
2250 | if( input < 0.0 ) | ||
2251 | input = -input; // Absolute value. | ||
2252 | if ( input >= output ) | ||
2253 | { | ||
2254 | // When we hit a peak, ride the peak to the top. | ||
2255 | output = input; | ||
2256 | } | ||
2257 | else | ||
2258 | { | ||
2259 | // Exponential decay of output when signal is low. | ||
2260 | output = output * scalar; | ||
2261 | // | ||
2262 | // When current gets close to 0.0, set current to 0.0 to prevent FP underflow | ||
2263 | // which can cause a severe performance degradation due to a flood | ||
2264 | // of interrupts. | ||
2265 | // | ||
2266 | if( output < vsf ) output = 0.0; | ||
2267 | } | ||
2268 | |||
2269 | return output; | ||
2270 | } | ||
diff --git a/noncore/multimedia/opierec/qtrec.h b/noncore/multimedia/opierec/qtrec.h new file mode 100644 index 0000000..d0623d0 --- a/dev/null +++ b/noncore/multimedia/opierec/qtrec.h | |||
@@ -0,0 +1,185 @@ | |||
1 | /**************************************************************************** | ||
2 | ** Created: Thu Jan 17 11:19:45 2002 | ||
3 | copyright 2002 by L.J. Potter ljp@llornkcor.com | ||
4 | ****************************************************************************/ | ||
5 | #ifndef QTREC_H | ||
6 | #define QTREC_H | ||
7 | #define VERSION 20021202 | ||
8 | |||
9 | #include <qpe/ir.h> | ||
10 | |||
11 | #include <iostream.h> | ||
12 | #include <qfile.h> | ||
13 | #include <qimage.h> | ||
14 | #include <qlineedit.h> | ||
15 | #include <qpixmap.h> | ||
16 | #include <qvariant.h> | ||
17 | #include <qwidget.h> | ||
18 | #include <stdio.h> | ||
19 | #include <stdlib.h> | ||
20 | |||
21 | #include "device.h" | ||
22 | #include "wavFile.h" | ||
23 | |||
24 | class QButtonGroup; | ||
25 | class QCheckBox; | ||
26 | class QComboBox; | ||
27 | class QGridLayout; | ||
28 | class QGroupBox; | ||
29 | class QHBoxLayout; | ||
30 | class QIconView; | ||
31 | class QIconViewItem; | ||
32 | class QLabel; | ||
33 | class QLabel; | ||
34 | class QListView; | ||
35 | class QListViewItem; | ||
36 | class QPushButton; | ||
37 | class QSlider; | ||
38 | class QTabWidget; | ||
39 | class QTimer; | ||
40 | class QVBoxLayout; | ||
41 | class QLineEdit; | ||
42 | |||
43 | #define MAX_TRACKS 2 | ||
44 | //#define BUFSIZE 4096 | ||
45 | // #define BUFSIZE 8182 //Z default buffer size | ||
46 | #define BUFSIZE 1024 | ||
47 | //#define BUFSIZE 2048 | ||
48 | #define FRAGSIZE 0x7fff000A; | ||
49 | |||
50 | #define WAVE_FORMAT_DVI_ADPCM (0x0011) | ||
51 | #define WAVE_FORMAT_PCM (0x0001) | ||
52 | //AFMT_IMA_ADPCM | ||
53 | |||
54 | class QtRec : public QWidget | ||
55 | { | ||
56 | Q_OBJECT | ||
57 | |||
58 | public: | ||
59 | QtRec( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); | ||
60 | ~QtRec(); | ||
61 | QSlider *OutputSlider,*InputSlider; | ||
62 | |||
63 | public slots: | ||
64 | private: | ||
65 | // int fragment; | ||
66 | int fd1; | ||
67 | int secCount; | ||
68 | QString timeString; | ||
69 | |||
70 | QLineEdit *renameBox; | ||
71 | QGroupBox* GroupBox1; | ||
72 | QString currentFile; | ||
73 | QString date, currentFileName, tmpFileName; | ||
74 | QTimer *t_timer; | ||
75 | bool needsStereoOut, paused, playing; | ||
76 | bool useTmpFile, autoMute; | ||
77 | |||
78 | bool eventFilter( QObject * , QEvent * ); | ||
79 | void okRename(); | ||
80 | void cancelRename(); | ||
81 | QString getStorage(const QString &); | ||
82 | bool rec(); | ||
83 | int getCurrentSizeLimit(); | ||
84 | long checkDiskSpace(const QString &); | ||
85 | void doMute(bool); | ||
86 | void errorStop(); | ||
87 | void fillDirectoryCombo(); | ||
88 | void getInVol(); | ||
89 | void getOutVol(); | ||
90 | void init(); | ||
91 | void initConfig(); | ||
92 | void initConnections(); | ||
93 | void selectItemByName(const QString &); | ||
94 | void setRecordButton(bool); | ||
95 | void start(); | ||
96 | void stop(); | ||
97 | void timerEvent( QTimerEvent *e ); | ||
98 | |||
99 | private slots: | ||
100 | |||
101 | |||
102 | void FastforwardPressed(); | ||
103 | void FastforwardReleased(); | ||
104 | void changeDirCombo(int); | ||
105 | void changeSizeLimitCombo(int); | ||
106 | void changeTimeSlider(int); | ||
107 | void changebitrateCombo(int); | ||
108 | void changedInVolume(); | ||
109 | void changedOutVolume(); | ||
110 | void changesamplerateCombo(int); | ||
111 | void cleanUp(); | ||
112 | void compressionSelected(bool); | ||
113 | void deleteSound(); | ||
114 | void doBeam(); | ||
115 | void doMenuPlay(); | ||
116 | void doMicMuting(bool); | ||
117 | void doPlayBtn(); | ||
118 | void doRename(); | ||
119 | void doVolMuting(bool); | ||
120 | void forwardTimerTimeout(); | ||
121 | void itClick(QListViewItem *item); | ||
122 | void listPressed(int, QListViewItem *, const QPoint&, int); | ||
123 | void newSound(); | ||
124 | void rewindPressed(); | ||
125 | void rewindReleased(); | ||
126 | void rewindTimerTimeout(); | ||
127 | void slotAutoMute(bool); | ||
128 | void thisTab(QWidget*); | ||
129 | void timeSliderPressed(); | ||
130 | void timeSliderReleased(); | ||
131 | void timerBreak(); | ||
132 | /* void changedOutVolume(int); */ | ||
133 | /* void changedInVolume(int); */ | ||
134 | |||
135 | protected: | ||
136 | |||
137 | Device *soundDevice; | ||
138 | WavFile *wavFile; | ||
139 | |||
140 | QButtonGroup *ButtonGroup1; | ||
141 | QCheckBox *outMuteCheckBox, *inMuteCheckBox, *compressionCheckBox, *autoMuteCheckBox; | ||
142 | QComboBox* sampleRateComboBox, * bitRateComboBox, *directoryComboBox, *sizeLimitCombo; | ||
143 | QHBoxLayout* Layout12; | ||
144 | QHBoxLayout* Layout13; | ||
145 | QHBoxLayout* Layout14; | ||
146 | QHBoxLayout* Layout16; | ||
147 | QHBoxLayout* Layout17; | ||
148 | QHBoxLayout* Layout19; | ||
149 | QIconView *IconView1; | ||
150 | QLabel *NewSoundLabel,*playLabel2; | ||
151 | QLabel *TextLabel3, *TextLabel1, *TextLabel2; | ||
152 | QListView *ListView1; | ||
153 | QPushButton *Stop_PushButton, *Play_PushButton, *Rec_PushButton, *NewSoundButton, *deleteSoundButton, *toBeginningButton, *toEndButton; | ||
154 | QString recDir; | ||
155 | QTabWidget *TabWidget; | ||
156 | QTimer *t, *rewindTimer, *forwardTimer; | ||
157 | QVBoxLayout* Layout15; | ||
158 | QVBoxLayout* Layout15b; | ||
159 | QVBoxLayout* Layout18; | ||
160 | QWidget *tab, *tab_2, *tab_3, *tab_4, *tab_5; | ||
161 | int sliderPos, total; | ||
162 | // short inbuffer[BUFSIZE], outbuffer[BUFSIZE]; | ||
163 | // unsigned short unsigned_inbuffer[BUFSIZE], unsigned_outbuffer[BUFSIZE]; | ||
164 | QGroupBox *sampleGroup, *bitGroup, *dirGroup, *sizeGroup; | ||
165 | /* short inbuffer[65536], outbuffer[65536]; */ | ||
166 | /* unsigned short unsigned_inbuffer[65536], unsigned_outbuffer[65536]; */ | ||
167 | |||
168 | |||
169 | bool doPlay(); | ||
170 | bool openPlayFile(); | ||
171 | bool setUpFile(); | ||
172 | bool setupAudio( bool b); | ||
173 | void endPlaying(); | ||
174 | void endRecording(); | ||
175 | void fileBeamFinished( Ir *ir); | ||
176 | void initIconView(); | ||
177 | void keyPressEvent( QKeyEvent *e); | ||
178 | void keyReleaseEvent( QKeyEvent *e); | ||
179 | void receive( const QCString &, const QByteArray & ); | ||
180 | void showListMenu(QListViewItem * ); | ||
181 | // void quickRec(); | ||
182 | |||
183 | }; | ||
184 | |||
185 | #endif // QTREC_H | ||
diff --git a/noncore/multimedia/opierec/wavFile.cpp b/noncore/multimedia/opierec/wavFile.cpp new file mode 100644 index 0000000..09695aa --- a/dev/null +++ b/noncore/multimedia/opierec/wavFile.cpp | |||
@@ -0,0 +1,303 @@ | |||
1 | //wavFile.cpp | ||
2 | #include "wavFile.h" | ||
3 | #include "qtrec.h" | ||
4 | |||
5 | #include <qdatetime.h> | ||
6 | #include <qstring.h> | ||
7 | #include <qmessagebox.h> | ||
8 | #include <qdir.h> | ||
9 | |||
10 | #include <qpe/timestring.h> | ||
11 | #include <qpe/config.h> | ||
12 | |||
13 | #include <errno.h> | ||
14 | |||
15 | #include <sys/time.h> | ||
16 | #include <sys/types.h> | ||
17 | #include <sys/vfs.h> | ||
18 | |||
19 | #include <fcntl.h> | ||
20 | #include <math.h> | ||
21 | #include <mntent.h> | ||
22 | #include <stdio.h> | ||
23 | #include <stdlib.h> | ||
24 | #include <unistd.h> | ||
25 | |||
26 | WavFile::WavFile( QObject * parent,const QString &fileName, bool makeNwFile, int sampleRate, | ||
27 | int channels, int resolution, int format ) | ||
28 | : QObject( parent) | ||
29 | { | ||
30 | qDebug("new wave file"); | ||
31 | bool b = makeNwFile; | ||
32 | wavSampleRate=sampleRate; | ||
33 | wavFormat=format; | ||
34 | wavChannels=channels; | ||
35 | wavResolution=resolution; | ||
36 | useTmpFile=false; | ||
37 | if( b) { | ||
38 | newFile(); | ||
39 | } else { | ||
40 | openFile(fileName); | ||
41 | } | ||
42 | } | ||
43 | |||
44 | bool WavFile::newFile() { | ||
45 | |||
46 | qDebug("Set up new file"); | ||
47 | Config cfg("QpeRec"); | ||
48 | cfg.setGroup("Settings"); | ||
49 | |||
50 | currentFileName=cfg.readEntry("directory",QDir::homeDirPath()); | ||
51 | QString date; | ||
52 | date = TimeString::dateString( QDateTime::currentDateTime(),false,true); | ||
53 | date.replace(QRegExp("'"),""); | ||
54 | date.replace(QRegExp(" "),"_"); | ||
55 | date.replace(QRegExp(":"),"."); | ||
56 | date.replace(QRegExp(","),""); | ||
57 | |||
58 | QString currentFile=date; | ||
59 | if(currentFileName.right(1).find("/",0,true) == -1) | ||
60 | currentFileName += "/" + date; | ||
61 | else | ||
62 | currentFileName += date; | ||
63 | currentFileName+=".wav"; | ||
64 | |||
65 | qDebug("set up file for recording: "+currentFileName); | ||
66 | char *pointer; | ||
67 | |||
68 | if( currentFileName.find("/mnt",0,true) == -1 | ||
69 | && currentFileName.find("/tmp",0,true) == -1 ) { | ||
70 | // if destination file is most likely in flash (assuming jffs2) | ||
71 | // we have to write to a different filesystem first | ||
72 | |||
73 | useTmpFile = true; | ||
74 | pointer=tmpnam(NULL); | ||
75 | qDebug("Opening tmp file %s",pointer); | ||
76 | track.setName( pointer); | ||
77 | |||
78 | } else { //just use regular file.. no moving | ||
79 | |||
80 | useTmpFile = false; | ||
81 | track.setName( currentFileName); | ||
82 | } | ||
83 | if(!track.open( IO_ReadWrite | IO_Truncate)) { | ||
84 | QString errorMsg=(QString)strerror(errno); | ||
85 | qDebug(errorMsg); | ||
86 | QMessageBox::message("Note", "Error opening file.\n" +errorMsg); | ||
87 | |||
88 | return false; | ||
89 | } else { | ||
90 | setWavHeader( track.handle() , &hdr); | ||
91 | } | ||
92 | return true; | ||
93 | } | ||
94 | |||
95 | WavFile::~WavFile() { | ||
96 | |||
97 | closeFile(); | ||
98 | } | ||
99 | |||
100 | void WavFile::closeFile() { | ||
101 | if(track.isOpen()) | ||
102 | track.close(); | ||
103 | } | ||
104 | |||
105 | int WavFile::openFile(const QString ¤tFileName) { | ||
106 | qDebug("open play file "+currentFileName); | ||
107 | closeFile(); | ||
108 | |||
109 | track.setName(currentFileName); | ||
110 | |||
111 | if(!track.open(IO_ReadOnly)) { | ||
112 | QString errorMsg=(QString)strerror(errno); | ||
113 | qDebug("<<<<<<<<<<< "+errorMsg+currentFileName); | ||
114 | QMessageBox::message("Note", "Error opening file.\n" +errorMsg); | ||
115 | return -1; | ||
116 | } else { | ||
117 | parseWavHeader( track.handle()); | ||
118 | } | ||
119 | return track.handle(); | ||
120 | } | ||
121 | |||
122 | bool WavFile::setWavHeader(int fd, wavhdr *hdr) { | ||
123 | |||
124 | strncpy((*hdr).riffID, "RIFF", 4); // RIFF | ||
125 | strncpy((*hdr).wavID, "WAVE", 4); //WAVE | ||
126 | strncpy((*hdr).fmtID, "fmt ", 4); // fmt | ||
127 | (*hdr).fmtLen = 16; // format length = 16 | ||
128 | |||
129 | if( wavFormat == WAVE_FORMAT_PCM) { | ||
130 | (*hdr).fmtTag = 1; // PCM | ||
131 | qDebug("set header WAVE_FORMAT_PCM"); | ||
132 | } | ||
133 | else { | ||
134 | (*hdr).fmtTag = WAVE_FORMAT_DVI_ADPCM; //intel ADPCM | ||
135 | qDebug("set header WAVE_FORMAT_DVI_ADPCM"); | ||
136 | } | ||
137 | |||
138 | // (*hdr).nChannels = 1;//filePara.channels;// ? 2 : 1*/; // channels | ||
139 | (*hdr).nChannels = wavChannels;// ? 2 : 1*/; // channels | ||
140 | |||
141 | (*hdr).sampleRate = wavSampleRate; //samples per second | ||
142 | (*hdr).avgBytesPerSec = (wavSampleRate)*( wavChannels*(wavResolution/8)); // bytes per second | ||
143 | (*hdr).nBlockAlign = wavChannels*( wavResolution/8); //block align | ||
144 | (*hdr).bitsPerSample = wavResolution; //bits per sample 8, or 16 | ||
145 | |||
146 | strncpy((*hdr).dataID, "data", 4); | ||
147 | |||
148 | write( fd,hdr, sizeof(*hdr)); | ||
149 | qDebug("writing header: bitrate%d, samplerate %d, channels %d", | ||
150 | wavResolution, wavSampleRate, wavChannels); | ||
151 | return true; | ||
152 | } | ||
153 | |||
154 | bool WavFile::adjustHeaders(int fd, int total) { | ||
155 | lseek(fd, 4, SEEK_SET); | ||
156 | int i = total + 36; | ||
157 | write( fd, &i, sizeof(i)); | ||
158 | lseek( fd, 40, SEEK_SET); | ||
159 | write( fd, &total, sizeof(total)); | ||
160 | qDebug("adjusting header %d", total); | ||
161 | return true; | ||
162 | } | ||
163 | |||
164 | int WavFile::parseWavHeader(int fd) { | ||
165 | qDebug("Parsing wav header"); | ||
166 | char string[4]; | ||
167 | int found; | ||
168 | short fmt; | ||
169 | unsigned short ch, bitrate; | ||
170 | unsigned long samplerrate, longdata; | ||
171 | |||
172 | if (read(fd, string, 4) < 4) { | ||
173 | qDebug(" Could not read from sound file.\n"); | ||
174 | return -1; | ||
175 | } | ||
176 | if (strncmp(string, "RIFF", 4)) { | ||
177 | qDebug(" not a valid WAV file.\n"); | ||
178 | return -1; | ||
179 | } | ||
180 | lseek(fd, 4, SEEK_CUR); | ||
181 | if (read(fd, string, 4) < 4) { | ||
182 | qDebug("Could not read from sound file.\n"); | ||
183 | return -1; | ||
184 | } | ||
185 | if (strncmp(string, "WAVE", 4)) { | ||
186 | qDebug("not a valid WAV file.\n"); | ||
187 | return -1; | ||
188 | } | ||
189 | found = 0; | ||
190 | |||
191 | while (!found) { | ||
192 | if (read(fd, string, 4) < 4) { | ||
193 | qDebug("Could not read from sound file.\n"); | ||
194 | return -1; | ||
195 | } | ||
196 | if (strncmp(string, "fmt ", 4)) { | ||
197 | if (read(fd, &longdata, 4) < 4) { | ||
198 | qDebug("Could not read from sound file.\n"); | ||
199 | return -1; | ||
200 | } | ||
201 | lseek(fd, longdata, SEEK_CUR); | ||
202 | } else { | ||
203 | lseek(fd, 4, SEEK_CUR); | ||
204 | if (read(fd, &fmt, 2) < 2) { | ||
205 | qDebug("Could not read format chunk.\n"); | ||
206 | return -1; | ||
207 | } | ||
208 | if (fmt != WAVE_FORMAT_PCM && fmt != WAVE_FORMAT_DVI_ADPCM) { | ||
209 | qDebug("Wave file contains unknown format." | ||
210 | " Unable to continue.\n"); | ||
211 | return -1; | ||
212 | } | ||
213 | wavFormat = fmt; | ||
214 | // compressionFormat=fmt; | ||
215 | qDebug("compressionFormat is %d", fmt); | ||
216 | if (read(fd, &ch, 2) < 2) { | ||
217 | qDebug("Could not read format chunk.\n"); | ||
218 | return -1; | ||
219 | } else { | ||
220 | wavChannels = ch; | ||
221 | qDebug("File has %d channels", ch); | ||
222 | } | ||
223 | if (read(fd, &samplerrate, 4) < 4) { | ||
224 | qDebug("Could not read from format chunk.\n"); | ||
225 | return -1; | ||
226 | } else { | ||
227 | wavSampleRate = samplerrate; | ||
228 | // sampleRate = samplerrate; | ||
229 | qDebug("File has samplerate of %d",(int) samplerrate); | ||
230 | } | ||
231 | lseek(fd, 6, SEEK_CUR); | ||
232 | if (read(fd, &bitrate, 2) < 2) { | ||
233 | qDebug("Could not read format chunk.\n"); | ||
234 | return -1; | ||
235 | } else { | ||
236 | wavResolution=bitrate; | ||
237 | // resolution = bitrate; | ||
238 | qDebug("File has bitrate of %d", bitrate); | ||
239 | } | ||
240 | found++; | ||
241 | } | ||
242 | } | ||
243 | found = 0; | ||
244 | while (!found) { | ||
245 | if (read(fd, string, 4) < 4) { | ||
246 | qDebug("Could not read from sound file.\n"); | ||
247 | return -1; | ||
248 | } | ||
249 | |||
250 | if (strncmp(string, "data", 4)) { | ||
251 | if (read(fd, &longdata, 4)<4) { | ||
252 | qDebug("Could not read from sound file.\n"); | ||
253 | return -1; | ||
254 | } | ||
255 | |||
256 | lseek(fd, longdata, SEEK_CUR); | ||
257 | } else { | ||
258 | if (read(fd, &longdata, 4) < 4) { | ||
259 | qDebug("Could not read from sound file.\n"); | ||
260 | return -1; | ||
261 | } else { | ||
262 | wavNumberSamples = longdata; | ||
263 | qDebug("file has length of %d \nlasting %d seconds", longdata, | ||
264 | (( longdata / wavSampleRate) / wavChannels) / ( wavChannels*( wavResolution/8)) ); | ||
265 | // wavSeconds = (( longdata / wavSampleRate) / wavChannels) / ( wavChannels*( wavResolution/8)); | ||
266 | |||
267 | return longdata; | ||
268 | } | ||
269 | } | ||
270 | } | ||
271 | |||
272 | lseek(fd, 0, SEEK_SET); | ||
273 | |||
274 | return 0; | ||
275 | } | ||
276 | |||
277 | QString WavFile::trackName() { | ||
278 | return track.name(); | ||
279 | } | ||
280 | |||
281 | int WavFile::wavHandle(){ | ||
282 | return track.handle(); | ||
283 | } | ||
284 | |||
285 | int WavFile::getFormat() { | ||
286 | return wavFormat; | ||
287 | } | ||
288 | |||
289 | int WavFile::getResolution() { | ||
290 | return wavResolution; | ||
291 | } | ||
292 | |||
293 | int WavFile::getSampleRate() { | ||
294 | return wavSampleRate; | ||
295 | } | ||
296 | |||
297 | int WavFile::getNumberSamples() { | ||
298 | return wavNumberSamples; | ||
299 | } | ||
300 | |||
301 | bool WavFile::isTempFile() { | ||
302 | return useTmpFile; | ||
303 | } | ||
diff --git a/noncore/multimedia/opierec/wavFile.h b/noncore/multimedia/opierec/wavFile.h new file mode 100644 index 0000000..51366ec --- a/dev/null +++ b/noncore/multimedia/opierec/wavFile.h | |||
@@ -0,0 +1,56 @@ | |||
1 | //wavFile.h | ||
2 | #ifndef WAVFILE_H | ||
3 | #define WAVFILE_H | ||
4 | |||
5 | #include <qobject.h> | ||
6 | #include <sys/soundcard.h> | ||
7 | #include <qfile.h> | ||
8 | #include <qstring.h> | ||
9 | |||
10 | typedef struct { | ||
11 | char riffID[4]; | ||
12 | unsigned long riffLen; | ||
13 | char wavID[4]; | ||
14 | char fmtID[4]; | ||
15 | unsigned long fmtLen; | ||
16 | unsigned short fmtTag; | ||
17 | unsigned short nChannels; | ||
18 | unsigned long sampleRate; | ||
19 | unsigned long avgBytesPerSec; | ||
20 | unsigned short nBlockAlign; | ||
21 | unsigned short bitsPerSample; | ||
22 | char dataID[4]; | ||
23 | unsigned long dataLen; | ||
24 | } wavhdr; | ||
25 | |||
26 | |||
27 | class WavFile : public QObject { | ||
28 | Q_OBJECT | ||
29 | public: | ||
30 | WavFile( QObject * parent=0,const QString &fileName=0, bool newFile=true, int sampleRate = 0, | ||
31 | int channels = 0, int resolution = 0, int format=0); | ||
32 | ~WavFile(); | ||
33 | wavhdr hdr; | ||
34 | bool adjustHeaders(int fd, int total); | ||
35 | QString currentFileName; | ||
36 | QString trackName(); | ||
37 | |||
38 | QFile track; | ||
39 | int wavHandle(); | ||
40 | int getFormat(); | ||
41 | int getResolution(); | ||
42 | int getSampleRate(); | ||
43 | int getNumberSamples(); | ||
44 | bool isTempFile(); | ||
45 | int openFile(const QString &); | ||
46 | bool newFile(); | ||
47 | void closeFile(); | ||
48 | |||
49 | private: | ||
50 | int wavFormat, wavChannels, wavResolution, wavSampleRate, wavNumberSamples; | ||
51 | bool useTmpFile; | ||
52 | bool setWavHeader(int fd, wavhdr *hdr); | ||
53 | int parseWavHeader(int fd); | ||
54 | }; | ||
55 | |||
56 | #endif | ||