-rw-r--r-- | core/applets/vmemo/vmemo.cpp | 2 |
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 | |||
@@ -384,193 +384,193 @@ int VMemo::openDSP() | |||
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 | ||
415 | int VMemo::openWAV(const char *filename) | 415 | int 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 | ||
447 | void VMemo::record(void) | 447 | void 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); |