-rw-r--r-- | core/applets/vmemo/vmemo.cpp | 66 | ||||
-rw-r--r-- | core/applets/vmemo/vmemo.h | 1 |
2 files changed, 45 insertions, 22 deletions
diff --git a/core/applets/vmemo/vmemo.cpp b/core/applets/vmemo/vmemo.cpp index 4d4d598..4c55dc7 100644 --- a/core/applets/vmemo/vmemo.cpp +++ b/core/applets/vmemo/vmemo.cpp | |||
@@ -16,24 +16,26 @@ | |||
16 | // Sun 03-17-2002 L.J.Potter <ljp@llornkcor.com> | 16 | // Sun 03-17-2002 L.J.Potter <ljp@llornkcor.com> |
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 | #include <errno.h> | ||
29 | #include <string.h> | ||
28 | 30 | ||
29 | typedef struct _waveheader { | 31 | typedef struct _waveheader { |
30 | u_long main_chunk; /* 'RIFF' */ | 32 | u_long main_chunk; /* 'RIFF' */ |
31 | u_long length; /* filelen */ | 33 | u_long length; /* filelen */ |
32 | u_long chunk_type; /* 'WAVE' */ | 34 | u_long chunk_type; /* 'WAVE' */ |
33 | u_long sub_chunk; /* 'fmt ' */ | 35 | u_long sub_chunk; /* 'fmt ' */ |
34 | u_long sc_len; /* length of sub_chunk, =16 | 36 | u_long sc_len; /* length of sub_chunk, =16 |
35 | (chunckSize) format len */ | 37 | (chunckSize) format len */ |
36 | u_short format; /* should be 1 for PCM-code (formatTag) */ | 38 | u_short format; /* should be 1 for PCM-code (formatTag) */ |
37 | 39 | ||
38 | u_short modus; /* 1 Mono, 2 Stereo (channels) */ | 40 | u_short modus; /* 1 Mono, 2 Stereo (channels) */ |
39 | u_long sample_fq; /* samples per second (samplesPerSecond) */ | 41 | u_long sample_fq; /* samples per second (samplesPerSecond) */ |
@@ -246,67 +248,79 @@ void VMemo::mousePressEvent( QMouseEvent *me ) | |||
246 | if (recording) { | 248 | if (recording) { |
247 | recording = FALSE; | 249 | recording = FALSE; |
248 | return; | 250 | return; |
249 | } | 251 | } |
250 | 252 | ||
251 | /* | 253 | /* |
252 | No mousePress/mouseRelease recording on the iPAQ. The REC button on the iPAQ calls these functions | 254 | No mousePress/mouseRelease recording on the iPAQ. The REC button on the iPAQ calls these functions |
253 | mousePressEvent and mouseReleaseEvent with a NULL parameter. | 255 | mousePressEvent and mouseReleaseEvent with a NULL parameter. |
254 | */ | 256 | */ |
255 | if (!systemZaurus && me != NULL) | 257 | if (!systemZaurus && me != NULL) |
256 | return; | 258 | return; |
257 | 259 | ||
258 | // Config config( "Sound" ); | 260 | Config config( "Sound" ); |
259 | // config.setGroup( "System" ); | 261 | config.setGroup( "System" ); |
260 | // useAlerts = config.readBoolEntry("Alert"); | 262 | useAlerts = config.readBoolEntry("Alert"); |
261 | 263 | ||
262 | // if(useAlerts) { | 264 | // if(useAlerts) |
263 | // if( QMessageBox::warning(this,"VMemo","Really Record?","Yes","No",0,0,1) ==1) | 265 | // QMessageBox::message("VMemo","Really Record?");//) ==1) |
264 | // return; | 266 | // return; |
265 | // } else { | 267 | // } else { |
266 | QSound::play(Resource::findSound("vmemob")); | 268 | QSound::play(Resource::findSound("vmemob")); |
267 | // } | 269 | // } |
268 | qDebug("Start recording"); | 270 | qDebug("Start recording"); |
269 | recording = TRUE; | 271 | recording = TRUE; |
270 | if (openDSP() == -1) { | 272 | if (openDSP() == -1) { |
271 | QMessageBox::critical(0, "VMemo", "Could not open dsp device.", "Abort"); | 273 | QMessageBox::critical(0, "VMemo", "Could not open dsp device.\n"+errorMsg, "Abort"); |
272 | recording = FALSE; | 274 | recording = FALSE; |
273 | return; | 275 | return; |
274 | } | 276 | } |
275 | 277 | ||
276 | Config vmCfg("VMemo"); | 278 | Config vmCfg("VMemo"); |
277 | vmCfg.setGroup("Defaults"); | 279 | vmCfg.setGroup("Defaults"); |
278 | 280 | ||
279 | QDateTime dt = QDateTime::currentDateTime(); | 281 | QDateTime dt = QDateTime::currentDateTime(); |
280 | QString fileName; | ||
281 | 282 | ||
282 | if(systemZaurus) | 283 | QString fName; |
283 | fileName=vmCfg.readEntry("Dir", "/mnt/cf/"); // zaurus does not have /mnt/ramfs | 284 | Config cfg( "Sound" ); |
284 | else | 285 | cfg.setGroup( "System" ); |
285 | fileName=vmCfg.readEntry("Dir", "/mnt/ramfs/"); | 286 | fileName = cfg.readEntry("RecLocation",QPEApplication::documentDir() ); |
286 | 287 | ||
287 | fileName += "vm_"; | 288 | int s; |
288 | fileName += dt.toString(); | 289 | s=fileName.find(':'); |
289 | fileName += ".wav"; | 290 | if(s) |
291 | fileName=fileName.right(fileName.length()-s-2)+"/"; | ||
290 | 292 | ||
293 | // if( !fileName.right(1).find('/') == -1) | ||
294 | // fileName+="/audio/"; | ||
295 | // else | ||
296 | // fileName+="audio/"; | ||
297 | |||
298 | // if(systemZaurus) | ||
299 | // fileName=vmCfg.readEntry("Dir", "/mnt/cf/"); // zaurus does not have /mnt/ramfs | ||
300 | // else | ||
301 | // fileName=vmCfg.readEntry("Dir", "/mnt/ramfs/"); | ||
302 | |||
303 | fName = "vm_"+ dt.toString()+ ".wav"; | ||
304 | fileName+=fName; | ||
305 | qDebug("filename is "+fileName); | ||
291 | // No spaces in the filename | 306 | // No spaces in the filename |
292 | fileName.replace(QRegExp("'"),""); | 307 | fileName.replace(QRegExp("'"),""); |
293 | fileName.replace(QRegExp(" "),"_"); | 308 | fileName.replace(QRegExp(" "),"_"); |
294 | fileName.replace(QRegExp(":"),"."); | 309 | fileName.replace(QRegExp(":"),"."); |
295 | fileName.replace(QRegExp(","),""); | 310 | fileName.replace(QRegExp(","),""); |
296 | 311 | ||
297 | if(openWAV(fileName.latin1()) == -1) { | 312 | if(openWAV(fileName.latin1()) == -1) { |
298 | QString err("Could not open the output file: "); | 313 | QString err("Could not open the output file\n"); |
299 | err += fileName; | 314 | err += fileName; |
300 | |||
301 | QMessageBox::critical(0, "VMemo", err, "Abort"); | 315 | QMessageBox::critical(0, "VMemo", err, "Abort"); |
302 | close(dsp); | 316 | close(dsp); |
303 | return; | 317 | return; |
304 | } | 318 | } |
305 | 319 | ||
306 | QArray<int> cats(1); | 320 | QArray<int> cats(1); |
307 | cats[0] = vmCfg.readNumEntry("Category", 0); | 321 | cats[0] = vmCfg.readNumEntry("Category", 0); |
308 | 322 | ||
309 | QString dlName("vm_"); | 323 | QString dlName("vm_"); |
310 | dlName += dt.toString(); | 324 | dlName += dt.toString(); |
311 | DocLnk l; | 325 | DocLnk l; |
312 | l.setFile(fileName); | 326 | l.setFile(fileName); |
@@ -325,66 +339,75 @@ void VMemo::mouseReleaseEvent( QMouseEvent * ) | |||
325 | 339 | ||
326 | int VMemo::openDSP() | 340 | int VMemo::openDSP() |
327 | { | 341 | { |
328 | Config cfg("Sound"); | 342 | Config cfg("Sound"); |
329 | cfg.setGroup("Record"); | 343 | cfg.setGroup("Record"); |
330 | 344 | ||
331 | speed = cfg.readNumEntry("SampleRate", 22050); | 345 | speed = cfg.readNumEntry("SampleRate", 22050); |
332 | channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) | 346 | channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) |
333 | if (cfg.readNumEntry("SixteenBit", 1)==1) { | 347 | if (cfg.readNumEntry("SixteenBit", 1)==1) { |
334 | format = AFMT_S16_LE; | 348 | format = AFMT_S16_LE; |
335 | resolution = 16; | 349 | resolution = 16; |
336 | } else { | 350 | } else { |
337 | format = AFMT_S8; | 351 | format = AFMT_U8; |
338 | resolution = 8; | 352 | resolution = 8; |
339 | } | 353 | } |
340 | 354 | ||
355 | qDebug("samplerate: %d, channels %d, resolution %d", speed, channels, resolution); | ||
341 | 356 | ||
342 | if(systemZaurus) { | 357 | if(systemZaurus) { |
343 | dsp = open("/dev/dsp1", O_RDWR); //Zaurus needs /dev/dsp1 | 358 | dsp = open("/dev/dsp1", O_RDWR); //Zaurus needs /dev/dsp1 |
344 | channels=1; //zaurus has one input channel | 359 | channels=1; //zaurus has one input channel |
345 | } else { | 360 | } else { |
346 | dsp = open("/dev/dsp", O_RDWR); | 361 | dsp = open("/dev/dsp", O_RDWR); |
347 | } | 362 | } |
348 | 363 | ||
349 | if(dsp == -1) { | 364 | if(dsp == -1) { |
350 | perror("open(\"/dev/dsp\")"); | 365 | perror("open(\"/dev/dsp\")"); |
366 | |||
367 | errorMsg="open(\"/dev/dsp\")\n "+(QString)strerror(errno); | ||
351 | return -1; | 368 | return -1; |
352 | } | 369 | } |
353 | 370 | ||
354 | if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) { | 371 | if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) { |
355 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); | 372 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); |
373 | errorMsg="ioctl(\"SNDCTL_DSP_SETFMT\")\n%d\n"+(QString)strerror(errno),format; | ||
356 | return -1; | 374 | return -1; |
357 | } | 375 | } |
358 | if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) { | 376 | if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) { |
359 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); | 377 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); |
378 | errorMsg="ioctl(\"SNDCTL_DSP_CHANNELS\")\n%d\n"+(QString)strerror(errno),channels; | ||
360 | return -1; | 379 | return -1; |
361 | } | 380 | } |
362 | if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) { | 381 | if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) { |
363 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); | 382 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); |
383 | errorMsg="ioctl(\"SNDCTL_DSP_SPEED\")\n%d\n"+(QString)strerror(errno),speed; | ||
364 | return -1; | 384 | return -1; |
365 | } | 385 | } |
366 | if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) { | 386 | if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) { |
367 | perror("ioctl(\"SOUND_PCM_READ_RATE\")"); | 387 | perror("ioctl(\"SOUND_PCM_READ_RATE\")"); |
388 | errorMsg="ioctl(\"SOUND_PCM_READ_RATE\")\n%d\n"+(QString)strerror(errno),rate; | ||
368 | return -1; | 389 | return -1; |
369 | } | 390 | } |
370 | 391 | ||
371 | return 1; | 392 | return 1; |
372 | } | 393 | } |
373 | 394 | ||
374 | int VMemo::openWAV(const char *filename) | 395 | int VMemo::openWAV(const char *filename) |
375 | { | 396 | { |
376 | track.setName(filename); | 397 | track.setName(filename); |
377 | if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) | 398 | if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) { |
399 | errorMsg=filename; | ||
378 | return -1; | 400 | return -1; |
401 | } | ||
379 | 402 | ||
380 | wav=track.handle(); | 403 | wav=track.handle(); |
381 | 404 | ||
382 | WaveHeader wh; | 405 | WaveHeader wh; |
383 | 406 | ||
384 | wh.main_chunk = RIFF; | 407 | wh.main_chunk = RIFF; |
385 | wh.length=0; | 408 | wh.length=0; |
386 | wh.chunk_type = WAVE; | 409 | wh.chunk_type = WAVE; |
387 | wh.sub_chunk = FMT; | 410 | wh.sub_chunk = FMT; |
388 | wh.sc_len = 16; | 411 | wh.sc_len = 16; |
389 | wh.format = PCM_CODE; | 412 | wh.format = PCM_CODE; |
390 | wh.modus = channels; | 413 | wh.modus = channels; |
@@ -421,25 +444,25 @@ void VMemo::record(void) | |||
421 | length+=write(wav, monoBuffer, result); | 444 | length+=write(wav, monoBuffer, result); |
422 | } else { //ipaq /stereo inputs | 445 | } else { //ipaq /stereo inputs |
423 | for (int i = 0; i < result; i+=2) { | 446 | for (int i = 0; i < result; i+=2) { |
424 | monoBuffer[j] = (sound[i]+sound[i+1])/2; | 447 | monoBuffer[j] = (sound[i]+sound[i+1])/2; |
425 | j++; | 448 | j++; |
426 | } | 449 | } |
427 | qApp->processEvents(); | 450 | qApp->processEvents(); |
428 | length+=write(wav, monoBuffer, result/2); | 451 | length+=write(wav, monoBuffer, result/2); |
429 | } | 452 | } |
430 | printf("%d\r",length); | 453 | printf("%d\r",length); |
431 | fflush(stdout); | 454 | fflush(stdout); |
432 | } | 455 | } |
433 | } else { //AFMT_S8 | 456 | } else { //AFMT_U8 |
434 | // 8bit unsigned | 457 | // 8bit unsigned |
435 | unsigned short sound[512], monoBuffer[512]; | 458 | unsigned short sound[512], monoBuffer[512]; |
436 | while(recording) { | 459 | while(recording) { |
437 | result = read(dsp, sound, 512); // 8192 | 460 | result = read(dsp, sound, 512); // 8192 |
438 | qApp->processEvents(); | 461 | qApp->processEvents(); |
439 | int j=0; | 462 | int j=0; |
440 | if(systemZaurus) { | 463 | if(systemZaurus) { |
441 | for (int i = 0; i < result; i++) { //since Z is mono do normally | 464 | for (int i = 0; i < result; i++) { //since Z is mono do normally |
442 | monoBuffer[i] = sound[i]; | 465 | monoBuffer[i] = sound[i]; |
443 | } | 466 | } |
444 | qApp->processEvents(); | 467 | qApp->processEvents(); |
445 | length+=write(wav, monoBuffer, result); | 468 | length+=write(wav, monoBuffer, result); |
@@ -482,17 +505,16 @@ void VMemo::record(void) | |||
482 | } | 505 | } |
483 | 506 | ||
484 | value = length+36; | 507 | value = length+36; |
485 | lseek(wav, 4, SEEK_SET); | 508 | lseek(wav, 4, SEEK_SET); |
486 | write(wav, &value, 4); | 509 | write(wav, &value, 4); |
487 | lseek(wav, 40, SEEK_SET); | 510 | lseek(wav, 40, SEEK_SET); |
488 | write(wav, &length, 4); | 511 | write(wav, &length, 4); |
489 | track.close(); | 512 | track.close(); |
490 | 513 | ||
491 | if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) | 514 | if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) |
492 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); | 515 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); |
493 | ::close(dsp); | 516 | ::close(dsp); |
494 | // if(useAlerts) | 517 | if(useAlerts) |
495 | // QMessageBox::message("Vmemo"," Done recording"); | 518 | QMessageBox::message("Vmemo"," Done recording\n"+ fileName); |
496 | // else | ||
497 | QSound::play(Resource::findSound("vmemoe")); | 519 | QSound::play(Resource::findSound("vmemoe")); |
498 | } | 520 | } |
diff --git a/core/applets/vmemo/vmemo.h b/core/applets/vmemo/vmemo.h index f30476f..3972877 100644 --- a/core/applets/vmemo/vmemo.h +++ b/core/applets/vmemo/vmemo.h | |||
@@ -21,24 +21,25 @@ | |||
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 | QString fileName, errorMsg; | ||
33 | 34 | ||
34 | public slots: | 35 | public slots: |
35 | void record(); | 36 | void record(); |
36 | void mousePressEvent( QMouseEvent * ); | 37 | void mousePressEvent( QMouseEvent * ); |
37 | void mouseReleaseEvent( QMouseEvent * ); | 38 | void mouseReleaseEvent( QMouseEvent * ); |
38 | void receive( const QCString &msg, const QByteArray &data ); | 39 | void receive( const QCString &msg, const QByteArray &data ); |
39 | 40 | ||
40 | private: | 41 | private: |
41 | bool useAlerts; | 42 | bool useAlerts; |
42 | void paintEvent( QPaintEvent* ); | 43 | void paintEvent( QPaintEvent* ); |
43 | 44 | ||
44 | int openDSP(); | 45 | int openDSP(); |