author | llornkcor <llornkcor> | 2002-07-24 15:18:26 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-07-24 15:18:26 (UTC) |
commit | 9e126f7ed2f73b26ef440c1cc54d0dc0e6308f68 (patch) (unidiff) | |
tree | e118086859eb8bee05bf39bbb8d7c2442c785547 | |
parent | 919228ff6aeb72b6d2585ae108e86d27d0b6bdb1 (diff) | |
download | opie-9e126f7ed2f73b26ef440c1cc54d0dc0e6308f68.zip opie-9e126f7ed2f73b26ef440c1cc54d0dc0e6308f68.tar.gz opie-9e126f7ed2f73b26ef440c1cc54d0dc0e6308f68.tar.bz2 |
added adpcm hidden config, and fixed tmp file moving before recording.. heh
-rw-r--r-- | core/applets/vmemo/adpcm.c | 252 | ||||
-rw-r--r-- | core/applets/vmemo/adpcm.h | 19 | ||||
-rw-r--r-- | core/applets/vmemo/vmemo.cpp | 150 | ||||
-rw-r--r-- | core/applets/vmemo/vmemo.h | 2 | ||||
-rw-r--r-- | core/applets/vmemo/vmemo.pro | 40 |
5 files changed, 350 insertions, 113 deletions
diff --git a/core/applets/vmemo/adpcm.c b/core/applets/vmemo/adpcm.c new file mode 100644 index 0000000..c4dfa50 --- a/dev/null +++ b/core/applets/vmemo/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; /* 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; /* place to keep next 4-bit value */ | ||
191 | int bufferstep; /* 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/core/applets/vmemo/adpcm.h b/core/applets/vmemo/adpcm.h new file mode 100644 index 0000000..9c17ffa --- a/dev/null +++ b/core/applets/vmemo/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/core/applets/vmemo/vmemo.cpp b/core/applets/vmemo/vmemo.cpp index b77e3b8..b5239eb 100644 --- a/core/applets/vmemo/vmemo.cpp +++ b/core/applets/vmemo/vmemo.cpp | |||
@@ -1,107 +1,118 @@ | |||
1 | /************************************************************************************ | 1 | /************************************************************************************ |
2 | ** | 2 | ** |
3 | ** This file may be distributed and/or modified under the terms of the | 3 | ** This file may be distributed and/or modified under the terms of the |
4 | ** GNU General Public License version 2 as published by the Free Software | 4 | ** GNU General Public License version 2 as published by the Free Software |
5 | ** Foundation and appearing in the file LICENSE.GPL included in the | 5 | ** Foundation and appearing in the file LICENSE.GPL included in the |
6 | ** packaging of this file. | 6 | ** packaging of this file. |
7 | ** | 7 | ** |
8 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 8 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
9 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 9 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
10 | ** | 10 | ** |
11 | ************************************************************************************/ | 11 | ************************************************************************************/ |
12 | // copyright 2002 Jeremy Cowgar <jc@cowgar.com> | 12 | // copyright 2002 Jeremy Cowgar <jc@cowgar.com> |
13 | /* | 13 | /* |
14 | * $Id$ | 14 | * $Id$ |
15 | */ | 15 | */ |
16 | // Sun 03-17-2002 L.J.Potter <ljp@llornkcor.com> | 16 | // Sun 03-17-2002 L.J.Potter <ljp@llornkcor.com> |
17 | extern "C" { | ||
18 | #include "adpcm.h" | ||
19 | } | ||
20 | |||
17 | #include <sys/utsname.h> | 21 | #include <sys/utsname.h> |
18 | #include <sys/time.h> | 22 | #include <sys/time.h> |
19 | #include <sys/types.h> | 23 | #include <sys/types.h> |
20 | #include <unistd.h> | 24 | #include <unistd.h> |
21 | #include <stdio.h> | 25 | #include <stdio.h> |
22 | #include <sys/stat.h> | 26 | #include <sys/stat.h> |
23 | #include <fcntl.h> | 27 | #include <fcntl.h> |
24 | #include <sys/ioctl.h> | 28 | #include <sys/ioctl.h> |
25 | #include <linux/soundcard.h> | 29 | #include <linux/soundcard.h> |
26 | 30 | ||
27 | #include <string.h> | 31 | #include <string.h> |
28 | #include <stdlib.h> | 32 | #include <stdlib.h> |
29 | #include <errno.h> | 33 | #include <errno.h> |
30 | #include <qtimer.h> | 34 | #include <qtimer.h> |
31 | 35 | ||
32 | typedef struct _waveheader { | 36 | typedef struct _waveheader { |
33 | u_long main_chunk; /* 'RIFF' */ | 37 | u_long main_chunk; /* 'RIFF' */ |
34 | u_long length; /* filelen */ | 38 | u_long length; /* filelen */ |
35 | u_long chunk_type; /* 'WAVE' */ | 39 | u_long chunk_type; /* 'WAVE' */ |
36 | u_long sub_chunk; /* 'fmt ' */ | 40 | u_long sub_chunk; /* 'fmt ' */ |
37 | u_long sc_len; /* length of sub_chunk, =16 | 41 | u_long sc_len; /* length of sub_chunk, =16 |
38 | (chunckSize) format len */ | 42 | (chunckSize) format len */ |
39 | u_short format; /* should be 1 for PCM-code (formatTag) */ | 43 | u_short format; /* should be 1 for PCM-code (formatTag) */ |
40 | 44 | ||
41 | u_short modus; /* 1 Mono, 2 Stereo (channels) */ | 45 | u_short modus; /* 1 Mono, 2 Stereo (channels) */ |
42 | u_long sample_fq; /* samples per second (samplesPerSecond) */ | 46 | u_long sample_fq; /* samples per second (samplesPerSecond) */ |
43 | u_long byte_p_sec; /* avg bytes per second (avgBytePerSecond) */ | 47 | u_long byte_p_sec; /* avg bytes per second (avgBytePerSecond) */ |
44 | u_short byte_p_spl; /* samplesize; 1 or 2 bytes (blockAlign) */ | 48 | u_short byte_p_spl; /* samplesize; 1 or 2 bytes (blockAlign) */ |
45 | u_short bit_p_spl; /* 8, 12 or 16 bit (bitsPerSample) */ | 49 | u_short bit_p_spl; /* 8, 12 or 16 bit (bitsPerSample) */ |
46 | 50 | ||
47 | u_long data_chunk; /* 'data' */ | 51 | u_long data_chunk; /* 'data' */ |
48 | 52 | ||
49 | u_long data_length;/* samplecount */ | 53 | u_long data_length;/* samplecount */ |
50 | } WaveHeader; | 54 | } WaveHeader; |
51 | 55 | ||
52 | #define RIFF 0x46464952 | 56 | #define RIFF 0x46464952 |
53 | #define WAVE 0x45564157 | 57 | #define WAVE 0x45564157 |
54 | #define FMT 0x20746D66 | 58 | #define FMT 0x20746D66 |
55 | #define DATA 0x61746164 | 59 | #define DATA 0x61746164 |
56 | #define PCM_CODE 1 | 60 | #define PCM_CODE 1 |
57 | #define WAVE_MONO 1 | 61 | #define WAVE_MONO 1 |
58 | #define WAVE_STEREO 2 | 62 | #define WAVE_STEREO 2 |
59 | 63 | ||
64 | struct adpcm_state encoder_state; | ||
65 | //struct adpcm_state decoder_state; | ||
66 | |||
67 | #define WAVE_FORMAT_DVI_ADPCM (0x0011) | ||
68 | #define WAVE_FORMAT_PCM (0x0001) | ||
69 | |||
70 | |||
60 | #include "vmemo.h" | 71 | #include "vmemo.h" |
61 | 72 | ||
62 | #include <qpe/qpeapplication.h> | 73 | #include <qpe/qpeapplication.h> |
63 | #include <qpe/resource.h> | 74 | #include <qpe/resource.h> |
64 | #include <qpe/config.h> | 75 | #include <qpe/config.h> |
65 | 76 | ||
66 | #include <qpainter.h> | 77 | #include <qpainter.h> |
67 | #include <qdatetime.h> | 78 | #include <qdatetime.h> |
68 | #include <qregexp.h> | 79 | #include <qregexp.h> |
69 | #include <qsound.h> | 80 | #include <qsound.h> |
70 | #include <qfile.h> | 81 | #include <qfile.h> |
71 | #include <qmessagebox.h> | 82 | #include <qmessagebox.h> |
72 | 83 | ||
73 | int seq = 0; | 84 | int seq = 0; |
74 | 85 | ||
75 | /* XPM */ | 86 | /* XPM */ |
76 | static char * vmemo_xpm[] = { | 87 | static char * vmemo_xpm[] = { |
77 | "16 16 102 2", | 88 | "16 16 102 2", |
78 | " c None", | 89 | " c None", |
79 | ". c #60636A", | 90 | ". c #60636A", |
80 | "+ c #6E6E72", | 91 | "+ c #6E6E72", |
81 | "@ c #68696E", | 92 | "@ c #68696E", |
82 | "# c #4D525C", | 93 | "# c #4D525C", |
83 | "$ c #6B6C70", | 94 | "$ c #6B6C70", |
84 | "% c #E3E3E8", | 95 | "% c #E3E3E8", |
85 | "& c #EEEEF2", | 96 | "& c #EEEEF2", |
86 | "* c #EAEAEF", | 97 | "* c #EAEAEF", |
87 | "= c #CACAD0", | 98 | "= c #CACAD0", |
88 | "- c #474A51", | 99 | "- c #474A51", |
89 | "; c #171819", | 100 | "; c #171819", |
90 | "> c #9B9B9F", | 101 | "> c #9B9B9F", |
91 | ", c #EBEBF0", | 102 | ", c #EBEBF0", |
92 | "' c #F4F4F7", | 103 | "' c #F4F4F7", |
93 | ") c #F1F1F5", | 104 | ") c #F1F1F5", |
94 | "! c #DEDEE4", | 105 | "! c #DEDEE4", |
95 | "~ c #57575C", | 106 | "~ c #57575C", |
96 | "{ c #010101", | 107 | "{ c #010101", |
97 | "] c #A2A2A6", | 108 | "] c #A2A2A6", |
98 | "^ c #747477", | 109 | "^ c #747477", |
99 | "/ c #B5B5B8", | 110 | "/ c #B5B5B8", |
100 | "( c #AEAEB2", | 111 | "( c #AEAEB2", |
101 | "_ c #69696D", | 112 | "_ c #69696D", |
102 | ": c #525256", | 113 | ": c #525256", |
103 | "< c #181C24", | 114 | "< c #181C24", |
104 | "[ c #97979B", | 115 | "[ c #97979B", |
105 | "} c #A7A7AC", | 116 | "} c #A7A7AC", |
106 | "| c #B0B0B4", | 117 | "| c #B0B0B4", |
107 | "1 c #C8C8D1", | 118 | "1 c #C8C8D1", |
@@ -151,501 +162,456 @@ static char * vmemo_xpm[] = { | |||
151 | "I c #BBBBC3", | 162 | "I c #BBBBC3", |
152 | "J c #C4C4CB", | 163 | "J c #C4C4CB", |
153 | "K c #909098", | 164 | "K c #909098", |
154 | "L c #737379", | 165 | "L c #737379", |
155 | "M c #343437", | 166 | "M c #343437", |
156 | "N c #8F8F98", | 167 | "N c #8F8F98", |
157 | "O c #000407", | 168 | "O c #000407", |
158 | "P c #2D3137", | 169 | "P c #2D3137", |
159 | "Q c #B0B1BC", | 170 | "Q c #B0B1BC", |
160 | "R c #3B3C40", | 171 | "R c #3B3C40", |
161 | "S c #6E6E74", | 172 | "S c #6E6E74", |
162 | "T c #95959C", | 173 | "T c #95959C", |
163 | "U c #74747A", | 174 | "U c #74747A", |
164 | "V c #1D1D1E", | 175 | "V c #1D1D1E", |
165 | "W c #91929A", | 176 | "W c #91929A", |
166 | "X c #42444A", | 177 | "X c #42444A", |
167 | "Y c #22282E", | 178 | "Y c #22282E", |
168 | "Z c #B0B2BC", | 179 | "Z c #B0B2BC", |
169 | "` c #898A90", | 180 | "` c #898A90", |
170 | " . c #65656A", | 181 | " . c #65656A", |
171 | ".. c #999AA2", | 182 | ".. c #999AA2", |
172 | "+. c #52535A", | 183 | "+. c #52535A", |
173 | "@. c #151B21", | 184 | "@. c #151B21", |
174 | "#. c #515257", | 185 | "#. c #515257", |
175 | "$. c #B5B5BE", | 186 | "$. c #B5B5BE", |
176 | "%. c #616167", | 187 | "%. c #616167", |
177 | "&. c #1A1D22", | 188 | "&. c #1A1D22", |
178 | "*. c #000713", | 189 | "*. c #000713", |
179 | "=. c #1F1F21", | 190 | "=. c #1F1F21", |
180 | " ", | 191 | " ", |
181 | " . + @ # ", | 192 | " . + @ # ", |
182 | " $ % & * = - ", | 193 | " $ % & * = - ", |
183 | " ; > , ' ) ! ~ ", | 194 | " ; > , ' ) ! ~ ", |
184 | " { ] ^ / ( _ : ", | 195 | " { ] ^ / ( _ : ", |
185 | " < [ } | 1 2 3 ", | 196 | " < [ } | 1 2 3 ", |
186 | " 4 5 6 7 8 9 0 a b c ", | 197 | " 4 5 6 7 8 9 0 a b c ", |
187 | " d e f g h i j 3 k l m n ", | 198 | " d e f g h i j 3 k l m n ", |
188 | " o p q r s t u v w n ", | 199 | " o p q r s t u v w n ", |
189 | " o x y z A B C D E n ", | 200 | " o x y z A B C D E n ", |
190 | " F G H I J K L M N O ", | 201 | " F G H I J K L M N O ", |
191 | " P Q R S T U V W X ", | 202 | " P Q R S T U V W X ", |
192 | " Y Z ` b ...+. ", | 203 | " Y Z ` b ...+. ", |
193 | " @.#.$.%.&. ", | 204 | " @.#.$.%.&. ", |
194 | " *.B =. ", | 205 | " *.B =. ", |
195 | " n n n n n n n n n "}; | 206 | " n n n n n n n n n "}; |
196 | 207 | ||
197 | 208 | ||
198 | VMemo::VMemo( QWidget *parent, const char *_name ) | 209 | VMemo::VMemo( QWidget *parent, const char *_name ) |
199 | : QWidget( parent, _name ) | 210 | : QWidget( parent, _name ) { |
200 | { | ||
201 | setFixedHeight( 18 ); | 211 | setFixedHeight( 18 ); |
202 | setFixedWidth( 14 ); | 212 | setFixedWidth( 14 ); |
203 | 213 | ||
204 | recording = FALSE; | 214 | recording = FALSE; |
205 | 215 | ||
206 | t_timer = new QTimer( this ); | 216 | t_timer = new QTimer( this ); |
207 | connect( t_timer, SIGNAL( timeout() ), SLOT( timerBreak() ) ); | 217 | connect( t_timer, SIGNAL( timeout() ), SLOT( timerBreak() ) ); |
208 | 218 | ||
209 | struct utsname name; /* check for embedix kernel running on the zaurus*/ | 219 | struct utsname name; /* check for embedix kernel running on the zaurus*/ |
210 | if (uname(&name) != -1) { | 220 | if (uname(&name) != -1) { |
211 | QString release=name.release; | 221 | QString release=name.release; |
212 | 222 | ||
213 | Config vmCfg("Vmemo"); | 223 | Config vmCfg("Vmemo"); |
214 | vmCfg.setGroup("Defaults"); | 224 | vmCfg.setGroup("Defaults"); |
215 | int toggleKey = setToggleButton(vmCfg.readNumEntry("toggleKey", -1)); | 225 | int toggleKey = setToggleButton(vmCfg.readNumEntry("toggleKey", -1)); |
226 | useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0); | ||
216 | 227 | ||
217 | qDebug("toggleKey %d", toggleKey); | 228 | qDebug("toggleKey %d", toggleKey); |
218 | 229 | ||
219 | if(release.find("embedix",0,TRUE) !=-1) | 230 | if(release.find("embedix",0,TRUE) !=-1) |
220 | systemZaurus=TRUE; | 231 | systemZaurus=TRUE; |
221 | else | 232 | else |
222 | systemZaurus=FALSE; | 233 | systemZaurus=FALSE; |
223 | 234 | ||
224 | myChannel = new QCopChannel( "QPE/VMemo", this ); | 235 | myChannel = new QCopChannel( "QPE/VMemo", this ); |
225 | connect( myChannel, SIGNAL(received(const QCString&, const QByteArray&)), | 236 | connect( myChannel, SIGNAL(received(const QCString&, const QByteArray&)), |
226 | this, SLOT(receive(const QCString&, const QByteArray&)) ); | 237 | this, SLOT(receive(const QCString&, const QByteArray&)) ); |
227 | 238 | ||
228 | if( toggleKey != -1 ) { | 239 | if( toggleKey != -1 ) { |
229 | // QPEApplication::grabKeyboard(); | 240 | // QPEApplication::grabKeyboard(); |
230 | QCopEnvelope e("QPE/Desktop", "keyRegister(int key, QString channel, QString message)"); | 241 | QCopEnvelope e("QPE/Desktop", "keyRegister(int key, QString channel, QString message)"); |
231 | // e << 4096; // Key_Escape | 242 | // e << 4096; // Key_Escape |
232 | // e << Key_F5; //4148 | 243 | // e << Key_F5; //4148 |
233 | e << toggleKey; | 244 | e << toggleKey; |
234 | e << QString("QPE/VMemo"); | 245 | e << QString("QPE/VMemo"); |
235 | e << QString("toggleRecord()"); | 246 | e << QString("toggleRecord()"); |
236 | } | 247 | } |
237 | if(toggleKey == 1) | 248 | if(toggleKey == 1) |
238 | usingIcon=TRUE; | 249 | usingIcon=TRUE; |
239 | else | 250 | else |
240 | usingIcon=FALSE; | 251 | usingIcon=FALSE; |
241 | if( vmCfg.readNumEntry("hideIcon",0) == 1) | 252 | if( vmCfg.readNumEntry("hideIcon",0) == 1) |
242 | hide(); | 253 | hide(); |
243 | } | 254 | } |
244 | } | 255 | } |
245 | 256 | ||
246 | VMemo::~VMemo() | 257 | VMemo::~VMemo() { |
247 | { | ||
248 | } | 258 | } |
249 | 259 | ||
250 | void VMemo::receive( const QCString &msg, const QByteArray &data ) | 260 | void VMemo::receive( const QCString &msg, const QByteArray &data ) { |
251 | { | ||
252 | qDebug("receive"); | 261 | qDebug("receive"); |
253 | QDataStream stream( data, IO_ReadOnly ); | 262 | QDataStream stream( data, IO_ReadOnly ); |
254 | if (msg == "toggleRecord()") { | 263 | if (msg == "toggleRecord()") { |
255 | if (recording) { | 264 | if (recording) { |
256 | fromToggle = TRUE; | 265 | fromToggle = TRUE; |
257 | mouseReleaseEvent(NULL); | 266 | mouseReleaseEvent(NULL); |
258 | // stopRecording(); | 267 | // stopRecording(); |
259 | } else { | 268 | } else { |
260 | fromToggle = TRUE; | 269 | fromToggle = TRUE; |
261 | // mousePressEvent(NULL); | 270 | // mousePressEvent(NULL); |
262 | startRecording(); | 271 | startRecording(); |
263 | } | 272 | } |
264 | } | 273 | } |
265 | } | 274 | } |
266 | 275 | ||
267 | void VMemo::paintEvent( QPaintEvent* ) | 276 | void VMemo::paintEvent( QPaintEvent* ) { |
268 | { | ||
269 | QPainter p(this); | 277 | QPainter p(this); |
270 | p.drawPixmap( 0, 1,( const char** ) vmemo_xpm ); | 278 | p.drawPixmap( 0, 1,( const char** ) vmemo_xpm ); |
271 | } | 279 | } |
272 | 280 | ||
273 | void VMemo::mousePressEvent( QMouseEvent * me) | 281 | void VMemo::mousePressEvent( QMouseEvent * me) { |
274 | { | ||
275 | // just to be safe | 282 | // just to be safe |
276 | if (recording) { | 283 | if (recording) { |
277 | recording = FALSE; | 284 | recording = FALSE; |
278 | return; | 285 | return; |
279 | } | 286 | } |
280 | /* No mousePress/mouseRelease recording on the iPAQ. The REC button on the iPAQ calls these functions | 287 | /* No mousePress/mouseRelease recording on the iPAQ. The REC button on the iPAQ calls these functions |
281 | mousePressEvent and mouseReleaseEvent with a NULL parameter. */ | 288 | mousePressEvent and mouseReleaseEvent with a NULL parameter. */ |
282 | if ( me->button() != LeftButton) | 289 | if ( me->button() != LeftButton || me != NULL) |
283 | |||
284 | // if (!systemZaurus && me != NULL) | 290 | // if (!systemZaurus && me != NULL) |
285 | return; | 291 | return; |
286 | 292 | ||
287 | if(!recording) | 293 | if(!recording) |
288 | startRecording(); | 294 | startRecording(); |
289 | else | 295 | else |
290 | stopRecording(); | 296 | stopRecording(); |
291 | } | 297 | } |
292 | 298 | ||
293 | void VMemo::mouseReleaseEvent( QMouseEvent * ) | 299 | void VMemo::mouseReleaseEvent( QMouseEvent * ) { |
294 | { | ||
295 | // if(usingIcon && !recording) | 300 | // if(usingIcon && !recording) |
296 | // stopRecording(); | 301 | // stopRecording(); |
297 | } | 302 | } |
298 | 303 | ||
299 | bool VMemo::startRecording() { | 304 | bool VMemo::startRecording() { |
300 | 305 | ||
301 | if ( recording) | 306 | if ( recording) |
302 | return FALSE; | 307 | return FALSE; |
303 | 308 | ||
304 | Config config( "Vmemo" ); | 309 | Config config( "Vmemo" ); |
305 | config.setGroup( "System" ); | 310 | config.setGroup( "System" ); |
306 | 311 | ||
307 | useAlerts = config.readBoolEntry("Alert",1); | 312 | useAlerts = config.readBoolEntry("Alert",1); |
308 | if(useAlerts) { | 313 | if(useAlerts) { |
309 | 314 | ||
310 | msgLabel = new QLabel( 0, "alertLabel" ); | 315 | msgLabel = new QLabel( 0, "alertLabel" ); |
311 | msgLabel->setText("<B><P><font size=+2>VMemo-Recording</font></B>"); | 316 | msgLabel->setText("<B><P><font size=+2>VMemo-Recording</font></B>"); |
312 | msgLabel->show(); | 317 | msgLabel->show(); |
313 | } | 318 | } |
314 | 319 | ||
315 | // if(useAlerts) | 320 | // if(useAlerts) |
316 | // QMessageBox::message("VMemo","Really Record?");//) ==1) | 321 | // QMessageBox::message("VMemo","Really Record?");//) ==1) |
317 | // return; | 322 | // return; |
318 | // } else { | 323 | // } else { |
319 | // if (!systemZaurus ) | 324 | // if (!systemZaurus ) |
320 | // QSound::play(Resource::findSound("vmemob")); | 325 | // QSound::play(Resource::findSound("vmemob")); |
321 | // } | 326 | // } |
322 | qDebug("Start recording engines"); | 327 | qDebug("Start recording engines"); |
323 | recording = TRUE; | 328 | recording = TRUE; |
324 | 329 | ||
325 | if (openDSP() == -1) { | 330 | if (openDSP() == -1) { |
326 | // QMessageBox::critical(0, "vmemo", "Could not open dsp device.\n"+errorMsg, "Abort"); | 331 | // QMessageBox::critical(0, "vmemo", "Could not open dsp device.\n"+errorMsg, "Abort"); |
327 | // delete msgLabel; | 332 | // delete msgLabel; |
328 | recording = FALSE; | 333 | recording = FALSE; |
329 | msgLabel=0; | 334 | msgLabel=0; |
330 | delete msgLabel; | 335 | delete msgLabel; |
331 | 336 | ||
332 | return FALSE; | 337 | return FALSE; |
333 | } | 338 | } |
334 | 339 | ||
335 | config.setGroup("Defaults"); | 340 | config.setGroup("Defaults"); |
336 | 341 | ||
337 | QDateTime dt = QDateTime::currentDateTime(); | 342 | QDateTime dt = QDateTime::currentDateTime(); |
338 | 343 | ||
339 | QString fName; | 344 | QString fName; |
340 | config.setGroup( "System" ); | 345 | config.setGroup( "System" ); |
341 | fName = QPEApplication::documentDir() ; | 346 | fName = QPEApplication::documentDir() ; |
342 | fileName = config.readEntry("RecLocation", fName); | 347 | fileName = config.readEntry("RecLocation", fName); |
343 | 348 | ||
344 | int s; | 349 | int s; |
345 | s=fileName.find(':'); | 350 | s=fileName.find(':'); |
346 | if(s) | 351 | if(s) |
347 | fileName=fileName.right(fileName.length()-s-2); | 352 | fileName=fileName.right(fileName.length()-s-2); |
348 | qDebug("pathname will be "+fileName); | 353 | qDebug("pathname will be "+fileName); |
349 | 354 | ||
350 | if( fileName.left(1).find('/') == -1) | 355 | if( fileName.left(1).find('/') == -1) |
351 | fileName="/"+fileName; | 356 | fileName="/"+fileName; |
352 | if( fileName.right(1).find('/') == -1) | 357 | if( fileName.right(1).find('/') == -1) |
353 | fileName+="/"; | 358 | fileName+="/"; |
354 | fName = "vm_"+ dt.toString()+ ".wav"; | 359 | fName = "vm_"+ dt.toString()+ ".wav"; |
355 | 360 | ||
356 | fileName+=fName; | 361 | fileName+=fName; |
357 | qDebug("filename is "+fileName); | 362 | qDebug("filename is "+fileName); |
358 | // No spaces in the filename | 363 | // No spaces in the filename |
359 | fileName.replace(QRegExp("'"),""); | 364 | fileName.replace(QRegExp("'"),""); |
360 | fileName.replace(QRegExp(" "),"_"); | 365 | fileName.replace(QRegExp(" "),"_"); |
361 | fileName.replace(QRegExp(":"),"."); | 366 | fileName.replace(QRegExp(":"),"."); |
362 | fileName.replace(QRegExp(","),""); | 367 | fileName.replace(QRegExp(","),""); |
363 | 368 | ||
364 | // open tmp file here | 369 | // open tmp file here |
365 | char *pointer; | 370 | char *pointer; |
366 | pointer=tmpnam(NULL); | 371 | pointer=tmpnam(NULL); |
367 | qDebug("Opening tmp file %s",pointer); | 372 | qDebug("Opening tmp file %s",pointer); |
368 | 373 | ||
369 | if(openWAV(pointer ) == -1) { | 374 | if(openWAV(pointer ) == -1) { |
370 | 375 | ||
371 | // if(openWAV(fileName.latin1()) == -1) { | 376 | // if(openWAV(fileName.latin1()) == -1) { |
372 | QString err("Could not open the temp file\n"); | 377 | QString err("Could not open the temp file\n"); |
373 | err += fileName; | 378 | err += fileName; |
374 | QMessageBox::critical(0, "vmemo", err, "Abort"); | 379 | QMessageBox::critical(0, "vmemo", err, "Abort"); |
375 | ::close(dsp); | 380 | ::close(dsp); |
376 | return FALSE; | 381 | return FALSE; |
377 | } | 382 | } |
378 | QString cmd; | 383 | record(); |
379 | cmd.sprintf("mv %s "+fileName,pointer); | ||
380 | 384 | ||
385 | QString cmd; | ||
386 | cmd.sprintf("mv %s "+fileName, pointer); | ||
381 | // move tmp file to regular file here | 387 | // move tmp file to regular file here |
382 | system(cmd.latin1()); | 388 | system(cmd.latin1()); |
383 | 389 | ||
384 | QArray<int> cats(1); | 390 | QArray<int> cats(1); |
385 | cats[0] = config.readNumEntry("Category", 0); | 391 | cats[0] = config.readNumEntry("Category", 0); |
386 | 392 | ||
387 | QString dlName("vm_"); | 393 | QString dlName("vm_"); |
388 | dlName += dt.toString(); | 394 | dlName += dt.toString(); |
389 | DocLnk l; | 395 | DocLnk l; |
390 | l.setFile(fileName); | 396 | l.setFile(fileName); |
391 | l.setName(dlName); | 397 | l.setName(dlName); |
392 | l.setType("audio/x-wav"); | 398 | l.setType("audio/x-wav"); |
393 | l.setCategories(cats); | 399 | l.setCategories(cats); |
394 | l.writeLink(); | 400 | l.writeLink(); |
395 | |||
396 | record(); | ||
397 | 401 | ||
398 | return TRUE; | 402 | return TRUE; |
399 | } | 403 | } |
400 | 404 | ||
401 | void VMemo::stopRecording() { | 405 | void VMemo::stopRecording() { |
402 | show(); | 406 | show(); |
403 | qDebug("Stopped recording"); | 407 | qDebug("Stopped recording"); |
404 | recording = FALSE; | 408 | recording = FALSE; |
405 | if(useAlerts) { | 409 | if(useAlerts) { |
406 | msgLabel->close(); | 410 | msgLabel->close(); |
407 | msgLabel=0; | 411 | msgLabel=0; |
408 | delete msgLabel; | 412 | delete msgLabel; |
409 | } | 413 | } |
410 | t_timer->stop(); | 414 | t_timer->stop(); |
411 | Config cfg("Vmemo"); | 415 | Config cfg("Vmemo"); |
412 | cfg.setGroup("Defaults"); | 416 | cfg.setGroup("Defaults"); |
413 | if( cfg.readNumEntry("hideIcon",0) == 1 ) | 417 | if( cfg.readNumEntry("hideIcon",0) == 1 ) |
414 | hide(); | 418 | hide(); |
415 | } | 419 | } |
416 | 420 | ||
417 | int VMemo::openDSP() | 421 | int VMemo::openDSP() { |
418 | { | ||
419 | Config cfg("Vmemo"); | 422 | Config cfg("Vmemo"); |
420 | cfg.setGroup("Record"); | 423 | cfg.setGroup("Record"); |
421 | 424 | ||
422 | speed = cfg.readNumEntry("SampleRate", 22050); | 425 | speed = cfg.readNumEntry("SampleRate", 22050); |
423 | channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) | 426 | channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) |
424 | if (cfg.readNumEntry("SixteenBit", 1)==1) { | 427 | if (cfg.readNumEntry("SixteenBit", 1)==1) { |
425 | format = AFMT_S16_LE; | 428 | format = AFMT_S16_LE; |
426 | resolution = 16; | 429 | resolution = 16; |
427 | } else { | 430 | } else { |
428 | format = AFMT_U8; | 431 | format = AFMT_U8; |
429 | resolution = 8; | 432 | resolution = 8; |
430 | } | 433 | } |
431 | 434 | ||
432 | qDebug("samplerate: %d, channels %d, resolution %d", speed, channels, resolution); | 435 | qDebug("samplerate: %d, channels %d, resolution %d", speed, channels, resolution); |
433 | 436 | ||
434 | if(systemZaurus) { | 437 | if(systemZaurus) { |
435 | dsp = open("/dev/dsp1", O_RDONLY); //Zaurus needs /dev/dsp1 | 438 | dsp = open("/dev/dsp1", O_RDONLY); //Zaurus needs /dev/dsp1 |
436 | channels=1; //zaurus has one input channel | 439 | channels=1; //zaurus has one input channel |
437 | } else { | 440 | } else { |
438 | dsp = open("/dev/dsp", O_RDONLY); | 441 | dsp = open("/dev/dsp", O_RDONLY); |
439 | } | 442 | } |
440 | 443 | ||
441 | if(dsp == -1) { | 444 | if(dsp == -1) { |
442 | perror("open(\"/dev/dsp\")"); | 445 | perror("open(\"/dev/dsp\")"); |
443 | errorMsg="open(\"/dev/dsp\")\n "+(QString)strerror(errno); | 446 | errorMsg="open(\"/dev/dsp\")\n "+(QString)strerror(errno); |
444 | QMessageBox::critical(0, "vmemo", errorMsg, "Abort"); | 447 | QMessageBox::critical(0, "vmemo", errorMsg, "Abort"); |
445 | return -1; | 448 | return -1; |
446 | } | 449 | } |
447 | 450 | ||
448 | if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) { | 451 | if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) { |
449 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); | 452 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); |
450 | return -1; | 453 | return -1; |
451 | } | 454 | } |
452 | if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) { | 455 | if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) { |
453 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); | 456 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); |
454 | return -1; | 457 | return -1; |
455 | } | 458 | } |
456 | if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) { | 459 | if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) { |
457 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); | 460 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); |
458 | return -1; | 461 | return -1; |
459 | } | 462 | } |
460 | if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) { | 463 | if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) { |
461 | perror("ioctl(\"SOUND_PCM_READ_RATE\")"); | 464 | perror("ioctl(\"SOUND_PCM_READ_RATE\")"); |
462 | return -1; | 465 | return -1; |
463 | } | 466 | } |
464 | 467 | ||
465 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; //mute | 468 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; //mute |
466 | 469 | ||
467 | return 1; | 470 | return 1; |
468 | } | 471 | } |
469 | 472 | ||
470 | int VMemo::openWAV(const char *filename) | 473 | int VMemo::openWAV(const char *filename) { |
471 | { | ||
472 | track.setName(filename); | 474 | track.setName(filename); |
473 | if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) { | 475 | if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) { |
474 | errorMsg=filename; | 476 | errorMsg=filename; |
475 | return -1; | 477 | return -1; |
476 | } | 478 | } |
477 | 479 | ||
478 | wav=track.handle(); | 480 | wav=track.handle(); |
479 | 481 | ||
480 | WaveHeader wh; | 482 | WaveHeader wh; |
481 | 483 | ||
482 | wh.main_chunk = RIFF; | 484 | wh.main_chunk = RIFF; |
483 | wh.length=0; | 485 | wh.length=0; |
484 | wh.chunk_type = WAVE; | 486 | wh.chunk_type = WAVE; |
485 | wh.sub_chunk = FMT; | 487 | wh.sub_chunk = FMT; |
486 | wh.sc_len = 16; | 488 | wh.sc_len = 16; |
487 | wh.format = PCM_CODE; | 489 | if(useADPCM) |
490 | wh.format = WAVE_FORMAT_DVI_ADPCM;//PCM_CODE; | ||
491 | else | ||
492 | wh.format = PCM_CODE; | ||
488 | wh.modus = channels; | 493 | wh.modus = channels; |
489 | wh.sample_fq = speed; | 494 | wh.sample_fq = speed; |
490 | wh.byte_p_sec = speed * channels * resolution/8; | 495 | wh.byte_p_sec = speed * channels * resolution/8; |
491 | wh.byte_p_spl = channels * (resolution / 8); | 496 | wh.byte_p_spl = channels * (resolution / 8); |
492 | wh.bit_p_spl = resolution; | 497 | wh.bit_p_spl = resolution; |
493 | wh.data_chunk = DATA; | 498 | wh.data_chunk = DATA; |
494 | wh.data_length= 0; | 499 | wh.data_length= 0; |
495 | // qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d" | 500 | // qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d" |
496 | // , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl ); | 501 | // , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl ); |
497 | write (wav, &wh, sizeof(WaveHeader)); | 502 | write (wav, &wh, sizeof(WaveHeader)); |
498 | 503 | ||
499 | return 1; | 504 | return 1; |
500 | } | 505 | } |
501 | 506 | ||
502 | void VMemo::record(void) | 507 | void VMemo::record(void) { |
503 | { | ||
504 | int length=0, result, value; | 508 | int length=0, result, value; |
505 | QString msg; | 509 | QString msg; |
506 | msg.sprintf("Recording format %d", format); | 510 | msg.sprintf("Recording format %d", format); |
507 | qDebug(msg); | 511 | qDebug(msg); |
508 | Config config("Vmemo"); | 512 | Config config("Vmemo"); |
509 | config.setGroup("Record"); | 513 | config.setGroup("Record"); |
510 | int sRate=config.readNumEntry("SizeLimit", 30); | 514 | int sRate=config.readNumEntry("SizeLimit", 30); |
511 | 515 | ||
512 | t_timer->start( sRate * 1000+1000, TRUE); | 516 | t_timer->start( sRate * 1000+1000, TRUE); |
513 | 517 | ||
514 | if(systemZaurus) { | 518 | // if(systemZaurus) { |
519 | // } else { // 16 bit only capabilities | ||
515 | 520 | ||
516 | msg.sprintf("Recording format zaurus"); | 521 | msg.sprintf("Recording format other"); |
517 | qDebug(msg); | 522 | qDebug(msg); |
518 | signed short sound[1024], monoBuffer[1024]; | ||
519 | |||
520 | if(format==AFMT_S16_LE) { | ||
521 | 523 | ||
524 | int bufsize=1024; | ||
525 | int bytesWritten=0; | ||
526 | signed short sound[1024], monoBuffer[1024]; | ||
527 | char abuf[bufsize/2]; | ||
528 | short sbuf[bufsize]; | ||
522 | 529 | ||
530 | while(recording) { | ||
523 | 531 | ||
524 | while(recording) { | 532 | if(useADPCM) |
525 | 533 | result = read( dsp, sbuf, bufsize); // 8192 | |
526 | result = read(dsp, sound, 1024); // 8192 | 534 | else |
527 | // int j=0; | 535 | result = read(dsp, sound, 1024); // 8192 |
528 | 536 | if( result <= 0) { | |
529 | for (int i = 0; i < result; i++) { //since Z is mono do normally | 537 | perror("recording error "); |
530 | monoBuffer[i] = sound[i]; | 538 | // qDebug(currentFileName); |
539 | QMessageBox::message(tr("Note"),tr("error recording")); | ||
540 | recording=FALSE;; | ||
541 | break; | ||
531 | } | 542 | } |
532 | 543 | ||
533 | length+=write(wav, monoBuffer, result); | 544 | if(useADPCM) { |
534 | if(length<0) | 545 | adpcm_coder( sbuf, abuf, result/2, &encoder_state); |
535 | recording=false; | 546 | bytesWritten = ::write(wav, abuf, result/4); |
536 | // for (int i = 0; i < result; i+=2) { | ||
537 | // monoBuffer[j] = sound[i]; | ||
538 | // // monoBuffer[j] = (sound[i]+sound[i+1])/2; | ||
539 | |||
540 | // j++; | ||
541 | // } | ||
542 | qApp->processEvents(); | ||
543 | // printf("%d\r",length); | ||
544 | // fflush(stdout); | ||
545 | } | ||
546 | |||
547 | } else { //AFMT_U8 | ||
548 | // 8bit unsigned | ||
549 | unsigned short sound[1024], monoBuffer[1024]; | ||
550 | while(recording) { | ||
551 | result = read(dsp, sound, 1024); // 8192 | ||
552 | // int j=0; | ||
553 | 547 | ||
554 | // if(systemZaurus) { | 548 | } else { |
549 | for (int i = 0; i < result; i++) { //since Z is mono do normally | ||
550 | monoBuffer[i] = sound[i]; | ||
551 | } | ||
555 | 552 | ||
556 | for (int i = 0; i < result; i++) { //since Z is mono do normally | 553 | length+=write(wav, monoBuffer, result); |
557 | monoBuffer[i] = sound[i]; | ||
558 | } | 554 | } |
559 | 555 | length +=bytesWritten; | |
560 | length+=write(wav, monoBuffer, result); | ||
561 | |||
562 | // for (int i = 0; i < result; i+=2) { | ||
563 | // monoBuffer[j] = (sound[i]+sound[i+1])/2; | ||
564 | // j++; | ||
565 | // } | ||
566 | // length+=write(wav, monoBuffer, result/2); | ||
567 | length += result; | ||
568 | // printf("%d\r",length); | ||
569 | // fflush(stdout); | ||
570 | } | ||
571 | |||
572 | qApp->processEvents(); | ||
573 | } | ||
574 | |||
575 | } else { // 16 bit only capabilities | ||
576 | |||
577 | |||
578 | msg.sprintf("Recording format other"); | ||
579 | qDebug(msg); | ||
580 | |||
581 | signed short sound[1024];//, monoBuffer[512]; | ||
582 | |||
583 | while(recording) { | ||
584 | |||
585 | result = read(dsp, sound, 1024); // 8192 | ||
586 | |||
587 | write(wav, sound, result); | ||
588 | length += result; | ||
589 | 556 | ||
590 | if(length<0) { | 557 | if(length<0) { |
591 | |||
592 | recording=false; | 558 | recording=false; |
593 | perror("dev/dsp's is a lookin' messy"); | 559 | perror("dev/dsp's is a lookin' messy"); |
594 | QMessageBox::message("Vmemo"," Done1 recording\n"+ fileName); | 560 | QMessageBox::message("Vmemo"," Done1 recording\n"+ fileName); |
595 | } | 561 | } |
596 | // printf("%d\r",length); | 562 | // printf("%d\r",length); |
597 | // fflush(stdout); | 563 | // fflush(stdout); |
598 | qApp->processEvents(); | 564 | qApp->processEvents(); |
599 | } | 565 | } |
600 | // qDebug("file has length of %d lasting %d seconds", | 566 | // qDebug("file has length of %d lasting %d seconds", |
601 | // length, (( length / speed) / channels) / 2 ); | 567 | // length, (( length / speed) / channels) / 2 ); |
602 | // medialplayer states wrong length in secs | 568 | // medialplayer states wrong length in secs |
603 | } | 569 | // } |
604 | 570 | ||
605 | //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<// | 571 | //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<// |
606 | 572 | ||
607 | value = length+36; | 573 | value = length+36; |
608 | 574 | ||
609 | lseek(wav, 4, SEEK_SET); | 575 | lseek(wav, 4, SEEK_SET); |
610 | write(wav, &value, 4); | 576 | write(wav, &value, 4); |
611 | lseek(wav, 40, SEEK_SET); | 577 | lseek(wav, 40, SEEK_SET); |
612 | 578 | ||
613 | write(wav, &length, 4); | 579 | write(wav, &length, 4); |
614 | 580 | ||
615 | track.close(); | 581 | track.close(); |
616 | qDebug("Track closed"); | 582 | qDebug("Track closed"); |
617 | 583 | ||
618 | if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) | 584 | if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) |
619 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); | 585 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); |
620 | 586 | ||
621 | ::close(dsp); | 587 | ::close(dsp); |
622 | fileName = fileName.left(fileName.length()-4); | 588 | fileName = fileName.left(fileName.length()-4); |
623 | // if(useAlerts) | 589 | // if(useAlerts) |
624 | // QMessageBox::message("Vmemo"," Done1 recording\n"+ fileName); | 590 | // QMessageBox::message("Vmemo"," Done1 recording\n"+ fileName); |
625 | qDebug("done recording "+fileName); | 591 | qDebug("done recording "+fileName); |
626 | 592 | ||
627 | // QSound::play(Resource::findSound("vmemoe")); | 593 | // QSound::play(Resource::findSound("vmemoe")); |
628 | 594 | ||
629 | Config cfg("qpe"); | 595 | Config cfg("qpe"); |
630 | cfg.setGroup("Volume"); | 596 | cfg.setGroup("Volume"); |
631 | QString foo = cfg.readEntry("Mute","TRUE"); | 597 | QString foo = cfg.readEntry("Mute","TRUE"); |
632 | if(foo.find("TRUE",0,TRUE) != -1) | 598 | if(foo.find("TRUE",0,TRUE) != -1) |
633 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; //mute | 599 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; //mute |
634 | 600 | ||
635 | } | 601 | } |
636 | 602 | ||
637 | int VMemo::setToggleButton(int tog) { | 603 | int VMemo::setToggleButton(int tog) { |
638 | 604 | ||
639 | for( int i=0; i < 10;i++) { | 605 | for( int i=0; i < 10;i++) { |
640 | switch (tog) { | 606 | switch (tog) { |
641 | case 0: | 607 | case 0: |
642 | return -1; | 608 | return -1; |
643 | break; | 609 | break; |
644 | case 1: | 610 | case 1: |
645 | return 0; | 611 | return 0; |
646 | break; | 612 | break; |
647 | case 2: | 613 | case 2: |
648 | return Key_Escape; | 614 | return Key_Escape; |
649 | break; | 615 | break; |
650 | case 3: | 616 | case 3: |
651 | return Key_Space; | 617 | return Key_Space; |
diff --git a/core/applets/vmemo/vmemo.h b/core/applets/vmemo/vmemo.h index 823c7b8..167af2a 100644 --- a/core/applets/vmemo/vmemo.h +++ b/core/applets/vmemo/vmemo.h | |||
@@ -1,63 +1,63 @@ | |||
1 | /**************************************************************************************94x78** | 1 | /**************************************************************************************94x78** |
2 | ** | 2 | ** |
3 | ** This file may be distributed and/or modified under the terms of the | 3 | ** This file may be distributed and/or modified under the terms of the |
4 | ** GNU General Public License version 2 as published by the Free Software | 4 | ** GNU General Public License version 2 as published by the Free Software |
5 | ** Foundation and appearing in the file LICENSE.GPL included in the | 5 | ** Foundation and appearing in the file LICENSE.GPL included in the |
6 | ** packaging of this file. | 6 | ** packaging of this file. |
7 | ** | 7 | ** |
8 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 8 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
9 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 9 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
10 | ** | 10 | ** |
11 | *********************************************************************************************/ | 11 | *********************************************************************************************/ |
12 | 12 | ||
13 | /* | 13 | /* |
14 | * $Id$ | 14 | * $Id$ |
15 | */ | 15 | */ |
16 | 16 | ||
17 | #ifndef __VMEMO_H__ | 17 | #ifndef __VMEMO_H__ |
18 | #define __VMEMO_H__ | 18 | #define __VMEMO_H__ |
19 | 19 | ||
20 | 20 | ||
21 | #include <qwidget.h> | 21 | #include <qwidget.h> |
22 | #include <qpixmap.h> | 22 | #include <qpixmap.h> |
23 | #include <qpe/applnk.h> | 23 | #include <qpe/applnk.h> |
24 | #include <qfile.h> | 24 | #include <qfile.h> |
25 | #include <qpe/qcopenvelope_qws.h> | 25 | #include <qpe/qcopenvelope_qws.h> |
26 | #include <qlabel.h> | 26 | #include <qlabel.h> |
27 | #include <qtimer.h> | 27 | #include <qtimer.h> |
28 | 28 | ||
29 | class VMemo : public QWidget | 29 | class VMemo : public QWidget |
30 | { | 30 | { |
31 | Q_OBJECT | 31 | Q_OBJECT |
32 | public: | 32 | public: |
33 | VMemo( QWidget *parent, const char *name = NULL); | 33 | VMemo( QWidget *parent, const char *name = NULL); |
34 | ~VMemo(); | 34 | ~VMemo(); |
35 | QFile track; | 35 | QFile track; |
36 | QString fileName, errorMsg; | 36 | QString fileName, errorMsg; |
37 | QLabel* msgLabel; | 37 | QLabel* msgLabel; |
38 | QTimer *t_timer; | 38 | QTimer *t_timer; |
39 | bool usingIcon; | 39 | bool usingIcon, useADPCM; |
40 | public slots: | 40 | public slots: |
41 | void record(); | 41 | void record(); |
42 | void mousePressEvent( QMouseEvent * ); | 42 | void mousePressEvent( QMouseEvent * ); |
43 | void mouseReleaseEvent( QMouseEvent * ); | 43 | void mouseReleaseEvent( QMouseEvent * ); |
44 | void receive( const QCString &msg, const QByteArray &data ); | 44 | void receive( const QCString &msg, const QByteArray &data ); |
45 | bool startRecording(); | 45 | bool startRecording(); |
46 | void stopRecording(); | 46 | void stopRecording(); |
47 | void timerBreak(); | 47 | void timerBreak(); |
48 | private: | 48 | private: |
49 | bool useAlerts; | 49 | bool useAlerts; |
50 | void paintEvent( QPaintEvent* ); | 50 | void paintEvent( QPaintEvent* ); |
51 | int setToggleButton(int); | 51 | int setToggleButton(int); |
52 | int openDSP(); | 52 | int openDSP(); |
53 | int openWAV(const char *filename); | 53 | int openWAV(const char *filename); |
54 | bool fromToggle; | 54 | bool fromToggle; |
55 | QPixmap vmemoPixmap; | 55 | QPixmap vmemoPixmap; |
56 | QCopChannel *myChannel; | 56 | QCopChannel *myChannel; |
57 | bool systemZaurus; | 57 | bool systemZaurus; |
58 | int dsp, wav, rate, speed, channels, format, resolution; | 58 | int dsp, wav, rate, speed, channels, format, resolution; |
59 | bool recording; | 59 | bool recording; |
60 | }; | 60 | }; |
61 | 61 | ||
62 | #endif // __VMEMO_H__ | 62 | #endif // __VMEMO_H__ |
63 | 63 | ||
diff --git a/core/applets/vmemo/vmemo.pro b/core/applets/vmemo/vmemo.pro index f8007b6..6599b52 100644 --- a/core/applets/vmemo/vmemo.pro +++ b/core/applets/vmemo/vmemo.pro | |||
@@ -1,25 +1,25 @@ | |||
1 | TEMPLATE= lib | 1 | TEMPLATE = lib |
2 | CONFIG += qt warn_on release | 2 | CONFIG += qt warn_on release |
3 | HEADERS= vmemo.h vmemoimpl.h | 3 | HEADERS = vmemo.h vmemoimpl.h adpcm.h |
4 | SOURCES= vmemo.cpp vmemoimpl.cpp | 4 | SOURCES = vmemo.cpp vmemoimpl.cpp adpcm.c |
5 | TARGET = vmemoapplet | 5 | TARGET = vmemoapplet |
6 | DESTDIR =$(OPIEDIR)/plugins/applets | 6 | DESTDIR =$(OPIEDIR)/plugins/applets |
7 | INCLUDEPATH += $(OPIEDIR)/include | 7 | INCLUDEPATH += $(OPIEDIR)/include |
8 | DEPENDPATH += $(OPIEDIR)/include | 8 | DEPENDPATH += $(OPIEDIR)/include |
9 | LIBS += -lqpe | 9 | LIBS += -lqpe |
10 | VERSION = 1.0.0 | 10 | VERSION = 1.0.0 |
11 | 11 | ||
12 | TRANSLATIONS = ../../../i18n/de/libvmemoapplet.ts \ | 12 | TRANSLATIONS = ../../../i18n/de/libvmemoapplet.ts \ |
13 | ../../../i18n/en/libvmemoapplet.ts \ | 13 | ../../../i18n/en/libvmemoapplet.ts \ |
14 | ../../../i18n/es/libvmemoapplet.ts \ | 14 | ../../../i18n/es/libvmemoapplet.ts \ |
15 | ../../../i18n/fr/libvmemoapplet.ts \ | 15 | ../../../i18n/fr/libvmemoapplet.ts \ |
16 | ../../../i18n/hu/libvmemoapplet.ts \ | 16 | ../../../i18n/hu/libvmemoapplet.ts \ |
17 | ../../../i18n/ja/libvmemoapplet.ts \ | 17 | ../../../i18n/ja/libvmemoapplet.ts \ |
18 | ../../../i18n/ko/libvmemoapplet.ts \ | 18 | ../../../i18n/ko/libvmemoapplet.ts \ |
19 | ../../../i18n/no/libvmemoapplet.ts \ | 19 | ../../../i18n/no/libvmemoapplet.ts \ |
20 | ../../../i18n/pl/libvmemoapplet.ts \ | 20 | ../../../i18n/pl/libvmemoapplet.ts \ |
21 | ../../../i18n/pt/libvmemoapplet.ts \ | 21 | ../../../i18n/pt/libvmemoapplet.ts \ |
22 | ../../../i18n/pt_BR/libvmemoapplet.ts \ | 22 | ../../../i18n/pt_BR/libvmemoapplet.ts \ |
23 | ../../../i18n/sl/libvmemoapplet.ts \ | 23 | ../../../i18n/sl/libvmemoapplet.ts \ |
24 | ../../../i18n/zh_CN/libvmemoapplet.ts \ | 24 | ../../../i18n/zh_CN/libvmemoapplet.ts \ |
25 | ../../../i18n/zh_TW/libvmemoapplet.ts | 25 | ../../../i18n/zh_TW/libvmemoapplet.ts |