author | llornkcor <llornkcor> | 2004-04-22 10:53:59 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2004-04-22 10:53:59 (UTC) |
commit | 2a950511ee173c2cbce5da4d14de9cea6fcd5034 (patch) (unidiff) | |
tree | e669b1291dba50a1ea59ad89a63ef75c3b5ddcaf /core | |
parent | 8340f9a7ab295f769721e23f3840220c09b7b144 (diff) | |
download | opie-2a950511ee173c2cbce5da4d14de9cea6fcd5034.zip opie-2a950511ee173c2cbce5da4d14de9cea6fcd5034.tar.gz opie-2a950511ee173c2cbce5da4d14de9cea6fcd5034.tar.bz2 |
optimize, remove an if statement from loop
-rw-r--r-- | core/applets/vmemo/vmemo.cpp | 66 |
1 files changed, 35 insertions, 31 deletions
diff --git a/core/applets/vmemo/vmemo.cpp b/core/applets/vmemo/vmemo.cpp index 1ead4dd..835f63a 100644 --- a/core/applets/vmemo/vmemo.cpp +++ b/core/applets/vmemo/vmemo.cpp | |||
@@ -271,3 +271,3 @@ void VMemo::paintEvent( QPaintEvent* ) { | |||
271 | 271 | ||
272 | void VMemo::mousePressEvent( QMouseEvent * me) { | 272 | void VMemo::mousePressEvent( QMouseEvent * /*me*/) { |
273 | /* No mousePress/mouseRelease recording on the iPAQ. The REC button on the iPAQ calls these functions | 273 | /* No mousePress/mouseRelease recording on the iPAQ. The REC button on the iPAQ calls these functions |
@@ -487,3 +487,5 @@ bool VMemo::record() { | |||
487 | length = 0; | 487 | length = 0; |
488 | int result, value; | 488 | int bytesWritten = 0; |
489 | int result = 0; | ||
490 | int value = 0; | ||
489 | QString msg; | 491 | QString msg; |
@@ -497,5 +499,2 @@ bool VMemo::record() { | |||
497 | 499 | ||
498 | // if(systemZaurus) { | ||
499 | // } else { // 16 bit only capabilities | ||
500 | |||
501 | msg.sprintf("Recording format other"); | 500 | msg.sprintf("Recording format other"); |
@@ -503,11 +502,7 @@ bool VMemo::record() { | |||
503 | 502 | ||
503 | config.setGroup("Defaults"); | ||
504 | useADPCM = config.readBoolEntry("use_ADPCM", 0); | ||
504 | 505 | ||
505 | int bytesWritten = 0; | 506 | int bufsize = config.readNumEntry("BufferSize",1024); |
506 | 507 | unsigned short sound[bufsize]; //, monoBuffer[bufsize]; | |
507 | Config vmCfg("Vmemo"); | ||
508 | vmCfg.setGroup("Defaults"); | ||
509 | useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0); | ||
510 | |||
511 | int bufsize = vmCfg.readNumEntry("BufferSize",1024); | ||
512 | signed short sound[bufsize], monoBuffer[bufsize]; | ||
513 | char abuf[bufsize / 2]; | 508 | char abuf[bufsize / 2]; |
@@ -515,11 +510,7 @@ bool VMemo::record() { | |||
515 | 510 | ||
511 | if(useADPCM) { | ||
516 | while(recording) { | 512 | while(recording) { |
517 | 513 | result = ::read(dsp, sbuf, bufsize); // adpcm read | |
518 | if(useADPCM) | ||
519 | result = ::read(dsp, sbuf, bufsize); // 8192 | ||
520 | else | ||
521 | result = ::read(dsp, sound, bufsize); // 8192 | ||
522 | if( result <= 0) { | 514 | if( result <= 0) { |
523 | perror("recording error "); | 515 | perror("recording error "); |
524 | // odebug << currentFileName << oendl; | ||
525 | QMessageBox::message(tr("Note"),tr("error recording")); | 516 | QMessageBox::message(tr("Note"),tr("error recording")); |
@@ -529,14 +520,28 @@ bool VMemo::record() { | |||
529 | } | 520 | } |
530 | |||
531 | if(useADPCM) { | ||
532 | adpcm_coder( sbuf, abuf, result/2, &encoder_state); | 521 | adpcm_coder( sbuf, abuf, result/2, &encoder_state); |
533 | bytesWritten = ::write(wav, abuf, result/4); | 522 | bytesWritten = ::write(wav, abuf, result/4); // adpcm write |
523 | length += bytesWritten; | ||
534 | 524 | ||
525 | if(length < 0) { | ||
526 | recording = false; | ||
527 | perror("dev/dsp's is a lookin' messy"); | ||
528 | QMessageBox::message("Vmemo","Error writing to file\n"+ fileName); | ||
529 | break; | ||
530 | return FALSE; | ||
531 | } | ||
532 | // printf("%d\r", length); | ||
533 | // fflush(stdout); | ||
534 | qApp->processEvents(); | ||
535 | } | ||
535 | } else { | 536 | } else { |
536 | // for (int i = 0; i < result; i++) { //since Z is mono do normally | 537 | while(recording) { |
537 | // monoBuffer[i] = sound[i]; | 538 | result = ::read(dsp, sound, bufsize); // read |
538 | // } | 539 | if( result <= 0) { |
540 | perror("recording error "); | ||
541 | QMessageBox::message(tr("Note"),tr("error recording")); | ||
542 | recording = FALSE; | ||
543 | break; | ||
544 | return FALSE; | ||
539 | 545 | ||
540 | length += write(wav, sound, result); | 546 | bytesWritten = ::write(wav, sound, result); // write |
541 | } | ||
542 | length += bytesWritten; | 547 | length += bytesWritten; |
@@ -550,3 +555,3 @@ bool VMemo::record() { | |||
550 | } | 555 | } |
551 | // odebug << "" << length << "\r" << oendl; | 556 | // printf("%d\r", length); |
552 | // fflush(stdout); | 557 | // fflush(stdout); |
@@ -554,7 +559,6 @@ bool VMemo::record() { | |||
554 | } | 559 | } |
560 | } | ||
561 | } | ||
555 | // qDebug("file has length of %d lasting %d seconds", | 562 | // qDebug("file has length of %d lasting %d seconds", |
556 | // length, (( length / speed) / channels) / 2 ); | 563 | // length, (( length / speed) / channels) / 2 ); |
557 | // } | ||
558 | |||
559 | //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<// | ||
560 | 564 | ||