author | llornkcor <llornkcor> | 2002-07-29 12:18:47 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-07-29 12:18:47 (UTC) |
commit | b4827a8b268af9d1485455cdf727f564047f396e (patch) (unidiff) | |
tree | e4cfe0063c4130337d46bce247e0430bf37ce70d | |
parent | b79ef334c6d13beb4fe7fff1e6985c081081a2f6 (diff) | |
download | opie-b4827a8b268af9d1485455cdf727f564047f396e.zip opie-b4827a8b268af9d1485455cdf727f564047f396e.tar.gz opie-b4827a8b268af9d1485455cdf727f564047f396e.tar.bz2 |
fix bug number 140
-rw-r--r-- | core/applets/vmemo/vmemo.cpp | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/core/applets/vmemo/vmemo.cpp b/core/applets/vmemo/vmemo.cpp index 035965e..0c792c6 100644 --- a/core/applets/vmemo/vmemo.cpp +++ b/core/applets/vmemo/vmemo.cpp | |||
@@ -421,220 +421,221 @@ void VMemo::stopRecording() { | |||
421 | if( cfg.readNumEntry("hideIcon",0) == 1 ) | 421 | if( cfg.readNumEntry("hideIcon",0) == 1 ) |
422 | hide(); | 422 | hide(); |
423 | } | 423 | } |
424 | 424 | ||
425 | int VMemo::openDSP() { | 425 | int VMemo::openDSP() { |
426 | Config cfg("Vmemo"); | 426 | Config cfg("Vmemo"); |
427 | cfg.setGroup("Record"); | 427 | cfg.setGroup("Record"); |
428 | 428 | ||
429 | speed = cfg.readNumEntry("SampleRate", 22050); | 429 | speed = cfg.readNumEntry("SampleRate", 22050); |
430 | channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) | 430 | channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) |
431 | if (cfg.readNumEntry("SixteenBit", 1)==1) { | 431 | if (cfg.readNumEntry("SixteenBit", 1)==1) { |
432 | format = AFMT_S16_LE; | 432 | format = AFMT_S16_LE; |
433 | resolution = 16; | 433 | resolution = 16; |
434 | } else { | 434 | } else { |
435 | format = AFMT_U8; | 435 | format = AFMT_U8; |
436 | resolution = 8; | 436 | resolution = 8; |
437 | } | 437 | } |
438 | 438 | ||
439 | qDebug("samplerate: %d, channels %d, resolution %d", speed, channels, resolution); | 439 | qDebug("samplerate: %d, channels %d, resolution %d", speed, channels, resolution); |
440 | 440 | ||
441 | if(systemZaurus) { | 441 | if(systemZaurus) { |
442 | dsp = open("/dev/dsp1", O_RDONLY); //Zaurus needs /dev/dsp1 | 442 | dsp = open("/dev/dsp1", O_RDONLY); //Zaurus needs /dev/dsp1 |
443 | channels=1; //zaurus has one input channel | 443 | channels=1; //zaurus has one input channel |
444 | } else { | 444 | } else { |
445 | dsp = open("/dev/dsp", O_RDONLY); | 445 | dsp = open("/dev/dsp", O_RDONLY); |
446 | } | 446 | } |
447 | 447 | ||
448 | if(dsp == -1) { | 448 | if(dsp == -1) { |
449 | perror("open(\"/dev/dsp\")"); | 449 | perror("open(\"/dev/dsp\")"); |
450 | errorMsg="open(\"/dev/dsp\")\n "+(QString)strerror(errno); | 450 | errorMsg="open(\"/dev/dsp\")\n "+(QString)strerror(errno); |
451 | QMessageBox::critical(0, "vmemo", errorMsg, "Abort"); | 451 | QMessageBox::critical(0, "vmemo", errorMsg, "Abort"); |
452 | return -1; | 452 | return -1; |
453 | } | 453 | } |
454 | 454 | ||
455 | if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) { | 455 | if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) { |
456 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); | 456 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); |
457 | return -1; | 457 | return -1; |
458 | } | 458 | } |
459 | if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) { | 459 | if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) { |
460 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); | 460 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); |
461 | return -1; | 461 | return -1; |
462 | } | 462 | } |
463 | if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) { | 463 | if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) { |
464 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); | 464 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); |
465 | return -1; | 465 | return -1; |
466 | } | 466 | } |
467 | if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) { | 467 | if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) { |
468 | perror("ioctl(\"SOUND_PCM_READ_RATE\")"); | 468 | perror("ioctl(\"SOUND_PCM_READ_RATE\")"); |
469 | return -1; | 469 | return -1; |
470 | } | 470 | } |
471 | 471 | ||
472 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; //mute | 472 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; //mute |
473 | 473 | ||
474 | return 1; | 474 | return 1; |
475 | } | 475 | } |
476 | 476 | ||
477 | int VMemo::openWAV(const char *filename) { | 477 | int VMemo::openWAV(const char *filename) { |
478 | track.setName(filename); | 478 | track.setName(filename); |
479 | if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) { | 479 | if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) { |
480 | errorMsg=filename; | 480 | errorMsg=filename; |
481 | return -1; | 481 | return -1; |
482 | } | 482 | } |
483 | 483 | ||
484 | wav=track.handle(); | 484 | wav=track.handle(); |
485 | useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0); | ||
485 | 486 | ||
486 | WaveHeader wh; | 487 | WaveHeader wh; |
487 | 488 | ||
488 | wh.main_chunk = RIFF; | 489 | wh.main_chunk = RIFF; |
489 | wh.length=0; | 490 | wh.length=0; |
490 | wh.chunk_type = WAVE; | 491 | wh.chunk_type = WAVE; |
491 | wh.sub_chunk = FMT; | 492 | wh.sub_chunk = FMT; |
492 | wh.sc_len = 16; | 493 | wh.sc_len = 16; |
493 | if(useADPCM) | 494 | if(useADPCM) |
494 | wh.format = WAVE_FORMAT_DVI_ADPCM;//PCM_CODE; | 495 | wh.format = WAVE_FORMAT_DVI_ADPCM;//PCM_CODE; |
495 | else | 496 | else |
496 | wh.format = PCM_CODE; | 497 | wh.format = PCM_CODE; |
497 | wh.modus = channels; | 498 | wh.modus = channels; |
498 | wh.sample_fq = speed; | 499 | wh.sample_fq = speed; |
499 | wh.byte_p_sec = speed * channels * resolution/8; | 500 | wh.byte_p_sec = speed * channels * resolution/8; |
500 | wh.byte_p_spl = channels * (resolution / 8); | 501 | wh.byte_p_spl = channels * (resolution / 8); |
501 | wh.bit_p_spl = resolution; | 502 | wh.bit_p_spl = resolution; |
502 | wh.data_chunk = DATA; | 503 | wh.data_chunk = DATA; |
503 | wh.data_length= 0; | 504 | wh.data_length= 0; |
504 | // qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d" | 505 | // qDebug("Write header channels %d, speed %d, b/s %d, blockalign %d, bitrate %d" |
505 | // , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl ); | 506 | // , wh.modus, wh.sample_fq, wh.byte_p_sec, wh.byte_p_spl, wh.bit_p_spl ); |
506 | write (wav, &wh, sizeof(WaveHeader)); | 507 | write (wav, &wh, sizeof(WaveHeader)); |
507 | 508 | ||
508 | return 1; | 509 | return 1; |
509 | } | 510 | } |
510 | 511 | ||
511 | bool VMemo::record() { | 512 | bool VMemo::record() { |
512 | 513 | ||
513 | int length=0, result, value; | 514 | int length=0, result, value; |
514 | QString msg; | 515 | QString msg; |
515 | msg.sprintf("Recording format %d", format); | 516 | msg.sprintf("Recording format %d", format); |
516 | qDebug(msg); | 517 | qDebug(msg); |
517 | Config config("Vmemo"); | 518 | Config config("Vmemo"); |
518 | config.setGroup("Record"); | 519 | config.setGroup("Record"); |
519 | int sRate=config.readNumEntry("SizeLimit", 30); | 520 | int sRate=config.readNumEntry("SizeLimit", 30); |
520 | if(sRate > 0) | 521 | if(sRate > 0) |
521 | t_timer->start( sRate * 1000+1000, TRUE); | 522 | t_timer->start( sRate * 1000+1000, TRUE); |
522 | 523 | ||
523 | // if(systemZaurus) { | 524 | // if(systemZaurus) { |
524 | // } else { // 16 bit only capabilities | 525 | // } else { // 16 bit only capabilities |
525 | 526 | ||
526 | msg.sprintf("Recording format other"); | 527 | msg.sprintf("Recording format other"); |
527 | qDebug(msg); | 528 | qDebug(msg); |
528 | 529 | ||
529 | int bufsize=1024; | 530 | int bufsize=1024; |
530 | int bytesWritten=0; | 531 | int bytesWritten=0; |
531 | signed short sound[1024], monoBuffer[1024]; | 532 | signed short sound[1024], monoBuffer[1024]; |
532 | char abuf[bufsize/2]; | 533 | char abuf[bufsize/2]; |
533 | short sbuf[bufsize]; | 534 | short sbuf[bufsize]; |
535 | useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0); | ||
534 | 536 | ||
535 | while(recording) { | 537 | while(recording) { |
536 | 538 | ||
537 | if(useADPCM) | 539 | if(useADPCM) |
538 | result = read( dsp, sbuf, bufsize); // 8192 | 540 | result = read( dsp, sbuf, bufsize); // 8192 |
539 | else | 541 | else |
540 | result = read(dsp, sound, 1024); // 8192 | 542 | result = read(dsp, sound, 1024); // 8192 |
541 | if( result <= 0) { | 543 | if( result <= 0) { |
542 | perror("recording error "); | 544 | perror("recording error "); |
543 | // qDebug(currentFileName); | 545 | // qDebug(currentFileName); |
544 | QMessageBox::message(tr("Note"),tr("error recording")); | 546 | QMessageBox::message(tr("Note"),tr("error recording")); |
545 | recording=FALSE; | 547 | recording=FALSE; |
546 | break; | 548 | break; |
547 | return FALSE; | 549 | return FALSE; |
548 | } | 550 | } |
549 | 551 | ||
550 | if(useADPCM) { | 552 | if(useADPCM) { |
551 | adpcm_coder( sbuf, abuf, result/2, &encoder_state); | 553 | adpcm_coder( sbuf, abuf, result/2, &encoder_state); |
552 | bytesWritten = ::write(wav, abuf, result/4); | 554 | bytesWritten = ::write(wav, abuf, result/4); |
553 | 555 | ||
554 | } else { | 556 | } else { |
555 | for (int i = 0; i < result; i++) { //since Z is mono do normally | 557 | for (int i = 0; i < result; i++) { //since Z is mono do normally |
556 | monoBuffer[i] = sound[i]; | 558 | monoBuffer[i] = sound[i]; |
557 | } | 559 | } |
558 | 560 | ||
559 | length+=write(wav, monoBuffer, result); | 561 | length+=write(wav, monoBuffer, result); |
560 | } | 562 | } |
561 | length +=bytesWritten; | 563 | length +=bytesWritten; |
562 | 564 | ||
563 | if(length<0) { | 565 | if(length<0) { |
564 | recording=false; | 566 | recording=false; |
565 | perror("dev/dsp's is a lookin' messy"); | 567 | perror("dev/dsp's is a lookin' messy"); |
566 | QMessageBox::message("Vmemo"," Done1 recording\n"+ fileName); | 568 | QMessageBox::message("Vmemo"," Done1 recording\n"+ fileName); |
567 | break; | 569 | break; |
568 | return FALSE; | 570 | return FALSE; |
569 | } | 571 | } |
570 | // printf("%d\r",length); | 572 | // printf("%d\r",length); |
571 | // fflush(stdout); | 573 | // fflush(stdout); |
572 | qApp->processEvents(); | 574 | qApp->processEvents(); |
573 | } | 575 | } |
574 | // qDebug("file has length of %d lasting %d seconds", | 576 | // qDebug("file has length of %d lasting %d seconds", |
575 | // length, (( length / speed) / channels) / 2 ); | 577 | // length, (( length / speed) / channels) / 2 ); |
576 | // medialplayer states wrong length in secs | ||
577 | // } | 578 | // } |
578 | 579 | ||
579 | //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<// | 580 | //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<// |
580 | 581 | ||
581 | value = length+36; | 582 | value = length+36; |
582 | 583 | ||
583 | lseek(wav, 4, SEEK_SET); | 584 | lseek(wav, 4, SEEK_SET); |
584 | write(wav, &value, 4); | 585 | write(wav, &value, 4); |
585 | lseek(wav, 40, SEEK_SET); | 586 | lseek(wav, 40, SEEK_SET); |
586 | 587 | ||
587 | write(wav, &length, 4); | 588 | write(wav, &length, 4); |
588 | 589 | ||
589 | track.close(); | 590 | track.close(); |
590 | qDebug("Track closed"); | 591 | qDebug("Track closed"); |
591 | 592 | ||
592 | if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) | 593 | if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) |
593 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); | 594 | perror("ioctl(\"SNDCTL_DSP_RESET\")"); |
594 | 595 | ||
595 | ::close(dsp); | 596 | ::close(dsp); |
596 | fileName = fileName.left(fileName.length()-4); | 597 | fileName = fileName.left(fileName.length()-4); |
597 | // if(useAlerts) | 598 | // if(useAlerts) |
598 | // QMessageBox::message("Vmemo"," Done1 recording\n"+ fileName); | 599 | // QMessageBox::message("Vmemo"," Done1 recording\n"+ fileName); |
599 | qDebug("done recording "+fileName); | 600 | qDebug("done recording "+fileName); |
600 | 601 | ||
601 | // QSound::play(Resource::findSound("vmemoe")); | 602 | // QSound::play(Resource::findSound("vmemoe")); |
602 | 603 | ||
603 | Config cfg("qpe"); | 604 | Config cfg("qpe"); |
604 | cfg.setGroup("Volume"); | 605 | cfg.setGroup("Volume"); |
605 | QString foo = cfg.readEntry("Mute","TRUE"); | 606 | QString foo = cfg.readEntry("Mute","TRUE"); |
606 | if(foo.find("TRUE",0,TRUE) != -1) | 607 | if(foo.find("TRUE",0,TRUE) != -1) |
607 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; //mute | 608 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; //mute |
608 | return TRUE; | 609 | return TRUE; |
609 | } | 610 | } |
610 | 611 | ||
611 | int VMemo::setToggleButton(int tog) { | 612 | int VMemo::setToggleButton(int tog) { |
612 | 613 | ||
613 | for( int i=0; i < 10;i++) { | 614 | for( int i=0; i < 10;i++) { |
614 | switch (tog) { | 615 | switch (tog) { |
615 | case 0: | 616 | case 0: |
616 | return -1; | 617 | return -1; |
617 | break; | 618 | break; |
618 | case 1: | 619 | case 1: |
619 | return 0; | 620 | return 0; |
620 | break; | 621 | break; |
621 | case 2: | 622 | case 2: |
622 | return Key_Escape; | 623 | return Key_Escape; |
623 | break; | 624 | break; |
624 | case 3: | 625 | case 3: |
625 | return Key_Space; | 626 | return Key_Space; |
626 | break; | 627 | break; |
627 | case 4: | 628 | case 4: |
628 | return Key_F12; | 629 | return Key_F12; |
629 | break; | 630 | break; |
630 | case 5: | 631 | case 5: |
631 | return Key_F9; | 632 | return Key_F9; |
632 | break; | 633 | break; |
633 | case 6: | 634 | case 6: |
634 | return Key_F10; | 635 | return Key_F10; |
635 | break; | 636 | break; |
636 | case 7: | 637 | case 7: |
637 | return Key_F11; | 638 | return Key_F11; |
638 | break; | 639 | break; |
639 | case 8: | 640 | case 8: |
640 | return Key_F13; | 641 | return Key_F13; |