-rw-r--r-- | core/applets/vmemo/vmemo.cpp | 12 | ||||
-rw-r--r-- | core/applets/vmemo/vmemo.h | 1 |
2 files changed, 11 insertions, 2 deletions
diff --git a/core/applets/vmemo/vmemo.cpp b/core/applets/vmemo/vmemo.cpp index 8875cdf..5ce6fa9 100644 --- a/core/applets/vmemo/vmemo.cpp +++ b/core/applets/vmemo/vmemo.cpp | |||
@@ -1,426 +1,434 @@ | |||
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 | 12 | ||
13 | /* | 13 | /* |
14 | * $Id$ | 14 | * $Id$ |
15 | */ | 15 | */ |
16 | 16 | ||
17 | #include <sys/utsname.h> | 17 | #include <sys/utsname.h> |
18 | #include <sys/time.h> | 18 | #include <sys/time.h> |
19 | #include <sys/types.h> | 19 | #include <sys/types.h> |
20 | #include <unistd.h> | 20 | #include <unistd.h> |
21 | #include <stdio.h> | 21 | #include <stdio.h> |
22 | #include <sys/stat.h> | 22 | #include <sys/stat.h> |
23 | #include <fcntl.h> | 23 | #include <fcntl.h> |
24 | #include <sys/ioctl.h> | 24 | #include <sys/ioctl.h> |
25 | #include <linux/soundcard.h> | 25 | #include <linux/soundcard.h> |
26 | #include <string.h> | 26 | #include <string.h> |
27 | #include <stdlib.h> | 27 | #include <stdlib.h> |
28 | 28 | ||
29 | typedef struct _waveheader { | 29 | typedef struct _waveheader { |
30 | u_long main_chunk; /* 'RIFF' */ | 30 | u_long main_chunk; /* 'RIFF' */ |
31 | u_long length; /* filelen */ | 31 | u_long length; /* filelen */ |
32 | u_long chunk_type; /* 'WAVE' */ | 32 | u_long chunk_type; /* 'WAVE' */ |
33 | u_long sub_chunk; /* 'fmt ' */ | 33 | u_long sub_chunk; /* 'fmt ' */ |
34 | u_long sc_len; /* length of sub_chunk, =16 | 34 | u_long sc_len; /* length of sub_chunk, =16 |
35 | (chunckSize) format len */ | 35 | (chunckSize) format len */ |
36 | u_short format; /* should be 1 for PCM-code (formatTag) */ | 36 | u_short format; /* should be 1 for PCM-code (formatTag) */ |
37 | 37 | ||
38 | u_short modus; /* 1 Mono, 2 Stereo (channels) */ | 38 | u_short modus; /* 1 Mono, 2 Stereo (channels) */ |
39 | u_long sample_fq; /* samples per second (samplesPerSecond) */ | 39 | u_long sample_fq; /* samples per second (samplesPerSecond) */ |
40 | u_long byte_p_sec; /* avg bytes per second (avgBytePerSecond) */ | 40 | u_long byte_p_sec; /* avg bytes per second (avgBytePerSecond) */ |
41 | u_short byte_p_spl; /* samplesize; 1 or 2 bytes (blockAlign) */ | 41 | u_short byte_p_spl; /* samplesize; 1 or 2 bytes (blockAlign) */ |
42 | u_short bit_p_spl; /* 8, 12 or 16 bit (bitsPerSample) */ | 42 | u_short bit_p_spl; /* 8, 12 or 16 bit (bitsPerSample) */ |
43 | 43 | ||
44 | u_long data_chunk; /* 'data' */ | 44 | u_long data_chunk; /* 'data' */ |
45 | 45 | ||
46 | u_long data_length;/* samplecount */ | 46 | u_long data_length;/* samplecount */ |
47 | } WaveHeader; | 47 | } WaveHeader; |
48 | 48 | ||
49 | #define RIFF 0x46464952 | 49 | #define RIFF 0x46464952 |
50 | #define WAVE 0x45564157 | 50 | #define WAVE 0x45564157 |
51 | #define FMT 0x20746D66 | 51 | #define FMT 0x20746D66 |
52 | #define DATA 0x61746164 | 52 | #define DATA 0x61746164 |
53 | #define PCM_CODE 1 | 53 | #define PCM_CODE 1 |
54 | #define WAVE_MONO 1 | 54 | #define WAVE_MONO 1 |
55 | #define WAVE_STEREO 2 | 55 | #define WAVE_STEREO 2 |
56 | 56 | ||
57 | #include "vmemo.h" | 57 | #include "vmemo.h" |
58 | 58 | ||
59 | #include <qpe/qpeapplication.h> | 59 | #include <qpe/qpeapplication.h> |
60 | #include <qpe/resource.h> | 60 | #include <qpe/resource.h> |
61 | #include <qpe/config.h> | 61 | #include <qpe/config.h> |
62 | 62 | ||
63 | #include <qpainter.h> | 63 | #include <qpainter.h> |
64 | #include <qdatetime.h> | 64 | #include <qdatetime.h> |
65 | #include <qsound.h> | 65 | #include <qsound.h> |
66 | #include <qfile.h> | 66 | #include <qfile.h> |
67 | #include <qmessagebox.h> | 67 | #include <qmessagebox.h> |
68 | 68 | ||
69 | int seq = 0; | 69 | int seq = 0; |
70 | 70 | ||
71 | /* XPM */ | 71 | /* XPM */ |
72 | static char * vmemo_xpm[] = { | 72 | static char * vmemo_xpm[] = { |
73 | "14 14 47 1", | 73 | "14 14 47 1", |
74 | " c None", | 74 | " c None", |
75 | ". c #101010", | 75 | ". c #101010", |
76 | "+ c #0D0D0D", | 76 | "+ c #0D0D0D", |
77 | "@ c #0B0B0B", | 77 | "@ c #0B0B0B", |
78 | "# c #393939", | 78 | "# c #393939", |
79 | "$ c #6C6C6C", | 79 | "$ c #6C6C6C", |
80 | "% c #5D5D5D", | 80 | "% c #5D5D5D", |
81 | "& c #4E4E4E", | 81 | "& c #4E4E4E", |
82 | "* c #1C1C1C", | 82 | "* c #1C1C1C", |
83 | "= c #131313", | 83 | "= c #131313", |
84 | "- c #7B7B7B", | 84 | "- c #7B7B7B", |
85 | "; c #303030", | 85 | "; c #303030", |
86 | "> c #383838", | 86 | "> c #383838", |
87 | ", c #3F3F3F", | 87 | ", c #3F3F3F", |
88 | "' c #343434", | 88 | "' c #343434", |
89 | ") c #060606", | 89 | ") c #060606", |
90 | "! c #444444", | 90 | "! c #444444", |
91 | "~ c #646464", | 91 | "~ c #646464", |
92 | "{ c #505050", | 92 | "{ c #505050", |
93 | "] c #717171", | 93 | "] c #717171", |
94 | "^ c #1B1B1B", | 94 | "^ c #1B1B1B", |
95 | "/ c #585858", | 95 | "/ c #585858", |
96 | "( c #4C4C4C", | 96 | "( c #4C4C4C", |
97 | "_ c #353535", | 97 | "_ c #353535", |
98 | ": c #0E0E0E", | 98 | ": c #0E0E0E", |
99 | "< c #080808", | 99 | "< c #080808", |
100 | "[ c #262626", | 100 | "[ c #262626", |
101 | "} c #121212", | 101 | "} c #121212", |
102 | "| c #7F7F7F", | 102 | "| c #7F7F7F", |
103 | "1 c #464646", | 103 | "1 c #464646", |
104 | "2 c #0C0C0C", | 104 | "2 c #0C0C0C", |
105 | "3 c #727272", | 105 | "3 c #727272", |
106 | "4 c #292929", | 106 | "4 c #292929", |
107 | "5 c #656565", | 107 | "5 c #656565", |
108 | "6 c #565656", | 108 | "6 c #565656", |
109 | "7 c #434343", | 109 | "7 c #434343", |
110 | "8 c #272727", | 110 | "8 c #272727", |
111 | "9 c #0F0F0F", | 111 | "9 c #0F0F0F", |
112 | "0 c #3A3A3A", | 112 | "0 c #3A3A3A", |
113 | "a c #090909", | 113 | "a c #090909", |
114 | "b c #535353", | 114 | "b c #535353", |
115 | "c c #545454", | 115 | "c c #545454", |
116 | "d c #494949", | 116 | "d c #494949", |
117 | "e c #7A7A7A", | 117 | "e c #7A7A7A", |
118 | "f c #202020", | 118 | "f c #202020", |
119 | "g c #3D3D3D", | 119 | "g c #3D3D3D", |
120 | "h c #1F1F1F", | 120 | "h c #1F1F1F", |
121 | " .+@ ", | 121 | " .+@ ", |
122 | " #$%&* ", | 122 | " #$%&* ", |
123 | " =-;>,')", | 123 | " =-;>,')", |
124 | " .$;!~,)", | 124 | " .$;!~,)", |
125 | " ;#{]!)", | 125 | " ;#{]!)", |
126 | " ^~/(_)", | 126 | " ^~/(_)", |
127 | " ./:@<[)", | 127 | " ./:@<[)", |
128 | " }. .|]1;;2 ", | 128 | " }. .|]1;;2 ", |
129 | " #-$;^/3&;;4@ ", | 129 | " #-$;^/3&;;4@ ", |
130 | ".$;;#5:67;89 ", | 130 | ".$;;#5:67;89 ", |
131 | ":%;0%&ab;8. ", | 131 | ":%;0%&ab;8. ", |
132 | "@cd%e!fg49 ", | 132 | "@cd%e!fg49 ", |
133 | " h0,!_;2@ ", | 133 | " h0,!_;2@ ", |
134 | " ))))) "}; | 134 | " ))))) "}; |
135 | 135 | ||
136 | VMemo::VMemo( QWidget *parent, const char *name ) | 136 | VMemo::VMemo( QWidget *parent, const char *name ) |
137 | : QWidget( parent, name ) | 137 | : QWidget( parent, name ) |
138 | { | 138 | { |
139 | setFixedHeight( 18 ); | 139 | setFixedHeight( 18 ); |
140 | setFixedWidth( 14 ); | 140 | setFixedWidth( 14 ); |
141 | 141 | ||
142 | recording = FALSE; | 142 | recording = FALSE; |
143 | 143 | ||
144 | myChannel = new QCopChannel( "QPE/VMemo", this ); | 144 | myChannel = new QCopChannel( "QPE/VMemo", this ); |
145 | connect( myChannel, SIGNAL(sayHi()), this, SLOT(sayHi()) ); | ||
145 | connect( myChannel, SIGNAL(received(const QCString&, const QByteArray&)), | 146 | connect( myChannel, SIGNAL(received(const QCString&, const QByteArray&)), |
146 | this, SLOT(receive(const QCString&, const QByteArray&)) ); | 147 | this, SLOT(receive(const QCString&, const QByteArray&)) ); |
147 | 148 | ||
148 | struct utsname name; /* check for embedix kernel running on the zaurus, if | 149 | struct utsname name; /* check for embedix kernel running on the zaurus, if |
149 | lineo change string, this break | 150 | lineo change string, this break |
150 | */ | 151 | */ |
151 | if (uname(&name) != -1) | 152 | if (uname(&name) != -1) |
152 | { | 153 | { |
153 | QString release=name.release; | 154 | QString release=name.release; |
154 | qWarning("System release: %s\n", name.release); | 155 | qWarning("System release: %s\n", name.release); |
155 | if(release.find("embedix",0,TRUE) !=-1) | 156 | if(release.find("embedix",0,TRUE) !=-1) |
156 | systemZaurus=TRUE; | 157 | systemZaurus=TRUE; |
157 | else | 158 | else |
158 | { | 159 | { |
159 | int fr; | 160 | int fr; |
160 | systemZaurus=FALSE; | 161 | systemZaurus=FALSE; |
161 | 162 | ||
162 | if ((fr = fork()) == -1) | 163 | if ((fr = fork()) == -1) |
163 | { | 164 | { |
164 | qWarning("Fork failed"); | 165 | qWarning("Fork failed"); |
165 | } | 166 | } |
166 | else if (fr == 0) | 167 | else if (fr == 0) |
167 | { | 168 | { |
168 | int key, max; | 169 | int key, max; |
169 | fd_set fdr; | 170 | fd_set fdr; |
170 | char buffer[10]; | 171 | char buffer[10]; |
171 | 172 | ||
172 | key = open("/dev/touchscreen/key", O_RDONLY); | 173 | key = open("/dev/touchscreen/key", O_RDONLY); |
173 | if (key == -1) | 174 | if (key == -1) |
174 | { | 175 | { |
175 | qWarning("Could not open key"); | 176 | qWarning("Could not open key"); |
176 | exit(1); | 177 | exit(1); |
177 | } | 178 | } |
178 | 179 | ||
179 | while(1) | 180 | while(1) |
180 | { | 181 | { |
181 | FD_ZERO(&fdr); | 182 | FD_ZERO(&fdr); |
182 | FD_SET(key, &fdr); | 183 | FD_SET(key, &fdr); |
183 | max = key; | 184 | max = key; |
184 | 185 | ||
185 | qWarning("while"); | 186 | qWarning("while"); |
186 | 187 | ||
187 | read(key, buffer, 10); | 188 | read(key, buffer, 10); |
188 | if(*buffer == (char)129) | 189 | if(*buffer == (char)129) |
189 | { | 190 | { |
190 | qWarning("REC = stop"); | 191 | qWarning("REC = stop"); |
191 | QCopEnvelope( "QPE/VMemo", "toggleRecord()"); | 192 | QCopEnvelope( "QPE/VMemo", "toggleRecord()"); |
192 | activate_signal("toggleRecordNow()"); | 193 | QCopEnvelope( "QPE/VMemo", "sayHi()"); |
193 | } | 194 | } |
194 | else if(*buffer == (char)1) | 195 | else if(*buffer == (char)1) |
195 | { | 196 | { |
196 | qWarning("REC = start"); | 197 | qWarning("REC = start"); |
197 | QCopEnvelope( "QPE/VMemo", "toggleRecord()"); | 198 | QCopEnvelope( "QPE/VMemo", "toggleRecord()"); |
198 | activate_signal("toggleRecordNow()"); | 199 | QCopEnvelope( "QPE/VMemo", "sayHi()"); |
199 | } | 200 | } |
200 | } | 201 | } |
201 | } | 202 | } |
202 | else if(fr) | 203 | else if(fr) |
203 | qWarning("parent: Fork = good"); | 204 | qWarning("parent: Fork = good"); |
204 | } | 205 | } |
205 | } | 206 | } |
206 | qWarning("VMemo done init"); | 207 | qWarning("VMemo done init"); |
207 | } | 208 | } |
208 | 209 | ||
209 | VMemo::~VMemo() | 210 | VMemo::~VMemo() |
210 | { | 211 | { |
211 | } | 212 | } |
212 | 213 | ||
214 | void VMemo::sayHi() | ||
215 | { | ||
216 | qWarning("Hi"); | ||
217 | } | ||
218 | |||
213 | void VMemo::receive( const QCString &msg, const QByteArray &data ) | 219 | void VMemo::receive( const QCString &msg, const QByteArray &data ) |
214 | { | 220 | { |
215 | QDataStream stream( data, IO_ReadOnly ); | 221 | QDataStream stream( data, IO_ReadOnly ); |
216 | qWarning(msg); | 222 | qWarning(msg); |
217 | if ( msg == "toggleRecord()" ) { | 223 | if ( msg == "toggleRecord()" ) { |
218 | qWarning("Hello"); | 224 | qWarning("Hello"); |
219 | } | 225 | } |
220 | } | 226 | } |
221 | 227 | ||
222 | void VMemo::paintEvent( QPaintEvent* ) | 228 | void VMemo::paintEvent( QPaintEvent* ) |
223 | { | 229 | { |
224 | QPainter p(this); | 230 | QPainter p(this); |
225 | p.drawPixmap( 0, 1,( const char** ) vmemo_xpm ); | 231 | p.drawPixmap( 0, 1,( const char** ) vmemo_xpm ); |
226 | } | 232 | } |
227 | 233 | ||
228 | void VMemo::mousePressEvent( QMouseEvent * ) | 234 | void VMemo::mousePressEvent( QMouseEvent * ) |
229 | { | 235 | { |
236 | QCopEnvelope( "QPE/VMemo", "sayHi()"); | ||
237 | |||
230 | // just to be safe | 238 | // just to be safe |
231 | if (recording) | 239 | if (recording) |
232 | { | 240 | { |
233 | recording = FALSE; | 241 | recording = FALSE; |
234 | return; | 242 | return; |
235 | } | 243 | } |
236 | 244 | ||
237 | qWarning("VMemo::mousePress()"); | 245 | qWarning("VMemo::mousePress()"); |
238 | QSound::play(Resource::findSound("vmemob")); | 246 | QSound::play(Resource::findSound("vmemob")); |
239 | 247 | ||
240 | recording = TRUE; | 248 | recording = TRUE; |
241 | qWarning("VMemo::mousePress() -> Starting to record"); | 249 | qWarning("VMemo::mousePress() -> Starting to record"); |
242 | if (openDSP() == -1) | 250 | if (openDSP() == -1) |
243 | { | 251 | { |
244 | // ### Display an error box | 252 | // ### Display an error box |
245 | QMessageBox::critical(0, "VMemo", "Could not open dsp device.", "Abort"); | 253 | QMessageBox::critical(0, "VMemo", "Could not open dsp device.", "Abort"); |
246 | recording = FALSE; | 254 | recording = FALSE; |
247 | return; | 255 | return; |
248 | } | 256 | } |
249 | 257 | ||
250 | Config vmCfg("VMemo"); | 258 | Config vmCfg("VMemo"); |
251 | vmCfg.setGroup("Defaults"); | 259 | vmCfg.setGroup("Defaults"); |
252 | 260 | ||
253 | QDateTime dt = QDateTime::currentDateTime(); | 261 | QDateTime dt = QDateTime::currentDateTime(); |
254 | QString fileName; | 262 | QString fileName; |
255 | if(systemZaurus) | 263 | if(systemZaurus) |
256 | fileName=vmCfg.readEntry("Dir", "/mnt/cf/"); // zaurus does not have /mnt/ramfs | 264 | fileName=vmCfg.readEntry("Dir", "/mnt/cf/"); // zaurus does not have /mnt/ramfs |
257 | else | 265 | else |
258 | fileName=vmCfg.readEntry("Dir", "/mnt/ramfs/"); | 266 | fileName=vmCfg.readEntry("Dir", "/mnt/ramfs/"); |
259 | 267 | ||
260 | fileName += "vm_"; | 268 | fileName += "vm_"; |
261 | fileName += dt.toString(); | 269 | fileName += dt.toString(); |
262 | fileName += ".wav"; | 270 | fileName += ".wav"; |
263 | 271 | ||
264 | // No spaces in the filename | 272 | // No spaces in the filename |
265 | fileName.replace(QRegExp("'"),""); | 273 | fileName.replace(QRegExp("'"),""); |
266 | fileName.replace(QRegExp(" "),"_"); | 274 | fileName.replace(QRegExp(" "),"_"); |
267 | fileName.replace(QRegExp(":"),"."); | 275 | fileName.replace(QRegExp(":"),"."); |
268 | fileName.replace(QRegExp(","),""); | 276 | fileName.replace(QRegExp(","),""); |
269 | 277 | ||
270 | if(openWAV(fileName.latin1()) == -1) | 278 | if(openWAV(fileName.latin1()) == -1) |
271 | { | 279 | { |
272 | // ### Display an error box | 280 | // ### Display an error box |
273 | qWarning("VMemo::mousePress() -> WAV error"); | 281 | qWarning("VMemo::mousePress() -> WAV error"); |
274 | close(dsp); | 282 | close(dsp); |
275 | return; | 283 | return; |
276 | } | 284 | } |
277 | 285 | ||
278 | QArray<int> cats(1); | 286 | QArray<int> cats(1); |
279 | cats[0] = vmCfg.readNumEntry("Category", 0); | 287 | cats[0] = vmCfg.readNumEntry("Category", 0); |
280 | 288 | ||
281 | QString dlName("vm_"); | 289 | QString dlName("vm_"); |
282 | dlName += dt.toString(); | 290 | dlName += dt.toString(); |
283 | DocLnk l; | 291 | DocLnk l; |
284 | l.setFile(fileName); | 292 | l.setFile(fileName); |
285 | l.setName(dlName); | 293 | l.setName(dlName); |
286 | l.setType("audio/x-wav"); | 294 | l.setType("audio/x-wav"); |
287 | l.setCategories(cats); | 295 | l.setCategories(cats); |
288 | l.writeLink(); | 296 | l.writeLink(); |
289 | 297 | ||
290 | record(); | 298 | record(); |
291 | } | 299 | } |
292 | 300 | ||
293 | void VMemo::mouseReleaseEvent( QMouseEvent * ) | 301 | void VMemo::mouseReleaseEvent( QMouseEvent * ) |
294 | { | 302 | { |
295 | qWarning("VMemo::mouseRelese() -> Done recording"); | 303 | qWarning("VMemo::mouseRelese() -> Done recording"); |
296 | recording = FALSE; | 304 | recording = FALSE; |
297 | } | 305 | } |
298 | 306 | ||
299 | int VMemo::openDSP() | 307 | int VMemo::openDSP() |
300 | { | 308 | { |
301 | Config cfg("Sound"); | 309 | Config cfg("Sound"); |
302 | cfg.setGroup("Record"); | 310 | cfg.setGroup("Record"); |
303 | 311 | ||
304 | speed = cfg.readNumEntry("SampleRate", 22050); | 312 | speed = cfg.readNumEntry("SampleRate", 22050); |
305 | channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) | 313 | channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) |
306 | if (cfg.readNumEntry("SixteenBit", 1)==1) | 314 | if (cfg.readNumEntry("SixteenBit", 1)==1) |
307 | { | 315 | { |
308 | format = AFMT_S16_LE; | 316 | format = AFMT_S16_LE; |
309 | resolution = 16; | 317 | resolution = 16; |
310 | } | 318 | } |
311 | else | 319 | else |
312 | { | 320 | { |
313 | format = AFMT_U8; | 321 | format = AFMT_U8; |
314 | resolution = 8; | 322 | resolution = 8; |
315 | } | 323 | } |
316 | 324 | ||
317 | if(systemZaurus) | 325 | if(systemZaurus) |
318 | { | 326 | { |
319 | dsp = open("/dev/dsp1", O_RDWR); //Zaurus needs /dev/dsp1 | 327 | dsp = open("/dev/dsp1", O_RDWR); //Zaurus needs /dev/dsp1 |
320 | channels=1; //zaurus has one input channel | 328 | channels=1; //zaurus has one input channel |
321 | } | 329 | } |
322 | else | 330 | else |
323 | dsp = open("/dev/dsp", O_RDWR); | 331 | dsp = open("/dev/dsp", O_RDWR); |
324 | 332 | ||
325 | if(dsp == -1) | 333 | if(dsp == -1) |
326 | { | 334 | { |
327 | perror("open(\"/dev/dsp\")"); | 335 | perror("open(\"/dev/dsp\")"); |
328 | return -1; | 336 | return -1; |
329 | } | 337 | } |
330 | 338 | ||
331 | if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) | 339 | if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) |
332 | { | 340 | { |
333 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); | 341 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); |
334 | return -1; | 342 | return -1; |
335 | } | 343 | } |
336 | if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) | 344 | if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) |
337 | { | 345 | { |
338 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); | 346 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); |
339 | return -1; | 347 | return -1; |
340 | } | 348 | } |
341 | if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) | 349 | if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) |
342 | { | 350 | { |
343 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); | 351 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); |
344 | return -1; | 352 | return -1; |
345 | } | 353 | } |
346 | if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) | 354 | if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) |
347 | { | 355 | { |
348 | perror("ioctl(\"SOUND_PCM_READ_RATE\")"); | 356 | perror("ioctl(\"SOUND_PCM_READ_RATE\")"); |
349 | return -1; | 357 | return -1; |
350 | } | 358 | } |
351 | 359 | ||
352 | return 1; | 360 | return 1; |
353 | } | 361 | } |
354 | 362 | ||
355 | int VMemo::openWAV(const char *filename) | 363 | int VMemo::openWAV(const char *filename) |
356 | { | 364 | { |
357 | qDebug("Creating %s ",filename); | 365 | qDebug("Creating %s ",filename); |
358 | track.setName(filename); | 366 | track.setName(filename); |
359 | if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) | 367 | if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) |
360 | { | 368 | { |
361 | qDebug("Could not open file"); | 369 | qDebug("Could not open file"); |
362 | return -1; | 370 | return -1; |
363 | } | 371 | } |
364 | wav=track.handle(); | 372 | wav=track.handle(); |
365 | 373 | ||
366 | WaveHeader wh; | 374 | WaveHeader wh; |
367 | 375 | ||
368 | wh.main_chunk = RIFF; | 376 | wh.main_chunk = RIFF; |
369 | wh.length=0; | 377 | wh.length=0; |
370 | wh.chunk_type = WAVE; | 378 | wh.chunk_type = WAVE; |
371 | wh.sub_chunk = FMT; | 379 | wh.sub_chunk = FMT; |
372 | wh.sc_len = 16; | 380 | wh.sc_len = 16; |
373 | wh.format = PCM_CODE; | 381 | wh.format = PCM_CODE; |
374 | wh.modus = channels; | 382 | wh.modus = channels; |
375 | wh.sample_fq = speed; | 383 | wh.sample_fq = speed; |
376 | wh.byte_p_sec = speed * channels * resolution/8; | 384 | wh.byte_p_sec = speed * channels * resolution/8; |
377 | wh.byte_p_spl = channels * (resolution / 8); | 385 | wh.byte_p_spl = channels * (resolution / 8); |
378 | wh.bit_p_spl = resolution; | 386 | wh.bit_p_spl = resolution; |
379 | wh.data_chunk = DATA; | 387 | wh.data_chunk = DATA; |
380 | wh.data_length= 0; | 388 | wh.data_length= 0; |
381 | // qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d" | 389 | // qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d" |
382 | // , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl ); | 390 | // , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl ); |
383 | write (wav, &wh, sizeof(WaveHeader)); | 391 | write (wav, &wh, sizeof(WaveHeader)); |
384 | 392 | ||
385 | return 1; | 393 | return 1; |
386 | } | 394 | } |
387 | 395 | ||
388 | void VMemo::record(void) | 396 | void VMemo::record(void) |
389 | { | 397 | { |
390 | int length=0, result, value; | 398 | int length=0, result, value; |
391 | char sound[8192]; | 399 | char sound[8192]; |
392 | 400 | ||
393 | qWarning("VMemo::record()"); | 401 | qWarning("VMemo::record()"); |
394 | 402 | ||
395 | while(recording) | 403 | while(recording) |
396 | { | 404 | { |
397 | result = read(dsp, sound, 512); // 8192 | 405 | result = read(dsp, sound, 512); // 8192 |
398 | qApp->processEvents(); | 406 | qApp->processEvents(); |
399 | write(wav, sound, result); | 407 | write(wav, sound, result); |
400 | qApp->processEvents(); | 408 | qApp->processEvents(); |
401 | length += result; | 409 | length += result; |
402 | qApp->processEvents(); | 410 | qApp->processEvents(); |
403 | // printf("%d\r",length); | 411 | // printf("%d\r",length); |
404 | // fflush(stdout); | 412 | // fflush(stdout); |
405 | } | 413 | } |
406 | 414 | ||
407 | qWarning("VMemo::record() -> Done recording"); | 415 | qWarning("VMemo::record() -> Done recording"); |
408 | qWarning("VMemo::record() -> Closing dsp"); | 416 | qWarning("VMemo::record() -> Closing dsp"); |
409 | 417 | ||
410 | value = length+36; | 418 | value = length+36; |
411 | lseek(wav, 4, SEEK_SET); | 419 | lseek(wav, 4, SEEK_SET); |
412 | write(wav, &value, 4); | 420 | write(wav, &value, 4); |
413 | lseek(wav, 40, SEEK_SET); | 421 | lseek(wav, 40, SEEK_SET); |
414 | write(wav, &length, 4); | 422 | write(wav, &length, 4); |
415 | // qDebug("File length %d, samplecount %d", value, length); | 423 | // qDebug("File length %d, samplecount %d", value, length); |
416 | track.close(); | 424 | track.close(); |
417 | 425 | ||
418 | if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) | 426 | if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) |
419 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); | 427 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); |
420 | ::close(dsp); | 428 | ::close(dsp); |
421 | 429 | ||
422 | qWarning("VMemo::record() -> playing done recording sound"); | 430 | qWarning("VMemo::record() -> playing done recording sound"); |
423 | QSound::play(Resource::findSound("vmemoe")); | 431 | QSound::play(Resource::findSound("vmemoe")); |
424 | qWarning("VMemo::record() -> terminating"); | 432 | qWarning("VMemo::record() -> terminating"); |
425 | QMessageBox::information(0, "VMemo", "Recording Done", 1); | 433 | QMessageBox::information(0, "VMemo", "Recording Done", 1); |
426 | } | 434 | } |
diff --git a/core/applets/vmemo/vmemo.h b/core/applets/vmemo/vmemo.h index d96cd94..824309e 100644 --- a/core/applets/vmemo/vmemo.h +++ b/core/applets/vmemo/vmemo.h | |||
@@ -1,54 +1,55 @@ | |||
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 | #include <qwidget.h> | 20 | #include <qwidget.h> |
21 | #include <qpixmap.h> | 21 | #include <qpixmap.h> |
22 | #include <qpe/applnk.h> | 22 | #include <qpe/applnk.h> |
23 | #include <qfile.h> | 23 | #include <qfile.h> |
24 | #include <qpe/qcopenvelope_qws.h> | 24 | #include <qpe/qcopenvelope_qws.h> |
25 | 25 | ||
26 | class VMemo : public QWidget | 26 | class VMemo : public QWidget |
27 | { | 27 | { |
28 | Q_OBJECT | 28 | Q_OBJECT |
29 | public: | 29 | public: |
30 | VMemo( QWidget *parent, const char *name = NULL); | 30 | VMemo( QWidget *parent, const char *name = NULL); |
31 | ~VMemo(); | 31 | ~VMemo(); |
32 | QFile track; | 32 | QFile track; |
33 | 33 | ||
34 | public slots: | 34 | public slots: |
35 | void record(); | 35 | void record(); |
36 | void mousePressEvent( QMouseEvent * ); | 36 | void mousePressEvent( QMouseEvent * ); |
37 | void mouseReleaseEvent( QMouseEvent * ); | 37 | void mouseReleaseEvent( QMouseEvent * ); |
38 | void receive( const QCString &msg, const QByteArray &data ); | 38 | void receive( const QCString &msg, const QByteArray &data ); |
39 | void sayHi(); | ||
39 | 40 | ||
40 | private: | 41 | private: |
41 | void paintEvent( QPaintEvent* ); | 42 | void paintEvent( QPaintEvent* ); |
42 | 43 | ||
43 | int openDSP(); | 44 | int openDSP(); |
44 | int openWAV(const char *filename); | 45 | int openWAV(const char *filename); |
45 | 46 | ||
46 | QPixmap vmemoPixmap; | 47 | QPixmap vmemoPixmap; |
47 | QCopChannel *myChannel; | 48 | QCopChannel *myChannel; |
48 | bool systemZaurus; | 49 | bool systemZaurus; |
49 | int dsp, wav, rate, speed, channels, format, resolution; | 50 | int dsp, wav, rate, speed, channels, format, resolution; |
50 | bool recording; | 51 | bool recording; |
51 | }; | 52 | }; |
52 | 53 | ||
53 | #endif // __VMEMO_H__ | 54 | #endif // __VMEMO_H__ |
54 | 55 | ||