summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/vmemo/vmemo.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/core/applets/vmemo/vmemo.cpp b/core/applets/vmemo/vmemo.cpp
index e25a1ab..10a947e 100644
--- a/core/applets/vmemo/vmemo.cpp
+++ b/core/applets/vmemo/vmemo.cpp
@@ -288,330 +288,330 @@ bool VMemo::startRecording() {
288 // QMessageBox::message("VMemo","Really Record?");//) ==1) 288 // QMessageBox::message("VMemo","Really Record?");//) ==1)
289 // return; 289 // return;
290 // } else { 290 // } else {
291 // if (!systemZaurus ) 291 // if (!systemZaurus )
292 // QSound::play(Resource::findSound("vmemob")); 292 // QSound::play(Resource::findSound("vmemob"));
293 // } 293 // }
294 qDebug("Start recording engines"); 294 qDebug("Start recording engines");
295 recording = TRUE; 295 recording = TRUE;
296 296
297 if (openDSP() == -1) { 297 if (openDSP() == -1) {
298 // QMessageBox::critical(0, "vmemo", "Could not open dsp device.\n"+errorMsg, "Abort"); 298 // QMessageBox::critical(0, "vmemo", "Could not open dsp device.\n"+errorMsg, "Abort");
299 // delete msgLabel; 299 // delete msgLabel;
300 recording = FALSE; 300 recording = FALSE;
301 return FALSE; 301 return FALSE;
302 } 302 }
303 303
304 config.setGroup("Defaults"); 304 config.setGroup("Defaults");
305 305
306 QDateTime dt = QDateTime::currentDateTime(); 306 QDateTime dt = QDateTime::currentDateTime();
307 307
308 QString fName; 308 QString fName;
309 config.setGroup( "System" ); 309 config.setGroup( "System" );
310 fName = QPEApplication::documentDir() ; 310 fName = QPEApplication::documentDir() ;
311 fileName = config.readEntry("RecLocation", fName); 311 fileName = config.readEntry("RecLocation", fName);
312 312
313 int s; 313 int s;
314 s=fileName.find(':'); 314 s=fileName.find(':');
315 if(s) 315 if(s)
316 fileName=fileName.right(fileName.length()-s-2); 316 fileName=fileName.right(fileName.length()-s-2);
317 qDebug("filename will be "+fileName); 317 qDebug("filename will be "+fileName);
318 if( fileName.left(1).find('/') == -1) 318 if( fileName.left(1).find('/') == -1)
319 fileName="/"+fileName; 319 fileName="/"+fileName;
320 if( fileName.right(1).find('/') == -1) 320 if( fileName.right(1).find('/') == -1)
321 fileName+="/"; 321 fileName+="/";
322 fName = "vm_"+ dt.toString()+ ".wav"; 322 fName = "vm_"+ dt.toString()+ ".wav";
323 323
324 fileName+=fName; 324 fileName+=fName;
325 qDebug("filename is "+fileName); 325 qDebug("filename is "+fileName);
326 // No spaces in the filename 326 // No spaces in the filename
327 fileName.replace(QRegExp("'"),""); 327 fileName.replace(QRegExp("'"),"");
328 fileName.replace(QRegExp(" "),"_"); 328 fileName.replace(QRegExp(" "),"_");
329 fileName.replace(QRegExp(":"),"."); 329 fileName.replace(QRegExp(":"),".");
330 fileName.replace(QRegExp(","),""); 330 fileName.replace(QRegExp(","),"");
331 331
332 if(openWAV(fileName.latin1()) == -1) { 332 if(openWAV(fileName.latin1()) == -1) {
333 // QString err("Could not open the output file\n"); 333 // QString err("Could not open the output file\n");
334 // err += fileName; 334 // err += fileName;
335 // QMessageBox::critical(0, "vmemo", err, "Abort"); 335 // QMessageBox::critical(0, "vmemo", err, "Abort");
336 close(dsp); 336 close(dsp);
337 return FALSE; 337 return FALSE;
338 } 338 }
339 339
340 QArray<int> cats(1); 340 QArray<int> cats(1);
341 cats[0] = config.readNumEntry("Category", 0); 341 cats[0] = config.readNumEntry("Category", 0);
342 342
343 QString dlName("vm_"); 343 QString dlName("vm_");
344 dlName += dt.toString(); 344 dlName += dt.toString();
345 DocLnk l; 345 DocLnk l;
346 l.setFile(fileName); 346 l.setFile(fileName);
347 l.setName(dlName); 347 l.setName(dlName);
348 l.setType("audio/x-wav"); 348 l.setType("audio/x-wav");
349 l.setCategories(cats); 349 l.setCategories(cats);
350 l.writeLink(); 350 l.writeLink();
351 351
352 352
353 record(); 353 record();
354 // delete msgLabel; 354 // delete msgLabel;
355 return TRUE; 355 return TRUE;
356} 356}
357 357
358void VMemo::stopRecording() { 358void VMemo::stopRecording() {
359 recording = FALSE; 359 recording = FALSE;
360 if(useAlerts) 360 if(useAlerts)
361 if( msgLabel) delete msgLabel; 361 if( msgLabel) delete msgLabel;
362} 362}
363 363
364int VMemo::openDSP() 364int VMemo::openDSP()
365{ 365{
366 Config cfg("Vmemo"); 366 Config cfg("Vmemo");
367 cfg.setGroup("Record"); 367 cfg.setGroup("Record");
368 368
369 speed = cfg.readNumEntry("SampleRate", 22050); 369 speed = cfg.readNumEntry("SampleRate", 22050);
370 channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) 370 channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1)
371 if (cfg.readNumEntry("SixteenBit", 1)==1) { 371 if (cfg.readNumEntry("SixteenBit", 1)==1) {
372 format = AFMT_S16_LE; 372 format = AFMT_S16_LE;
373 resolution = 16; 373 resolution = 16;
374 } else { 374 } else {
375 format = AFMT_U8; 375 format = AFMT_U8;
376 resolution = 8; 376 resolution = 8;
377 } 377 }
378 378
379 qDebug("samplerate: %d, channels %d, resolution %d", speed, channels, resolution); 379 qDebug("samplerate: %d, channels %d, resolution %d", speed, channels, resolution);
380 380
381 if(systemZaurus) { 381 if(systemZaurus) {
382 dsp = open("/dev/dsp1", O_RDWR); //Zaurus needs /dev/dsp1 382 dsp = open("/dev/dsp1", O_RDWR); //Zaurus needs /dev/dsp1
383 channels=1; //zaurus has one input channel 383 channels=1; //zaurus has one input channel
384 } else { 384 } else {
385 dsp = open("/dev/dsp", O_RDWR); 385 dsp = open("/dev/dsp", O_RDWR);
386 } 386 }
387 387
388 if(dsp == -1) { 388 if(dsp == -1) {
389 perror("open(\"/dev/dsp\")"); 389 perror("open(\"/dev/dsp\")");
390 errorMsg="open(\"/dev/dsp\")\n "+(QString)strerror(errno); 390 errorMsg="open(\"/dev/dsp\")\n "+(QString)strerror(errno);
391 QMessageBox::critical(0, "vmemo", errorMsg, "Abort"); 391 QMessageBox::critical(0, "vmemo", errorMsg, "Abort");
392 return -1; 392 return -1;
393 } 393 }
394 394
395 if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) { 395 if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) {
396 perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); 396 perror("ioctl(\"SNDCTL_DSP_SETFMT\")");
397 return -1; 397 return -1;
398 } 398 }
399 if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) { 399 if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) {
400 perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); 400 perror("ioctl(\"SNDCTL_DSP_CHANNELS\")");
401 return -1; 401 return -1;
402 } 402 }
403 if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) { 403 if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) {
404 perror("ioctl(\"SNDCTL_DSP_SPEED\")"); 404 perror("ioctl(\"SNDCTL_DSP_SPEED\")");
405 return -1; 405 return -1;
406 } 406 }
407 if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) { 407 if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) {
408 perror("ioctl(\"SOUND_PCM_READ_RATE\")"); 408 perror("ioctl(\"SOUND_PCM_READ_RATE\")");
409 return -1; 409 return -1;
410 } 410 }
411 411
412 return 1; 412 return 1;
413} 413}
414 414
415int VMemo::openWAV(const char *filename) 415int VMemo::openWAV(const char *filename)
416{ 416{
417 track.setName(filename); 417 track.setName(filename);
418 if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) { 418 if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) {
419 errorMsg=filename; 419 errorMsg=filename;
420 return -1; 420 return -1;
421 } 421 }
422 422
423 wav=track.handle(); 423 wav=track.handle();
424 424
425 WaveHeader wh; 425 WaveHeader wh;
426 426
427 wh.main_chunk = RIFF; 427 wh.main_chunk = RIFF;
428 wh.length=0; 428 wh.length=0;
429 wh.chunk_type = WAVE; 429 wh.chunk_type = WAVE;
430 wh.sub_chunk = FMT; 430 wh.sub_chunk = FMT;
431 wh.sc_len = 16; 431 wh.sc_len = 16;
432 wh.format = PCM_CODE; 432 wh.format = PCM_CODE;
433 wh.modus = channels; 433 wh.modus = channels;
434 wh.sample_fq = speed; 434 wh.sample_fq = speed;
435 wh.byte_p_sec = speed * channels * resolution/8; 435 wh.byte_p_sec = speed * channels * resolution/8;
436 wh.byte_p_spl = channels * (resolution / 8); 436 wh.byte_p_spl = channels * (resolution / 8);
437 wh.bit_p_spl = resolution; 437 wh.bit_p_spl = resolution;
438 wh.data_chunk = DATA; 438 wh.data_chunk = DATA;
439 wh.data_length= 0; 439 wh.data_length= 0;
440 // qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d" 440 // qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d"
441 // , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl ); 441 // , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl );
442 write (wav, &wh, sizeof(WaveHeader)); 442 write (wav, &wh, sizeof(WaveHeader));
443 443
444 return 1; 444 return 1;
445} 445}
446 446
447void VMemo::record(void) 447void VMemo::record(void)
448{ 448{
449 int length=0, result, value; 449 int length=0, result, value;
450 QString msg; 450 QString msg;
451 msg.sprintf("Recording format %d", format); 451 msg.sprintf("Recording format %d", format);
452 qDebug(msg); 452 qDebug(msg);
453 453
454 if(systemZaurus) { 454 if(systemZaurus) {
455 455
456 msg.sprintf("Recording format zaurus"); 456 msg.sprintf("Recording format zaurus");
457 qDebug(msg); 457 qDebug(msg);
458 signed short sound[512], monoBuffer[512]; 458 signed short sound[512], monoBuffer[512];
459 459
460 if(format==AFMT_S16_LE) { 460 if(format==AFMT_S16_LE) {
461 461
462 while(recording) { 462 while(recording) {
463 463
464 result = read(dsp, sound, 512); // 8192 464 result = read(dsp, sound, 512); // 8192
465 int j=0; 465 int j=0;
466 466
467 if(systemZaurus) { 467 if(systemZaurus) {
468 for (int i = 0; i < result; i++) { //since Z is mono do normally 468 for (int i = 0; i < result; i++) { //since Z is mono do normally
469 monoBuffer[i] = sound[i]; 469 monoBuffer[i] = sound[i];
470 } 470 }
471 471
472 length+=write(wav, monoBuffer, result); 472 length+=write(wav, monoBuffer, result);
473 if(length<0) 473 if(length<0)
474 recording=false; 474 recording=false;
475 475
476 } else { //ipaq /stereo inputs 476 } else { //ipaq /stereo inputs
477 477
478 478
479 for (int i = 0; i < result; i+=2) { 479 for (int i = 0; i < result; i+=2) {
480/ monoBuffer[j] = sound[i]; 480 monoBuffer[j] = sound[i];
481 // monoBuffer[j] = (sound[i]+sound[i+1])/2; 481 // monoBuffer[j] = (sound[i]+sound[i+1])/2;
482 482
483 j++; 483 j++;
484 } 484 }
485 485
486 length+=write(wav, monoBuffer, result); 486 length+=write(wav, monoBuffer, result);
487 if(length<0) 487 if(length<0)
488 recording=false; 488 recording=false;
489 // length+=write(wav, monoBuffer, result/2); 489 // length+=write(wav, monoBuffer, result/2);
490 } 490 }
491 qApp->processEvents(); 491 qApp->processEvents();
492// printf("%d\r",length); 492// printf("%d\r",length);
493// fflush(stdout); 493// fflush(stdout);
494 } 494 }
495 495
496} else { //AFMT_U8 496} else { //AFMT_U8
497 // 8bit unsigned 497 // 8bit unsigned
498 unsigned short sound[512], monoBuffer[512]; 498 unsigned short sound[512], monoBuffer[512];
499 while(recording) { 499 while(recording) {
500 result = read(dsp, sound, 512); // 8192 500 result = read(dsp, sound, 512); // 8192
501 int j=0; 501 int j=0;
502 502
503 if(systemZaurus) { 503 if(systemZaurus) {
504 504
505 for (int i = 0; i < result; i++) { //since Z is mono do normally 505 for (int i = 0; i < result; i++) { //since Z is mono do normally
506 monoBuffer[i] = sound[i]; 506 monoBuffer[i] = sound[i];
507 } 507 }
508 508
509 length+=write(wav, monoBuffer, result); 509 length+=write(wav, monoBuffer, result);
510 510
511 } else { //ipaq /stereo inputs 511 } else { //ipaq /stereo inputs
512 512
513 for (int i = 0; i < result; i+=2) { 513 for (int i = 0; i < result; i+=2) {
514 monoBuffer[j] = (sound[i]+sound[i+1])/2; 514 monoBuffer[j] = (sound[i]+sound[i+1])/2;
515 j++; 515 j++;
516 } 516 }
517 517
518 length+=write(wav, monoBuffer, result/2); 518 length+=write(wav, monoBuffer, result/2);
519 519
520 if(length<0) 520 if(length<0)
521 recording=false; 521 recording=false;
522 522
523 } 523 }
524 length += result; 524 length += result;
525// printf("%d\r",length); 525// printf("%d\r",length);
526// fflush(stdout); 526// fflush(stdout);
527 } 527 }
528 528
529 qApp->processEvents(); 529 qApp->processEvents();
530 } 530 }
531 531
532 } else { // this is specific for ipaqs that do not have 8 bit capabilities 532 } else { // this is specific for ipaqs that do not have 8 bit capabilities
533 533
534 msg.sprintf("Recording format other"); 534 msg.sprintf("Recording format other");
535 qDebug(msg); 535 qDebug(msg);
536 536
537 signed short sound[512], monoBuffer[512]; 537 signed short sound[512], monoBuffer[512];
538 538
539 while(recording) { 539 while(recording) {
540 540
541 result = read(dsp, sound, 512); // 8192 541 result = read(dsp, sound, 512); // 8192
542 542
543 write(wav, sound, result); 543 write(wav, sound, result);
544 length += result; 544 length += result;
545 if(length<0) { 545 if(length<0) {
546 546
547 recording=false; 547 recording=false;
548 perror("dev/dsp's is a lookin' messy"); 548 perror("dev/dsp's is a lookin' messy");
549 QMessageBox::message("Vmemo"," Done1 recording\n"+ fileName); 549 QMessageBox::message("Vmemo"," Done1 recording\n"+ fileName);
550 } 550 }
551// printf("%d\r",length); 551// printf("%d\r",length);
552// fflush(stdout); 552// fflush(stdout);
553 qApp->processEvents(); 553 qApp->processEvents();
554 } 554 }
555 // qDebug("file has length of %d lasting %d seconds", 555 // qDebug("file has length of %d lasting %d seconds",
556 // length, (( length / speed) / channels) / 2 ); 556 // length, (( length / speed) / channels) / 2 );
557 // medialplayer states wrong length in secs 557 // medialplayer states wrong length in secs
558 } 558 }
559 559
560 //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<// 560 //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<//
561 561
562 value = length+36; 562 value = length+36;
563 563
564 lseek(wav, 4, SEEK_SET); 564 lseek(wav, 4, SEEK_SET);
565 write(wav, &value, 4); 565 write(wav, &value, 4);
566 lseek(wav, 40, SEEK_SET); 566 lseek(wav, 40, SEEK_SET);
567 567
568 write(wav, &length, 4); 568 write(wav, &length, 4);
569 569
570 track.close(); 570 track.close();
571 qDebug("Tracvk closed"); 571 qDebug("Tracvk closed");
572 572
573 if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) 573 if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1)
574 perror("ioctl(\"SNDCTL_DSP_RESET\")"); 574 perror("ioctl(\"SNDCTL_DSP_RESET\")");
575 575
576 ::close(dsp); 576 ::close(dsp);
577 fileName = fileName.left(fileName.length()-4); 577 fileName = fileName.left(fileName.length()-4);
578 // if(useAlerts) 578 // if(useAlerts)
579 // QMessageBox::message("Vmemo"," Done1 recording\n"+ fileName); 579 // QMessageBox::message("Vmemo"," Done1 recording\n"+ fileName);
580 qDebug("done recording "+fileName); 580 qDebug("done recording "+fileName);
581 QSound::play(Resource::findSound("vmemoe")); 581 QSound::play(Resource::findSound("vmemoe"));
582} 582}
583 583
584int VMemo::setToggleButton(int tog) { 584int VMemo::setToggleButton(int tog) {
585 585
586 for( int i=0; i < 10;i++) { 586 for( int i=0; i < 10;i++) {
587 switch (tog) { 587 switch (tog) {
588 case 0: 588 case 0:
589 return -1; 589 return -1;
590 break; 590 break;
591 case 1: 591 case 1:
592 return 0; 592 return 0;
593 break; 593 break;
594 case 2: 594 case 2:
595 return Key_Escape; 595 return Key_Escape;
596 break; 596 break;
597 case 3: 597 case 3:
598 return Key_Space; 598 return Key_Space;
599 break; 599 break;
600 case 4: 600 case 4:
601 return Key_F12; 601 return Key_F12;
602 break; 602 break;
603 case 5: 603 case 5:
604 return Key_F9; 604 return Key_F9;
605 break; 605 break;
606 case 6: 606 case 6:
607 return Key_F10; 607 return Key_F10;
608 break; 608 break;
609 case 7: 609 case 7:
610 return Key_F11; 610 return Key_F11;
611 break; 611 break;
612 case 8: 612 case 8:
613 return Key_F13; 613 return Key_F13;
614 break; 614 break;
615 }; 615 };
616 } 616 }
617} 617}